void tbGioLam_TextChanged(object sender, EventArgs e) { if (string.IsNullOrEmpty(tbGioLam.Text) || tbGioLam.Text == "0") { tbCong.Text = "0"; return; } //int cong = int.Parse(tbGioLam.Text); cShift ca = cbCa.SelectedItem as cShift; if (ca == null) { AutoClosingMessageBox.Show("ca null", "", 1000); return; } TimeSpan sophutlamthem = new TimeSpan(0, (int)numSoPhutOT.Value, 0); Double giolam = (string.IsNullOrEmpty(tbGioLam.Text)) ? 0f : Double.Parse(tbGioLam.Text); giolam = giolam + sophutlamthem.TotalHours; Double cong = 0f; if (ca.ShiftID == 0 || ca.ShiftID == int.MinValue || ca.ShiftID == int.MinValue + 1) { cong = giolam / 8f; } else { cong = (giolam / ca.WorkingTimeTS.TotalHours) * ca.Workingday; } cong = Math.Round(cong, 2); tbCong.Text = cong.ToString(); // ("#0.##"); }
void cbCa_SelectionChangeCommitted(object sender, EventArgs e) { cShift ca = (cbCa.SelectedItem) as cShift; if (ca == null) { AutoClosingMessageBox.Show("ca null", "", 1000); return; } DateTime ngay = dtpNgay.Value.Date; if (ca.ShiftID == 0 || ca.ShiftID == int.MinValue || ca.ShiftID == int.MinValue + 1) { dtpBDLam.Value = new DateTime(ngay.Year, ngay.Month, ngay.Day, 0, 0, 0); dtpKTLam.Value = new DateTime(ngay.Year, ngay.Month, ngay.Day, 0, 0, 0); dtpBDLam.Update(); dtpKTLam.Update(); return; } // chọn ca 1, 2 ,.... DateTime timeBD = ngay.Add(ca.OnnDutyTS); DateTime timeKT = ngay.Add(ca.OffDutyTS); dtpBDLam.Value = timeBD; dtpKTLam.Value = timeKT; }
private void FillValueForControl(cChkInOut pChkInOut, cShift pcurrCa) { lbCheckINOUT.Tag = pChkInOut; tbGioLam.Tag = pChkInOut.TGLamTinhCong; tbTreSom.Tag = (int)Math.Floor(((pChkInOut.VaoTre + pChkInOut.RaaSom).TotalMinutes)); tbOLaiThem.Tag = (int)Math.Floor((pChkInOut.OLaiThem.TotalMinutes));//[TBD] Xem lại chỗ này vì phải ở lại trên 30ph mới có currỞ Lại thêm lbTre.Tag = (int)Math.Floor(pChkInOut.VaoTre.TotalMinutes); lbSom.Tag = (int)Math.Floor(pChkInOut.RaaSom.TotalMinutes); tbGioLam.Text = pChkInOut.TGLamTinhCong.TotalHours.ToString("#0.##"); tbTreSom.Text = ((int)tbTreSom.Tag).ToString(); tbOLaiThem.Text = ((int)tbOLaiThem.Tag).ToString(); lbTre.Text = ((int)lbTre.Tag).ToString(); lbSom.Text = ((int)lbSom.Tag).ToString(); if ((int)tbOLaiThem.Tag == 0) { checkXacNhanLamThem.CheckedChanged -= checkXacNhanLamThem_CheckedChanged; checkXacNhanLamThem.Enabled = false; numPhutTinhLamThem.Enabled = false; numPhutTinhLamThem.Value = 0; } else { checkXacNhanLamThem.CheckedChanged += checkXacNhanLamThem_CheckedChanged; checkXacNhanLamThem.Enabled = true; int tmpMax = (int)tbOLaiThem.Tag;// (((int)tbOLaiThem.Tag - (int)tbTreSom.Tag) > ThamSo._maxPhutLamThem) ? ((int)tbOLaiThem.Tag - (int)tbTreSom.Tag) : 0; numPhutTinhLamThem.Value = 0; numPhutTinhLamThem.Maximum = tmpMax; } checkXacNhanLamThem.Checked = false; }
void dtpGio_Vao_ValueChanged(object sender, EventArgs e) { if (cbCa_Vao.SelectedIndex == 0) { return; // neu chon tuỳ chinh thi thoat ko lam gi het } cShift ca = cbCa_Vao.SelectedItem as cShift; // lay ca duoc chon và kiem tra xem gio vao có nằm trong khoảng hiểu ca ko. // neu ko hieu ca chuyen combo ve tùy chỉnh if (ca == null) { return; } DateTime x = dtpGio_Vao.Value; if (x.TimeOfDay >= ca.OnTimeInTS.Subtract(new TimeSpan(ca.DayCount, 0, 0, 0)) && x.TimeOfDay <= ca.CutInTS.Subtract(new TimeSpan(ca.DayCount, 0, 0, 0))) { // nằm trong khoảng hiểu thì ko làm gì hết } else // nằm ngoài khoảng hiểu, chuyển về tùy chọn tùy chỉnh { cbCa_Vao.SelectedIndex = 0; } }
private void rad_CheckedChanged(object sender, EventArgs e) { if (cbCa_Vao.SelectedIndex == 0) { return; // neu chon tuỳ chinh thi thoat ko lam gi het } cShift ca = cbCa_Vao.SelectedItem as cShift; // lay ca duoc chon và kiem tra xem gio vao có nằm trong khoảng hiểu ca ko. // neu ko hieu ca chuyen combo ve tùy chỉnh if (ca == null) { return; } bool kieugio = radVao.Checked; //kiểm tra coi thuộc ca nào, kiểu gì để thay đổi combox dtpGioMoi.ValueChanged -= DtpGioMoiValueChanged; DateTime x = DateTime.MinValue; x = (kieugio) ? DateTime.Today.Add(ca.OnnDutyTS) : DateTime.Today.Add(ca.OffDutyTS.Subtract(new TimeSpan(ca.DayCount, 0, 0, 0))); // dtpGioMoi.Value = x; dtpGioMoi.Update(); dtpGioMoi.ValueChanged += DtpGioMoiValueChanged; }
private void cbCa_SelectedIndexChanged(object sender, EventArgs e) { cShift tmpCa = (cShift)cbCa.SelectedItem; DateTime gio = (rdbtnVao.Checked) ? dateTimeGioMoi.Value.Date.Add(tmpCa.OnnDutyTS) : dateTimeGioMoi.Value.Date.Add(tmpCa.OffDutyTS); dateTimeGioMoi.Value = new DateTime(gio.Year, gio.Month, gio.Day, gio.Hour, gio.Minute, 0); }
private void cbCa_Sua_OnSelectedIndexChanged(object sender, EventArgs e) { if (sender == cbCaVao_Sua) { cShift tmpshift = (sender as ComboBox).SelectedItem as cShift; DataRowView row = dgrdTongHop.Tag as DataRowView; DateTime tmpVao = (DateTime)row["TimeStrNgay"]; tmpVao = tmpVao.Date.Add(tmpshift.OnnDutyTS); //[1]dtpVao_Sua.ValueChanged -= dtp_Sua_OnValueChanged; dtpVao_Sua.Value = tmpVao; //[1]dtpVao_Sua.ValueChanged += dtp_Sua_OnValueChanged; dtpVao_Sua.Update(); } else { cShift tmpshift = (sender as ComboBox).SelectedItem as cShift; DataRowView row = dgrdTongHop.Tag as DataRowView; DateTime tmpRa = (DateTime)row["TimeStrNgay"]; tmpRa = tmpRa.Date.Add(tmpshift.OffDutyTS); //[1]dtpRa_Sua.ValueChanged -= dtp_Sua_OnValueChanged; dtpRa_Sua.Value = tmpRa; //[1]dtpRa_Sua.ValueChanged += dtp_Sua_OnValueChanged; dtpRa_Sua.Update(); } }
private void cbCa_Them_OnSelectedIndexChanged(object sender, EventArgs eventArgs) { if (dgrdTongHop.SelectedRows.Count == 0) { return; } DataRowView row = dgrdTongHop.SelectedRows[0].DataBoundItem as DataRowView; if (sender == cbCaVao_Them) { if (cbCaVao_Them.SelectedIndex == 0) { return; } cShift tmpshift = (sender as ComboBox).SelectedItem as cShift; DateTime tmpVao = (DateTime)row["TimeStrNgay"]; tmpVao = tmpVao.Date.Add(tmpshift.OnnDutyTS); dtpVao_Them.ValueChanged -= dtp_Them_OnValueChanged; dtpVao_Them.Value = tmpVao; dtpVao_Them.Update(); dtpVao_Them.ValueChanged += dtp_Them_OnValueChanged; } else { cShift tmpshift = (sender as ComboBox).SelectedItem as cShift; DateTime tmpRa = (DateTime)row["TimeStrNgay"]; tmpRa = tmpRa.Date.Add(tmpshift.OffDutyTS); dtpRa_Them.ValueChanged -= dtp_Them_OnValueChanged; dtpRa_Them.Value = tmpRa; dtpRa_Them.Update(); dtpRa_Them.ValueChanged += dtp_Them_OnValueChanged; } }
private void btnXacNhan_Click(object sender, EventArgs e) { #region lấy dữ liệu từ form DataGridView tmpDatagrid = dgrdGioCoLamThem; DataGridViewRow tmpSelectedRow = tmpDatagrid.SelectedRows[0]; DataRowView rowView = tmpSelectedRow.DataBoundItem as DataRowView; int tmpUserEnrollNumber = (int)rowView["UserEnrollNumber"]; DateTime tmpOldChkInTime = (DateTime)rowView["TimeStrVao"]; DateTime tmpOldChkOutTime = (DateTime)rowView["TimeStrRa"]; cUserInfo tmpNV = fListNVChk.Find(item => item.UserEnrollNumber == tmpUserEnrollNumber); cChkInOut tmpOldChkINOUT = tmpNV.DSVaoRa.Find(item => (item.HaveINOUT > 0) && item.Vao.TimeStr == tmpOldChkInTime && item.Raa.TimeStr == tmpOldChkOutTime); cShift tmpOldShift = tmpOldChkINOUT.ThuocCa; if (lbCheckINOUT.Tag == null) { AutoClosingMessageBox.Show("lbCheckINOUT.Tag == null", "Error", 1000); return; } cShift tmpNewShift = (cShift)cbChonCa.SelectedItem; cChkInOut tmpNewChkINOUT = (cChkInOut)lbCheckINOUT.Tag; // lúc tính công chưa có gán THUOCCA lại nên ở đây phải gán lại tmpNewChkINOUT.ThuocCa = tmpNewShift; int tmpNewShiftID = tmpNewShift.ShiftID; // shiftID của DSCa mở rộng int tmpTre = int.Parse(lbTre.Tag.ToString()); TimeSpan tmpTreTS = new TimeSpan(0, tmpTre, 0); int tmpSom = int.Parse(lbSom.Tag.ToString()); TimeSpan tmpSomTS = new TimeSpan(0, tmpSom, 0); int tmpSoPhutTreSom = int.Parse(tbTreSom.Tag.ToString()); // > 0 nếu (chấm tay < 8h => ra sớm), đúng ca nhưng có vào trễ ra sớm TimeSpan tmpSoPhutTreSomTS = new TimeSpan(0, tmpSoPhutTreSom, 0); int tmpSoPhutOLaiThem = int.Parse(tbOLaiThem.Tag.ToString()); TimeSpan tmpSoPhutOLaiThemTS = new TimeSpan(0, tmpSoPhutOLaiThem, 0); bool tmpIsOT = checkXacNhanLamThem.Checked; int tmpSoPhutLamThem = (tmpIsOT) ? (int)numPhutTinhLamThem.Value : 0; TimeSpan tmpSoPhutLamThemTS = new TimeSpan(0, tmpSoPhutLamThem, 0); #endregion bool pTinhPC150 = checkTinhPC150.Checked; if (tmpNewShift.OnnDutyTS > ThamSo._20h00 && tmpNewShift.Workingday > 1f) { cChkInOut[] arrCIO = XL.TachGio2Ca3Va1(tmpNV.DSCa, tmpNewChkINOUT, tmpNewChkINOUT.ThuocCa); XL.TinhCongTheoCa(arrCIO[0], arrCIO[0].ThuocCa); XL.TinhCongTheoCa(arrCIO[1], arrCIO[1].ThuocCa); XL.BUS_TachCaVaXacNhan(tmpNV, tmpOldChkINOUT, arrCIO, tmpIsOT, tmpSoPhutLamThem, tmpSoPhutLamThemTS, pTinhPC150); XL.XemCong(new List <cUserInfo>() { tmpNV }, fNgayBD, fNgayKT); } else { XL.BUS_XacNhan(tmpNV, tmpOldChkINOUT, tmpNewChkINOUT, tmpIsOT, tmpSoPhutLamThem, tmpSoPhutLamThemTS, pTinhPC150); XL.XemCong(new List <cUserInfo>() { tmpNV }, fNgayBD, fNgayKT); } LoadDataGrid(); }
private void dtp_Sua_OnValueChanged(object sender, EventArgs e) { if (sender == dtpVao_Sua) { cShift tmpshift = cbCaVao_Sua.SelectedItem as cShift; DataRowView row = dgrdTongHop.Tag as DataRowView; DateTime tmpVao = (DateTime)row["TimeStrNgay"]; tmpVao = tmpVao.Date.Add(tmpshift.OnnDutyTS); DateTime inputTime = dtpVao_Sua.Value; if (inputTime != tmpVao) { cbCaVao_Sua.SelectedIndexChanged -= cbCa_Sua_OnSelectedIndexChanged; cbCaVao_Sua.SelectedIndex = 0; cbCaVao_Sua.SelectedIndexChanged += cbCa_Sua_OnSelectedIndexChanged; } dtpVao_Sua.Update(); } else { cShift tmpshift = cbCaRa_Sua.SelectedItem as cShift; DataRowView row = dgrdTongHop.Tag as DataRowView; DateTime tmpRa = (DateTime)row["TimeStrNgay"]; tmpRa = tmpRa.Date.Add(tmpshift.OffDutyTS); DateTime inputTime = dtpRa_Sua.Value; if (inputTime != tmpRa) { cbCaRa_Sua.SelectedIndexChanged -= cbCa_Sua_OnSelectedIndexChanged; cbCaRa_Sua.SelectedIndex = 0; cbCaRa_Sua.SelectedIndexChanged += cbCa_Sua_OnSelectedIndexChanged; } dtpRa_Sua.Update(); } }
private void cbVaoCa_SelectedIndexChanged(object sender, EventArgs e) { cShift tmpCa = (cShift)cbVaoCa.SelectedItem; DateTime dateVao = dateTimeVaoMoi.Value.Date.Add(tmpCa.OnnDutyTS); DateTime dateRa = dateTimeRaMoi.Value.Date.Add(tmpCa.OffDutyTS); dateTimeVaoMoi.Value = new DateTime(dateVao.Year, dateVao.Month, dateVao.Day, dateVao.Hour, dateVao.Minute, 0); dateTimeRaMoi.Value = new DateTime(dateRa.Year, dateRa.Month, dateRa.Day, dateRa.Hour, dateRa.Minute, 0); }
void dateTimeVaoMoi_ValueChanged(object sender, EventArgs e) { cShift tmpCa = (cShift)cbVaoCa.SelectedItem; if (dateTimeVaoMoi.Value.TimeOfDay != tmpCa.OnnDutyTS) { cbVaoCa.SelectedIndexChanged -= cbVaoCa_SelectedIndexChanged; cbVaoCa.SelectedIndex = 0; cbVaoCa.Refresh(); cbVaoCa.SelectedIndexChanged += cbVaoCa_SelectedIndexChanged; } }
private void dateTimeVaoMoi_ValueChanged(object sender, EventArgs e) { cbKieuNhapVao.SelectedIndexChanged -= cbKieuNhapVao_SelectedIndexChanged; int tempID = (int)cbKieuNhapVao.SelectedValue; cShift tempShift = ThamSo.DSCa.Find(item => item.ShiftID == tempID); if (dateTimeVaoMoi.Value.TimeOfDay != tempShift.OnnDutyTS) { cbKieuNhapVao.SelectedIndex = 0; } cbKieuNhapVao.SelectedIndexChanged += cbKieuNhapVao_SelectedIndexChanged; }
private void cbChonCa_SelectedIndexChanged(object sender, EventArgs e) { if (cbChonCa.DataSource == null || cbChonCa.Items.Count == 0) { #region reset layout tbGioLam.Text = "0"; tbTreSom.Text = "0"; tbOLaiThem.Text = "0"; checkXacNhanLamThem.Checked = false; checkXacNhanLamThem.Enabled = false; numPhutTinhLamThem.Value = 0; numPhutTinhLamThem.Enabled = false; #endregion return; } // đang chọn 1 ca nào đó, lấy ca đang chọn và fill thông tin cShift currCa = cbChonCa.SelectedItem as cShift; if (currCa == null) { return; } numPhutTinhLamThem.Value = 0; TimeSpan lamthem = new TimeSpan(0, 0, (int)numPhutTinhLamThem.Value, 0); DateTime ngaycong = tmpCurrChkINOUT.ThuocNgayCong; TimeSpan vaotre = XL.TinhVaoTre(tmpCurrChkINOUT.Vao.TimeStr, ngaycong.Add(currCa.OnnDutyTS), ngaycong.Add(currCa.chophepvaotreTS)); TimeSpan raasom = XL.TinhRaaSom(tmpCurrChkINOUT.Raa.TimeStr, ngaycong.Add(currCa.OffDutyTS), ngaycong.Add(currCa.chopheprasomTS)); tbTreSom.Text = Math.Round((vaotre + raasom).TotalMinutes, 2).ToString(); DateTime vaolam = XL.TinhVaoLam(tmpCurrChkINOUT.Vao.TimeStr, ngaycong.Add(currCa.OnnDutyTS), vaotre); DateTime raalam = XL.TinhRaaLam(tmpCurrChkINOUT.Raa.TimeStr, ngaycong.Add(currCa.OffDutyTS), raasom, lamthem); tbGioLam.Text = Math.Round((raalam - vaolam - currCa.LunchMinute).TotalHours, 2).ToString(); TimeSpan olaithem = XL.TinhOLaiThem(tmpCurrChkINOUT.Raa.TimeStr, ngaycong.Add(currCa.OffDutyTS), ngaycong.Add(currCa.batdaulamthemTS)); checkXacNhanLamThem.Checked = false; if (olaithem == ThamSo._0gio) { tbOLaiThem.Text = "0"; checkXacNhanLamThem.Enabled = false; numPhutTinhLamThem.Enabled = false; numPhutTinhLamThem.Value = 0; } else { tbOLaiThem.Text = Math.Floor(olaithem.TotalMinutes).ToString(); checkXacNhanLamThem.Enabled = true; numPhutTinhLamThem.Enabled = true; numPhutTinhLamThem.Value = 0; numPhutTinhLamThem.Maximum = Convert.ToDecimal(Math.Floor(olaithem.TotalMinutes)); } }
private void switchButton1_ValueChanged(object sender, EventArgs e) { cShift tmpCa = (cShift)cbCa.SelectedItem; bool tmpKieuGioVao = switchButton1.Value; if (!((tmpKieuGioVao && dateTimeGioMoi.Value.TimeOfDay == tmpCa.OnnDutyTS) || (tmpKieuGioVao == false && dateTimeGioMoi.Value.TimeOfDay == tmpCa.OffDutyTS))) { cbCa.SelectedIndexChanged -= cbCa_SelectedIndexChanged; cbCa.SelectedIndex = 0; cbCa.Refresh(); cbCa.SelectedIndexChanged += cbCa_SelectedIndexChanged; } }
private void rdbtnVaoRa_CheckedChanged(object sender, EventArgs e) { cShift tmpCa = (cShift)cbCa.SelectedItem; bool tmpKieuGioVao = rdbtnVao.Checked; if (!((tmpKieuGioVao && dateTimeGioMoi.Value.TimeOfDay == tmpCa.OnnDutyTS) || (tmpKieuGioVao == false && dateTimeGioMoi.Value.TimeOfDay == tmpCa.OffDutyTS))) { cbCa.SelectedIndexChanged -= cbCa_SelectedIndexChanged; cbCa.SelectedIndex = 0; cbCa.Refresh(); cbCa.SelectedIndexChanged += cbCa_SelectedIndexChanged; } }
void dtp_ValueChanged(object sender, EventArgs e) { DateTime timeBD = dtpBDLam.Value; DateTime timeKT = dtpKTLam.Value; TimeSpan giolam = timeKT - timeBD; if (giolam < ThamSo._0gio || giolam > ThamSo._24h00) { giolam = ThamSo._0gio; tbGioLam.Text = giolam.TotalHours.ToString("#0.##"); return; } cShift ca = cbCa.SelectedItem as cShift; if (ca == null) { AutoClosingMessageBox.Show("ca null", "", 1000); return; } if (ca.ShiftID == 0) { tbGioLam.Text = giolam.TotalHours.ToString("#0.##"); } else if (ca.ShiftID == int.MinValue) { if (giolam > ThamSo._8gio) { giolam = ThamSo._8gio; } } else if (ca.ShiftID == int.MinValue + 1) { if (giolam > ThamSo._12gio) { giolam = ThamSo._12gio; } } else // ca 1,2,3, hc.. { if (giolam > ca.WorkingTimeTS) { giolam = ca.WorkingTimeTS; } } tbGioLam.Text = giolam.TotalHours.ToString("#0.##"); }
private void frm_ChamCongTay_Load(object sender, EventArgs e) { ThamSo.VeCheckBox_CheckAll(dgrdDSNVTrgPhg, checkAll_GridDSNV, checkAll_CheckedChanged, new Point(7, 3)); m_listIDPhongBan = new List <int>(); dtpBDLam.ValueChanged += dtp_ValueChanged; dtpKTLam.ValueChanged += dtp_ValueChanged; dtpNgay.ValueChanged += dtpNgay_ValueChanged; m_DSCa = new List <cShift>(ThamSo.DSCa); cShift tmp = new cShift() { ShiftID = 0, ShiftCode = "--" }; cShift ca8tieng = new cShift() { ShiftID = int.MinValue, ShiftCode = "Ca 8 tiếng" }; cShift cadai = new cShift() { ShiftID = int.MinValue + 1, ShiftCode = "Ca dài 12 tiếng" }; m_DSCa.Insert(0, cadai); m_DSCa.Insert(0, ca8tieng); m_DSCa.Insert(0, tmp); cbCa.ValueMember = "ShiftID"; cbCa.DisplayMember = "ShiftCode"; cbCa.DataSource = m_DSCa; cbCa.SelectionChangeCommitted += cbCa_SelectionChangeCommitted; tbGioLam.TextChanged += tbGioLam_TextChanged; DataTable tablePhong = DAL.LayDSPhong(ThamSo.currUserID); if (tablePhong.Rows.Count == 0) { AutoClosingMessageBox.Show("Bạn chưa được phân quyền thao tác.", "Thông báo", 2000); return; } //2. lấy dữ liệu phòng ban được phép thao tác và load treePhongBan : xoá dữ liệu trước và load treePhongBan.Nodes.Clear(); loadTreePhgBan(treePhongBan, tablePhong); // đăng ký sự kiện cho tree và chọn topNode treePhongBan.AfterSelect += treePhongBan_AfterSelect; treePhongBan.SelectedNode = treePhongBan.TopNode; }
private void frm_ChamCongTay_Load(object sender, EventArgs e) { ThamSo.VeCheckBox_CheckAll(dgrdDSNVTrgPhg, checkAll_GridDSNV, checkAll_CheckedChanged, new Point(7, 3)); dtpBDLam.ValueChanged += dtp_ValueChanged; dtpKTLam.ValueChanged += dtp_ValueChanged; dtpNgay.ValueChanged += dtpNgay_ValueChanged; m_DSCa = new List <cShift>(ThamSo.DSCa); cShift tmp = new cShift() { ShiftID = 0, ShiftCode = "--" }; cShift ca8tieng = new cShift() { ShiftID = int.MinValue, ShiftCode = "Ca 8 tiếng" }; cShift cadai = new cShift() { ShiftID = int.MinValue + 1, ShiftCode = "Ca dài 12 tiếng" }; m_DSCa.Insert(0, cadai); m_DSCa.Insert(0, ca8tieng); m_DSCa.Insert(0, tmp); cbCa.ValueMember = "ShiftID"; cbCa.DisplayMember = "ShiftCode"; cbCa.DataSource = m_DSCa; cbCa.SelectionChangeCommitted += cbCa_SelectionChangeCommitted; tbGioLam.TextChanged += tbGioLam_TextChanged; // 1. khởi tạo các biến cục bộ flstIDPhongBan = new List <int>(); //2. lấy dữ liệu phòng ban được phép thao tác và load treePhongBan : xoá dữ liệu trước và load fTablePhongBan = ThamSo.TablePhongBan.Copy(); treePhongBan.Nodes.Clear(); loadTreePhgBan(treePhongBan, fTablePhongBan); // 3. Duyệt dữ liệu toàn bộ danh sách nhân viên được phép thao tác(và thêm cột check) // và khởi tạo các giá trị mặc định cho từng nhân viên fTableDSNV = ThamSo.DataTableDSNV.Copy(); fTableDSNV.Columns.Add("check", typeof(bool)); // đăng ký sự kiện cho tree và chọn topNode treePhongBan.AfterSelect += treePhongBan_AfterSelect; treePhongBan.SelectedNode = treePhongBan.TopNode; }
private void cbKieuNhapRa_SelectedIndexChanged(object sender, EventArgs e) { if (cbKieuNhapRa.SelectedIndex == 0) { return; } else { dateTimeRaMoi.ValueChanged -= dateTimeRaMoi_ValueChanged; int tempID = (int)cbKieuNhapRa.SelectedValue; cShift tempShift = _dsCaRa.Find(item => item.ShiftID == tempID); dateTimeRaMoi.Value = new DateTime(dateTimeRaMoi.Value.Year, dateTimeRaMoi.Value.Month, dateTimeRaMoi.Value.Day, tempShift.OffDutyTS.Hours, tempShift.OffDutyTS.Minutes, 0); dateTimeRaMoi.Update(); dateTimeRaMoi.ValueChanged += dateTimeRaMoi_ValueChanged; } }
//------------------ các hàm xử lý ------------------------------------ public void LoadDSGioTheoCa() { // 1. tạm thời disable comboBoxDSCa.SelectedIndexChanged, mở lên lại ở bước [TBD] comboBoxDSCa.SelectedIndexChanged -= comboBoxDSCa_SelectedIndexChanged; //2. lấy dữ liệu ca làm việc DataTable dt = null; _dsCaLamViec = new List <cShift>(); comboBoxDSCa.DataSource = dt; //DataRow dr = dt.NewRow(); //3. duyệt từng dòng dữ liệu, bind vào comboBox Ca làm việc for (int i = 0; i < dt.Rows.Count; i++) { if ((int)dt.Rows[i]["ShiftID"] == -1) { continue; } string tempShiftCode = dt.Rows[i]["ShiftCode"].ToString(); string tempOnduty = dt.Rows[i]["Onduty"].ToString(); string tempOffduty = dt.Rows[i]["Offduty"].ToString(); int tempDayCount = (int)dt.Rows[i]["DayCount"]; int tempWorkingTime = (int)dt.Rows[i]["WorkingTime"]; string tempCustomShiftCode = string.Empty; //GetDescriptionShiftCode(tempShiftCode, tempOnduty, tempOffduty, tempDayCount); cShift CaLVObj = new cShift() { ShiftID = (int)dt.Rows[i]["ShiftID"], ShiftCode = tempCustomShiftCode, OnnDutyTS = TimeSpan.Parse(tempOnduty), OffDutyTS = TimeSpan.Parse(tempOffduty), DayCount = tempDayCount, WorkingTimeTS = new TimeSpan(0, tempWorkingTime, 0) }; _dsCaLamViec.Add(CaLVObj); // tạo danh sách giờ chuẩn để xử lý hiển thị dateTimeGioSua string giolamviec = dt.Rows[i]["Onduty"].ToString(); TimeSpan tsp = TimeSpan.Parse(giolamviec); _dsGioVaoCa.Add(tsp); giolamviec = dt.Rows[i]["Offduty"].ToString(); tsp = TimeSpan.Parse(giolamviec); _dsGioRaCa.Add(tsp); } // 5. mở lại sự kiện comboBoxDSCa.SelectedIndexChanged comboBoxDSCa.SelectedIndexChanged += comboBoxDSCa_SelectedIndexChanged; }
private void dtp_Them_OnValueChanged(object sender, EventArgs eventArgs) { if (dgrdTongHop.SelectedRows.Count == 0) { return; } DataRowView row = dgrdTongHop.SelectedRows[0].DataBoundItem as DataRowView; if (sender == dtpVao_Them) { if (cbCaVao_Them.SelectedIndex == 0) { return; } cShift tmpshift = cbCaVao_Them.SelectedItem as cShift; DateTime tmpVao = (DateTime)row["TimeStrNgay"]; tmpVao = tmpVao.Date.Add(tmpshift.OnnDutyTS); DateTime inputTime = dtpVao_Them.Value; if (inputTime != tmpVao) { cbCaVao_Them.SelectedIndexChanged -= cbCa_Them_OnSelectedIndexChanged; cbCaVao_Them.SelectedIndex = 0; cbCaVao_Them.SelectedIndexChanged += cbCa_Them_OnSelectedIndexChanged; } dtpVao_Them.Update(); } else { if (cbCaRa_Them.SelectedIndex == 0) { return; } cShift tmpshift = cbCaRa_Them.SelectedItem as cShift; DateTime tmpRa = (DateTime)row["TimeStrNgay"]; tmpRa = tmpRa.Date.Add(tmpshift.OffDutyTS); DateTime inputTime = dtpRa_Them.Value; if (inputTime != tmpRa) { cbCaRa_Them.SelectedIndexChanged -= cbCa_Them_OnSelectedIndexChanged; cbCaRa_Them.SelectedIndex = 0; cbCaRa_Them.SelectedIndexChanged += cbCa_Them_OnSelectedIndexChanged; } dtpRa_Them.Update(); } }
void test3() { List <cShift> list1 = new List <cShift>() { new cShift() { ShiftCode = "1" }, new cShift() { ShiftCode = "2" } }; Debug.WriteLine(" List 1: " + list1.Count + " pt: " + list1[0].ShiftCode + " va " + list1[1].ShiftCode); List <cShift> listCopy = new List <cShift>(); listCopy.AddRange(list1); Debug.WriteLine(" List 1 Copy By AddRange: " + listCopy.Count + " pt: " + listCopy[0].ShiftCode + " va " + listCopy[1].ShiftCode); /* * List<cShift> list2 = new List<cShift>(list1); * Debug.WriteLine(" List 2 = new List<cShift>(list1) gom: " + list2.Count + " pt: " + list2[0].ShiftCode + " va " + list2[1].ShiftCode); * list2[0].ShiftCode = "3"; * Debug.WriteLine(" Modified element 0 of List 2 " + list2.Count + " pt: " + list2[0].ShiftCode + " va " + list2[1].ShiftCode); * Debug.WriteLine(" So voi list1[0] = " + list1[0].ShiftCode); * Debug.WriteLine(" So voi listCopy[0] = " + listCopy[0].ShiftCode); */ //=> 2 list cùng trỏ chung đến 1 phần tử => thay đổi pt của list này thì pt của đó của list kia cũng bị thay đổi List <cShift> list3 = new List <cShift>(); cShift[] temp = new cShift[] { }; list1.CopyTo(temp); list3 = temp.ToList(); //list3 = list1. list3[0].ShiftCode = "3"; Debug.WriteLine(" Modified element 0 of List 3 " + list3.Count + " pt: " + list3[0].ShiftCode + " va " + list3[1].ShiftCode); Debug.WriteLine(" So voi list1[0] = " + list1[0].ShiftCode); Debug.WriteLine(" So voi listCopy[0] = " + listCopy[0].ShiftCode); //=> 2 list cùng trỏ chung đến 1 phần tử => thay đổi pt của list này thì pt của đó của list kia cũng bị thay đổi }
void DtpGioMoiValueChanged(object sender, EventArgs e) { if (cbCa_Vao.SelectedIndex == 0) { return; // neu chon tuỳ chinh thi thoat ko lam gi het } cShift ca = cbCa_Vao.SelectedItem as cShift; // lay ca duoc chon và kiem tra xem gio vao có nằm trong khoảng hiểu ca ko. // neu ko hieu ca chuyen combo ve tùy chỉnh if (ca == null) { return; } bool kieugio = radVao.Checked; DateTime x = dtpGioMoi.Value; if (kieugio) // nếu chọn kiểu vào thì so sánh với ontimein, cutin { if (x.TimeOfDay >= ca.OnTimeInTS.Subtract(new TimeSpan(ca.DayCount, 0, 0, 0)) && x.TimeOfDay <= ca.CutInTS.Subtract(new TimeSpan(ca.DayCount, 0, 0, 0))) { // nằm trong khoảng hiểu thì ko làm gì hết } else // nằm ngoài khoảng hiểu, chuyển về tùy chọn tùy chỉnh { cbCa_Vao.SelectedIndex = 0; } } else // nếu chọn kiểu ra thì so sánh với ontimeout, cutout { if (x.TimeOfDay >= ca.OnTimeOutTS.Subtract(new TimeSpan(ca.DayCount, 0, 0, 0)) && x.TimeOfDay <= ca.CutOutTS.Subtract(new TimeSpan(ca.DayCount, 0, 0, 0))) { } else { cbCa_Vao.SelectedIndex = 0; } } }
private void cbCa_Raa_SelectionChangeCommitted(object sender, EventArgs e) { if (cbCa_Raa.SelectedIndex == 0) { return; // neu chon tuỳ chinh thi thoat ko lam gi het } cShift ca = cbCa_Raa.SelectedItem as cShift; // lay ca chon if (ca == null) { return; } // gán giờ theo ca, huỷ rồi bật lại sự kiện datetimepicker change dtpGio_Raa.ValueChanged -= dtpGio_Raa_ValueChanged; DateTime x = DateTime.Today.Add(ca.OffDutyTS); dtpGio_Raa.Value = x; dtpGio_Raa.Update(); dtpGio_Raa.ValueChanged += dtpGio_Raa_ValueChanged; }
private void cbChonCa_SelectedIndexChanged(object sender, EventArgs e) { cShift currCa = cbChonCa.SelectedItem as cShift; if (lbCheckINOUT.Tag == null) { return; } cChkInOut tmpCurrChkINOUT = (cChkInOut)lbCheckINOUT.Tag; if (currCa.LoaiCa == 0) { XL.TinhCongTheoCa(tmpCurrChkINOUT, currCa); } else { XL.TinhCongTheoCa(tmpCurrChkINOUT, currCa); } // gán giá trị cho các control chi tiết FillValueForControl(tmpCurrChkINOUT, currCa); }
private void cbCa_SelectionChangeCommitted(object sender, EventArgs e) { if (cbCa_Vao.SelectedIndex == 0) { return; // neu chon tuỳ chinh thi thoat ko lam gi het } cShift ca = cbCa_Vao.SelectedItem as cShift; // lay ca chon bool kieugio = radVao.Checked; if (ca == null) { return; } // gán giờ theo ca, huỷ rồi bật lại sự kiện datetimepicker change dtpGioMoi.ValueChanged -= DtpGioMoiValueChanged; DateTime x = DateTime.MinValue; x = (kieugio) ? DateTime.Today.Add(ca.OnnDutyTS) : DateTime.Today.Add(ca.OffDutyTS.Subtract(new TimeSpan(ca.DayCount, 0, 0, 0))); // dtpGioMoi.Value = x; dtpGioMoi.Update(); dtpGioMoi.ValueChanged += DtpGioMoiValueChanged; }
private void btnXacNhan_Click(object sender, EventArgs e) { #region lấy dữ liệu từ form currRowIndex = dgrdGioCoLamThem.SelectedRows[0].Index; numPhutTinhLamThem.Update(); int tmpSoPhutLamThem = (checkXacNhanLamThem.Checked) ? Convert.ToInt32(numPhutTinhLamThem.Value) : 0; int iUserEnrollNumber = currNV.UserEnrollNumber; cShift tmpNewShift = cbChonCa.SelectedItem as cShift; if (tmpNewShift == null) { return; } // lúc tính công chưa có gán THUOCCA lại nên ở đây phải gán lại #endregion bool pTinhPC150 = checkTinhPC150.Checked; if (tmpNewShift.OnnDutyTS > ThamSo._20h00 && tmpNewShift.Workingday > 1f) { cChkInOut[] arrCIO = XL.TachGio2Ca3Va1(currNV.DSCa, tmpCurrChkINOUT, tmpNewShift); DAL.ThemGioChoNV(iUserEnrollNumber, arrCIO[0].Raa.TimeStr, false, arrCIO[0].Raa.MachineNo, ThamSo.currUserID, "", "tách giờ ca 3&1, ca 3&1A"); DAL.ThemGioChoNV(iUserEnrollNumber, arrCIO[1].Vao.TimeStr, true, arrCIO[1].Vao.MachineNo, ThamSo.currUserID, "", "tách giờ ca 3&1, ca 3&1A"); XL.BUS_XacNhan(iUserEnrollNumber, arrCIO[0].ThuocCa, pTinhPC150, 0, arrCIO[0]); // vì ca 3 ko có làm thêm nên 0 XL.BUS_XacNhan(iUserEnrollNumber, arrCIO[1].ThuocCa, pTinhPC150, tmpSoPhutLamThem, arrCIO[1]); // vì ca 1 mới có làm thêm XL.XemCong(currNV, m_DSNV, fNgayBD, fNgayKT); } else { XL.BUS_XacNhan(iUserEnrollNumber, tmpNewShift, pTinhPC150, tmpSoPhutLamThem, tmpCurrChkINOUT); XL.XemCong(currNV, m_DSNV, fNgayBD, fNgayKT); } LoadDataGrid(); }
private void dgrdGioCoLamThem_SelectionChanged(object sender, EventArgs e) { if (dgrdGioCoLamThem.SelectedRows.Count == 0) { #region reset layout cbChonCa.DataSource = null; tbGioLam.Text = "0"; tbTreSom.Text = "0"; tbOLaiThem.Text = "0"; checkXacNhanLamThem.Checked = false; checkXacNhanLamThem.Enabled = false; numPhutTinhLamThem.Value = 0; numPhutTinhLamThem.Enabled = false; #endregion // ngoài reset layout thì disable nút xác nhận để tránh ấn nhầm gây lỗi btnXacNhan.Enabled = false; return; } // vì disable nếu e.rowindex = -1 nên bật lại nếu >= 0 btnXacNhan.Enabled = true; DataGridView tmpDataGrid = (DataGridView)sender; //1. lấy dòng đang chọn và dữ liệu được chọn. gán currView để có thể lấy được dữ liệu DataRowView dataRowView = tmpDataGrid.SelectedRows[0].DataBoundItem as DataRowView; currView = dataRowView; if (currView == null) { return; } //2. tìm user đang chọn để load lại ds ca mở rộng int tmpUserEnrollNumber = (int)dataRowView["UserEnrollNumber"]; currNV = m_DSNV.Find(item => item.UserEnrollNumber == tmpUserEnrollNumber); //3. xác định ngày đang chọn //3. tìm tmpCurrChkINOUT đang chọn tmpCurrChkINOUT = dataRowView["obj"] as cChkInOut; if (tmpCurrChkINOUT == null) { return; } DateTime tmpTimeStrVao = tmpCurrChkINOUT.Vao.TimeStr; DateTime tmpTimeStrRa = tmpCurrChkINOUT.Raa.TimeStr; DateTime ngaydangchon = tmpCurrChkINOUT.ThuocNgayCong; // tạo bản copy để tính công chứ ko tính công trực tiếp trên tmpCurrChkINOUT vì sẽ làm thay đổi giá trị bên trong của nó //tmpCurrChkINOUTCopy = MyUtility.DeepClone(tmpCurrChkINOUT); // 4. nếu đã thuộc ca thì giữ nguyên ca, ko load những cái khác cShift tmpCa = MyUtility.DeepClone(tmpCurrChkINOUT.ThuocCa); List <cShift> tmpDSCa; if (tmpCa.ShiftID != int.MinValue) // không cần kiểm tra tmpCa null vì DS đã lọc chỉ còn giữ HaveINOUT=true { tmpDSCa = new List <cShift>() { tmpCa }; } else // tmpCa.ShiftID == int.MinValue ==> ca KĐQĐ =>load ds ca mở rộng { tmpDSCa = new List <cShift>(currNV.DSCaMoRong); cShift caKDQD = tmpCa; // ca KDQD đã có sẵn shiftid = Minvalue XL.TaoCaTuDo(tmpCa, tmpTimeStrVao, ThamSo._8gio, ThamSo._05phut, ThamSo._10phut, ThamSo._30phut, 1f); cShift CaDaiA = new cShift() { ShiftID = int.MinValue + 1, ShiftCode = "Ca Dài 12 tiếng", LoaiCa = 1 }; XL.TaoCaTuDo(CaDaiA, tmpTimeStrVao, ThamSo._12gio, ThamSo._05phut, ThamSo._10phut, ThamSo._30phut, 1.5f); tmpDSCa.Insert(0, caKDQD); tmpDSCa.Insert(1, CaDaiA); // loại bỏ những ca chắc chắn ko xảy ra: ra ca < check vào 30ph. check ra < vào ca 30ph tmpDSCa.RemoveAll(item => item.LoaiCa == 0 && (tmpTimeStrRa <ngaydangchon.Add(item.OnnDutyTS).Add(ThamSo._30phut) || tmpTimeStrVao> ngaydangchon.Add(item.OffDutyTS).Subtract(ThamSo._30phut))); } // fill dữ liệu 2 dòng giờ vào -giờ ra, fill comboBox danh sách ca, set mặc định item chọn là 0 //, các giá trị còn lại thì do combo index changed fill tbGioVao.Text = tmpTimeStrVao.ToString("H:mm:ss d/M/yyyy"); tbGioRaa.Text = tmpTimeStrRa.ToString("H:mm:ss d/M/yyyy"); cbChonCa.ValueMember = "ShiftID"; cbChonCa.DisplayMember = "ShiftCode"; cbChonCa.DataSource = tmpDSCa; checkTinhPC150.Checked = currNV.MacDinhTinhPC150; // mặc định check tính pc 50% theo nhân viên phòng nào cbChonCa.Update(); }
private void btnThucHien_Click(object sender, EventArgs e) { // kiểm tra chọn ca làm việc chưa? chưa thì báo cShift ca = cbCa.SelectedItem as cShift; if (ca == null || cbCa.SelectedIndex == 0) { AutoClosingMessageBox.Show("Bạn chưa chọn ca làm việc.", "Thông báo", 1500); return; } //đã chọn ca làm việc DateTime ngay = dtpNgay.Value.Date; DateTime timeBD = dtpBDLam.Value; DateTime timeKT = dtpKTLam.Value; TimeSpan giolam = timeKT - timeBD; // kiểm tra giờ làm < 0 thì báo lỗi if (giolam < ThamSo._0gio) { giolam = ThamSo._0gio; AutoClosingMessageBox.Show("Giờ ra phải lớn hơn giờ vào.", "Lỗi", 1500); return; } string lydo = string.Empty; if (string.IsNullOrWhiteSpace(cbLyDo.Text)) { lydo = cbLyDo.Text; } string ghichu = tbGhiChu.Text; // kiểm tra chọn NV chưa, chưa thì báo DataTable tableCheckNV = dgrdDSNVTrgPhg.DataSource as DataTable; if (tableCheckNV == null) { return; } DataRow[] arrRows = tableCheckNV.Select("check = true", "UserEnrollNumber asc"); if (arrRows.Length == 0) { AutoClosingMessageBox.Show("Bạn chưa chọn nhân viên.", "Thông báo", 1500); return; } // đã chọn NV, lấy ds mã CC đã chọn bool flag = true; foreach (DataRow row in arrRows) { //dsNVcheck.Add((int)row["UserEnrollNumber"]); int iUserEnrollNumber = (int)row["UserEnrollNumber"]; if (ca.ShiftID == int.MinValue) { XL.TaoCaTuDo(ca, timeBD, ThamSo._8gio, ThamSo._05phut, ThamSo._10phut, ThamSo._30phut, 1f); } else if (ca.ShiftID == int.MinValue + 1) { XL.TaoCaTuDo(ca, timeBD, ThamSo._12gio, ThamSo._05phut, ThamSo._10phut, ThamSo._30phut, 1.5f); } string onnduty = ca.OnnDutyTS.ToString(@"hh\:mm"); string offduty = ca.OffDutyTS.ToString(@"hh\:mm"); int lategrace = Convert.ToInt32(ca.LateGraceTS.TotalMinutes); int earlygrace = Convert.ToInt32(ca.EarlyGraceTS.TotalMinutes); int afterot = Convert.ToInt32(ca.AfterOTTS.TotalMinutes); int daycount = ca.DayCount; Single wktime = Convert.ToSingle(ca.WorkingTimeTS.TotalMinutes); Single wkdayy = Convert.ToSingle(ca.Workingday); int sophutOT = (int)numSoPhutOT.Value; bool tinhPC150 = checkTinhPC150.Checked; int n; if (ca.OnnDutyTS == ThamSo._21h45 && ca.Workingday == 2f) // ca 3 và 1 => tách { cShift ca3 = ThamSo.DSCa.Find(o => o.OnnDutyTS == ThamSo._21h45 && o.Workingday == 1f); cShift ca1 = ThamSo.DSCa.Find(o => o.OnnDutyTS == ThamSo._05h45 && o.Workingday == 1f); n = DAL.ThemChamCongTay(iUserEnrollNumber, timeBD, ngay.Add(ca3.OffDutyTS), ca3.ShiftID, ca3.ShiftCode , ca3.OnnDutyTS.ToString(@"hh\:mm"), ca3.OffDutyTS.ToString(@"hh\:mm") , Convert.ToInt32(ca3.LateGraceTS.TotalMinutes), Convert.ToInt32(ca3.EarlyGraceTS.TotalMinutes), Convert.ToInt32(ca3.AfterOTTS.TotalMinutes) , ca3.DayCount, Convert.ToSingle(ca3.WorkingTimeTS.TotalMinutes), ca3.Workingday, 0, tinhPC150, lydo, ghichu); // add thêm 1 ngày ở thời gian bd vì ca 1 của ngày hôm sau n = DAL.ThemChamCongTay(iUserEnrollNumber, ngay.AddDays(1d).Add(ca1.OnnDutyTS).Add(new TimeSpan(0, 0, 1)), timeKT, ca1.ShiftID, ca1.ShiftCode , ca1.OnnDutyTS.ToString(@"hh\:mm"), ca1.OffDutyTS.ToString(@"hh\:mm") , Convert.ToInt32(ca1.LateGraceTS.TotalMinutes), Convert.ToInt32(ca1.EarlyGraceTS.TotalMinutes), Convert.ToInt32(ca1.AfterOTTS.TotalMinutes) , ca1.DayCount, Convert.ToSingle(ca1.WorkingTimeTS.TotalMinutes), ca1.Workingday, sophutOT, tinhPC150, lydo, ghichu); } else { // BUG chú ý thêm 1 giây để tránh tình trạng giờ vào trùng giờ ra n = DAL.ThemChamCongTay(iUserEnrollNumber, timeBD.Add(new TimeSpan(0, 0, 1)), timeKT, ca.ShiftID, ca.ShiftCode , onnduty, offduty, lategrace, earlygrace, afterot, daycount, wktime, wkdayy, sophutOT, tinhPC150, lydo, ghichu); } if (n == 0) { MessageBox.Show("Có lỗi trong quá trình thực hiện."); flag = false; break; } } if (flag) { AutoClosingMessageBox.Show("Thêm giờ chấm tay cho các nhân viên thành công.", "Thông báo", 2000); } }