YdmBaseClass.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  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.YdmBase
  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 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.ValueMember = valueMember;
  138. uce.SelectedIndex = -1;
  139. SetComboItemHeight(uce);
  140. }
  141. }
  142. /// <summary>
  143. /// 设置GRID行的颜色
  144. /// </summary>
  145. /// <param name="ultragrid">要设置的GRID</param>
  146. public static void SetGridRowColor(UltraGrid ultragrid)
  147. {
  148. if (ultragrid == null)
  149. return;
  150. foreach (UltraGridRow row in ultragrid.Rows)
  151. {
  152. if (row.Cells["VALIDFLAG"].Value.ToString().ToUpper() != "TRUE" && row.Cells["VALIDFLAG"].Value.ToString()!="有效")
  153. {
  154. row.Appearance.ForeColor = Color.Red;
  155. }
  156. else
  157. {
  158. row.Appearance.ForeColor = Color.Black;
  159. }
  160. if (row.HasChild()&&row.ChildBands[0].Rows.Count > 0) //主从表--子表
  161. {
  162. foreach (UltraGridRow crow in row.ChildBands[0].Rows)
  163. {
  164. if (crow.Cells["VALIDFLAG"].Value.ToString().ToUpper() != "TRUE" && crow.Cells["VALIDFLAG"].Value.ToString() != "有效")
  165. {
  166. crow.Appearance.ForeColor = Color.Red;
  167. }
  168. else
  169. {
  170. crow.Appearance.ForeColor = Color.Black;
  171. }
  172. }
  173. }
  174. }
  175. }
  176. /// <summary>
  177. ///设置GRID不可编辑 不带选择框
  178. /// </summary>
  179. /// <param name="ug">GRID</param>
  180. public static void SetGridActivateOnly(UltraGrid ug)
  181. {
  182. if (ug == null)
  183. return;
  184. foreach (UltraGridRow row in ug.Rows)
  185. {
  186. for (int i = 0; i < row.Cells.Count; i++)
  187. row.Cells[i].Activation = Activation.ActivateOnly;
  188. }
  189. }
  190. /// <summary>
  191. /// 设置UltraComboEditor中的中文和非中文统一高度。
  192. /// </summary>
  193. /// <param name="cmb"></param>
  194. public static void SetComboItemHeight(UltraComboEditor cmb)
  195. {
  196. foreach (ValueListItem item in cmb.Items)
  197. {
  198. if (Regex.IsMatch(item.DisplayText, @"[\u4e00-\u9fa5]+"))
  199. {
  200. item.Appearance.FontData.SizeInPoints = 9.0F;
  201. }
  202. else
  203. {
  204. item.Appearance.FontData.SizeInPoints = 10.5F;
  205. }
  206. }
  207. }
  208. /// <summary>
  209. /// 用于基础信息表的操作后的定位
  210. /// </summary>
  211. /// <param name="ultragrid">要定位的GRID</param>
  212. /// <param name="colName">要定位的列名</param>
  213. /// <param name="keyword">关键字</param>
  214. public static void Postioning(UltraGrid ultragrid ,string colName,string keyword)
  215. {
  216. foreach (UltraGridRow row in ultragrid.Rows)
  217. {
  218. if (row.Cells[colName].Value.ToString() == keyword)
  219. {
  220. row.Activate();
  221. break;
  222. }
  223. }
  224. }
  225. /// <summary>
  226. /// GRID列自适应 除了备注列
  227. /// </summary>
  228. /// <param name="ug">GRID</param>
  229. public static void SetColAutoSizeExceptMemo(UltraGrid ug)
  230. {
  231. UltraGridColumn[] col = new UltraGridColumn[] {ug.DisplayLayout.Bands[0].Columns["MEMO"] };
  232. GridHelper.RefreshAndAutoSizeExceptColumns(ug, col);
  233. }
  234. /// <summary>
  235. /// 过滤主表中没有但从表有的记录
  236. /// </summary>
  237. /// <param name="dt1">主表</param>
  238. /// <param name="dt2">从表</param>
  239. /// <param name="condition">关联主键</param>
  240. public static DataTable FilterTable(DataTable dt1, DataTable dt2, string condition)
  241. {
  242. if (dt1 != null && dt1.Rows.Count > 0 && dt2 != null)
  243. {
  244. for (int i = 0; i < dt2.Rows.Count; i++)
  245. {
  246. string conditionValue = dt2.Rows[i][condition].ToString();
  247. DataRow[] dr = dt1.Select(condition + "='" + conditionValue + "'");
  248. if (dr == null || dr.Length == 0)
  249. dt2.Rows[i].Delete();
  250. }
  251. dt2.AcceptChanges();
  252. return dt2;
  253. }
  254. return null;
  255. }
  256. /// <summary>
  257. /// 将下拉框绑定到GRID列
  258. /// </summary>
  259. /// <param name="uce">下拉框(已经初始化完成)</param>
  260. /// <param name="ColumnName">列名</param>
  261. /// <param name="con">空间集合(每次只需填入this.Controls)</param>
  262. /// <param name="ug">GRID</param>
  263. /// <param name="i">GRID的第几层结构</param>
  264. public static void BindColumn(UltraComboEditor uce, string ColumnName, System.Windows.Forms.Control.ControlCollection con,UltraGrid ug,int i)
  265. {
  266. con.Add(uce);
  267. uce.Visible = false;
  268. ug.DisplayLayout.Bands[i].Columns[ColumnName].EditorComponent = uce;
  269. ug.DisplayLayout.Bands[i].Columns[ColumnName].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDown;
  270. SetComboItemHeight(uce);
  271. }
  272. /// <summary>
  273. /// 绑定生成一个有树结构的下拉菜单
  274. /// </summary>
  275. /// <param name= "dtNodeSets "> 菜单记录数据所在的表 </param>
  276. /// <param name= "strParentColumn "> 表中用于标记父记录的字段 </param>
  277. /// <param name= "strRootValue "> 第一层记录的父记录值(通常设计为0或者-1或者Null)用来表示没有父记录 </param>
  278. /// <param name= "strIndexColumn "> 索引字段,也就是放在DropDownList的Value里面的字段 </param>
  279. /// <param name= "strTextColumn "> 显示文本字段,也就是放在DropDownList的Text里面的字段 </param>
  280. /// <param name= "drpBind "> 需要绑定的DropDownList </param>
  281. /// <param name= "i "> 用来控制缩入量的值,请输入-1 </param>
  282. public static void MakeTree(DataTable dtNodeSets, string strParentColumn, string strRootValue, string strIndexColumn, string strTextColumn, TreeNodeCollection drpBind, int i)
  283. {
  284. //每向下一层,多一个缩入单位
  285. i++;
  286. DataView dvNodeSets = new DataView(dtNodeSets);
  287. string filter = string.IsNullOrEmpty(strRootValue) ? strParentColumn + " is null" : string.Format(strParentColumn + "='{0}'", strRootValue);
  288. dvNodeSets.RowFilter = filter ;
  289. string strPading = " "; //缩入字符
  290. //通过i来控制缩入字符的长度,我这里设定的是一个全角的空格
  291. for (int j = 0; j < i; j++)
  292. strPading += " ";//如果要增加缩入的长度,改成两个全角的空格就可以了
  293. foreach (DataRowView drv in dvNodeSets)
  294. {
  295. TreeNode tnNode = new TreeNode();
  296. tnNode = new TreeNode();//建立一个新节点(学名叫:一个实例)
  297. tnNode.Tag = drv[strIndexColumn].ToString();//节点的Value值,一般为数据库的id值
  298. tnNode.Text = drv[strTextColumn].ToString();//节点的Text,节点的文本显示
  299. if (!string.IsNullOrEmpty(drv["PID"].ToString()))
  300. {
  301. tnNode.ToolTipText = drv["PID"].ToString();
  302. }
  303. else
  304. {
  305. tnNode.ImageIndex = 0;
  306. }
  307. //ListItem li = new ListItem(strPading + "|- " + drv[strTextColumn].ToString(), drv[strIndexColumn].ToString());
  308. drpBind.Add(tnNode);
  309. MakeTree(dtNodeSets, strParentColumn, drv[strIndexColumn].ToString(), strIndexColumn, strTextColumn, tnNode.Nodes, i);
  310. }
  311. //递归结束,要回到上一层,所以缩入量减少一个单位
  312. i--;
  313. }
  314. /// <summary>
  315. /// 时间计算返回月
  316. /// </summary>
  317. /// <param name="startTime">开始时间</param>
  318. /// <param name="endTime">结束时间</param>
  319. /// <returns></returns>
  320. public static int getMonth(DateTime startTime, DateTime endTime)
  321. {
  322. int year1 = startTime.Year;
  323. int year2 = endTime.Year;
  324. int month1 = startTime.Month;
  325. int month2 = endTime.Month;
  326. int months = 12 * (year2 - year1) + (month2 - month1);
  327. return months;
  328. }
  329. /// <summary>
  330. /// 判断是否有中文
  331. /// </summary>
  332. /// <param name="words">待判断的字符串</param>
  333. /// <returns></returns>
  334. public static bool WordsIScn(string words)
  335. {
  336. Regex rx = new Regex(@"[\\u4e00-\\u9fa5]");
  337. return rx.IsMatch(words.Trim(),0);
  338. }
  339. /// <summary>
  340. /// 初始化科室下拉框
  341. /// </summary>
  342. /// <param name="uce"></param>
  343. /// <param name="customInfo"></param>
  344. /// <param name="validDataPurviewIds"></param>
  345. /// <param name="ob"></param>
  346. public static void InitSection(UltraComboEditor uce, String[] validDataPurviewIds, OpeBase ob)
  347. {
  348. DataTable dt = ServerHelper.GetData("com.steering.pss.ydm.base.WarehousePermissions.getBaseSection", new object[] { validDataPurviewIds }, ob);
  349. if (dt != null && dt.Rows.Count > 0)
  350. {
  351. uce.DataSource = dt;
  352. uce.DisplayMember = "DEPARTNAME";
  353. uce.ValueMember = "DEPARTID";
  354. }
  355. else
  356. {
  357. uce.DataSource = null;
  358. }
  359. }
  360. /// <summary>
  361. /// 销售片区数据权限
  362. /// </summary>
  363. /// <param name="validDataPurviewIds"></param>
  364. /// <param name="ob"></param>
  365. /// <returns></returns>
  366. public static string[] Section(String[] validDataPurviewIds, OpeBase ob)
  367. {
  368. DataTable dt = ServerHelper.GetData("com.steering.pss.ydm.base.WarehousePermissions.getSection", new object[] { validDataPurviewIds }, ob);
  369. if (dt != null && dt.Rows.Count > 0)
  370. {
  371. string[] section = new string[dt.Rows.Count];
  372. for (int i = 0; i < dt.Rows.Count; i++)
  373. {
  374. section[i] = dt.Rows[i]["SALE_AREA_NO"].ToString();
  375. }
  376. return section;
  377. }
  378. else
  379. {
  380. return new string[1] { "" };
  381. }
  382. }
  383. /// <summary>
  384. /// 科室数据权限(1)基础信息
  385. /// </summary>
  386. /// <param name="validDataPurviewIds"></param>
  387. /// <param name="ob"></param>
  388. /// <returns></returns>
  389. public static string[] BaseSection(String[] validDataPurviewIds, OpeBase ob)
  390. {
  391. DataTable dt = ServerHelper.GetData("com.steering.pss.ydm.base.WarehousePermissions.getBaseSection", new object[] { validDataPurviewIds }, ob);
  392. if (dt != null && dt.Rows.Count > 0)
  393. {
  394. string[] section = new string[dt.Rows.Count];
  395. for (int i = 0; i < dt.Rows.Count; i++)
  396. {
  397. section[i] = dt.Rows[i]["DEPARTID"].ToString();
  398. }
  399. return section;
  400. }
  401. else
  402. {
  403. return new string[1] { "" };
  404. }
  405. }
  406. }
  407. }