Exemple #1
0
        private void btnHoanTat_Click_1(object sender, EventArgs e)
        {
            var result = MessageBox.Show("Bạn có muốn lưu sự thay đổi xuống cơ sở dữ liệu hay không?", "Lưu thông tin", MessageBoxButtons.YesNo);

            if (result == DialogResult.Yes)
            {
                KiemKho_View kiemkhoNew = new KiemKho_View();
                kiemkhoNew.MaKiemKho = txtMaPhieu.Text;
                kiemkhoNew.NgayKiem  = dateNgayBan.Value;
                kiemkhoNew.NhanVien  = Context.getInstance().nv.MaNhanVien;
                kiemkhoNew.TrangThai = 1;

                foreach (var item in ct_kiemkhos)
                {
                    item.MaKiemKho = kiemkhoNew.MaKiemKho;
                    if (item.TonSoSach == 0)
                    {
                        item.TonSoSach = item.SoLuong;
                    }
                    item.ChenhLech = item.SoLuong - item.TonSoSach;
                    dt.Inserts.Add(item.toCT_KiemKho());
                }

                if (KiemKho_DAL.add_KiemKho(kiemkhoNew, dt))
                {
                    MessageBox.Show("Lưu thông tin thành công!");
                }
                else
                {
                    MessageBox.Show("Đã có lỗi xảy ra, vui lòng kiểm tra dữ liệu!");
                }
            }
        }
Exemple #2
0
        public static bool add_KiemKho(KiemKho_View hd, DataUpdate <CT_KIEMKHO> list_Change)
        {
            using (var transaction = Context.getInstance().db.Database.BeginTransaction())
            {
                try
                {
                    hd.TrangThai = 1;
                    Context.getInstance().db.Entry(hd.toKiemKho()).State = System.Data.Entity.EntityState.Added;
                    list_Change.Inserts.ForEach(x =>
                    {
                        Context.getInstance().db.Entry(x).State = System.Data.Entity.EntityState.Added;
                    });

                    Context.getInstance().db.SaveChanges();
                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    //Context.getInstance().db.KHOes.Local.Clear();
                    //Context.getInstance().db.CT_HOADON.Local.Clear();
                    //Context.getInstance().db.KHACHHANGs.Local.Clear();
                    //Context.getInstance().db.NHANVIENs.Local.Clear();
                    Context.Refresh();
                    Console.WriteLine("ERROR--------------------------------------" + ex.Message);
                    return(false);
                }
            }
            return(true);
        }
Exemple #3
0
        private void InnitVal()
        {
            this.list_NCC    = new List <ThuongHieu_View>();
            this.kiemkho     = new KiemKho_View();
            this.ct_kiemkhos = new List <CT_KiemKho_View>();
            this.dt          = new DataUpdate <CT_KIEMKHO>();
            txtNhanVien.Text = Context.getInstance().nv.TenNhanVien;
            txtMaPhieu.Text  = KiemKho_DAL.getMaxKiemKho(1);

            setCbxThuongHieu("");
            UpdateGridView();
        }