F_PM_0301.cs 9.8 KB

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