public bool addDetail(ChiTietHoaDonNXB chitiet) { if (isDetailExisted(chitiet)) { return(false); } _chitiet.Add(chitiet); return(true); }
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<ChiTietHoaDonNXB> ListChiTiet = new List<ChiTietHoaDonNXB>(); HoaDonNXB hd = new HoaDonNXB(); hd.MaSoNXB = int.Parse(txbMaSoNXB.Text.ToString()); hd.NgayLap = DateTime.Parse(dtpNgayLap.Value.ToString("yyyy-MM-dd")); //Lay list chi tiet 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))) { ChiTietHoaDonNXB ct = new ChiTietHoaDonNXB(); 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); } } //Kiem tra chi tiet . Chi ong code cai nay nhin no gon hon ne 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; //for (int i = 0; i < ListChiTiet.Count; i++) //{ // hd.addDetail(ListChiTiet[i]); //} int x = HoaDonNXBManager.add(hd); if (x != 0) { MessageBox.Show("Đã thêm thành công hóa đơn nhà xuất bản"); txbMaHoaDon.Text = x + ""; } } else if (dialogResult == DialogResult.No) { return; } }
public bool isDetailExisted(ChiTietHoaDonNXB chitiet) { return _chitiet.Contains(chitiet); }
public bool addDetail(ChiTietHoaDonNXB chitiet) { if (isDetailExisted(chitiet)) { return false; } _chitiet.Add(chitiet); return true; }
public ViewResult BlankEditorRow(int masonxb, int masosach = 0) { var nxb = NhaXuatBanManager.find((int)masonxb); var chitiet = new ChiTietHoaDonNXB(); if(masosach != 0) { chitiet.MaSoSach = (int)masosach; if (_hoadon.ChiTiet.Contains(chitiet)) { return null; } } else { var founded = false; foreach (Sach s in nxb.Sach.Where(s => s.CongNoNXB.Count > 0).ToList()) { chitiet.MaSoSach = s.MaSoSach; chitiet.Sach = s; if (_hoadon.ChiTiet.Contains(chitiet)) { continue; } founded = true; break; } if (!founded) { return null; } } ViewBag.currentNXB = nxb; ViewBag.cultureInfo = CultureInfo; ViewBag.DMSach = new SelectList(nxb.Sach, nameof(SachManager.Properties.MaSoSach), nameof(SachManager.Properties.TenSach), ""); chitiet.SoLuong = 1; chitiet.DonGia = chitiet.Sach.GiaNhap; _hoadon.addDetail(chitiet); return View("ChiTietEditorRow", chitiet); }
public JsonResult isDetailExisted(string masosach) { var key = Int32.Parse(masosach); var chitiet = new ChiTietHoaDonNXB(); chitiet.MaSoSach = key; if (_hoadon.isDetailExisted(chitiet)) { return Json(true,JsonRequestBehavior.AllowGet); } else { return Json(false, JsonRequestBehavior.AllowGet); } }
public bool isDetailExisted(ChiTietHoaDonNXB chitiet) { return(_chitiet.Contains(chitiet)); }
public static bool edit(ChiTietHoaDonNXB chitiet) { try { using (EntitiesDataContext db = new EntitiesDataContext()) { CHITIETHOADONNXB ct; ct = (from c in db.CHITIETHOADONNXBs where c.masohoadon.Equals(chitiet.MaSoHoaDon) && c.masosach.Equals(chitiet.MaSoSach) select c).SingleOrDefault(); if (ct == null) return false; ct.soluong = chitiet.SoLuong; ct.trangthai = chitiet.TrangThai; db.SubmitChanges(); return true; } } catch (Exception ex) { Console.WriteLine(ex.Message); return false; } }
public static bool add(ChiTietHoaDonNXB chitiet, int masohoadon) { try { using (EntitiesDataContext db = new EntitiesDataContext()) { CHITIETHOADONNXB ct; ct = (from c in db.CHITIETHOADONNXBs where c.masohoadon.Equals(masohoadon) && c.masosach.Equals(chitiet.MaSoSach) select c).SingleOrDefault(); if (ct != null) return false; ct = new CHITIETHOADONNXB { masohoadon = masohoadon, masosach = chitiet.MaSoSach, soluong = chitiet.SoLuong, dongia = chitiet.DonGia, trangthai = chitiet.TrangThai == null ? 0 : 1 }; db.CHITIETHOADONNXBs.InsertOnSubmit(ct); db.SubmitChanges(); return true; } } catch (Exception ex) { Console.WriteLine(ex.Message); return false; } }
public static bool add(ChiTietHoaDonNXB chitiet) { return add(chitiet, chitiet.MaSoHoaDon); }