using CollaborativePlatformMain.DFEntity.MessageSubUtil;
using CollaborativePlatformMain.Form.MessageSubPage;
using CollaborativePlatformMain.Form.MessageSubPage.Project;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace CollaborativePlatformMain.Form
{
///
/// BigFullProfessiongForm.xaml 的交互逻辑
///
public partial class BigFullProfessiongForm : Window
{
///
/// 父级窗体
///
public HomepageForm HomepageForm;
/////
///// 父级窗体
/////
//public OperatingFloorPage OperatingFloorPage;
///
/// 子级窗体
///
public FullProfessionPage SmallPage;
///
/// 子级窗体
///
public FullProfessionPage BigPage;
/////
///// 暖通数据
/////
//public ObservableCollection WarmDatas = new ObservableCollection();
public BigFullProfessiongForm(HomepageForm homepageForm, FullProfessionPage fullProfessionPage, string bulingName = "")
{
InitializeComponent();
HomepageForm = homepageForm;
SmallPage = fullProfessionPage;
}
///
/// 窗体初始化
///
///
///
private void Window_Loaded(object sender, RoutedEventArgs e)
{
BigPage = new FullProfessionPage(HomepageForm);
//长款
BigPage.Width = 1000;
BigPage.Height = 420;
//tree赋值
BigPage.tr_threemodel.ItemsSource = OperatingFloorPage.ArchOperaDatas;
BigPage.tr_threemode2.ItemsSource = OperatingFloorPage.StruOperaDatas;
BigPage.tr_threemode3.ItemsSource = OperatingFloorPage.WaterOperaDatas;
BigPage.tr_threemode4.ItemsSource = OperatingFloorPage.WarmOperaDatas;
BigPage.tr_threemode5.ItemsSource = OperatingFloorPage.EleOperaDatas;
//屏蔽点击事件
BigPage.tb_arch.IsHitTestVisible = false;
BigPage.tb_stru.IsHitTestVisible = false;
BigPage.tb_water.IsHitTestVisible = false;
BigPage.tb_warm.IsHitTestVisible = false;
BigPage.tb_ele.IsHitTestVisible = false;
// 创建新的列定义
ColumnDefinition colDef1 = new ColumnDefinition();
colDef1.Width = new GridLength(1, GridUnitType.Star);
ColumnDefinition colDef2 = new ColumnDefinition();
colDef2.Width = new GridLength(1, GridUnitType.Star);
ColumnDefinition colDef3 = new ColumnDefinition();
colDef3.Width = new GridLength(1, GridUnitType.Star);
ColumnDefinition colDef4 = new ColumnDefinition();
colDef4.Width = new GridLength(1, GridUnitType.Star);
ColumnDefinition colDef5 = new ColumnDefinition();
colDef5.Width = new GridLength(1, GridUnitType.Star);
// 清除旧的列定义
BigPage.gridName.ColumnDefinitions.Clear();
// 添加到Grid中
BigPage.gridName.ColumnDefinitions.Add(colDef1);
BigPage.gridName.ColumnDefinitions.Add(colDef2);
BigPage.gridName.ColumnDefinitions.Add(colDef3);
BigPage.gridName.ColumnDefinitions.Add(colDef4);
BigPage.gridName.ColumnDefinitions.Add(colDef5);
frame.Navigate(BigPage);
}
///
/// 窗体关闭事件
///
///
///
private void Window_Closed(object sender, EventArgs e)
{
HomepageForm.Visibility = Visibility.Visible;
}
///
/// 一键底图
///
///
///
private void Button_Click(object sender, RoutedEventArgs e)
{
string value = bt_ditu.Content.ToString();
if (value.Contains("底图"))
{
SelectItemByClick(BigPage.tr_threemodel, false, "Visible");
bt_ditu.Content = "确定";
}
else
{
//选中的标高
Dictionary> archDatas = new Dictionary>();
foreach (OperatEntity operatEntity in BigPage.tr_threemodel.ItemsSource)
{
//版本号
foreach (var twoData in operatEntity.SubDatas)
{
//原图、对比图、治理图
foreach (var threeData in twoData.SubDatas)
{
if (threeData.Node.Contains("治理"))
{
//整栋图、分层图
foreach (var fourData in threeData.SubDatas)
{
if (fourData.Node.Contains("分层"))
{
foreach (var fiveData in fourData.SubDatas)
{
if (archDatas.ContainsKey(fiveData.Node))
{
archDatas[fiveData.Node].AddRange(fiveData.SubDatas.Where(x => x.IsCheck).ToList());
}
else
{
archDatas.Add(fiveData.Node, fiveData.SubDatas.Where(x => x.IsCheck).ToList());
}
}
}
}
}
}
}
}
SelectItemByClick(BigPage.tr_threemodel, false, "Collapsed");
//项目
foreach (OperatEntity firstData in BigPage.tr_threemode4.ItemsSource)
{
//版本号
foreach (var twoData in firstData.SubDatas)
{
//原图、对比图、治理图
foreach (var threeData in twoData.SubDatas)
{
if (threeData.Node.Contains("治理"))
{
//整栋图、分层图
foreach (var fourData in threeData.SubDatas)
{
if (fourData.Node.Contains("分层"))
{
foreach (var fiveData in fourData.SubDatas)
{
List sameDatas = archDatas[fiveData.Node];
sameDatas.ForEach(x =>
{
OperatEntity operatEntity = new OperatEntity(x.Node, x.DrawPath, new ObservableCollection(), true);
operatEntity.isShow = "Collapsed";
operatEntity.isCheck = false;
fiveData.SubDatas.Add(operatEntity);
});
}
}
}
}
}
}
}
bt_ditu.Content = "一键底图";
}
}
///
/// 修改checkbox选中
///
///
///
///
///
///
public TreeViewItem SelectItemByClick(ItemsControl itemsControl, bool isSelect, string isvisible, bool isSub = false)
{
foreach (object item in itemsControl.Items)
{
TreeViewItem currentItem = itemsControl.ItemContainerGenerator.ContainerFromItem(item) as TreeViewItem;
if (currentItem == null) continue;
OperatEntity testData = currentItem.DataContext as OperatEntity;
//if (testData.IsLayer)
//{
if (currentItem.IsExpanded)
{
CheckBox checkBox = FindVisualChild(currentItem, "cb_Check");
if (checkBox != null)
{
OperatEntity operatEntity = checkBox.DataContext as OperatEntity;
if (operatEntity.IsLayer)
{
checkBox.IsChecked = isSelect;
if (isvisible == "Visible")
{
checkBox.Visibility = Visibility.Visible;
}
else
{
checkBox.Visibility = Visibility.Collapsed;
}
checkBox.UpdateLayout();
}
}
SelectItemByClick(currentItem, isSelect, isvisible, true);
}
else
{
currentItem.IsExpanded = true;
currentItem.UpdateLayout();
CheckBox checkBox = FindVisualChild(currentItem, "cb_Check");
if (checkBox != null)
{
OperatEntity operatEntity = checkBox.DataContext as OperatEntity;
if (operatEntity.IsLayer)
{
checkBox.IsChecked = isSelect;
if (isvisible == "Visible")
{
checkBox.Visibility = Visibility.Visible;
}
else
{
checkBox.Visibility = Visibility.Collapsed;
}
checkBox.UpdateLayout();
}
}
SelectItemByClick(currentItem, isSelect, isvisible, true);
currentItem.IsExpanded = false;
currentItem.UpdateLayout();
}
//}
//else
//{
// SelectItemByClick(currentItem, isSelect, isvisible);
//}
}
return null;
}
///
/// 获取listview某一列子控件
///
/// 控件
/// 指定名称
///
private CheckBox FindVisualChild(DependencyObject obj, string name)
{
//无限寻找下一级
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++)
{
DependencyObject child = VisualTreeHelper.GetChild(obj, i);
if (child != null && child is CheckBox text && text.Name == name) return text;
else
{
CheckBox childOfChildren = FindVisualChild(child, name);
if (childOfChildren != null) return childOfChildren;
}
}
return null;
}
///
/// 修改选择框可见性
///
public void SetShow(ObservableCollection operatEntities, string value)
{
foreach (var operatEntity in operatEntities)
{
if (operatEntity.IsLayer)
{
operatEntity.IsShow = value;
}
SetShow(operatEntity.SubDatas, value);
}
}
///
/// 一键落图
///
///
///
private void Button_Click_1(object sender, RoutedEventArgs e)
{
string value = bt_luotu.Content.ToString();
if (value.Contains("落图"))
{
SelectItemByClick(BigPage.tr_threemode4, false, "Visible");
bt_luotu.Content = "确定";
}
else
{
//选中的标高
Dictionary> archDatas = new Dictionary>();
foreach (OperatEntity operatEntity in BigPage.tr_threemode4.ItemsSource)
{
//版本号
foreach (var twoData in operatEntity.SubDatas)
{
//原图、对比图、治理图
foreach (var threeData in twoData.SubDatas)
{
if (threeData.Node.Contains("治理"))
{
//整栋图、分层图
foreach (var fourData in threeData.SubDatas)
{
if (fourData.Node.Contains("分层"))
{
foreach (var fiveData in fourData.SubDatas)
{
if (archDatas.ContainsKey(fiveData.Node))
{
archDatas[fiveData.Node].AddRange(fiveData.SubDatas.Where(x => x.IsCheck).ToList());
}
else
{
archDatas.Add(fiveData.Node, fiveData.SubDatas.Where(x => x.IsCheck).ToList());
}
}
}
}
}
}
}
}
SelectItemByClick(BigPage.tr_threemode4, false, "Collapsed");
//项目
foreach (OperatEntity firstData in BigPage.tr_threemodel.ItemsSource)
{
//版本号
foreach (var twoData in firstData.SubDatas)
{
//原图、对比图、治理图
foreach (var threeData in twoData.SubDatas)
{
if (threeData.Node.Contains("治理"))
{
//整栋图、分层图
foreach (var fourData in threeData.SubDatas)
{
if (fourData.Node.Contains("分层"))
{
foreach (var fiveData in fourData.SubDatas)
{
List sameDatas = archDatas[fiveData.Node];
sameDatas.ForEach(x =>
{
OperatEntity operatEntity = new OperatEntity(x.Node, x.DrawPath, new ObservableCollection(), true);
operatEntity.isShow = "Collapsed";
operatEntity.isCheck = false;
fiveData.SubDatas.Add(operatEntity);
});
}
}
}
}
}
}
}
bt_luotu.Content = "一键落图";
}
}
private void Butto_Click_1(object sender, RoutedEventArgs e)
{
}
}
}