Esempio n. 1
0
        public static HoaDonNhap_View get_HoaDonNhap_By_MaHD(string maHD)
        {
            var hd = from hoadon in Context.getInstance().db.HOADON_NHAPHANG
                     where hoadon.MaHoaDon == maHD
                     select new HoaDonNhap_View
            {
                MaHoaDon       = hoadon.MaHoaDon,
                NgayLap        = hoadon.NgayLap,
                NhanVien       = hoadon.NHANVIEN1.TenNhanVien,
                MaNhanVien     = hoadon.MaNguoiLap,
                TongTien       = hoadon.TongTien,
                TrangThai      = hoadon.TrangThai,
                NhaCungCap     = hoadon.NHACUNGCAP.TenNhaCungCap,
                MaNhaCungCap   = hoadon.MaNhaCungCap,
                SoDienThoai    = hoadon.NHACUNGCAP.SoDienThoai,
                MaNhanVienSua  = hoadon.MaNguoiSua,
                TenNhanVienSua = hoadon.NHANVIEN.TenNhanVien,
                NgaySua        = (DateTime)hoadon.NgaySua,
                GhiChu         = hoadon.GhiChu
            };
            HoaDonNhap_View hdV = hd.ToList()[0];

            hdV.ChiTietHoaDon = CT_HoaDonNhap_DAL.get_CTHoaDonNhap_By_MaHD_TT01(hdV.MaHoaDon);
            hdV.InitOldData();
            if (hdV.TrangThai == 0)
            {
                hdV.Mode = TT.DELETE;
            }
            return(hdV);
        }
Esempio n. 2
0
        private void f_Clear()
        {
            hoadonnhap = new HoaDonNhap_View();
            ls_cthd    = new List <CT_HoaDonNhap_View>();

            txtMaPhieu.Text         = HoaDonNhap_DAL.get_HoaDonNhapMax();
            dateNgayBan.Value       = DateTime.Now;
            cbxTenNCC.SelectedIndex = 0;
            txtTongTien.Text        = "0";
            gridControl1.DataSource = ls_cthd;
            gridControl1.RefreshDataSource();
        }
Esempio n. 3
0
        public static bool add_HoaDonNhap(HoaDonNhap_View hd, List <CT_HoaDonNhap_View> ct_hds)
        {
            using (var transaction = Context.getInstance().db.Database.BeginTransaction())
            {
                try
                {
                    decimal phanTramLoiNhuanBanLe   = decimal.Parse(HeThong_DAL.getHeThongByMa("HT002").GiaTri);
                    decimal phanTramLoiNhuanBanBuon = decimal.Parse(HeThong_DAL.getHeThongByMa("HT003").GiaTri);

                    Context.getInstance().db.Entry(hd.toHoaDonNhap()).State = System.Data.Entity.EntityState.Added;
                    Context.getInstance().db.SaveChanges();
                    LINHKIEN lk;
                    ct_hds.ForEach(x =>
                    {
                        foreach (var seri in x.SoSeri)
                        {
                            Context.getInstance().db.Entry(x.toCT_HoaDonNhap(seri)).State = System.Data.Entity.EntityState.Added;
                            //nhap kho
                            KHO myK        = new KHO();
                            myK.MaLinhKien = x.MaLinhKien;
                            myK.Seri       = seri;
                            myK.NgayNhap   = hd.NgayLap;
                            myK.TrangThai  = 1;
                            Context.getInstance().db.Entry(myK).State = System.Data.Entity.EntityState.Added;
                        }
                        lk = Context.getInstance().db.LINHKIENs.Where(key => key.MaLinhKien == x.MaLinhKien).FirstOrDefault();
                        if (lk.GiaNhap != x.GiaNhap)
                        {
                            lk.GiaNhap  = x.GiaNhap;
                            lk.GiaBanLe = x.GiaNhap + (x.GiaNhap * phanTramLoiNhuanBanLe / 100);
                            lk.GiaBanSi = x.GiaNhap + (x.GiaNhap * phanTramLoiNhuanBanBuon / 100);
                            Context.getInstance().db.Entry(lk).State = System.Data.Entity.EntityState.Modified;
                        }
                    });
                    //update so tien nhap hang cua nha cc
                    NHACUNGCAP ncc = Context.getInstance().db.NHACUNGCAPs.Where(key => key.MaNhaCungCap == hd.MaNhaCungCap).FirstOrDefault();
                    ncc.Tong += hd.TongTien;
                    Context.getInstance().db.Entry(ncc).State = System.Data.Entity.EntityState.Modified;

                    Context.getInstance().db.SaveChanges();
                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    Context.Refresh();
                    Console.WriteLine("ERROR--------------------------------------" + ex.Message);
                    return(false);
                }
            }
            return(true);
        }
Esempio n. 4
0
        public static bool del_HoaDon(HoaDonNhap_View hd, DataUpdate <CT_HOADON_NHAPHANG> list_Change)
        {
            using (var transaction = Context.getInstance().db.Database.BeginTransaction())
            {
                try
                {
                    hd.TrangThai = 0;
                    Context.getInstance().db.Entry(hd.toHoaDonNhap()).State = System.Data.Entity.EntityState.Modified;

                    //list_Change.Inserts.ForEach(x =>
                    //{
                    //});

                    //list_Change.Updates.ForEach(x =>
                    //{
                    //    x.TinhTrang = 1;
                    //    Context.getInstance().db.Entry(getCTHD(x)).State = System.Data.Entity.EntityState.Modified;
                    //});

                    list_Change.Deletes.ForEach(x =>
                    {
                        //set trang thai = 0 o day
                        x.TinhTrang = 0;
                        Context.getInstance().db.Entry(getCTHD(x)).State = System.Data.Entity.EntityState.Modified;

                        //them trong kho
                        KHO kho       = Context.getInstance().db.KHOes.Where(key => key.MaLinhKien == x.MaLinhKien).Where(k => k.Seri == x.Seri).FirstOrDefault();
                        kho.TrangThai = 0;
                        Context.getInstance().db.Entry(kho).State = System.Data.Entity.EntityState.Modified;
                    });

                    //update so tien nhap hang cua nha cung cap
                    NHACUNGCAP kh = Context.getInstance().db.NHACUNGCAPs.Where(key => key.MaNhaCungCap == hd.MaNhaCungCap).FirstOrDefault();
                    kh.Tong -= hd.TongTien;
                    Context.getInstance().db.Entry(kh).State = System.Data.Entity.EntityState.Modified;

                    Context.getInstance().db.SaveChanges();
                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    Context.Refresh();
                    Console.WriteLine("ERROR--------------------------------------" + ex.Message);
                    return(false);
                }
            }
            return(true);
        }
Esempio n. 5
0
        private void InnitVal(string maHD)
        {
            ls_cthd = new List <CT_HoaDonNhap_View>();

            if (maHD.Equals(""))
            {
                isNew                 = true;
                hoadonnhap            = new HoaDonNhap_View();
                hoadonnhap.NhanVien   = Context.getInstance().nv.TenNhanVien;
                hoadonnhap.MaNhanVien = Context.getInstance().nv.MaNhanVien;
                hoadonnhap.MaHoaDon   = HoaDonNhap_DAL.get_HoaDonNhapMax();
                hoadonnhap.NgayLap    = DateTime.Now;
                hoadonnhap.GhiChu     = "";
            }
            else
            {
                isNew      = false;
                hoadonnhap = HoaDonNhap_DAL.get_HoaDonNhap_By_MaHD(maHD);
            }
            setDataLoad();
        }
Esempio n. 6
0
        private void btn_Update_Click(object sender, EventArgs e)
        {
            HoaDonNhap_View hd = gridView1.GetFocusedRow() as HoaDonNhap_View;

            if (hd != null)
            {
                if (hd.Mode != TT.DELETE)
                {
                    var result = MessageBox.Show("Bạn có muốn xóa hóa đơn nhập hàng " + hd.MaHoaDon + "?", "Lưu thông tin", MessageBoxButtons.YesNo);
                    if (result == DialogResult.Yes)
                    {
                        HoaDonNhap_View hdn = HoaDonNhap_DAL.get_HoaDonNhap_By_MaHD(hd.MaHoaDon);
                        if (hdn.TrangThai == 2)
                        {
                            MessageBox.Show("Không thể xóa hóa đơn nhập hàng " + hd.MaHoaDon + " vì linh kiện đã được bán");
                            return;
                        }
                        DataUpdate <CT_HOADON_NHAPHANG> dt = new DataUpdate <CT_HOADON_NHAPHANG>();
                        foreach (var item in hd.ChiTietHoaDon)
                        {
                            dt.Deletes.AddRange(item.toList_CT_HoaDonNhap());
                        }
                        hd.MaNhanVienSua = Context.getInstance().nv.MaNhanVien;
                        hd.NgaySua       = DateTime.Now;
                        if (HoaDonNhap_DAL.del_HoaDon(hd, dt))
                        {
                            MessageBox.Show("Lưu thông tin thành công!");
                            gridThaoTac.Delete();
                            gridControl1.RefreshDataSource();
                        }
                        else
                        {
                            MessageBox.Show("Đã có lỗi xảy ra, vui lòng kiểm tra dữ liệu!");
                        }
                    }
                }
            }
        }