//khi Lưu lại hóa đơn private void btnLuu_Click(object sender, EventArgs e) { DialogResult dialogResult = MessageBox.Show("Bạn có muốn lưu", "Thông báo", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { List <ChiTietHoaDonDaiLy> ListChiTiet = new List <ChiTietHoaDonDaiLy>(); HoaDonDaiLy hd = new HoaDonDaiLy(); hd.MaSoDaiLy = int.Parse(txbMaSoDaiLy.Text.ToString()); hd.NgayLap = DateTime.Parse(dtpNgayLap.Value.ToString("yyyy-MM-dd")); for (int i = 0; i < gdvChiTiet.RowCount - 1; i++) { if (!String.IsNullOrEmpty(Convert.ToString(gdvChiTiet.Rows[i].Cells[0].Value)) && !String.IsNullOrEmpty(Convert.ToString(gdvChiTiet.Rows[i].Cells[1].Value)) && !String.IsNullOrEmpty(Convert.ToString(gdvChiTiet.Rows[i].Cells[2].Value))) { ChiTietHoaDonDaiLy ct = new ChiTietHoaDonDaiLy(); ct.MaSoSach = int.Parse(gdvChiTiet.Rows[i].Cells[0].Value.ToString()); ct.SoLuong = int.Parse(gdvChiTiet.Rows[i].Cells[1].Value.ToString()); ct.DonGia = int.Parse(gdvChiTiet.Rows[i].Cells[2].Value.ToString()); ListChiTiet.Add(ct); } } if (ListChiTiet.Count > 1) { for (int i = 0; i < ListChiTiet.Count - 1; i++) { for (int j = i + 1; j < ListChiTiet.Count; j++) { if (ListChiTiet[i].MaSoSach.Equals(ListChiTiet[j].MaSoSach)) { MessageBox.Show("Không nhập trùng sách"); return; } } } } hd.ChiTiet = ListChiTiet; int x = HoaDonDaiLyManager.add(hd); if (x != 0) { MessageBox.Show("Đã thêm thành công hóa đơn đại lý"); txbMaHoaDon.Text = x + ""; } } else if (dialogResult == DialogResult.No) { return; } }
public ActionResult ThanhToan(HoaDonDaiLy model, FormCollection collection) { try { // TODO: Add insert logic here if (ModelState.IsValid) { var result = HoaDonDaiLyManager.add(model); if (result != 0) { _hoadon = null; putSuccessMessage("Thanh toán thành công"); return(RedirectToAction("Details", new { id = result })); } else { putErrorMessage("Thanh toán không thành công"); } } else { putModelStateFailErrors(ModelState); } //ViewBag.cultureInfo = CultureInfo; //ViewBag.currentDaiLy = _hoadon.DaiLy; //ViewBag.DMSach = new SelectList(_hoadon.DaiLy.getSachNo(), // nameof(SachManager.Properties.MaSoSach), // nameof(SachManager.Properties.TenSach), ""); //_hoadon.NgayLap = DateTime.Now; //return View(_hoadon); return(RedirectToAction("ThanhToan", new { masodaily = _hoadon.MaSoDaiLy })); } catch (Exception ex) { putErrorMessage(ex.Message); return(RedirectToAction("ThanhToan", new { masodaily = _hoadon.MaSoDaiLy })); } }