//Get:Index/AddCar public ActionResult AddCar(string fPId) { //取得會員帳號並指定給fUserId string fUserId = (Session["Member"] as tMember).fUserId; //找出會員放入訂單明細的產品,該產品的fIsApproved為"否" //表示該產品是購物車狀態 var currentCar = db.tOrderDetail .Where(m => m.fPId == fPId && m.fIsApproved == "否" && m.fUserId == fUserId) .FirstOrDefault(); //若currentCar等於null,表示會員選購的產品不是購物車狀態 if (currentCar == null) { //找出目前選購的產品並指定給product var product = db.tProduct.Where(m => m.fPId == fPId).FirstOrDefault(); //將產品放入訂單明細,因為產品的fIsApproved為"否",表示為購物車狀態 tOrderDetail orderDetail = new tOrderDetail(); orderDetail.fUserId = fUserId; orderDetail.fPId = product.fPId; orderDetail.fName = product.fName; orderDetail.fPrice = product.fPrice; orderDetail.fQty = 1; orderDetail.fIsApproved = "否"; db.tOrderDetail.Add(orderDetail); } else { //若產品為購物車狀態,即將該產品數量加1 currentCar.fQty += 1; } db.SaveChanges(); //執行Home控制器的ShoppingCar動作方法 return RedirectToAction("ShoppingCar"); }
public ActionResult AddCar(string fPId) { //string fUserId = (Session["Member"] as tMember).fUserId; string fUserId = "tom"; var currentCar = db.tOrderDetail.Where(m => m.fPId == fPId && m.fIsApproved == "否" && m.fUserId == fUserId).FirstOrDefault(); if (currentCar == null) { var product = db.tProduct.Where(m => m.fPId == fPId).FirstOrDefault(); tOrderDetail orderDetail = new tOrderDetail(); orderDetail.fUserId = fUserId; orderDetail.fPId = product.fPId; orderDetail.fName = product.fName; orderDetail.fPrice = product.fPrice; orderDetail.fQty = 1; orderDetail.fIsApproved = "否"; db.tOrderDetail.Add(orderDetail); } else { currentCar.fQty += 1; } db.SaveChanges(); return(RedirectToAction("ShoppingCar")); }
public ActionResult AddCart(string pName) { string userName = (Session["Member"] as tMember).userName; var currentCar = db.tOrderDetails.Where(m => m.pName == pName && m.isApprove == "否" && m.userName == userName).FirstOrDefault(); if (currentCar == null) { var product = db.tProds.Where(m => m.pName == pName).FirstOrDefault(); tOrderDetail newOrder = new tOrderDetail(); newOrder.userName = userName; newOrder.pName = product.pName; newOrder.pPrice = product.pPrice; newOrder.pQty = 1; newOrder.isApprove = "否"; db.tOrderDetails.Add(newOrder); } else { currentCar.pQty += 1; } db.SaveChanges(); var buyAmount = db.tOrderDetails.Where(m => m.isApprove == "否" && m.userName == userName).ToList(); foreach (var item in buyAmount) { total += (int)item.pQty; } Session["Total"] = total; return(RedirectToAction("Product")); }
public ActionResult AddCar(string fPId) { string fUserId = (Session["Member"] as tMember).fUserId; var currentCar = db.tOrderDetail.FirstOrDefault(x => x.fPId == fPId && x.fIsApproved == "否" && x.fUserId == fUserId); if (currentCar == null) { var product = db.tProduct.FirstOrDefault(x => x.fPId == fPId); var detail = new tOrderDetail(); detail.fUserId = fUserId; detail.fPId = product.fPId; detail.fName = product.fName; detail.fPrice = product.fPrice; detail.fQty = 1; detail.fIsApproved = "否"; db.tOrderDetail.Add(detail); } else { currentCar.fQty += 1; } db.SaveChanges(); return(RedirectToAction("ShoppingCar")); }
public JsonResult 實體店新增訂單(EmployeeOrderViewModel empOrder) { if (Session[CSession關鍵字.SK_LOGINED_EMPLOYEE] != null) { tEmployee emp = Session[CSession關鍵字.SK_LOGINED_EMPLOYEE] as tEmployee; if (Session[CSession關鍵字.SK_ORDERDETAIL] == null) { return(Json(new { result = false, msg = "訂單尚未完成!", url = Url.Action("實體店新增訂單", "Order") })); } else { List <EmployeeOrderDetailViewModel> orders = Session[CSession關鍵字.SK_ORDERDETAIL] as List <EmployeeOrderDetailViewModel>; MotaiDataEntities dbContext = new MotaiDataEntities(); tCustomer customer = dbContext.tCustomers.Where(c => c.cCellPhone == empOrder.cCellphone).FirstOrDefault(); tOrder list = new tOrder(); list.oEmployeeId = emp.EmployeeId; list.oCustomerId = customer.CustomerId; if (empOrder.oAddress == null) { list.oAddress = customer.cAddress; } else { list.oAddress = empOrder.oAddress; } list.oDate = empOrder.oDate; list.cNote = empOrder.cNote; list.oWarehouseName = empOrder.oWarehouseName; dbContext.tOrders.Add(list); dbContext.SaveChanges(); int orderId = dbContext.tOrders.OrderByDescending(i => i.OrderId).First().OrderId; int originalPrice = 0; foreach (var items in orders) { tOrderDetail detail = new tOrderDetail(); detail.oOrderId = orderId; detail.oProductId = items.oProductId; detail.oProductQty = items.oProductQty; detail.oNote = items.oNote; dbContext.tOrderDetails.Add(detail); tProduct product = dbContext.tProducts.Where(p => p.ProductId.Equals(items.oProductId)).FirstOrDefault(); originalPrice += items.oProductQty * Convert.ToInt32(product.pPrice); } tOrder order = dbContext.tOrders.Where(o => o.OrderId == orderId).FirstOrDefault(); int promotionId = orderRespoitory.SelectPromotionId(originalPrice, empOrder.oDate); if (promotionId != 0) { order.oPromotionId = promotionId; } dbContext.SaveChanges(); Session[CSession關鍵字.SK_ORDERDETAIL] = null; return(Json(new { result = true, msg = "新增成功", url = Url.Action("realCheckView", "Order"), OrderId = orderId })); } } else { return(Json(new { result = false, msg = "尚未登入!", url = Url.Action("員工登入", "Employee") })); } }
//取得目前購物車 public ActionResult AddToCart(string fProductID, string fLenght, string fWidth, int fQuantity, int fGlassID) { var currentCart = operation.GetCurrentCart(); tOrderDetail t = new tOrderDetail() { fProductID = fProductID, fLenght = Convert.ToDecimal(fLenght), fWidth = Convert.ToDecimal(fWidth), fQuantity = fQuantity, fGlassID = fGlassID }; currentCart.AddPorduct(t); return(PartialView("_CartPartial")); }
//新增一筆 用 tOrderDetail 物件 public bool AddPorduct(tOrderDetail detial) { var cartItem = new CartItem(); { cartItem.fProductID = detial.fProductID; cartItem.fLenght = detial.fLenght; cartItem.fWidth = detial.fWidth; cartItem.fQuantity = detial.fQuantity; cartItem.fGlassID = detial.fGlassID; } //加入購物車 this.cartItems.Add(cartItem); return(true); }
public ActionResult AddCar(string fPId) { var Member = this.Member; if (Member == null) { Session.Clear(); //清除Session變數資料 return(RedirectToAction("Index")); } //取得會員帳號並指定給fUserId string fUserId = Member.fUserId; //找出會員放入訂單明細的產品,該產品的fIsApproved為"否" //表示該產品是購物車狀態 var currentCar = db.tOrderDetail .Where(m => m.fPId == fPId && m.fIsApproved == "否" && m.fUserId == fUserId) .FirstOrDefault(); //若currentCar等於null,表示會員選購的產品不是購物車狀態 if (currentCar == null) { //找出目前選購的產品並指定給product var product = db.tProduct.Where(m => m.fPId == fPId).FirstOrDefault(); //將產品放入訂單明細,因為產品的fIsApproved為"否",表示為購物車狀態 tOrderDetail orderDetail = new tOrderDetail(); orderDetail.fUserId = fUserId; orderDetail.fPId = product.fPId; orderDetail.fName = product.fName; orderDetail.fPrice = product.fPrice; orderDetail.fQty = 1; orderDetail.fAmount = product.fPrice * orderDetail.fQty; orderDetail.fIsApproved = "否"; db.tOrderDetail.Add(orderDetail); } else { //若產品為購物車狀態,即將該產品數量加1 currentCar.fQty = (currentCar.fQty > 8 ? 9 : currentCar.fQty++); currentCar.fAmount = currentCar.fPrice * currentCar.fQty; } db.SaveChanges(); //執行Cart控制器的Index動作方法 return(RedirectToAction("Index")); }
public ActionResult 出貨單查詢() { if (Session[CSession關鍵字.SK_LOGINED_EMPLOYEE] == null) { return(RedirectToAction("員工登入", "Employee")); } MotaiDataEntities dbContext = new MotaiDataEntities(); List <tShipList> tShipLists = dbContext.tShipLists.OrderByDescending(s => s.sShipDate).ToList(); List <ShipSelectViewModel> shipSelects = new List <ShipSelectViewModel>(); foreach (var item in tShipLists) { List <tShipDetail> tShipDetails = dbContext.tShipDetails.Where(sd => sd.ShipId.Equals(item.ShipId)).ToList(); ShipSelectViewModel select = new ShipSelectViewModel(); List <ShipSelectDetailModel> details = new List <ShipSelectDetailModel>(); foreach (var itemdetail in tShipDetails) { tProduct product = dbContext.tProducts.Where(p => p.ProductId.Equals(itemdetail.sProductId)).FirstOrDefault(); tWarehouseName warehouseName = dbContext.tWarehouseNames.Where(w => w.WarehouseNameId.Equals(itemdetail.sWarehouseNameId)).FirstOrDefault(); tOrderDetail orderd = dbContext.tOrderDetails.Where(o => o.oOrderDetailId.Equals(itemdetail.sOrderDetailId)).FirstOrDefault(); ShipSelectDetailModel selectDetail = new ShipSelectDetailModel(); selectDetail.ProductNum = product.pNumber; selectDetail.ProductName = product.pName; selectDetail.OrderId = orderd.oOrderId; selectDetail.sQuantity = itemdetail.sQuantity; selectDetail.WareHouseName = warehouseName.WarehouseName; details.Add(selectDetail); } tEmployee employee = dbContext.tEmployees.Where(e => e.EmployeeId.Equals(item.sEmployeeId)).FirstOrDefault(); select.EmployeeName = employee.eName; select.ShipSerialValue = item.sShipSerialValue; select.ShipDate = item.sShipDate; select.ShipNote = item.sShipNote; select.ShipDetails = details; shipSelects.Add(select); } return(View(shipSelects)); }
public ActionResult AddCart(string fPId) { string user = (Session[CDictionary.SK_LOGINED_USER] as tMember).fUserId; var cart = db.tOrderDetail .Where(m => m.fPId == fPId && m.fIsApproved == "N" && m.fUserId == user) .FirstOrDefault(); if (cart == null) { var product = db.tProduct .Where(p => p.fPId == fPId) .FirstOrDefault(); //string guid = Guid.NewGuid().ToString(); tOrderDetail od = new tOrderDetail(); od.fUserId = user; //od.fOrderId = guid; od.fPId = product.fPId; od.fName = product.fName; od.fPrice = product.fPrice; od.fQty = 1; od.fIsApproved = "N"; db.tOrderDetail.Add(od); } else { cart.fQty += 1; } db.SaveChanges(); return RedirectToAction("Index"); }
//網購寫入訂單 public string webOrder(WebPay payData) { if (Session[CSession關鍵字.SK_LOGINED_CUSTOMER] != null) { tCustomer cust = Session[CSession關鍵字.SK_LOGINED_CUSTOMER] as tCustomer; MotaiDataEntities dbContext = new MotaiDataEntities(); List <tStatu> StatuList = dbContext.tStatus.Where(s => s.sCustomerId.Equals(cust.CustomerId)).ToList(); string szHtml = String.Empty; string szErrorMessage = String.Empty; List <string> enErrors = new List <string>(); try { using (AllInOne oPayment = new AllInOne()) { /* 服務參數 */ oPayment.ServiceMethod = AllPay.Payment.Integration.HttpMethod.HttpPOST; oPayment.ServiceURL = "https://payment-stage.opay.tw/Cashier/AioCheckOut/V5"; oPayment.HashKey = "5294y06JbISpM5x9"; oPayment.HashIV = "v77hoKGq4kWxNNIS"; oPayment.MerchantID = "2000132"; /* 基本參數 */ string baseURI = Request.Url.Scheme + "://" + Request.Url.Authority; if (payData.payType == 2) { oPayment.Send.ReturnURL = baseURI + Url.Action("orderCredit", "Order"); } else { oPayment.Send.ReturnURL = baseURI + Url.Action("ATMpayOff", "Order"); } oPayment.Send.ClientBackURL = baseURI; //oPayment.Send.OrderResultURL = baseURI; int number = (DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second) * 3; oPayment.Send.MerchantTradeNo = "MD" + DateTime.Now.Date.ToString("yyyyMMdd") + number.ToString("000000"); oPayment.Send.MerchantTradeDate = DateTime.Now; oPayment.Send.TotalAmount = Decimal.Parse(payData.totalPay); oPayment.Send.TradeDesc = "感謝購買墨台商品"; if (payData.payType == 1) { oPayment.Send.ChoosePayment = PaymentMethod.ATM; oPayment.SendExtend.ExpireDate = Int32.Parse("3"); } else { oPayment.Send.ChoosePayment = PaymentMethod.Credit; } //oPayment.Send.ChoosePayment = PaymentMethod.ALL; oPayment.Send.Remark = "饒了我吧"; oPayment.Send.ChooseSubPayment = PaymentMethodItem.None; oPayment.Send.NeedExtraPaidInfo = ExtraPaymentInfo.No; oPayment.Send.HoldTrade = HoldTradeType.No; oPayment.Send.DeviceSource = DeviceType.PC; oPayment.Send.UseRedeem = UseRedeemFlag.No; //購物金/紅包折抵 oPayment.Send.IgnorePayment = ""; // 例如財付通:Tenpay // 加入選購商品資料。 foreach (var item in StatuList) { tProduct product = dbContext.tProducts.Where(p => p.ProductId.Equals(item.sProductId)).FirstOrDefault(); //var chg = JObject.Parse(item.Value.ToString()); oPayment.Send.Items.Add(new Item() { Name = product.pName, Price = product.pPrice, Currency = "NTD", Quantity = item.sProductQty, URL = "<< 產品說明位址 >>" }); } // 當付款方式為 ALL 時,建議增加的參數。 if (payData.payType == 1) { oPayment.SendExtend.PaymentInfoURL = baseURI + Url.Action("orderATM", "Order"); } ////攜帶參數 //WebOrderModel order = new WebOrderModel(); //order.boughtList = StatuList; //order.webpay = payData; //order.customer = cust; //order.payDate = oPayment.Send.MerchantTradeDate; //http.Session[oPayment.Send.MerchantTradeNo] = order; //database產生訂單 tOrder newOrder = new tOrder(); newOrder.oCustomerId = cust.CustomerId; newOrder.oEmployeeId = 19; newOrder.oDate = DateTime.Now; newOrder.oAddress = payData.shipAddress; newOrder.oWarehouseName = 1; newOrder.cNote = oPayment.Send.MerchantTradeNo; dbContext.tOrders.Add(newOrder); dbContext.SaveChanges(); tOrder CreateOrder = dbContext.tOrders.OrderByDescending(o => o.OrderId).FirstOrDefault(); tOrderPay pay = new tOrderPay(); pay.oOrderId = CreateOrder.OrderId; pay.oOrderInstallment = 1; pay.oPayType = payData.payType; pay.oPayment = Convert.ToInt32(payData.totalPay); pay.oPayDate = DateTime.Now; dbContext.tOrderPays.Add(pay); foreach (var item in StatuList) { tOrderDetail orderDetail = new tOrderDetail(); orderDetail.oOrderId = CreateOrder.OrderId; orderDetail.oProductId = item.sProductId; orderDetail.oProductQty = item.sProductQty; dbContext.tOrderDetails.Add(orderDetail); dbContext.tStatus.Remove(item); dbContext.SaveChanges(); } dbContext.SaveChanges(); /* 產生訂單 */ enErrors.AddRange(oPayment.CheckOut()); /* 產生產生訂單 Html Code 的方法 */ //string szHtml = String.Empty; enErrors.AddRange(oPayment.CheckOutString(ref szHtml)); } } catch (Exception ex) { // 例外錯誤處理。 enErrors.Add(ex.Message); } finally { // 顯示錯誤訊息。 if (enErrors.Count() > 0) { szErrorMessage = String.Join("\\r\\n", enErrors); } } if (enErrors.Count() == 0) { return(szHtml); } else { return(szErrorMessage); } } return(String.Empty); }
//網購傳回ATM訂單 public void orderATM(string callback) { MotaiDataEntities dbContext = new MotaiDataEntities(); List <string> enErrors = new List <string>(); Hashtable htFeedback = null; try { using (AllInOne oPayment = new AllInOne()) { oPayment.HashKey = "5294y06JbISpM5x9"; oPayment.HashIV = "v77hoKGq4kWxNNIS"; /* 取回付款結果 */ enErrors.AddRange(oPayment.CheckOutFeedback(ref htFeedback)); } // 取回所有資料 if (enErrors.Count() == 0) { /* 支付後的回傳的基本參數 */ string szMerchantID = String.Empty; string szMerchantTradeNo = String.Empty; string szPaymentType = String.Empty; string szRtnCode = String.Empty; string szRtnMsg = String.Empty; string szTradeAmt = String.Empty; string szTradeDate = String.Empty; string szTradeNo = String.Empty; string szBankCode = String.Empty; string szVirtualAccount = String.Empty; string szExpireDate = String.Empty; // 取得資料 foreach (string szKey in htFeedback.Keys) { switch (szKey) { /* 支付後的回傳的基本參數 */ case "MerchantID": szMerchantID = htFeedback[szKey].ToString(); break; case "MerchantTradeNo": szMerchantTradeNo = htFeedback[szKey].ToString(); break; case "RtnCode": szRtnCode = htFeedback[szKey].ToString(); break; case "RtnMsg": szRtnMsg = htFeedback[szKey].ToString(); break; case "TradeNo": szTradeNo = htFeedback[szKey].ToString(); break; case "TradeAmt": szTradeAmt = htFeedback[szKey].ToString(); break; case "PaymentType": szPaymentType = htFeedback[szKey].ToString(); break; case "TradeDate": szTradeDate = htFeedback[szKey].ToString(); break; case "BankCode": szBankCode = htFeedback[szKey].ToString(); break; case "vAccount": szVirtualAccount = htFeedback[szKey].ToString(); break; case "ExpireDate": szExpireDate = htFeedback[szKey].ToString(); break; default: break; } } WebOrderModel Trade = Session[szMerchantTradeNo] as WebOrderModel; //先建訂單 tOrder newOrder = new tOrder(); newOrder.oCustomerId = Trade.customer.CustomerId; newOrder.oDate = Trade.payDate; newOrder.oAddress = Trade.webpay.shipAddress; newOrder.oWarehouseName = 1; dbContext.tOrders.Add(newOrder); dbContext.SaveChanges(); tOrder CreateOrder = dbContext.tOrders.OrderByDescending(o => o.OrderId).FirstOrDefault(); foreach (var item in Trade.boughtList) { tOrderDetail orderDetail = new tOrderDetail(); orderDetail.oOrderId = CreateOrder.OrderId; orderDetail.oProductId = item.sProductId; orderDetail.oProductQty = item.sProductQty; dbContext.tOrderDetails.Add(orderDetail); dbContext.tStatus.Remove(item); } dbContext.SaveChanges(); } else { // 其他資料處理。 } } catch (Exception ex) { // 例外錯誤處理。 enErrors.Add(ex.Message); } finally { this.Response.Clear(); // 回覆成功訊息。 if (enErrors.Count() == 0) { this.Response.Write("1|OK"); } // 回覆錯誤訊息。 else { this.Response.Write(String.Format("0|{0}", String.Join("\\r\\n", enErrors))); } this.Response.Flush(); this.Response.End(); } }
public COrderDetail(tOrderDetail o) { _orderDetail = o; }
public static result sendOrder(string name, string phone, string email, string countryid, string districtid, string add, string paymenttype, string note, string cname, string dname, string discountid, string p_name, string p_phone, string p_email, string p_add, string p_country, string p_countryname, string p_district, string p_districtname) { var r = new result(); try { ShoppingCart cart = (ShoppingCart)HttpContext.Current.Session["Cart"]; if (cart.Rows.Count > 0) { CNManagerDataContext db = new CNManagerDataContext(); var o = new tOrder(); var top = (from k in db.tOrders orderby k.Id descending select new { k.Id }).Skip(0).Take(1); int stt = 0; if (top.Count() > 0) { stt = top.FirstOrDefault().Id; } var _code = "CODE" + DateTime.Now.ToString("ddMMyy") + (stt + 1).ToString("D3"); o.OrderCode = _code; string userId = ""; if (!string.IsNullOrEmpty(Convert.ToString(HttpContext.Current.Session["cn_mb_user_id"]))) { userId = HttpContext.Current.Session["cn_mb_user_id"].ToString(); } if (userId != "") { o.MemberId = int.Parse(userId); } HttpCookie ck_ref = HttpContext.Current.Request.Cookies["cn_ref"]; if (ck_ref != null && ck_ref.Value != "") { if (userId != "") { if (ck_ref.Value != userId) { o.RefId = int.Parse(ck_ref.Value.Trim()); } } else { o.RefId = int.Parse(ck_ref.Value.Trim()); } } o.BranchTypeId = branchTypeId; o.CustomerName = name.Trim(); o.Phone = phone.Trim(); o.Email = email.Trim(); o.CountryId = int.Parse(countryid.Trim()); o.CountryName = cname.Trim(); o.DistrictId = int.Parse(districtid.Trim()); o.DistrictName = dname.Trim(); o.Address = add.Trim(); o.Note = note; o.Status = 1; if (discountid != "") { o.DiscountId = int.Parse(discountid.Trim()); } o.CreatedAt = DateTime.Now; o.ConfirmStatus = false; o.PaymentType = paymenttype == "1" ? true : false; o.PaymentAddress = p_add.Trim(); if (p_country.Trim() != "") { o.PaymentCountryId = int.Parse(p_country.Trim()); } o.PaymentCountryName = p_countryname.Trim(); if (p_district.Trim() != "") { o.PaymentDistrictId = int.Parse(p_district.Trim()); } o.PaymentDistrictName = p_districtname.Trim(); o.PaymentEmail = p_email.Trim(); o.PaymentName = p_name.Trim(); o.PaymentPhone = p_phone.Trim(); db.tOrders.InsertOnSubmit(o); db.SubmitChanges(); int orderId = o.Id; for (int k = 0; k < cart.Rows.Count; k++) { var p = new tOrderDetail(); p.OrderId = orderId; p.ProductId = int.Parse(cart.Rows[k]["ID"].ToString()); p.Price = double.Parse(cart.Rows[k]["Price"].ToString()); p.Quantity = int.Parse(cart.Rows[k]["Quantity"].ToString()); p.Score = byte.Parse(cart.Rows[k]["Score"].ToString()); p.IsSale = bool.Parse(cart.Rows[k]["IsSale"].ToString()); db.tOrderDetails.InsertOnSubmit(p); } db.SubmitChanges(); if (cart.Rows.Count > 0) { cart.Rows.Clear(); } r._mess = "Đặt hàng thành công, chúng tôi sẽ liên hệ với bạn trong thời gian sớm nhất"; r._content = "1"; //send mail order var em = db.sp_sendmail_order("C'Nice", _code, email.Trim()); } else { r._mess = "Không có sản phẩm nào trong giỏ hàng, hãy lựa chọn sản phẩm"; r._content = "0"; } } catch (Exception ax) { r._mess = "Có lỗi khi gửi đơn hàng của bạn, vui lòng thử gửi lại hoặc kiểm tra lại thông tin. [" + ax.Message + "]"; r._content = "0"; } return(r); }