frmTimeupdate.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Data;
  6. using System.Data.SqlClient;
  7. namespace LYFZ.Software.MainBusiness.TimeAndAttendance
  8. {
  9. public class frmTimeupdate : LYFZ.Software.UI.TimeAndAttendance.frmTimeupdate
  10. {
  11. LYFZ.BLL.BLL_ErpOrder ordbll = new BLL.BLL_ErpOrder();
  12. LYFZ.BLL.BLL_Lonintimeset lonintimeset = new BLL.BLL_Lonintimeset();
  13. LYFZ.Model.Model_lonintimeset lonintime = new Model.Model_lonintimeset();
  14. public frmTimeupdate()
  15. {
  16. this.Load += frmTimeupdate_Load;
  17. this.btnClassCountAdd.Click += btnClassCountAdd_Click;
  18. this.btnClassCountUpdate.Click += btnClassCountUpdate_Click;
  19. this.btnClassCountDelete.Click += btnClassCountDelete_Click;
  20. this.dgvData.Click += dgvData_Click;
  21. }
  22. int CurrentRowIndex = 0;
  23. /// <summary>
  24. /// 程序第一次运行
  25. /// </summary>
  26. /// <param name="sender"></param>
  27. /// <param name="e"></param>
  28. private void frmTimeupdate_Load(object sender, EventArgs e)
  29. {
  30. this.dgvData.Rows.Clear();
  31. DataTable dt = ordbll.GetView_Custom("lonintimeset", StrWhere: "", ShowColumnName: "ID,name as 工作安排,time1 as 上班时间,time2 as 下班时间,time3 as 上班时间2,time4 as 下班时间2").Tables[0];
  32. this.dgvData.DataSource(dt, strHideField: "ID");
  33. this.dgvData.ClearSelection();
  34. this.GetClear();
  35. }
  36. /// <summary>
  37. /// 添加数据、修改数据
  38. /// </summary>
  39. /// <param name="sender"></param>
  40. /// <param name="e"></param>
  41. private void btnClassCountAdd_Click(object sender, EventArgs e)
  42. {
  43. string StrClassName = this.txtClassName.Text.Trim();
  44. string StrFirstTimeStart = "";
  45. string StrFirstTimeEnd = "";
  46. string StrSecondTimeStart = "";
  47. string StrSecondTimeEnd = "";
  48. if (string.IsNullOrEmpty(StrClassName))
  49. { MessageBoxCustom.Show("班次名称不能为空!"); return; }
  50. else if (StrClassName.Trim()=="休息")
  51. { MessageBoxCustom.Show("班次名称'休息'为系统默认名称,不能取名与系统默认名称重复!"); return; }
  52. if (this.mskFirstTimeStart.Text.Trim() != ":")
  53. {
  54. try { DateTime ssa = Convert.ToDateTime(SDateTime.Now.ToString("yyyy-MM-dd") + " " + this.mskFirstTimeStart.Text.Trim()); }
  55. catch { MessageBoxCustom.Show("第一班段的上班时间不是有效时间格式"); this.mskFirstTimeStart.Text = ""; return; }
  56. StrFirstTimeStart = this.mskFirstTimeStart.Text.Trim();
  57. }
  58. if (this.mskFirstTimeEnd.Text.Trim() != ":")
  59. {
  60. try { DateTime ssa = Convert.ToDateTime(SDateTime.Now.ToString("yyyy-MM-dd") + " " + this.mskFirstTimeEnd.Text.Trim()); }
  61. catch { MessageBoxCustom.Show("第一班段的下班时间不是有效时间格式"); this.mskFirstTimeEnd.Text = ""; return; }
  62. StrFirstTimeEnd = this.mskFirstTimeEnd.Text.Trim();
  63. }
  64. if (this.mskSecondTimeStart.Text.Trim() != ":")
  65. {
  66. try { DateTime ssa = Convert.ToDateTime(SDateTime.Now.ToString("yyyy-MM-dd") + " " + this.mskSecondTimeStart.Text.Trim()); }
  67. catch { MessageBoxCustom.Show("第二班段的上班时间不是有效时间格式"); this.mskSecondTimeStart.Text = ""; return; }
  68. StrSecondTimeStart = this.mskSecondTimeStart.Text.Trim();
  69. }
  70. if (this.mskSecondTimeEnd.Text.Trim() != ":")
  71. {
  72. try { DateTime ssa = Convert.ToDateTime(SDateTime.Now.ToString("yyyy-MM-dd") + " " + this.mskSecondTimeEnd.Text.Trim()); }
  73. catch { MessageBoxCustom.Show("第二班段的下班时间不是有效时间格式"); this.mskSecondTimeEnd.Text = ""; return; }
  74. StrSecondTimeEnd = this.mskSecondTimeEnd.Text.Trim();
  75. }
  76. if (string.IsNullOrEmpty(StrFirstTimeStart) && string.IsNullOrEmpty(StrFirstTimeEnd))
  77. { MessageBoxCustom.Show("第一班段上下班时间不能为空!"); return; }
  78. else if (string.IsNullOrEmpty(StrFirstTimeStart) && !string.IsNullOrEmpty(StrFirstTimeEnd))
  79. { MessageBoxCustom.Show("第一班段上班时间不能为空!"); return; }
  80. else if (!string.IsNullOrEmpty(StrFirstTimeStart) && string.IsNullOrEmpty(StrFirstTimeEnd))
  81. { MessageBoxCustom.Show("第一班段下班时间不能为空!"); return; }
  82. else if (Convert.ToDateTime(SDateTime.Now.ToString("yyyy-MM-dd") + " " + StrFirstTimeStart + ":00") >= Convert.ToDateTime(SDateTime.Now.ToString("yyyy-MM-dd") + " " + StrFirstTimeEnd + ":00"))
  83. { MessageBoxCustom.Show("第一班段的下班时间不能早于上班时间"); return; }
  84. if (string.IsNullOrEmpty(StrSecondTimeStart) && !string.IsNullOrEmpty(StrSecondTimeEnd))
  85. { MessageBoxCustom.Show("第二班段不能只填上班班时间!"); return; }
  86. else if (!string.IsNullOrEmpty(StrSecondTimeStart) && string.IsNullOrEmpty(StrSecondTimeEnd))
  87. { MessageBoxCustom.Show("第二班段不能只填下班时间!"); return; }
  88. else if (!string.IsNullOrEmpty(StrSecondTimeStart) && !string.IsNullOrEmpty(StrSecondTimeEnd))
  89. {
  90. if (Convert.ToDateTime(SDateTime.Now.ToString("yyyy-MM-dd") + " " + StrSecondTimeStart + ":00") >= Convert.ToDateTime(SDateTime.Now.ToString("yyyy-MM-dd") + " " + StrSecondTimeEnd + ":00"))
  91. { MessageBoxCustom.Show("第二班段的下班时间不能早于上班时间"); return; }
  92. if (Convert.ToDateTime(SDateTime.Now.ToString("yyyy-MM-dd") + " " + StrSecondTimeStart + ":00") <= Convert.ToDateTime(SDateTime.Now.ToString("yyyy-MM-dd") + " " + StrFirstTimeEnd + ":00"))
  93. { MessageBoxCustom.Show("第二班段的上班时间不能早于第一班段的下班时间!"); return; }
  94. }
  95. if (!string.IsNullOrEmpty(StrFirstTimeStart) && !string.IsNullOrEmpty(StrFirstTimeEnd))
  96. {
  97. if (this.CurrentRowIndex > 0)
  98. {
  99. DataTable dt = ordbll.GetView_Custom("lonintimeset", StrWhere: "ID != '" + this.CurrentRowIndex + "' And name = '" + StrClassName + "'", ShowColumnName: "*").Tables[0];
  100. if (dt.Rows.Count > 0)
  101. { MessageBoxCustom.Show("班次名称已存在,不能重复添加班次!"); return; }
  102. dt = ordbll.GetView_Custom("lonintimeset", StrWhere: "ID = '" + this.CurrentRowIndex + "'", ShowColumnName: "*").Tables[0];
  103. LYFZ.Model.Model_lonintimeset model = lonintimeset.DataRowToModel(dt.Rows[0]);
  104. model.Name = StrClassName;
  105. model.Time1 = StrFirstTimeStart;
  106. model.Time2 = StrFirstTimeEnd;
  107. model.Time3 = StrSecondTimeStart;
  108. model.Time4 = StrSecondTimeEnd;
  109. if (MessageBoxCustom.Show("您确定要修改吗?", "温馨提示", System.Windows.Forms.MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
  110. {
  111. if (lonintimeset.Update(model))
  112. {
  113. MessageBoxCustom.Show("修改成功!");
  114. this.frmTimeupdate_Load(this, null);
  115. }
  116. else
  117. { MessageBoxCustom.Show("修改失败!"); }
  118. }
  119. }
  120. else
  121. {
  122. if (!lonintimeset.Exists("name", StrClassName))
  123. {
  124. LYFZ.Model.Model_lonintimeset model = new Model.Model_lonintimeset();
  125. model.Name = StrClassName;
  126. model.Time1 = StrFirstTimeStart;
  127. model.Time2 = StrFirstTimeEnd;
  128. model.Time3 = StrSecondTimeStart;
  129. model.Time4 = StrSecondTimeEnd;
  130. if (MessageBoxCustom.Show("您确定要添加吗?", "温馨提示", System.Windows.Forms.MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
  131. {
  132. if (lonintimeset.Add(model))
  133. {
  134. MessageBoxCustom.Show("添加成功!");
  135. this.frmTimeupdate_Load(this, null);
  136. }
  137. else
  138. { MessageBoxCustom.Show("添加失败!"); }
  139. }
  140. }
  141. else
  142. { MessageBoxCustom.Show("班次名称已存在,不能重复添加班次!"); }
  143. }
  144. }
  145. else
  146. { MessageBoxCustom.Show("数据不满足条件,数据添加失败!"); }
  147. }
  148. /// <summary>
  149. /// 新建
  150. /// </summary>
  151. /// <param name="sender"></param>
  152. /// <param name="e"></param>
  153. private void btnClassCountUpdate_Click(object sender, EventArgs e)
  154. {
  155. this.GetClear();
  156. }
  157. /// <summary>
  158. /// 删除数据
  159. /// </summary>
  160. /// <param name="sender"></param>
  161. /// <param name="e"></param>
  162. private void btnClassCountDelete_Click(object sender, EventArgs e)
  163. {
  164. if (this.CurrentRowIndex > 0)
  165. {
  166. if (MessageBoxCustom.Show("您确定要删除吗?", "温馨提示", System.Windows.Forms.MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
  167. {
  168. if (lonintimeset.Delete(this.CurrentRowIndex))
  169. {
  170. MessageBoxCustom.Show("删除成功!");
  171. this.frmTimeupdate_Load(this, null);
  172. }
  173. else
  174. { MessageBoxCustom.Show("删除失败!"); }
  175. }
  176. }
  177. else
  178. { MessageBoxCustom.Show("没选中数据,数据删除失败!"); }
  179. }
  180. /// <summary>
  181. /// 点击获取数据
  182. /// </summary>
  183. /// <param name="sender"></param>
  184. /// <param name="e"></param>
  185. private void dgvData_Click(object sender, EventArgs e)
  186. {
  187. if (this.dgvData.CurrentCell.ColumnIndex >= 0 && this.dgvData.CurrentCell.RowIndex >= 0)
  188. {
  189. this.CurrentRowIndex = Convert.ToInt32(this.dgvData.CurrentRow.Cells["ID"].Value); ;
  190. this.txtClassName.Text = this.dgvData.CurrentRow.Cells["工作安排"].Value.ToString().Trim();
  191. this.mskFirstTimeStart.Text = this.dgvData.CurrentRow.Cells["上班时间"].Value.ToString().Trim();
  192. this.mskFirstTimeEnd.Text = this.dgvData.CurrentRow.Cells["下班时间"].Value.ToString().Trim();
  193. this.mskSecondTimeStart.Text = this.dgvData.CurrentRow.Cells["上班时间2"].Value.ToString().Trim();
  194. this.mskSecondTimeEnd.Text = this.dgvData.CurrentRow.Cells["下班时间2"].Value.ToString().Trim();
  195. this.btnClassCountAdd.Text = " 修改班次";
  196. this.btnClassCountDelete.Enabled = true;
  197. }
  198. }
  199. /// <summary>
  200. /// 清除值
  201. /// </summary>
  202. void GetClear()
  203. {
  204. this.CurrentRowIndex = 0;
  205. this.txtClassName.Text = "";
  206. this.mskFirstTimeStart.Text = "";
  207. this.mskSecondTimeStart.Text = "";
  208. this.mskFirstTimeEnd.Text = "";
  209. this.mskSecondTimeEnd.Text = "";
  210. this.btnClassCountAdd.Text = " 添加班次";
  211. this.btnClassCountDelete.Enabled = false;
  212. }
  213. }
  214. }