QcmZbsTemplateHeadCtrl.cs 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. using Core.Mes.Client.Comm.Control;
  2. using Core.Mes.Client.Comm.Server;
  3. using Core.Mes.Client.Comm.Tool;
  4. using Core.StlMes.Client.Qcm.BLL;
  5. using Core.StlMes.Client.Qcm.model;
  6. using CoreFS.CA06;
  7. using CoreFS.SA06;
  8. using Infragistics.Win.UltraWinGrid;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Data;
  12. using System.Drawing;
  13. using System.Linq;
  14. using System.Windows.Forms;
  15. namespace Core.StlMes.Client.Qcm.Control
  16. {
  17. public partial class QcmZbsTemplateHeadCtrl : UserControl
  18. {
  19. private QcmZbsTemplateHeadBLL _zbsTemplateHeadBLL;
  20. private OpeBase ob;
  21. public QcmZbsTemplateHeadCtrl(System.Windows.Forms.Control container, OpeBase ob)
  22. {
  23. InitializeComponent();
  24. this.ob = ob;
  25. _zbsTemplateHeadBLL = new QcmZbsTemplateHeadBLL(ob);
  26. container.Controls.Add(this);
  27. this.Dock = DockStyle.Fill;
  28. EntityHelper.ShowGridCaption<QcmZbsTemplateHeadEntity>(ultraGrid1.DisplayLayout.Bands[0]);
  29. }
  30. private string _decription = "";
  31. private string _validflag = "";
  32. public void Query(string decription, string validflag)
  33. {
  34. _decription = decription;
  35. _validflag = validflag;
  36. qcmZbsTemplateHeadEntityBindingSource.DataSource = _zbsTemplateHeadBLL.Query(decription, validflag);
  37. foreach (var row in ultraGrid1.Rows)
  38. {
  39. GridEdite(row);
  40. }
  41. }
  42. public void Relocate(string tbh, string decription, string validflag)
  43. {
  44. Query(decription, validflag);
  45. var row = ultraGrid1.Rows.Where(a => a.GetValue("tbh") == tbh).FirstOrDefault();
  46. if (row != null)
  47. {
  48. row.Activate();
  49. }
  50. }
  51. public void Save()
  52. {
  53. var rows = ultraGrid1.Rows.Where(a => a.GetValue("Chk") == "True");
  54. if (rows.Count() == 0)
  55. {
  56. MessageUtil.ShowWarning("请选择记录!");
  57. return;
  58. }
  59. List<QcmZbsTemplateHeadEntity> parms = new List<QcmZbsTemplateHeadEntity>();
  60. string tbh = "";
  61. foreach (var row in rows)
  62. {
  63. QcmZbsTemplateHeadEntity zbsTemplateHead = EntityHelper.CopyEntity<QcmZbsTemplateHeadEntity>(row.ListObject);
  64. if (zbsTemplateHead.Description == "")
  65. {
  66. MessageUtil.ShowWarning("请输入模板描述!");
  67. return;
  68. }
  69. if (zbsTemplateHead.SheetCount == null)
  70. {
  71. MessageUtil.ShowWarning("请输入模板SHEET页数!");
  72. return;
  73. }
  74. zbsTemplateHead.CreateName = CoreUserInfo.UserInfo.GetUserName();
  75. zbsTemplateHead.UpdateName = CoreUserInfo.UserInfo.GetUserName();
  76. parms.Add(zbsTemplateHead);
  77. tbh = zbsTemplateHead.Tbh;
  78. }
  79. if (MessageUtil.ShowYesNoAndQuestion("是否确认保存?") == DialogResult.No) return;
  80. _zbsTemplateHeadBLL.Save(parms);
  81. MessageUtil.ShowTips("保存成功!");
  82. Relocate(tbh, _decription, _validflag);
  83. }
  84. public void UpdateValidflag(string validflag)
  85. {
  86. var rows = ultraGrid1.Rows.Where(a => a.GetValue("Chk") == "True");
  87. if (rows.Count() == 0)
  88. {
  89. MessageUtil.ShowWarning("请选择记录!");
  90. return;
  91. }
  92. List<QcmZbsTemplateHeadEntity> parms = new List<QcmZbsTemplateHeadEntity>();
  93. string tbh = "";
  94. foreach (var row in rows)
  95. {
  96. QcmZbsTemplateHeadEntity zbsTemplateHead = EntityHelper.CopyEntity<QcmZbsTemplateHeadEntity>(row.ListObject);
  97. zbsTemplateHead.DeleteName = CoreUserInfo.UserInfo.GetUserName();
  98. parms.Add(zbsTemplateHead);
  99. tbh = zbsTemplateHead.Tbh;
  100. }
  101. if (MessageUtil.ShowYesNoAndQuestion(string.Format("是否确认{0}?",
  102. validflag == "0" ? "作废" : "恢复")) == DialogResult.No) return;
  103. _zbsTemplateHeadBLL.UpdateValidflag(parms, validflag);
  104. MessageUtil.ShowTips(string.Format("{0}成功!", validflag == "0" ? "作废" : "恢复"));
  105. Relocate(tbh, _decription, _validflag);
  106. }
  107. private void ultraGrid1_CellChange(object sender, Infragistics.Win.UltraWinGrid.CellEventArgs e)
  108. {
  109. ultraGrid1.UpdateData();
  110. GridEdite(e.Cell.Row);
  111. }
  112. private void GridEdite(UltraGridRow row)
  113. {
  114. if (row.GetValue("Chk") == "True")
  115. {
  116. foreach (UltraGridCell cell in row.Cells)
  117. {
  118. if (cell.Column.CellActivation == Activation.AllowEdit)
  119. {
  120. cell.Activation = Activation.AllowEdit;
  121. }
  122. }
  123. }
  124. else
  125. {
  126. foreach (UltraGridCell cell in row.Cells)
  127. {
  128. if (cell.Column.Key == "Chk") continue;
  129. if (cell.Column.CellActivation == Activation.AllowEdit)
  130. {
  131. cell.Activation = Activation.ActivateOnly;
  132. }
  133. }
  134. }
  135. }
  136. private void ultraGrid1_InitializeRow(object sender, InitializeRowEventArgs e)
  137. {
  138. if (e.Row.GetValue("Validflag") == "无效")
  139. {
  140. e.Row.Appearance.ForeColor = Color.Red;
  141. }
  142. else
  143. {
  144. e.Row.Appearance.ForeColor = Color.Black;
  145. }
  146. }
  147. private void ultraTextEditor1_EditorButtonClick(object sender, Infragistics.Win.UltraWinEditors.EditorButtonEventArgs e)
  148. {
  149. QcmZbsTemplateHeadEntity zbsTemplateEntity = EntityHelper.CopyEntity<QcmZbsTemplateHeadEntity>(ultraGrid1.ActiveRow.ListObject);
  150. if (zbsTemplateEntity.Validflag == "")
  151. {
  152. MessageUtil.ShowWarning("请先保存记录,然后再上传图片!");
  153. return;
  154. }
  155. string path = "Qcm/ZbsTemplate/" + zbsTemplateEntity.Tbh + "/";
  156. if (e.Button.Key == "View")
  157. {
  158. FormFileDown down = new FormFileDown(ob, path);
  159. //if (flag == "试样关系")
  160. //{
  161. // down.DeleteButton.Visible = false;
  162. //}
  163. down.ShowDialog();
  164. if (down.CtrlFileDown1.List.Count == 0 && zbsTemplateEntity.Xls != "")
  165. {
  166. zbsTemplateEntity.UpdateName = CoreUserInfo.UserInfo.GetUserName();
  167. zbsTemplateEntity.Xls = "";
  168. _zbsTemplateHeadBLL.UpdateXls(zbsTemplateEntity);
  169. Relocate(zbsTemplateEntity.Tbh, _decription, _validflag);
  170. }
  171. }
  172. if (e.Button.Key == "Upload")
  173. {
  174. var serverFileList = FileHelper.Download(path);
  175. if (serverFileList.Count > 0)
  176. {
  177. MessageUtil.ShowWarning("该记录已存在一份文件,请删除后再重新上传!");
  178. return;
  179. }
  180. List<FileBean> list = new List<FileBean>();
  181. FileBean bean = new FileBean();
  182. OpenFileDialog file = new OpenFileDialog();
  183. file.Multiselect = false;
  184. DialogResult drStat;
  185. drStat = file.ShowDialog();
  186. if (drStat == DialogResult.OK)
  187. {
  188. string filePath = file.FileName;
  189. string fileName = System.IO.Path.GetFileName(filePath);
  190. bean = new FileBean();
  191. bean.setFileName(fileName);
  192. bean.setPathName(path);
  193. bean.setFile(FileHelper.FileToArray(filePath));
  194. list.Add(bean);
  195. zbsTemplateEntity.UpdateName = CoreUserInfo.UserInfo.GetUserName();
  196. zbsTemplateEntity.Xls = path + fileName;
  197. _zbsTemplateHeadBLL.UpdateXls(zbsTemplateEntity);
  198. bool isSuccess = Core.Mes.Client.Comm.Server.FileHelper.Upload(list);
  199. if (isSuccess)
  200. {
  201. MessageUtil.ShowTips("上传成功!");
  202. Relocate(zbsTemplateEntity.Tbh, _decription, _validflag);
  203. }
  204. else
  205. {
  206. MessageUtil.ShowTips("上传失败,请重试!");
  207. }
  208. }
  209. }
  210. }
  211. }
  212. }