using System; using System.Collections.Generic; using System.Linq; using System.Text; using DevComponents.DotNetBar.Layout; using DevComponents.DotNetBar.Controls; namespace WCS_Client.UC { public class LCWhereUtil { public static List GetWhereText(List LCItemList) { try { List QWList = new List(); foreach (LayoutControlItem Item in LCItemList) { if (Item == null || Item.Control == null || Item.Tag == null) { continue; } if (Item.Tag is LCWhereInfo) { LCWhereInfo QWItem = Item.Tag as LCWhereInfo; if (string.IsNullOrEmpty(QWItem.QWhereText)) { continue; } string s = Get_LCWhere(Item, QWItem.QWhereText); if (string.IsNullOrEmpty(s)) { continue; } QWList.Add(new LCWhereInfo() { QWhereText = s, ReplaceNo = QWItem.ReplaceNo, GroupNo = QWItem.GroupNo }); } else if (Item.Tag is List) { List QWItemList = Item.Tag as List; foreach (LCWhereInfo qitem in QWItemList) { if (string.IsNullOrEmpty(qitem.QWhereText)) { continue; } string s = Get_LCWhere(Item, qitem.QWhereText); if (string.IsNullOrEmpty(s)) { continue; } QWList.Add(new LCWhereInfo() { QWhereText = s, ReplaceNo = qitem.ReplaceNo, GroupNo = qitem.GroupNo }); } } } if (QWList.Count > 0) { List QGroupList = new List(); foreach (LCWhereInfo qitem in QWList) { LCWhereInfo Nqitem = QGroupList.Find(a => a.ReplaceNo == qitem.ReplaceNo && a.GroupNo == qitem.GroupNo); if (Nqitem == null) { QGroupList.Add(new LCWhereInfo() { ReplaceNo = qitem.ReplaceNo, QWhereText = qitem.QWhereText, GroupNo = qitem.GroupNo }); continue; } if (Nqitem.GroupNo == -1) { Nqitem.QWhereText = string.Format("{0} and {1}", Nqitem.QWhereText, qitem.QWhereText); } else { Nqitem.QWhereText = string.Format("{0} or {1}", Nqitem.QWhereText, qitem.QWhereText); } } List QReplaceList = new List(); foreach (LCWhereInfo reitem in QGroupList) { LCWhereInfo Nqitem = QReplaceList.Find(a => a.ReplaceNo == reitem.ReplaceNo); if (Nqitem == null) { if (reitem.GroupNo == -1) { QReplaceList.Add(new LCWhereInfo() { ReplaceNo = reitem.ReplaceNo, QWhereText = reitem.QWhereText, GroupNo = -1 }); } else { QReplaceList.Add(new LCWhereInfo() { ReplaceNo = reitem.ReplaceNo, QWhereText = string.Format("({0})", reitem.QWhereText), GroupNo = -1 }); } } else { if (reitem.GroupNo == -1) { Nqitem.QWhereText = string.Format("{0} and {1}", Nqitem.QWhereText, reitem.QWhereText); } else { Nqitem.QWhereText = string.Format("{0} and ({1})", Nqitem.QWhereText, reitem.QWhereText); } } } return (from n in QReplaceList orderby n.ReplaceNo select n.QWhereText).ToList(); } } catch { } return null; } public static string Get_LCWhere(LayoutControlItem LCItem, string ReplaceString) { return Get_LCWhere(LCItem, "", ReplaceString); } public static string Get_LCWhere(LayoutControlItem LCItem, string ConnAndOr, string ReplaceString) { try { if (LCItem == null || LCItem.Control == null || string.IsNullOrEmpty(ReplaceString)) { throw new Exception(); } string s = ""; if (LCItem.Control is TextBoxX) { if (string.IsNullOrEmpty(LCItem.Control.Text)) { throw new Exception(); } s = string.Format(ReplaceString, LCItem.Control.Text); } else if (LCItem.Control is ComboBoxEx) { ComboBoxEx Citem = LCItem.Control as ComboBoxEx; if (Citem.SelectedValue == null || string.IsNullOrEmpty(Citem.SelectedValue.ToString())) { throw new Exception(); } s = string.Format(ReplaceString, Citem.SelectedValue.ToString()); } else if (LCItem.Control is LC_DropChkList) { LC_DropChkList Item = LCItem.Control as LC_DropChkList; List DataItemList = Item.GetValue(); if (DataItemList == null || DataItemList.Count == 0) { throw new Exception(); } bool istag = true; foreach (string str in DataItemList) { if (istag) { s = string.Format(ReplaceString, str); istag = false; continue; } s = s + " or " + string.Format(ReplaceString, str); } } else if (LCItem.Control is LC_TwoDateTime) { LC_TwoDateTime Item = LCItem.Control as LC_TwoDateTime; List dtList = Item.GetValue(); if (dtList == null || dtList.Count != 2) { throw new Exception(); } s = string.Format(ReplaceString, dtList[0], dtList[1]); } else if (LCItem.Control is DevComponents.Editors.IntegerInput) { DevComponents.Editors.IntegerInput Item = LCItem.Control as DevComponents.Editors.IntegerInput; if (Item.Value <= 0) { throw new Exception(); } s = string.Format(ReplaceString, Item.Value); } else if (LCItem.Control is CheckBoxX) { CheckBoxX Item = LCItem.Control as CheckBoxX; if (Item.CheckState == System.Windows.Forms.CheckState.Indeterminate) { throw new Exception(); } s = string.Format(ReplaceString, Item.Checked ? 1 : 0); } else { throw new Exception(); } if (!string.IsNullOrEmpty(s)) { s = string.Format(" {0} ({1})", ConnAndOr, s); } return s; } catch { } return ""; } public static string Get_LCWhereOr(LayoutControlItem LCItem, string ReplaceString) { return Get_LCWhere(LCItem, "Or", ReplaceString); } public static string Get_LCWhereAnd(LayoutControlItem LCItem, string ReplaceString) { return Get_LCWhere(LCItem, "And", ReplaceString); } } public class LCWhereInfo { string _QWhereText = ""; public string QWhereText { get { return _QWhereText; } set { _QWhereText = value; } } int _ReplaceNo = 0; public int ReplaceNo { get { return _ReplaceNo; } set { _ReplaceNo = value; } } int _GroupNo = -1; public int GroupNo { get { return _GroupNo; } set { _GroupNo = value; } } } }