// GET: PhieuNhap/Edit/5
 public ActionResult Edit(int?id)
 {
     if (id == null)
     {
         putErrorMessage("Đường dẫn không chính xác");
         return(RedirectToAction("All"));
     }
     if (_currentHoaDon == null || _currentHoaDon != id)
     {
         _currentHoaDon = id;
         _hoadon        = HoaDonNXBManager.find((int)id);
         if (_hoadon == null)
         {
             putErrorMessage("Không tìm thấy");
             return(RedirectToAction("All"));
         }
         if (_hoadon.TrangThai == 1)
         {
             //Nếu đã duyệt thì không cho sửa, chuyển sang trang chi tiết
             _currentHoaDon = null;
             putErrorMessage("Hóa đơn đã duyệt");
             return(RedirectToAction("Details", new { id = id }));
         }
     }
     ViewBag.cultureInfo = CultureInfo;
     ViewBag.currentNXB  = _hoadon.NXB;
     ViewBag.DMSach      = new SelectList(_hoadon.NXB.Sach.Where(s => s.CongNoNXB.Count > 0).ToList(),
                                          nameof(SachManager.Properties.MaSoSach),
                                          nameof(SachManager.Properties.TenSach), "");
     setAlertMessage();
     return(View(_hoadon));
 }
Ejemplo n.º 2
0
        private void gdvHoaDon_SelectionChanged(object sender, EventArgs e)
        {
            int index = ((DataGridView)sender).CurrentRow.Index;

            _CurrentHD = (((DataGridView)sender).DataSource as List <HoaDonNXB>)[index];
            select(_CurrentHD);
        }
 public static int add(HoaDonNXB hoadon)
 {
     try
     {
         using (EntitiesDataContext db = new EntitiesDataContext())
         {
             var hd = new HOADONNXB
             {
                 masonxb   = hoadon.MaSoNXB,
                 ngaylap   = hoadon.NgayLap,
                 tongtien  = hoadon.ChiTiet.Sum(ct => ct.SoLuong * ct.DonGia),
                 trangthai = 0
             };
             db.HOADONNXBs.InsertOnSubmit(hd);
             db.SubmitChanges();
             foreach (ChiTietHoaDonNXB ct in hoadon.ChiTiet)
             {
                 ChiTiet.add(ct, hd.masohoadon);
             }
             return(hd.masohoadon);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         return(0);
     }
 }
        public static bool edit(HoaDonNXB hoadon)
        {
            try
            {
                using (EntitiesDataContext db = new EntitiesDataContext())
                {
                    HOADONNXB hd;
                    hd = (from p in db.HOADONNXBs
                          where p.masohoadon.Equals(hoadon.MaSoHoaDon)
                          select p).SingleOrDefault();
                    if (hd == null)
                    {
                        return(false);
                    }
                    hd.masonxb   = hoadon.MaSoNXB;
                    hd.ngaylap   = hoadon.NgayLap;
                    hd.trangthai = hoadon.TrangThai;
                    hd.tongtien  = hoadon.ChiTiet.Sum(ct => ct.SoLuong * ct.DonGia); // tính tổng tiền các chi tiết
                    db.CHITIETHOADONNXBs.DeleteAllOnSubmit(hd.CHITIETHOADONNXBs);
                    db.SubmitChanges();
                    foreach (ChiTietHoaDonNXB ct in hoadon.ChiTiet)
                    {
                        ChiTiet.add(ct, hoadon.MaSoHoaDon);
                    }

                    return(true);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(false);
            }
        }
        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 JsonResult GetProperties(string request)
        {
            List <string> results = new List <string>();

            foreach (string pro in HoaDonNXB.searchKeys())
            {
                results.Add(request + pro);
            }
            return(Json(results, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 7
0
        public void select(HoaDonNXB hd)
        {
            if (hd != null)
            {
                txbMaHD.Text         = hd.MaSoHoaDon + "";
                cmbNXB.SelectedValue = hd.MaSoNXB;
                string   day        = hd.NgayLap.ToString();
                DateTime thedate    = DateTime.Parse(day);
                String   dateString = thedate.ToString("yyyy/MM/dd");
                day = dateString;

                char[] cut = day.ToCharArray();
                string nam = "";
                for (int i = 0; i < 4; i++)
                {
                    nam += cut[i];
                }
                string thang = "";
                for (int i = 5; i < 7; i++)
                {
                    thang += cut[i];
                }
                string ngay = "";
                for (int i = 8; i < 10; i++)
                {
                    ngay += cut[i];
                }
                dtpNgay.Value = new DateTime(int.Parse(nam), int.Parse(thang), int.Parse(ngay));
                int trangthai = (int)hd.TrangThai;
                if (trangthai == 1)
                {
                    btDuyet.Text    = "Đã duyệt";
                    btDuyet.Enabled = false;
                    btXoa.Enabled   = false;
                }
                if (trangthai == 0)
                {
                    btDuyet.Text    = "Duyệt hóa đơn";
                    btDuyet.Enabled = true;
                    btXoa.Enabled   = true;
                }
            }
        }
 public ActionResult ThanhToan(HoaDonNXB model, FormCollection collection)
 {
     try
     {
         // TODO: Add insert logic here
         if (ModelState.IsValid)
         {
             var result = HoaDonNXBManager.add(model);
             if (result != 0)
             {
                 _hoadon = null;
                 putSuccessMessage("Thêm hóa đơn thành công");
                 return(RedirectToAction("Details", new { id = result }));
             }
             else
             {
                 putErrorMessage("Thánh toán không thành công");
                 return(RedirectToAction("ThanhToan", new { masonxb = _hoadon.MaSoNXB }));
             }
         }
         else
         {
             putModelStateFailErrors(ModelState);
             return(RedirectToAction("ThanhToan", new { masonxb = _hoadon.MaSoNXB }));
         }
         //ViewBag.cultureInfo = CultureInfo;
         //ViewBag.currentNXB = _hoadon.NXB;
         //ViewBag.DMSach = new SelectList(_hoadon.NXB.Sach.Where(s => s.CongNoNXB.Count > 0).ToList(),
         //                        nameof(SachManager.Properties.MaSoSach),
         //                        nameof(SachManager.Properties.TenSach), "");
         //_hoadon.NgayLap = DateTime.Now;
         //return View(_hoadon);
     }
     catch (Exception ex)
     {
         putErrorMessage(ex.Message);
         return(RedirectToAction("ThanhToan", new { masonxb = _hoadon.MaSoNXB }));
     }
 }
 // GET: PhieuNhap/ThanhToan
 public ActionResult ThanhToan(int?masonxb)
 {
     if (masonxb != null)
     {
         var nxb = NhaXuatBanManager.find((int)masonxb);
         if (nxb == null || nxb.TrangThai == 0)
         {
             putErrorMessage("Không tìm thấy nhà xuất bản");
             return(RedirectToAction("ThanhToan"));
         }
         ViewBag.cultureInfo = CultureInfo;
         ViewBag.currentNXB  = nxb;
         ViewBag.DMSach      = new SelectList(nxb.Sach.Where(s => s.CongNoNXB.Count > 0).ToList(),
                                              nameof(SachManager.Properties.MaSoSach),
                                              nameof(SachManager.Properties.TenSach), "");
         if (_hoadon == null)
         {
             _hoadon = new HoaDonNXB();
         }
         _hoadon.MaSoNXB = nxb.MaSoNXB;
         _hoadon.NXB     = nxb;
         _hoadon.NgayLap = DateTime.Now;
         setAlertMessage();
         return(View(_hoadon));
     }
     else
     {
         ViewBag.DMNXB = new SelectList(NhaXuatBanManager.getAllAlive()
                                        .Where(nxb => nxb.TongTienNo > 0).ToList(),
                                        nameof(NhaXuatBanManager.Properties.MaSoNXB),
                                        nameof(NhaXuatBanManager.Properties.TenNXB), "");
         _hoadon = new HoaDonNXB();
         setAlertMessage();
         return(View());
     }
 }
 public ActionResult Edit(HoaDonNXB model, FormCollection collection)
 {
     try
     {
         if (ModelState.IsValid)
         {
             if (HoaDonNXBManager.edit(model))
             {
                 _currentHoaDon = null;
                 putSuccessMessage("Cập nhật thành công");
                 return(RedirectToAction("Details", new { id = model.MaSoHoaDon }));
             }
             else
             {
                 putErrorMessage("Cập nhật thất bại");
             }
         }
         else
         {
             putModelStateFailErrors(ModelState);
         }
         return(RedirectToAction("Edit", new { id = model.MaSoHoaDon }));
         // TODO: Add update logic here
         //_hoadon = model;
         //ViewBag.currentNXB = _hoadon.NXB;
         //ViewBag.DMSach = new SelectList(_hoadon.NXB.Sach.Where(s => s.CongNoNXB.Count > 0).ToList(),
         //                        nameof(SachManager.Properties.MaSoSach),
         //                        nameof(SachManager.Properties.TenSach), "");
         //return View(_hoadon);
     }
     catch (Exception ex)
     {
         putErrorMessage(ex.Message);
         return(RedirectToAction("Edit", new { id = model.MaSoHoaDon }));
     }
 }
 public frmChiTietHoaDonNXB(Form parent, HoaDonNXB hd)
     : this(parent)
 {
     _CurrentHD = hd;
 }