Example #1
0
        public ActionResult Checkout()
        {
            cvmOrder models = new cvmOrder()
            {
                receive_name    = "",
                receive_memail  = "",
                receive_address = "",
                payment_no      = "01",
                remark          = "",
                PaymentsList    = db.payments.OrderBy(m => m.payment_no).ToList(),
            };

            return(View(models));
        }
Example #2
0
        private static string CreateNewOrderNo(cvmOrder model)
        {
            Shop.OrderID = 0;
            Shop.OrderNo = "0";
            string str_order_no = "";
            string str_guid     = Guid.NewGuid().ToString().Substring(0, 25).ToUpper();

            using (dbcon db = new dbcon())
            {
                order order = new order();
                order.order_closed    = 0;
                order.order_validate  = 0;
                order.order_no        = "";
                order.order_date      = DateTime.Now;
                order.mno             = UserAccount.UserNo;
                order.order_status    = "ON";
                order.order_guid      = str_guid;
                order.payment_no      = model.payment_no;
                order.payment_name    = Shop.GetPaymentName(model.payment_no);
                order.receive_name    = model.receive_name;
                order.receive_phone   = model.receive_phone;
                order.receive_email   = model.receive_memail;
                order.receive_address = model.receive_address;
                order.remark          = model.remark;
                db.order.Add(order);
                db.SaveChanges();


                //此時order_no還沒編號,待寫入guid後,再拿出來對比,使用rowid進行 +0 取8位 得出 str_order_no
                var neword = db.order.Where(m => m.order_guid == str_guid).FirstOrDefault();
                if (neword != null)
                {
                    str_order_no    = neword.rowid.ToString().PadLeft(8, '0');
                    neword.order_no = str_order_no;
                    Shop.OrderID    = neword.rowid;
                    Shop.OrderNo    = str_order_no;
                    db.SaveChanges();
                }
            }
            return(str_order_no);
        }
Example #3
0
        public ActionResult Checkout(cvmOrder model)
        {
            if (!ModelState.IsValid)
            {
                if (model.PaymentsList == null)
                {
                    model.PaymentsList = db.payments.OrderBy(m => m.payment_no).ToList();
                }
                return(View(model));
            }

            if (!Cart.CartPayment(model))
            {
                TempData["message"] = "營位不足, 請再次確認.";
                if (model.PaymentsList == null)
                {
                    model.PaymentsList = db.payments.OrderBy(m => m.payment_no).ToList();
                }
                return(View(model));
            }

            return(Redirect("~/ECPayment.aspx"));
        }
Example #4
0
        public static bool CartPayment(cvmOrder model)
        {
            OrderNo = CreateNewOrderNo(model);
            using (dbcon db = new dbcon())
            {
                var datas = db.carts
                            .Where(m => m.mno == UserAccount.UserNo)
                            .ToList();
                if (datas != null)
                {
                    //將同會員購買的所有品項加總 為什麼不用CartTotal??
                    int int_amount = datas.Sum(m => m.amount).GetValueOrDefault();
                    //加上稅金
                    decimal dec_tax = 0;
                    if (int_amount > 0)
                    {
                        dec_tax = Math.Round((decimal)(int_amount * 5 / 100), 0);
                    }
                    int int_total = int_amount + (int)dec_tax;
                    var data      = db.order.Where(m => m.order_no == OrderNo).FirstOrDefault();
                    if (data != null)
                    {
                        data.amounts = int_amount;
                        data.taxs    = (int)dec_tax;
                        data.totals  = int_total;
                    }

                    foreach (var item in datas)
                    {
                        var stock_date_list = item.ptype_spec.Trim().Split(' ').ToList();
                        stock_date_list.RemoveAt(stock_date_list.Count - 1);
                        foreach (var d in stock_date_list)
                        {
                            DateTime date     = Convert.ToDateTime(d);
                            var      hasStock = db.product_typedetail_everydaystock.Count(e => e.ptype_no == item.ptype_no && e.stock_date == date && e.stock >= item.ptype_qty) > 0;
                            if (!hasStock)
                            {
                                return(false);
                            }
                        }
                        order_detail detail = new order_detail();
                        detail.order_no      = OrderNo;
                        detail.pno           = item.pno;
                        detail.pname         = item.pname;
                        detail.ptype_no      = item.ptype_no;
                        detail.ptype_name    = item.ptype_name;
                        detail.vendor_no     = Shop.GetVendorNoByProduct(item.pno);
                        detail.category_name = Shop.GetCategoryName(item.pno);
                        detail.ptype_spec    = item.ptype_spec;
                        detail.qty           = item.ptype_qty;
                        detail.price         = item.ptype_price;
                        detail.amount        = item.amount;
                        detail.remark        = "";
                        db.order_detail.Add(detail);

                        db.carts.Remove(item);
                    }
                    db.SaveChanges();
                }
            }
            return(true);
        }