Пример #1
0
 private void btnLuu_Click(object sender, EventArgs e)
 {
     if (grChiTietKhoanChi.RowCount != 0)
     {
         try
         {
             InvoiceDAO       dt = new InvoiceDAO();
             InvoiceDetailDAO dc = new InvoiceDetailDAO();
             Invoice          a  = new Invoice();
             a.CourseID         = (int)cbbNamhoc.SelectedValue;
             a.SemesterID       = (int)cbbHocky.SelectedValue;
             a.CreatedDate      = DateTime.Now;
             a.EmployeeID       = LoginDetail.LoginID;
             a.NameMoneyReceive = txtHoten.Text;
             a.PhoneNumber      = txtSDT.Text;
             a.AdressDetail     = txtDiachi.Text;
             a.TotalPrice       = decimal.Parse(txtTongchi.Text);
             a.SpendSpeciesID   = (int)cbbLoaichi.SelectedValue;
             a.Note             = txtGhichu.Text;
             System.Guid a1 = dt.Insert(a);
             if (a1 != null)
             {
                 for (int i = 0; i < grChiTietKhoanChi.RowCount; i++)
                 {
                     InvoiceDetail b = new InvoiceDetail();
                     b.InvoiceID         = a1;
                     b.NameInvoiceDetail = grChiTietKhoanChi.GetRowCellValue(i, grChiTietKhoanChi.Columns["NameInvoiceDetail"]).ToString();
                     b.Price             = (decimal)grChiTietKhoanChi.GetRowCellValue(i, grChiTietKhoanChi.Columns["Price"]);
                     b.Unit             = grChiTietKhoanChi.GetRowCellValue(i, grChiTietKhoanChi.Columns["Unit"]).ToString();
                     b.Amount           = (int)grChiTietKhoanChi.GetRowCellValue(i, grChiTietKhoanChi.Columns["Amount"]);
                     b.TotalPriceDetail = (decimal)grChiTietKhoanChi.GetRowCellValue(i, grChiTietKhoanChi.Columns["TotalPriceDetail"]);
                     b.Note             = grChiTietKhoanChi.GetRowCellValue(i, grChiTietKhoanChi.Columns["Note"]).ToString();
                     b.Status           = false;
                     if (dc.Insert(b) == true)
                     {
                     }
                     else
                     {
                         MessageBox.Show("Bản ghi " + i + " bị lỗi");
                         break;
                     }
                 }
                 MessageBox.Show("Lưu thành công");
                 this.Close();
             }
         }
         catch
         {
         }
     }
 }
Пример #2
0
        public ActionResult Checkout(INVOICE invoice)
        {
            var sessionCart = (CartModel)Session[Common.CommonConstants.CART_SESSION];
            var sessionUser = Session[Common.CommonConstants.USER_SESSION];

            invoice.Created_Time = DateTime.Now;
            invoice.Status       = 0;
            invoice.Total        = sessionCart.Total * (100 - sessionCart.DiscountAmount) / 100;

            if (sessionCart.DiscountCode != null)
            {
                invoice.Id_Discount_Code = new DiscountCodeDAO().GetDiscountCodeByCode(sessionCart.DiscountCode).Id;
            }

            if (sessionUser != null)
            {
                var user = (USER)sessionUser;
                invoice.Id_User = user.Id;
            }

            if (ModelState.IsValid)
            {
                var invoiceId = new InvoiceDAO().Insert(invoice);

                if (invoiceId > 0)
                {
                    var detailDAO = new InvoiceDetailDAO();

                    foreach (var item in sessionCart.ListCartItem)
                    {
                        var invoiceDetail = new INVOICE_DETAIL
                        {
                            Id_Invoice = invoiceId,
                            Id_Product = item.Product.Id,
                            Quantity   = item.Quantity
                        };

                        detailDAO.Insert(invoiceDetail);
                    }

                    Session[Common.CommonConstants.CART_SESSION] = null;

                    return(Json(new { result = true }));
                }
            }

            return(PartialView("CheckoutForm", invoice));
        }
Пример #3
0
        public void LoadChiTietHoaDon()
        {
            InvoiceDetailDAO dt = new InvoiceDetailDAO();

            grChitietkhoanchi.DataSource = dt.ListInvoiceDetail(System.Guid.Parse(txtMaHoaDon.Text));
        }
Пример #4
0
        public void LoadChiTietHoaDon(System.Guid a)
        {
            InvoiceDetailDAO dt = new InvoiceDetailDAO();

            grcChiTietKhoanChi.DataSource = dt.ListInvoiceDetail(a);
        }