コード例 #1
0
 private void ThemPN_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("Bạn có muốn thêm 1 phiếu nhập mới không?", "Thông báo", MessageBoxButtons.YesNo)
         == System.Windows.Forms.DialogResult.Yes)
     {
         try
         {
             PhieuNhap newPN = new PhieuNhap()
             {
                 maPN     = txtMaPN.Text,
                 ngayNhap = dtNgayViet.Value,
                 tongTien = 0
             };
             db.PhieuNhaps.Add(newPN);
             db.SaveChanges();
             FormPhieuNhap_Load(sender, e);
             MessageBox.Show("Thêm thành công!");
             FormChiTietPhieuNhap.MaPN = txtMaPN.Text;
             if (MessageBox.Show("Bạn có muốn thêm 1 phiếu nhập mới không?", "Thông báo", MessageBoxButtons.YesNo)
                 == System.Windows.Forms.DialogResult.Yes)
             {
                 FormChiTietPhieuNhap ctpn = new FormChiTietPhieuNhap();
                 this.Hide();
                 ctpn.ShowDialog();
                 this.Show();
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
     }
 }
コード例 #2
0
 private void SuaPN_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("Bạn có muốn sửa phiếu nhập vừa chọn không?", "Thông báo", MessageBoxButtons.YesNo)
         == System.Windows.Forms.DialogResult.Yes)
     {
         try
         {
             if (MaPN == "")
             {
                 MessageBox.Show("Bạn phải chọn phiếu nhập trước!", "Thông báo");
             }
             else
             {
                 PhieuNhap selectedItem = db.PhieuNhaps.SingleOrDefault(x => x.maPN == MaPN);
                 selectedItem.ngayNhap = dtNgayViet.Value;
                 FormChiTietPhieuNhap ctpn = new FormChiTietPhieuNhap();
                 FormChiTietPhieuNhap.MaPN = MaPN;
                 this.Hide();
                 ctpn.ShowDialog();
                 this.Show();
                 db.SaveChanges();
                 FormPhieuNhap_Load(sender, e);
                 MessageBox.Show("Sửa thành công", "Thông báo");
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
     }
     else
     {
         try
         {
             PhieuNhap selectedItem = db.PhieuNhaps.SingleOrDefault(x => x.maPN == MaPN);
             selectedItem.ngayNhap = dtNgayViet.Value;
             db.SaveChanges();
             FormPhieuNhap_Load(sender, e);
             MessageBox.Show("Sửa thành công", "Thông báo");
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
     }
 }