public bool UpdateStatusOrder(OuikumOrderDetail orDetial)
        {
            using (var trans = new TransactionScope())
            {
                string sqlUpdate = "StatusProduct = '" + orDetial.StatusProduct + "'";
                string sqlWhere  = "OrDetailID = " + orDetial.OrDetailID + " AND ProductID = " + orDetial.ProductID;
                UpdateByCondition <OuikumOrderDetail>(sqlUpdate, sqlWhere);

                trans.Complete();
                IsResult = true;
            }
            return(IsResult);
        }
        public ActionResult SaveStatus(string OrDetailCode, string StatusProduct)
        {
            OuikumOrderDetail orDetial = new OuikumOrderDetail();
            var    svOrderPur          = new OrderPurchaseService();
            var    svOrderStauts       = new OrderStatusService();
            string SQLWhere            = string.Empty;

            try
            {
                var GetorderDetail = svOrderPur.SelectData <View_OuikumOrderDetailSC>("OrDetailID,OrDetailcode,ProductID,ProductName,StatusProduct", "IsDelete = 0 AND OrDetailCode = '" + OrDetailCode + "'").First();
                SQLWhere = svOrderStauts.CreateWhereAction(OrderStatusAction.ConfirmBySC, LogonCompID);
                var Status = svOrderPur.SelectData <OuikumStausOrder>("NameStatus", SQLWhere, "NameStatus", 1, 0);

                orDetial.OrDetailID = GetorderDetail.OrDetailID;
                if (GetorderDetail.StatusProduct == "A")
                {
                    orDetial.StatusProduct = "B";
                }
                else if (GetorderDetail.StatusProduct == "B")
                {
                    orDetial.StatusProduct = "C";
                }
                else
                {
                    orDetial.StatusProduct = "D";
                }
                orDetial.ProductID    = GetorderDetail.ProductID;
                orDetial.ModifiedDate = DateTime.Now;

                #region Update Satatus OrderDetail

                svOrderPur.UpdateStatusOrder(orDetial);
                #endregion
            }
            catch (Exception ex)
            {
                return(Json(new { IsSuccess = false }));
            }

            return(Json(new { IsSuccess = true }));
        }
        public ActionResult AddOrderProduct(FormCollection form)
        {
            OuikumOrder       tOrder       = new OuikumOrder();
            OuikumOrderDetail tOrderDetail = new OuikumOrderDetail();
            var svCart     = new CartService();
            var svShipment = new ShipmentService();

            #region set Order
            tOrder.SendName    = form["SendName"];
            tOrder.SendSername = form["SendSername"];
            tOrder.SendTel     = form["SendTel"];
            tOrder.Email       = form["Email"];

            if (form["AddrLine1"] != null)
            {
                tOrder.AddrLine1 = form["AddrLine1"];
            }

            if (form["AddrLine2"] != null)
            {
                tOrder.AddrLine2 = form["AddrLine2"];
            }

            tOrder.SubDirtrict  = form["SubDirtrict"];
            tOrder.DirtrictID   = Convert.ToInt32(form["DirtrictID"]);
            tOrder.ProviceID    = Convert.ToInt32(form["ProviceID"]);
            tOrder.Postal       = form["Postal"];
            tOrder.CompID       = LogonCompID;
            tOrder.OrderStatus  = "A";
            tOrder.Total        = Convert.ToDecimal(form["Total"]);
            tOrder.RowFlag      = 1;
            tOrder.RowVersion   = 1;
            tOrder.IsDelete     = false;
            tOrder.IsShow       = true;
            tOrder.OrderDate    = DateTime.Now;
            tOrder.CreatedDate  = DateTime.Now;
            tOrder.ModifiedDate = DateTime.Now;
            tOrder.CreatedBy    = Convert.ToString(LogonCompID);
            tOrder.ModifiedBy   = Convert.ToString(LogonCompID);
            #endregion

            var getTempCart     = svCart.SelectData <View_TempCart>("*", "IsDelete = 0 and TempIDLogon = " + LogonCompID);
            var OrderNumber     = 1;
            var TempOrderDetail = new List <OuikumOrderDetail>();
            var ShipmentProduct = svShipment.SelectData <View_ShipmentProduct>("*", "IsDelete = 0 and TempIDLogon = " + LogonCompID);
            ViewBag.ShipmentProduct = ShipmentProduct;

            if (getTempCart.Count > 0)
            {
                for (int i = 0; i <= getTempCart.Count - 1; i++)
                {
                    decimal?TotalPriceProduct = 0;
                    #region set OrderDetail
                    var detail = new OuikumOrderDetail();
                    detail.ProductID = getTempCart[i].TempProdcutID;
                    detail.CompSCID  = getTempCart[i].CompID;
                    detail.Qty       = getTempCart[i].TempCountProduct;
                    detail.Qty_Price = getTempCart[i].TempPrice;

                    foreach (var getShipmentPrice in (List <View_ShipmentProduct>)ViewBag.ShipmentProduct)
                    {
                        if (getShipmentPrice.CompID == getTempCart[i].CompID && getShipmentPrice.ProductID == getTempCart[i].TempProdcutID)
                        {
                            if (getTempCart[i].TempCountProduct <= getShipmentPrice.BuyMaximum && getTempCart[i].TempCountProduct >= getShipmentPrice.BuyMinimum)
                            {
                                detail.PriceShipment = getShipmentPrice.PriceShipment;
                                TotalPriceProduct    = getShipmentPrice.PriceShipment;
                            }
                        }
                    }

                    var SumPriceUnit1 = getTempCart[i].TempCountProduct * getTempCart[i].TempPrice;
                    detail.TotalPriceproduct = SumPriceUnit1;
                    detail.TotalSum          = SumPriceUnit1 + TotalPriceProduct;
                    detail.StatusProduct     = "A";
                    detail.OrDetailCode      = AutoGenCode("Or-D", OrderNumber);
                    detail.IsShow            = true;
                    detail.IsDelete          = false;
                    detail.RowFlag           = 1;
                    detail.RowVersion        = 1;
                    detail.CreatedDate       = DateTime.Now;
                    detail.ModifiedDate      = DateTime.Now;
                    detail.CreatedBy         = Convert.ToString(LogonCompID);
                    detail.ModifiedBy        = Convert.ToString(LogonCompID);
                    OrderNumber++;
                    TempOrderDetail.Add(detail);
                    TotalPriceProduct = 0;
                    #endregion
                }

                #region Insert b2bOrder
                svCart.InsertOrder(tOrder, TempOrderDetail);
                #endregion
            }
            UpdateTempCart();

            if (svCart.IsResult)
            {
                var compBuyer = svCompany.SelectData <View_getSendmailOrder>("Email, namebuyer , CompID ,OrderID", " OrderID = " + tOrder.OrderID, null).First();

                if (!SendEmailOrdertoBuyer(compBuyer.namebuyer, compBuyer.Email, compBuyer.OrderID))
                {
                    return(Json(new { IsSuccess = false, Result = res.EmaiOrderToBuyer.lblresulttobuyerfalse }));
                }
                else
                {
                    //return Json(new { IsSuccess = true, Result = res.EmaiOrderToBuyer.lblresulttobuyer });
                    var compSeller = svCompany.SelectDataEmailtoSeller <view_getMailOrdertoSeller>(" emailseller, OrderID, compidseller ", " OrderID = " + tOrder.OrderID);
                    var Mailseller = new List <view_getMailOrdertoSeller>();
                    if (compSeller.Count > 0)
                    {
                        for (int a = 0; a <= compSeller.Count - 1; a++)
                        {
                            var email = new view_getMailOrdertoSeller();
                            email.emailseller  = compSeller[a].emailseller;
                            email.OrderID      = compSeller[a].OrderID;
                            email.compidseller = compSeller[a].compidseller;
                            Mailseller.Add(email);
                        }
                        if (!SendEmailOrdertoSeller(Mailseller, tOrder.OrderID))
                        {
                            return(Json(new { IsSuccess = false, Result = res.EmaiOrderToBuyer.lblresulttobuyerfalse }));
                        }
                        else
                        {
                            return(Json(new { IsSuccess = true, Result = res.EmaiOrderToBuyer.lblresulttobuyer }));
                        }
                    }
                }
            }


            return(Json(new { IsSuccess = true, Result = "บันทึกรายการสั่งซื้อของคุณเรียบร้อยแล้ว" }));

            // return svCart.IsResult;
        }