Beispiel #1
0
        public void Init()
        {
            IRepository repo = new Repository();

            var list = repo.Query<OrderItem>(x => x.OrderID == ID)
                .FindAll(x => x.IsActive && Product.Cache.Load(x.ProductGuid) != null);

            if (list.Count > 0)
            {
                var oiBase = list.Find(x => Product.Cache.Load(x.ProductGuid).ProductType.Equals(ProductType.PlayerNumber));
                if (oiBase != null)
                {
                    var mapperPlayerNumber = new MapperConfiguration(cfg =>
                        cfg.CreateMap<OrderItem, OrdrItmPlayerNumber>().AfterMap((s, d) => d.Init()))
                        .CreateMapper();

                    OIPlayerNumber = mapperPlayerNumber.Map<OrdrItmPlayerNumber>(oiBase);
                }

                oiBase = list.Find(x => Product.Cache.Load(x.ProductGuid).ProductType.Equals(ProductType.PlayerName));
                if (oiBase != null)
                {
                    var mapperPlayerName = new MapperConfiguration(cfg =>
                        cfg.CreateMap<OrderItem, OrdrItmPlayerName>().AfterMap((s, d) => d.Init()))
                        .CreateMapper();

                    OIPlayerName = mapperPlayerName.Map<OrdrItmPlayerName>(oiBase);
                }

                if (OIPlayerNumber != null && OIPlayerName != null)
                {
                    UrlOrderView = "iArsenalOrderView_Printing.aspx";

                    oiBase = list.Find(x => Product.Cache.Load(x.ProductGuid).ProductType.Equals(ProductType.ArsenalFont));
                    if (oiBase != null)
                    {
                        var mapperArsenalFont = new MapperConfiguration(cfg =>
                            cfg.CreateMap<OrderItem, OrdrItmArsenalFont>().AfterMap((s, d) => d.Init()))
                            .CreateMapper();

                        OIArsenalFont = mapperArsenalFont.Map<OrdrItmArsenalFont>(oiBase);
                    }

                    oiBase = list.Find(x => Product.Cache.Load(x.ProductGuid).ProductType.Equals(ProductType.PremiershipPatch));
                    if (oiBase != null)
                    {
                        var mapperPremiershipPatch = new MapperConfiguration(cfg =>
                            cfg.CreateMap<OrderItem, OrdrItmPremiershipPatch>().AfterMap((s, d) => d.Init()))
                            .CreateMapper();

                        OIPremiershipPatch = mapperPremiershipPatch.Map<OrdrItmPremiershipPatch>(oiBase);
                    }

                    oiBase =
                        list.Find(
                            x => Product.Cache.Load(x.ProductGuid).ProductType.Equals(ProductType.ChampionshipPatch));
                    if (oiBase != null)
                    {
                        var mapperChampionshipPatch = new MapperConfiguration(cfg =>
                            cfg.CreateMap<OrderItem, OrdrItmChampionshipPatch>().AfterMap((s, d) => d.Init()))
                            .CreateMapper();

                        OIChampionshipPatch = mapperChampionshipPatch.Map<OrdrItmChampionshipPatch>(oiBase);
                    }
                }
                else
                {
                    throw new Exception("Unable to init Order_Printing.");
                }
            }

            #region Order Status Workflow Info

            var strWorkflow = "{{ \"StatusType\": \"{0}\", \"StatusInfo\": \"{1}\" }}";

            string[] workflowInfo =
            {
                string.Format(strWorkflow, ((int) OrderStatusType.Draft), "未提交"),
                string.Format(strWorkflow, ((int) OrderStatusType.Submitted), "后台审核"),
                string.Format(strWorkflow, ((int) OrderStatusType.Confirmed), "球衣收到"),
                string.Format(strWorkflow, ((int) OrderStatusType.Ordered), "打印中"),
                string.Format(strWorkflow, ((int) OrderStatusType.Delivered), "已发货")
            };

            StatusWorkflowInfo = workflowInfo;

            #endregion
        }
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            using (var conn = new SqlConnection(DataAccess.ConnectString))
            {
                conn.Open();
                var trans = conn.BeginTransaction();

                try
                {
                    if (string.IsNullOrEmpty(ddlReplicaKit.SelectedValue))
                    {
                        throw new Exception("请选择需要订购的球衣");
                    }

                    var m = _repo.Single<Member>(Mid);

                    if (!string.IsNullOrEmpty(tbMemberWeChat.Text.Trim()))
                    {
                        m.WeChat = tbMemberWeChat.Text.Trim();

                        _repo.Update(m);
                    }
                    else
                    {
                        throw new Exception("请输入会员微信号");
                    }

                    //New Order
                    var o = new Order();
                    int newId;

                    if (OrderID > 0)
                    {
                        o = _repo.Single<Order>(OrderID);
                    }

                    o.Mobile = tbOrderMobile.Text.Trim();
                    o.Address = tbOrderAddress.Text.Trim();

                    //if (rblOrderPayment.SelectedValue.Equals("Bank", StringComparison.OrdinalIgnoreCase))
                    //{
                    //    o.Payment = "{" + rblOrderPayment.SelectedValue + "|" + tbBankName.Text.Trim() + "|" +
                    //                tbBankAccount.Text.Trim() + "}";
                    //}
                    //else
                    //{
                    //    o.Payment = "{" + rblOrderPayment.SelectedValue + "|" + tbAlipay.Text.Trim() + "}";
                    //}

                    o.Payment = string.Empty;

                    o.Postage = Convert.ToSingle(rblOrderPostage.SelectedValue);
                    o.UpdateTime = DateTime.Now;
                    o.Description = tbOrderDescription.Text.Trim();
                    o.OrderType = OrderBaseType.ReplicaKit;

                    if (OrderID > 0)
                    {
                        _repo.Update(o, trans);

                        // used by setting OrderItem foreign key
                        newId = OrderID;
                    }
                    else
                    {
                        o.MemberID = m.ID;
                        o.MemberName = m.Name;

                        o.Price = 0;
                        o.Sale = null;
                        o.Deposit = null;
                        o.Status = OrderStatusType.Draft;
                        o.Rate = 0;
                        o.CreateTime = DateTime.Now;
                        o.IsActive = true;
                        o.Remark = string.Empty;

                        //Get the Order ID after Insert new one
                        object key;
                        _repo.Insert(o, out key, trans);
                        newId = Convert.ToInt32(key);
                    }

                    //Remove Order Item of this Order
                    if (OrderID > 0 && o.ID.Equals(OrderID))
                    {
                        _repo.Query<OrderItem>(x => x.OrderID == OrderID).Delete(trans);
                    }

                    //New Order Item for ReplicaKit
                    var pReplicaKit = Product.Cache.Load(new Guid(ddlReplicaKit.SelectedValue));

                    var oi = new OrdrItmReplicaKit();

                    if (pReplicaKit == null)
                        throw new Exception("无相关纪念品或缺货,请联系管理员");

                    // HARD CORD for HongKong Home Kit
                    //bool isHongKongKit = pReplicaKit.Code.Equals("M74756HK", StringComparison.OrdinalIgnoreCase);
                    //float salePrinting = 61f;

                    oi.OrderID = newId;
                    oi.Size = tbOrderItemSize.Text.Trim().ToUpper();
                    oi.Quantity = 1;
                    oi.Sale = null;
                    oi.Remark = string.Empty;

                    oi.Place(m, pReplicaKit, trans);

                    // New Order Item for Home Player Number & Name
                    if (!string.IsNullOrEmpty(ddlPlayerDetail.SelectedValue))
                    {
                        var pNumber = Product.Cache.Load(ProductType.PlayerNumber).Find(p => p.IsActive);
                        var pName = Product.Cache.Load(ProductType.PlayerName).Find(p => p.IsActive);

                        if (pNumber == null || pName == null)
                            throw new Exception("无印号信息,请联系管理员");

                        var oiFont = new OrdrItmArsenalFont();
                        var oiNumber = new OrdrItmPlayerNumber();
                        var oiName = new OrdrItmPlayerName();

                        oiFont.OrderID = newId;
                        oiFont.Size = string.Empty;
                        oiFont.Quantity = 1;
                        oiFont.Sale = null;
                        oiFont.Remark = string.Empty;

                        oiNumber.OrderID = newId;
                        oiNumber.Quantity = 1;

                        oiName.OrderID = newId;
                        oiName.Quantity = 1;

                        if (ddlPlayerDetail.SelectedValue.Equals("custom"))
                        {
                            // Custom Printing

                            if (string.IsNullOrEmpty(tbPlayerNumber.Text.Trim()) ||
                                string.IsNullOrEmpty(tbPlayerName.Text.Trim()))
                                throw new Exception("请填写自定义印字印号");

                            // New Order Item for Arsenal Font
                            if (cbArsenalFont.Checked)
                            {
                                var pFont = Product.Cache.Load(ProductType.ArsenalFont).Find(p => p.IsActive);

                                if (pFont == null)
                                    throw new Exception("无特殊字体信息,请联系管理员");

                                oiFont.Place(m, trans);

                                oiNumber.Size = tbPlayerNumber.Text.Trim();
                                oiNumber.Sale = 0f;
                                oiNumber.Remark = "custom";
                                oiNumber.Place(m, trans);

                                oiName.Size = tbPlayerName.Text.Trim();
                                oiName.Sale = 0f;
                                oiName.Remark = "custom";
                                oiName.Place(m, trans);
                            }
                            else
                            {
                                oiNumber.Size = tbPlayerNumber.Text.Trim();

                                //if (isHongKongKit)
                                //{ oiNumber.Sale = salePrinting; }
                                //else
                                //{ oiNumber.Sale = null; }
                                oiNumber.Sale = null;

                                oiNumber.Remark = "custom";
                                oiNumber.Place(m, trans);

                                oiName.Size = tbPlayerName.Text.Trim();

                                //if (isHongKongKit)
                                //{ oiName.Sale = salePrinting; }
                                //else
                                //{ oiName.Sale = null; }
                                oiName.Sale = null;

                                oiName.Remark = "custom";
                                oiName.Place(m, trans);
                            }
                        }
                        else
                        {
                            // Arsenal Player Printing
                            var player = Arsenal_Player.Cache.Load(new Guid(ddlPlayerDetail.SelectedValue));

                            if (player == null)
                                throw new Exception("无球员信息,请联系管理员");

                            var printingName = GetArsenalPlayerPrintingName(player);

                            // New Order Item for Arsenal Font
                            if (cbArsenalFont.Checked)
                            {
                                var pFont = Product.Cache.Load(ProductType.ArsenalFont).Find(p => p.IsActive);

                                if (pFont == null)
                                    throw new Exception("无特殊字体信息,请联系管理员");

                                oiFont.Place(m, trans);

                                oiNumber.Size = player.SquadNumber.ToString();
                                oiNumber.Sale = 0f;
                                oiNumber.Remark = player.ID.ToString();
                                oiNumber.Place(m, trans);

                                oiName.Size = printingName;
                                oiName.Sale = 0f;
                                oiName.Remark = player.ID.ToString();
                                oiName.Place(m, trans);
                            }
                            else
                            {
                                oiNumber.Size = player.SquadNumber.ToString();

                                //if (isHongKongKit)
                                //{ oiNumber.Sale = salePrinting; }
                                //else
                                //{ oiNumber.Sale = null; }
                                oiNumber.Sale = null;

                                oiNumber.Remark = player.ID.ToString();
                                oiNumber.Place(m, trans);

                                oiName.Size = printingName;

                                //if (isHongKongKit)
                                //{ oiName.Sale = salePrinting; }
                                //else
                                //{ oiName.Sale = null; }
                                oiName.Sale = null;

                                oiName.Remark = player.ID.ToString();
                                oiName.Place(m, trans);
                            }
                        }
                    }

                    // HARD CODE FOR HongKong Home Kit
                    //if (!isHongKongKit)
                    //{

                    // New Order Item for Premiership Patch
                    if (Convert.ToInt32(rblPremierPatch.SelectedValue) > 0)
                    {
                        var pPremierPatch = Product.Cache.Load(ProductType.PremiershipPatch).Find(p => p.IsActive);

                        if (pPremierPatch == null)
                            throw new Exception("无英超袖标信息,请联系管理员");

                        var oiPremierPatch = new OrdrItmPremiershipPatch
                        {
                            OrderID = newId,
                            Size = string.Empty,
                            Quantity = Convert.ToInt32(rblPremierPatch.SelectedValue),
                            Sale = null,
                            Remark = string.Empty
                        };

                        oiPremierPatch.Place(m, trans);
                    }

                    // New Order Item for Championship Patch
                    if (Convert.ToInt32(rblChampionPatch.SelectedValue) > 0)
                    {
                        var pChampionPatch = Product.Cache.Load(ProductType.ChampionshipPatch).Find(p => p.IsActive);

                        if (pChampionPatch == null)
                            throw new Exception("无欧冠袖标信息,请联系管理员");

                        var oiChampionShipPatch = new OrdrItmChampionshipPatch
                        {
                            OrderID = newId,
                            Size = string.Empty,
                            Quantity = Convert.ToInt32(rblChampionPatch.SelectedValue),
                            Sale = null,
                            Remark = string.Empty
                        };

                        oiChampionShipPatch.Place(m, trans);
                    }

                    //}

                    trans.Commit();

                    ClientScript.RegisterClientScriptBlock(typeof(string), "succeed",
                        string.Format("alert('订单({0})保存成功');window.location.href = 'ServerOrderView.ashx?OrderID={0}'",
                            newId), true);
                }
                catch (Exception ex)
                {
                    trans.Rollback();

                    ClientScript.RegisterClientScriptBlock(typeof(string), "failed", $"alert('{ex.Message}')", true);
                }

                //conn.Close();
            }
        }