Ejemplo n.º 1
0
        private void dtpNgay_ValueChanged(object sender, EventArgs e)
        {
            try             //general try catch
            {
                if (XL.KiemtraDulieuCapnhatTuServer(DateTime.Now) == false)
                {
                    ACMessageBox.Show(Resources.Text_DuLieuChamCongChuaUpdate, Resources.Caption_ThongBao, 4000);
                }

                treePhongBan_AfterSelect(treePhongBan, new TreeViewEventArgs(treePhongBan.SelectedNode, TreeViewAction.ByMouse));
            } catch (Exception ex)             //general try catch
            {
                lg.Error(string.Format("[{0}]_[{1}]\n", this.Name, System.Reflection.MethodBase.GetCurrentMethod().Name), ex);
                MessageBox.Show(Resources.Text_CoLoi, Resources.Caption_Loi);
            }
        }
Ejemplo n.º 2
0
        private void frm_DiemDanhNV_Load(object sender, EventArgs e)
        {
            DataTable tablePhong = DAL.LayDSPhong(XL2.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);

            if (XL.KiemtraDulieuCapnhatTuServer(DateTime.Now) == false)
            {
                AutoClosingMessageBox.Show("Dữ liệu chấm công chưa được cập nhật mới nhất từ các máy chấm công.\nCác thay đổi giờ chấm công có thể làm sai sót giờ chấm công thực tế khi dữ liệu được cập nhật.", "Thông báo", 4000);
            }

            // đăng ký sự kiện cho tree và chọn topNode
            treePhongBan.AfterSelect += treePhongBan_AfterSelect;
            treePhongBan.SelectedNode = treePhongBan.TopNode;
            dtpNgay.ValueChanged     += dtpNgay_ValueChanged;
        }
        private void btnXem_Click(object sender, EventArgs e)
        {
            if (XL2.KiemtraKetnoiCSDL() == false)
            {
                return;
            }

            //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();
            BindingContext[dgrdDSNVTrgPhg.DataSource].EndCurrentEdit();

            try             //general try catch
            {
                #region     //2. lấy danh sách nhân viên check, nếu chưa có nv nào check thì thông báo

                var listNV = (from DataGridViewRow dataGridViewRow in dgrdDSNVTrgPhg.Rows
                              let rowView = dataGridViewRow.DataBoundItem as DataRowView
                                            where (rowView["check"] != DBNull.Value && (bool)rowView["check"])
                                            select(cUserInfo) rowView["cUserInfo"])
                             .ToList();

                if (listNV.Count == 0)
                {
                    ACMessageBox.Show(Resources.Text_ChuaChonNV, Resources.Caption_ThongBao, 2000);                     //
                    GC.Collect();
                    return;
                }

                #endregion
                //2. lấy dữ liệu chấm công của các nhân viên
                if (XL.KiemtraDulieuCapnhatTuServer(DateTime.Now) == false)
                {
                    ACMessageBox.Show(Resources.Text_DuLieuChamCongChuaUpdate, Resources.Caption_ThongBao, 4000);
                }

                DataTable fDataTableChkInOut = new DataTable();
                try {
                    var Arr_MaCC = (from nv in listNV select nv.MaCC).ToArray();
                    fDataTableChkInOut = DAO5.LayTableCIO_A(Arr_MaCC, startTime, endTime);
                    fDataTableChkInOut.Columns.Add("check", typeof(bool));
                } catch (Exception exception) {
                    lg.Error(string.Format("[{0}]_[{1}]\n", this.Name, System.Reflection.MethodBase.GetCurrentMethod().Name), exception);

                    MessageBox.Show(Resources.Text_MatKetNoiCSDL, Resources.Caption_Loi);
                    GC.Collect();
                }

                DataTable dataTableChiTietVao = dgrdCTGioVao.DataSource as DataTable;
                DataTable dataTableChiTietRa  = dgrdCTGioRa.DataSource as DataTable;
                if (dataTableChiTietVao == null)
                {
                    dataTableChiTietVao = fDataTableChkInOut.Clone();
                }
                else
                {
                    dataTableChiTietVao.Rows.Clear();
                }

                if (dataTableChiTietRa == null)
                {
                    dataTableChiTietRa = fDataTableChkInOut.Clone();
                }
                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;
            } catch (Exception ex)             //general try catch
            {
                lg.Error(string.Format("[{0}]_[{1}]\n", this.Name, System.Reflection.MethodBase.GetCurrentMethod().Name), ex);
                MessageBox.Show(Resources.Text_CoLoi, Resources.Caption_Loi);
            }
        }
Ejemplo n.º 4
0
        private void btnXem_Click(object sender, EventArgs e)
        {
            if (XL2.KiemtraKetnoiCSDL() == false)
            {
                return;
            }


            #region             //1. lấy dữ liệu từ form lấy ngày BD và kết thúc nếu quá 62 ngày thì báo

            dtpNgayBD.Update();
            dtpNgayKT.Update();
            var ngayBD = dtpNgayBD.Value.Date;
            var ngayKT = dtpNgayKT.Value.Date;
            if (ngayBD > ngayKT)
            {
                MyUtility.Swap(ref ngayBD, ref ngayKT);
            }
            var ngayBD_Bef2D = ngayBD.AddDays(-2d);
            var ngayKT_Aft2D = ngayKT.AddDays(2d);
            // ngày 1->5 là trừ ra = 4, + 1 để ra số ngày, + thêm 2 để ra cột(UserEnrollNumber và số lượng)

            if ((ngayKT - ngayBD).Duration() > new TimeSpan(62, 0, 0, 0))
            {
                if (MessageBox.Show(Resources.Text_KhoangThoiGianXemCongQuaDai, Resources.Caption_XacNhan, MessageBoxButtons.YesNo) == DialogResult.No)
                {
                    return;
                }
            }
            #endregion

            XL.SaveSetting(lastStartDate: ngayBD, lastEndDate: ngayKT);
            BindingContext[dgrdDSNVTrgPhg.DataSource].EndCurrentEdit();

            #region             //2. lấy danh sách nhân viên check, nếu chưa có nv nào check thì thông báo

            var listNV = (from DataGridViewRow dataGridViewRow in dgrdDSNVTrgPhg.Rows
                          let rowView = dataGridViewRow.DataBoundItem as DataRowView
                                        where (rowView["check"] != DBNull.Value && (bool)rowView["check"])
                                        select(cUserInfo) rowView["cUserInfo"])
                         .ToList();

            if (listNV.Count == 0)
            {
                ACMessageBox.Show(Resources.Text_ChuaChonNV, Resources.Caption_ThongBao, 2000);                 //
                GC.Collect();
                return;
            }

            #endregion

            //3. lấy dữ liệu chấm công của các nhân viên
            try {
                if (XL.KiemtraDulieuCapnhatTuServer(DateTime.Now) == false)
                {
                    ACMessageBox.Show(Resources.Text_DuLieuChamCongChuaUpdate, Resources.Caption_ThongBao, 4000);
                }
                WaitWindow.Show(this.XuLyXemCong, "Đang xử lý, vui lòng đợi trong giây lát...", new object[] { listNV, ngayBD_Bef2D, ngayKT_Aft2D });
                //XL.XemCong_v08(listNV, ngayBD_Bef2D, ngayKT_Aft2D);
                Reload4DataGrid(listNV);
            } catch (Exception exception) {
                lg.Error(string.Format("[{0}]_[{1}]\n", this.Name, System.Reflection.MethodBase.GetCurrentMethod().Name), exception);
                MessageBox.Show(Resources.Text_MatKetNoiCSDL, Resources.Caption_Loi);
                GC.Collect();
            }
        }
        private void btnXem_Click(object sender, EventArgs e)
        {
            if (SqlDataAccessHelper.TestConnection(SqlDataAccessHelper.ConnectionString) == false)
            {
                AutoClosingMessageBox.Show("Mất kết nối với CSDL. Vui lòng thử lại sau.", "Lỗi", 2000);
                return;
            }
            //1. lấy dữ liệu từ form

            #region lấy ngày BD và kết thúc nếu quá 62 ngày thì báo

            dtpNgayBD.Update();
            dtpNgayKT.Update();
            var ngayBD       = dtpNgayBD.Value.Date;
            var ngayKT       = dtpNgayKT.Value.Date;
            var ngayBD_Bef2D = ngayBD.AddDays(-2d);
            var ngayKT_Aft2D = ngayKT.AddDays(2d);
            // ngày 1->5 là trừ ra = 4, + 1 để ra số ngày, + thêm 2 để ra cột(UserEnrollNumber và số lượng)

            if ((ngayKT - ngayBD).Duration() > new TimeSpan(62, 0, 0, 0))
            {
                if (MessageBox.Show("Khoảng thời gian xem công quá dài, dữ liệu chấm công từ server lớn có thể làm tràn bộ nhớ. \nBạn muốn tiếp tục?", "Xác nhận", MessageBoxButtons.YesNo) == DialogResult.No)
                {
                    return;
                }
            }
            #endregion


            BindingContext[dgrdDSNVTrgPhg.DataSource].EndCurrentEdit();
            //2. lấy danh sách nhân viên check, nếu chưa có nv nào check thì thông báo
            IEnumerable <DataGridViewRow> lstGridViewRow = dgrdDSNVTrgPhg.Rows.Cast <DataGridViewRow>();
            var listNV = (from row in (lstGridViewRow)
                          where ((DataRowView)row.DataBoundItem)["check"] != DBNull.Value && (bool)((DataRowView)row.DataBoundItem)["check"]
                          select(cUserInfo)((DataRowView)row.DataBoundItem).Row["cUserInfo"]).ToList();

            if (listNV.Count == 0)
            {
                AutoClosingMessageBox.Show("Bạn chưa chọn Nhân viên", "Thông báo", 2000);
                GC.Collect();
                return;
            }

            m_Bang_TongHopXemCong.Rows.Clear();
            m_Bang_GioKDQD.Rows.Clear();
            m_Bang_GioThieuCheck.Rows.Clear();
            m_Bang_ThK_TreSom.Rows.Clear();
            //3. lấy dữ liệu chấm công của các nhân viên
            try {
                if (XL.KiemtraDulieuCapnhatTuServer(DateTime.Now) == false)
                {
                    AutoClosingMessageBox.Show("Dữ liệu chấm công chưa được cập nhật mới nhất từ các máy chấm công.\nCác thay đổi giờ chấm công có thể làm sai sót giờ chấm công thực tế khi dữ liệu được cập nhật.", "Thông báo", 4000);
                }
                XL.XemCong(listNV, ngayBD_Bef2D, ngayKT_Aft2D);
                XL.TaoTableXemCong(listNV, m_Bang_TongHopXemCong);
                XL.TaoTableGioKDQD(listNV, m_Bang_GioKDQD);
                XL.TaoTableGioThieuCheck(listNV, m_Bang_GioThieuCheck);
                XL.TaoTableThK_TreSom(listNV, m_Bang_ThK_TreSom);
            } catch (Exception exception) {
                lg.Error("Xem Cong", exception);
                MessageBox.Show("Mất kết nối đến máy chủ. Vui lòng thử lại sau.", "Lỗi");
                GC.Collect();
                return;
            }
        }
Ejemplo n.º 6
0
        private void btnXuatBB_Click(object sender, EventArgs e)
        {
            if (SqlDataAccessHelper.TestConnection(SqlDataAccessHelper.ConnectionString) == false)
            {
                AutoClosingMessageBox.Show("Mất kết nối với CSDL. Vui lòng thử lại sau.", "Lỗi", 2000);
                return;
            }

            //1. lấy dữ liệu từ form
            #region lấy ngày BD và kết thúc, và update lại Ngày BD = 1 ngày trước 31/08 12:00 AM, ngày KT là 1 ngày sau ngay 1 23:59:59
            dtpNgay.Update();
            DateTime ngayBD = dtpNgay.Value.Date;
            ngayBD = ngayBD.AddDays(-2d);
            DateTime ngayKT = ngayBD.AddDays(4d);
            #endregion

            // lấy dsnv tất cả nv thuộc các phòng ban được chọn
            DataTable table = DAL.LayDSNV(m_listIDPhongBan.ToArray());
            if (table.Rows.Count == 0)
            {
                return;
            }
            m_DSNV.Clear();
            XL.KhoiTaoDSNV(m_DSNV, table);

            //3. lấy dữ liệu chấm công của các nhân viên
            //[CHÚ Ý] ngày bắt đầu và kết thúc đã cộng trừ thêm 1 ngày trước sau ở bở trên
            if (XL.KiemtraDulieuCapnhatTuServer(DateTime.Now) == false)
            {
                AutoClosingMessageBox.Show("Dữ liệu chấm công chưa được cập nhật mới nhất từ các máy chấm công.\nCác thay đổi giờ chấm công có thể làm sai sót giờ chấm công thực tế khi dữ liệu được cập nhật.", "Thông báo", 4000);
            }

            int SoNVDangLamViec = 0, SoNVDaRaVe = 0, SoNVVang = 0;
            //dsnv = XL.XemCong(table, ArrDSMaCC_Checked, ngayBD, ngayKT);
            XL.DiemDanh(m_DSNV, ngayBD, ngayKT);
            m_CTDiemDanh.Rows.Clear();
            XL.TaoTableDiemDanh(m_DSNV, m_CTDiemDanh, out SoNVDangLamViec, out SoNVDaRaVe, out SoNVVang);

            saveFileDlgDiemDanh.Filter = "Excel File|*.xlsx";
            saveFileDlgDiemDanh.ShowDialog();
            if (saveFileDlgDiemDanh.FileName == String.Empty)
            {
                return;
            }
            var saveFileName = saveFileDlgDiemDanh.FileName;

            using (var p = new ExcelPackage()) {
                #region Ghi file , nếu xảy ra lỗi thì báo
                XuatBBDSNVDLV(p);
                XuatBBDSNVVang(p);
                Byte[] bin = p.GetAsByteArray();
                try {
                    File.WriteAllBytes(saveFileName, bin);                    //(file_path, bin);
                    AutoClosingMessageBox.Show("Xuất báo biểu thành công.", "Thông báo", 2000);
                } catch (Exception exception) {
                    lg.Error("XuatBBDiemDanh", exception);
                    if (exception is UnauthorizedAccessException)
                    {
                        MessageBox.Show("Bạn chưa được cấp quyền ghi file vào folder.", "Lỗi");
                    }
                    else if (exception is DirectoryNotFoundException)
                    {
                        MessageBox.Show("Không tìm thấy folder lưu trữ.", "Lỗi");
                    }
                    else if (exception is IOException)
                    {
                        MessageBox.Show("File đang mở bởi ứng dụng khác.", "Lỗi");
                    }
                    else
                    {
                        MessageBox.Show("Không thể ghi được file báo biểu.", "Lỗi");
                    }
                }

                #endregion
            }
        }