private void Load_dataGridNewUserAccount()
 {
     try {
         DataTable dataTable = SqlDataAccessHelper.ExecuteQueryString("Select UserID, UserAccount from NewUserAccount", null, null);
         dataGridTK.DataSource = dataTable;
     } catch (Exception exception) {
         throw exception;
     }
 }
Beispiel #2
0
        private void ThemGioChamCong_Load(object sender, EventArgs e)
        {
            mDataTableOriginal = SqlDataAccessHelper.ExecuteQueryString(SelectStringDSGioVaoRa()
                                                                        , new string[] { "@ThoiGianBatDau", "@ThoiGianKetThuc" }
                                                                        , new object[] { _gioBatDau, _gioKetThuc });
            DataView dtv1 = new DataView(mDataTableOriginal, "MachineNo%2 = 1", string.Empty, DataViewRowState.CurrentRows);
            DataView dtv2 = new DataView(mDataTableOriginal, "MachineNo%2 = 0", string.Empty, DataViewRowState.CurrentRows);

            dataGridView1.DataSource = dtv1;
            dataGridView2.DataSource = dtv2;
            GanGiaTri(mDataTableOriginal);
        }
Beispiel #3
0
        private DataTable LayDSCacPhongban(int UserID)
        {
            string query = string.Empty;

            query += @"select RelationDept.ID, RelationDept.Description, RelationDept.RelationID, DeptPrivilege.IsYes 
						from RelationDept, DeptPrivilege
						where DeptPrivilege.IDD = RelationDept.ID						
						and DeptPrivilege.UserID = @UserID"                        ;
            DataTable kq;

            kq = SqlDataAccessHelper.ExecuteQueryString(query, new string[] { "@UserID" }, new object[] { UserID });
            return(kq);
        }
Beispiel #4
0
        private DataTable LayDSTaikhoan()
        {
            string query = string.Empty;

            #region query
            query += @"		SELECT	NewUserAccount.UserAccount, NewUserAccount.UserID
							FROM	NewUserAccount
							where	NewUserAccount.UserID <> @UserID  "                            ;
            #endregion
            DataTable kq;
            kq = SqlDataAccessHelper.ExecuteQueryString(query, new string[] { "@UserID" }, new object[] { ThamSo.currUserID });
            return(kq);
        }
Beispiel #5
0
        private DataTable LayDSChucNang(int UserID)
        {
            string query = string.Empty;

            #region query

            query += @"select distinct  MenuPrivilege.UserID, MenuPrivilege.MenuID, MenuPrivilege.IsYes from MenuPrivilege
					where MenuPrivilege.UserID = @UserID"                    ;

            #endregion

            DataTable kq = SqlDataAccessHelper.ExecuteQueryString(query, new string[] { "@UserID" }, new object[] { UserID });
            return(kq);
        }
        private void Load_cbTaikhoanWE()
        {
            try {
                DataTable dataTable = SqlDataAccessHelper.ExecuteQueryString(
                    @"  select UserID, UserAccount from UserAccount 
						where UserAccount not in (select NewUserAccount.UserAccount from NewUserAccount)"                        , null, null);
                cbTaikhoanWE.DataSource    = dataTable;
                cbTaikhoanWE.DisplayMember = "UserAccount";
                cbTaikhoanWE.ValueMember   = "UserID";
                tbPass1.Text = tbPass2.Text = string.Empty;
                if (dataTable == null || dataTable.Rows.Count == 0)
                {
                    btnTaoTK.Enabled = false;
                }
            } catch (Exception exception) {
                throw exception;
            }
        }
Beispiel #7
0
 private void ChuanBiDataTableDSNhanVien()
 {
     ThamSo.DataTableDSNV = SqlDataAccessHelper.ExecuteQueryString(ThamSo.queryDSNVThaoTac,
                                                                   new[] { "@UserID", "@IsYes" }, new object[] { ThamSo.currUserID, 1 });
 }
Beispiel #8
0
 private void ChuanBiDataTablePhongBan()
 {
     ThamSo.TablePhongBan = SqlDataAccessHelper.ExecuteQueryString(ThamSo.queryDSPhongBan,
                                                                   new[] { "@UserID", "@IsYes" }, new object[] { ThamSo.currUserID, 1 });
 }
Beispiel #9
0
        private void ChuanBiDSLichTrinh()
        {
            if (ThamSo.DSLichTrinh == null)
            {
                ThamSo.DSLichTrinh = new List <cShiftSchedule>();
            }
            else
            {
                ThamSo.DSLichTrinh.Clear();
            }
            List <cShift> tmpDSCa = ThamSo.DSCa;

            DataTable table          = SqlDataAccessHelper.ExecuteQueryString(ThamSo.queryDSLichTrinh, null, null);
            int       tempScheduleID = -1;

            foreach (DataRow dataRow in table.Rows)
            {
                if (tempScheduleID == -1)
                {
                    tempScheduleID = (int)dataRow["SchID"];
                }
                else
                {
                    if (tempScheduleID == (int)dataRow["SchID"])
                    {
                        continue;
                    }
                    else
                    {
                        tempScheduleID = (int)dataRow["SchID"];
                    }
                }

                //= (int)dataRow["SchID"]; // tempT1, tempT2, tempT3, tempT4, tempT5, tempT6, tempT7;
                DataRow[]      arrSubRecord = table.Select("SchID = " + tempScheduleID, string.Empty, DataViewRowState.CurrentRows);
                cShiftSchedule tmpLichTrinh = new cShiftSchedule()
                {
                    SchID = tempScheduleID
                };
                tmpLichTrinh.ListT1 = new List <cShift>();
                tmpLichTrinh.ListT2 = new List <cShift>();
                tmpLichTrinh.ListT3 = new List <cShift>();
                tmpLichTrinh.ListT4 = new List <cShift>();
                tmpLichTrinh.ListT5 = new List <cShift>();
                tmpLichTrinh.ListT6 = new List <cShift>();
                tmpLichTrinh.ListT7 = new List <cShift>();
                foreach (DataRow subRecord in arrSubRecord)
                {
                    int    tempTChungCho1Hang = (int)subRecord["T1"]; // tempT1, tempT2, tempT3, tempT4, tempT5, tempT6, tempT7;
                    cShift tempShift          = tmpDSCa.Find(item => item.ShiftID == tempTChungCho1Hang);

                    tmpLichTrinh.ListT1.Add(tempShift);
                    tmpLichTrinh.ListT2.Add(tempShift);
                    tmpLichTrinh.ListT3.Add(tempShift);
                    tmpLichTrinh.ListT4.Add(tempShift);
                    tmpLichTrinh.ListT5.Add(tempShift);
                    tmpLichTrinh.ListT6.Add(tempShift);
                    tmpLichTrinh.ListT7.Add(tempShift);
                }
                ThamSo.DSLichTrinh.Add(tmpLichTrinh);
            }
        }
Beispiel #10
0
        private void ChuanBiDSCaLamViec()
        {
            if (ThamSo.DSCa == null)
            {
                ThamSo.DSCa = new List <cShift>();
            }
            else
            {
                ThamSo.DSCa.Clear();
            }

            //ko cần try catch ở đây
            DataTable dt = SqlDataAccessHelper.ExecuteQueryString(ThamSo.queryDSCa, null, null);

            if (dt.Rows.Count == 0)
            {
                return;
            }
            foreach (DataRow row in dt.Rows)
            {
                int    iShiftID   = (int)row["ShiftID"];
                string sShiftCode = row["ShiftCode"].ToString();

                TimeSpan tsOnDuty;
                TimeSpan.TryParse(row["Onduty"].ToString(), out tsOnDuty);
                TimeSpan tOnTimeIn = tsOnDuty.Subtract(new TimeSpan(0, (int)row["OnTimeIn"], 0));
                TimeSpan tCutIn    = tsOnDuty.Add(new TimeSpan(0, (int)row["CutIn"], 0));

                int      iDayCount     = (int)row["DayCount"];
                int      iShowPosition = (int)row["ShowPosition"];
                TimeSpan tOffDuty;
                TimeSpan.TryParse(row["Offduty"].ToString(), out tOffDuty);

                tOffDuty = tOffDuty.Add(new TimeSpan(iDayCount, 0, 0, 0));
                TimeSpan tOnTimeOut = tOffDuty.Subtract(new TimeSpan(0, (int)row["OnTimeOut"], 0));
                TimeSpan tCutOut    = tOffDuty.Add(new TimeSpan(0, (int)row["CutOut"], 0));

                TimeSpan tAfterOT    = new TimeSpan(0, (int)row["AfterOT"], 0);
                TimeSpan tLateGrace  = new TimeSpan(0, (int)row["LateGrace"], 0);
                TimeSpan tEarlyGrace = new TimeSpan(0, (int)row["EarlyGrace"], 0);

                TimeSpan tOnLunch = ThamSo._0gio, tOffLunch = ThamSo._0gio;
                if (row["OnLunch"] != DBNull.Value && row["OffLunch"] != DBNull.Value)
                {
                    TimeSpan.TryParse(row["OnLunch"].ToString(), out tOnLunch);
                    TimeSpan.TryParse(row["OffLunch"].ToString(), out tOffLunch);
                }

                int    tempWorkingTime = int.Parse(row["WorkingTime"].ToString());
                cShift tempShift       = new cShift()
                {
                    LoaiCa          = 0,
                    ShiftID         = iShiftID, ShiftCode = sShiftCode,
                    DayCount        = iDayCount, QuaDem = (iDayCount == 1),
                    OnnDutyTS       = tsOnDuty, OffDutyTS = tOffDuty,
                    OnTimeInTS      = tOnTimeIn, CutInTS = tCutIn, OnTimeOutTS = tOnTimeOut, CutOutTS = tCutOut,
                    AfterOTTS       = tAfterOT,
                    LateGraceTS     = tLateGrace, EarlyGraceTS = tEarlyGrace,
                    Workingday      = Convert.ToSingle(row["Workingday"].ToString()),
                    ShowPosition    = iShowPosition,
                    WorkingTimeTS   = new TimeSpan(0, tempWorkingTime, 0),
                    chophepvaotreTS = tsOnDuty.Add(tLateGrace),
                    chopheprasomTS  = tOffDuty.Subtract(tEarlyGrace),
                    batdaulamthemTS = tOffDuty.Add(ThamSo._30phut),//[TBD] tempOffDuty + tempAfterOT,
                    LunchMinute     = tOffLunch.Subtract(tOnLunch)
                };
                ThamSo.DSCa.Add(tempShift);
            }
        }
Beispiel #11
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            #region lay du lieu tu form
            string tempUsername = tb_UserName.Text, tempPassword = tb_Password.Text;

            string passEncrypt = MyUtility.Mahoa(tb_Password.Text);

            string passdefault = DateTime.Now.Minute + "@" + DateTime.Now.Hour + "@" + DateTime.Now.Month + "@" + DateTime.Now.Day;
            #endregion

            if (tempUsername == Resources.rootAccount && tempPassword == passdefault)
            {
                ThamSo.currUserID      = int.Parse(Resources.rootUserID);
                ThamSo.currUserAccount = Resources.rootAccount;
                panelDangNhap.Visible  = false;
                PhanQuyenMenu(0);
            }
            else
            {
                string tmpConnStr = KiemtraDocFileKetnoiDL(Resources.ConnectionStringPath);

                if (string.IsNullOrEmpty(tmpConnStr))   // đọc file bị lỗi
                {
                    frm_KetNoiCSDL frmKetNoiCsdl = new frm_KetNoiCSDL();
                    if (frmKetNoiCsdl.ShowDialog() == DialogResult.Yes)
                    {
                        SqlDataAccessHelper.ConnectionString = frmKetNoiCsdl.fConnectionString;
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    // đọc được file, test kết nối với CSDL

                    SqlConnection connection = new SqlConnection(tmpConnStr);
                    try {
                        connection.Open();
                    } catch (Exception) {
                        connection.Close();
                        AutoClosingMessageBox.Show("Mất kết nối đến Máy chủ. Vui lòng thử lại.", "Lỗi", 2000);
                        return;
                    }
                    // ra khỏi try catch nghĩa là mở kết nối thành công, nên đóng lại và gán chuỗi kết nối luôn
                    connection.Close();
                    SqlDataAccessHelper.ConnectionString = tmpConnStr;

                    try {
                        DataTable dt = SqlDataAccessHelper.ExecuteQueryString(ThamSo.queryLogIn,
                                                                              new[] { "@UserAccount", "@Password" },
                                                                              new object[] { tb_UserName.Text, passEncrypt });

                        if (dt.Rows.Count != 0)   // tài khoản thường ->

                        {
                            ThamSo.currUserID      = (int)dt.Rows[0]["UserID"];
                            ThamSo.currUserAccount = dt.Rows[0]["UserAccount"].ToString();
                            panelDangNhap.Visible  = false;

                            PhanQuyenMenu(1);

                            ChuanBiDuLieu();
                            //subMenuChamCongTay_Click(subMenuChamCongTay, null); //[TBD] nhớ bỏ khi release
                        }
                        else if (MessageBox.Show("Tài khoản hoặc mật khẩu chưa đúng. Vui lòng điền lại.", Resources.MessBoxTitle_ThongBao, MessageBoxButtons.OK) == DialogResult.OK)
                        {
                            tb_UserName.Text = tb_Password.Text = string.Empty;
                        }
                    } catch (Exception) {
                        AutoClosingMessageBox.Show("Mất kết nối đến Máy chủ hoặc CSDL không đúng. Vui lòng thử lại.", "Lỗi", 2000);
                    }
                }
            }
        }
Beispiel #12
0
        /// <summary>
        /// phân quyền
        /// </summary>
        /// <param name="pAccountType">0: root, 1: account trong CSDL</param>
        private void PhanQuyenMenu(int pAccountType)
        {
            // tài khoản root thì xem nếu chưa tồn thì cho phép tạo tài khoản, còn các menu khác đều ẩn
            if (pAccountType == 0)
            {
                MenuAdmin.Visible = MenuAdmin.Enabled = true;
                MenuAdminSub_TaoAccount.Visible = MenuAdminSub_TaoAccount.Enabled = true;

                MenuDuLieu.Visible     = MenuDuLieu.Enabled = true;
                SubMenu_ChonDL.Enabled = true;

                return;
            }
            // account thường

            DataTable dt = SqlDataAccessHelper.ExecuteQueryString(ThamSo.queryPhanQuyenMenu, new[] { "@UserID" }, new object[] { ThamSo.currUserID });

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                bool enable = (bool)dt.Rows[i]["IsYes"];
                switch ((int)dt.Rows[i]["MenuID"])
                {
                case 1009:
                    MenuDuLieu.Enabled     = enable;
                    SubMenu_ChonDL.Enabled = enable;
                    break;

                case 4001:
                    MenuChamCong.Enabled           = enable;
                    SubMenu_XemCongNV.Enabled      = enable;
                    SubMenu_DiemDanh.Enabled       = enable;
                    SubMenu_KhaiBaoVang.Enabled    = enable;
                    MenuHoatDong.Enabled           = enable;
                    SubMenu_SuaGioHangLoat.Enabled = enable;
                    SubMenu_xemHistory.Enabled     = enable;
                    break;

                case 5001:
                    if (enable)
                    {
                        MenuTaiKhoan.Enabled  = true;
                        SubMenu_TaoTK.Enabled = true;
                    }
                    else
                    {
                        SubMenu_TaoTK.Enabled = false;
                    }
                    break;

                case 5002:
                    if (enable)
                    {
                        MenuTaiKhoan.Enabled  = true;
                        SubMenu_DoiMK.Enabled = enable;
                    }
                    else
                    {
                        SubMenu_DoiMK.Enabled = false;
                    }
                    break;

                default:
                    break;
                }
            }
        }
        private void btnXem_Click(object sender, EventArgs e)
        {
            //0. xoa dữ liệu cũ
            //1. lấy dữ liệu từ form
            dtpBD.Update(); dtpKT.Update();
            DateTime startTime = dtpBD.Value;
            DateTime endTime   = dtpKT.Value;

            dgrdDSNVTrgPhg.EndEdit();
            this.BindingContext[this.dgrdDSNVTrgPhg.DataSource].EndCurrentEdit();
            //2. lấy danh sách nhân viên check
            LayDSNVXemCong(dgrdDSNVTrgPhg.DataSource as DataTable, flstDSNVChkXemGioVaoRa, flstDSNVPhong);

            //3. lấy dữ liệu chấm công của các nhân viên
            if (flstDSNVChkXemGioVaoRa.Count == 0)
            {
                AutoClosingMessageBox.Show("Chưa chọn Nhân viên", "Thông báo", 2000);
                return;
            }

            try {
                fDataTableChkInOut = SqlDataAccessHelper.ExecuteQueryString(SelStr_GetDSGioVaoRa()
                                                                            , new[] { "@BatDauVao", "@KetThucVao", "@BatDauRa", "@KetThucRa" }
                                                                            , new object[] { startTime, endTime, startTime, endTime });
            } catch (Exception) {
                MessageBox.Show("Mất kết nối đến máy chủ. Vui lòng thử lại sau.", "Lỗi");
                return;
            }

            DataTable dataTableChiTietVao = dgrdCTGioVao.DataSource as DataTable;
            DataTable dataTableChiTietRa  = dgrdCTGioRa.DataSource as DataTable;

            if (dataTableChiTietVao == null)
            {
                dataTableChiTietVao = fDataTableChkInOut.Clone();
                dataTableChiTietVao.Columns.Add("check", typeof(bool));
            }
            else
            {
                dataTableChiTietVao.Rows.Clear();
            }

            if (dataTableChiTietRa == null)
            {
                dataTableChiTietRa = fDataTableChkInOut.Clone();
                dataTableChiTietRa.Columns.Add("check", typeof(bool));
            }
            else
            {
                dataTableChiTietRa.Rows.Clear();
            }


            //4. xử lý dữ liệu để đưa lên lưới tổng hợp
            foreach (DataRow row in fDataTableChkInOut.Rows)
            {
                if ((int)row["MachineNo"] % 2 == 1)
                {
                    dataTableChiTietVao.ImportRow(row);
                }
                else
                {
                    dataTableChiTietRa.ImportRow(row);
                }
            }
            dgrdCTGioVao.DataSource              = dataTableChiTietVao;
            dgrdCTGioRa.DataSource               = dataTableChiTietRa;
            checkAllGridCheckIn.CheckedChanged  -= checkAll_CheckedChanged;
            checkAllGridCheckOut.CheckedChanged -= checkAll_CheckedChanged;
            checkAllGridCheckIn.Checked          = false;
            checkAllGridCheckOut.Checked         = false;
            checkAllGridCheckIn.CheckedChanged  += checkAll_CheckedChanged;
            checkAllGridCheckOut.CheckedChanged += checkAll_CheckedChanged;
        }
        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;
        }
Beispiel #15
0
        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;
        }