Beispiel #1
0
        /// <summary>
        /// 编辑信息
        /// </summary>
        public string EditApiOrder()
        {
            int           roleId  = helpcommon.ParmPerportys.GetNumParms(userInfo.User.personaId);
            int           menuId  = helpcommon.ParmPerportys.GetNumParms(Request.Form["menuId"].ToString());
            string        OrderId = Request.Form["OrderId"].ToString();
            StringBuilder s       = new StringBuilder();

            bll.apiorderbll      apiorderBll = new bll.apiorderbll();
            PublicHelpController ph          = new PublicHelpController();
            DataTable            dt          = apiorderBll.getOrderDetailsMsg(OrderId);

            string[] ssName       = apiorderBll.getDataName("apiOrderDetails");
            string[] ssNameParent = apiorderBll.getDataName("apiOrder"); //主菜单显示字段
            string[] ss           = ph.getFiledPermisson(roleId, menuId, funName.selectChildOrder);
            if (dt != null)
            {
                #region 表头
                s.Append("<tr>");
                for (int z = 0; z < ssName.Length; z++)
                {
                    if (ss.Contains(ssName[z]))
                    {
                        s.Append("<th>");
                        if (ssName[z] == "detailsOrderId")
                        {
                            s.Append("子订单ID");
                        }
                        if (ssName[z] == "detailsScode")
                        {
                            s.Append("商品货号");
                        }
                        if (ssName[z] == "detailsColor")
                        {
                            s.Append("颜色");
                        }
                        if (ssName[z] == "detailsImg")
                        {
                            s.Append("图片");
                        }
                        if (ssName[z] == "detailsItemPrice")
                        {
                            s.Append("商品售价");
                        }
                        if (ssName[z] == "detailsTaxPrice")
                        {
                            s.Append("税费金额");
                        }
                        if (ssName[z] == "detailsSaleCount")
                        {
                            s.Append("销售数量");
                        }
                        if (ssName[z] == "detailsDeliveryPrice")
                        {
                            s.Append("快递费用");
                        }
                        if (ssName[z] == "detailsStatus")
                        {
                            s.Append("详情状态");
                        }
                        if (ssName[z] == "detailsTime")
                        {
                            s.Append("下单时间");
                        }
                        if (ssName[z] == "detailsPayTime")
                        {
                            s.Append("付款时间");
                        }
                        if (ssName[z] == "detailsEditTime")
                        {
                            s.Append("编辑时间");
                        }
                        if (ssName[z] == "detailsSendTime")
                        {
                            s.Append("发货时间");
                        }
                        if (ssName[z] == "detailsSucessTime")
                        {
                            s.Append("结束时间");
                        }
                        if (ssName[z] == "detailsSplit")
                        {
                            s.Append("分配状态");
                        }
                        if (ssName[z] == "Def1")
                        {
                            s.Append("默认1");
                        }
                        if (ssName[z] == "Def2")
                        {
                            s.Append("默认2");
                        }
                        if (ssName[z] == "Def3")
                        {
                            s.Append("默认3");
                        }
                        if (ssName[z] == "Def4")
                        {
                            s.Append("默认4");
                        }
                        if (ssName[z] == "Def5")
                        {
                            s.Append("默认5");
                        }

                        s.Append("</th>");
                    }
                }
                s.Append("</tr>");
                #endregion

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    s.Append("<tr>");
                    for (int j = 0; j < ss.Length; j++)
                    {
                        if (ss[j].ToLower() == "id")
                        {
                            s.Append("<td>");
                            s.Append("<label id='lblId'>" + dt.Rows[i][ss[j]].ToString() + "</label>");
                            s.Append("</td>");
                        }
                        else if (ss[j].ToLower().Contains("price"))
                        {
                            s.Append("<td>");
                            s.Append("<label>" + Convert.ToDecimal(dt.Rows[i][ss[j]]).ToString("f2") + "</label>");
                            s.Append("</td>");
                        }
                        else if (ss[j].ToLower() == "detailsimg")
                        {
                            s.Append("<td>");
                            s.Append("<img src=\"" + dt.Rows[i][ss[j]].ToString() + "\" style='height:60px;' onerror='errorImg(this)'  />");
                            s.Append("</td>");
                        }
                        else
                        {
                            if (ss[j].ToLower() == "detailssplit" && (dt.Rows[i][ss[j]].ToString() == "1" || dt.Rows[i][ss[j]].ToString() == "0"))
                            {
                                if (dt.Rows[i][ss[j]].ToString() == "1")
                                {
                                    s.Append("<td class='orderSplitStates'>");
                                    s.Append("已分配");
                                    s.Append("</td>");
                                }
                                else
                                {
                                    s.Append("<td>");
                                    s.Append("未分配");
                                    s.Append("</td>");
                                }
                            }
                            else
                            {
                                s.Append("<td>");
                                s.Append(dt.Rows[i][ss[j]].ToString());
                                s.Append("</td>");
                            }
                        }
                    }
                    s.Append("</tr>");
                }
            }
            s.Append("-*-");
            DataTable dt1 = DbHelperSQL.Query(@"select * from apiOrderRemark a left join users b on a.UserId=b.Id where a.OrderId='" + OrderId + "'").Tables[0];
            if (dt1.Rows.Count > 0)
            {
                s.Append("<table class='mytable'>");
                s.Append("<tr><th style='width:125px'>操作时间</th><th>备注内容</th><th style='width:55px'>操作人</th>");
                if (ph.isFunPermisson(roleId, menuId, funName.updateName))
                {
                    s.Append("<th style='width:35px'>编辑</th>");
                }
                if (ph.isFunPermisson(roleId, menuId, funName.deleteName))
                {
                    s.Append("<th style='width:35px'>删除</th>");
                }
                s.Append("</tr>");
                for (int i = 0; i < dt1.Rows.Count; i++)
                {
                    s.Append("<tr><td>" + dt1.Rows[i]["Edittime"] + "</td><td class='tdRemark'>" + dt1.Rows[i]["Remark"] + "</td><td>" + dt1.Rows[i]["userRealName"] + "</td>");
                    if (ph.isFunPermisson(roleId, menuId, funName.updateName))
                    {
                        if (userInfo.User.Id.ToString() == dt1.Rows[i]["UserId"].ToString())
                        {
                            s.Append("<td class='EditRemark'><a href='#' title='" + dt1.Rows[i]["Id"] + "' >编辑</a></td>");
                        }
                        else
                        {
                            s.Append("<td></td>");
                        }
                    }
                    if (ph.isFunPermisson(roleId, menuId, funName.deleteName))
                    {
                        s.Append("<td><a href='#' onclick='DeleteRemark(\"" + dt1.Rows[i]["Id"] + "\")'>删除</a></td>");
                    }
                    s.Append("</tr>");
                }
                s.Append("</table>");
            }

            return(s.ToString());
        }
Beispiel #2
0
        /// <summary>
        /// 获取订单详情列表
        /// </summary>
        /// <returns></returns>
        public string getOrderDetails()
        {
            StringBuilder s       = new StringBuilder();
            string        orderId = Request.Form["orderId"].ToString();                                      //订单ID
            int           roleId  = helpcommon.ParmPerportys.GetNumParms(userInfo.User.personaId);           //角色
            int           menuId  = helpcommon.ParmPerportys.GetNumParms(Request.Form["menuId"].ToString()); //菜单

            try
            {
                bll.apiorderbll      apiorderBll  = new bll.apiorderbll();
                PublicHelpController ph           = new PublicHelpController();
                DataTable            dt           = apiorderBll.getOrderDetailsMsg(orderId);
                string[]             ssName       = apiorderBll.getDataName("apiOrderDetails");
                string[]             ssNameParent = apiorderBll.getDataName("apiOrder"); //主菜单显示字段
                string[]             ss           = ph.getFiledPermisson(roleId, menuId, funName.selectChildOrder);



                s.Append("<tr>");
                s.Append("<td colspan='" + ssNameParent.Length + 2 + "'>");
                s.Append("<table class='details' cellspacing='0' cellpadding='0'>");

                if (dt != null)
                {
                    #region 表头
                    s.Append("<tr>");
                    for (int z = 0; z < ssName.Length; z++)
                    {
                        if (ss.Contains(ssName[z]))
                        {
                            s.Append("<td>");
                            if (ssName[z] == "detailsOrderId")
                            {
                                s.Append("子订单编号");
                            }
                            if (ssName[z] == "detailsScode")
                            {
                                s.Append("商品货号");
                            }
                            if (ssName[z] == "detailsColor")
                            {
                                s.Append("颜色");
                            }
                            if (ssName[z] == "detailsImg")
                            {
                                s.Append("图片");
                            }
                            if (ssName[z] == "detailsItemPrice")
                            {
                                s.Append("成交价");
                            }
                            if (ssName[z] == "detailsTaxPrice")
                            {
                                s.Append("税金");
                            }
                            if (ssName[z] == "detailsSaleCount")
                            {
                                s.Append("数量");
                            }
                            if (ssName[z] == "detailsDeliveryPrice")
                            {
                                s.Append("快递费");
                            }
                            if (ssName[z] == "detailsStatus")
                            {
                                s.Append("订单状态");
                            }
                            if (ssName[z] == "detailsTime")
                            {
                                s.Append("下单时间");
                            }
                            if (ssName[z] == "detailsPayTime")
                            {
                                s.Append("付款时间");
                            }
                            if (ssName[z] == "detailsEditTime")
                            {
                                s.Append("编辑时间");
                            }
                            if (ssName[z] == "detailsSendTime")
                            {
                                s.Append("发货时间");
                            }
                            if (ssName[z] == "detailsSucessTime")
                            {
                                s.Append("结束时间");
                            }
                            if (ssName[z] == "detailsSplit")
                            {
                                s.Append("分配状态");
                            }
                            if (ssName[z] == "Def1")
                            {
                                s.Append("默认1");
                            }
                            if (ssName[z] == "Def2")
                            {
                                s.Append("默认2");
                            }
                            if (ssName[z] == "Def3")
                            {
                                s.Append("默认3");
                            }
                            if (ssName[z] == "Def4")
                            {
                                s.Append("默认4");
                            }
                            if (ssName[z] == "Def5")
                            {
                                s.Append("默认5");
                            }

                            s.Append("</td>");
                        }
                    }

                    //s.Append("<td>分配</td><td>编辑</td><td>删除</td>");
                    s.Append("</tr>");
                    #endregion

                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        //(订单当前状态:1为待确认,2为确认,3为待发货,4为发货,5交易成功,6通关异常,7,通关成功,11退货,12取消)
                        s.Append("<tr>");
                        for (int j = 0; j < ss.Length; j++)
                        {
                            if (ss[j].ToLower() == "id")
                            {
                                s.Append("<td>");
                                s.Append("<label id='lblId'>" + dt.Rows[i][ss[j]].ToString() + "</label>");
                                s.Append("</td>");
                            }
                            else if (ss[j].ToLower().Contains("price"))
                            {
                                s.Append("<td>");
                                s.Append("<label>" + Convert.ToDecimal(dt.Rows[i][ss[j]].ToString() == "" ? "0" : dt.Rows[i][ss[j]]).ToString("f2") + "</label>");
                                s.Append("</td>");
                            }
                            else if (ss[j].ToLower() == "detailsimg")
                            {
                                s.Append("<td>");
                                s.Append("<img src=\"" + dt.Rows[i][ss[j]].ToString() + "\" style='height:60px;' onerror='errorImg(this)'  />");
                                s.Append("</td>");
                            }
                            else
                            {
                                if (ss[j].ToLower() == "detailssplit" && (dt.Rows[i][ss[j]].ToString() == "1" || dt.Rows[i][ss[j]].ToString() == "0")) //订单分配
                                {
                                    if (dt.Rows[i][ss[j]].ToString() == "1")
                                    {
                                        s.Append("<td class='orderSplitStates'>");
                                        s.Append("已分配");
                                        s.Append("</td>");
                                    }
                                    else
                                    {
                                        s.Append("<td>");
                                        s.Append("未分配");
                                        s.Append("</td>");
                                    }
                                }
                                else if (ss[j].ToLower() == "detailsstatus") //订单详情
                                {
                                    #region 订单详情值
                                    s.Append("<td>");
                                    if (dt.Rows[i][ss[j]].ToString() == "1")
                                    {
                                        s.Append("待确认");
                                    }
                                    else if (dt.Rows[i][ss[j]].ToString() == "2")
                                    {
                                        s.Append("已确认");
                                    }
                                    else if (dt.Rows[i][ss[j]].ToString() == "3")
                                    {
                                        s.Append("待发货");
                                    }
                                    else if (dt.Rows[i][ss[j]].ToString() == "4")
                                    {
                                        s.Append("已发货");
                                    }
                                    else if (dt.Rows[i][ss[j]].ToString() == "5")
                                    {
                                        s.Append("交易成功");
                                    }
                                    else if (dt.Rows[i][ss[j]].ToString() == "6")
                                    {
                                        s.Append("通关异常");
                                    }
                                    else if (dt.Rows[i][ss[j]].ToString() == "7")
                                    {
                                        s.Append("通关成功");
                                    }
                                    else if (dt.Rows[i][ss[j]].ToString() == "11")
                                    {
                                        s.Append("退货");
                                    }
                                    else if (dt.Rows[i][ss[j]].ToString() == "12")
                                    {
                                        s.Append("取消");
                                    }
                                    s.Append("</td>");
                                    #endregion
                                }
                                else
                                {
                                    s.Append("<td>");
                                    s.Append(dt.Rows[i][ss[j]].ToString());
                                    s.Append("</td>");
                                }
                            }
                        }

                        s.Append("</tr>");
                    }
                }
            }
            catch (Exception ex) { return(ex.Message); }

            s.Append("</table>");
            s.Append("</td>");
            s.Append("</tr>");

            return(s.ToString());
        }
Beispiel #3
0
        /// <summary>
        /// 分配供应商
        /// </summary>
        /// <returns></returns>
        public string getSplitSingle()
        {
            //def2   是否已分配(0未分配,1分配)

            string s              = string.Empty;
            string splitResult    = string.Empty;                                                     //分配订单返回的结果
            string repeatOrderIds = string.Empty;                                                     //重复分配的订单(表示已分配成功的订单)
            //string noOrderIds = string.Empty;                                                         //禁止分配的订单(表示订单状态非待确认状态)
            OrderHelper oh = new OrderHelper();                                                       //订单类

            bll.apiorderbll apiorderBll = new bll.apiorderbll();
            List <string>   list        = new List <string>();                                        //接收订单编号(过滤空值)
            string          orderId     = Request.Form["orderId"] ?? string.Empty;                    //订单ID

            string[] orderIds = helpcommon.StrSplit.StrSplitData(orderId, ',');                       //分割订单ID,查看是否多个订单同时分配

            for (int i = 0; i < orderIds.Length; i++)
            {
                if (!string.IsNullOrWhiteSpace(orderIds[i]))
                {
                    list.Add(orderIds[i]);
                }
            }

            #region 过滤已分配完成的订单
            List <model.apiOrder> listApiOrder = apiorderBll.getOrderMsg(orderIds);                //根据主订单获取子订单商品

            for (int m = listApiOrder.Count - 1; m >= 0; m--)
            {
                if (listApiOrder[m].def2 == "1" || listApiOrder[m].orderStatus != 1)                //过滤已分配成功的订单(表示已分配成功的订单)和禁止分配的订单(表示订单状态非待确认状态)
                {
                    repeatOrderIds += listApiOrder[m].orderId + ",";
                    listApiOrder.RemoveAt(m);
                }
            }
            if (listApiOrder.Count <= 0)
            {
                return("订单(" + repeatOrderIds + ")不允许重复分配");
            }
            #endregion

            if (list.Count > 1)
            {
                #region 分配多个订单
                for (int m = 0; m < listApiOrder.Count; m++)
                {
                    DataTable dt = apiorderBll.getOrderDetailsMsg(listApiOrder[m].orderId);           //根据主订单获取子订单商品

                    if (dt != null)
                    {
                        string[] scode = new string[dt.Rows.Count];                                   //一个订单是否有多个商品(获取一个订单中有几个商品)
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            scode[i] = dt.Rows[i]["detailsScode"].ToString();                         //得到子订单中的商品货号
                        }
                        s += oh.getBalance(listApiOrder[m].orderId, scode) + "\r\n";
                    }
                }
                #endregion
            }
            else
            {
                #region 分配单个订单
                orderId = orderId.Trim(',');
                DataTable dt = apiorderBll.getOrderDetailsMsg(orderId);                               //根据主订单获取子订单商品

                if (dt != null)
                {
                    string[] scode = new string[dt.Rows.Count];                                       //一个订单是否有多个商品(获取一个订单中有几个商品)
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        scode[i] = dt.Rows[i]["detailsScode"].ToString();                             //得到子订单中的商品货号
                    }
                    s = oh.getBalance(orderId, scode);
                }
                #endregion
            }

            if (!string.IsNullOrWhiteSpace(repeatOrderIds))
            {
                s += "\r\n订单(" + repeatOrderIds + ")不允许重复分配";
            }

            apiorderBll = null;
            return(s);
        }
        /// <summary>
        /// 拆单,分配订单
        /// </summary>
        /// <param name="orderId">订单编号</param>
        /// <param name="scode">商品货号</param>
        /// <returns></returns>
        public string getBalance(string orderId, string[] scode)
        {
            string s           = string.Empty;
            string splitResult = string.Empty;                                     //分配订单返回的结果
            string sqlText     = string.Empty;
            string cancelOrder = string.Empty;                                     //取消订单返回结果

            bll.apiorderbll apiorderBll = new bll.apiorderbll();
            DataTable       dtTime      = apiorderBll.getOrderDetailsMsg(orderId); //获取原始订单时间

            for (int f = 0; f < scode.Length; f++)                                 //如果一个订单存在多个商品,根据订单ID和货号进行遍历分配供应商
            {
                DataTable dt  = new DataTable();                                   //返回当前货号所在订单中的商品购买数量
                DataTable dt1 = new DataTable();                                   //返回当前商品(scode)的供应商,价格,库存3个属性值集合

                string detailsOrderId     = string.Empty;                          //子订单ID
                string detailsColor       = string.Empty;                          //商品颜色
                string detailsImg         = string.Empty;                          //商品图片
                string detailsTime        = string.Empty;                          //订单插入时间
                string minusBanlaceResult = string.Empty;                          //销售库存减去本次销售数量结果(成功、失败)
                string orderScode         = scode[f].ToString();                   //当前商品的货号(scode)
                int    orderScodeNum      = 0;                                     //子订单商品购买数量
                int    totalBalance       = 0;                                     //当前商品(scode)的总库存(所有供应商的库存和)
                int    saleBalanceDef3    = 0;                                     //当前商品(scode)已售数量(销售字段Def3的值)

                #region 根据orderId,scode获取订单商品购买数量
                //商品购买数量
                if (!string.IsNullOrWhiteSpace(orderId) && !string.IsNullOrWhiteSpace(orderScode))
                {
                    dt             = apiorderBll.getOrderMsg(orderId, orderScode);                                                             //根据订单号和货号返回此scode货号所在订单中的商品数量。
                    orderScodeNum  = helpcommon.ParmPerportys.GetNumParms(dt.Rows[0]["detailsSaleCount"].ToString());                          //返回此scode货号所在订单中的商品数量。
                    detailsOrderId = dt.Rows[0]["detailsOrderId"].ToString();                                                                  //子订单ID
                    detailsColor   = dt.Rows[0]["detailsColor"].ToString();                                                                    //商品颜色
                    detailsImg     = dt.Rows[0]["detailsImg"].ToString();                                                                      //商品图片
                    detailsTime    = dtTime.Rows[0]["detailsTime"].ToString();                                                                 //订单插入时间
                }
                #endregion

                #region 当前货号的3个信息值:1.供应商,2.价格,3.库存(因product表中只存在总库存数量,所以应该去productstock表中查询这3个属性值)
                Dictionary <string, decimal> dicPrice = new Dictionary <string, decimal>();                                                    //存放库存数量,价格
                Dictionary <string, int>     dicLevel = new Dictionary <string, int>();                                                        //存放数据源NO,库存数量

                Dictionary <string, decimal> dicPrice1 = new Dictionary <string, decimal>();                                                   //存放库存数量,价格
                Dictionary <string, int>     dicLevel1 = new Dictionary <string, int>();                                                       //存放数据源NO,库存数量

                ProductStockBLL ProductStockBll = new ProductStockBLL();
                dt1 = ProductStockBll.getScodeBalance(orderScode, false);                                      //返回供应商,价格,库存(当前货号的3个信息值:1.供应商,2.价格,3.库存)


                for (int i = 0; i < dt1.Rows.Count; i++)
                {
                    totalBalance += helpcommon.ParmPerportys.GetNumParms(dt1.Rows[i]["balance"].ToString());   //当前商品(scode)的总库存(所有供应商的库存和)
                }

                var m = dt1.AsEnumerable().ToArray();                                                                                               //dt1转换为数组
                var p = (from c in m orderby c["vencode"].ToString(), c["balance"].ToString(), c["price"].ToString() descending select c).ToList(); //已按供应商,库存,价格排序
                saleBalanceDef3 = ProductStockBll.getScodeBalanceSales(orderScode);                                                                 //此scode已售数量
                #endregion

                #region 总库存<=已售数量-1
                if (totalBalance <= saleBalanceDef3 - 1)//总库存<=已售数量-1(因为在bms接收app订单的时候,product表中的def3销售字段就会加上相应的订单商品购买数量)
                {
                    string cancelMsg = "库存不足,系统自动取消,";
                    //update
                    string orderResult         = MD5DAL.AppAPIHelper.ChangeOrderStatus(orderId, 3);            //给app发送取消消息
                    helpcommon.appOrderMsg msg = helpcommon.ReSerialize.ReserializeMethod(orderResult);
                    if (msg != null)
                    {
                        if (msg.Code == "0")   //code:0表示取消订单成功
                        {
                            model.pbxdatasourceDataContext context = new model.pbxdatasourceDataContext();
                            context.Connection.Open();
                            context.Transaction = context.Connection.BeginTransaction();

                            bll.sourceorderbll sourceorderBll = new bll.sourceorderbll();
                            ProductBll         Productbll     = new ProductBll();
                            cancelOrder       += sourceorderBll.cancelOrder(orderId, context);                  //bms取消订单(修改相关数据表状态为12)
                            minusBanlaceResult = Productbll.minusBanlace(orderScode, orderScodeNum, context);   //减掉此次购买商品数量  helpcommon.ParmPerportys.GetNumParms(dt1.Rows[i]["balance"].ToString());

                            if (cancelOrder.Contains("成功") && minusBanlaceResult.Contains("成功"))
                            {
                                context.Transaction.Commit();
                            }
                            else
                            {
                                context.Transaction.Rollback();
                            }
                            sourceorderBll = null;
                            Productbll     = null;
                        }
                        else
                        {
                            cancelMsg += "(" + msg.Message + ")给app推送取消订单信息失败";
                        }
                    }
                    return(cancelMsg + orderResult);                                                            // "库存不足,请取消此订单";
                }
                #endregion

                #region 分配供应商(一个订单多件商品,可能会被拆分到几个供应商。这里指同款商品多个或多款商品多个)
                int restNum = orderScodeNum; //分配到几个供应商,依次分配后,还剩下多少需要分配
                int state   = 0;             //
                for (int i = 0; i < p.Count; i++)
                {
                    if (state > 0)
                    {
                        continue;
                    }

                    #region 检测是否存在分配成功却又取消分配的订单(需重新分配)
                    DataTable dtSendSource = new bll.sourceorderbll().getOrderSendData(orderId, orderScode);                                                                                        //根据订单ID在apisendorder源头表中检测是否存在分配成功却又取消分配的订单(需重新分配)
                    sqlText += @"update apiorderdetails set detailsEditTime='" + DateTime.Now.ToString("yyyy-MM-dd") + "'  where orderId='" + orderId + "' and detailsscode='" + orderScode + "';"; //子订单编辑修改的时间
                    #endregion

                    if (helpcommon.ParmPerportys.GetNumParms(p[i]["balance"].ToString()) >= orderScodeNum)          //判断哪些数据源中的商品库存量>客户所购商品数量(供应商的库存已倒序)
                    {
                        #region 某个供应商存在足够多的库存,直接分配完成
                        //如果是取消过的订单
                        //update  p[i]["vencode"].ToString()
                        //比较vencode,取    取消订单的供应商的下一个
                        //select * from apiSendOrder where orderId = dt.Rows[0]["orderId"].ToString()

                        if (dtSendSource.Rows.Count == 1)    //存在分配成功却又取消分配的订单(需重新分配)【分配成功却又取消分配的订单只处理分配到一个供应商的订单,多个供应商由人工分配】
                        {
                            #region 存在分配成功却又取消分配的订单(需重新分配),因为前面已分配过,所以无需新增,修改即可
                            if (p[i]["vencode"].ToString() == dtSendSource.Rows[0]["sendSource"].ToString())
                            {
                                if (i + 1 < p.Count)
                                {
                                    //根据订单号、货号更改订单数量,编辑时间,供应商
                                    sqlText += @"update apiSendOrder set  newSaleCount='" + orderScodeNum + "',editTime='" + DateTime.Now.ToString("yyyy-MM-dd") + "',sendSource = '" + p[i + 1]["vencode"].ToString() + "' where orderId='" + orderId + "' and newscode='" + orderScode + "';";
                                    state++;
                                }
                                else
                                {
                                    return("订单(" + orderId + ")无供应商可分配,请取消订单");
                                }
                            }
                            #endregion
                        }
                        else
                        {
                            #region  存在分配成功却又取消分配的订单(新增记录)
                            //否则insert
                            var sendOrderId = DateTime.Now.ToString("yyyyMMddHHmmss") + new Random().Next(1000, 9999).ToString();
                            sqlText += @"insert into apiSendOrder(orderId,detailsOrderId,newOrderId,newScode,newColor,newSize,newImg,newSaleCount,
newStatus,createTime,editTime,showStatus,sendSource) values('"
                                       + orderId + "','"
                                       + detailsOrderId + "','"
                                       + sendOrderId + "','"
                                       + orderScode + "','"
                                       + detailsColor + "','"
                                       + "','"
                                       + detailsImg + "',"
                                       + orderScodeNum + ","
                                       + 1 + ",'"  //新订单状态(订单当前状态:1为待确认,2为确认,3为待发货,4为发货,5交易成功,6通关异常,7,通关成功,11退货,12取消)
                                       + detailsTime + "','"
                                       + DateTime.Now.ToString("yyyy-MM-dd") + "',"
                                       + 0 + ",'" //审核开放(是否开放给供应商查看,0为未开放,1为开放)
                                       + p[i]["vencode"].ToString() + "');";
                            state++;
                            #endregion
                        }
                        #endregion
                    }
                    else
                    {
                        #region 一个供应商库存不足,需几个供应商加在一起

                        if (dtSendSource.Rows.Count > 1)    //存在分配成功却又取消分配的订单(需重新分配)
                        {
                            return("人工处理一个订单分配到几个供应商的订单");
                        }
                        else
                        {
                            sqlText += @"insert into apiSendOrder(orderId,detailsOrderId,newOrderId,newScode,newColor,newSize,newImg,newSaleCount,
newStatus,createTime,editTime,showStatus,sendSource) values('"
                                       + orderId + "','"
                                       + detailsOrderId + "','"
                                       + DateTime.Now.ToString("yyyyMMddHHmmss") + new Random().Next(1000, 9999) + "','"
                                       + orderScode + "','"
                                       + detailsColor + "','"
                                       + "','"
                                       + detailsImg + "',"
                                       + helpcommon.ParmPerportys.GetNumParms(p[i]["balance"].ToString()) + ","
                                       + 1 + ",'" //新订单状态(订单当前状态:1为待确认,2为确认,3为待发货,4为发货,5交易成功,6通关异常,7,通关成功,11退货,12取消)
                                       + detailsTime + "','"
                                       + DateTime.Now.ToString("yyyy-MM-dd") + "',"
                                       + 0 + ",'"//审核开放(是否开放给供应商查看,0为未开放,1为开放)
                                       + p[i]["vencode"].ToString() + "');";

                            if (helpcommon.ParmPerportys.GetNumParms(p[i]["balance"].ToString()) >= restNum)                            //当分配完成后
                            {
                                restNum = restNum - helpcommon.ParmPerportys.GetNumParms(p[i]["balance"].ToString());                   //剩余购买数量
                                state++;
                            }
                        }

                        #endregion
                    }
                }
                #endregion
            }

            SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["ConnectionString"].ToString());
            con.Open();
            SqlTransaction st      = con.BeginTransaction();
            SqlCommand     command = new SqlCommand();
            try
            {
                //def2   是否已分配(0未分配,1分配)
                sqlText += @"update apiorder set def2 = 1 where orderId='" + orderId + "';";

                IDataParameter[] ipara = new IDataParameter[] { new SqlParameter("@sqlText", SqlDbType.NVarChar, 4000) };
                ipara[0].Value     = sqlText;
                command.Connection = con;
                command.Parameters.AddRange(ipara);
                command.CommandType = CommandType.StoredProcedure;
                command.CommandText = "sendSource";
                command.Transaction = st;
                command.ExecuteNonQuery();

                st.Commit();
                splitResult = "订单(" + orderId + ")分配成功";
            }
            catch (Exception ex) { st.Rollback(); splitResult = "分配失败,程序错误" + ex.Message + sqlText; }

            return(splitResult);
        }