using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; using System.Data; using System.Data.SqlClient; using System.Data.OleDb; using System.Drawing; using LYFZ.ComponentLibrary; using System.Collections; namespace LYFZ.Software.MainBusiness.TimeAndAttendance { public class frmTimeMain : LYFZ.Software.UI.TimeAndAttendance.frmTimeMain { LYFZ.BLL.BLL_ErpOrder orbll = new BLL.BLL_ErpOrder(); LYFZ.BLL.BLL_Loninbansets lbsetbll = new BLL.BLL_Loninbansets(); public frmTimeMain() { this.Load += frmTimeMain_Load; this.btnLastWeek.Click += btnLastWeek_Click; this.btnNextWeek.Click += btnNextWeek_Click; this.btnEmployeeSchedule.Click += btnEmployeeSchedule_Click; this.btnSaveModule.Click += btnSaveModule_Click; this.btnGetModule.Click += btnGetModule_Click; this.btnSaveed.Click += btnSaveed_Click; this.btnTimeSet.Click += btnTimeSet_Click; this.btnSigned.Click += btnSigned_Click; this.btnSignedRecords.Click += btnSignedRecords_Click; this.btnClose.Click += btnClose_Click; this.dtpYearMonth.ClickChengedValue += dtpYearMonth_ClickChengedValue; this.chkWeekMode.Click += chkzhouyue_Click; this.cmbtreev.Leave += cmbtreev_Leave; this.dgvData.CellDoubleClick += dgvData_CellDoubleClick; this.dgvData.CellMouseDown += dgvData_CellMouseDown; this.dgvData.DataGridViewConMenu_ItemClicked += dgvData_DataGridViewConMenu_ItemClicked; this.dgvData.Scroll += dgvData_Scroll; this.Resize += frmTimeMain_Resize; //BindCompanyList(); cbxCompanyList.ComboBoxTree_NodeMouseClick += CbxCompanyList_ComboBoxTree_NodeMouseClick; } private void CbxCompanyList_ComboBoxTree_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) { this.GetQueryMonthData(); } DateTime WeekStartDate; DateTime WeekEndDate; string StrTextName = ""; /// /// 窗体加载事件 /// /// /// void frmTimeMain_Load(object sender, EventArgs e) { this.panelLastNextWeek.Visible = false; Control.CheckForIllegalCrossThreadCalls = false; this.dgvData.dgvColumnHeadersHeight = 35; this.dtpYearMonth.StrDateValue = SDateTime.Now.ToString("yyyy-MM"); #region 获取本周 this.WeekStartDate = SDateTime.Now.AddDays(Convert.ToInt32(SDateTime.Now.DayOfWeek) * -1); this.WeekEndDate = SDateTime.Now.AddDays(6 - Convert.ToInt32(SDateTime.Now.DayOfWeek)); #endregion StrTextName = "休息,请假,"; DataTable dat = orbll.GetView_Custom("lonintimeset", StrWhere: "", ShowColumnName: "name").Tables[0]; for (int cmb = 0; cmb < dat.Rows.Count; cmb++) { StrTextName += dat.Rows[cmb]["name"].ToString().Trim() + ","; } // 部门人员绑定 LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.BindComboBoxTreeView_DepartmentAndEmployee(this.cbxCompanyList, IsFirstNodeNull: true, IsFirstNodeName: "全部", IsShowResign: false, IsShowAdmin: true, tb_User: LYFZ.DAL.DAL_ErpUser.SimpleUserDataTable); this.cbxCompanyList.AfterSelectLevelFirstNode = true; this.cbxCompanyList.IsNodeMouseClick = true; this.cbxCompanyList.IsSelectParentNode = true; cbxCompanyList.TextFindTag("全部"); this.GetQueryMonthData(); bool b = LYFZ.Software.MainBusiness.VersionControl.StaticVersion.UIFunctionVersion( VersionControl.VersionFunctionEnum.员工考勤考勤管理); if (!b) { this.Close(); } } void BindCompanyList() { BLL.BLL_ErpCompanyInfo bllCompany = new BLL.BLL_ErpCompanyInfo(); DataTable dt = bllCompany.GetAllList().Tables[0]; cbxCompanyList.Items.Add(new ItemValue("", "全部")); foreach(DataRow dr in dt.Rows) { cbxCompanyList.Items.Add(new ItemValue(dr["Company_DividedShop"].ToString(), dr["Company_Name"].ToString_s())); } cbxCompanyList.SelectedIndex = 0; } /// /// 上星期 /// /// /// void btnLastWeek_Click(object sender, EventArgs e) { this.WeekStartDate = this.WeekStartDate.AddDays(-7); this.WeekEndDate = this.WeekEndDate.AddDays(-7); this.GetQueryWeekData(); this.GetWeekCount(); } /// /// 下星期 /// /// /// void btnNextWeek_Click(object sender, EventArgs e) { this.WeekStartDate = this.WeekStartDate.AddDays(7); this.WeekEndDate = this.WeekEndDate.AddDays(7); this.GetQueryWeekData(); this.GetWeekCount(); } /// /// 员工档期 /// /// /// void btnEmployeeSchedule_Click(object sender, EventArgs e) { LYFZ.Software.MainBusiness.CameraControlBook.SmallForm.A_EmployeeScheduleSmallForm frm = new CameraControlBook.SmallForm.A_EmployeeScheduleSmallForm(); frm.StartPosition = System.Windows.Forms.FormStartPosition.Manual; frm.Location = new Point(LYFZ.EnumPublic.FormLocation_X, LYFZ.EnumPublic.FormLocation_Y); frm.Size = new Size(LYFZ.EnumPublic.FormSize_Width, LYFZ.EnumPublic.FormSize_Height); frm.ShowDialog(); } /// /// 存为模板 /// /// /// void btnSaveModule_Click(object sender, EventArgs e) { string StrModelName = "考勤排班模板(月)"; string StrExtension = ".Mban"; if (this.chkWeekMode.Checked) { StrModelName = "考勤排班模板(周)"; StrExtension = ".Wban"; } DataTable NewTable = this.dgvData.ToDataTable(IsShowVisible: true); SaveFileDialog saveFile = new SaveFileDialog(); saveFile.FileName = StrModelName; saveFile.Title = "存排班模板"; saveFile.Filter = "文件ban |*" + StrExtension; saveFile.FilterIndex = 1; DialogResult drst = saveFile.ShowDialog(); if (drst == DialogResult.No || drst == DialogResult.Cancel || drst == DialogResult.No || drst == DialogResult.Abort) { return; } string StrPath = saveFile.FileName.Trim().Replace(StrExtension, ""); //if (LYFZ.Command.Command_ExportExcel.DataTable2Sheet(StrPath + ".xls", NewTable, "Sheet1", IsCoveredExistingFile: true)) //{ // string StrSrcPath = StrPath + ".xls"; // string StrDesPath = saveFile.FileName.Trim(); // if (File.Exists(StrSrcPath)) // { // if (File.Exists(StrDesPath)) // { // try // { File.Delete(StrDesPath); } // catch // { MessageBoxCustom.Show("存模板失败!"); return; } // } // FileInfo fi = new FileInfo(StrSrcPath); // try // { // fi.MoveTo(StrDesPath); // MessageBoxCustom.Show("存模板成功!"); // } // catch // { // File.Delete(StrSrcPath); // MessageBoxCustom.Show("存模板失败!"); // return; // } // } // else // { MessageBoxCustom.Show("存模板失败!"); } //} //else //{ MessageBoxCustom.Show("存模板失败!"); } LYFZ.ComponentLibrary.FrmLoadHandling.ExecutionDoWorkMethod(delegate (object obj, System.ComponentModel.BackgroundWorker backgroundWorker) { try { if (LYFZ.WinAPI.CustomPublicMethod.DataGridViewToExcel(StrPath + ".xls", NewTable, null, backgroundWorker)) { string StrSrcPath = StrPath + ".xls"; string StrDesPath = saveFile.FileName.Trim(); if (File.Exists(StrSrcPath)) { if (File.Exists(StrDesPath)) { try { File.Delete(StrDesPath); } catch { MessageBoxCustom.Show("存模板失败!"); return; } } FileInfo fi = new FileInfo(StrSrcPath); try { fi.MoveTo(StrDesPath); MessageBoxCustom.Show("存模板成功!"); } catch { File.Delete(StrSrcPath); MessageBoxCustom.Show("存模板失败!"); return; } } else { MessageBoxCustom.Show("存模板失败!"); } } else { MessageBoxCustom.Show("存模板失败!"); } } catch (Exception ex) { MessageBoxCustom.Show(String.Format("导出数据出错:{0}", ex.Message)); } }); } /// /// 读取模板 /// /// /// void btnGetModule_Click(object sender, EventArgs e) { string StrExtension = ".Mban"; if (this.chkWeekMode.Checked) { StrExtension = ".Wban"; } OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.Filter = "文件ban |*" + StrExtension; if (openFileDialog1.ShowDialog() == DialogResult.OK) { this.dgvData.Rows.Clear(); DataGridViewRow dgvr = null; DataGridViewCell cell = null; DataTable dtPerson = orbll.GetView_Custom("tb_ErpUser", StrWhere: "User_Status='在职'", ShowColumnName: "User_EmployeeID,User_Name").Tables[0]; DataTable dtExcel = LYFZ.WinAPI.CustomPublicMethod.GetExcelDatatable(openFileDialog1.FileName.Trim()); string StrWhere = ""; if (this.chkWeekMode.Checked) { StrWhere = LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.GetDateTime("Time", this.WeekStartDate.ToString("yyyy-MM-dd"), this.WeekEndDate.ToString("yyyy-MM-dd")); } else { string StrDateStart = this.dtpYearMonth.StrDateValue.Trim() + "-01"; string StrDateEnd = Convert.ToDateTime(StrDateStart).AddMonths(1).AddSeconds(-1).ToString("yyyy-MM-dd"); StrWhere = LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.GetDateTime("Time", StrDateStart, StrDateEnd); } DataTable dt = this.GetWorkPerson(); if (dtPerson.Rows.Count > 0) { for (int i = 0; i < dtPerson.Rows.Count; i++) { dgvr = new DataGridViewRow(); cell = new DataGridViewTextBoxCell(); cell.Value = dtPerson.Rows[i]["User_EmployeeID"].ToString().Trim(); dgvr.Cells.Add(cell); cell = new DataGridViewTextBoxCell(); cell.Value = dtPerson.Rows[i]["User_Name"].ToString().Trim(); dgvr.Cells.Add(cell); DataRow[] dtRows = dtExcel.Select("员工编号 = '" + dtPerson.Rows[i]["User_EmployeeID"].ToString().Trim() + "'"); for (int j = 2; j < this.dgvData.Columns.Count; j++) { string StrCellValue = ""; if (dtRows.Length > 0) { if (j < dtExcel.Columns.Count) { if (!string.IsNullOrEmpty(dtRows[0][j].ToString().Trim())) { StrCellValue = dtRows[0][j].ToString().Trim(); } } } cell = new DataGridViewTextBoxCell(); cell.Value = StrCellValue.Trim(); if (StrCellValue.Trim() == "休息") { string StrWhereDate = ""; if (this.chkWeekMode.Checked) { StrWhereDate = this.WeekStartDate.AddDays((j - 2)).ToString("yyyy-MM-dd"); } else { StrWhereDate = Convert.ToDateTime(this.dtpYearMonth.StrDateValue.Trim() + "-01").AddDays((j - 2)).ToString("yyyy-MM-dd"); } DataRow[] dtRows2 = dt.Select("工作人员 = '" + dtPerson.Rows[i]["User_EmployeeID"].ToString().Trim() + "' And 工作日期 = '" + StrWhereDate + "'"); if (dtRows2.Length > 0) { cell.Style.BackColor = Color.Red; } } dgvr.Cells.Add(cell); } this.dgvData.Rows.Add(dgvr); } } } } /// /// 获取人员 /// /// DataTable GetWorkPerson() { string StrDateStart = this.dtpYearMonth.StrDateValue.Trim() + "-01"; string StrDateEnd = Convert.ToDateTime(StrDateStart).AddMonths(1).AddSeconds(-1).ToString("yyyy-MM-dd"); if (this.chkWeekMode.Checked) { StrDateStart = this.WeekStartDate.ToString("yyyy-MM-dd"); StrDateEnd = this.WeekEndDate.ToString("yyyy-MM-dd"); } string StrWhere = " Where" + LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.GetDateTime("Convert(datetime,工作日期)", StrDateStart, StrDateEnd, ConnectWord: ""); return this.GetWorkPerson(StrWhere); } /// /// 获取人员的DataTable /// /// DataTable GetWorkPerson(string StrWhere) { string ExecuteSql = "with t AS ( " + "select Ordpg_ReservationPhotographyName AS 工作人员,dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ordpg_ReservationPhotographyTime)) AS 工作日期 from tb_ErpOrdersPhotography Where Ordpg_ReservationPhotographyName != '' And Ordpg_ReservationPhotographyTime is not null " + "UNION ALL " + "select Ordpg_ReservationPhotographyAssistant AS 工作人员,dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ordpg_ReservationPhotographyTime)) AS 工作日期 from tb_ErpOrdersPhotography Where Ordpg_ReservationPhotographyAssistant != '' And Ordpg_ReservationPhotographyTime is not null " + "UNION ALL " + "select Ordpg_ReservationMakeupArtist AS 工作人员,dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ordpg_ReservationPhotographyTime)) AS 工作日期 from tb_ErpOrdersPhotography Where Ordpg_ReservationMakeupArtist != '' And Ordpg_ReservationPhotographyTime is not null " + "UNION ALL " + "select Ordpg_ReservationMakeupAssistant AS 工作人员,dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ordpg_ReservationPhotographyTime)) AS 工作日期 from tb_ErpOrdersPhotography Where Ordpg_ReservationMakeupAssistant != '' And Ordpg_ReservationPhotographyTime is not null " + "UNION ALL " + "select Ordpg_ReservationBootDivision AS 工作人员,dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ordpg_ReservationPhotographyTime)) AS 工作日期 from tb_ErpOrdersPhotography Where Ordpg_ReservationBootDivision != '' And Ordpg_ReservationPhotographyTime is not null " + "UNION ALL " + "select Ordpg_ReservationBootDivisionAssistant AS 工作人员,dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ordpg_ReservationPhotographyTime)) AS 工作日期 from tb_ErpOrdersPhotography Where Ordpg_ReservationBootDivisionAssistant != '' And Ordpg_ReservationPhotographyTime is not null " + "UNION ALL " + "select Ordv_ReservationClothingName AS 工作人员,dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ordv_ReservationClothingTime)) AS 工作日期 from tb_ErpOrderDigital Where Ordv_ReservationClothingName != '' And Ordv_ReservationClothingTime is not null " + "UNION ALL " + "select Ordv_ReservationEarlyRepairName AS 工作人员,dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ordv_ReservationEarlyRepairTime)) AS 工作日期 from tb_ErpOrderDigital Where Ordv_ReservationEarlyRepairName != '' And Ordv_ReservationEarlyRepairTime is not null " + "UNION ALL " + "select Ordv_ReservationFilmSelectionName AS 工作人员,dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ordv_ReservationFilmSelectionTime)) AS 工作日期 from tb_ErpOrderDigital Where Ordv_ReservationFilmSelectionName != '' And Ordv_ReservationFilmSelectionTime is not null " + "UNION ALL " + "select Ordv_ReservationRefinementName AS 工作人员,dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ordv_ReservationRefinementTime)) AS 工作日期 from tb_ErpOrderDigital Where Ordv_ReservationRefinementName != '' And Ordv_ReservationRefinementTime is not null " + "UNION ALL " + "select Ordv_ReservationDesignerName AS 工作人员,dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ordv_ReservationDesignerTime)) AS 工作日期 from tb_ErpOrderDigital Where Ordv_ReservationDesignerName != '' And Ordv_ReservationDesignerTime is not null " + "UNION ALL " + "select Ordv_ReservationLookDesignName AS 工作人员,dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ordv_ReservationLookDesignTime)) AS 工作日期 from tb_ErpOrderDigital Where Ordv_ReservationLookDesignName != '' And Ordv_ReservationLookDesignTime is not null " + "UNION ALL " + "select Ordv_ReservationSendPhotoName AS 工作人员,dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ordv_ReservationSendPhotoTime)) AS 工作日期 from tb_ErpOrderDigital Where Ordv_ReservationSendPhotoName != '' And Ordv_ReservationSendPhotoTime is not null " + "UNION ALL " + "select OPlist_ReservationTakeName AS 工作人员,dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(OPlist_ReservationTakeTime)) AS 工作日期 from tb_ErpOrderProductList where OPlist_Type = '2' And OPlist_ReservationTakeName != '' And OPlist_ReservationTakeTime is not null " + "UNION ALL " + "select Ws_Serviceman1 AS 工作人员,dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ws_WeddingDate)) AS 工作日期 from tb_ErpWeddingService Where Ws_Status = '0' And Ws_Serviceman1 != '' And Ws_WeddingDate is not null " + "UNION ALL " + "select Ws_Serviceman2 AS 工作人员,dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ws_WeddingDate)) AS 工作日期 from tb_ErpWeddingService Where Ws_Status = '0' And Ws_Serviceman2 != '' And Ws_WeddingDate is not null " + ") " + "select * from t " + StrWhere + "Group By 工作人员,工作日期"; return orbll.GetView_Custom(ExecuteSql).Tables[0]; } /// /// 保存 /// /// /// void btnSaveed_Click(object sender, EventArgs e) { LYFZ.Model.Model_Loninbansets model = null; List clist = new List(); string StrMages = ""; for (int i = 0; i < this.dgvData.Rows.Count; i++) { string StrTip = ""; for (int j = 2; j < this.dgvData.Columns.Count; j++) { if (this.dgvData.Rows[i].Cells[j].Value.ToString().Trim() == "休息" && this.dgvData.Rows[i].Cells[j].Style.BackColor == Color.Red) { StrTip += this.dgvData.Columns[j].Name.Trim().Replace("\r\n", "") + ","; } } if (!string.IsNullOrEmpty(StrTip)) { StrMages += this.dgvData.Rows[i].Cells["姓名"].Value.ToString().Trim() + ":" + StrTip.TrimEnd(',') + "\r\n"; } } if (!string.IsNullOrEmpty(StrMages)) { MessageBoxCustom.Show("列表中红色格子的休息日已安排有工作,不能安排休息!\r\n" + StrMages); return; } if (this.chkWeekMode.Checked) { string StrStartDate = this.WeekStartDate.ToString("yyyy-MM-dd"); string StrEndDate = this.WeekEndDate.ToString("yyyy-MM-dd"); string StrWhere = LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.GetDateTime("Time", StrStartDate, StrEndDate, ConnectWord: ""); DataTable dt = orbll.GetView_Custom("loninbansets", StrWhere: StrWhere, ShowColumnName: "*").Tables[0]; for (int i = 0; i < this.dgvData.Rows.Count; i++) { for (int j = 3; j < this.dgvData.Columns.Count; j++) { string StrNowDateTime = Convert.ToDateTime(this.WeekStartDate.AddDays(j - 3).ToString("yyyy-MM-dd")).ToString("yyyy-MM-dd HH:mm:ss"); DataRow[] dtRows = dt.Select("User_ID = '" + this.dgvData.Rows[i].Cells["员工编号"].Value.ToString().Trim() + "' And Time = '" + StrNowDateTime + "'"); if (dtRows.Length > 0) { if (this.dgvData.Rows[i].Cells[j].Value.ToString().Trim() != dtRows[0]["Fixed"].ToString().Trim()) { model = lbsetbll.DataRowToModel(dtRows[0]); model.Fixed = this.dgvData.Rows[i].Cells[j].Value.ToString().Trim(); model.Time = Convert.ToDateTime(model.Time).ToString("yyyy-MM-dd HH:mm:ss"); clist.Add(lbsetbll.GetUpdateCommandInfo(model)); } } else { model = new Model.Model_Loninbansets(); model.User_ID = this.dgvData.Rows[i].Cells["员工编号"].Value.ToString().Trim(); model.Time = StrNowDateTime; model.Fixed = this.dgvData.Rows[i].Cells[j].Value.ToString().Trim(); clist.Add(lbsetbll.GetAddCommandInfo(model)); } } } } else { string StrStartDate = this.dtpYearMonth.StrDateValue.Trim() + "-01"; string StrEndDate = Convert.ToDateTime(StrStartDate).AddMonths(1).ToString("yyyy-MM-dd"); string StrWhere = LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.GetDateTime("Time", StrStartDate, StrEndDate, ConnectWord: ""); DataTable dt = orbll.GetView_Custom("loninbansets", StrWhere: StrWhere, ShowColumnName: "*").Tables[0]; for (int i = 0; i < this.dgvData.Rows.Count; i++) { for (int j = 1; j < this.dgvData.Columns.Count - 2; j++) { string StrNowDateTime = this.dtpYearMonth.StrDateValue.Trim() + "-" + (j).ToString("d2") + " 00:00:00"; DataRow[] dtRows = dt.Select("User_ID = '" + this.dgvData.Rows[i].Cells["员工编号"].Value.ToString().Trim() + "' And Time = '" + StrNowDateTime + "'"); if (dtRows.Length > 0) { if (this.dgvData.Rows[i].Cells[j + 2].Value.ToString().Trim() != dtRows[0]["Fixed"].ToString().Trim()) { model = lbsetbll.DataRowToModel(dtRows[0]); model.Fixed = this.dgvData.Rows[i].Cells[j + 2].Value.ToString().Trim(); model.Time = Convert.ToDateTime(model.Time).ToString("yyyy-MM-dd HH:mm:ss"); clist.Add(lbsetbll.GetUpdateCommandInfo(model)); } } else { model = new Model.Model_Loninbansets(); model.User_ID = this.dgvData.Rows[i].Cells["员工编号"].Value.ToString().Trim(); model.Time = StrNowDateTime; model.Fixed = this.dgvData.Rows[i].Cells[j + 2].Value.ToString().Trim(); clist.Add(lbsetbll.GetAddCommandInfo(model)); } } } } if (clist.Count > 0) { if (MessageBoxCustom.Show("您确定要保存吗?", "温馨提示", MessageBoxButtons.YesNo) == DialogResult.Yes) { int intExecuteCount = 0; LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, System.ComponentModel.BackgroundWorker backgroundWorker) { intExecuteCount = LYFZ.BLL.BaseBllOperate.ExecuteSqlTran(clist); }); if (intExecuteCount > 0) { MessageBoxCustom.Show("保存成功!"); } else { MessageBoxCustom.Show("保存失败!"); } } } else { MessageBoxCustom.Show("没做过任何修改,无须保存!"); } } /// /// 时间设置 /// /// /// void btnTimeSet_Click(object sender, EventArgs e) { frmTimeupdate frm = new frmTimeupdate(); frm.ShowDialog(); } /// /// 签单 /// /// /// void btnSigned_Click(object sender, EventArgs e) { if (this.dgvData.SelectedRows.Count > 0) { frmTimesign frm = new frmTimesign(); frm.StrUserNumber = this.dgvData.SelectedRows[0].Cells["员工编号"].Value.ToString().Trim(); frm.StrUserName = this.dgvData.SelectedRows[0].Cells["姓名"].Value.ToString().Trim(); frm.ShowDialog(); } else { MessageBoxCustom.Show("请选择一个员工签单!"); } } /// /// 签单记录 /// /// /// void btnSignedRecords_Click(object sender, EventArgs e) { frmtimeRecording frm = new frmtimeRecording(); frm.ShowDialog(); } /// /// 关闭 /// /// /// void btnClose_Click(object sender, EventArgs e) { this.Close(); } /// /// 选择年月 /// /// void dtpYearMonth_ClickChengedValue(string SelectValue) { this.GetQueryMonthData(); } /// /// 周模式 /// /// /// void chkzhouyue_Click(object sender, EventArgs e) { this.dgvData.Rows.Clear(); if (this.chkWeekMode.Checked) { this.panelLastNextWeek.Visible = true; this.dtpYearMonth.Visible = false; this.lblWhichWeek.Visible = true; this.GetQueryWeekData(); this.GetWeekCount(); } else { this.panelLastNextWeek.Visible = false; this.dtpYearMonth.Visible = true; this.lblWhichWeek.Visible = false; this.frmTimeMain_Load(null, null); } } /// /// 鼠标焦点离开时 /// /// /// void cmbtreev_Leave(object sender, EventArgs e) { if (this.cmbtreev.Visible) { if (this.cmbtreev.Text.Trim() == "休息") { string StrTime = ""; if (this.chkWeekMode.Checked == true) { StrTime = this.WeekStartDate.AddDays(this.dgvData.CurrentCell.ColumnIndex - 3).ToString("yyyy-MM-dd"); } else { StrTime = this.dtpYearMonth.StrDateValue + "-" + (this.dgvData.CurrentCell.ColumnIndex - 2).ToString("d2"); } string StrWhere = "where 工作人员='" + this.dgvData.CurrentRow.Cells["员工编号"].Value.ToString() + "' " + LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.GetDateTime("Convert(datetime,工作日期)", StrTime, StrTime) + " "; DataTable dt = new DataTable(); #region 查询当安排为休息或者空时 判断该员工当天有没有安排 LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, System.ComponentModel.BackgroundWorker backgroundWorker) { dt = this.GetWorkPerson(StrWhere); }); if (dt.Rows.Count > 0) { MessageBoxCustom.Show("此员工当前时间已有安排!请选择正确的排班"); } else { this.dgvData.CurrentCell.Value = this.cmbtreev.Text.Trim(); } #endregion } else { this.dgvData.CurrentCell.Value = this.cmbtreev.Text.Trim(); if (this.dgvData.CurrentCell.Style.BackColor == Color.Red) { this.dgvData.CurrentCell.Style.BackColor = this.dgvData.CurrentRow.Cells[this.dgvData.CurrentCell.ColumnIndex - 1].Style.BackColor; } } this.cmbtreev.Visible = false; } } /// /// 双击单元格显示下拉框 /// /// /// void dgvData_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex >= 0 && e.ColumnIndex >= 0) { if (this.dgvData.Columns[e.ColumnIndex].HeaderText.Trim() != "姓名") { DataGridViewCell cell = this.dgvData.Rows[e.RowIndex].Cells[e.ColumnIndex]; Rectangle rect = this.dgvData.GetCellDisplayRectangle(cell.ColumnIndex, cell.RowIndex, true); this.cmbtreev.Size = cell.Size; this.cmbtreev.Location = new Point(rect.Location.X + this.dgvData.Location.X, rect.Location.Y + this.dgvData.Location.Y); this.cmbtreev.Visible = true; if (cell.Value != System.DBNull.Value) { this.cmbtreev.TextFindTag(cell.Value.ToString().Trim()); } this.cmbtreev.Focus(); } } } /// /// 右键菜单 /// /// /// void dgvData_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e) { if (e.Button == MouseButtons.Right) { this.dgvData.conMenu.Items.Clear(); ToolStripMenuItem item = null; string StrTime = ""; if (this.chkWeekMode.Checked == true) { StrTime = this.WeekStartDate.AddDays(e.ColumnIndex - 3).ToString("yyyy-MM-dd"); } else { StrTime = this.dtpYearMonth.StrDateValue + "-" + (e.ColumnIndex - 2).ToString("d2"); } List strList = new List(this.StrTextName.Split(',')); for (int i = 0; i < strList.Count; i++) { item = new ToolStripMenuItem(); item.Text = strList[i].Trim(); item.Tag = StrTime + "|" + e.ColumnIndex; this.dgvData.conMenu.Items.Add(item); } } } /// /// 右键菜单选择项事件 /// /// /// void dgvData_DataGridViewConMenu_ItemClicked(object sender, ToolStripItemClickedEventArgs e) { ToolStripItem item = e.ClickedItem; string[] StrSplit = item.Tag.ToString().Trim().Split('|'); if (item.Text.Trim() == "休息"|| item.Text.Trim() == "请假") { string StrMagess = ""; string StrpPrson = ""; List StrList = new List(); for (int i = 0; i < this.dgvData.SelectedRows.Count; i++) { StrList.Add(this.dgvData.SelectedRows[i].Cells["员工编号"].Value.ToString().Trim()); StrpPrson += "'" + this.dgvData.SelectedRows[i].Cells["员工编号"].Value.ToString().Trim() + "',"; } Hashtable htData = new Hashtable(); LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, System.ComponentModel.BackgroundWorker backgroundWorker) { string StrWhere = "where 工作人员 in (" + StrpPrson.TrimEnd(',') + ") " + LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.GetDateTime("Convert(datetime,工作日期)", StrSplit[0].Trim(), StrSplit[0].Trim()) + " "; DataTable dt = this.GetWorkPerson(StrWhere); for (int i = 0; i < StrList.Count; i++) { DataRow[] dtRows = dt.Select("工作人员 = '" + StrList[i].Trim() + "'"); if (dtRows.Length > 0) { StrMagess += LYFZ.BLL.BLL_ErpOrderView.GetUserName(StrList[i].Trim()) + ","; } else { htData[StrList[i].Trim()] = item.Text.Trim(); } } }); for (int i = 0; i < this.dgvData.SelectedRows.Count; i++) { if (htData.ContainsKey(this.dgvData.SelectedRows[i].Cells["员工编号"].Value.ToString().Trim())) { this.dgvData.SelectedRows[i].Cells[Convert.ToInt32(StrSplit[1])].Value = item.Text.Trim(); } } if (StrMagess.Trim().Length > 0) { MessageBoxCustom.Show("员工:" + StrMagess + ",当前时间已有安排!请选择正确的排班"); } } else { for (int i = 0; i < this.dgvData.SelectedRows.Count; i++) { this.dgvData.SelectedRows[i].Cells[Convert.ToInt32(StrSplit[1])].Value = item.Text.Trim(); if (this.dgvData.SelectedRows[i].Cells[Convert.ToInt32(StrSplit[1])].Style.BackColor == Color.Red) { this.dgvData.SelectedRows[i].Cells[Convert.ToInt32(StrSplit[1])].Style.BackColor = this.dgvData.SelectedRows[i].Cells[Convert.ToInt32(StrSplit[1]) - 1].Style.BackColor; } } } } /// /// 列表滚动条滚动事件 /// /// /// void dgvData_Scroll(object sender, ScrollEventArgs e) { if (this.cmbtreev.Visible) { this.cmbtreev_Leave(this, null); } } /// /// 窗体大小发生变化 /// /// /// void frmTimeMain_Resize(object sender, EventArgs e) { switch (this.panelClose.Location.Y) { case 1: this.flowLayoutPanel1.Height = 31; break; case 31: this.flowLayoutPanel1.Height = 62; break; } } /// /// 获取Excel数据 /// /// /// DataTable FromExcel(string path) { string strConn; strConn = "provider=microsoft.jet.oledb.4.0;data source=" + path + ";extended properties=excel 8.0"; OleDbConnection OleConn = new OleDbConnection(strConn); OleConn.Open(); String sql = "SELECT * FROM [Sheet1$]";//改变这sql语句取你需要的 OleDbDataAdapter OleDaExcel = new OleDbDataAdapter(sql, OleConn); DataSet OleDsExcle = new DataSet(); OleDaExcel.Fill(OleDsExcle); OleConn.Close(); return OleDsExcle.Tables[0]; } /// /// 获取当前星期是今年的第几周 /// void GetWeekCount() { int IntWeekCount = (this.WeekStartDate.DayOfYear / 7); DateTime d1 = new DateTime(this.WeekStartDate.Year, 1, 1); if (d1.DayOfWeek != 0) { IntWeekCount += 2; } else { IntWeekCount += 1; } this.lblWhichWeek.Text = "第" + IntWeekCount + "周"; } /// /// 周查询 /// void GetQueryWeekData() { string StrColumnName = "员工编号,部门,姓名"; for (int i = 0; i < 7; i++) { int dd = this.WeekStartDate.AddDays(i).Day; int MM = this.WeekStartDate.AddDays(i).Month; switch (i) { case 0: StrColumnName += ",星期日\r\n" + MM + "月" + dd + "日"; break; case 1: StrColumnName += ",星期一\r\n" + MM + "月" + dd + "日"; break; case 2: StrColumnName += ",星期二\r\n" + MM + "月" + dd + "日"; break; case 3: StrColumnName += ",星期三\r\n" + MM + "月" + dd + "日"; break; case 4: StrColumnName += ",星期四\r\n" + MM + "月" + dd + "日"; break; case 5: StrColumnName += ",星期五\r\n" + MM + "月" + dd + "日"; break; case 6: StrColumnName += ",星期六\r\n" + MM + "月" + dd + "日"; break; } } this.dgvData.DataColumns(StrColumnName, strHideField: "员工编号"); this.dgvData.Columns["姓名"].Frozen = true; int IntdgvDataColumnsCount = this.dgvData.Columns.GetColumnCount(DataGridViewElementStates.Visible); int intdgvDataWidth = (this.dgvData.Width - 50) / IntdgvDataColumnsCount; for (int i = 0; i < this.dgvData.Columns.Count; i++) { this.dgvData.Columns[i].Width = intdgvDataWidth; } string companyWhere = ""; ItemValue itemValue = GetCompanyDataInfo(); if (!string.IsNullOrEmpty(itemValue.Value.ToString_s())) { companyWhere = itemValue.Value.ToString_s(); } //if(!string.IsNullOrEmpty(((ItemValue)cbxCompanyList.SelectedItem).Value.ToString_s())) //{ // companyWhere = " and User_DividedShop = '" + ((ItemValue)cbxCompanyList.SelectedItem).Value.ToString_s()+"'"; //} DataSet dtSet = new DataSet(); LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, System.ComponentModel.BackgroundWorker backgroundWorker) { string ExecuteSql = "select Dt_Name,User_EmployeeID,User_Name from tb_ErpUser Left Join tb_ErpDepartment on tb_ErpDepartment.ID = User_Department where User_Status='在职' And User_Account <> 'admin' " + companyWhere + " order by tb_ErpDepartment.ID;"; ExecuteSql += "select User_ID,fixed,dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(time)) AS time from loninbansets where time >= '" + this.WeekStartDate.ToString("yyyy-MM-dd 00:00:00") + "' and time <= '" + this.WeekEndDate.ToString("yyyy-MM-dd HH:mm:ss") + "' order by time;"; dtSet = orbll.GetView_Custom(ExecuteSql); }); DataTable da = dtSet.Tables["ds"]; DataTable dt = dtSet.Tables["ds1"]; for (int i = 0; i < da.Rows.Count; i++) { DataGridViewRow dgvr = new DataGridViewRow(); DataGridViewCell cell = null; cell = new DataGridViewTextBoxCell(); cell.Value = da.Rows[i]["User_EmployeeID"].ToString().Trim(); dgvr.Cells.Add(cell); cell = new DataGridViewTextBoxCell(); cell.Value = da.Rows[i]["Dt_Name"].ToString().Trim(); dgvr.Cells.Add(cell); cell = new DataGridViewTextBoxCell(); cell.Value = da.Rows[i]["User_Name"].ToString().Trim(); dgvr.Cells.Add(cell); for (int j = 3; j < this.dgvData.Columns.Count; j++) { cell = new DataGridViewTextBoxCell(); cell.Value = ""; DataRow[] dtRow = dt.Select("user_id = '" + da.Rows[i]["User_EmployeeID"].ToString().Trim() + "' And time = '" + this.WeekStartDate.AddDays(j - 3).ToString("yyyy-MM-dd") + "'"); if (dtRow.Length > 0) { if (!string.IsNullOrEmpty(dtRow[0]["fixed"].ToString())) { cell.Value = dtRow[0]["fixed"]; } } dgvr.Cells.Add(cell); } this.dgvData.Rows.Add(dgvr); } this.dgvData.ClearSelection(); } ItemValue GetCompanyDataInfo() { ItemValue itemValue = new ItemValue("",""); if (this.cbxCompanyList.Tag != null && this.cbxCompanyList.TreeView.SelectedNode != null) { string dataValue = this.cbxCompanyList.Tag.ToString(); string dataType = this.cbxCompanyList.StrGetName.Trim(); if (dataType.Length > 0) { switch (dataType.ToLower()) { case "storename": itemValue.Value = "and User_DividedShop = '" + dataValue + "'"; break; case "department": itemValue.Value = "and User_Department = '" + dataValue + "'"; break; case "user": itemValue.Value = "and User_EmployeeID = '" + dataValue + "'"; break; } } } return itemValue; } /// /// 月查询 /// void GetQueryMonthData() { string companyWhere = ""; ItemValue itemValue = GetCompanyDataInfo(); if(!string.IsNullOrEmpty(itemValue.Value.ToString_s())) { companyWhere = itemValue.Value.ToString_s(); } int yyyy = Convert.ToInt32(this.dtpYearMonth.StrYear); int MM = Convert.ToInt32(this.dtpYearMonth.StrMonth); DataSet dtSet = new DataSet(); LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, System.ComponentModel.BackgroundWorker backgroundWorker) { string ExecuteSql = "select Dt_Name,User_EmployeeID,User_Name from tb_ErpUser Left Join tb_ErpDepartment on tb_ErpDepartment.ID = User_Department where User_Status='在职' And User_Account <> 'admin' "+ companyWhere + " order by tb_ErpDepartment.ID;"; ExecuteSql += "select User_ID,fixed,time from loninbansets where datename(yyyy,Time)='" + yyyy + "' and datename(MM,Time)='" + MM.ToString("d2") + "';"; dtSet = orbll.GetView_Custom(ExecuteSql); }); DataTable da = dtSet.Tables["ds"]; DataTable dt = dtSet.Tables["ds1"]; this.dgvData.Rows.Clear(); this.dgvData.Columns.Clear(); string StrColumnName = "员工编号,部门,姓名"; int intDsy = Convert.ToInt32(Convert.ToDateTime(this.dtpYearMonth.StrDateValue.Trim() + "-01").AddMonths(1).AddSeconds(-1).ToString("dd")); for (int i = 0; i < intDsy; i++) { StrColumnName += "," + (i + 1) + "日" + Environment.NewLine + Convert.ToDateTime(this.dtpYearMonth.StrDateValue + "-01").AddDays(i).ToString("dddd") + ""; } this.dgvData.DataColumns(StrColumnName, strHideField: "员工编号"); this.dgvData.Columns["姓名"].Frozen = true; for (int i = 0; i < this.dgvData.Columns.Count; i++) { switch (this.dgvData.Columns[i].Name.Trim()) { case "姓名": this.dgvData.Columns[i].Width = 80; break; default: this.dgvData.Columns[i].Width = 80; break; } } for (int i = 0; i < da.Rows.Count; i++) { DataGridViewRow dgvr = new DataGridViewRow(); DataGridViewCell cell = null; for (int j = 0; j < dgvData.Columns.Count; j++) { cell = new DataGridViewTextBoxCell(); switch (j) { case 0: cell.Value = da.Rows[i]["User_EmployeeID"]; break; case 1: cell.Value = da.Rows[i]["Dt_Name"].ToString().Trim(); break; case 2: cell.Value = da.Rows[i]["User_Name"]; break; default: cell.Value = ""; DataRow[] dtRow = dt.Select("user_id='" + da.Rows[i]["User_EmployeeID"] + "' And time = '" + Convert.ToDateTime((this.dtpYearMonth.StrDateValue + "-" + (j - 2).ToString("d2"))) + "'"); if (dtRow.Length > 0) { if (!string.IsNullOrEmpty(dtRow[0]["fixed"].ToString())) { cell.Value = dtRow[0]["fixed"]; } } break; } dgvr.Cells.Add(cell); } this.dgvData.Rows.Add(dgvr); } this.dgvData.ClearSelection(); } /// /// 把空数据转换成SQL的空字符 /// /// /// string SqlNull(object obj) { if (obj == null) return ""; return obj.ToString().Trim(); } } }