public static bool InsertHangNhap(HangNhap hn)
 {
     try
     {
         using (SieuThiDBDataContext db = new SieuThiDBDataContext())
         {
             db.HangNhaps.InsertOnSubmit(hn);
             db.SubmitChanges();
             return(true);
         }
     }
     catch
     {
         return(false);
     }
 }
Exemple #2
0
        private void btnTaoPhieuNhap_Click(object sender, EventArgs e)
        {
            int ktra = 0;

            if (listHHN.Count > 0)
            {
                DonHang dh = new DonHang
                {
                    MaNV   = int.Parse(txtMaNV.Text),
                    NgayDH = DateTime.Parse(txtNgayDat.Text)
                };
                if (DonHangBus.InsertDonHang(dh))
                {
                    foreach (var item in listHHN)
                    {
                        HangNhap hn = new HangNhap
                        {
                            DonGia  = item.DG,
                            MaDH    = dh.MaDH,
                            MaHang  = item.MaHang,
                            SoLuong = item.SL
                        };
                        if (!DonHangBus.InsertHangNhap(hn))
                        {
                            ktra++;
                        }
                    }
                }
                else
                {
                    ktra++;
                }
                if (ktra == 0)
                {
                    MessageBox.Show("Tạo đơn hàng thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            else
            {
                MessageBox.Show("Hãy thêm hàng hóa muốn nhập", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }