private void XemLichSuSuaGioChamCong_Load(object sender, EventArgs e) { DataTable table = SqlDataAccessHelper.ExecuteQueryString( ThamSo.SelLichSuSuaGioChamCong(), new[] { "@UserID" }, new object[] { ThamSo.currUserID }); table.Columns.Add("TenThaoTac", typeof(string)); table.Columns.Add("KieuChamCu", typeof(string)); table.Columns.Add("KieuChamMoi", typeof(string)); int loai = 0; foreach (DataRow row in table.Rows) { loai = (int)row["CommandType"]; if (loai == -1) // xoá { row["TenThaoTac"] = "Xóa"; #region set null các cột liên quan đến giờ mới row["TimeStrNew"] = DBNull.Value; row["MachineNoNew"] = DBNull.Value; row["KieuChamMoi"] = DBNull.Value; #endregion } else if (loai == 0) // sửa { row["TenThaoTac"] = "Sửa"; } else // thêm { row["TenThaoTac"] = "Thêm"; #region set null các cột liên quan đến giờ cũ row["TimeStrOld"] = DBNull.Value; row["MachineNoOld"] = DBNull.Value; row["KieuChamCu"] = DBNull.Value; #endregion } if (row["MachineNoOld"] != DBNull.Value) { int maycu = (int)row["MachineNoOld"]; if (maycu % 2 == 1) { row["KieuChamCu"] = "Vào"; } else { row["KieuChamCu"] = "Ra"; } } if (row["MachineNoNew"] != DBNull.Value) { int maymoi = (int)row["MachineNoNew"]; if (maymoi % 2 == 1) { row["KieuChamMoi"] = "Vào"; } else { row["KieuChamMoi"] = "Ra"; } } } dataGridView1.DataSource = table; }
private void dgrdGioCoLamThem_RowEnter(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex == -1) { cbChonCa.SelectedIndexChanged -= cbChonCa_SelectedIndexChanged; cbChonCa.DataSource = null; tbTreSom.Tag = tbOLaiThem.Tag = lbTre.Tag = lbSom.Tag = null; tbTreSom.Text = tbOLaiThem.Text = lbTre.Text = lbSom.Text = string.Empty; return; } DataGridView tmpDataGrid = (DataGridView)sender; //1. lấy dòng đang chọn và dữ liệu được chọn DataRowView dataRowView = tmpDataGrid.Rows[e.RowIndex].DataBoundItem as DataRowView; tmpDataGrid.Tag = dataRowView; if (dataRowView == null) { return; } //2. lấy user đang chọn để load lại ds ca mở rộng int tmpUserEnrollNumber = (int)dataRowView["UserEnrollNumber"]; cUserInfo tmpNV = fListNVChk.Find(item => item.UserEnrollNumber == tmpUserEnrollNumber); //3. lấy tmpCurrChkINOUT đang chọn DateTime tmpTimeStrVao = (DateTime)dataRowView[ThamSo.nameVao]; DateTime tmpTimeStrRa = (DateTime)dataRowView[ThamSo.nameRa]; DateTime tmpNgay = ThamSo.GetDate(tmpTimeStrVao); cChkInOut tmpCurrChkINOUT = tmpNV.DSVaoRa.Find(item => (item.HaveINOUT > 0) && item.Vao.TimeStr == tmpTimeStrVao && item.Raa.TimeStr == tmpTimeStrRa); // 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ó cChkInOut 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 = tmpCurrChkINOUTCopy.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>(tmpNV.DSCaMoRong); cShift caKDQD = tmpCa; 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 giờ", LoaiCa = 1 }; XL.TaoCaTuDo(CaDaiA, tmpTimeStrVao, ThamSo._12gio, ThamSo._05phut, ThamSo._10phut, ThamSo._30phut, 1.5f); log.Debug(CaDaiA.OnnDutyTS + "\t" + CaDaiA.OffDutyTS + "\t" + CaDaiA.WorkingTimeTS); tmpDSCa.Insert(0, caKDQD); tmpDSCa.Insert(1, CaDaiA); tmpDSCa.RemoveAll(item => item.LoaiCa == 0 && (tmpTimeStrRa <tmpNgay.Add(item.OnnDutyTS) || tmpTimeStrVao> tmpNgay.Add(item.OffDutyTS))); } tbGioVao.Tag = tmpTimeStrVao; tbGioRaa.Tag = tmpTimeStrRa; tbGioVao.Text = tmpTimeStrVao.ToString("H:mm:ss d/M/yyyy"); tbGioRaa.Text = tmpTimeStrRa.ToString("H:mm:ss d/M/yyyy"); lbCheckINOUT.Tag = tmpCurrChkINOUTCopy; cbChonCa.SelectedIndexChanged -= cbChonCa_SelectedIndexChanged; cbChonCa.DataSource = tmpDSCa; cbChonCa.ValueMember = "ShiftID"; cbChonCa.DisplayMember = "ShiftCode"; cbChonCa.SelectedIndexChanged += cbChonCa_SelectedIndexChanged; cbChonCa.SelectedItem = tmpCa; checkTinhPC150.Checked = false; FillValueForControl(tmpCurrChkINOUTCopy, tmpCa); cbChonCa.Update(); }
private void btnTinhLuongVaXuatBB_Click(object sender, EventArgs e) { DateTime thang = new DateTime(dtpThang.Value.Year, dtpThang.Value.Month, 1); DateTime ngayBD = new DateTime(dtpThang.Value.Year, dtpThang.Value.Month, 1); DateTime ngayKT = new DateTime(dtpThang.Value.Year, dtpThang.Value.Month, DateTime.DaysInMonth(dtpThang.Value.Year, dtpThang.Value.Month)); ngayBD = ngayBD.AddDays(-1d); ngayKT = ngayKT.AddDays(2d).Subtract(new TimeSpan(0, 0, 1)); DataTable tableAllDSNV = SqlDataAccessHelper.ExecuteQueryString(ThamSo.SelStrLayDSNV(), null, null); List <cUserInfo> dsnv = new List <cUserInfo>(); KhoitaoDSNV(tableAllDSNV, dsnv); XL.XemCong(dsnv, ngayBD, ngayKT); double dsanluong = (double)(numSanLuong.Value); double ddongia = (double)numDonGia.Value; double dluongtoithieu = (double)numLuongTT.Value; double dcongnhat = (double)numLuongCongNhat.Value; double dboiduongca3 = (double)numBoiDuongCa3.Value; XL.DocLuongDieuChinh(thang, dsnv); XL.TinhLuong(thang, dsnv, ddongia, dsanluong, dluongtoithieu, dcongnhat, dboiduongca3); saveFileDialog.Filter = "Excel File|*.xlsx"; saveFileDialog.ShowDialog(); if (saveFileDialog.FileName == string.Empty) { return; } using (ExcelPackage p = new ExcelPackage()) { //Create a sheet p.Workbook.Worksheets.Add("Bang Luong"); ExcelWorksheet ws = p.Workbook.Worksheets[1]; ws.Name = "Bang Luong"; //Setting Sheet's name ws.Cells.Style.Font.Size = 8; //Default font size for whole sheet ws.Cells.Style.Font.Name = "Times News Roman"; //Default Font name for whole sheet ws.Cells.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; ws.Cells.Style.VerticalAlignment = ExcelVerticalAlignment.Center; //Merging cells and create a center heading for out table int iLastRow = 0, iLastCol = 0; ws.Cells[2, 1].Value = "STT"; ws.Cells[2, 2].Value = "Tên NV"; ws.Cells[2, 3].Value = "Mã CC"; ws.Cells[2, 4].Value = "T.Công"; ws.Cells[2, 5].Value = "T.PC"; ws.Cells[2, 6].Value = "Công CV"; ws.Cells[2, 7].Value = "Lương CB"; ws.Cells[2, 8].Value = "Làm qua đêm"; ws.Cells[2, 9].Value = "Bồi dưỡng ca 3"; ws.Cells[2, 10].Value = "Lương SP"; ws.Cells[2, 11].Value = "Điều chỉnh lương tháng trước"; ws.Cells[2, 12].Value = "Tổng lương"; ws.Cells[2, 1].Style.WrapText = true; ws.Cells[2, 2].Style.WrapText = true; ws.Cells[2, 3].Style.WrapText = true; ws.Cells[2, 4].Style.WrapText = true; ws.Cells[2, 5].Style.WrapText = true; ws.Cells[2, 6].Style.WrapText = true; ws.Cells[2, 7].Style.WrapText = true; ws.Cells[2, 8].Style.WrapText = true; ws.Cells[2, 9].Style.WrapText = true; ws.Cells[2, 10].Style.WrapText = true; ws.Cells[2, 11].Style.WrapText = true; ws.Cells[2, 12].Style.WrapText = true; for (int iRow = 3, index = 0; index < dsnv.Count; iRow++, index++) { cUserInfo nv = dsnv[index]; ws.Cells[iRow, 1].Value = index + 1; ws.Cells[iRow, 2].Value = nv.UserFullName; ws.Cells[iRow, 3].Value = nv.UserEnrollNumber; ws.Cells[iRow, 4].Value = nv.TongCongThang.ToString(); //; ws.Cells[iRow, 5].Value = nv.TongPCapThang.ToString(); //; ws.Cells[iRow, 6].Value = nv.TongCongCV.ToString("#0.#"); //; ws.Cells[iRow, 7].Value = nv.Luong.LuongCB.ToString("###,###,##0.###"); //; ws.Cells[iRow, 8].Value = nv.TongNgayQuaDem.ToString("#0"); //; ws.Cells[iRow, 9].Value = nv.Luong.BoiDuongQuaDem.ToString("###,##0"); //; ws.Cells[iRow, 10].Value = nv.Luong.LuongSP.ToString("###,###,##0.###"); //; ws.Cells[iRow, 11].Value = nv.Luong.LuongThangTruoc.ToString("###,###,##0.###"); //; ws.Cells[iRow, 12].Value = nv.Luong.TongLuong.ToString("###,###,##0.###"); //; ws.Cells[iRow, 1].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.Black); ws.Cells[iRow, 2].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.Black); ws.Cells[iRow, 3].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.Black); ws.Cells[iRow, 4].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.Black); ws.Cells[iRow, 5].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.Black); ws.Cells[iRow, 6].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.Black); ws.Cells[iRow, 7].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.Black); ws.Cells[iRow, 8].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.Black); ws.Cells[iRow, 9].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.Black); ws.Cells[iRow, 10].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.Black); ws.Cells[iRow, 11].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.Black); ws.Cells[iRow, 12].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.Black); } ws.Column(1).Width = 4; ws.Column(2).Width = 18; ws.Column(3).Width = 6; ws.Column(4).Width = 8; ws.Column(5).Width = 8; ws.Column(6).Width = 8; ws.Column(7).Width = 11.5; ws.Column(8).Width = 8; ws.Column(9).Width = 10; ws.Column(10).Width = 11.5; ws.Column(11).Width = 11.5; ws.Column(12).Width = 15; ws.Cells[1, 1, 1, 12].Value = "Bảng lương tháng " + dtpThang.Value.ToString("MM/yyyy"); ws.Cells[1, 1, 1, 12].Style.Font.Bold = true; ws.Cells[1, 1, 1, 12].Style.Font.Size = 14; ws.Cells[1, 1, 1, 12].Merge = true; ws.Cells[2, 1, 2, 12].Style.Font.Bold = true; Byte[] bin = p.GetAsByteArray(); string file_path = saveFileDialog.FileName; File.WriteAllBytes(file_path, bin); } saveFileDialog.FileName = string.Empty; }