F_PM_2108.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. /*******************************************************************************
  2. * Copyright(c) 2015 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:F_PM_2108.cs
  5. * 2.功能描述:清除在产残留数据
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 王鑫 2015/08/10 1.00 新建
  9. *******************************************************************************/
  10. using System;
  11. using System.Data;
  12. using System.Text;
  13. using System.Windows.Forms;
  14. using Dongke.IBOSS.PRD.Basics.BaseResources;
  15. using Dongke.IBOSS.PRD.Basics.DockPanel;
  16. using Dongke.IBOSS.PRD.Client.CommonModule;
  17. using Dongke.IBOSS.PRD.Client.Controls;
  18. using Dongke.IBOSS.PRD.Client.DataModels;
  19. using Dongke.IBOSS.PRD.WCF.DataModels;
  20. using Dongke.IBOSS.PRD.WCF.Proxys;
  21. namespace Dongke.IBOSS.PRD.Client.PMModule
  22. {
  23. public partial class F_PM_2108 : DKDockPanelBase
  24. {
  25. #region 成员变量
  26. // 窗体的单例模式
  27. private static F_PM_2108 _instance;
  28. //默认清空工序,重置回用户当前权限工序
  29. private string _currentUserPurview = null;
  30. //默认清空生产线,重置回用户当前权限生产线
  31. private string _currentUserLinePuview = null;
  32. #endregion
  33. #region 构造函数
  34. public F_PM_2108()
  35. {
  36. InitializeComponent();
  37. //自动适应列宽
  38. this.tsbtnAdaptive.Text = ButtonText.TSBTN_ADAPTIVE;
  39. //关闭
  40. this.tsbtnClose.Text = ButtonText.TSBTN_CLOSE;
  41. //查询
  42. this.btnSearch.Text = ButtonText.BTN_SEARCH;
  43. // 清除选择
  44. this.tsbtnClearSelected.Text = ButtonText.TSBTN_CLEARSELECTED;
  45. //批量清除
  46. this.tsbtnAllClear.Text = ButtonText.TSBTN_CLEARALL;
  47. //清空条件
  48. this.btnClearCondition.Text = ButtonText.BTN_CLEARCONDITION;
  49. //查询条件
  50. this.gbxCondition.Text = Constant.LABEL_QUERY_CONDITIONS;
  51. // 窗体显示的Title
  52. this.Text = FormTitles.F_PM_2108;
  53. }
  54. #endregion
  55. #region 单例模式
  56. /// <summary>
  57. /// 单例模式,防止重复创建窗体
  58. /// </summary>
  59. public static F_PM_2108 Instance
  60. {
  61. get
  62. {
  63. if (_instance == null || _instance.IsDisposed)
  64. {
  65. _instance = new F_PM_2108();
  66. }
  67. return _instance;
  68. }
  69. }
  70. #endregion
  71. #region 事件
  72. /// <summary>
  73. /// 窗体加载事件
  74. /// </summary>
  75. /// <param name="sender"></param>
  76. /// <param name="e"></param>
  77. private void F_PM_2108_Load(object sender, EventArgs e)
  78. {
  79. try
  80. {
  81. // 加载权限
  82. FormPermissionManager.FormPermissionControl(this.Name, this,
  83. LogInUserInfo.CurrentUser.CurrentUserEntity.UserRightData,
  84. LogInUserInfo.CurrentUser.CurrentUserEntity.FunctionData);
  85. // 设置表格不自动创建列
  86. this.dgvInProductionData.AutoGenerateColumns = false;
  87. this.dtpUpdateTimeStart.Value = DateTime.Now.Date;
  88. this.dtpUpdateTimeEnd.Value = DateTime.Now.Date;
  89. this.dtpUpdateTimeStart.Enabled = false;
  90. this.dtpUpdateTimeEnd.Enabled = false;
  91. }
  92. catch (Exception ex)
  93. {
  94. // 对异常进行共通处理
  95. ExceptionManager.HandleEventException(this.ToString(),
  96. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  97. }
  98. }
  99. /// <summary>
  100. /// 窗体关闭事件
  101. /// </summary>
  102. /// <param name="sender"></param>
  103. /// <param name="e"></param>
  104. private void F_PM_2108_FormClosed(object sender, FormClosedEventArgs e)
  105. {
  106. _instance = null;
  107. }
  108. /// <summary>
  109. /// 关闭按钮事件
  110. /// </summary>
  111. /// <param name="sender"></param>
  112. /// <param name="e"></param>
  113. private void tsbtnClose_Click(object sender, EventArgs e)
  114. {
  115. this.Close();
  116. }
  117. /// <summary>
  118. /// 查询按钮事件
  119. /// </summary>
  120. /// <param name="sender"></param>
  121. /// <param name="e"></param>
  122. private void btnSearch_Click(object sender, EventArgs e)
  123. {
  124. try
  125. {
  126. this.dgvInProductionData.DataSource = null;
  127. this.dgvInProductionData.DataSource = this.GetSearchData();
  128. }
  129. catch (Exception ex)
  130. {
  131. this.btnSearch.Enabled = true;
  132. this.btnClearCondition.Enabled = true;
  133. // 对异常进行共通处理
  134. ExceptionManager.HandleEventException(this.ToString(),
  135. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  136. }
  137. }
  138. /// <summary>
  139. /// 自动适应列宽
  140. /// </summary>
  141. /// <param name="sender"></param>
  142. /// <param name="e"></param>
  143. private void tsbtnAdaptive_Click(object sender, EventArgs e)
  144. {
  145. this.dgvInProductionData.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
  146. }
  147. /// <summary>
  148. /// 清空条件按钮事件
  149. /// </summary>
  150. /// <param name="sender"></param>
  151. /// <param name="e"></param>
  152. private void btnClearCondition_Click(object sender, EventArgs e)
  153. {
  154. //清空更多条件内容;
  155. this.dkProcedureSearchBox.ClearControl();
  156. this.dkproductionLineSearchBox.ClearControl();
  157. this.dtpUpdateTimeStart.Value = DateTime.Now.Date;
  158. this.dtpUpdateTimeEnd.Value = DateTime.Now.Date;
  159. this.dkProcedureSearchBox.ProcedureIDS = this._currentUserPurview;
  160. this.dkproductionLineSearchBox.ProductionLineIDS = this._currentUserLinePuview;
  161. this.txtBarcode.Text = "";
  162. this.chkDateTime.Checked = false;
  163. }
  164. /// <summary>
  165. /// 清除选择按钮事件
  166. /// </summary>
  167. /// <param name="sender"></param>
  168. /// <param name="e"></param>
  169. private void tsbtnClearSelected_Click(object sender, EventArgs e)
  170. {
  171. try
  172. {
  173. DataTable dt = this.dgvInProductionData.DataSource as DataTable;
  174. if (dt == null)
  175. {
  176. return;
  177. }
  178. dt.AcceptChanges();
  179. DataRow[] dr = dt.Select("Sel=1");
  180. if (dr.Length == 0)
  181. {
  182. MessageBox.Show("请选择清除在产的产品",
  183. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  184. return;
  185. }
  186. DialogResult dialogResult
  187. = MessageBox.Show("确认是否清除选中的在产产品?",
  188. this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
  189. if (dialogResult.Equals(DialogResult.No))
  190. {
  191. return;
  192. }
  193. string barcodes = "";
  194. foreach (DataRow r in dr)
  195. {
  196. barcodes += r["barcode"].ToString() + ",";
  197. }
  198. barcodes = barcodes.TrimEnd(',');
  199. // 清除
  200. int result = (int)DoAsync(() =>
  201. {
  202. return PMModuleProxy.Service.SaveClearInproduction(barcodes);
  203. });
  204. if (result > Constant.INT_IS_ZERO)
  205. {
  206. MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "在产产品", "清除数据"),
  207. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  208. // 刷新窗口数据
  209. this.btnSearch_Click(sender, e);
  210. }
  211. else if (result == -Constant.INT_IS_ONE)
  212. {
  213. MessageBox.Show("返工产品不允许清除",
  214. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  215. return;
  216. }
  217. else if (result == -Constant.INT_IS_TWO)
  218. {
  219. MessageBox.Show("报损待审产品不允许清除",
  220. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  221. return;
  222. }
  223. else
  224. {
  225. MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "在产产品", "清除数据"),
  226. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  227. return;
  228. }
  229. }
  230. catch (Exception ex)
  231. {
  232. // 对异常进行共通处理
  233. ExceptionManager.HandleEventException(this.ToString(),
  234. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  235. }
  236. }
  237. /// <summary>
  238. /// 批量清除按钮事件
  239. /// </summary>
  240. /// <param name="sender"></param>
  241. /// <param name="e"></param>
  242. private void tsbtnAllClear_Click(object sender, EventArgs e)
  243. {
  244. try
  245. {
  246. F_PM_2109 frmPM2109 = new F_PM_2109();
  247. DialogResult dialogResult = frmPM2109.ShowDialog();
  248. // 重新加载GridView
  249. if (dialogResult == DialogResult.OK)
  250. {
  251. btnSearch_Click(sender, e);
  252. }
  253. }
  254. catch (Exception ex)
  255. {
  256. // 对异常进行共通处理
  257. ExceptionManager.HandleEventException(this.ToString(),
  258. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  259. }
  260. }
  261. /// <summary>
  262. /// 表格状态自动提交
  263. /// </summary>
  264. /// <param name="sender"></param>
  265. /// <param name="e"></param>
  266. private void dgvInProductionData_CurrentCellDirtyStateChanged(object sender, EventArgs e)
  267. {
  268. try
  269. {
  270. if (this.dgvInProductionData.CurrentRow != null && this.dgvInProductionData.IsCurrentCellDirty)
  271. {
  272. if ("Sel".Equals(this.dgvInProductionData.Columns
  273. [this.dgvInProductionData.CurrentCell.ColumnIndex].Name))
  274. {
  275. this.dgvInProductionData.CommitEdit(DataGridViewDataErrorContexts.Commit);
  276. }
  277. }
  278. }
  279. catch (Exception ex)
  280. {
  281. // 对异常进行共通处理
  282. ExceptionManager.HandleEventException(this.ToString(),
  283. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  284. }
  285. }
  286. #endregion
  287. #region 私有方法
  288. /// <summary>
  289. /// 根据界面查询条件获取数据集
  290. /// </summary>
  291. private DataTable GetSearchData()
  292. {
  293. try
  294. {
  295. RPT010401_SE se = new RPT010401_SE();
  296. se.ProductionLineIDS = dkproductionLineSearchBox.ProductionLineIDS;
  297. se.ProcedureIDS = dkProcedureSearchBox.ProcedureIDS;
  298. if (chkDateTime.Checked)
  299. {
  300. se.UpdateTimeStart = DateTime.Parse(this.dtpUpdateTimeStart.Value.ToString("yyyy-MM-dd") + " 0:0:0");
  301. se.UpdateTimeEnd = DateTime.Parse(this.dtpUpdateTimeEnd.Value.ToString("yyyy-MM-dd") + " 23:59:59");
  302. }
  303. se.Barcode = this.txtBarcode.Text.Trim();
  304. // 调用服务器端获取数据集
  305. ServiceResultEntity sre = DoAsync<ServiceResultEntity>(() =>
  306. {
  307. return PMModuleProxy.Service.GetPM2108Data(se);
  308. }
  309. );
  310. if (sre.Status == Constant.ServiceResultStatus.Success)
  311. {
  312. if (sre.Data.Tables[0].Rows.Count <= Constant.INT_IS_ZERO)
  313. {
  314. // 提示未查找到数据
  315. MessageBox.Show(Messages.MSG_CMN_I002, this.Text,
  316. MessageBoxButtons.OK, MessageBoxIcon.Warning);
  317. //清空数据
  318. return null;
  319. }
  320. return sre.Data.Tables[0];
  321. }
  322. return null;
  323. }
  324. catch (Exception ex)
  325. {
  326. throw ex;
  327. }
  328. }
  329. #endregion
  330. private void chkDateTime_CheckedChanged(object sender, EventArgs e)
  331. {
  332. dtpUpdateTimeStart.Enabled = chkDateTime.Checked;
  333. dtpUpdateTimeEnd.Enabled = chkDateTime.Checked;
  334. }
  335. }
  336. }