public FmThongTinNhapHang(NhapHang nh = null, NhapHangController nhctr = null)
 {
     InitializeComponent();
     if (nhctr == null) NHCtr = new NhapHangController();
     else NHCtr = nhctr;
     SPCTCtr = new SanPham_ChiTietController(NHCtr._db);
     dtgvChiTietNH.AutoGenerateColumns = false;
     dtgvChiTietSP.AutoGenerateColumns = false;
     if (nh == null)
     {
         this.nh = new NhapHang(NHCtr._db);
         this.Text = "Thêm Mới Đơn Nhập Hàng";
         LoadDTGV_ChiTietSP();
         dtpkNgay.Value = DateTime.Now;
     }
     else
     {
         ViewMode = true;
         this.nh = nh;
         this.nh._set_context(NHCtr._db);
         ThongTinFormNhapHang = this.nh;
         btLuu.Enabled = false;
         btThem.Enabled = false;
         btXoa.Enabled = false;
         gbDSSanPham.Enabled = false;
         LoadDTGV_ChiTietNH();
     }
 }
 public int add(NhapHang obj)
 {
     this._db.ds_nhaphang.Add(obj);
     //commit
     this.save();
     //return ma moi nhat
     return this._db.ds_nhaphang.Max(x => x.id);
 }
        public void reload(NhapHang nh)
        {
            List<ChiTiet_NhapHang> Added = new List<ChiTiet_NhapHang>();
            List<ChiTiet_NhapHang> Deleted = _db
                .ChangeTracker.Entries<ChiTiet_NhapHang>()
                .Where(ctnh => ctnh.Entity.nhaphang == null)
                .Select(ct => ct.Entity).ToList<ChiTiet_NhapHang>();

            foreach (ChiTiet_NhapHang ctnh in Added) nh.ds_chitiet_nhaphang.Remove(ctnh);
            foreach (ChiTiet_NhapHang ctnh in Deleted) _db.Entry<ChiTiet_NhapHang>(ctnh).Reload();
        }
        public Boolean delete(NhapHang obj)
        {
            try
            {
                //get entity
                obj = this.get_by_id(obj.id);
                //remove relation
                foreach (ChiTiet_NhapHang ctnh in obj.ds_chitiet_nhaphang) ctnh.delete();

                //remove
                this._db.ds_nhaphang.Remove(obj);
                //commit
                return this.save();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
                return false;
            }
        }
Esempio n. 5
0
 //method
 public void change(NhapHang nh)
 {
     this.active = nh.active;
     this.ngay = nh.ngay;
     this.tongtien = nh.tongtien;
 }