123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Data;
- using System.Data.SqlClient;
- using System.Windows.Forms;
- namespace LYFZ.Software.MainBusiness.TimeAndAttendance
- {
- public class frmTimesign : LYFZ.Software.UI.TimeAndAttendance.frmTimesign
- {
- LYFZ.BLL.BLL_ErpOrder orbll = new BLL.BLL_ErpOrder();
- LYFZ.BLL.BLL_Loginsign loginsign = new BLL.BLL_Loginsign();
- public frmTimesign()
- {
- this.Load += frmTimesign_Load;
- this.btncancel.Click += btncancel_Click;
- this.btnsign.Click += btnsign_Click;
- this.dtptimes.KeyDown += dtptimes_KeyDown;
- this.dtptimes.TextChanged += dtptimes_TextChanged;
- this.dtptimes.Leave += dtptimes_Leave;
- this.cmbTypes.SelectedIndexChanged += cmbTypes_SelectedIndexChanged;
- }
- /// <summary>
- /// 员工编号
- /// </summary>
- public string StrUserNumber = "";
- /// <summary>
- /// 员工姓名
- /// </summary>
- public string StrUserName = "";
- /// <summary>
- /// 是否保存
- /// </summary>
- public bool IsSaveed = false;
- /// <summary>
- /// 窗体加载事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void frmTimesign_Load(object sender, EventArgs e)
- {
- this.txtname.Text = this.StrUserName;
- this.dtptimes.DateValue = SDateTime.Now.ToString("yyyy-MM-dd");
- this.txtprincipal.Text = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_Name;
- DataTable da = orbll.GetView_Custom("lonintimeset", StrWhere: "", ShowColumnName: "name").Tables[0];
- //for (int i = 0; i < da.Rows.Count; i++)
- //{ this.cmbTypes.Items.Add(da.Rows[i][0].ToString()); }
- //this.cmbTypes.Items.Add("全天(随班次)");
- //this.cmbTypes.Items.Add("第一班段(上班)");
- //this.cmbTypes.Items.Add("第一班段(下班)");
- //this.cmbTypes.Items.Add("第一班段(上下班)");
- //this.cmbTypes.Items.Add("第二班段(上班)");
- //this.cmbTypes.Items.Add("第二班段(下班)");
- //this.cmbTypes.Items.Add("第二班段(上下班)");
- this.dtptimes_Leave(this, null);
- this.GetSignSingle();
- }
- /// <summary>
- /// 获取签单记录
- /// </summary>
- void GetSignSingle()
- {
- 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];
- this.dgvData.DataSource(dt, strHideField: "ID");
- }
- /// <summary>
- /// 签单
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void btnsign_Click(object sender, EventArgs e)
- {
- if (string.IsNullOrEmpty(this.dtptimes.DateValue.Trim()))
- { MessageBoxCustom.Show("签单日期不能为空!"); return; }
- if (string.IsNullOrEmpty(this.cmbTypes.Text.Trim()))
- { MessageBoxCustom.Show("请选择签单类型!"); return; }
- DataTable da = orbll.GetView_Custom("tb_ErpUser", StrWhere: "User_EmployeeID='" + this.StrUserNumber + "'", ShowColumnName: "User_EmployeeID").Tables[0];
- if (da.Rows.Count > 0)
- {
- 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];
- if (dtSign.Rows.Count > 0)
- { MessageBoxCustom.Show(this.txtname.Text.Trim() + " '" + this.dtptimes.DateValue.Trim() + "' 休息,不用签单!"); return; }
- 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];
- if (dt.Rows.Count > 0)
- { MessageBoxCustom.Show("'" + this.dtptimes.DateValue.Trim() + "' 的'" + this.cmbTypes.Text.Trim() + "'已签过,不能重复签!"); return; }
- LYFZ.Model.Model_Loginsign Model = new Model.Model_Loginsign();
- Model.User_Id = this.StrUserNumber.Trim();
- Model.Name = this.txtname.Text.Trim();
- Model.Date = this.dtptimes.DateValue.Trim();
- Model.Type = this.cmbTypes.Text.Trim();
- Model.Cleck = this.txtprincipal.Text.Trim();
- if (MessageBoxCustom.Show("您确定要签单吗?", "温馨提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
- {
- if (loginsign.Add(Model))
- {
- this.IsSaveed = true;
- MessageBoxCustom.Show("签单成功!");
- this.GetSignSingle();
- }
- else
- { MessageBoxCustom.Show("签单失败!"); }
- }
- }
- else
- { MessageBoxCustom.Show("您选择的人员不存在,人员或已经被删除!"); }
- }
- /// <summary>
- /// 取消
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void btncancel_Click(object sender, EventArgs e)
- { this.Close(); }
- /// <summary>
- /// 日期Text值改变事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void dtptimes_TextChanged(object sender, EventArgs e)
- {
- this.dtptimes_Leave(this, null);
- }
- /// <summary>
- /// 日期回车事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void dtptimes_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Enter)
- { this.dtptimes_Leave(this, null); }
- }
- /// <summary>
- /// 离开事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void dtptimes_Leave(object sender, EventArgs e)
- {
- this.txtfixed.Text = "";
- this.cmbTypes.Items.Clear();
- if (!string.IsNullOrEmpty(this.dtptimes.DateValue.Trim()))
- {
- 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];
- if (dt.Rows.Count > 0)
- {
- this.txtfixed.Text = dt.Rows[0]["fixed"].ToString().Trim();
- if (!string.IsNullOrEmpty(dt.Rows[0]["fixed"].ToString().Trim()) && dt.Rows[0]["fixed"].ToString().Trim() != "休息")
- {
- this.cmbTypes.Items.Add(LYFZ.EnumPublic.AttendanceSignType.StrAllDay.Trim());
- this.cmbTypes.Items.Add(LYFZ.EnumPublic.AttendanceSignType.StrFirstParagraph_GoToWork.Trim());
- this.cmbTypes.Items.Add(LYFZ.EnumPublic.AttendanceSignType.StrFirstParagraph_GoOffWork.Trim());
- this.cmbTypes.Items.Add(LYFZ.EnumPublic.AttendanceSignType.StrFirstParagraph_GoToAndOffWork.Trim());
- if (!string.IsNullOrEmpty(dt.Rows[0]["time3"].ToString().Trim()) && !string.IsNullOrEmpty(dt.Rows[0]["time4"].ToString().Trim()))
- {
- this.cmbTypes.Items.Add(LYFZ.EnumPublic.AttendanceSignType.StrSecondParagraph_GoToWork.Trim());
- this.cmbTypes.Items.Add(LYFZ.EnumPublic.AttendanceSignType.StrSecondParagraph_GoOffWork.Trim());
- this.cmbTypes.Items.Add(LYFZ.EnumPublic.AttendanceSignType.StrSecondParagraph_GoToAndOffWork.Trim());
- }
- }
- }
- }
- }
- /// <summary>
- /// 类型选择事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void cmbTypes_SelectedIndexChanged(object sender, EventArgs e)
- {
- if (this.cmbTypes.Text.Trim() == "全天")
- { this.labelEx8.Visible = true; }
- else
- { this.labelEx8.Visible = false; }
- }
- }
- }
|