ComBaseSplineCtrl.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  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.UltraWinEditors;
  9. using Infragistics.Win.UltraWinGrid;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Data;
  13. using System.Drawing;
  14. using System.Linq;
  15. using System.Windows.Forms;
  16. using Infragistics.Win;
  17. namespace Core.StlMes.Client.Qcm.Control
  18. {
  19. public partial class ComBaseSplineCtrl : UserControl
  20. {
  21. private OpeBase _ob;
  22. private ComBaseSplineBLL _splineBLL;
  23. private UltraComboEditor _cmb;
  24. private string flag = "";
  25. public string Flag
  26. {
  27. get { return flag; }
  28. set { flag = value; }
  29. }
  30. //查询条件
  31. string _phyNameMin = "";
  32. string _sampleStyle = "";
  33. string _validflag = "";
  34. string _seamArea = "";
  35. public ComBaseSplineCtrl(System.Windows.Forms.Control container, OpeBase ob)
  36. {
  37. InitializeComponent();
  38. _ob = ob;
  39. _splineBLL = new ComBaseSplineBLL(ob);
  40. container.Controls.Add(this);
  41. this.Dock = DockStyle.Fill;
  42. this.BringToFront();
  43. EntityHelper.ShowGridCaption<ComBaseSplineEntity>(ultraGrid1.DisplayLayout.Bands[0]);
  44. LoadData();
  45. }
  46. private void LoadData()
  47. {
  48. _cmb = new UltraComboEditor();
  49. _cmb.Visible = false;
  50. _cmb.DataSource = _splineBLL.GetComBasePhyC();
  51. _cmb.DisplayMember = "PHY_TYPE";
  52. _cmb.ValueMember = "PHY_CODE";
  53. this.Controls.Add(_cmb);
  54. ultraGrid1.DisplayLayout.Bands[0].Columns["PhyCodeMin"].EditorComponent = _cmb;
  55. ultraGrid1.DisplayLayout.Bands[0].Columns["PhyCodeMin"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownList;
  56. ClsBaseInfo.FillComBaseInfo(ultraComboEditor2, "4081", _ob, false);
  57. ValueList list = new ValueList();
  58. ValueListItem[] items = new ValueListItem[] {
  59. new ValueListItem("0", "天管"),
  60. new ValueListItem("1", "天淮"),
  61. };
  62. list.ValueListItems.AddRange(items);
  63. ultraGrid1.DisplayLayout.Bands[0].Columns["SeamArea"].ValueList = list;
  64. }
  65. public void Query(string phyNameMin, string sampleStyle, string validflag,string seamArea)
  66. {
  67. _phyNameMin = phyNameMin;
  68. _sampleStyle = sampleStyle;
  69. _validflag = validflag;
  70. _seamArea = seamArea;
  71. comBaseSplineEntityBindingSource.DataSource = _splineBLL.Query(phyNameMin, sampleStyle, validflag, seamArea);
  72. foreach (var row in ultraGrid1.Rows)
  73. {
  74. GridEdite(row);
  75. }
  76. }
  77. public void Query2(string phyCodeMin, string itemCodeF, string itemCodeC,
  78. string ordLnPk, string itemCodeW)
  79. {
  80. comBaseSplineEntityBindingSource.DataSource = _splineBLL.Query2(
  81. phyCodeMin, itemCodeF, itemCodeC, ordLnPk, itemCodeW);
  82. foreach (var row in ultraGrid1.Rows)
  83. {
  84. GridEdite(row);
  85. }
  86. }
  87. public void QueryNk(string phyCodeMin, string stdCode, string stdCodeTest, string itemCodeF)
  88. {
  89. comBaseSplineEntityBindingSource.DataSource = _splineBLL.QueryNk(
  90. phyCodeMin, stdCode, stdCodeTest, itemCodeF);
  91. foreach (var row in ultraGrid1.Rows)
  92. {
  93. GridEdite(row);
  94. }
  95. }
  96. public bool Save(List<ComBaseSplineCEntity2> list)
  97. {
  98. ultraGrid1.UpdateData();
  99. var rows = ultraGrid1.Rows.AsQueryable().Where(a => a.GetValue("Chk") == "True");
  100. //var rows = queryable.Select(a => EntityHelper.CopyEntity<ComBaseSplineEntity>(a.ListObject)).ToList();
  101. List<ComBaseSplineEntity2> splineEntitys = new List<ComBaseSplineEntity2>();
  102. foreach (var row in rows)
  103. {
  104. ComBaseSplineEntity2 splineEntity = EntityHelper.CopyEntity<ComBaseSplineEntity2>(row.ListObject);
  105. if (splineEntity.SplineNo == "")
  106. {
  107. MessageUtil.ShowWarning("请输入试样编号!");
  108. row.Cells["SplineNo"].Activate();
  109. return false;
  110. }
  111. if (splineEntity.PhyCodeMin == "")
  112. {
  113. MessageUtil.ShowWarning("请输入取样码!");
  114. row.Cells["PhyCodeMin"].Activate();
  115. return false;
  116. }
  117. else if (splineEntity.Length == null)
  118. {
  119. MessageUtil.ShowWarning("请输入毛样长!");
  120. row.Cells["Length"].Activate();
  121. return false;
  122. }
  123. else if (splineEntity.SizeDesc == "")
  124. {
  125. MessageUtil.ShowWarning("请输入名义规格!");
  126. row.Cells["SizeDesc"].Activate();
  127. return false;
  128. }
  129. else if (splineEntity.SampleStyle == "")
  130. {
  131. MessageUtil.ShowWarning("请输入毛样类型!");
  132. row.Cells["SampleStyle"].Activate();
  133. return false;
  134. }
  135. else if (splineEntity.SampleStyle == "408101" && splineEntity.Width == null)
  136. {
  137. MessageUtil.ShowWarning("请输入毛样宽度!");
  138. row.Cells["Width"].Activate();
  139. return false;
  140. }
  141. else if (splineEntity.SeamArea == "")
  142. {
  143. MessageUtil.ShowWarning("请输入所属区域!");
  144. row.Cells["SeamArea"].Activate();
  145. return false;
  146. }
  147. else if (_splineBLL.IsRepeat(splineEntity))
  148. {
  149. MessageUtil.ShowWarning("数据重复,请检查后再保存!\r\n唯一性限制:试样组+试验方向+试验尺寸+名义规格");
  150. row.Activate();
  151. return false;
  152. }
  153. splineEntity.SplineRStds = new List<ComBaseSplineRStdEntity>();
  154. var stdCodeS = row.GetValue("StdCodeS").Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
  155. var stdNameS = row.GetValue("StdNameS").Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
  156. for (int i = 0; i < stdCodeS.Length; i++)
  157. {
  158. splineEntity.SplineRStds.Add(new ComBaseSplineRStdEntity()
  159. {
  160. StdCode = stdCodeS[i],
  161. StdName = stdNameS[i],
  162. CreateName = CoreUserInfo.UserInfo.GetUserName(),
  163. UpdateName = CoreUserInfo.UserInfo.GetUserName()
  164. });
  165. }
  166. splineEntity.CreateName = CoreUserInfo.UserInfo.GetUserName();
  167. splineEntity.UpdateName = CoreUserInfo.UserInfo.GetUserName();
  168. splineEntitys.Add(splineEntity);
  169. }
  170. if (MessageUtil.ShowYesNoAndQuestion("是否确认保存?") == DialogResult.No)
  171. {
  172. return false;
  173. }
  174. _splineBLL.Save(splineEntitys, list);
  175. if (rows.FirstOrDefault() != null)
  176. Relocate(rows.FirstOrDefault().GetValue("eic"));
  177. return true;
  178. }
  179. private void Relocate(string eic)
  180. {
  181. Query(_phyNameMin, _sampleStyle, _validflag,_seamArea);
  182. var row = ultraGrid1.Rows.AsQueryable().Where(a => a.GetValue("eic") == eic).FirstOrDefault();
  183. if (row != null)
  184. {
  185. row.Activate();
  186. }
  187. }
  188. public void UpdateValidflag(string flag)
  189. {
  190. ultraGrid1.UpdateData();
  191. var rows = ultraGrid1.Rows.AsQueryable().Where(a => a.GetValue("Chk") == "True")
  192. .Select(a => EntityHelper.CopyEntity<ComBaseSplineEntity>(a.ListObject)).ToList();
  193. foreach (var row in rows)
  194. {
  195. row.DeleteName = CoreUserInfo.UserInfo.GetUserName();
  196. row.UpdateName = CoreUserInfo.UserInfo.GetUserName();
  197. }
  198. _splineBLL.UpdateValidflag(rows, flag);
  199. }
  200. private void ultraGrid1_CellChange(object sender, Infragistics.Win.UltraWinGrid.CellEventArgs e)
  201. {
  202. e.Cell.Row.Update();
  203. if (e.Cell.Column.Key == "PhyCodeMin")
  204. {
  205. e.Cell.Row.Cells["PhyNameMin"].Value = e.Cell.Text;
  206. }
  207. else if (e.Cell.Column.Key == "Chk")
  208. {
  209. GridEdite(e.Cell.Row);
  210. }
  211. else if (e.Cell.Column.Key == "SampleStyle")
  212. {
  213. if (e.Cell.Value.ToString() == "408102")
  214. {
  215. e.Cell.Row.Cells["Width"].Value = null;
  216. e.Cell.Row.Cells["Width"].Activation = Activation.ActivateOnly;
  217. }
  218. else
  219. {
  220. e.Cell.Row.Cells["Width"].Activation = Activation.AllowEdit;
  221. }
  222. }
  223. if (e.Cell.Column.Key == "Chk")
  224. {
  225. UltraGridRow chkRow = e.Cell.Row;
  226. foreach (UltraGridRow row in ultraGrid1.Rows)
  227. {
  228. if (row.Cells["Chk"].Value.ToString() == "True" && row != chkRow)
  229. {
  230. row.Cells["Chk"].Value = "False";
  231. row.Update();
  232. }
  233. }
  234. }
  235. if (e.Cell.Column.Key == "Chk3")
  236. {
  237. UltraGridRow chkRow = e.Cell.Row;
  238. foreach (UltraGridRow row in ultraGrid1.Rows)
  239. {
  240. if (row.Cells["Chk3"].Value.ToString() == "True" && row != chkRow)
  241. {
  242. row.Cells["Chk3"].Value = "False";
  243. row.Update();
  244. }
  245. }
  246. }
  247. }
  248. private void GridEdite(UltraGridRow row)
  249. {
  250. if (row.GetValue("Chk") == "True")
  251. {
  252. foreach (UltraGridCell cell in row.Cells)
  253. {
  254. if (cell.Column.CellActivation == Activation.AllowEdit)
  255. {
  256. cell.Activation = Activation.AllowEdit;
  257. }
  258. }
  259. }
  260. else
  261. {
  262. foreach (UltraGridCell cell in row.Cells)
  263. {
  264. if (cell.Column.Key.Contains("Chk")) continue;
  265. if (cell.Column.CellActivation == Activation.AllowEdit)
  266. {
  267. cell.Activation = Activation.ActivateOnly;
  268. }
  269. }
  270. }
  271. if (row.Cells["SampleStyle"].Value.ToString() == "408102")
  272. {
  273. row.Cells["Width"].Value = null;
  274. row.Cells["Width"].Activation = Activation.ActivateOnly;
  275. }
  276. ultraGrid1.UpdateData();
  277. }
  278. private void ultraTextEditor1_EditorButtonClick(object sender, EditorButtonEventArgs e)
  279. {
  280. ComBaseSplineEntity splineEntity = (ComBaseSplineEntity)ultraGrid1.ActiveRow.ListObject;
  281. if (splineEntity.Validflag == "")
  282. {
  283. MessageUtil.ShowWarning("请先保存记录,然后再上传图片!");
  284. return;
  285. }
  286. string path = "Qcm/Spline/" + splineEntity.Eic + "/";
  287. if (e.Button.Key == "View")
  288. {
  289. FormFileDown down = new FormFileDown(_ob, path);
  290. if (flag == "试样关系")
  291. {
  292. down.DeleteButton.Visible = false;
  293. }
  294. down.ShowDialog();
  295. if (down.CtrlFileDown1.List.Count == 0)
  296. {
  297. _splineBLL.UpdateFilePosition("", splineEntity.Eic);
  298. ultraGrid1.ActiveRow.Cells["FilePosition"].Value = "";
  299. }
  300. }
  301. if (e.Button.Key == "Upload")
  302. {
  303. var serverFileList = FileHelper.Download(path);
  304. if (serverFileList.Count > 0)
  305. {
  306. MessageUtil.ShowWarning("该记录已存在一份文件,请删除后再重新上传!");
  307. return;
  308. }
  309. List<FileBean> list = new List<FileBean>();
  310. FileBean bean = new FileBean();
  311. OpenFileDialog file = new OpenFileDialog();
  312. file.Multiselect = false;
  313. DialogResult drStat;
  314. drStat = file.ShowDialog();
  315. if (drStat == DialogResult.OK)
  316. {
  317. string filePath = file.FileName;
  318. string fileName = System.IO.Path.GetFileName(filePath);
  319. bean = new FileBean();
  320. bean.setFileName(fileName);
  321. bean.setPathName(path);
  322. bean.setFile(FileHelper.FileToArray(filePath));
  323. list.Add(bean);
  324. bool isSuccess = Core.Mes.Client.Comm.Server.FileHelper.Upload(list);
  325. if (isSuccess)
  326. {
  327. _splineBLL.UpdateFilePosition(path + fileName, splineEntity.Eic);
  328. MessageUtil.ShowTips("上传成功!");
  329. Relocate(splineEntity.Eic);
  330. }
  331. else
  332. {
  333. MessageUtil.ShowTips("上传失败,请重试!");
  334. }
  335. }
  336. }
  337. }
  338. private void ultraGrid1_InitializeRow(object sender, InitializeRowEventArgs e)
  339. {
  340. if (e.Row.GetValue("Validflag") == "无效")
  341. {
  342. e.Row.Appearance.ForeColor = Color.Red;
  343. }
  344. }
  345. private void ultraTextEditor2_EditorButtonClick(object sender, EditorButtonEventArgs e)
  346. {
  347. if (ultraGrid1.ActiveCell.Column.Key == "StdNameS")
  348. {
  349. this.Cursor = Cursors.WaitCursor;
  350. var actRow = ultraGrid1.ActiveRow;
  351. ComBaseStdChoice baseStdChoice = new ComBaseStdChoice(new string[] { "S" }, actRow.GetValue("StdCodeS"), _ob);
  352. this.Cursor = Cursors.Default;
  353. if (baseStdChoice.ShowDialog() == DialogResult.OK)
  354. {
  355. actRow.SetValue("StdCodeS", baseStdChoice.ChoiceStdCodes);
  356. actRow.SetValue("StdNameS", baseStdChoice.ChoiceStdNames);
  357. }
  358. }
  359. else if (ultraGrid1.ActiveCell.Column.Key == "ItemNameF")
  360. {
  361. string phyCodeMin = ultraGrid1.ActiveRow.GetValue("PhyCodeMin");
  362. DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.ComBaseQuery.geComBasePhyRItem",
  363. new object[] { phyCodeMin }, _ob);
  364. dt.Columns["ITEM_NAME_F"].Caption = "试验方向";
  365. dt.Columns["ITEM_NAME_C"].Caption = "试验尺寸";
  366. BaseInfoPopup baseInfoPopup = new BaseInfoPopup(dt, "ITEM_NAME_F", "ITEM_CODE_F", "ITEM_CODE_C");
  367. baseInfoPopup.Text = "试验选择";
  368. baseInfoPopup.LabelTextBox1.Caption = "试验方向";
  369. baseInfoPopup.Shown += new EventHandler((c, d) =>
  370. {
  371. IQueryable<UltraGridRow> rows = baseInfoPopup.UltraGrid1.Rows.AsQueryable().Where(
  372. a => a.GetValue("ITEM_CODE_F") == ultraGrid1.ActiveRow.GetValue("ItemCodeF")
  373. && a.GetValue("ITEM_CODE_C") == ultraGrid1.ActiveRow.GetValue("ItemCodeS"));
  374. if (rows.Count() > 0)
  375. {
  376. rows.First().Activate();
  377. }
  378. });
  379. if (baseInfoPopup.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  380. {
  381. ultraGrid1.ActiveRow.SetValue("ItemNameF", baseInfoPopup.ChoicedRow.GetValue("ITEM_NAME_F"));
  382. ultraGrid1.ActiveRow.SetValue("ItemCodeF", baseInfoPopup.ChoicedRow.GetValue("ITEM_CODE_F"));
  383. ultraGrid1.ActiveRow.SetValue("ItemNameS", baseInfoPopup.ChoicedRow.GetValue("ITEM_NAME_C"));
  384. ultraGrid1.ActiveRow.SetValue("ItemCodeS", baseInfoPopup.ChoicedRow.GetValue("ITEM_CODE_C"));
  385. }
  386. }
  387. }
  388. }
  389. }