F_PM_0301.cs 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  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. if (_currentProcedureID == 28 || _currentProcedureID == 29 || _currentProcedureID==9) {
  108. this.dgvProduction.Columns["Remarks"].Visible = true;
  109. }
  110. }
  111. catch (Exception ex)
  112. {
  113. // 对异常进行共通处理
  114. ExceptionManager.HandleEventException(this.ToString(),
  115. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  116. }
  117. }
  118. /// <summary>
  119. /// 窗体关闭事件
  120. /// </summary>
  121. /// <param name="sender"></param>
  122. /// <param name="e"></param>
  123. private void F_PM_0301_FormClosed(object sender, System.Windows.Forms.FormClosedEventArgs e)
  124. {
  125. _dicInstance = null;
  126. }
  127. /// <summary>
  128. /// 自动适应列宽
  129. /// </summary>
  130. /// <param name="sender"></param>
  131. /// <param name="e"></param>
  132. private void tsbtnAdaptive_Click(object sender, EventArgs e)
  133. {
  134. this.dgvProduction.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
  135. }
  136. /// <summary>
  137. /// 清空条件按钮事件
  138. /// </summary>
  139. /// <param name="sender"></param>
  140. /// <param name="e"></param>
  141. private void btnClearCondition_Click(object sender, EventArgs e)
  142. {
  143. this.txtBarCode.Text = "";
  144. this.txtGoodsCode.Text = "";
  145. this.txtGoodsName.Text = "";
  146. this.txtUserCode.Text = "";
  147. this.scbOrganization.ClearValue();
  148. //this.txtRemarks.Text = "";
  149. //this.statusIsReworked.ClearItemCheck();
  150. this.scbGoodsType.ClearValue();
  151. this.dtpStartTime.Value = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
  152. this.dtpEndTime.Value = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day).AddDays(1).AddMinutes(-1);
  153. }
  154. /// <summary>
  155. /// 查询按钮事件
  156. /// </summary>
  157. /// <param name="sender"></param>
  158. /// <param name="e"></param>
  159. private void btnSearch_Click(object sender, EventArgs e)
  160. {
  161. try
  162. {
  163. // 记录当前选中行
  164. int selectRowIndex = this._selecedRow;
  165. // 异步处理
  166. this.btnSearch.Enabled = false;
  167. this.btnClearCondition.Enabled = false;
  168. SearchProductionDataEntity requestEntity = CreatesearchProductionDataRequestEntity();
  169. DataTable dtProductionData = (DataTable)DoAsync(new AsyncMethod(() =>
  170. {
  171. return PMModuleProxy.Service.GetProductionData(requestEntity);
  172. }));
  173. DataSet dsProductionData = new DataSet();
  174. dsProductionData.Tables.Add(dtProductionData);
  175. this.btnSearch.Enabled = true;
  176. this.btnClearCondition.Enabled = true;
  177. if (dsProductionData != null)
  178. {
  179. base.DataSource = dsProductionData;
  180. if (this.DataSource != null && this.DataSource.Tables.Count > Constant.INT_IS_ZERO)
  181. {
  182. this.dgvProduction.DataSource = this.DataSource.Tables[0];
  183. if (this.DataSource.Tables[0].Rows.Count <= Constant.INT_IS_ZERO)
  184. {
  185. // 提示未查找到数据
  186. MessageBox.Show(Messages.MSG_CMN_I002, this.Text,
  187. MessageBoxButtons.OK, MessageBoxIcon.Information);
  188. }
  189. else
  190. {
  191. if (selectRowIndex >= Constant.INT_IS_ZERO)
  192. {
  193. if (selectRowIndex >= dsProductionData.Tables[0].Rows.Count)
  194. {
  195. this.dgvProduction.Rows[this.dgvProduction.Rows.Count - 1].Selected = true;
  196. this.dgvProduction.CurrentCell = this.dgvProduction.Rows[this.dgvProduction.Rows.Count - 1].Cells["GoodsCode"];
  197. }
  198. else
  199. {
  200. this.dgvProduction.Rows[selectRowIndex].Selected = true;
  201. this.dgvProduction.CurrentCell = this.dgvProduction.Rows[selectRowIndex].Cells["GoodsCode"];
  202. }
  203. }
  204. }
  205. }
  206. }
  207. }
  208. catch (Exception ex)
  209. {
  210. this.btnSearch.Enabled = true;
  211. this.btnClearCondition.Enabled = true;
  212. // 对异常进行共通处理
  213. ExceptionManager.HandleEventException(this.ToString(),
  214. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  215. }
  216. }
  217. /// <summary>
  218. /// 关闭按钮事件
  219. /// </summary>
  220. /// <param name="sender"></param>
  221. /// <param name="e"></param>
  222. private void tsbtnClose_Click(object sender, EventArgs e)
  223. {
  224. this.Close();
  225. }
  226. /// <summary>
  227. /// 新建按钮事件
  228. /// </summary>
  229. /// <param name="sender"></param>
  230. /// <param name="e"></param>
  231. private void tsbtnAdd_Click(object sender, EventArgs e)
  232. {
  233. try
  234. {
  235. F_PM_0302 frmPM0402 = new F_PM_0302(_currentProcedureID, _fromTitle);
  236. DialogResult dialogResult = frmPM0402.ShowDialog();
  237. // 重新加载GridView
  238. if (dialogResult == DialogResult.OK)
  239. {
  240. SearchProductionDataEntity requestEntity = CreatesearchProductionDataRequestEntity();
  241. DataTable dtProductionData = (DataTable)DoAsync(new AsyncMethod(() =>
  242. {
  243. return PMModuleProxy.Service.GetProductionData(requestEntity);
  244. }));
  245. if (dtProductionData != null && dtProductionData.Rows.Count > Constant.INT_IS_ZERO)
  246. {
  247. this.dgvProduction.DataSource = null;
  248. this.dgvProduction.DataSource = dtProductionData;
  249. // 设置ToolStripButton按钮状态
  250. this.SetToolStripButtonEnable();
  251. this.dgvProduction.ReadOnly = true;
  252. }
  253. }
  254. }
  255. catch (Exception ex)
  256. {
  257. // 对异常进行共通处理
  258. ExceptionManager.HandleEventException(this.ToString(),
  259. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  260. }
  261. }
  262. #endregion
  263. #region 私有方法
  264. /// <summary>
  265. /// 设置工具按钮的可用状态
  266. /// </summary>
  267. private void SetToolStripButtonEnable()
  268. {
  269. if (this.dgvProduction.CurrentCell != null)
  270. {
  271. this.tsbtnEdit.Enabled = true;
  272. }
  273. else
  274. {
  275. this.tsbtnEdit.Enabled = false;
  276. }
  277. }
  278. /// <summary>
  279. /// 搜索条件
  280. /// </summary>
  281. /// <returns></returns>
  282. private SearchProductionDataEntity CreatesearchProductionDataRequestEntity()
  283. {
  284. SearchProductionDataEntity result = new SearchProductionDataEntity();
  285. result.BarCode = this.txtBarCode.Text.Trim();
  286. result.GoodsCode = this.txtGoodsCode.Text.Trim();
  287. result.GoodsName = this.txtGoodsName.Text.Trim();
  288. result.UserCode = this.txtUserCode.Text.Trim();
  289. result.OrganizationID = scbOrganization.SearchedPKMember;
  290. result.Remarks = "";
  291. // this.txtRemarks.Text.Trim();
  292. //object[] objRework = this.statusIsReworked.SelectedValues;
  293. string Rework = "";
  294. //for (int i = 0; i < objRework.Length; i++)
  295. //{
  296. // Rework += objRework[i] + ",";
  297. //}
  298. Rework = Rework.TrimEnd(',');
  299. result.IsRework = Rework;
  300. result.BeginDate = this.dtpStartTime.Value;
  301. result.EndDate = this.dtpEndTime.Value;//.AddDays(1)
  302. result.ProcedureID = _currentProcedureID;
  303. result.GoodsTypeCode = this.scbGoodsType.SearchedValue + "";
  304. return result;
  305. }
  306. #endregion
  307. }
  308. }