CraftFileLv2Ctrl.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using Core.StlMes.Client.SaleOrder.BLL;
  10. using CoreFS.CA06;
  11. using Core.Mes.Client.Comm.Tool;
  12. using CoreFS.SA06;
  13. using Infragistics.Win.UltraWinGrid;
  14. using Core.StlMes.Client.Qcm;
  15. using Core.Mes.Client.Comm.Server;
  16. using Core.Mes.Client.Comm.Control;
  17. using System.IO;
  18. namespace Core.StlMes.Client.SaleOrder.Control
  19. {
  20. public partial class CraftFileLv2Ctrl : UserControl
  21. {
  22. private CraftFileLv2BLL _craftFileLv2BLL;
  23. private CraftOrdDesignBLL _craftOrdDesignBLL;
  24. private OpeBase _ob;
  25. private string _msc = "";
  26. private string _processCode = "";
  27. public CraftFileLv2Ctrl(System.Windows.Forms.Control container, OpeBase ob, string msc, string processCode)
  28. {
  29. InitializeComponent();
  30. _ob = ob;
  31. _craftFileLv2BLL = new CraftFileLv2BLL(ob);
  32. _craftOrdDesignBLL = new CraftOrdDesignBLL(ob);
  33. _msc = msc;
  34. _processCode = processCode;
  35. container.Controls.Add(this);
  36. this.Dock = DockStyle.Fill;
  37. EntityHelper.ShowGridCaption<CraftFileLv2Entity>(ultraGrid1.DisplayLayout.Bands[0]);
  38. BindComboBox();
  39. }
  40. private void BindComboBox()
  41. {
  42. DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.CoreControlPointBasics.GetProcess", null, _ob);
  43. ultraComboEditor1.DataSource = dt;
  44. ultraComboEditor1.DisplayMember = "PROCESS_DESC";
  45. ultraComboEditor1.ValueMember = "PROCESS_CODE";
  46. }
  47. private string _craftNoLv2 = "";
  48. private string _validflag = "";
  49. public void Query(string craftNoLv2, string validflag)
  50. {
  51. _craftNoLv2 = craftNoLv2;
  52. _validflag = validflag;
  53. List<CraftFileLv2Entity> sourceData = _craftFileLv2BLL.Query(
  54. craftNoLv2, validflag, _msc, _processCode);
  55. craftFileLv2EntityBindingSource.DataSource = sourceData;
  56. foreach (var row in ultraGrid1.Rows)
  57. {
  58. GridEdite(row);
  59. if (row.GetValue("VALIDFLAG") == "无效")
  60. {
  61. row.Appearance.ForeColor = Color.Red;
  62. }
  63. }
  64. }
  65. public void QueryAll()
  66. {
  67. _isFilter = true;
  68. craftFileLv2EntityBindingSource.DataSource = _craftFileLv2BLL.QueryAll();
  69. }
  70. private bool _isFilter = false;
  71. public void FilterCraftFileLv2(string designKey, string processCode, string craftNoLv2, string validflag,
  72. string craftFileLv2Pks, string craftNo, string msc)
  73. {
  74. ultraGrid1.BeginUpdate();
  75. ultraTextEditor2.ButtonsRight.Clear();
  76. this.craftFileLv2EntityBindingSource.DataSource = _craftFileLv2BLL.FilterCraftFileLv2(
  77. designKey, processCode, craftNoLv2, validflag, craftNo, msc);
  78. string[] craftFileLv2PkAry = craftFileLv2Pks.Split(';');
  79. foreach (var row in ultraGrid1.Rows)
  80. {
  81. if (craftFileLv2PkAry.Contains(row.GetValue("Pk")))
  82. {
  83. row.Cells["Chk"].Value = true;
  84. }
  85. }
  86. GridHelper.SetExcludeColumnsActive(ultraGrid1.DisplayLayout.Bands[0], "Chk");
  87. _isFilter = true;
  88. ultraGrid1.EndUpdate();
  89. ultraGrid1.UpdateData();
  90. }
  91. public void Save(CraftFileLv2CCtrl fileLv2CCtrl)
  92. {
  93. ultraGrid1.UpdateData();
  94. var rows = ultraGrid1.Rows.AsQueryable().Where(a => a.GetValue("Chk") == "True");
  95. int chkCnt = rows.Count() +
  96. fileLv2CCtrl.UltraGrid1.Rows.AsQueryable().Where(a => a.GetValue("Chk") == "True").Count();
  97. if (chkCnt == 0)
  98. {
  99. MessageUtil.ShowWarning("请选择记录保存!");
  100. return;
  101. }
  102. var parms = new List<CraftFileLv2Entity>();
  103. string pk = "";
  104. foreach (var row in rows)
  105. {
  106. var craftFileLv2 = EntityHelper.CopyEntity<CraftFileLv2Entity>(row.ListObject);
  107. if (craftFileLv2.ProcessCode == "")
  108. {
  109. MessageUtil.ShowWarning("选择适用工序!");
  110. row.SetCellActive("ProcessCode");
  111. return;
  112. }
  113. //if (craftFileLv2.CraftPath == "")
  114. //{
  115. // MessageUtil.ShowWarning("请上传二级工艺文件!");
  116. // row.SetCellActive("CraftPath");
  117. // return;
  118. //}
  119. craftFileLv2.CreateName = CoreUserInfo.UserInfo.GetUserName();
  120. craftFileLv2.UpdateName = CoreUserInfo.UserInfo.GetUserName();
  121. craftFileLv2.ProcessDesc = row.GetText("ProcessCode");
  122. if (craftFileLv2.Msc == "")
  123. {
  124. craftFileLv2.Msc = _msc;
  125. }
  126. parms.Add(craftFileLv2);
  127. pk = craftFileLv2.Pk;
  128. }
  129. var fileLv2CParms = fileLv2CCtrl.GetSaveParms();
  130. if (fileLv2CParms == null) return;
  131. if (MessageUtil.ShowYesNoAndQuestion("是否确认保存?") == DialogResult.No)
  132. {
  133. return;
  134. }
  135. string[] results = (string[])_craftFileLv2BLL.Save(parms, fileLv2CParms);
  136. MessageUtil.ShowTips("保存成功!");
  137. Relocate(results[0]);
  138. fileLv2CCtrl.Relocate(results[1]);
  139. return;
  140. }
  141. public void UpdateValidflag(string flag, CraftFileLv2CCtrl fileLv2CCtrl)
  142. {
  143. ultraGrid1.UpdateData();
  144. var rows = ultraGrid1.Rows.AsQueryable().Where(a => a.GetValue("Chk") == "True");
  145. int chkCnt = rows.Count() + fileLv2CCtrl.UltraGrid1.Rows.Where(a=>a.GetValue("Chk") == "True").Count();
  146. if (chkCnt == 0)
  147. {
  148. MessageUtil.ShowWarning("请选择记录!");
  149. return;
  150. }
  151. var parms = new List<CraftFileLv2Entity>();
  152. string pk = "";
  153. foreach (var row in rows)
  154. {
  155. var craftFileLv2 = EntityHelper.CopyEntity<CraftFileLv2Entity>(row.ListObject);
  156. craftFileLv2.CreateName = CoreUserInfo.UserInfo.GetUserName();
  157. craftFileLv2.UpdateName = CoreUserInfo.UserInfo.GetUserName();
  158. parms.Add(craftFileLv2);
  159. pk = craftFileLv2.Pk;
  160. }
  161. string tip = flag == "1" ? "恢复" : "作废";
  162. if (MessageUtil.ShowYesNoAndQuestion("是否确认" + tip + "记录?") == DialogResult.No) return;
  163. var craftFileLv2CParms = fileLv2CCtrl.GetUpdateValidflagParms();
  164. _craftFileLv2BLL.UpdateValidflag(parms, craftFileLv2CParms, flag);
  165. MessageUtil.ShowTips(tip + "成功!");
  166. Relocate(pk);
  167. if (craftFileLv2CParms.Count > 0)
  168. {
  169. fileLv2CCtrl.Relocate(craftFileLv2CParms[0].Pk);
  170. }
  171. }
  172. private void Relocate(string pk)
  173. {
  174. Query(_craftNoLv2, _validflag);
  175. var row = ultraGrid1.Rows.AsQueryable().Where(a => a.GetValue("Pk") == pk).FirstOrDefault();
  176. if (row != null)
  177. {
  178. row.Activate();
  179. }
  180. }
  181. private void GridEdite(UltraGridRow row)
  182. {
  183. if (row.GetValue("Chk") == "True")
  184. {
  185. foreach (UltraGridCell cell in row.Cells)
  186. {
  187. if (cell.Column.CellActivation == Activation.AllowEdit)
  188. {
  189. cell.Activation = Activation.AllowEdit;
  190. }
  191. }
  192. }
  193. else
  194. {
  195. foreach (UltraGridCell cell in row.Cells)
  196. {
  197. if (cell.Column.Key == "Chk") continue;
  198. if (cell.Column.CellActivation == Activation.AllowEdit)
  199. {
  200. cell.Activation = Activation.ActivateOnly;
  201. }
  202. }
  203. }
  204. ultraGrid1.UpdateData();
  205. }
  206. private void ultraGrid1_CellChange(object sender, CellEventArgs e)
  207. {
  208. e.Cell.Row.Update();
  209. if (e.Cell.Column.Key == "ProcessCode")
  210. {
  211. e.Cell.Row.SetValue("ProcessDesc", e.Cell.Text);
  212. e.Cell.Row.SetValue("PlineName", "");
  213. e.Cell.Row.SetValue("PlineCode", "");
  214. }
  215. if (!_isFilter)
  216. {
  217. if (e.Cell.Column.Key == "Chk")
  218. {
  219. GridEdite(e.Cell.Row);
  220. UltraGridRow chkRow = e.Cell.Row;
  221. foreach (UltraGridRow row in ultraGrid1.Rows)
  222. {
  223. if (row.Cells["Chk"].Value.ToString() == "True" && row != chkRow)
  224. {
  225. row.Cells["Chk"].Value = false;
  226. row.Update();
  227. }
  228. }
  229. }
  230. }
  231. }
  232. private void ultraTextEditor1_EditorButtonClick(object sender, Infragistics.Win.UltraWinEditors.EditorButtonEventArgs e)
  233. {
  234. ComBasePlineChoice plineChoice;
  235. try
  236. {
  237. this.Cursor = Cursors.WaitCursor;
  238. string plineCodes = ultraGrid1.ActiveRow.GetValue("PlineCode");
  239. string processCode = ultraGrid1.ActiveRow.GetValue("ProcessCode");
  240. plineChoice = new ComBasePlineChoice(plineCodes, processCode, _ob);
  241. }
  242. finally
  243. {
  244. this.Cursor = Cursors.Default;
  245. }
  246. if (plineChoice.ShowDialog() == DialogResult.OK)
  247. {
  248. ultraGrid1.ActiveRow.SetValue("PlineName", plineChoice.PlineNames);
  249. ultraGrid1.ActiveRow.SetValue("PlineCode", plineChoice.PlineCodes);
  250. }
  251. }
  252. private void ultraTextEditor2_EditorButtonClick(object sender, Infragistics.Win.UltraWinEditors.EditorButtonEventArgs e)
  253. {
  254. CraftFileLv2Entity fileLv2Entity = (CraftFileLv2Entity)ultraGrid1.ActiveRow.ListObject;
  255. if (fileLv2Entity.Validflag == "")
  256. {
  257. MessageUtil.ShowWarning("请先保存记录,然后再上传工艺文件!");
  258. return;
  259. }
  260. string path = "Qcm/CraftLv2/" + fileLv2Entity.Pk + "/";
  261. List<CraftFileLv2Entity> updateParms = new List<CraftFileLv2Entity>();
  262. if (e.Button.Key == "Query")
  263. {
  264. FormFileDown down = new FormFileDown(_ob, path);
  265. if (_isFilter)
  266. {
  267. down.DeleteButton.Visible = false;
  268. }
  269. down.ShowDialog();
  270. if (down.CtrlFileDown1.List.Count == 0)
  271. {
  272. CraftFileLv2Entity parm = (CraftFileLv2Entity)ultraGrid1.ActiveRow.ListObject;
  273. parm.CraftNoLv2 = "";
  274. parm.CraftPath = "";
  275. updateParms.Add(parm);
  276. _craftFileLv2BLL.Update(updateParms);
  277. ultraGrid1.ActiveRow.Cells["CraftPath"].Value = "";
  278. }
  279. }
  280. if (e.Button.Key == "Upload")
  281. {
  282. var serverFileList = FileHelper.Download(path);
  283. if (serverFileList.Count > 0)
  284. {
  285. MessageUtil.ShowWarning("该记录已存在一份文件,请删除后再重新上传!");
  286. return;
  287. }
  288. List<FileBean> list = new List<FileBean>();
  289. FileBean bean = new FileBean();
  290. OpenFileDialog file = new OpenFileDialog();
  291. file.Multiselect = false;
  292. DialogResult drStat;
  293. drStat = file.ShowDialog();
  294. if (drStat == DialogResult.OK)
  295. {
  296. string filePath = file.FileName;
  297. string fileName = System.IO.Path.GetFileName(filePath);
  298. CraftFileLv2Entity parm = (CraftFileLv2Entity)ultraGrid1.ActiveRow.ListObject;
  299. int exist = _craftFileLv2BLL.IsExistCraftLv2(fileName.Remove(fileName.LastIndexOf('.')), parm.Pk);
  300. if (exist > 0)
  301. {
  302. MessageUtil.ShowWarning("上传失败,系统已存在相同的工艺文件号!");
  303. return;
  304. }
  305. bean = new FileBean();
  306. bean.setFileName(fileName);
  307. bean.setPathName(path);
  308. bean.setFile(FileHelper.FileToArray(filePath));
  309. list.Add(bean);
  310. bool isSuccess = Core.Mes.Client.Comm.Server.FileHelper.Upload(list);
  311. if (isSuccess)
  312. {
  313. parm.UpdateName = CoreUserInfo.UserInfo.GetUserName();
  314. parm.CraftNoLv2 = fileName.Remove(fileName.LastIndexOf('.'));
  315. parm.CraftPath = path + fileName;
  316. updateParms.Add(parm);
  317. _craftFileLv2BLL.Update(updateParms);
  318. ultraGrid1.ActiveRow.Cells["CraftPath"].Value = path + fileName;
  319. MessageUtil.ShowTips("上传成功!");
  320. Relocate(parm.Pk);
  321. }
  322. else
  323. {
  324. MessageUtil.ShowTips("上传失败,请重试!");
  325. }
  326. }
  327. }
  328. }
  329. private void ultraGrid1_AfterRowInsert(object sender, RowEventArgs e)
  330. {
  331. e.Row.SetValue("Msc", _msc);
  332. e.Row.SetValue("ProcessCode", _processCode);
  333. }
  334. }
  335. }