frmTimesign.cs 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. using System.Windows.Forms;
  8. namespace LYFZ.Software.MainBusiness.TimeAndAttendance
  9. {
  10. public class frmTimesign : LYFZ.Software.UI.TimeAndAttendance.frmTimesign
  11. {
  12. LYFZ.BLL.BLL_ErpOrder orbll = new BLL.BLL_ErpOrder();
  13. LYFZ.BLL.BLL_Loginsign loginsign = new BLL.BLL_Loginsign();
  14. public frmTimesign()
  15. {
  16. this.Load += frmTimesign_Load;
  17. this.btncancel.Click += btncancel_Click;
  18. this.btnsign.Click += btnsign_Click;
  19. this.dtptimes.KeyDown += dtptimes_KeyDown;
  20. this.dtptimes.TextChanged += dtptimes_TextChanged;
  21. this.dtptimes.Leave += dtptimes_Leave;
  22. this.cmbTypes.SelectedIndexChanged += cmbTypes_SelectedIndexChanged;
  23. }
  24. /// <summary>
  25. /// 员工编号
  26. /// </summary>
  27. public string StrUserNumber = "";
  28. /// <summary>
  29. /// 员工姓名
  30. /// </summary>
  31. public string StrUserName = "";
  32. /// <summary>
  33. /// 是否保存
  34. /// </summary>
  35. public bool IsSaveed = false;
  36. /// <summary>
  37. /// 窗体加载事件
  38. /// </summary>
  39. /// <param name="sender"></param>
  40. /// <param name="e"></param>
  41. void frmTimesign_Load(object sender, EventArgs e)
  42. {
  43. this.txtname.Text = this.StrUserName;
  44. this.dtptimes.DateValue = SDateTime.Now.ToString("yyyy-MM-dd");
  45. this.txtprincipal.Text = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_Name;
  46. DataTable da = orbll.GetView_Custom("lonintimeset", StrWhere: "", ShowColumnName: "name").Tables[0];
  47. //for (int i = 0; i < da.Rows.Count; i++)
  48. //{ this.cmbTypes.Items.Add(da.Rows[i][0].ToString()); }
  49. //this.cmbTypes.Items.Add("全天(随班次)");
  50. //this.cmbTypes.Items.Add("第一班段(上班)");
  51. //this.cmbTypes.Items.Add("第一班段(下班)");
  52. //this.cmbTypes.Items.Add("第一班段(上下班)");
  53. //this.cmbTypes.Items.Add("第二班段(上班)");
  54. //this.cmbTypes.Items.Add("第二班段(下班)");
  55. //this.cmbTypes.Items.Add("第二班段(上下班)");
  56. this.dtptimes_Leave(this, null);
  57. this.GetSignSingle();
  58. }
  59. /// <summary>
  60. /// 获取签单记录
  61. /// </summary>
  62. void GetSignSingle()
  63. {
  64. DataTable dt = orbll.GetView_Custom("loginsign Left Join tb_ErpUser On User_Id = User_EmployeeID", StrWhere: "User_Id = '" + this.StrUserNumber + "' And Date like '" + SDateTime.Now.Year + "%'", ShowColumnName: "loginsign.id,User_Name AS 姓名,date AS 签单日期,type AS 签单班次,cleck AS 经手人", filedOrder: "Date DESC").Tables[0];
  65. this.dgvData.DataSource(dt, strHideField: "ID");
  66. }
  67. /// <summary>
  68. /// 签单
  69. /// </summary>
  70. /// <param name="sender"></param>
  71. /// <param name="e"></param>
  72. void btnsign_Click(object sender, EventArgs e)
  73. {
  74. if (string.IsNullOrEmpty(this.dtptimes.DateValue.Trim()))
  75. { MessageBoxCustom.Show("签单日期不能为空!"); return; }
  76. if (string.IsNullOrEmpty(this.cmbTypes.Text.Trim()))
  77. { MessageBoxCustom.Show("请选择签单类型!"); return; }
  78. DataTable da = orbll.GetView_Custom("tb_ErpUser", StrWhere: "User_EmployeeID='" + this.StrUserNumber + "'", ShowColumnName: "User_EmployeeID").Tables[0];
  79. if (da.Rows.Count > 0)
  80. {
  81. DataTable dtSign = orbll.GetView_Custom("loninbansets", StrWhere: "User_ID = '" + this.StrUserNumber + "' And Time = '" + this.dtptimes.DateValue.Trim() + " 00:00:00' And fixed = '休息'", ShowColumnName: "ID").Tables[0];
  82. if (dtSign.Rows.Count > 0)
  83. { MessageBoxCustom.Show(this.txtname.Text.Trim() + " '" + this.dtptimes.DateValue.Trim() + "' 休息,不用签单!"); return; }
  84. DataTable dt = orbll.GetView_Custom("loginsign", StrWhere: "User_Id = '" + this.StrUserNumber + "' And Date = '" + this.dtptimes.DateValue.Trim() + "' And Type = '" + this.cmbTypes.Text.Trim() + "'", ShowColumnName: "ID").Tables[0];
  85. if (dt.Rows.Count > 0)
  86. { MessageBoxCustom.Show("'" + this.dtptimes.DateValue.Trim() + "' 的'" + this.cmbTypes.Text.Trim() + "'已签过,不能重复签!"); return; }
  87. LYFZ.Model.Model_Loginsign Model = new Model.Model_Loginsign();
  88. Model.User_Id = this.StrUserNumber.Trim();
  89. Model.Name = this.txtname.Text.Trim();
  90. Model.Date = this.dtptimes.DateValue.Trim();
  91. Model.Type = this.cmbTypes.Text.Trim();
  92. Model.Cleck = this.txtprincipal.Text.Trim();
  93. if (MessageBoxCustom.Show("您确定要签单吗?", "温馨提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
  94. {
  95. if (loginsign.Add(Model))
  96. {
  97. this.IsSaveed = true;
  98. MessageBoxCustom.Show("签单成功!");
  99. this.GetSignSingle();
  100. }
  101. else
  102. { MessageBoxCustom.Show("签单失败!"); }
  103. }
  104. }
  105. else
  106. { MessageBoxCustom.Show("您选择的人员不存在,人员或已经被删除!"); }
  107. }
  108. /// <summary>
  109. /// 取消
  110. /// </summary>
  111. /// <param name="sender"></param>
  112. /// <param name="e"></param>
  113. void btncancel_Click(object sender, EventArgs e)
  114. { this.Close(); }
  115. /// <summary>
  116. /// 日期Text值改变事件
  117. /// </summary>
  118. /// <param name="sender"></param>
  119. /// <param name="e"></param>
  120. void dtptimes_TextChanged(object sender, EventArgs e)
  121. {
  122. this.dtptimes_Leave(this, null);
  123. }
  124. /// <summary>
  125. /// 日期回车事件
  126. /// </summary>
  127. /// <param name="sender"></param>
  128. /// <param name="e"></param>
  129. void dtptimes_KeyDown(object sender, KeyEventArgs e)
  130. {
  131. if (e.KeyCode == Keys.Enter)
  132. { this.dtptimes_Leave(this, null); }
  133. }
  134. /// <summary>
  135. /// 离开事件
  136. /// </summary>
  137. /// <param name="sender"></param>
  138. /// <param name="e"></param>
  139. void dtptimes_Leave(object sender, EventArgs e)
  140. {
  141. this.txtfixed.Text = "";
  142. this.cmbTypes.Items.Clear();
  143. if (!string.IsNullOrEmpty(this.dtptimes.DateValue.Trim()))
  144. {
  145. DataTable dt = orbll.GetView_Custom("loninbansets Left Join lonintimeset on name = fixed", StrWhere: "User_ID = '" + this.StrUserNumber + "' And Time = '" + Convert.ToDateTime(this.dtptimes.DateValue.Trim()).ToString("yyyy-MM-dd HH:mm:ss") + "'", ShowColumnName: "fixed,time1,time2,time3,time4").Tables[0];
  146. if (dt.Rows.Count > 0)
  147. {
  148. this.txtfixed.Text = dt.Rows[0]["fixed"].ToString().Trim();
  149. if (!string.IsNullOrEmpty(dt.Rows[0]["fixed"].ToString().Trim()) && dt.Rows[0]["fixed"].ToString().Trim() != "休息")
  150. {
  151. this.cmbTypes.Items.Add(LYFZ.EnumPublic.AttendanceSignType.StrAllDay.Trim());
  152. this.cmbTypes.Items.Add(LYFZ.EnumPublic.AttendanceSignType.StrFirstParagraph_GoToWork.Trim());
  153. this.cmbTypes.Items.Add(LYFZ.EnumPublic.AttendanceSignType.StrFirstParagraph_GoOffWork.Trim());
  154. this.cmbTypes.Items.Add(LYFZ.EnumPublic.AttendanceSignType.StrFirstParagraph_GoToAndOffWork.Trim());
  155. if (!string.IsNullOrEmpty(dt.Rows[0]["time3"].ToString().Trim()) && !string.IsNullOrEmpty(dt.Rows[0]["time4"].ToString().Trim()))
  156. {
  157. this.cmbTypes.Items.Add(LYFZ.EnumPublic.AttendanceSignType.StrSecondParagraph_GoToWork.Trim());
  158. this.cmbTypes.Items.Add(LYFZ.EnumPublic.AttendanceSignType.StrSecondParagraph_GoOffWork.Trim());
  159. this.cmbTypes.Items.Add(LYFZ.EnumPublic.AttendanceSignType.StrSecondParagraph_GoToAndOffWork.Trim());
  160. }
  161. }
  162. }
  163. }
  164. }
  165. /// <summary>
  166. /// 类型选择事件
  167. /// </summary>
  168. /// <param name="sender"></param>
  169. /// <param name="e"></param>
  170. void cmbTypes_SelectedIndexChanged(object sender, EventArgs e)
  171. {
  172. if (this.cmbTypes.Text.Trim() == "全天")
  173. { this.labelEx8.Visible = true; }
  174. else
  175. { this.labelEx8.Visible = false; }
  176. }
  177. }
  178. }