YdmBaseClass.cs 17 KB

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