示例#1
0
文件: Congnhan.cs 项目: leson96/Demo
 public List <PhuCap> ViewPhuCap(string sql)
 {
     try
     {
         List <PhuCap> list = new List <PhuCap>();
         SqlDataReader dr   = p.View(sql);
         if (dr != null)
         {
             string MaPhuCap, TenPhuCap;
             int    SoTienPhuCap;
             while (dr.Read())
             {
                 MaPhuCap     = dr.GetString(0);
                 TenPhuCap    = dr.GetString(1);
                 SoTienPhuCap = dr.GetInt32(2);
                 PhuCap pc = new PhuCap(MaPhuCap, TenPhuCap, SoTienPhuCap);
                 list.Add(pc);
             }
         }
         return(list);
     }
     catch (SqlException p)
     {
         throw p;
     }
 }
示例#2
0
        public string Update(PhuCap obj)
        {
            myData.PhuCaps.Update(obj);
            myData.SaveChanges();

            return(null);
        }
示例#3
0
        public string Add(PhuCap obj)
        {
            myData.PhuCaps.Add(obj);
            myData.SaveChanges();

            return(null);
        }
示例#4
0
 public static void TinhCong_HangNgay(cNgayCong ngayCong, TimeSpan startNT, TimeSpan endddNT,
                                      out ThoiGian TG, out PhuCap PhuCaps, out float TongCong, out float TongNgayLV, out bool QuaDem)
 {
     TG         = new ThoiGian();
     PhuCaps    = new PhuCap();
     TongCong   = 0f;
     TongNgayLV = 0f;             //ver4.0.0.1
     QuaDem     = false;
 }
示例#5
0
 public static PhuCapDTO ToDTO(this PhuCap phuCap)
 {
     return(new PhuCapDTO()
     {
         PhuCapId = phuCap.PhuCapId,
         TenPhuCap = phuCap.TenPhuCap,
         TienPhuCap = phuCap.TienPhuCap,
         TrangThai = phuCap.TrangThai
     });
 }
 public int UpdatePhuCap(PhuCap pc)
 {
     try
     {
         return(new Congnhan().UpdatePhuCap(pc));
     }
     catch (Exception p)
     {
         throw p;
     }
 }
        public void ThemPC(PhuCap pc)
        {
            DAL_PhuCap dal_PhuCap = new DAL_PhuCap();

            dal_PhuCap.Open();
            string insertString = "insert into PhuCap(MaPC,TenPC,HeSoPC,Ghichu) values(" + pc.MaPC + ",'" + pc.TenPC + "'," + pc.HeSoPC + ","
                                  + pc.GhiChu + "')";
            SqlCommand cmd = new SqlCommand(insertString, dal_PhuCap.conn);

            cmd.ExecuteNonQuery();
            cmd.Dispose();
            dal_PhuCap.Close();
        }
示例#8
0
        public string Add(PhuCap obj)
        {
            //Kiểm tra khóa chính
            if (myData.PhuCaps.ToList().Find(x => x.PhuCapId == obj.PhuCapId) != null)
            {
                return("Phụ cấp id đã tồn tại");
            }

            myData.PhuCaps.Add(obj);
            myData.SaveChanges();

            return(null);
        }
示例#9
0
文件: Congnhan.cs 项目: leson96/Demo
        public int UpdatePhuCap(PhuCap phucap)
        {
            List <SqlParameter> paras = new List <SqlParameter>();

            paras.Add(new SqlParameter("@maphucap", phucap.MaPhuCap));
            paras.Add(new SqlParameter("@tenphucap", phucap.TenPhuCap));
            paras.Add(new SqlParameter("@sotienphucap", phucap.SoTienPhuCap));
            try
            {
                return(p.ExecNonQuery("updatephucap", CommandType.StoredProcedure, paras));
            }
            catch (SqlException p)
            {
                throw p;
            }
        }
        public void CapNhatPC(PhuCap pc)
        {
            DAL_PhuCap dal_PhuCap = new DAL_PhuCap();

            dal_PhuCap.Open();
            string     updateString = "SUAPB";
            SqlCommand cmd          = new SqlCommand(updateString, dal_PhuCap.conn);

            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@MaPC", SqlDbType.Text).Value    = pc.MaPC;
            cmd.Parameters.Add("@TenPC", SqlDbType.Text).Value   = pc.TenPC;
            cmd.Parameters.Add("@HeSoPC", SqlDbType.Float).Value = pc.HeSoPC;
            cmd.Parameters.Add("@GhiChu", SqlDbType.Text).Value  = pc.GhiChu;
            cmd.ExecuteNonQuery();
            cmd.Dispose();
            dal_PhuCap.Close();
        }
示例#11
0
        private void btThemPC_Click(object sender, EventArgs e)
        {
            if (txtMaPC.Text == "" || txtTenPC.Text == "" || txtTienPC.Text == "")
            {
                MessageBox.Show("Không có dữ liệu để phụ cấp", "Thông báo");
                return;
            }
            PhuCap pc = new PhuCap(txtMaPC.Text, txtTenPC.Text, int.Parse(txtTienPC.Text));

            try
            {
                cnb.AddPhuCap(pc);
            }
            catch (Exception p)
            {
                MessageBox.Show(p.ToString());
            }
        }
示例#12
0
文件: Form1.cs 项目: leson96/Demo
        private void btSuaPC_Click(object sender, EventArgs e)
        {
            if (txtMaPC.Text == "" || txtTenPC.Text == "" || txtTienPC.Text == "")
            {
                MessageBox.Show("Khong co du lieu");
                return;
            }
            PhuCap pc = new PhuCap(txtMaPC.Text, txtTenPC.Text, int.Parse(txtTienPC.Text));

            try
            {
                cnb.UpdatePhuCap(pc);
            }
            catch (Exception p)
            {
                MessageBox.Show(p.ToString());
            }
        }
示例#13
0
        public string Update(PhuCap obj)
        {
            var local = myData.Set <PhuCap>()
                        .Local
                        .FirstOrDefault(entry => entry.PhuCapId.Equals(obj.PhuCapId));

            // check if local is not null
            if (local != null)
            {
                // detach
                myData.Entry(local).State = EntityState.Detached;
            }
            // set Modified flag in your entry
            myData.Entry(obj).State = EntityState.Modified;
            //myData.PhuCaps.Update(obj);
            myData.SaveChanges();

            return(null);
        }
示例#14
0
        public string Remove(PhuCap obj)
        {
            ////Kiểm tra quan hệ
            //NhanVienPhuCap nhanVienPhuCap = myData.NhanVienPhuCaps.ToList().Find(x => x.PhuCapId == obj.PhuCapId);
            //if (nhanVienPhuCap != null)
            //{
            //    return "Nhân viên - phụ cấp \"" + nhanVienPhuCap.NhanVienPhuCapId + "\" đang tham chiếu tới khóa này vui lòng xóa hoặc điều hướng sang khóa khác rồi tiếp tục";
            //}

            //myData.PhuCaps.Remove(obj);

            //Đoạn trên dùng để xóa

            //Lấy phụ cấp dựa vào id
            obj = myData.PhuCaps.Find(obj.PhuCapId);

            //Cập nhật trạng thái
            obj.TrangThai = 0;
            myData.PhuCaps.Update(obj);
            myData.SaveChanges();

            return(null);
        }
        public void AutoAdd()
        {
            //Ngày đầu tiên của tháng mới bắt đầu tính lương
            if (DateTime.Now.IsFirstDayOfMonth() != false)
            {
                return;
            }
            foreach (NhanVienCongViec nhanVienCongViec in myData.NhanVienCongViecs.ToList())
            {
                bool add = true;
                //Không tính lương cho nhân viến quá 2 lần
                foreach (LuongThang lt in myData.LuongThangs.ToList())
                {
                    if (lt.NhanVienId == nhanVienCongViec.NhanVienId &&
                        ((DateTime)lt.NgayTinhLuong).EqualTo(DateTime.Now.FirstDayOfMonth()) == true)
                    {
                        add = false;
                        break;
                    }
                }
                if (add == false)
                {
                    break;
                }

                //Chỉ tính lương cho nhân viên có
                //ngày bắt đầu trước hôm nay và
                //ngày kết thúc băng null hoặc sau ngày đầu tiên của tháng trước
                if (((DateTime)nhanVienCongViec.NgayBatDau).Before(DateTime.Now) &&
                    (nhanVienCongViec.NgayKetThuc == null || ((DateTime)nhanVienCongViec.NgayKetThuc).After(DateTime.Now.FirstDayOfPreviousMonth())))
                {
                    LuongThang luongThang = new LuongThang();

                    //Tao id
                    int max = 0;
                    List <LuongThang> luongThangs = myData.LuongThangs.ToList();
                    foreach (LuongThang lt in luongThangs)
                    {
                        if (int.Parse(lt.LuongThangId) > max)
                        {
                            max = int.Parse(lt.LuongThangId);
                        }
                    }

                    luongThang.LuongThangId = "" + (max + 1);
                    luongThang.NhanVienId   = nhanVienCongViec.NhanVienId;
                    luongThang.LuongCoBan   = myData.HopDongs.ToList().Find(x => x.NhanVienId == luongThang.NhanVienId && x.TrangThai == 1) != null?
                                              myData.HopDongs.ToList().Find(x => x.NhanVienId == luongThang.NhanVienId && x.TrangThai == 1).LuongCanBan : "0";

                    string chucVuId = myData.NhanViens.ToList().Find(x => x.NhanVienId == luongThang.NhanVienId).ChucVuId;
                    luongThang.HSChucVu   = myData.ChucVus.ToList().Find(x => x.ChucVuId == chucVuId).HSChucVu;
                    luongThang.HSCongViec = nhanVienCongViec.HSCongViec;
                    DateTime ngayBatDauLamCuaThangTruoc = ((DateTime)nhanVienCongViec.NgayBatDau).After(DateTime.Now.FirstDayOfPreviousMonth()) ?
                                                          (DateTime)nhanVienCongViec.NgayBatDau : DateTime.Now.FirstDayOfPreviousMonth();
                    DateTime ngayKetThucLamCuaThangTruoc = nhanVienCongViec.NgayKetThuc == null?DateTime.Now.FirstDayOfPreviousMonth().LastDayOfMonth() :
                                                               (DateTime)nhanVienCongViec.NgayKetThuc;

                    luongThang.SoNgayLam           = 0;
                    luongThang.SoNgayNghiCoPhep    = 0;
                    luongThang.SoNgayNghiKhongPhep = 0;
                    luongThang.SoNgayNghiOm        = 0;
                    luongThang.ThuongLe            = "0";

                    foreach (BangChamCong bangChamCong in myData.BangChamCongs.ToList())
                    {
                        //Đếm số ngày làm việc của
                        //nhân viên đang xét và
                        //ngày làm việc phải nằm trong đoạn [ngayBatDauLamCuaThangTruoc, ngayKetThucLamCuaThangTruoc]
                        //nếu có trạng thái là tt1 => soNgayLam
                        //nếu có trạng thái là tt2 => SoNgayNghiCoPhep
                        //nếu có trạng thái là tt3 => SoNgayNghiKhongPhep
                        //nếu có trạng thái là tt4 => SoNgayNghiOm
                        //nếu có ngày làm trùng vs ngày lễ => có tiền thưởng
                        if (luongThang.NhanVienId == bangChamCong.NhanVienId && (
                                bangChamCong.NgayLamViec.EqualTo(ngayBatDauLamCuaThangTruoc) ||
                                (bangChamCong.NgayLamViec.After(ngayBatDauLamCuaThangTruoc) && bangChamCong.NgayLamViec.Before(ngayKetThucLamCuaThangTruoc)) ||
                                bangChamCong.NgayLamViec.EqualTo(ngayKetThucLamCuaThangTruoc)))
                        {
                            //Tính số ngày làm, nghỉ
                            if (bangChamCong.TrangThaiChamCongId == "tt1")
                            {
                                luongThang.SoNgayLam++;
                            }
                            else
                            {
                                if (bangChamCong.TrangThaiChamCongId == "tt2")
                                {
                                    luongThang.SoNgayNghiCoPhep++;
                                }
                                else
                                {
                                    if (bangChamCong.TrangThaiChamCongId == "tt3")
                                    {
                                        luongThang.SoNgayNghiKhongPhep++;
                                    }
                                    else
                                    {
                                        if (bangChamCong.TrangThaiChamCongId == "tt4")
                                        {
                                            luongThang.SoNgayNghiOm++;
                                        }
                                    }
                                }
                            }
                            //Tính tiền thưởng
                            foreach (ThuongLe thuongLe in myData.ThuongLes.ToList())
                            {
                                if (((DateTime)thuongLe.NgayLe).EqualTo(bangChamCong.NgayLamViec))
                                {
                                    luongThang.ThuongLe = "" + (long.Parse(luongThang.ThuongLe) + long.Parse(thuongLe.TienThuongLe));
                                }
                            }
                        }
                    }

                    luongThang.PhuCapNhanVien = "" + 0;
                    foreach (NhanVienPhuCap nhanVienPhuCap in myData.NhanVienPhuCaps.ToList())
                    {
                        if (nhanVienPhuCap.NhanVienId == luongThang.NhanVienId)
                        {
                            PhuCap phuCap = myData.PhuCaps.ToList().Find(x => x.PhuCapId == nhanVienPhuCap.PhuCapId);
                            luongThang.PhuCapNhanVien = "" + (long.Parse(luongThang.PhuCapNhanVien) + long.Parse(phuCap.TienPhuCap));
                        }
                    }

                    luongThang.PhuCapChucVu = myData.ChucVus.ToList().Find(x => x.ChucVuId == myData.NhanViens.ToList()
                                                                           .Find(y => y.NhanVienId == luongThang.NhanVienId).ChucVuId).TienPhuCapChucVu;
                    //Tính hệ số thâm niên
                    DateTime ngayDauTienDiLam = DateTime.Now;
                    foreach (NhanVienCongViec nvcv in myData.NhanVienCongViecs.ToList())
                    {
                        if (luongThang.NhanVienId == nvcv.NhanVienId)
                        {
                            if (ngayDauTienDiLam.After((DateTime)nvcv.NgayBatDau))
                            {
                                ngayDauTienDiLam = (DateTime)nvcv.NgayBatDau;
                            }
                        }
                    }
                    luongThang.PhuCapThamNien = ((int)(DateTime.Now - ngayDauTienDiLam).Days / 365) * 0.1;
                    luongThang.TienDuAn       = "" + 0;
                    foreach (NhanVienDuAn nhanVienDuAn in myData.NhanVienDuAns.ToList())
                    {
                        if (nhanVienDuAn.NhanVienId == luongThang.NhanVienId)
                        {
                            DuAn duAn = myData.DuAns.ToList().Find(x => x.DuAnId == nhanVienDuAn.DuAnId);
                            if (((DateTime)duAn.NgayKetThuc).After(DateTime.Now.FirstDayOfPreviousMonth()) &&
                                ((DateTime)duAn.NgayKetThuc).Before(DateTime.Now.FirstDayOfPreviousMonth().LastDayOfMonth()))
                            {
                                luongThang.TienDuAn = "" + (long.Parse(luongThang.TienDuAn) + (nhanVienDuAn.PhanTramCV * long.Parse(duAn.ThuongDuAn) / 100));
                            }
                        }
                    }
                    luongThang.NgayTinhLuong = DateTime.Now.FirstDayOfMonth();
                    long luongMotNgay = long.Parse(luongThang.LuongCoBan) * (long)(1.0 + (double)luongThang.HSChucVu + (double)luongThang.HSCongViec + (double)luongThang.PhuCapThamNien) / 26;
                    luongThang.LuongThucLanh = "" + ((long)(luongMotNgay * (int)luongThang.SoNgayLam) + long.Parse(luongThang.ThuongLe)
                                                     + long.Parse(luongThang.TienDuAn) + long.Parse(luongThang.PhuCapNhanVien));

                    //Lưu vào database
                    myData.LuongThangs.Add(luongThang);
                    myData.SaveChanges();
                }
            }
        }