FrmTubeRollFileManage.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using CoreFS.CA06;
  10. using Infragistics.Win.UltraWinEditors;
  11. using Core.StlMes.Client.ZGMil.Signature;
  12. using Core.StlMes.Client.ZGMil.Entity;
  13. using Core.Mes.Client.Comm.Control;
  14. using Infragistics.Win.UltraWinGrid;
  15. using Core.Mes.Client.Comm.Tool;
  16. using Core.Mes.Client.Comm.Server;
  17. using CoreFS.SA06;
  18. using System.Collections;
  19. using Infragistics.Win;
  20. using System.IO;
  21. using Core.StlMes.Client.ZGMil.Common;
  22. namespace Core.StlMes.Client.ZGMil
  23. {
  24. public partial class FrmTubeRollFileManage : FrmBase
  25. {
  26. private string departm = "";
  27. UltraComboEditor ucePline = new UltraComboEditor();//产线名称
  28. private string plineCode;
  29. private string[] plineCodes = { };
  30. private string fileName = "";//路径
  31. public FrmTubeRollFileManage()
  32. {
  33. InitializeComponent();
  34. }
  35. private void FrmTubeRollFileManage_Load(object sender, EventArgs e)
  36. {
  37. NativeMethodNew na = new NativeMethodNew(this.ob);
  38. departm = UserInfo.GetDepartment();
  39. plineCode = na.GetPCode(departm);//获取 用户 对应的产线
  40. plineCodes = BaseMethod.GetPlineCode(ValidDataPurviewIds, ob);
  41. //plineCode = na.GetPCodePline(this.ValidDataPurviewIds);//获取产线方法
  42. TubeRoll.InitComboEditorValue(ucePline, "com.steering.mes.signature.FrmTubeRollFileManage.queryPlineCode", "PLINE_CODE", this.ob, false, plineCode);
  43. TubeRoll.BindColumn(ucePline, "PLINE_CODE", this.Controls, this.ultraGrid1, 0);
  44. DoQuery();
  45. }
  46. /// <summary>
  47. /// 重写基类方法
  48. /// </summary>
  49. /// <param name="sender"></param>
  50. /// <param name="ToolbarKey"></param>
  51. public override void ToolBar_Click(object sender, string ToolbarKey)
  52. {
  53. switch (ToolbarKey)
  54. {
  55. case "Query":
  56. DoQuery();
  57. break;
  58. case "Add":
  59. DoAdd();
  60. break;
  61. case "Delete":
  62. DoDelete();
  63. break;
  64. case "Update":
  65. DoUpdare();
  66. break;
  67. case "Close":
  68. this.Close();
  69. break;
  70. }
  71. }
  72. private void DoQuery()
  73. {
  74. DataTable dt = ServerHelper.GetData("com.steering.mes.signature.FrmTubeRollFileManage.queryMinStgnature", new Object[] { plineCodes, this.UserInfo.GetUserName() }, ob);
  75. GridHelper.CopyDataToDatatable(dt, this.dataTable1, true);
  76. foreach (UltraGridRow ugr in ultraGrid1.Rows)
  77. {
  78. ugr.Cells["PLINE_CODE"].Appearance.BackColor =Color.Transparent;
  79. ugr.Cells["PLINE_CODE"].Appearance.BackHatchStyle = BackHatchStyle.Default;
  80. ugr.Cells["PLINE_CODE"].Activation = Infragistics.Win.UltraWinGrid.Activation.ActivateOnly;
  81. //ugr.Cells["COL_GROUP"].Appearance.BackColor = Color.Transparent;
  82. //ugr.Cells["COL_GROUP"].Appearance.BackHatchStyle = BackHatchStyle.Default;
  83. //ugr.Cells["COL_GROUP"].Activation = Infragistics.Win.UltraWinGrid.Activation.ActivateOnly;
  84. }
  85. }
  86. private void DoAdd()
  87. {
  88. ultraGrid1.UpdateData();
  89. ArrayList list1 = new ArrayList();
  90. string pline = "";
  91. string bz = "";
  92. string url = "";
  93. string userName = "";
  94. //int count = 0;
  95. IQueryable<UltraGridRow> uGrid = ultraGrid1.Rows.AsQueryable().Where(" CHK = 'True'");
  96. if (uGrid.Count() == 0)
  97. {
  98. MessageUtil.ShowTips("请选择要新增的数据!");
  99. return;
  100. }
  101. foreach (UltraGridRow ugr in uGrid)
  102. {
  103. //if (Convert.ToBoolean(ugr.Cells["CHK"].Text) == true)
  104. //{
  105. // count += 1;
  106. pline = ugr.Cells["PLINE_CODE"].Value.ToString();
  107. bz = ugr.Cells["COL_GROUP"].Value.ToString();
  108. url = ugr.Cells["URL"].Value.ToString();
  109. userName = ugr.Cells["COL_USER"].Text.Trim();
  110. string gx = "";
  111. if (pline == "") { MessageUtil.ShowTips("产线不能为空!"); return; }
  112. if (bz == "") { MessageUtil.ShowTips("班组不能为空!"); return; }
  113. if (userName == "") { MessageUtil.ShowTips("签名不能为空!"); return; }
  114. if (url == "") { MessageUtil.ShowTips("路径不能为空!"); return; }
  115. if (ugr.Cells["PROCESS_NO"].Text.Trim()!= "") { //MessageUtil.ShowTips("工序名称不能为空!"); return;
  116. gx = ugr.Cells["PROCESS_NO"].Value.ToString();
  117. }
  118. //DataTable dt1 = ServerHelper.GetData("com.steering.mes.signature.FrmTubeRollFileManage.querySameName", new object[] { ugr.Cells["COL_USER"].Value.ToString() }, this.ob);
  119. //if (dt1 != null && dt1.Rows.Count > 0)
  120. //{
  121. // MessageUtil.ShowWarning("系统暂时不允许相同姓名的数据!\n若如确实存在相同名字情况,请暂时将名字区分一下!");
  122. // return;
  123. //}
  124. DataTable dt = ServerHelper.GetData("com.steering.mes.signature.FrmTubeRollFileManage.queryMinStgnature2", new object[] {ugr.Cells["USER_ID"].Text.Trim()}, ob);
  125. if (dt.Rows.Count > 0) { MessageUtil.ShowTips("已存在数据,不能进行此操作!"); return; }
  126. //StreamReader file = new StreamReader(fileName);
  127. //Image file= Image.FromFile(fileName);
  128. //file.to
  129. ArrayList list = new ArrayList();
  130. list.Add(pline);
  131. list.Add(bz);
  132. list.Add(url);
  133. list.Add(userName);
  134. list.Add(ugr.Cells["REMARK"].Text.Trim());
  135. list.Add(gx);
  136. list.Add(FileHelper.FileToArray(ugr.Cells["PIR"].Text.ToString()));
  137. list.Add(ugr.Cells["USERID_GRADE"].Text.ToString());
  138. list1.Add(list);
  139. //}
  140. }
  141. //if (count == 0)
  142. //{
  143. // MessageUtil.ShowTips("请选择要保存的数据!");
  144. // return;
  145. //}
  146. if (MessageUtil.ShowYesNoAndQuestion("是否保存签名?") == System.Windows.Forms.DialogResult.No) return;
  147. CoreClientParam ccp = new CoreClientParam();
  148. ccp.ServerName = "com.steering.mes.signature.FrmTubeRollFileManage";
  149. ccp.MethodName = "addMinStgnature";
  150. ccp.ServerParams = new object[] { list1 };
  151. ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  152. if (ccp.ReturnCode != -1)
  153. {
  154. MessageUtil.ShowTips(ccp.ReturnInfo);
  155. if (ccp.ReturnInfo.Equals("新增成功!"))
  156. {
  157. DoQuery();
  158. }
  159. }
  160. }
  161. private void DoDelete()
  162. {
  163. //int count = 0;
  164. ultraGrid1.UpdateData();
  165. ArrayList pram1 = new ArrayList();
  166. IQueryable<UltraGridRow> uGrid = ultraGrid1.Rows.AsQueryable().Where(" CHK = 'True'");
  167. if (uGrid.Count() == 0)
  168. {
  169. MessageUtil.ShowTips("请选择要删除的数据!");
  170. return;
  171. }
  172. if (MessageUtil.ShowYesNoAndQuestion("是否确认删除签名文件?") == System.Windows.Forms.DialogResult.No)
  173. {
  174. return;
  175. }
  176. foreach (UltraGridRow ugr in uGrid)
  177. {
  178. //if (Convert.ToBoolean(ugr.Cells["CHK"].Text) == true)
  179. //{
  180. // count += 1;
  181. string craftFilePathOld = ugr.Cells["URL"].Text;
  182. if (FileHelper.Delete(craftFilePathOld) == false)
  183. {
  184. MessageUtil.ShowWarning("删除工艺文件失败,请重试!");
  185. return;
  186. }
  187. ArrayList pram = new ArrayList();
  188. pram.Add(ugr.Cells["USER_ID"].Value.ToString());
  189. pram1.Add(pram);
  190. //}
  191. }
  192. //if (count == 0)
  193. //{
  194. // MessageUtil.ShowWarning("请选择一条记录!");
  195. // return;
  196. //}
  197. if (MessageUtil.ShowYesNoAndQuestion("是否删除签名?") == System.Windows.Forms.DialogResult.No) return;
  198. int countinsert = ServerHelper.SetData("com.steering.mes.signature.FrmTubeRollFileManage.deleteMinStgnature", new Object[] { pram1 }, this.ob);
  199. if (countinsert > 0)
  200. {
  201. MessageUtil.ShowTips("删除成功!");
  202. }
  203. else
  204. {
  205. MessageUtil.ShowTips("删除失败!"); return;
  206. }
  207. DoQuery();
  208. }
  209. private void DoUpdare()
  210. {
  211. ultraGrid1.UpdateData();
  212. //int count = 0;
  213. ArrayList pram1 = new ArrayList();
  214. IQueryable<UltraGridRow> uGrid = ultraGrid1.Rows.AsQueryable().Where(" CHK = 'True'");
  215. if (uGrid.Count() == 0)
  216. {
  217. MessageUtil.ShowTips("请选择要修改的数据!");
  218. return;
  219. }
  220. foreach (UltraGridRow ugr in uGrid)
  221. {
  222. //if (Convert.ToBoolean(ugr.Cells["CHK"].Text) == true)
  223. //{
  224. // count += 1;
  225. //string craftFilePathOld = ugr.Cells["URL"].Text;
  226. //if (FileHelper.Delete(craftFilePathOld) == false)
  227. //{
  228. // MessageUtil.ShowWarning("删除工艺文件失败,请重试!");
  229. // return;
  230. //}
  231. //DoUpdateLoad(ugr);
  232. string gx="";
  233. if (ugr.Cells["PROCESS_NO"].Text.Trim() != "") { gx = ugr.Cells["PROCESS_NO"].Value.ToString(); }
  234. ArrayList pram = new ArrayList();
  235. pram.Add(ugr.Cells["COL_USER"].Value.ToString());
  236. pram.Add(ugr.Cells["REMARK"].Text.Trim());
  237. pram.Add(ugr.Cells["URL"].Value.ToString());
  238. pram.Add(gx);
  239. //pram.Add(FileHelper.FileToArray(fileName));
  240. pram.Add(ugr.Cells["USER_ID"].Value.ToString());
  241. pram.Add(ugr.Cells["COL_GROUP"].Value.ToString());
  242. pram.Add(ugr.Cells["USERID_GRADE"].Text.ToString());
  243. //DataTable dt = ServerHelper.GetData("com.steering.mes.signature.FrmTubeRollFileManage.querySameNameByUpdate", new object[] { ugr.Cells["COL_USER"].Value.ToString(), ugr.Cells["USER_ID"].Value.ToString() }, this.ob);
  244. //if (dt != null && dt.Rows.Count > 0)
  245. //{
  246. // MessageUtil.ShowWarning("系统已存在相同名字的数据,系统暂时不支持!如果确实是不同人,请暂时在名字上加以区分!");
  247. // return;
  248. //}
  249. pram1.Add(pram);
  250. //}
  251. }
  252. //if (count == 0)
  253. //{
  254. // MessageUtil.ShowWarning("请选择一条记录!");
  255. // return;
  256. //}
  257. if (MessageUtil.ShowYesNoAndQuestion("是否修改签名记录?") == System.Windows.Forms.DialogResult.No) return;
  258. CoreClientParam ccp = new CoreClientParam();
  259. ccp.ServerName = "com.steering.mes.signature.FrmTubeRollFileManage";
  260. ccp.MethodName = "updateMinStgnature";
  261. ccp.ServerParams = new object[] { pram1 };
  262. ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  263. if (ccp.ReturnCode != -1)
  264. {
  265. MessageUtil.ShowTips(ccp.ReturnInfo);
  266. if (ccp.ReturnInfo.Equals("修改成功!"))
  267. {
  268. DoQuery();
  269. }
  270. }
  271. //int countinsert = ServerHelper.SetData("com.steering.mes.signature.FrmTubeRollFileManage.updateMinStgnature", new Object[] { pram1 }, this.ob);
  272. //if (countinsert > 0)
  273. //{
  274. // MessageUtil.ShowTips("修改成功!");
  275. //}
  276. //else
  277. //{
  278. // MessageUtil.ShowTips("修改失败!"); return;
  279. //}
  280. //DoQuery();
  281. }
  282. ///// <summary>
  283. ///// 修改时新增路径
  284. ///// </summary>
  285. ///// <param name="ugr"></param>
  286. //private void DoUpdateLoad(UltraGridRow row)
  287. //{
  288. // string askSubItem = row.GetValue("PLINE_CODE");
  289. // string bz = row.GetValue("COL_GROUP");
  290. // string filePath = "ZGMil/Signature/" + askSubItem + "/" + bz + "/";
  291. // FormFileDown down = new FormFileDown(this.ob, filePath);
  292. // down.CtrlFileDown1.FilePath = filePath;
  293. // //if (down.CtrlFileDown1.List.Count > 0)
  294. // //{
  295. // // MessageUtil.ShowWarning("只能上传一份文件!");
  296. // // return;
  297. // //}
  298. // List<FileBean> list = new List<FileBean>();
  299. // FileBean bean = new FileBean();
  300. // OpenFileDialog file = new OpenFileDialog();
  301. // file.Multiselect = false;
  302. // DialogResult drStat;
  303. // drStat = file.ShowDialog();
  304. // if (drStat == DialogResult.OK)
  305. // {
  306. // fileName = file.FileName;
  307. // FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
  308. // long s = fs.Length;
  309. // if (s / 1024.0 > 20)
  310. // {
  311. // MessageUtil.ShowTips("图片大于20KB,请重新上传!");
  312. // return;
  313. // }
  314. // string filena = System.IO.Path.GetFileName(fileName);
  315. // DataTable dt = ServerHelper.GetData("com.steering.mes.signature.FrmTubeRollFileManage.queryMinStgnature2", new object[] { row.Cells["USER_ID"].Value.ToString() }, ob);
  316. // if (dt.Rows.Count > 0)
  317. // {
  318. // string seturl = dt.Rows[0]["SIGN_ROUTE"].ToString();
  319. // bool isdelete = Core.Mes.Client.Comm.Server.FileHelper.Delete(seturl);
  320. // //ServerHelper.SetData("com.steering.mes.signature.FrmTubeRollFileManage.updateMinStgnature1", new object[] { filePath + filena, fileName, row.Cells["USER_ID"].Value.ToString() }, ob);
  321. // CoreClientParam ccp = new CoreClientParam();
  322. // ccp.ServerName = "com.steering.mes.signature.FrmTubeRollFileManage";
  323. // ccp.MethodName = "updateMinStgnature1";
  324. // ccp.ServerParams = new object[] { filePath + filena, fileName, row.Cells["USER_ID"].Value.ToString() };
  325. // ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  326. // if (ccp.ReturnCode == -1) { MessageBox.Show("上传失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Question); return; }
  327. // }
  328. // bean = new FileBean();
  329. // bean.setFileName(filena);
  330. // bean.setPathName(filePath);
  331. // bean.setFile(FileHelper.FileToArray(fileName));
  332. // list.Add(bean);
  333. // bool isSuccess = Core.Mes.Client.Comm.Server.FileHelper.Upload(list);
  334. // if (isSuccess)
  335. // {
  336. // MessageBox.Show("上传成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Question);
  337. // }
  338. // else
  339. // {
  340. // MessageBox.Show("上传失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Question);
  341. // }
  342. // ultraGrid1.ActiveCell.Value = filena;
  343. // ultraGrid1.ActiveRow.Cells["URL"].Value = filePath + filena;
  344. // }
  345. //}
  346. /// <summary>
  347. /// 上传
  348. /// </summary>
  349. /// <param name="sender"></param>
  350. /// <param name="e"></param>
  351. private void craftImg_EditorButtonClick(object sender, EditorButtonEventArgs e)
  352. {
  353. UltraGridRow row = ultraGrid1.ActiveRow;
  354. string askSubItem = row.GetValue("PLINE_CODE");
  355. string bz = row.GetValue("COL_GROUP");
  356. string filePath = "ZGMil/Signature/" + askSubItem + "/" + bz + "/";
  357. if (e.Button.Key.ToLower().Equals("select"))
  358. {
  359. FormFileDown down = new FormFileDown(this.ob, row.Cells["URL"].Text);
  360. down.CtrlFileDown1.Button3.Visible = false;
  361. down.ShowDialog();
  362. }
  363. if (e.Button.Key.ToLower().Equals("insert"))
  364. {
  365. if (askSubItem.Equals("") || bz.Equals(""))
  366. {
  367. MessageUtil.ShowTips("没有产线或班组不允许上传!");
  368. return;
  369. }
  370. FormFileDown down = new FormFileDown(this.ob, filePath);
  371. down.CtrlFileDown1.FilePath = filePath;
  372. //if (down.CtrlFileDown1.List.Count > 0)
  373. //{
  374. // MessageUtil.ShowWarning("只能上传一份文件!");
  375. // return;
  376. //}
  377. List<FileBean> list = new List<FileBean>();
  378. FileBean bean = new FileBean();
  379. OpenFileDialog file = new OpenFileDialog();
  380. file.Multiselect = false;
  381. DialogResult drStat;
  382. drStat = file.ShowDialog();
  383. if (drStat == DialogResult.OK)
  384. {
  385. fileName = file.FileName;
  386. FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
  387. long s = fs.Length;
  388. if (s/1024.0>20)
  389. {
  390. MessageUtil.ShowTips("图片大于20KB,请重新上传!");
  391. return;
  392. }
  393. string filena = System.IO.Path.GetFileName(fileName);
  394. DataTable dt = ServerHelper.GetData("com.steering.mes.signature.FrmTubeRollFileManage.queryMinStgnature2", new object[] { row.Cells["USER_ID"].Value.ToString() }, ob);
  395. if (dt.Rows.Count > 0)
  396. {
  397. string seturl = dt.Rows[0]["SIGN_ROUTE"].ToString();
  398. bool isdelete = Core.Mes.Client.Comm.Server.FileHelper.Delete(seturl);
  399. //ServerHelper.SetData("com.steering.mes.signature.FrmTubeRollFileManage.updateMinStgnature1", new object[] { filePath + filena, fileName, row.Cells["USER_ID"].Value.ToString() }, ob);
  400. CoreClientParam ccp = new CoreClientParam();
  401. ccp.ServerName = "com.steering.mes.signature.FrmTubeRollFileManage";
  402. ccp.MethodName = "updateMinStgnature1";
  403. ccp.ServerParams = new object[] { filePath + filena, FileHelper.FileToArray(fileName), row.Cells["USER_ID"].Value.ToString() };
  404. ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  405. if (ccp.ReturnCode == -1) { MessageBox.Show("上传失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Question); return; }
  406. }
  407. bean = new FileBean();
  408. bean.setFileName(filena);
  409. bean.setPathName(filePath);
  410. bean.setFile(FileHelper.FileToArray(fileName));
  411. list.Add(bean);
  412. bool isSuccess = Core.Mes.Client.Comm.Server.FileHelper.Upload(list);
  413. if (isSuccess)
  414. {
  415. MessageBox.Show("上传成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Question);
  416. }
  417. else
  418. {
  419. MessageBox.Show("上传失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Question);
  420. }
  421. ultraGrid1.ActiveCell.Value = filena;
  422. ultraGrid1.ActiveRow.Cells["URL"].Value = filePath + filena;
  423. ultraGrid1.ActiveRow.Cells["PIR"].Value = fileName;
  424. }
  425. }
  426. }
  427. private void ultraGrid1_AfterSelectChange(object sender, AfterSelectChangeEventArgs e)
  428. {
  429. try
  430. {
  431. ultraGrid1.UpdateData();
  432. foreach (UltraGridRow r in ultraGrid1.Rows)
  433. {
  434. r.Cells["CHK"].Value = r.Selected;
  435. }
  436. }
  437. catch { }
  438. }
  439. }
  440. }