Esempio n. 1
0
        public ActionResult Create([Bind(Include = "OrderDetailID,OrderID,ProductID,ProductName,ProductCode,UnitPrice,Quantity,PromotionPrice,CreateDate,CreateUser,ModifiedDate,ModifiedUser,IsActive")] OrderDetail orderDetail)
        {
            var UserSession = (UserLogin)Session[TechDeviShopVs002.Common.CommonConstants.USER_SESSION];

            if (ModelState.IsValid)
            {
                var _dal = new OrderDetailsDAL();

                orderDetail.CreateUser = UserSession.UserID;
                var pd = new ProductDAL().ViewDetail(orderDetail.ProductID);
                orderDetail.ProductName    = pd.ProductName;
                orderDetail.ProductCode    = pd.ProductCode;
                orderDetail.UnitPrice      = pd.Price;
                orderDetail.PromotionPrice = pd.PromotionPrice;

                int id = _dal.Insert(orderDetail);
                if (id > 0)
                {
                    return(RedirectToAction("Index", "OrderDetails"));
                }
                else
                {
                    ModelState.AddModelError("", "Thêm Chi tiết hóa đơn ko thành công");
                }
            }
            ViewBag.OrderID   = new SelectList(db.Orders, "OrderID", "OrderID", orderDetail.OrderID);
            ViewBag.ProductID = new SelectList(db.Products, "ProductID", "ProductName", orderDetail.ProductID);
            //ViewBag.ProductName = new SelectList(db.Products, "ProductName", "ProductName", orderDetail.ProductName);
            //ViewBag.ProductCode = new SelectList(db.Products, "ProductCode", "ProductCode", orderDetail.ProductCode);
            //ViewBag.UnitPrice = new SelectList(db.Products, "UnitPrice", "Price", orderDetail.UnitPrice);
            //ViewBag.PromotionPrice = new SelectList(db.Products, "PromotionPrice", "PromotionPrice", orderDetail.PromotionPrice);
            return(View(orderDetail));
        }
Esempio n. 2
0
 private void BtnCreate_Click(object sender, EventArgs e)
 {
     odbll.AmountPaid  = Convert.ToDouble(txtAmountPaid.Text);
     odbll.Comment     = txtComment.Text.ToUpper();
     odbll.Discount    = Convert.ToDouble(txtDiscount.Text);
     odbll.PaymentMode = CmbPaymentMode.Text.ToUpper();
     odbll.PayDate     = DateTime.Now.Date;
     odbll.Status      = CmbStatus.Text.ToUpper();
     odbll.OrderDate   = DateTime.Now.Date;
     odbll.UserID      = Convert.ToInt32(CmbUserID.SelectedValue);
     odbll.CustomerID  = Convert.ToInt32(CmbCustomerID.SelectedValue);
     try
     {
         bool IsSuccess = oddal.Insert(odbll);
         if (IsSuccess)
         {
             MessageBox.Show("Successfully created", "Confirm", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
             DataTable dt = new DataTable();
             dt = oddal.Select();
             dataGridView1.DataSource = dt;
         }
         else
         {
             MessageBox.Show("Failed to initiate a record", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString(), "UI error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
     }
 }