private void btXoa_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Bạn có muốn xóa thông tin đã chọn không?", "Thông báo", MessageBoxButtons.YesNo)
                == System.Windows.Forms.DialogResult.Yes)
            {
                try
                {
                    Chitietnhap ctPN = db.Chitietnhaps.SingleOrDefault(x => x.maPN == MaPN && x.maHH == selectedMaHH);

                    pn.tongTien -= ctPN.soLuong * ctPN.thanhTien;

                    HangHoa hh = db.HangHoas.SingleOrDefault(x => x.maHH == ctPN.maHH);
                    hh.soluong += ctPN.soLuong;

                    db.Chitietnhaps.Remove(ctPN);
                    db.SaveChanges();
                    FormChiTietPhieuNhap_Load(sender, e);
                    MessageBox.Show("Xóa thành công!");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
        private void btSua_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Bạn có muốn sửa thông tin đã chọn không?", "Thông báo", MessageBoxButtons.YesNo)
                == System.Windows.Forms.DialogResult.Yes)
            {
                try
                {
                    Chitietnhap ctPN = db.Chitietnhaps.SingleOrDefault(x => x.maPN == MaPN && x.maHH == selectedMaHH);
                    ctPN.HangHoa.soluong -= ctPN.soLuong;
                    pn.tongTien          -= ctPN.soLuong * ctPN.thanhTien.Value;

                    ctPN.maHH      = cbSanPham.SelectedValue.ToString();
                    ctPN.soLuong   = int.Parse(txtSoLuong.Text);
                    ctPN.thanhTien = decimal.Parse(txtDonGia.Text);

                    pn.tongTien += ctPN.soLuong * ctPN.thanhTien.Value;

                    HangHoa hh = db.HangHoas.Single(x => x.maHH == ctPN.maHH);
                    hh.soluong += ctPN.soLuong;

                    db.SaveChanges();
                    FormChiTietPhieuNhap_Load(sender, e);

                    MessageBox.Show("Sửa thành công!");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
示例#3
0
        public ActionResult DeleteConfirmed(int id)
        {
            Chitietnhap chitietnhap = db.Chitietnhaps.Find(id);

            db.Chitietnhaps.Remove(chitietnhap);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
示例#4
0
 public ActionResult Edit([Bind(Include = "STT,Maphieunhap,Mahanghoa,Soluong,Ngaynhap,MaNCC")] Chitietnhap chitietnhap)
 {
     if (ModelState.IsValid)
     {
         db.Entry(chitietnhap).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.Mahanghoa   = new SelectList(db.Hanghoas, "Mahanghoa", "Mahanghoa", chitietnhap.Mahanghoa);
     ViewBag.Maphieunhap = new SelectList(db.Phieunhaps, "Maphieunhap", "Maphieunhap", chitietnhap.Maphieunhap);
     return(View(chitietnhap));
 }
示例#5
0
        // GET: Chitietnhaps/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Chitietnhap chitietnhap = db.Chitietnhaps.Find(id);

            if (chitietnhap == null)
            {
                return(HttpNotFound());
            }
            return(View(chitietnhap));
        }
示例#6
0
        // GET: Chitietnhaps/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Chitietnhap chitietnhap = db.Chitietnhaps.Find(id);

            if (chitietnhap == null)
            {
                return(HttpNotFound());
            }
            ViewBag.Mahanghoa   = new SelectList(db.Hanghoas, "Mahanghoa", "Mahanghoa", chitietnhap.Mahanghoa);
            ViewBag.Maphieunhap = new SelectList(db.Phieunhaps, "Maphieunhap", "Maphieunhap", chitietnhap.Maphieunhap);
            return(View(chitietnhap));
        }
        private void btnThem_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Bạn có muốn thêm thông tin vừa nhập cho phiếu nhập đã chọn không?", "Thông báo", MessageBoxButtons.YesNo)
                == System.Windows.Forms.DialogResult.Yes)
            {
                try
                {
                    Chitietnhap ctpn1 = db.Chitietnhaps.Single(x => x.maPN == pn.maPN && x.maHH == selectedMaHH);
                    if (ctpn1 != null)
                    {
                        ctpn1.soLuong += int.Parse(txtSoLuong.Text);
                        HangHoa hh = db.HangHoas.Single(x => x.maHH == ctpn1.maHH);
                        hh.soluong  += ctpn1.soLuong;
                        pn.tongTien += int.Parse(txtSoLuong.Text) * ctpn1.thanhTien;
                    }
                    else
                    {
                        Chitietnhap ctPN = new Chitietnhap()
                        {
                            maPN      = MaPN,
                            maHH      = cbSanPham.SelectedValue.ToString(),
                            soLuong   = int.Parse(txtSoLuong.Text),
                            thanhTien = decimal.Parse(txtDonGia.Text)
                        };
                        HangHoa hh = db.HangHoas.Single(x => x.maHH == ctPN.maHH);
                        hh.soluong += ctPN.soLuong;

                        db.Chitietnhaps.Add(ctPN);
                        pn.tongTien += ctPN.soLuong * ctPN.thanhTien;
                    }

                    db.SaveChanges();
                    FormChiTietPhieuNhap_Load(sender, e);
                    MessageBox.Show("Thêm thành công!");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }