F_PM_0401.cs 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. /*******************************************************************************
  2. * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:F_PM_0401.cs
  5. * 2.功能描述:交坯计件一览
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 王鑫 2014/09/23 1.00 新建
  9. *******************************************************************************/
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Data;
  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.DataModels;
  18. using Dongke.IBOSS.PRD.WCF.DataModels.PMModule;
  19. using Dongke.IBOSS.PRD.WCF.Proxys;
  20. using Dongke.IBOSS.PRD.WCF.Proxys.PMModuleService;
  21. namespace Dongke.IBOSS.PRD.Client.PMModule
  22. {
  23. /// <summary>
  24. /// 交坏计件一览
  25. /// </summary>
  26. public partial class F_PM_0401 : DockPanelBase
  27. {
  28. #region 成员变量
  29. // 窗体的单例模式
  30. private static Dictionary<int, F_PM_0401> _dicInstance;
  31. // 当前工序ID
  32. private int _currentProcedureID = 0;
  33. // 最后选择行
  34. private int _selecedRow;
  35. // 窗体显示的Title
  36. private string _fromTitle;
  37. #endregion
  38. #region 构造函数
  39. public F_PM_0401()
  40. {
  41. InitializeComponent();
  42. this.tsbtnAdd.Text = ButtonText.TSBTN_ADD;
  43. //编辑
  44. this.tsbtnEdit.Text = ButtonText.TSBTN_EDIT;
  45. //自动适应列宽
  46. this.tsbtnAdaptive.Text = ButtonText.TSBTN_ADAPTIVE;
  47. //关闭
  48. this.tsbtnClose.Text = ButtonText.TSBTN_CLOSE;
  49. //查询
  50. this.btnSearch.Text = ButtonText.BTN_SEARCH;
  51. //清空条件
  52. this.btnClearCondition.Text = ButtonText.BTN_CLEARCONDITION;
  53. //查询条件
  54. this.gbxCondition.Text = Constant.LABEL_QUERY_CONDITIONS;
  55. this.Text = _fromTitle;
  56. }
  57. #endregion
  58. #region 单例模式
  59. /// <summary>
  60. /// 一个工序ID有一个单例,防止重复创建窗体
  61. /// </summary>
  62. /// <param name="procedureID">工序ID</param>
  63. /// <returns></returns>
  64. public static F_PM_0401 Instance(int procedureID, string fromTitle)
  65. {
  66. F_PM_0401 fInstance = null;
  67. if (_dicInstance == null)
  68. {
  69. _dicInstance = new Dictionary<int, F_PM_0401>();
  70. fInstance = new F_PM_0401();
  71. _dicInstance.Add(procedureID, fInstance);
  72. }
  73. else if (_dicInstance.ContainsKey(procedureID))
  74. {
  75. fInstance = _dicInstance[procedureID];
  76. }
  77. else
  78. {
  79. fInstance = new F_PM_0401();
  80. _dicInstance.Add(procedureID, fInstance);
  81. }
  82. fInstance._currentProcedureID = procedureID;
  83. fInstance._fromTitle = fromTitle;
  84. fInstance.Text = fromTitle;
  85. return fInstance;
  86. }
  87. #endregion
  88. #region 事件
  89. /// <summary>
  90. /// 窗体加载事件
  91. /// </summary>
  92. /// <param name="sender"></param>
  93. /// <param name="e"></param>
  94. private void F_PM_0401_Load(object sender, System.EventArgs e)
  95. {
  96. try
  97. {
  98. // 加载权限
  99. FormPermissionManager.FormPermissionControl(this.Name, this,
  100. LogInUserInfo.CurrentUser.CurrentUserEntity.UserRightData, LogInUserInfo.CurrentUser.CurrentUserEntity.FunctionData);
  101. // 设置表格不自动创建列
  102. this.dgvProduction.AutoGenerateColumns = false;
  103. // 初始化时间控件为当前日期
  104. this.dtpStartTime.Value = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
  105. this.dtpEndTime.Value = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day).AddDays(1).AddMinutes(-1);
  106. // 设置ToolStripButton状态
  107. this.SetToolStripButtonEnable();
  108. }
  109. catch (Exception ex)
  110. {
  111. // 对异常进行共通处理
  112. ExceptionManager.HandleEventException(this.ToString(),
  113. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  114. }
  115. }
  116. /// <summary>
  117. /// 窗体关闭事件
  118. /// </summary>
  119. /// <param name="sender"></param>
  120. /// <param name="e"></param>
  121. private void F_PM_0401_FormClosed(object sender, System.Windows.Forms.FormClosedEventArgs e)
  122. {
  123. _dicInstance = null;
  124. }
  125. /// <summary>
  126. /// 自动适应列宽
  127. /// </summary>
  128. /// <param name="sender"></param>
  129. /// <param name="e"></param>
  130. private void tsbtnAdaptive_Click(object sender, EventArgs e)
  131. {
  132. this.dgvProduction.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
  133. }
  134. /// <summary>
  135. /// 清空条件按钮事件
  136. /// </summary>
  137. /// <param name="sender"></param>
  138. /// <param name="e"></param>
  139. private void btnClearCondition_Click(object sender, EventArgs e)
  140. {
  141. this.txtBarCode.Text = "";
  142. this.txtGoodsCode.Text = "";
  143. this.txtGoodsName.Text = "";
  144. this.txtUserCode.Text = "";
  145. this.scbOrganization.ClearValue();
  146. //this.txtRemarks.Text = "";
  147. this.scbGoodsType.ClearValue();
  148. //this.statusIsReworked.ClearItemCheck();
  149. this.dtpStartTime.Value = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
  150. this.dtpEndTime.Value = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day).AddDays(1).AddMinutes(-1);
  151. }
  152. /// <summary>
  153. /// 查询按钮事件
  154. /// </summary>
  155. /// <param name="sender"></param>
  156. /// <param name="e"></param>
  157. private void btnSearch_Click(object sender, EventArgs e)
  158. {
  159. try
  160. {
  161. // 记录当前选中行
  162. int selectRowIndex = this._selecedRow;
  163. // 异步处理
  164. this.btnSearch.Enabled = false;
  165. this.btnClearCondition.Enabled = false;
  166. SearchProductionDataEntity requestEntity = CreatesearchProductionDataRequestEntity();
  167. DataTable dtProductionData = (DataTable)DoAsync(new AsyncMethod(() =>
  168. {
  169. return PMModuleProxy.Service.GetProductionData(requestEntity);
  170. }));
  171. DataSet dsProductionData = new DataSet();
  172. dsProductionData.Tables.Add(dtProductionData);
  173. this.btnSearch.Enabled = true;
  174. this.btnClearCondition.Enabled = true;
  175. if (dsProductionData != null)
  176. {
  177. base.DataSource = dsProductionData;
  178. if (this.DataSource != null && this.DataSource.Tables.Count > Constant.INT_IS_ZERO)
  179. {
  180. this.dgvProduction.DataSource = this.DataSource.Tables[0];
  181. if (this.DataSource.Tables[0].Rows.Count <= Constant.INT_IS_ZERO)
  182. {
  183. // 提示未查找到数据
  184. MessageBox.Show(Messages.MSG_CMN_I002, this.Text,
  185. MessageBoxButtons.OK, MessageBoxIcon.Information);
  186. }
  187. else
  188. {
  189. if (selectRowIndex >= Constant.INT_IS_ZERO)
  190. {
  191. if (selectRowIndex >= dsProductionData.Tables[0].Rows.Count)
  192. {
  193. this.dgvProduction.Rows[this.dgvProduction.Rows.Count - 1].Selected = true;
  194. this.dgvProduction.CurrentCell = this.dgvProduction.Rows[this.dgvProduction.Rows.Count - 1].Cells["GoodsCode"];
  195. }
  196. else
  197. {
  198. this.dgvProduction.Rows[selectRowIndex].Selected = true;
  199. this.dgvProduction.CurrentCell = this.dgvProduction.Rows[selectRowIndex].Cells["GoodsCode"];
  200. }
  201. }
  202. }
  203. }
  204. }
  205. }
  206. catch (Exception ex)
  207. {
  208. this.btnSearch.Enabled = true;
  209. this.btnClearCondition.Enabled = true;
  210. // 对异常进行共通处理
  211. ExceptionManager.HandleEventException(this.ToString(),
  212. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  213. }
  214. }
  215. /// <summary>
  216. /// 关闭按钮事件
  217. /// </summary>
  218. /// <param name="sender"></param>
  219. /// <param name="e"></param>
  220. private void tsbtnClose_Click(object sender, EventArgs e)
  221. {
  222. this.Close();
  223. }
  224. /// <summary>
  225. /// 新建按钮事件
  226. /// </summary>
  227. /// <param name="sender"></param>
  228. /// <param name="e"></param>
  229. private void tsbtnAdd_Click(object sender, EventArgs e)
  230. {
  231. try
  232. {
  233. F_PM_0402 frmPM0402 = new F_PM_0402(_currentProcedureID, _fromTitle);
  234. DialogResult dialogResult = frmPM0402.ShowDialog();
  235. // 重新加载GridView
  236. if (dialogResult == DialogResult.OK)
  237. {
  238. SearchProductionDataEntity requestEntity = CreatesearchProductionDataRequestEntity();
  239. DataTable dtProductionData = (DataTable)DoAsync(new AsyncMethod(() =>
  240. {
  241. return PMModuleProxy.Service.GetProductionData(requestEntity);
  242. }));
  243. if (dtProductionData != null && dtProductionData.Rows.Count > Constant.INT_IS_ZERO)
  244. {
  245. this.dgvProduction.DataSource = null;
  246. this.dgvProduction.DataSource = dtProductionData;
  247. // 设置ToolStripButton按钮状态
  248. this.SetToolStripButtonEnable();
  249. this.dgvProduction.ReadOnly = true;
  250. }
  251. }
  252. }
  253. catch (Exception ex)
  254. {
  255. // 对异常进行共通处理
  256. ExceptionManager.HandleEventException(this.ToString(),
  257. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  258. }
  259. }
  260. #endregion
  261. #region 私有方法
  262. /// <summary>
  263. /// 设置工具按钮的可用状态
  264. /// </summary>
  265. private void SetToolStripButtonEnable()
  266. {
  267. if (this.dgvProduction.CurrentCell != null)
  268. {
  269. this.tsbtnEdit.Enabled = true;
  270. }
  271. else
  272. {
  273. this.tsbtnEdit.Enabled = false;
  274. }
  275. }
  276. /// <summary>
  277. /// 搜索条件
  278. /// </summary>
  279. /// <returns></returns>
  280. private SearchProductionDataEntity CreatesearchProductionDataRequestEntity()
  281. {
  282. SearchProductionDataEntity result = new SearchProductionDataEntity();
  283. result.BarCode = this.txtBarCode.Text.Trim();
  284. result.GoodsCode = this.txtGoodsCode.Text.Trim();
  285. result.GoodsName = this.txtGoodsName.Text.Trim();
  286. result.UserCode = this.txtUserCode.Text.Trim();
  287. result.OrganizationID = this.scbOrganization.SearchedPKMember;
  288. result.Remarks = "";
  289. // this.txtRemarks.Text.Trim();
  290. //object[] objRework = this.statusIsReworked.SelectedValues;
  291. //string Rework = "";
  292. //for (int i = 0; i < objRework.Length; i++)
  293. //{
  294. // Rework += objRework[i] + ",";
  295. //}
  296. //Rework = Rework.TrimEnd(',');
  297. //result.IsRework = Rework;
  298. result.BeginDate = this.dtpStartTime.Value;
  299. result.EndDate = this.dtpEndTime.Value;
  300. result.ProcedureID = _currentProcedureID;
  301. result.GoodsTypeCode = scbGoodsType.SearchedValue + "";
  302. return result;
  303. }
  304. #endregion
  305. }
  306. }