using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data; using DevComponents.DotNetBar.Layout; using DevComponents.DotNetBar.Controls; namespace WCS_Client.UC { public class WorkDataUtil { public static DataSet GetWorkParameter(List LCItemList) { try { List WorkDataList = new List(); foreach (LayoutControlItem LCItem in LCItemList) { if (LCItem == null || LCItem.Control == null || LCItem.Tag == null) { continue; } List Tmplist = GetLCItemValue(LCItem); if (Tmplist != null) { WorkDataList.AddRange(Tmplist); } } List WorkNameList = new List(); foreach (WorkDataInfo witem in WorkDataList) { if (!WorkNameList.Contains(witem.WorkName)) { WorkNameList.Add(witem.WorkName); } } DataSet ds = new DataSet(); foreach (string wname in WorkNameList) { DataTable dt = new DataTable(wname); List wdlist = WorkDataList.FindAll(a => a.WorkName == wname); foreach (WorkDataInfo w in wdlist) { dt.Columns.Add(w.ParameterName, typeof(string)); } DataRow dr = dt.NewRow(); foreach (WorkDataInfo w in wdlist) { dr[w.ParameterName] = w.ParameterData; } dt.Rows.Add(dr); ds.Tables.Add(dt); } return ds; } catch { } return null; } public static List GetLCItemValue(LayoutControlItem LCItem) { try { if (LCItem == null || LCItem.Control == null || LCItem.Tag == null) { throw new Exception(); } List WorkDataList = new List(); if (LCItem.Tag is WorkDataInfo) { WorkDataList.Add(LCItem.Tag as WorkDataInfo); } else if (LCItem.Tag is List) { WorkDataList.AddRange(LCItem.Tag as List); } else { throw new Exception(); } string s = ""; if (LCItem.Control is ComboBoxEx) { ComboBoxEx Citem = LCItem.Control as ComboBoxEx; s = Citem.SelectedValue == null ? "" : Citem.SelectedValue.ToString(); } else if (LCItem.Control is TextBoxX) { s = LCItem.Control.Text; } else if (LCItem.Control is LC_DropChkList) { LC_DropChkList Item = LCItem.Control as LC_DropChkList; s = ListToString(Item.GetValue()); } else if (LCItem.Control is DevComponents.Editors.IntegerInput) { DevComponents.Editors.IntegerInput Item = LCItem.Control as DevComponents.Editors.IntegerInput; s = Item.Value.ToString(); } else if (LCItem.Control is CheckBoxX) { CheckBoxX Item = LCItem.Control as CheckBoxX; if (Item.Checked) { s = "1"; } else { s = "0"; } } else if (LCItem.Control is DevComponents.Editors.DateTimeAdv.DateTimeInput) { DevComponents.Editors.DateTimeAdv.DateTimeInput Item = LCItem.Control as DevComponents.Editors.DateTimeAdv.DateTimeInput; s = Item.Value.ToString(); } else { throw new Exception(); } foreach (WorkDataInfo witem in WorkDataList) { witem.ParameterData = s; } return WorkDataList; } catch { } return null; } public static String ListToString(List list) { string s = ""; if (list != null) { int Count = list.Count; for (int i = 0; i < Count; i++) { if (i == 0) { s = list[i]; continue; } s = s + "," + list[i]; } } return s; } } public class WorkDataInfo { string _WorkName = ""; /// /// 方法名 /// public string WorkName { get { return _WorkName; } set { _WorkName = value; } } string _ParameterName = ""; /// /// 参数名 /// public string ParameterName { get { return _ParameterName; } set { _ParameterName = value; } } string _ParameterData = ""; /// /// 参数数量 /// public string ParameterData { get { return _ParameterData; } set { _ParameterData = value; } } } }