YdmBaseClass.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. using System;
  2. using Core.Mes.Client.Comm.Server;
  3. using Infragistics.Win.UltraWinEditors;
  4. using CoreFS.CA06;
  5. using System.Data;
  6. using Infragistics.Win.UltraWinGrid;
  7. using System.Drawing;
  8. using Infragistics.Win;
  9. using System.Text.RegularExpressions;
  10. using Core.Mes.Client.Comm.Control;
  11. using System.Collections.Generic;
  12. using System.ComponentModel;
  13. using System.Windows.Forms;
  14. namespace Core.StlMes.Client.Qcm.Control
  15. {
  16. /// <summary>
  17. /// 用于提供物流管理的一些公共的方法,如初始化下拉框
  18. /// </summary>
  19. /// Author WHB 2015-01-19
  20. public class YdmBaseClass
  21. {
  22. /// <summary>
  23. /// 初始化下拉框(增强型)
  24. /// </summary>
  25. /// <param name="uce">下拉框</param>
  26. /// <param name="methodId">请求的服务</param>
  27. /// <param name="valueMember">值成员</param>
  28. /// <param name="textMember">显示成员</param>
  29. /// <param name="ob">ob对象</param>
  30. /// <param name="isEmpty">是否添加空行</param>
  31. public static void InitComboEditorNew(UltraComboEditor uce, string methodId, string valueMember, string textMember,OpeBase ob, bool isEmpty)
  32. {
  33. InitComboEditor(uce, methodId, valueMember, ob, isEmpty);
  34. uce.DisplayMember = textMember;
  35. }
  36. /// <summary>
  37. /// 初始化下拉框
  38. /// </summary>
  39. /// <param name="uce">下拉框</param>
  40. /// <param name="methodId">请求的服务</param>
  41. /// <param name="valueMember">值成员</param>
  42. /// <param name="ob">ob对象</param>
  43. /// <param name="isEmpty">是否有空行</param>
  44. public static void InitComboEditor(UltraComboEditor uce,string methodId,string valueMember,OpeBase ob,bool isEmpty)
  45. {
  46. DataTable dt = ServerHelper.GetData(methodId,null,ob);
  47. if (dt != null && dt.Rows.Count > 0)
  48. {
  49. if (isEmpty)
  50. {
  51. Object[] obj = new Object[] { "", "" };
  52. DataRow dr = dt.NewRow();
  53. dr.ItemArray=obj;
  54. dt.Rows.InsertAt( dr, 0);
  55. }
  56. uce.DataSource = dt;
  57. uce.ValueMember = valueMember;
  58. SetComboItemHeight(uce);
  59. }
  60. }
  61. /// <summary>
  62. /// 初始化下拉框
  63. /// </summary>
  64. /// <param name="uce">下拉框</param>
  65. /// <param name="methodId">请求的服务</param>
  66. /// <param name="valueMember">值成员</param>
  67. /// <param name="ob">ob对象</param>
  68. /// <param name="isEmpty">是否有空行</param>
  69. public static void InitComboEditor1(UltraComboEditor uce, string methodId, string valueMember, OpeBase ob, bool isEmpty)
  70. {
  71. DataTable dt = ServerHelper.GetData(methodId, null, ob);
  72. if (dt != null && dt.Rows.Count > 0)
  73. {
  74. if (isEmpty)
  75. {
  76. Object[] obj = new Object[] { "", "" };
  77. DataRow dr = dt.NewRow();
  78. dr.ItemArray = obj;
  79. dt.Rows.InsertAt(dr, 0);
  80. }
  81. uce.DataSource = dt;
  82. uce.ValueMember = valueMember;
  83. SetComboItemHeight(uce);
  84. }
  85. }
  86. /// <summary>
  87. /// 初始化下拉框
  88. /// </summary>
  89. /// <param name="uce">下拉框</param>
  90. /// <param name="methodId">请求的服务</param>
  91. /// <param name="valueMember">值成员</param>
  92. /// <param name="ob">ob对象</param>
  93. /// <param name="isEmpty">是否有空行</param>
  94. public static void InitComboEditorBelong(UltraComboEditor uce, string methodId, string valueMember, OpeBase ob, bool isEmpty)
  95. {
  96. DataTable dt = ServerHelper.GetData(methodId, null, ob);
  97. if (dt != null && dt.Rows.Count > 0)
  98. {
  99. dt.Rows.Add(new object[]{"销售公司","100101"});
  100. dt.Rows.Add(new object[]{"国贸公司","100102" });
  101. dt.Rows.Add(new object[] { "钢贸公司", "100103" });
  102. dt.Rows.Add(new object[] { "制造部", "002001001" });
  103. if (isEmpty)
  104. {
  105. Object[] obj = new Object[] { "", "" };
  106. DataRow dr = dt.NewRow();
  107. dr.ItemArray = obj;
  108. dt.Rows.InsertAt(dr, 0);
  109. }
  110. uce.DataSource = dt;
  111. uce.ValueMember = valueMember;
  112. SetComboItemHeight(uce);
  113. }
  114. }
  115. /// <summary>
  116. /// 初始化下拉框 --带参数的
  117. /// </summary>
  118. /// <param name="uce"></param>
  119. /// <param name="methodId"></param>
  120. /// <param name="valueMember"></param>
  121. /// <param name="ob"></param>
  122. /// <param name="isEmpty"></param>
  123. /// <param name="obj"></param>
  124. public static void InitComboEditorWithParm(UltraComboEditor uce, string methodId, string DisplayMember, string valueMember, OpeBase ob, bool isEmpty,Object []parm)
  125. {
  126. DataTable dt = ServerHelper.GetData(methodId, parm, ob);
  127. if (dt != null && dt.Rows.Count > 0)
  128. {
  129. if (isEmpty)
  130. {
  131. Object[] obj = new Object[] { "", "" };
  132. DataRow dr = dt.NewRow();
  133. dr.ItemArray = obj;
  134. dt.Rows.InsertAt(dr, 0);
  135. }
  136. uce.DataSource = dt;
  137. uce.DisplayMember = DisplayMember;
  138. uce.ValueMember = valueMember;
  139. uce.SelectedIndex = -1;
  140. SetComboItemHeight(uce);
  141. }
  142. }
  143. /// <summary>
  144. /// 设置GRID行的颜色
  145. /// </summary>
  146. /// <param name="ultragrid">要设置的GRID</param>
  147. public static void SetGridRowColor(UltraGrid ultragrid)
  148. {
  149. if (ultragrid == null)
  150. return;
  151. foreach (UltraGridRow row in ultragrid.Rows)
  152. {
  153. if (row.Cells["VALIDFLAG"].Value.ToString().ToUpper() != "TRUE" && row.Cells["VALIDFLAG"].Value.ToString()!="有效")
  154. {
  155. row.Appearance.ForeColor = Color.Red;
  156. }
  157. else
  158. {
  159. row.Appearance.ForeColor = Color.Black;
  160. }
  161. if (row.HasChild()&&row.ChildBands[0].Rows.Count > 0) //主从表--子表
  162. {
  163. foreach (UltraGridRow crow in row.ChildBands[0].Rows)
  164. {
  165. if (crow.Cells["VALIDFLAG"].Value.ToString().ToUpper() != "TRUE" && crow.Cells["VALIDFLAG"].Value.ToString() != "有效")
  166. {
  167. crow.Appearance.ForeColor = Color.Red;
  168. }
  169. else
  170. {
  171. crow.Appearance.ForeColor = Color.Black;
  172. }
  173. }
  174. }
  175. }
  176. }
  177. /// <summary>
  178. ///设置GRID不可编辑 不带选择框
  179. /// </summary>
  180. /// <param name="ug">GRID</param>
  181. public static void SetGridActivateOnly(UltraGrid ug)
  182. {
  183. if (ug == null)
  184. return;
  185. foreach (UltraGridRow row in ug.Rows)
  186. {
  187. for (int i = 0; i < row.Cells.Count; i++)
  188. row.Cells[i].Activation = Activation.ActivateOnly;
  189. }
  190. }
  191. /// <summary>
  192. /// 设置UltraComboEditor中的中文和非中文统一高度。
  193. /// </summary>
  194. /// <param name="cmb"></param>
  195. public static void SetComboItemHeight(UltraComboEditor cmb)
  196. {
  197. foreach (ValueListItem item in cmb.Items)
  198. {
  199. if (Regex.IsMatch(item.DisplayText, @"[\u4e00-\u9fa5]+"))
  200. {
  201. item.Appearance.FontData.SizeInPoints = 9.0F;
  202. }
  203. else
  204. {
  205. item.Appearance.FontData.SizeInPoints = 10.5F;
  206. }
  207. }
  208. }
  209. /// <summary>
  210. /// 用于基础信息表的操作后的定位
  211. /// </summary>
  212. /// <param name="ultragrid">要定位的GRID</param>
  213. /// <param name="colName">要定位的列名</param>
  214. /// <param name="keyword">关键字</param>
  215. public static void Postioning(UltraGrid ultragrid ,string colName,string keyword)
  216. {
  217. foreach (UltraGridRow row in ultragrid.Rows)
  218. {
  219. if (row.Cells[colName].Value.ToString() == keyword)
  220. {
  221. row.Activate();
  222. break;
  223. }
  224. }
  225. }
  226. /// <summary>
  227. /// GRID列自适应 除了备注列
  228. /// </summary>
  229. /// <param name="ug">GRID</param>
  230. public static void SetColAutoSizeExceptMemo(UltraGrid ug)
  231. {
  232. UltraGridColumn[] col = new UltraGridColumn[] {ug.DisplayLayout.Bands[0].Columns["MEMO"] };
  233. GridHelper.RefreshAndAutoSizeExceptColumns(ug, col);
  234. }
  235. /// <summary>
  236. /// 过滤主表中没有但从表有的记录
  237. /// </summary>
  238. /// <param name="dt1">主表</param>
  239. /// <param name="dt2">从表</param>
  240. /// <param name="condition">关联主键</param>
  241. public static DataTable FilterTable(DataTable dt1, DataTable dt2, string condition)
  242. {
  243. if (dt1 != null && dt1.Rows.Count > 0 && dt2 != null)
  244. {
  245. for (int i = 0; i < dt2.Rows.Count; i++)
  246. {
  247. string conditionValue = dt2.Rows[i][condition].ToString();
  248. DataRow[] dr = dt1.Select(condition + "='" + conditionValue + "'");
  249. if (dr == null || dr.Length == 0)
  250. dt2.Rows[i].Delete();
  251. }
  252. dt2.AcceptChanges();
  253. return dt2;
  254. }
  255. return null;
  256. }
  257. /// <summary>
  258. /// 将下拉框绑定到GRID列
  259. /// </summary>
  260. /// <param name="uce">下拉框(已经初始化完成)</param>
  261. /// <param name="ColumnName">列名</param>
  262. /// <param name="con">空间集合(每次只需填入this.Controls)</param>
  263. /// <param name="ug">GRID</param>
  264. /// <param name="i">GRID的第几层结构</param>
  265. public static void BindColumn(UltraComboEditor uce, string ColumnName, System.Windows.Forms.Control.ControlCollection con,UltraGrid ug,int i)
  266. {
  267. con.Add(uce);
  268. uce.Visible = false;
  269. ug.DisplayLayout.Bands[i].Columns[ColumnName].EditorComponent = uce;
  270. ug.DisplayLayout.Bands[i].Columns[ColumnName].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDown;
  271. SetComboItemHeight(uce);
  272. }
  273. /// <summary>
  274. /// 绑定生成一个有树结构的下拉菜单
  275. /// </summary>
  276. /// <param name= "dtNodeSets "> 菜单记录数据所在的表 </param>
  277. /// <param name= "strParentColumn "> 表中用于标记父记录的字段 </param>
  278. /// <param name= "strRootValue "> 第一层记录的父记录值(通常设计为0或者-1或者Null)用来表示没有父记录 </param>
  279. /// <param name= "strIndexColumn "> 索引字段,也就是放在DropDownList的Value里面的字段 </param>
  280. /// <param name= "strTextColumn "> 显示文本字段,也就是放在DropDownList的Text里面的字段 </param>
  281. /// <param name= "drpBind "> 需要绑定的DropDownList </param>
  282. /// <param name= "i "> 用来控制缩入量的值,请输入-1 </param>
  283. public static void MakeTree(DataTable dtNodeSets, string strParentColumn, string strRootValue, string strIndexColumn, string strTextColumn, TreeNodeCollection drpBind, int i)
  284. {
  285. //每向下一层,多一个缩入单位
  286. i++;
  287. DataView dvNodeSets = new DataView(dtNodeSets);
  288. string filter = string.IsNullOrEmpty(strRootValue) ? strParentColumn + " is null" : string.Format(strParentColumn + "='{0}'", strRootValue);
  289. dvNodeSets.RowFilter = filter ;
  290. string strPading = " "; //缩入字符
  291. //通过i来控制缩入字符的长度,我这里设定的是一个全角的空格
  292. for (int j = 0; j < i; j++)
  293. strPading += " ";//如果要增加缩入的长度,改成两个全角的空格就可以了
  294. foreach (DataRowView drv in dvNodeSets)
  295. {
  296. TreeNode tnNode = new TreeNode();
  297. tnNode = new TreeNode();//建立一个新节点(学名叫:一个实例)
  298. tnNode.Tag = drv[strIndexColumn].ToString();//节点的Value值,一般为数据库的id值
  299. tnNode.Text = drv[strTextColumn].ToString();//节点的Text,节点的文本显示
  300. if (!string.IsNullOrEmpty(drv["PID"].ToString()))
  301. {
  302. tnNode.ToolTipText = drv["PID"].ToString();
  303. }
  304. else
  305. {
  306. tnNode.ImageIndex = 0;
  307. }
  308. //ListItem li = new ListItem(strPading + "|- " + drv[strTextColumn].ToString(), drv[strIndexColumn].ToString());
  309. drpBind.Add(tnNode);
  310. MakeTree(dtNodeSets, strParentColumn, drv[strIndexColumn].ToString(), strIndexColumn, strTextColumn, tnNode.Nodes, i);
  311. }
  312. //递归结束,要回到上一层,所以缩入量减少一个单位
  313. i--;
  314. }
  315. /// <summary>
  316. /// 时间计算返回月
  317. /// </summary>
  318. /// <param name="startTime">开始时间</param>
  319. /// <param name="endTime">结束时间</param>
  320. /// <returns></returns>
  321. public static int getMonth(DateTime startTime, DateTime endTime)
  322. {
  323. int year1 = startTime.Year;
  324. int year2 = endTime.Year;
  325. int month1 = startTime.Month;
  326. int month2 = endTime.Month;
  327. int months = 12 * (year2 - year1) + (month2 - month1);
  328. return months;
  329. }
  330. /// <summary>
  331. /// 判断是否有中文
  332. /// </summary>
  333. /// <param name="words">待判断的字符串</param>
  334. /// <returns></returns>
  335. public static bool WordsIScn(string words)
  336. {
  337. Regex rx = new Regex(@"[\\u4e00-\\u9fa5]");
  338. return rx.IsMatch(words.Trim(),0);
  339. }
  340. /// <summary>
  341. /// 初始化科室下拉框
  342. /// </summary>
  343. /// <param name="uce"></param>
  344. /// <param name="customInfo"></param>
  345. /// <param name="validDataPurviewIds"></param>
  346. /// <param name="ob"></param>
  347. public static void InitSection(UltraComboEditor uce, String[] validDataPurviewIds, OpeBase ob)
  348. {
  349. DataTable dt = ServerHelper.GetData("com.steering.pss.ydm.base.WarehousePermissions.getBaseSection", new object[] { validDataPurviewIds }, ob);
  350. if (dt != null && dt.Rows.Count > 0)
  351. {
  352. uce.DataSource = dt;
  353. uce.DisplayMember = "DEPARTNAME";
  354. uce.ValueMember = "DEPARTID";
  355. }
  356. else
  357. {
  358. uce.DataSource = null;
  359. }
  360. }
  361. /// <summary>
  362. /// 销售片区数据权限
  363. /// </summary>
  364. /// <param name="validDataPurviewIds"></param>
  365. /// <param name="ob"></param>
  366. /// <returns></returns>
  367. public static string[] Section(String[] validDataPurviewIds, OpeBase ob)
  368. {
  369. DataTable dt = ServerHelper.GetData("com.steering.pss.ydm.base.WarehousePermissions.getSection", new object[] { validDataPurviewIds }, ob);
  370. if (dt != null && dt.Rows.Count > 0)
  371. {
  372. string[] section = new string[dt.Rows.Count];
  373. for (int i = 0; i < dt.Rows.Count; i++)
  374. {
  375. section[i] = dt.Rows[i]["SALE_AREA_NO"].ToString();
  376. }
  377. return section;
  378. }
  379. else
  380. {
  381. return new string[1] { "" };
  382. }
  383. }
  384. /// <summary>
  385. /// 科室数据权限(1)基础信息
  386. /// </summary>
  387. /// <param name="validDataPurviewIds"></param>
  388. /// <param name="ob"></param>
  389. /// <returns></returns>
  390. public static string[] BaseSection(String[] validDataPurviewIds, OpeBase ob)
  391. {
  392. DataTable dt = ServerHelper.GetData("com.steering.pss.ydm.base.WarehousePermissions.getBaseSection", new object[] { validDataPurviewIds }, ob);
  393. if (dt != null && dt.Rows.Count > 0)
  394. {
  395. string[] section = new string[dt.Rows.Count];
  396. for (int i = 0; i < dt.Rows.Count; i++)
  397. {
  398. section[i] = dt.Rows[i]["DEPARTID"].ToString();
  399. }
  400. return section;
  401. }
  402. else
  403. {
  404. return new string[1] { "" };
  405. }
  406. }
  407. }
  408. }