/// <summary> /// Tạo ComboBox danh sách các ca làm việc /// </summary> private void PopulateShiftCombo() { ShiftDO shiftDO = new ShiftDO(); DataSet dsShift = shiftDO.GetShiftOver(); cboShift.DataSource = dsShift.Tables[0]; cboShift.DisplayMember = "ShiftName"; cboShift.ValueMember = "ShiftOverID"; }
/// <summary> /// thiet lap lich lam viec cho nhung nhan vien duoc chon /// </summary> private void SetWorkingTime() { int DeparmentID = (int)departmentTreeView.SelectedNode.Tag; int employeeID = 0; try { // dsWorkingTime = workingTimeDO.GetWorkingTimeByMonthNew(1, CurrentMonth, CurrentYear); dsEmployee = employeeDO.GetEmployeeByDepartment(DeparmentID); WorkingTimeDataRows = dsEmployee.Tables[0].Select(dataFilter, dataSort); // hien thi form thong bao trang thai hoan thanh frmStatusMessage message = new frmStatusMessage(); string strStatus = WorkingContext.LangManager.GetString("frmStatus_thongbao"); //message.Show("Đang sinh dữ liệu bảng chấm công, xin chờ trong giây lát..."); message.Show("Đang cập nhật lịch làm thêm cho nhân viên ..."); message.ProgressBar.Value = 0; // int totalEmployees = dataRows.Length; Cursor = Cursors.WaitCursor; int percentToComplete = 0; int percentProcessing = 0; for (int i = 0; i < lvwListEmployee.SelectedIndicies.Length; i++) { ++percentProcessing; // AddWorkingTimeByEmployee(dsWorkingTime,1); // chỉ số hàng được chọn int rowIndex = (int)lvwListEmployee.SelectedItems[i].Tag; DataRow dr = dsEmployee.Tables[0].Rows[rowIndex]; employeeID = int.Parse(dr["EmployeeID"].ToString()); //dsWorkingTime = workingTimeDO.GetWorkingTimeByMonth(employeeID, CurrentMonth, CurrentYear); //if (dsWorkingTime.Tables[0].Rows.Count > 0) //{ // UpdateWorkingTimeByEmployee(dsWorkingTime, employeeID); //} //else //{ shiftDO = new ShiftDO(); shiftDO.DeleteOverTimeInMonth(CurrentMonth, CurrentYear); AddWorkingTimeByEmployee(employeeID); //} percentToComplete = (percentProcessing * 100) / lvwListEmployee.SelectedIndicies.Length; message.ProgressBar.Value = percentToComplete; } message.Close(); Cursor = Cursors.Default; string str = WorkingContext.LangManager.GetString("frmRegWork_Up_Messa"); string str1 = WorkingContext.LangManager.GetString("frmRegWork_Up_Title"); //MessageBox.Show("Đăng ký thời gian làm việc thành công", "Đăng ký thời gian làm việc", MessageBoxButtons.OK, MessageBoxIcon.Information); MessageBox.Show(str, str1, MessageBoxButtons.OK, MessageBoxIcon.Information); } catch { string str = WorkingContext.LangManager.GetString("frmLunch_SetLunch_ThongBao"); string str1 = WorkingContext.LangManager.GetString("frmLunch_SetLunch_Title"); //MessageBox.Show("Có lỗi xảy ra khi cập nhật dữ liệu ăn trưa", "Thiết lập ăn trưa", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show(str, str1, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnUpdate_Click(object sender, EventArgs e) { if (selectedDates != null) { RemoveOldDateInfo(); if (!deleteOverTime.Checked) { SetOverTime(); } else { shiftDO = new ShiftDO(); shiftDO.DeleteOverTimeInMonth(CurrentMonth, CurrentYear); } } if (monthCalendar1.Dates.Count > 0) { SetWorkingTime(); } }
/// <summary> /// /// </summary> private void LoadWorkingCalendarByEmployee() { monthCalendar1.Dates.Clear(); int DeparmentID = (int)departmentTreeView.SelectedNode.Tag; dsEmployee = employeeDO.GetEmployeeByDepartment(DeparmentID); int employeeID = (int)dsEmployee.Tables[0].Rows[selectedRowIndex]["EmployeeID"]; workingTimeDO = new RegWorkingTimeDO(); dsWorkingTime = workingTimeDO.GetOverTimeByMonth(employeeID, CurrentMonth, CurrentYear); shiftDO = new ShiftDO(); DataSet dsShiftOver = new DataSet(); if (dsWorkingTime.Tables[0].Rows.Count > 0) { foreach (DataRow dr in dsWorkingTime.Tables[0].Rows) { DateTime Day = DateTime.Parse(dr["WorkingDay"].ToString()); int ShiftOverID = int.Parse(dr["ShiftOverID"].ToString()); dsShiftOver = shiftDO.GetShiftOverByID(ShiftOverID); DateItem dateItem = new DateItem(); dateItem.DateColor = lblOverTimeLegend.ForeColor; dateItem.BackColor = lblOverTimeLegend.BackColor; dateItem.Date = Day; if (dsShiftOver != null) dateItem.Text = dsShiftOver.Tables[0].Rows[0]["ShiftName"].ToString(); monthCalendar1.AddDateInfo(dateItem); } } monthCalendar1.Refresh(); monthCalendar1.ClearSelection(); }
/// <summary> /// Thêm thông tin đăng ký thời gian làm việc cho tung nhan vien /// </summary> /// <param name="employeeID"></param> /// <returns></returns> private int AddWorkingTimeByEmployee(int employeeID) { int ret = 0; try { int NumDays = DateTime.DaysInMonth(CurrentYear, CurrentMonth); DateTime DayInMonth = new DateTime(CurrentYear, CurrentMonth, 1); //DataRow drEmployee = dsEmployee.Tables[0].Rows[rowIndex]; for (int i = 1; i <= NumDays; i++) { //DataRow dr = dsWorkingTime.Tables[0].NewRow(); //dr.BeginEdit(); //dr["EmployeeID"] = employeeID; //dr["Day"] = DayInMonth; //int index = 0; DateItem[] dateItem = monthCalendar1.GetDateInfo(DayInMonth); if (dateItem.Length > 0) { DataRow dr = dsRegOverTime.Tables[0].NewRow(); // dr.BeginEdit(); dr.BeginEdit(); dr["EmployeeID"] = employeeID; ShiftDO shiftDO = new ShiftDO(); DataSet dsShiftOver = shiftDO.GetShiftOverByName(dateItem[0].Text); //index++; dr["ShiftOverID"] = dsShiftOver.Tables[0].Rows[0]["ShiftOverID"].ToString(); dr["StartOverTime"] = dsShiftOver.Tables[0].Rows[0]["TimeIn"].ToString(); DateTime startTime = Convert.ToDateTime(dsShiftOver.Tables[0].Rows[0]["TimeIn"].ToString()); DateTime stopTime = Convert.ToDateTime(dsShiftOver.Tables[0].Rows[0]["TimeOut"].ToString()); DateTime startLunch = Convert.ToDateTime(dsShiftOver.Tables[0].Rows[0]["LunchStart"].ToString()); DateTime stopLunch = Convert.ToDateTime(dsShiftOver.Tables[0].Rows[0]["LunchStop"].ToString()); DateTime startDinner = Convert.ToDateTime(dsShiftOver.Tables[0].Rows[0]["DinnerStart"].ToString()); DateTime stopDinner = Convert.ToDateTime(dsShiftOver.Tables[0].Rows[0]["DinnerStop"].ToString()); TimeSpan leng = stopTime - startTime - (stopLunch - startLunch) - (stopDinner - startDinner); DateTime length = Convert.ToDateTime("12/12/2005 " + leng.Hours + ":" + leng.Minutes + ":" + leng.Milliseconds); dr["Length"] = Convert.ToDateTime(length).ToShortTimeString(); //Convert.ToDateTime(stopTime - startTime - (stopLunch - startLunch) - (stopDinner - startDinner)) // .ToShortTimeString(); dr["WorkingDay"] = DayInMonth.ToShortDateString(); dr["WorkOverTimeInfo"] = txtWorkOverTimeInfo.Text; if (ckHaveDinner.Checked) { dr["DinnerAmount"] = Double.Parse(cboDinnnerAmount.Text); } else { dr["DinnerAmount"] = DBNull.Value; } dr.EndEdit(); dsRegOverTime.Tables[0].Rows.Add(dr); ret = regOverTimeDO.AddRegOverTime(dsRegOverTime); //if (dateItem[0].BackColor == lblWorkingDayLegend.BackColor) //{ // DataRow[] drShift = dsShift.Tables[0].Select("ShiftName='" + dateItem[0].Text + "'"); // dr["ShiftID"] = drShift[0]["ShiftID"]; // decimal Times = Convert.ToDecimal(drShift[0]["TimeSheet"]); // dr["TimeSheet"] = Times; //} //else if (dateItem[0].BackColor == lblNonWorkingDayLegend.BackColor) //{ // dr["ShiftID"] = 0; //} //else if (dateItem[0].BackColor == lblHolidayLegend.BackColor) //{ // dr["ShiftID"] = -1; //} //else if (dateItem[0].BackColor == lblOverTimeLegend.BackColor) //{ // dr["ShiftID"] = -2; //} } else { //dr["ShiftID"] = 0; } //dr.EndEdit(); //dsWorkingTime.Tables[0].Rows.Add(dr); DayInMonth = DayInMonth.AddDays(1); } // ret = workingTimeDO.AddWorkingTime(dsWorkingTime); } catch { } return ret; }
/// <summary> /// Đăng ký làm thêm giờ /// </summary> public void RegDepartmentOverTime(DateTime workingDay) { frmMessage frmMessage = new frmMessage(); string OverTimeMessage = ""; int STT = 0; for (int i = 0; i < lvwListEmployee.SelectedIndicies.Length; i++) { // chỉ số hàng được chọn int rowIndex = (int)lvwListEmployee.SelectedItems[i].Tag; DataRow drEmployee = dsEmployee.Tables[0].Rows[rowIndex]; // dr.BeginEdit(); // foreach (DataRow drEmployee in dsEmployee.Tables[0].Rows) // { int ret = 0; try { DataRow dr = dsRegOverTime.Tables[0].NewRow(); // dr.BeginEdit(); dr.BeginEdit(); dr["EmployeeID"] = drEmployee["EmployeeID"]; ShiftDO shiftDO = new ShiftDO(); DataSet dsShiftOver = shiftDO.GetShiftOverByID(int.Parse(cboShift.SelectedValue.ToString())); dr["ShiftOverID"] = dsShiftOver.Tables[0].Rows[0]["ShiftOverID"].ToString(); dr["StartOverTime"] = dsShiftOver.Tables[0].Rows[0]["TimeIn"].ToString(); DateTime startTime = Convert.ToDateTime(dsShiftOver.Tables[0].Rows[0]["TimeIn"].ToString()); DateTime stopTime = Convert.ToDateTime(dsShiftOver.Tables[0].Rows[0]["TimeOut"].ToString()); DateTime startLunch = Convert.ToDateTime(dsShiftOver.Tables[0].Rows[0]["LunchStart"].ToString()); DateTime stopLunch = Convert.ToDateTime(dsShiftOver.Tables[0].Rows[0]["LunchStop"].ToString()); DateTime startDinner = Convert.ToDateTime(dsShiftOver.Tables[0].Rows[0]["DinnerStart"].ToString()); DateTime stopDinner = Convert.ToDateTime(dsShiftOver.Tables[0].Rows[0]["DinnerStop"].ToString()); TimeSpan leng = stopTime - startTime - (stopLunch - startLunch) - (stopDinner - startDinner); DateTime length = Convert.ToDateTime("12/12/2005 " + leng.Hours + ":" + leng.Minutes + ":" + leng.Milliseconds); dr["Length"] = Convert.ToDateTime(length).ToShortTimeString(); //Convert.ToDateTime(stopTime - startTime - (stopLunch - startLunch) - (stopDinner - startDinner)) // .ToShortTimeString(); dr["WorkingDay"] = workingDay.ToShortDateString(); dr["WorkOverTimeInfo"] = txtWorkOverTimeInfo.Text; if (ckHaveDinner.Checked) { dr["DinnerAmount"] = Double.Parse(cboDinnnerAmount.Text); } else { dr["DinnerAmount"] = DBNull.Value; } dr.EndEdit(); dsRegOverTime.Tables[0].Rows.Add(dr); ret = regOverTimeDO.AddRegOverTime(dsRegOverTime); } catch { } if (ret == EmployeeStatus.EMPLOYEE_LEAVE) { OverTimeMessage = drEmployee["CardID"] + " - " + drEmployee["EmployeeName"] + " đã đi công tác"; STT++; frmMessage.AddMessage(STT.ToString() + ". " + OverTimeMessage); } if (ret == EmployeeStatus.EMPLOYEE_REST) { OverTimeMessage = drEmployee["CardID"] + " - " + drEmployee["EmployeeName"] + " đã đăng ký nghỉ"; STT++; frmMessage.AddMessage(STT.ToString() + ". " + OverTimeMessage); } //else if (ret == EmployeeStatus.EMPLOYEE_ABSENT) //{ // OverTimeMessage = drEmployee["CardID"] + " - " + drEmployee["EmployeeName"] + " vắng mặt"; // STT++; // frmMessage.AddMessage(STT.ToString() + ". " + OverTimeMessage); //} } if (STT != 0) { frmMessage.Show(); } else { frmMessage.Close(); string str = WorkingContext.LangManager.GetString("frmRegOverTime1_DangKyOT_Messa1"); string str1 = WorkingContext.LangManager.GetString("frmRegOverTime1_DangKyOT_Title"); //MessageBox.Show("Không thể đăng ký làm thêm giờ cho nhân viên này", "Đăng ký làm thêm giờ", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show(str, str1, MessageBoxButtons.OK, MessageBoxIcon.Information); // if ((this.Text =="Thêm đăng ký làm thêm giờ" )|| (this.Text == "Sửa đăng ký làm thêm giờ")) // { // MessageBox.Show("Đăng ký làm thêm giờ cho bộ phận " + departmentTreeView.SelectedNode.Text + " thành công!", "Đăng ký làm thêm giờ", MessageBoxButtons.OK, MessageBoxIcon.Information); // } // else // { // MessageBox.Show(departmentTreeView.SelectedNode.Text +" の部門の残業登録が正常に完了しました !","",MessageBoxButtons.OK, MessageBoxIcon.Information); // // } } }
private void frmShift_Load(object sender, System.EventArgs e) { Refresh(); shiftDO = new ShiftDO(); if (dsShift != null) { //tbShift.; txtShiftName.Focus(); EditStatus = 0; // chế độ sửa dtShift = dsShift.Tables[0]; if (currentShift >= 0) { string str = WorkingContext.LangManager.GetString("frmShift_Text2"); this.Text = str; //this.Text = "Sửa ca làm việc "; // Hiển thị thông nhân viên if (dsShift != null) LoadShiftData(); this.BindingContext[dtShift].Position = currentShift; } } else if (dsShiftOver != null) { //tabPage1.Enabled = false; //tbShift.SelectedIndex = 1; //txtShiftOverName.Focus(); //EditStatus = 0; // chế độ sửa //dtShiftOver = dsShiftOver.Tables[0]; ////int thu = dsShiftOver.Tables[0].Rows.Count; //if (currentShift >= 0) //{ // string str = WorkingContext.LangManager.GetString("frmShift_Text2"); // this.Text = str; // //this.Text = "Sửa ca làm việc "; // // Hiển thị thông nhân viên // LoadShiftOverData(); // this.BindingContext[dtShiftOver].Position = currentShift; //} } else { string str = WorkingContext.LangManager.GetString("frmShift_Text1"); this.Text = str; EditStatus = 1; //chế độ thêm mới shiftDO = new ShiftDO(); dsShift = shiftDO.GetShift(); DefaultValue(); } }
private void frmListShift_Load(object sender, EventArgs e) { Refresh(); shiftDO = new ShiftDO(); PopulateShift(); }
/// <summary> /// Xóa ca làm thêm /// </summary> public void DeleteShiftOver() { if (selectedRow < 0) { string str = WorkingContext.LangManager.GetString("frmListShift_Del_Messa4"); string str1 = WorkingContext.LangManager.GetString("frmListShift_Del_Title"); //MessageBox.Show("Bạn chưa chọn ca nào!", "Xóa ca", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show(str, str1, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } int ret = 0; try { ShiftDO shiftDO = new ShiftDO(); DataSet dsShiftOver = shiftDO.GetShiftOver(); DataTable dtShift = dsShiftOver.Tables[0]; dtShift.Rows[selectedRow].Delete(); ret = shiftDO.DeleteShiftOver(dsShiftOver); } catch { dtShift.RejectChanges(); } if (ret == 2) { string str = WorkingContext.LangManager.GetString("frmListShift_Del_Messa3"); string str1 = WorkingContext.LangManager.GetString("frmListShift_Del_Title"); //MessageBox.Show("Ca đã được xóa khỏi cơ sở dữ liệu", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); MessageBox.Show(str, str1, MessageBoxButtons.OK, MessageBoxIcon.Information); dtShift.AcceptChanges(); // PopulateEmployeeListView(); } else { string str = WorkingContext.LangManager.GetString("frmListShift_Del_Messa4"); string str1 = WorkingContext.LangManager.GetString("frmListShift_Del_Title"); //MessageBox.Show("Không thể xóa ca khỏi cơ sở dữ liệu", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); MessageBox.Show(str, str1, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); dtShift.RejectChanges(); } }