ComBasePurchaseAgreementCtrl.cs 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. using Core.Mes.Client.Comm.Server;
  2. using Core.Mes.Client.Comm.Tool;
  3. using Core.StlMes.Client.Qcm.BLL;
  4. using Core.StlMes.Client.Qcm.model;
  5. using CoreFS.CA06;
  6. using CoreFS.SA06;
  7. using Infragistics.Win.UltraWinGrid;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Data;
  11. using System.Drawing;
  12. using System.Linq;
  13. using System.Windows.Forms;
  14. namespace Core.StlMes.Client.Qcm.Control
  15. {
  16. public delegate void ClearData();
  17. public partial class ComBasePurchaseAgreementCtrl : UserControl
  18. {
  19. private ComBasePurchaseAgreementBLL _purchaseAgreementBLL;
  20. private OpeBase _ob;
  21. public event ClearData ClearData;
  22. public ComBasePurchaseAgreementCtrl(System.Windows.Forms.Control container, OpeBase ob)
  23. {
  24. InitializeComponent();
  25. _ob = ob;
  26. container.Controls.Add(this);
  27. this.Dock = DockStyle.Fill;
  28. _purchaseAgreementBLL = new ComBasePurchaseAgreementBLL(ob);
  29. EntityHelper.ShowGridCaption<ComBasePurchaseAgreementCtrlEntity>(ultraGrid1.DisplayLayout.Bands[0]);
  30. }
  31. private string agreementDesc = "";
  32. private string validflag = "";
  33. public void Query(string agreementDesc, string validflag)
  34. {
  35. this.agreementDesc = agreementDesc;
  36. this.validflag = validflag;
  37. comBasePurchaseAgreementCtrlEntityBindingSource.DataSource = _purchaseAgreementBLL.Query(agreementDesc, validflag);
  38. foreach (var row in ultraGrid1.Rows)
  39. {
  40. GridEdite(row);
  41. }
  42. }
  43. public void Relocat(string agreementCode)
  44. {
  45. Query(agreementDesc, validflag);
  46. var row = ultraGrid1.Rows.Where(a => a.GetValue("AgreementCode") == agreementCode).FirstOrDefault();
  47. if (row != null)
  48. {
  49. row.Activate();
  50. }
  51. }
  52. public void Save(List<ComBasePurchaseStdIdxEntity> purchaseStdIdxs, List<ComBasePurchaseProviderEntity> purchaseProviders)
  53. {
  54. try
  55. {
  56. ultraGrid1.UpdateData();
  57. }
  58. catch
  59. {
  60. }
  61. var row = ultraGrid1.Rows.Where(a => a.GetValue("Chk") == "True").FirstOrDefault();
  62. if (row == null && purchaseStdIdxs.Count == 0 && purchaseProviders.Count == 0)
  63. {
  64. MessageUtil.ShowWarning("请选择一条记录!");
  65. return;
  66. }
  67. ComBasePurchaseAgreementEntity purchaseAgreement = null;
  68. if (row != null)
  69. {
  70. purchaseAgreement = EntityHelper.CopyEntity<ComBasePurchaseAgreementEntity>(row.ListObject);
  71. if (row.Cells["SigningDate"].Value == null)
  72. {
  73. purchaseAgreement.SigningDate = null;
  74. }
  75. else
  76. {
  77. purchaseAgreement.SigningDate = (DateTime)row.Cells["SigningDate"].Value;
  78. }
  79. purchaseAgreement.CreateName = CoreUserInfo.UserInfo.GetUserName();
  80. purchaseAgreement.UpdateName = CoreUserInfo.UserInfo.GetUserName();
  81. }
  82. if (MessageUtil.ShowYesNoAndQuestion("是否确认保存?") == DialogResult.No)
  83. {
  84. return;
  85. }
  86. string agreementCode = _purchaseAgreementBLL.Save(purchaseAgreement, purchaseProviders, purchaseStdIdxs);
  87. MessageUtil.ShowTips("保存成功!");
  88. Relocat(agreementCode);
  89. }
  90. public void UpdateValidflag(string validflag)
  91. {
  92. var row = ultraGrid1.Rows.Where(a => a.GetValue("Chk") == "True").FirstOrDefault();
  93. if (row == null)
  94. {
  95. MessageUtil.ShowWarning("请选择一条记录!");
  96. return;
  97. }
  98. var purchaseAgreement = EntityHelper.CopyEntity<ComBasePurchaseAgreementEntity>(row.ListObject);
  99. purchaseAgreement.CreateName = CoreUserInfo.UserInfo.GetUserName();
  100. purchaseAgreement.UpdateName = CoreUserInfo.UserInfo.GetUserName();
  101. string tips = validflag == "0" ? "作废" : "恢复";
  102. if (MessageUtil.ShowYesNoAndQuestion("是否确认" + tips + "?") == DialogResult.No)
  103. {
  104. return;
  105. }
  106. _purchaseAgreementBLL.UpdateValidflag(purchaseAgreement, validflag);
  107. MessageUtil.ShowTips(tips + "成功!");
  108. if (ClearData != null)
  109. {
  110. ClearData();
  111. }
  112. Relocat(purchaseAgreement.AgreementCode);
  113. }
  114. private void ultraTextEditor1_EditorButtonClick(object sender, Infragistics.Win.UltraWinEditors.EditorButtonEventArgs e)
  115. {
  116. //this.Cursor = Cursors.WaitCursor;
  117. //string suppCodes = ultraGrid1.ActiveRow.GetValue("SuppCodes");
  118. //ComBasePurchaseProviderChoice purchaseProviderChoice = new ComBasePurchaseProviderChoice(_ob, suppCodes);
  119. //this.Cursor = Cursors.Default;
  120. //if (purchaseProviderChoice.ShowDialog() == DialogResult.OK)
  121. //{
  122. // ultraGrid1.ActiveRow.SetValue("SuppCodes", purchaseProviderChoice.SuppCodes);
  123. // ultraGrid1.ActiveRow.SetValue("SuppDescs", purchaseProviderChoice.SuppDescs);
  124. //}
  125. DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.ComBaseQuery.geComBaseStdNPurchase", new object[] { }, _ob);
  126. dt.Columns["STD_NAME"].Caption = "内控管理编号";
  127. BaseInfoPopup baseInfoPopup = new BaseInfoPopup(dt, "STD_NAME", "STD_CODE", "STDSTYLE");
  128. baseInfoPopup.LabelTextBox1.Caption = "内控管理编号";
  129. baseInfoPopup.Shown += new EventHandler((a, b) =>
  130. {
  131. var actRow = baseInfoPopup.UltraGrid1.Rows.AsQueryable().Where(
  132. c => c.GetValue("STD_CODE") == ultraGrid1.ActiveRow.GetValue("StdCodeNk")).FirstOrDefault();
  133. if (actRow != null)
  134. {
  135. actRow.Activate();
  136. }
  137. });
  138. this.Cursor = Cursors.Default;
  139. if (baseInfoPopup.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  140. {
  141. ultraGrid1.ActiveRow.SetValue("StdNameNk", baseInfoPopup.ChoicedRow.GetValue("STD_NAME"));
  142. ultraGrid1.ActiveRow.SetValue("StdCodeNk", baseInfoPopup.ChoicedRow.GetValue("STD_CODE"));
  143. }
  144. }
  145. private void ultraGrid1_InitializeRow(object sender, Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e)
  146. {
  147. if (e.Row.GetValue("Validflag") == "无效")
  148. {
  149. e.Row.Appearance.ForeColor = Color.Red;
  150. }
  151. }
  152. private void ultraGrid1_CellChange(object sender, Infragistics.Win.UltraWinGrid.CellEventArgs e)
  153. {
  154. if (ultraGrid1.ActiveCell.Column.Key != "SigningDate")
  155. {
  156. ultraGrid1.UpdateData();
  157. }
  158. if (e.Cell.Column.Key == "Chk")
  159. {
  160. UltraGridRow chkRow = e.Cell.Row;
  161. foreach (UltraGridRow row in ultraGrid1.Rows)
  162. {
  163. if (row.Cells["Chk"].Value.ToString() == "True" && row != chkRow)
  164. {
  165. row.Cells["Chk"].Value = "False";
  166. row.Update();
  167. }
  168. }
  169. }
  170. GridEdite(e.Cell.Row);
  171. }
  172. private void GridEdite(UltraGridRow row)
  173. {
  174. if (row.GetValue("Chk") == "True")
  175. {
  176. foreach (UltraGridCell cell in row.Cells)
  177. {
  178. if (cell.Column.CellActivation == Activation.AllowEdit)
  179. {
  180. cell.Activation = Activation.AllowEdit;
  181. }
  182. }
  183. }
  184. else
  185. {
  186. foreach (UltraGridCell cell in row.Cells)
  187. {
  188. if (cell.Column.Key == "Chk") continue;
  189. if (cell.Column.CellActivation == Activation.AllowEdit)
  190. {
  191. cell.Activation = Activation.ActivateOnly;
  192. }
  193. }
  194. }
  195. //ultraGrid1.UpdateData();
  196. }
  197. private void ultraDateTimeEditor1_BeforeExitEditMode(object sender, Infragistics.Win.BeforeExitEditModeEventArgs e)
  198. {
  199. }
  200. private void ultraGrid1_BeforeCellUpdate(object sender, BeforeCellUpdateEventArgs e)
  201. {
  202. if (e.Cell.Column.Key == "SigningDate")
  203. {
  204. string strNew = e.NewValue.ToString();
  205. string strOld = e.Cell.Value.ToString();
  206. }
  207. }
  208. private void ultraGrid1_CellDataError(object sender, CellDataErrorEventArgs e)
  209. {
  210. if (ultraGrid1.ActiveCell.Column.Key == "SigningDate")
  211. {
  212. MessageUtil.ShowWarning("请输入正确的日期!");
  213. e.RaiseErrorEvent = false;
  214. return;
  215. }
  216. }
  217. }
  218. }