Exemplo n.º 1
0
        private void btnXoa_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (XtraMessageBox.Show("Bạn có muốn xóa không?", "THÔNG BÁO", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
            {
                return;
            }
            for (int i = 0; i < gridView1.SelectedRowsCount; i++)
            {
                if (Convert.ToInt32(gridView1.GetSelectedRows()[i]) > 0)
                {
                    string _id = gridView1.GetRowCellValue(gridView1.GetSelectedRows()[i], colOid).ToString();

                    ChiTietXepCa br = XpoDefault.Session.FindObject <ChiTietXepCa> (CriteriaOperator.Parse("Oid = ?", _id));
                    if (br != null)
                    {
                        br.Delete();
                        XpoDefault.Session.CommitTransaction();
                        XpoDefault.Session.PurgeDeletedObjects();
                    }
                }
            }
            RefreshData();
        }
Exemplo n.º 2
0
        private void btnImport_Click(object sender, EventArgs e)
        {
            Cursor = Cursors.WaitCursor;
            if (dtThangImport.EditValue == null)
            {
                XtraMessageBox.Show("Bạn chưa chọn tháng.", "Thông Báo");
                return;
            }
            int count = 0;

            string   _MaNhanVien = dt.Rows[0]["Mã NV"].ToString();
            ChamCong c           = new ChamCong();

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (dt.Rows[i]["Checked"] == System.DBNull.Value || Convert.ToBoolean(dt.Rows[i]["Checked"]) == false)
                {
                    continue;
                }
                if (dt.Rows[i]["NhanVien"] == System.DBNull.Value)
                {
                    continue;
                }
                //Lưu thông tin xếp ca
                #region "Xếp Ca"
                ChiTietXepCa ct = new ChiTietXepCa()
                {
                    Ngay     = DateTime.Parse(dt.Rows[i]["Ngày"].ToString()),
                    NhanVien = dt.Rows[i]["NhanVien"] as Employee,
                    Ca       = dt.Rows[i]["Ca"] as DanhMucCa,
                    GhiChu   = "",
                    Key      = dtThangImport.DateTime.Month.ToString() + "-" + dtThangImport.DateTime.Year.ToString()
                };
                if (dt.Rows[i]["Vào 1"] != System.DBNull.Value)
                {
                    DateTime conv = DateTime.Parse(dt.Rows[i]["Vào 1"].ToString());
                    ct.GhiChu += conv.ToShortTimeString();
                }
                if (dt.Rows[i]["Ra 1"] != System.DBNull.Value)
                {
                    DateTime conv = DateTime.Parse(dt.Rows[i]["Ra 1"].ToString());
                    ct.GhiChu += "|" + conv.ToShortTimeString();
                }
                if (dt.Rows[i]["Vào 2"] != System.DBNull.Value)
                {
                    DateTime conv = DateTime.Parse(dt.Rows[i]["Vào 2"].ToString());
                    ct.GhiChu += "|" + conv.ToShortTimeString();
                }
                if (dt.Rows[i]["Ra 2"] != System.DBNull.Value)
                {
                    DateTime conv = DateTime.Parse(dt.Rows[i]["Ra 2"].ToString());
                    ct.GhiChu += "|" + conv.ToShortTimeString();
                }
                if (dt.Rows[i]["Vào 3"] != System.DBNull.Value)
                {
                    DateTime conv = DateTime.Parse(dt.Rows[i]["Vào 3"].ToString());
                    ct.GhiChu += "|" + conv.ToShortTimeString();
                }
                if (dt.Rows[i]["Ra 3"] != System.DBNull.Value)
                {
                    DateTime conv = DateTime.Parse(dt.Rows[i]["Ra 3"].ToString());
                    ct.GhiChu += "|" + conv.ToShortTimeString() + "\r\n";
                }

                XPCollection xpcCTCa = new XPCollection(xpcChiTietCa, CriteriaOperator.And(new BinaryOperator("Ngay", ct.Ngay),
                                                                                           new BinaryOperator("NhanVien", ct.NhanVien)));
                if (xpcCTCa.Count > 0)
                {
                    ChiTietXepCa ct1 = xpcCTCa[0] as ChiTietXepCa;
                    ct1.Ca     = ct.Ca;
                    ct1.GhiChu = ct.GhiChu;
                }
                else
                {
                    xpcChiTietCa.Add(ct);
                }
                #endregion

                //Lưu Thông tin chấm công
                #region "Chấm Công"

                #region Giờ Vào
                c = new ChamCong()
                {
                    Thang           = dtThangImport.DateTime,
                    NhanVien        = dt.Rows[i]["NhanVien"] as Employee,
                    FirstDate       = dtNgayDauThang.DateTime,
                    LastDate        = dtNgayCuoiThang.DateTime,
                    TenBangChamCong = dtThangImport.DateTime.Month.ToString() + "-" + dtThangImport.DateTime.Year.ToString()
                };

                DateTime     d  = DateTime.Parse(dt.Rows[i]["Ngày"].ToString());
                TimeSpan     ts = d - c.FirstDate;
                XPCollection xpcLoaiDLChamCong = new XPCollection(xpcLoaiDuLieuChamCong, new BinaryOperator("LoaiChamCong", "Giờ Vào"));
                if (xpcLoaiDLChamCong.Count > 0)
                {
                    c.LoaiDuLieuChamCong = xpcLoaiDLChamCong[0] as LoaiDuLieuChamCong;
                    XPCollection xpcCC = new XPCollection(xpcChamCong, CriteriaOperator.And(new BinaryOperator("NhanVien", c.NhanVien),
                                                                                            new BinaryOperator("Thang", c.Thang), new BinaryOperator("LoaiDuLieuChamCong", c.LoaiDuLieuChamCong)));
                    if (xpcCC.Count > 0)
                    {
                        ChamCong c1 = xpcCC[0] as ChamCong;
                        c1[ts.Days + 1] = dt.Rows[i]["GioVao"].ToString();
                    }
                    else
                    {
                        c[ts.Days + 1] = dt.Rows[i]["GioVao"].ToString();
                        xpcChamCong.Add(c);
                    }
                }
                #endregion

                #region Giờ Ra
                c = new ChamCong()
                {
                    Thang           = dtThangImport.DateTime,
                    NhanVien        = dt.Rows[i]["NhanVien"] as Employee,
                    FirstDate       = dtNgayDauThang.DateTime,
                    LastDate        = dtNgayCuoiThang.DateTime,
                    TenBangChamCong = dtThangImport.DateTime.Month.ToString() + "-" + dtThangImport.DateTime.Year.ToString()
                };
                xpcLoaiDLChamCong = new XPCollection(xpcLoaiDuLieuChamCong, new BinaryOperator("LoaiChamCong", "Giờ Ra"));
                if (xpcLoaiDLChamCong.Count > 0)
                {
                    c.LoaiDuLieuChamCong = xpcLoaiDLChamCong[0] as LoaiDuLieuChamCong;
                    XPCollection xpcCC = new XPCollection(xpcChamCong, CriteriaOperator.And(new BinaryOperator("NhanVien", c.NhanVien),
                                                                                            new BinaryOperator("Thang", c.Thang), new BinaryOperator("LoaiDuLieuChamCong", c.LoaiDuLieuChamCong)));
                    if (xpcCC.Count > 0)
                    {
                        ChamCong c1 = xpcCC[0] as ChamCong;
                        c1[ts.Days + 1] = dt.Rows[i]["GioRa"].ToString();
                    }
                    else
                    {
                        c[ts.Days + 1] = dt.Rows[i]["GioRa"].ToString();
                        xpcChamCong.Add(c);
                    }
                }
                #endregion

                #region Tổng Thời Gian Làm
                c = new ChamCong()
                {
                    Thang           = dtThangImport.DateTime,
                    NhanVien        = dt.Rows[i]["NhanVien"] as Employee,
                    FirstDate       = dtNgayDauThang.DateTime,
                    LastDate        = dtNgayCuoiThang.DateTime,
                    TenBangChamCong = dtThangImport.DateTime.Month.ToString() + "-" + dtThangImport.DateTime.Year.ToString()
                };
                xpcLoaiDLChamCong = new XPCollection(xpcLoaiDuLieuChamCong, new BinaryOperator("LoaiChamCong", "Tổng Thời Gian Làm"));
                if (xpcLoaiDLChamCong.Count > 0)
                {
                    c.LoaiDuLieuChamCong = xpcLoaiDLChamCong[0] as LoaiDuLieuChamCong;
                    XPCollection xpcCC = new XPCollection(xpcChamCong, CriteriaOperator.And(new BinaryOperator("NhanVien", c.NhanVien),
                                                                                            new BinaryOperator("Thang", c.Thang), new BinaryOperator("LoaiDuLieuChamCong", c.LoaiDuLieuChamCong)));
                    if (xpcCC.Count > 0)
                    {
                        ChamCong c1 = xpcCC[0] as ChamCong;
                        c1[ts.Days + 1] = dt.Rows[i]["Tổng Thời Gian Làm"].ToString();
                    }
                    else
                    {
                        c[ts.Days + 1] = dt.Rows[i]["Tổng Thời Gian Làm"].ToString();
                        xpcChamCong.Add(c);
                    }
                }
                #endregion

                //Tăng Ca
                //5 Loại Tăng Ca: Tăng Ca NT,Tăng Ca NT Ca Đêm, Tăng Ca NN, Tăng Ca NN Ca Đêm, Tăng Ca Ngày Lễ
                #region Tăng Ca NT
                c = new ChamCong()
                {
                    Thang           = dtThangImport.DateTime,
                    NhanVien        = dt.Rows[i]["NhanVien"] as Employee,
                    FirstDate       = dtNgayDauThang.DateTime,
                    LastDate        = dtNgayCuoiThang.DateTime,
                    TenBangChamCong = dtThangImport.DateTime.Month.ToString() + "-" + dtThangImport.DateTime.Year.ToString()
                };
                xpcLoaiDLChamCong = new XPCollection(xpcLoaiDuLieuChamCong, new BinaryOperator("LoaiChamCong", "Tăng Ca NT"));
                if (xpcLoaiDLChamCong.Count > 0)
                {
                    c.LoaiDuLieuChamCong = xpcLoaiDLChamCong[0] as LoaiDuLieuChamCong;
                    XPCollection xpcCC = new XPCollection(xpcChamCong, CriteriaOperator.And(new BinaryOperator("NhanVien", c.NhanVien),
                                                                                            new BinaryOperator("Thang", c.Thang), new BinaryOperator("LoaiDuLieuChamCong", c.LoaiDuLieuChamCong)));
                    if (xpcCC.Count > 0)
                    {
                        ChamCong c1 = xpcCC[0] as ChamCong;
                        c1[ts.Days + 1] = dt.Rows[i]["Tăng Ca NT"].ToString();
                    }
                    else
                    {
                        c[ts.Days + 1] = dt.Rows[i]["Tăng Ca NT"].ToString();
                        xpcChamCong.Add(c);
                    }
                }
                #endregion

                #region Tăng Ca NT Ca Đêm
                c = new ChamCong()
                {
                    Thang           = dtThangImport.DateTime,
                    NhanVien        = dt.Rows[i]["NhanVien"] as Employee,
                    FirstDate       = dtNgayDauThang.DateTime,
                    LastDate        = dtNgayCuoiThang.DateTime,
                    TenBangChamCong = dtThangImport.DateTime.Month.ToString() + "-" + dtThangImport.DateTime.Year.ToString()
                };
                xpcLoaiDLChamCong = new XPCollection(xpcLoaiDuLieuChamCong, new BinaryOperator("LoaiChamCong", "Tăng Ca NT Ca Đêm"));
                if (xpcLoaiDLChamCong.Count > 0)
                {
                    c.LoaiDuLieuChamCong = xpcLoaiDLChamCong[0] as LoaiDuLieuChamCong;
                    XPCollection xpcCC = new XPCollection(xpcChamCong, CriteriaOperator.And(new BinaryOperator("NhanVien", c.NhanVien),
                                                                                            new BinaryOperator("Thang", c.Thang), new BinaryOperator("LoaiDuLieuChamCong", c.LoaiDuLieuChamCong)));
                    if (xpcCC.Count > 0)
                    {
                        ChamCong c1 = xpcCC[0] as ChamCong;
                        c1[ts.Days + 1] = dt.Rows[i]["Tăng Ca NT Ca Đêm"].ToString();
                    }
                    else
                    {
                        c[ts.Days + 1] = dt.Rows[i]["Tăng Ca NT Ca Đêm"].ToString();
                        xpcChamCong.Add(c);
                    }
                }
                #endregion

                #region Tăng Ca NN
                c = new ChamCong()
                {
                    Thang           = dtThangImport.DateTime,
                    NhanVien        = dt.Rows[i]["NhanVien"] as Employee,
                    FirstDate       = dtNgayDauThang.DateTime,
                    LastDate        = dtNgayCuoiThang.DateTime,
                    TenBangChamCong = dtThangImport.DateTime.Month.ToString() + "-" + dtThangImport.DateTime.Year.ToString()
                };
                xpcLoaiDLChamCong = new XPCollection(xpcLoaiDuLieuChamCong, new BinaryOperator("LoaiChamCong", "Tăng Ca NN"));
                if (xpcLoaiDLChamCong.Count > 0)
                {
                    c.LoaiDuLieuChamCong = xpcLoaiDLChamCong[0] as LoaiDuLieuChamCong;
                    XPCollection xpcCC = new XPCollection(xpcChamCong, CriteriaOperator.And(new BinaryOperator("NhanVien", c.NhanVien),
                                                                                            new BinaryOperator("Thang", c.Thang), new BinaryOperator("LoaiDuLieuChamCong", c.LoaiDuLieuChamCong)));
                    if (xpcCC.Count > 0)
                    {
                        ChamCong c1 = xpcCC[0] as ChamCong;
                        c1[ts.Days + 1] = dt.Rows[i]["Tăng Ca NN"].ToString();
                    }
                    else
                    {
                        c[ts.Days + 1] = dt.Rows[i]["Tăng Ca NN"].ToString();
                        xpcChamCong.Add(c);
                    }
                }
                #endregion

                #region Tăng Ca NN Ca Đêm
                c = new ChamCong()
                {
                    Thang           = dtThangImport.DateTime,
                    NhanVien        = dt.Rows[i]["NhanVien"] as Employee,
                    FirstDate       = dtNgayDauThang.DateTime,
                    LastDate        = dtNgayCuoiThang.DateTime,
                    TenBangChamCong = dtThangImport.DateTime.Month.ToString() + "-" + dtThangImport.DateTime.Year.ToString()
                };
                xpcLoaiDLChamCong = new XPCollection(xpcLoaiDuLieuChamCong, new BinaryOperator("LoaiChamCong", "Tăng Ca NN Ca Đêm"));
                if (xpcLoaiDLChamCong.Count > 0)
                {
                    c.LoaiDuLieuChamCong = xpcLoaiDLChamCong[0] as LoaiDuLieuChamCong;
                    XPCollection xpcCC = new XPCollection(xpcChamCong, CriteriaOperator.And(new BinaryOperator("NhanVien", c.NhanVien),
                                                                                            new BinaryOperator("Thang", c.Thang), new BinaryOperator("LoaiDuLieuChamCong", c.LoaiDuLieuChamCong)));
                    if (xpcCC.Count > 0)
                    {
                        ChamCong c1 = xpcCC[0] as ChamCong;
                        c1[ts.Days + 1] = dt.Rows[i]["Tăng Ca NN Ca Đêm"].ToString();
                    }
                    else
                    {
                        c[ts.Days + 1] = dt.Rows[i]["Tăng Ca NN Ca Đêm"].ToString();
                        xpcChamCong.Add(c);
                    }
                }
                #endregion

                #region Tăng Ca Ngày Lễ
                c = new ChamCong()
                {
                    Thang           = dtThangImport.DateTime,
                    NhanVien        = dt.Rows[i]["NhanVien"] as Employee,
                    FirstDate       = dtNgayDauThang.DateTime,
                    LastDate        = dtNgayCuoiThang.DateTime,
                    TenBangChamCong = dtThangImport.DateTime.Month.ToString() + "-" + dtThangImport.DateTime.Year.ToString()
                };
                xpcLoaiDLChamCong = new XPCollection(xpcLoaiDuLieuChamCong, new BinaryOperator("LoaiChamCong", "Tăng Ca NL"));
                if (xpcLoaiDLChamCong.Count > 0)
                {
                    c.LoaiDuLieuChamCong = xpcLoaiDLChamCong[0] as LoaiDuLieuChamCong;
                    XPCollection xpcCC = new XPCollection(xpcChamCong, CriteriaOperator.And(new BinaryOperator("NhanVien", c.NhanVien),
                                                                                            new BinaryOperator("Thang", c.Thang), new BinaryOperator("LoaiDuLieuChamCong", c.LoaiDuLieuChamCong)));
                    if (xpcCC.Count > 0)
                    {
                        ChamCong c1 = xpcCC[0] as ChamCong;
                        c1[ts.Days + 1] = dt.Rows[i]["Tăng Ca NL"].ToString();
                    }
                    else
                    {
                        c[ts.Days + 1] = dt.Rows[i]["Tăng Ca NL"].ToString();
                        xpcChamCong.Add(c);
                    }
                }
                #endregion

                #region Số Ngày Công
                // Số Ngày Công
                c = new ChamCong()
                {
                    Thang           = dtThangImport.DateTime,
                    NhanVien        = dt.Rows[i]["NhanVien"] as Employee,
                    FirstDate       = dtNgayDauThang.DateTime,
                    LastDate        = dtNgayCuoiThang.DateTime,
                    TenBangChamCong = dtThangImport.DateTime.Month.ToString() + "-" + dtThangImport.DateTime.Year.ToString()
                };
                xpcLoaiDLChamCong = new XPCollection(xpcLoaiDuLieuChamCong, new BinaryOperator("LoaiChamCong", "Số Ngày Công"));
                if (xpcLoaiDLChamCong.Count > 0)
                {
                    c.LoaiDuLieuChamCong = xpcLoaiDLChamCong[0] as LoaiDuLieuChamCong;
                    XPCollection xpcCC = new XPCollection(xpcChamCong, CriteriaOperator.And(new BinaryOperator("NhanVien", c.NhanVien),
                                                                                            new BinaryOperator("Thang", c.Thang), new BinaryOperator("LoaiDuLieuChamCong", c.LoaiDuLieuChamCong)));
                    if (xpcCC.Count > 0)
                    {
                        ChamCong c1 = xpcCC[0] as ChamCong;
                        c1[ts.Days + 1] = dt.Rows[i]["Số Ngày Công"].ToString();
                    }
                    else
                    {
                        c[ts.Days + 1] = dt.Rows[i]["Số Ngày Công"].ToString();
                        xpcChamCong.Add(c);
                    }
                }
                #endregion

                #region Số Ngày Công Thực Tế
                // Số Ngày Công
                c = new ChamCong()
                {
                    Thang           = dtThangImport.DateTime,
                    NhanVien        = dt.Rows[i]["NhanVien"] as Employee,
                    FirstDate       = dtNgayDauThang.DateTime,
                    LastDate        = dtNgayCuoiThang.DateTime,
                    TenBangChamCong = dtThangImport.DateTime.Month.ToString() + "-" + dtThangImport.DateTime.Year.ToString()
                };
                xpcLoaiDLChamCong = new XPCollection(xpcLoaiDuLieuChamCong, new BinaryOperator("LoaiChamCong", "Số Ngày Công Thực Tế"));
                if (xpcLoaiDLChamCong.Count > 0)
                {
                    c.LoaiDuLieuChamCong = xpcLoaiDLChamCong[0] as LoaiDuLieuChamCong;
                    XPCollection xpcCC = new XPCollection(xpcChamCong, CriteriaOperator.And(new BinaryOperator("NhanVien", c.NhanVien),
                                                                                            new BinaryOperator("Thang", c.Thang), new BinaryOperator("LoaiDuLieuChamCong", c.LoaiDuLieuChamCong)));
                    if (xpcCC.Count > 0)
                    {
                        ChamCong c1 = xpcCC[0] as ChamCong;
                        c1[ts.Days + 1] = dt.Rows[i]["Số Ngày Công Thực Tế"].ToString();
                    }
                    else
                    {
                        c[ts.Days + 1] = dt.Rows[i]["Số Ngày Công Thực Tế"].ToString();
                        xpcChamCong.Add(c);
                    }
                }
                #endregion

                #endregion

                count++;
            }
            XpoDefault.Session.Save(xpcChamCong);
            XpoDefault.Session.Save(xpcChiTietCa);
            Cursor = Cursors.Default;


            XtraMessageBox.Show(String.Format("Lưu thành công {0} dòng.", count), "Thông Báo");
        }