using System.Collections.Generic;
using System.Windows.Media;
using System.Windows;
using System;
using HandyControl.Data;
using HxEnum;
using XCommon.Tip;
using XImagingXhandler.XDAL;
using XHandler.View.MethodProperty;
using System.Windows.Controls;
using DataEntity.Share;
using System.Collections.ObjectModel;
using System.Linq;
using XCore;
namespace XHandler.View.Com
{
///
/// 视图共用类
///
public class ViewCom
{
#region 查找控件的子控件,并返回子控件对象
public static List GetChildObjects(DependencyObject obj, Type typename) where T : FrameworkElement
{
DependencyObject child = null;
List childList = new List();
for (int i = 0; i <= VisualTreeHelper.GetChildrenCount(obj) - 1; i++)
{
child = VisualTreeHelper.GetChild(obj, i);
if (child is T && (((T)child).GetType() == typename))
{
childList.Add((T)child);
}
childList.AddRange(GetChildObjects(child, typename));
}
return childList;
}
#endregion
#region 打开子方法流程状态页面
///
/// 打开子方法流程状态页面
///
///
///
public static void OpenSubMethodWorkflow(TreeView runTreeviewWorkflow)
{
if (runTreeviewWorkflow.SelectedItem == null)
{
return;
}
MethodEx mEx = runTreeviewWorkflow.SelectedItem as MethodEx;
if (mEx.tag == null)
{
return;
}
// 不是子方法,无法查看
int iNum = new MethodListBll().getNumByMethodName(mEx.method_name);
if (!iNum.Equals((int)(MethodNameEnum.subMethod)))
{
ShowTip.ShowNotice("不是子方法,无法查看", InfoType.Warning);
return;
}
MethodSubMethod method = (MethodSubMethod)mEx.tag;
SubMethodWorkflow subMethodWorkflow = new SubMethodWorkflow(method);
subMethodWorkflow.Show();
}
#endregion
#region 初始化工作流
///
/// 初始化工作流
///
///
public static void InitWorkFlow(MethodEx rootMethod)
{
// 获取方法指令集合
ObservableCollection methods = MethodDB.GetMethodFromdb(Shared.SoftwareInformation.software_device_number);
// 获取固定方法节点
var selFixMethod = methods.Where(s => s.method_group_id == EnumManagement.GetEnumValue(MethodGroupEnum.None)).OrderBy(s => s.method_id);
rootMethod.method_name = "root";
rootMethod.Level = -1;
if (!selFixMethod.Any())
{
return;
}
List fixMethodList = selFixMethod.ToList();
for (int index = 0; index < fixMethodList.Count; index++)
{
Method fixMethodItem = fixMethodList[index];
MethodEx mEx = new MethodEx(fixMethodItem, rootMethod);
mEx.Index = rootMethod.Children.Count + 1;
mEx.strIndex = mEx.Index.ToString();
mEx.Moveable = false;
// 可往台面布置内拖动
mEx.canDrop = mEx.method_id.Equals("1");
rootMethod.Children.Add(mEx);
if (mEx.method_id == "0") // 开始
{
StartProperty property = new StartProperty(mEx);
mEx.control = property;
}
else if (mEx.method_id == "2") // 结束
{
EndProperty property = new EndProperty(mEx);
mEx.control = property;
}
}
}
#endregion
#region MethodEx重新排序号
///
/// MethodEx重新排序号
///
///
///
public static void ReOrderMethodIndex(string index, MethodEx mEx)
{
int subIndex = 1;
foreach (var mExItem in mEx.Children)
{
mExItem.Index = subIndex;
mExItem.Level = mEx.Level + 1;
if (mExItem.Level == 0)
{
mExItem.strIndex = subIndex.ToString();
}
else
{
mExItem.strIndex = index + "-" + subIndex;
}
ReOrderMethodIndex(mExItem.strIndex, mExItem);
subIndex++;
}
}
#endregion
}
}