FrmSignature.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  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.Mes.Client.Comm.Control;
  12. using Infragistics.Win.UltraWinGrid;
  13. using Core.Mes.Client.Comm.Tool;
  14. using Core.Mes.Client.Comm.Server;
  15. using CoreFS.SA06;
  16. using System.Collections;
  17. using Infragistics.Win;
  18. using System.IO;
  19. using Pur.Entity;
  20. using com.hnshituo.pur.vo;
  21. using Pur.configure;
  22. using Pur.PublicTools;
  23. using Pur.Pop_upWindow;
  24. namespace Pur
  25. {
  26. public partial class FrmSignature : FrmPmsBase
  27. {
  28. public FrmSignature()
  29. {
  30. InitializeComponent();
  31. }
  32. private void FrmSignature_Load(object sender, EventArgs e)
  33. {
  34. DoQuery("");
  35. GridHelper.SetExcludeColumnsActive(ultraGrid1.DisplayLayout.Bands[0], new String[] { "ownername", "CERTPATH", "CERTDESC", "CHK" });
  36. }
  37. /// <summary>
  38. /// 重写基类方法
  39. /// </summary>
  40. /// <param name="sender"></param>
  41. /// <param name="ToolbarKey"></param>
  42. public override void ToolBar_Click(object sender, string ToolbarKey)
  43. {
  44. switch (ToolbarKey)
  45. {
  46. case "Query":
  47. DoQuery("");
  48. break;
  49. case "Add":
  50. DoSave();
  51. break;
  52. case "Delete":
  53. DoDelete();
  54. break;
  55. case "Close":
  56. this.Close();
  57. break;
  58. }
  59. }
  60. private void DoQuery(String strID)
  61. {
  62. Signature sg = new Signature();
  63. sg.Validflag = "1";
  64. DataTable dt = this.execute<DataTable>("com.hnshituo.pur.configure.service.SignatureService", "get_Signature", new object[] { sg});
  65. GridHelper.CopyDataToDatatable(dt, this.dataTable1, true);
  66. foreach (UltraGridRow ugr in ultraGrid1.Rows)
  67. {
  68. ugr.Cells["orgId"].Appearance.BackColor =Color.Transparent;
  69. ugr.Cells["orgId"].Appearance.BackHatchStyle = BackHatchStyle.Default;
  70. ugr.Cells["orgId"].Activation = Infragistics.Win.UltraWinGrid.Activation.ActivateOnly;
  71. }
  72. if (String.IsNullOrEmpty(strID))
  73. {
  74. publicPms.doActiveSelRow(ultraGrid1,"id",strID);
  75. }
  76. }
  77. private void DoSave()
  78. {
  79. ultraGrid1.UpdateData();
  80. ArrayList list = new ArrayList();
  81. string strid = "";
  82. //int count = 0;
  83. IQueryable<UltraGridRow> uGrid = ultraGrid1.Rows.AsQueryable().Where(" CHK = 'True'");
  84. if (uGrid.Count() == 0)
  85. {
  86. MessageUtil.ShowTips("请选择要新增的数据!");
  87. return;
  88. }
  89. foreach (UltraGridRow ugr in uGrid)
  90. {
  91. String id = ugr.Cells["id"].Value.ToString().Trim();
  92. strid = id;
  93. String orgId = ugr.Cells["orgId"].Value.ToString().Trim();
  94. String orgName = ugr.Cells["orgName"].Value.ToString().Trim();
  95. String ownerUserid = ugr.Cells["ownerUserid"].Value.ToString().Trim();
  96. String ownerName = ugr.Cells["ownerName"].Value.ToString().Trim();
  97. String certDesc = ugr.Cells["certDesc"].Value.ToString().Trim();
  98. if (orgId == "") { MessageUtil.ShowTips("所属部门不能为空!"); return; }
  99. if (orgName == "") { MessageUtil.ShowTips("所属部门不能为空!"); return; }
  100. if (ownerUserid == "") { MessageUtil.ShowTips("所属人不能为空!"); return; }
  101. if (ownerName == "") { MessageUtil.ShowTips("所属人不能为空!"); return; }
  102. Signature sg = new Signature();
  103. sg.Validflag = "1";
  104. sg.OwnerUserid = ownerUserid;
  105. int count = this.execute<int>("com.hnshituo.pur.configure.service.SignatureService", "count", new object[] { sg });
  106. if (count <= 0) { MessageUtil.ShowTips("不存在用户:" + ownerName + "签名数据信息,不能进行此操作,请先上传签名文件!"); return; }
  107. Signature sig = new Signature();
  108. sig.Id = id;
  109. sig.CertDesc = certDesc;
  110. sig.OrgId = orgId;
  111. sig.OrgName = orgName;
  112. sig.OwnerName = ownerName;
  113. sig.OwnerUserid = ownerUserid;
  114. sig.UpdateUserid = UserInfo.GetUserID();
  115. sig.UpdateName = UserInfo.GetUserName();
  116. sig.UpdateTime = DateTime.Now;
  117. list.Add(sig);
  118. //}
  119. }
  120. if (list.Count <= 0)
  121. {
  122. MessageUtil.ShowTips("请选择要新增的数据!");
  123. return;
  124. }
  125. if (MessageUtil.ShowYesNoAndQuestion("是否保存签名?") == System.Windows.Forms.DialogResult.No) return;
  126. CoreResult crt = this.execute<CoreResult>("com.hnshituo.pur.configure.service.SignatureService", "do_Save", new object[] { list });
  127. if (crt.Resultcode != 0)
  128. {
  129. MessageUtil.ShowTips("保存失败:"+crt.Resultmsg);
  130. return;
  131. }
  132. MessageUtil.ShowTips("操作成功");
  133. DoQuery(strid);
  134. }
  135. private void DoDelete()
  136. {
  137. ultraGrid1.UpdateData();
  138. ArrayList pram = new ArrayList();
  139. IQueryable<UltraGridRow> uGrid = ultraGrid1.Rows.AsQueryable().Where(" CHK = 'True'");
  140. if (uGrid.Count() == 0)
  141. {
  142. MessageUtil.ShowTips("请选择要删除的数据!");
  143. return;
  144. }
  145. if (MessageUtil.ShowYesNoAndQuestion("是否确认删除签名文件?") != DialogResult.Yes)
  146. {
  147. return;
  148. }
  149. foreach (UltraGridRow ugr in uGrid)
  150. {
  151. string craftFilePathOld = ugr.Cells["certPathOld"].Text;
  152. if (FileHelper.Delete(craftFilePathOld) == false)
  153. {
  154. MessageUtil.ShowWarning("删除签名文件失败,请重试!");
  155. return;
  156. }
  157. pram.Add(ugr.Cells["id"].Value.ToString());
  158. }
  159. if (MessageUtil.ShowYesNoAndQuestion("是否删除签名?")!= DialogResult.Yes) return;
  160. CoreResult crt = this.execute<CoreResult>("com.hnshituo.pur.configure.service.SignatureService", "do_Delete", new object[] { pram });
  161. if (crt.Resultcode !=0)
  162. {
  163. MessageUtil.ShowTips("删除成功!");
  164. }
  165. else
  166. {
  167. MessageUtil.ShowTips("删除失败:"+crt.Resultmsg); return;
  168. }
  169. DoQuery("");
  170. }
  171. /// <summary>
  172. /// 上传
  173. /// </summary>
  174. /// <param name="sender"></param>
  175. /// <param name="e"></param>
  176. private void craftImg_EditorButtonClick(object sender, EditorButtonEventArgs e)
  177. {
  178. UltraGridRow ugr = ultraGrid1.ActiveRow;
  179. string ownerid = ugr.GetValue("OWNERUSERID");
  180. string id = ugr.GetValue("id");
  181. String orgId = ugr.Cells["orgId"].Value.ToString().Trim();
  182. String orgName = ugr.Cells["orgName"].Value.ToString().Trim();
  183. String ownerUserid = ugr.Cells["ownerUserid"].Value.ToString().Trim();
  184. String ownerName = ugr.Cells["ownerName"].Value.ToString().Trim();
  185. String certPath = ugr.Cells["certPath"].Value.ToString().Trim();
  186. String certPathOld = ugr.Cells["certPathOld"].Value.ToString().Trim();
  187. String certDesc = ugr.Cells["certDesc"].Value.ToString().Trim();
  188. //String filePathOld = "PMS/Signature/" + ownerid + "/";
  189. if (e.Button.Key.ToLower().Equals("select"))
  190. {
  191. FrmPopFileShow down = new FrmPopFileShow(this.ob, certPathOld);
  192. down.DeleteButton.Visible = false;
  193. down.ShowDialog();
  194. }
  195. if (e.Button.Key.ToLower().Equals("insert"))
  196. {
  197. String fileName = "";
  198. String filena = "";
  199. if (String.IsNullOrEmpty(ownerid))
  200. {
  201. MessageUtil.ShowTips("没有所属人员id不允许上传,请先选择人员信息!");
  202. return;
  203. }
  204. OpenFileDialog file = new OpenFileDialog();
  205. file.Multiselect = false;
  206. DialogResult drStat;
  207. drStat = file.ShowDialog();
  208. if (drStat == DialogResult.OK)
  209. {
  210. fileName = file.FileName;
  211. FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
  212. long s = fs.Length;
  213. if (s / 1024.0 > 20)
  214. {
  215. MessageUtil.ShowTips("图片大于20KB,请重新上传!");
  216. return;
  217. }
  218. String filePathlocal = System.IO.Path.GetFullPath(fileName);
  219. filena = System.IO.Path.GetFileName(fileName);
  220. }
  221. if (ultraGrid1.ActiveRow == null)
  222. {
  223. MessageUtil.ShowTips("未选择签名项");
  224. return;
  225. }
  226. if (String.IsNullOrEmpty(filena) || String.IsNullOrEmpty(fileName))
  227. {
  228. MessageUtil.ShowTips("请选择待上传文件");
  229. return;
  230. }
  231. Signature sat = new Signature();
  232. sat.OwnerUserid = ownerid;
  233. String filePathNew = "Pms/Signature/" + ownerid + "/";
  234. sat.CertPath = filena;
  235. sat.CertPathOld = filePathNew + filena;
  236. sat.Id = id;
  237. sat.CertDesc = certDesc;
  238. sat.OrgId = orgId;
  239. sat.OrgName = orgName;
  240. sat.OwnerName = ownerName;
  241. sat.OwnerUserid = ownerUserid;
  242. sat.Image = FileHelper.FileToArray(fileName);
  243. sat.CreateUserid = UserInfo.GetUserID();
  244. sat.CreateName = UserInfo.GetUserName();
  245. sat.CreateTime = DateTime.Now;
  246. sat.Validflag = "1";
  247. if (GetCraftFileCraftNoCnt(filena, ownerid) > 0)
  248. {
  249. MessageUtil.ShowTips("已存在该签名文件:" + filena);
  250. return;
  251. }
  252. List<FileBean> list = new List<FileBean>();
  253. FileBean bean = new FileBean();
  254. bean = new FileBean();
  255. bean.setFileName(filena);
  256. bean.setPathName(filePathNew);
  257. bean.setFile(FileHelper.FileToArray(fileName));
  258. list.Add(bean);
  259. bool isSuccess = Core.Mes.Client.Comm.Server.FileHelper.Upload(list);
  260. if (isSuccess)
  261. {
  262. CoreResult crt = new CoreResult();
  263. //开始写数据库
  264. if (String.IsNullOrEmpty(id))
  265. {
  266. crt = this.execute<CoreResult>("com.hnshituo.pur.configure.service.SignatureService", "do_Insert", new object[] { sat });
  267. }
  268. else
  269. {
  270. crt = this.execute<CoreResult>("com.hnshituo.pur.configure.service.SignatureService", "do_Update", new object[] { sat });
  271. }
  272. if (crt.Resultcode != 0)
  273. {
  274. MessageUtil.ShowTips("上传失败:" + crt.Resultmsg);
  275. }
  276. else
  277. {
  278. MessageUtil.ShowTips("上传成功");
  279. DoQuery(crt.Resultmsg);
  280. }
  281. }
  282. else
  283. {
  284. MessageBox.Show("上传失败");
  285. }
  286. }
  287. }
  288. /// <summary>
  289. /// 判断是否之前已提交相同的文件
  290. /// </summary>
  291. /// <param name="craftNo"></param>
  292. /// <returns></returns>
  293. private int GetCraftFileCraftNoCnt(string CERT_PATH, string OwnerUserid)
  294. {
  295. Signature sat = new Signature();
  296. sat.CertPath = CERT_PATH;
  297. sat.OwnerUserid = OwnerUserid;
  298. sat.Validflag = "1";
  299. int dt = this.execute<int>("com.hnshituo.pur.configure.service.SignatureService", "count", new object[] { sat });
  300. return dt;
  301. }
  302. private void ultraGrid1_AfterSelectChange(object sender, AfterSelectChangeEventArgs e)
  303. {
  304. try
  305. {
  306. ultraGrid1.UpdateData();
  307. foreach (UltraGridRow r in ultraGrid1.Rows)
  308. {
  309. r.Cells["CHK"].Value = r.Selected;
  310. }
  311. }
  312. catch { }
  313. }
  314. private void txt_selectMan_EditorButtonClick(object sender, EditorButtonEventArgs e)
  315. {
  316. SetectManByDept frm = new SetectManByDept(this.ob);
  317. frm.ShowDialog();
  318. if (frm.strTips == "1")
  319. {
  320. String strdeptId = frm.StrDeptId;
  321. String strDeptName = frm.StrDeptName;
  322. String strUserName = frm.StrUserName;
  323. String strUserId = frm.StrUserID;
  324. if (ultraGrid1.ActiveRow == null)
  325. {
  326. return;
  327. }
  328. else
  329. {
  330. UltraGridRow row = ultraGrid1.ActiveRow;
  331. row.Cells["orgId"].Value = strdeptId;
  332. row.Cells["orgName"].Value = strDeptName;
  333. row.Cells["ownername"].Value = strUserName;
  334. row.Cells["ownerUserid"].Value = strUserId;
  335. }
  336. }
  337. }
  338. }
  339. }