Ejemplo n.º 1
0
 public bool addDetail(ChiTietHoaDonDaiLy chitiet)
 {
     if (isDetailExisted(chitiet))
     {
         return(false);
     }
     _chitiet.Add(chitiet);
     return(true);
 }
        //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;
            }
        }
Ejemplo n.º 3
0
 public bool isDetailExisted(ChiTietHoaDonDaiLy chitiet)
 {
     return(_chitiet.Contains(chitiet));
 }
 public ViewResult BlankEditorRow(int masodaily, int masosach = 0)
 {
     var dl = DaiLyManager.find((int)masodaily);
     var chitiet = new ChiTietHoaDonDaiLy();
     if(masosach != 0)
     {
         chitiet.MaSoSach = (int)masosach;
         if (_hoadon.ChiTiet.Contains(chitiet))
         {
             return null;
         }
     }
     else
     {
         var founded = false;
         foreach (Sach s in dl.getSachNo())
         {
             chitiet.MaSoSach = s.MaSoSach;
             chitiet.Sach = s;
             if (_hoadon.ChiTiet.Contains(chitiet))
             {
                 continue;
             }
             founded = true;
             break;
         }
         if (!founded)
         {
             return null;
         }
     }
     ViewBag.currentDaiLy = dl;
     ViewBag.cultureInfo = CultureInfo;
     ViewBag.DMSach = new SelectList(dl.getSachNo(),
                                 nameof(SachManager.Properties.MaSoSach),
                                 nameof(SachManager.Properties.TenSach), "");
     chitiet.SoLuong = 1;
     chitiet.DonGia = chitiet.Sach.GiaNhap;
     _hoadon.addDetail(chitiet);
     ViewData["masodaily"] = dl.MaSoDaiLy;
     return View("ChiTietEditorRow", chitiet);
 }
 public JsonResult isDetailExisted(string masosach)
 {
     var key = Int32.Parse(masosach);
     var chitiet = new ChiTietHoaDonDaiLy();
     chitiet.MaSoSach = key;
     if (_hoadon.isDetailExisted(chitiet))
     {
         return Json(true,JsonRequestBehavior.AllowGet);
     }
     else
     {
         return Json(false, JsonRequestBehavior.AllowGet);
     }
 }
Ejemplo n.º 6
0
 public bool isDetailExisted(ChiTietHoaDonDaiLy chitiet)
 {
     return _chitiet.Contains(chitiet);
 }
Ejemplo n.º 7
0
 public bool addDetail(ChiTietHoaDonDaiLy chitiet)
 {
     if (isDetailExisted(chitiet))
     {
         return false;
     }
     _chitiet.Add(chitiet);
     return true;
 }
 public static bool edit(ChiTietHoaDonDaiLy chitiet)
 {
     try
     {
         using (EntitiesDataContext db = new EntitiesDataContext())
         {
             CHITIETHOADONDAILY ct;
             ct = (from c in db.CHITIETHOADONDAILies
                   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(ChiTietHoaDonDaiLy chitiet, int masohoadon)
 {
     try
     {
         using (EntitiesDataContext db = new EntitiesDataContext())
         {
             CHITIETHOADONDAILY ct;
             ct = (from c in db.CHITIETHOADONDAILies
                   where c.masohoadon.Equals(masohoadon)
                   && c.masosach.Equals(chitiet.MaSoSach)
                   select c).SingleOrDefault();
             if (ct != null) return false;
             ct = new CHITIETHOADONDAILY
             {
                 masohoadon = masohoadon,
                 masosach = chitiet.MaSoSach,
                 soluong = chitiet.SoLuong,
                 dongia = chitiet.DonGia,
                 trangthai = chitiet.TrangThai == null ? 0 : 1
             };
             db.CHITIETHOADONDAILies.InsertOnSubmit(ct);
             db.SubmitChanges();
             return true;
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         return false;
     }
 }
 public static bool add(ChiTietHoaDonDaiLy chitiet)
 {
     return add(chitiet, chitiet.MaSoHoaDon);
 }