F_PC_0401.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. /*******************************************************************************
  2. * Copyright(c) 2014 dongke All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:F_HR_0501.cs
  5. * 2.功能描述:班次配置
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 冯雪 2014/09/22 1.00 新建
  9. *******************************************************************************/
  10. using System;
  11. using System.Data;
  12. using System.Windows.Forms;
  13. using Dongke.IBOSS.PRD.Basics.BaseResources;
  14. using Dongke.IBOSS.PRD.Basics.DockPanel;
  15. using Dongke.IBOSS.PRD.Client.CommonModule;
  16. using Dongke.IBOSS.PRD.Client.DataModels;
  17. using Dongke.IBOSS.PRD.WCF.DataModels.ConfigModule;
  18. using Dongke.IBOSS.PRD.WCF.Proxys;
  19. using Dongke.IBOSS.PRD.WCF.Proxys.PCModuleService;
  20. namespace Dongke.IBOSS.PRD.Client.PCModule
  21. {
  22. /// <summary>
  23. /// 班次配置
  24. /// </summary>
  25. public partial class F_PC_0401 : DockPanelBase
  26. {
  27. #region 成员变量
  28. // 窗体的单例模式
  29. private static F_PC_0401 _instance;
  30. //选择的行
  31. private int _selectedRowIndex;
  32. #endregion
  33. #region 构造函数
  34. /// <summary>
  35. /// 构造函数
  36. /// </summary>
  37. public F_PC_0401()
  38. {
  39. InitializeComponent();
  40. FormPermissionManager.FormPermissionControl(this.Name, this,
  41. LogInUserInfo.CurrentUser.CurrentUserEntity.UserRightData, LogInUserInfo.CurrentUser.CurrentUserEntity.FunctionData);
  42. this.SetFromTitleInfo();
  43. }
  44. #endregion
  45. #region 单例模式
  46. /// <summary>
  47. /// 单例模式,防止重复创建窗体
  48. /// </summary>
  49. public static F_PC_0401 Instance
  50. {
  51. get
  52. {
  53. if (_instance == null)
  54. {
  55. _instance = new F_PC_0401();
  56. }
  57. return _instance;
  58. }
  59. }
  60. #endregion
  61. #region 事件
  62. /// <summary>
  63. /// 页面加载事件
  64. /// </summary>
  65. /// <param name="sender"></param>
  66. /// <param name="e"></param>
  67. private void F_PC_0401_Load(object sender, EventArgs e)
  68. {
  69. try
  70. {
  71. // 加载权限
  72. FormPermissionManager.FormPermissionControl(this.Name, this,
  73. Dongke.IBOSS.PRD.Client.DataModels.LogInUserInfo.CurrentUser.CurrentUserEntity.UserRightData,
  74. Dongke.IBOSS.PRD.Client.DataModels.LogInUserInfo.CurrentUser.CurrentUserEntity.FunctionData);
  75. // 设置表格不自动创建列
  76. this.dgvClassesSet.AutoGenerateColumns = false;
  77. // 设置ToolStripButton状态
  78. this.SetToolStripButtonEnable();
  79. }
  80. catch (Exception ex)
  81. {
  82. // 对异常进行共通处理
  83. ExceptionManager.HandleEventException(this.ToString(),
  84. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  85. }
  86. }
  87. /// <summary>
  88. /// 窗体关闭事件
  89. /// </summary>
  90. /// <param name="sender"></param>
  91. /// <param name="e"></param>
  92. private void F_PC_0401_FormClosed(object sender, FormClosedEventArgs e)
  93. {
  94. _instance = null;
  95. }
  96. /// <summary>
  97. /// 行获取焦点后查看明细
  98. /// </summary>
  99. /// <param name="sender"></param>
  100. /// <param name="e"></param>
  101. private void dgvClassesSet_CellEnter(object sender, DataGridViewCellEventArgs e)
  102. {
  103. try
  104. {
  105. if (this.dgvClassesSet.CurrentCell != null)
  106. {
  107. // 记录最后选择行
  108. this._selectedRowIndex = this.dgvClassesSet.CurrentCell.RowIndex;
  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 tsbtnClose_Click(object sender, EventArgs e)
  124. {
  125. this.Close();
  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.dgvClassesSet.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
  135. this.dgvClassesDetail.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
  136. }
  137. /// <summary>
  138. /// 查询按钮
  139. /// </summary>
  140. /// <param name="sender"></param>
  141. /// <param name="e"></param>
  142. private void btnSearch_Click(object sender, EventArgs e)
  143. {
  144. try
  145. {
  146. this.GetDataGridViewInfo();
  147. // 记录当前选中行
  148. int selectRowIndex = this._selectedRowIndex;
  149. #region 选择原有行
  150. if (this.dgvClassesSet.Rows.Count > Constant.INT_IS_ZERO && selectRowIndex >= Constant.INT_IS_ZERO)
  151. {
  152. if (selectRowIndex >= ((DataTable)this.dgvClassesSet.DataSource).Rows.Count)
  153. {
  154. this.dgvClassesSet.Rows[this.dgvClassesSet.Rows.Count - 1].Selected = true;
  155. this.dgvClassesSet.CurrentCell = this.dgvClassesSet.Rows[this.dgvClassesSet.Rows.Count - 1].Cells["UserCode"];
  156. }
  157. else
  158. {
  159. this.dgvClassesSet.Rows[selectRowIndex].Selected = true;
  160. this.dgvClassesSet.CurrentCell = this.dgvClassesSet.Rows[selectRowIndex].Cells["UserCode"];
  161. }
  162. }
  163. #endregion
  164. }
  165. catch (Exception ex)
  166. {
  167. // 对异常进行共通处理
  168. ExceptionManager.HandleEventException(this.ToString(),
  169. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  170. }
  171. }
  172. /// <summary>
  173. /// 新建按钮
  174. /// </summary>
  175. /// <param name="sender"></param>
  176. /// <param name="e"></param>
  177. private void tsbtnAdd_Click(object sender, EventArgs e)
  178. {
  179. try
  180. {
  181. F_PC_0402 frmPC0402 = new F_PC_0402(Constant.FormMode.Add);
  182. DialogResult dialogresult = frmPC0402.ShowDialog();
  183. if (dialogresult.Equals(DialogResult.OK))
  184. {
  185. this.GetDataGridViewInfo();
  186. }
  187. }
  188. catch (Exception ex)
  189. {
  190. // 对异常进行共通处理
  191. ExceptionManager.HandleEventException(this.ToString(),
  192. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  193. }
  194. }
  195. /// <summary>
  196. /// 逻辑按钮
  197. /// </summary>
  198. /// <param name="sender"></param>
  199. /// <param name="e"></param>
  200. private void tsbtnEdit_Click(object sender, EventArgs e)
  201. {
  202. try
  203. {
  204. if (this.dgvClassesSet.CurrentRow != null)
  205. {
  206. int classesSettingID = Convert.ToInt32(this.dgvClassesSet.CurrentRow.Cells["ClassesSettingID"].Value.ToString());
  207. int userId = Convert.ToInt32(this.dgvClassesSet.CurrentRow.Cells["userId"].Value.ToString());
  208. F_PC_0402 frmPC0402 = new F_PC_0402(Constant.FormMode.Edit);
  209. frmPC0402.ClassesSettingID = classesSettingID;
  210. frmPC0402.UserId = userId;
  211. frmPC0402.UserCode = this.dgvClassesSet.CurrentRow.Cells["UserCode"].Value.ToString();
  212. frmPC0402.UserName1 = this.dgvClassesSet.CurrentRow.Cells["userName"].Value.ToString();
  213. frmPC0402.Remark = this.dgvClassesSet.CurrentRow.Cells["Remarks"].Value.ToString();
  214. frmPC0402.AccountDate = Convert.ToDateTime(this.dgvClassesSet.CurrentRow.Cells["AccountDate"].Value);
  215. DialogResult dialogresult = frmPC0402.ShowDialog();
  216. if (dialogresult.Equals(DialogResult.OK))
  217. {
  218. this.GetDataGridViewInfo();
  219. }
  220. }
  221. }
  222. catch (Exception ex)
  223. {
  224. // 对异常进行共通处理
  225. ExceptionManager.HandleEventException(this.ToString(),
  226. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  227. }
  228. }
  229. /// <summary>
  230. /// 单元格鼠标双击事件
  231. /// </summary>
  232. /// <param name="sender"></param>
  233. /// <param name="e"></param>
  234. private void dgvClassesSet_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
  235. {
  236. if (Constant.INT_IS_NEGATIE_ONE < e.RowIndex && Constant.INT_IS_NEGATIE_ONE < e.ColumnIndex && this.tsbtnEdit.Enabled && this.tsbtnEdit.Visible)
  237. {
  238. this.tsbtnEdit_Click(sender, e);
  239. }
  240. }
  241. /// <summary>
  242. /// 行选中事件
  243. /// </summary>
  244. /// <param name="sender"></param>
  245. /// <param name="e"></param>
  246. private void dgvClassesSet_SelectionChanged(object sender, EventArgs e)
  247. {
  248. try
  249. {
  250. // 在绑定总表时 不查询明细
  251. if (this.dgvClassesSet.CurrentCell == null && this.dgvClassesSet.Rows.Count > Constant.INT_IS_ZERO)
  252. {
  253. return;
  254. }
  255. // 选中行时查询明细
  256. else
  257. {
  258. if (this.dgvClassesSet.Rows.Count != Constant.INT_IS_ZERO)
  259. {
  260. if (!this.txtUserCode.ReadOnly)
  261. {
  262. int classesSettingID = Convert.ToInt32(this.dgvClassesSet.Rows[_selectedRowIndex].Cells["ClassesSettingID"].Value);
  263. DataSet result = (DataSet)DoAsync(() =>
  264. {
  265. return PCModuleProxy.Service.SearchClassesDetail(classesSettingID);
  266. });
  267. // 绑定明细数据
  268. this.dgvClassesDetail.DataSource = result.Tables[0];
  269. this.dgvClassesSet.Focus();
  270. }
  271. }
  272. }
  273. }
  274. catch (Exception ex)
  275. {
  276. // 对异常进行共通处理
  277. ExceptionManager.HandleEventException(this.ToString(),
  278. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  279. }
  280. }
  281. /// <summary>
  282. /// 清空条件按钮
  283. /// </summary>
  284. /// <param name="sender"></param>
  285. /// <param name="e"></param>
  286. private void btnClearCondition_Click(object sender, EventArgs e)
  287. {
  288. this.txtUserCode.Clear();
  289. this.txtRemarks.Clear();
  290. this.dtpStartSetDate.Value = DateTime.Now.Date;
  291. this.dtpEndSetDate.Value = DateTime.Now.Date;
  292. }
  293. #endregion
  294. #region 私有方法
  295. /// <summary>
  296. /// 获取工种调整信息
  297. /// </summary>
  298. private void GetDataGridViewInfo()
  299. {
  300. try
  301. {
  302. SearchClassesSettingEntity searchEntity = new SearchClassesSettingEntity();
  303. searchEntity.UserCode = this.txtUserCode.Text.Trim();
  304. searchEntity.StartAccountDate = this.dtpStartSetDate.Value.Date;
  305. searchEntity.EndAccountDate = this.dtpEndSetDate.Value.Date; //this.dtpStartSetDate.Value.Date.AddDays(1);
  306. searchEntity.Remarks = this.txtRemarks.Text.Trim();
  307. searchEntity.ValueFlag = Convert.ToInt32(Constant.ValueFlag.Effective);
  308. //查询
  309. DataSet dsResult = (DataSet)DoAsync(new AsyncMethod(() =>
  310. {
  311. return PCModuleProxy.Service.SearchClassesSetting(searchEntity);
  312. }));
  313. if (dsResult != null && dsResult.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
  314. {
  315. // 记录最后选择行
  316. int selectRowIndex = this._selectedRowIndex;
  317. this.dgvClassesSet.DataSource = dsResult.Tables[0];
  318. if (dsResult.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
  319. {
  320. // 定位当前行
  321. if (this.dgvClassesSet.Rows.Count > selectRowIndex)
  322. {
  323. this._selectedRowIndex = selectRowIndex;
  324. this.dgvClassesSet.Rows[selectRowIndex].Selected = true;
  325. }
  326. else if (this.dgvClassesSet.Rows.Count <= selectRowIndex)
  327. {
  328. this._selectedRowIndex = dgvClassesSet.Rows.Count - 1;
  329. this.dgvClassesSet.Rows[dgvClassesSet.Rows.Count - 1].Selected = true;
  330. }
  331. this.dgvClassesSet.ReadOnly = true;
  332. }
  333. }
  334. else
  335. {
  336. // 清空明细中的数据
  337. this.dgvClassesSet.DataSource = null;
  338. this.dgvClassesDetail.DataSource = null;
  339. // 提示未查找到数据
  340. MessageBox.Show(Messages.MSG_CMN_I002, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  341. }
  342. // 设置ToolStripButton按钮状态
  343. this.SetToolStripButtonEnable();
  344. }
  345. catch (Exception ex)
  346. {
  347. throw ex;
  348. }
  349. }
  350. /// <summary>
  351. /// 设置窗体按钮的文本信息
  352. /// </summary>
  353. private void SetFromTitleInfo()
  354. {
  355. this.Text = FormTitles.F_PC_0401;
  356. this.tsbtnAdd.Text = ButtonText.TSBTN_ADD;
  357. this.tsbtnEdit.Text = ButtonText.TSBTN_EDIT;
  358. this.tsbtnAdaptive.Text = ButtonText.TSBTN_ADAPTIVE;
  359. this.tsbtnClose.Text = ButtonText.TSBTN_CLOSE;
  360. this.btnSearch.Text = ButtonText.BTN_SEARCH;
  361. this.btnClearCondition.Text = ButtonText.BTN_CLEARCONDITION;
  362. this.gbxCondition.Text = Constant.LABEL_QUERY_CONDITIONS;
  363. }
  364. /// <summary>
  365. /// 设置工具按钮的可用状态
  366. /// </summary>
  367. /// <remarks>
  368. private void SetToolStripButtonEnable()
  369. {
  370. if (this.dgvClassesSet.CurrentCell != null)
  371. {
  372. this.tsbtnEdit.Enabled = true;
  373. }
  374. else
  375. {
  376. this.tsbtnEdit.Enabled = false;
  377. }
  378. }
  379. #endregion
  380. }
  381. }