123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270 |
- 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<string> GetWhereText(List<LayoutControlItem> LCItemList)
- {
- try
- {
- List<LCWhereInfo> QWList = new List<LCWhereInfo>();
- 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<LCWhereInfo>)
- {
- List<LCWhereInfo> QWItemList = Item.Tag as List<LCWhereInfo>;
- 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<LCWhereInfo> QGroupList = new List<LCWhereInfo>();
- 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<LCWhereInfo> QReplaceList = new List<LCWhereInfo>();
- 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<string> 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<DateTime> 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;
- }
- }
- }
- }
|