Ejemplo n.º 1
0
        private void InItOperateResult(List <IOperationResult> results, string successError, string fatalError)
        {
            OperateResult result2;

            foreach (IOperationResult result in results)
            {
                if (!result.IsSuccess)
                {
                    string strMessage = fatalError + "失败原因:";

                    if (result.ValidationErrors.Count == 0)
                    {
                        if (result.OperateResult != null && result.OperateResult.Count > 0)
                        {
                            OperateResultCollection operateResultCollection = result.OperateResult;
                            strMessage = operateResultCollection.Aggregate(strMessage, (current, operateResult) => current + (operateResult.Message + " "));
                        }
                        else
                        {
                            IInteractionResult interresult = result as IInteractionResult;
                            if (interresult.InteractionContext != null)
                            {
                                if (interresult.InteractionContext.SimpleMessage != null)
                                {
                                    strMessage = strMessage + (interresult.InteractionContext.SimpleMessage + " ");
                                }
                            }
                        }
                    }
                    else
                    {
                        strMessage = result.ValidationErrors.Aggregate(strMessage, (current, vr) => current + (vr.Message + " "));
                    }
                    throw new Exception(strMessage);
                }
                if (result.SuccessDataEnity == null)
                {
                    return;
                }
                foreach (var dyhead in result.SuccessDataEnity)
                {
                    result2 = new OperateResult
                    {
                        SuccessStatus = true,
                        Message       = successError + ":" + dyhead["BillNo"],
                        MessageType   = MessageType.Normal,
                        Name          = successError,
                        PKValue       = dyhead["FFormId"]
                    };
                    base.OperationResult.OperateResult.Add(result2);
                }
            }
            base.OperationResult.IsShowMessage = true;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 校验操作
        /// </summary>
        /// <param name="result"></param>
        private bool CheckResult(IOperationResult result, out string mssg)
        {
            if (!result.IsSuccess)
            {
                mssg = "";
                foreach (var item in result.ValidationErrors)
                {
                    mssg = mssg + item.Message;
                }
                if (!result.InteractionContext.IsNullOrEmpty())
                {
                    mssg = mssg + result.InteractionContext.SimpleMessage;
                }

                return(false);
            }
            else
            {
                OperateResultCollection operateResults = result.OperateResult;
                string fnmber = operateResults[0].Number;
                mssg = "生成收款单单号:" + fnmber;
                return(true);
            }
        }
Ejemplo n.º 3
0
        public static IOperationResult DoAction(Context context, string[] selPKArray, Enum_OPPAction action)
        {
            IOperationResult            operationResult         = new OperationResult();
            OperateResultCollection     operateResultCollection = new OperateResultCollection();
            Dictionary <string, string> dictionary = new Dictionary <string, string>();
            List <DynamicObject>        list       = new List <DynamicObject>();
            FormMetadata formMetadata = (FormMetadata)MetaDataServiceHelper.Load(context, "CRM_OPP_Opportunity", true);
            BusinessInfo businessInfo = formMetadata.BusinessInfo;

            DynamicObject[] array = BusinessDataServiceHelper.Load(context, selPKArray, businessInfo.GetDynamicObjectType());
            if (array == null || array.Length == 0)
            {
                operateResultCollection.Add(OpportunityCommon.CreateOperateResult(false, ResManager.LoadKDString("未找到对应的数据,可能已被删除!", "006008030001276", SubSystemType.CRM, new object[0])));
                operationResult.OperateResult = operateResultCollection;
                return(operationResult);
            }
            DynamicObject[] array2 = array;
            for (int i = 0; i < array2.Length; i++)
            {
                DynamicObject dynamicObject = array2[i];
                string        text          = CheckBeforeAction(dynamicObject, action);
                if (text != "")
                {
                    operateResultCollection.Add(OpportunityCommon.CreateOperateResult(false, text));
                    operationResult.OperateResult = operateResultCollection;
                }
                else
                {
                    if (action == Enum_OPPAction.WIN)
                    {
                        dynamicObject["FDocumentStatus"] = "E";
                    }
                    else
                    {
                        if (action == Enum_OPPAction.LOSE)
                        {
                            dynamicObject["FDocumentStatus"] = "F";
                        }
                        else
                        {
                            if (action == Enum_OPPAction.UNWIN || action == Enum_OPPAction.UNLOSE)
                            {
                                dynamicObject["FDocumentStatus"] = "G";
                            }
                        }
                    }
                    if (action == Enum_OPPAction.WIN || action == Enum_OPPAction.LOSE)
                    {
                        DynamicObjectCollection dynamicObjectCollection = dynamicObject["T_CRM_OppPhase"] as DynamicObjectCollection;
                        foreach (DynamicObject current in dynamicObjectCollection)
                        {
                            if (current["FIsCurrent"].ToString() == "True")
                            {
                                current["FEndtimeReal"] = DateTime.Now;
                                break;
                            }
                        }
                    }
                    dictionary.Add(dynamicObject["Id"].ToString(), dynamicObject["FOPPName"].ToString());
                    list.Add(dynamicObject);
                }
            }
            if (list.Count > 0)
            {
                IOperationResult operationResult2 = BusinessDataServiceHelper.Save(context, businessInfo, list.ToArray(), null, "");
                if (action == Enum_OPPAction.WIN || action == Enum_OPPAction.LOSE)
                {
                    Dictionary <string, string> dictionary2 = new Dictionary <string, string>();
                    string format = ResManager.LoadKDString("赢单商机【{0}】", "006008030001476", SubSystemType.CRM, new object[0]);
                    string text2  = "Win";
                    if (action == Enum_OPPAction.LOSE)
                    {
                        format = ResManager.LoadKDString("输单商机【{0}】", "006008030001477", SubSystemType.CRM, new object[0]);
                        text2  = "Lose";
                    }
                    foreach (OperateResult current2 in operationResult2.OperateResult)
                    {
                        if (current2.SuccessStatus)
                        {
                            dictionary2.Add(current2.PKValue.ToString(), string.Format(format, dictionary[current2.PKValue.ToString()]));
                        }
                    }
                    if (dictionary2.Count > 0)
                    {
                        ILatestInfoService latestInfoService = ServiceFactory.GetLatestInfoService(context);
                        latestInfoService.AddActionInfo(context, "CRM_OPP_Opportunity", text2, dictionary2);
                    }
                }
                if (operationResult.OperateResult.Count > 0)
                {
                    using (IEnumerator <OperateResult> enumerator3 = operationResult2.OperateResult.GetEnumerator())
                    {
                        while (enumerator3.MoveNext())
                        {
                            OperateResult current3 = enumerator3.Current;
                            operationResult.OperateResult.Add(current3);
                        }
                        return(operationResult);
                    }
                }
                operationResult.OperateResult = operationResult2.OperateResult;
            }
            return(operationResult);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 反审核并删除需要删除的销售订单
        /// </summary>
        /// <param name="pkids"></param>
        /// <param name="p"></param>
        /// <param name="ctx"></param>
        private void UnAuditBill(Context ctx, string p, string[] pkids)
        {
            //反审核服务
            FormMetadata  meta          = MetaDataServiceHelper.Load(ctx, p, true) as FormMetadata;
            OperateOption UnAuditOption = OperateOption.Create();
            var           UnAuditResult = BusinessDataServiceHelper.UnAudit(ctx, meta.BusinessInfo, pkids, UnAuditOption);

            if (UnAuditResult.IsSuccess)
            {
                //删除服务
                OperateOption deleteOption = OperateOption.Create();
                var           delectResult = BusinessDataServiceHelper.Delete(ctx, meta.BusinessInfo, pkids, deleteOption);
                //删除成功将成功信息及状态返回写中间表
                if (delectResult.IsSuccess)
                {
                    OperateResultCollection successResult = delectResult.OperateResult;
                    List <string>           succSql       = new List <string>();
                    foreach (OperateResult item in successResult)
                    {
                        if ("SAL_SaleOrder".Equals(p))
                        {
                            string strSql = string.Format(@"/*dialect*/UPDATE SALE_MAIN@ZyK3Link
                                                                              SET FFLAG = '3', FUPDATEDATE = '{0}', FERRORMESSAGE = '{1}'
                                                                              WHERE FSALBILLNO = '{2}'
                                                                             ", System.DateTime.Now.ToString(), item.Number.ToString() + "销售订单删除成功",
                                                          item.Number);
                            succSql.Add(strSql);
                        }
                        if ("ENG_BOM".Equals(p))
                        {
                            string strSql = string.Format(@"/*dialect*/UPDATE BOM_MAIN@ZyK3Link
                                                                             SET FFLAG = '3', FUPDATEDATE = '{0}', FERRORMESSAGE = '{1}'
                                                                             WHERE FSALBILLNO = '{2}'
                                                                           ", System.DateTime.Now.ToString(), item.Number.ToString() + "物料清单删除成功",
                                                          item.Number);
                            succSql.Add(strSql);
                        }
                        if ("BD_MATERIAL".Equals(p))
                        {
                            string strSql = string.Format(@"/*dialect*/UPDATE PRD_MAIN@ZyK3Link
                                                                              SET FFLAG = '3', FUPDATEDATE = '{0}', FERRORMESSAGE = '{1}'
                                                                              WHERE FSALBILLNO = '{2}'
                                                                            ", System.DateTime.Now.ToString(), item.Number.ToString() + "物料删除成功",
                                                          item.Number);
                            succSql.Add(strSql);
                        }
                    }
                    Kingdee.BOS.Log.Logger.Info(DateTime.Now.ToString() + "deleteSucc", succSql.ToString(), true);
                    DBUtils.ExecuteBatch(ctx, succSql, 100);
                }
                else
                {
                    //多条记录被删除,一部分删除成功,一部分删除失败,将成功和失败的信息及状态都返写回中间表
                    List <ValidationErrorInfo> errorDeleteList = new List <ValidationErrorInfo>();
                    errorDeleteList = delectResult.ValidationErrors;//删除失败记录返写中间表
                    if (errorDeleteList != null && errorDeleteList.Count() > 0)
                    {
                        List <string> errorSql = new List <string>();
                        for (int k = 0; k < errorDeleteList.Count(); k++)
                        {
                            if ("SAL_SaleOrder".Equals(p))
                            {
                                string strSql = string.Format(@"/*dialect*/UPDATE SALE_MAIN@ZyK3Link
                                                                              SET FFLAG = '2', FUPDATEDATE = '{0}', FERRORMESSAGE = '{1}'
                                                                              WHERE FSALBILLNO = (SELECT FBILLNO FROM T_SAL_ORDER WHERE FID = '{2}')
                                                                             ", System.DateTime.Now.ToString(), errorDeleteList[k].Message, errorDeleteList[k].BillPKID);
                                errorSql.Add(strSql);
                            }
                            if ("ENG_BOM".Equals(p))
                            {
                                string strSql = string.Format(@"/*dialect*/UPDATE BOM_MAIN@ZyK3Link
                                                                             SET FFLAG = '2', FUPDATEDATE = '{0}', FERRORMESSAGE = '{1}'
                                                                             WHERE FSALBILLNO = (SELECT FNUMBER FROM T_ENG_BOM WHERE FID = '{2}')
                                                                           ", System.DateTime.Now.ToString(), errorDeleteList[k].Message, errorDeleteList[k].BillPKID);
                                errorSql.Add(strSql);
                            }
                            if ("BD_MATERIAL".Equals(p))
                            {
                                string strSql = string.Format(@"/*dialect*/UPDATE PRD_MAIN@ZyK3Link
                                                                              SET FFLAG = '2', FUPDATEDATE = '{0}', FERRORMESSAGE = '{1}'
                                                                              WHERE FSALBILLNO = (SELECT FNUMBER FROM T_BD_MATERIAL WHERE FID = '{2}')
                                                                            ", System.DateTime.Now.ToString(), errorDeleteList[k].Message, errorDeleteList[k].BillPKID);
                                errorSql.Add(strSql);
                            }
                        }
                        Kingdee.BOS.Log.Logger.Error(DateTime.Now.ToString() + "deleteError", errorSql.ToString(), new Exception());
                        DBUtils.ExecuteBatch(ctx, errorSql, 100);
                    }
                    //删除成功记录返回写中间表
                    OperateResultCollection successResult = delectResult.OperateResult;
                    if (successResult != null && successResult.Count() > 0)
                    {
                        List <string> succSql = new List <string>();
                        foreach (OperateResult item in successResult)
                        {
                            if ("SAL_SaleOrder".Equals(p))
                            {
                                string strSql = string.Format(@"/*dialect*/UPDATE SALE_MAIN@ZyK3Link
                                                                              SET FFLAG = '3', FUPDATEDATE = '{0}', FERRORMESSAGE = '{1}'
                                                                              WHERE FSALBILLNO = '{2}'
                                                                             ", System.DateTime.Now.ToString(), item.Number.ToString() + "销售订单删除成功",
                                                              item.Number);
                                succSql.Add(strSql);
                            }
                            if ("ENG_BOM".Equals(p))
                            {
                                string strSql = string.Format(@"/*dialect*/UPDATE BOM_MAIN@ZyK3Link
                                                                             SET FFLAG = '3', FUPDATEDATE = '{0}', FERRORMESSAGE = '{1}'
                                                                             WHERE FSALBILLNO = '{2}'
                                                                           ", System.DateTime.Now.ToString(), item.Number.ToString() + "物料清单删除成功",
                                                              item.Number);
                                succSql.Add(strSql);
                            }
                            if ("BD_MATERIAL".Equals(p))
                            {
                                string strSql = string.Format(@"/*dialect*/UPDATE PRD_MAIN@ZyK3Link
                                                                              SET FFLAG = '3', FUPDATEDATE = '{0}', FERRORMESSAGE = '{1}'
                                                                              WHERE FSALBILLNO = '{2}'
                                                                            ", System.DateTime.Now.ToString(), item.Number.ToString() + "物料删除成功",
                                                              item.Number);
                                succSql.Add(strSql);
                            }
                            Kingdee.BOS.Log.Logger.Info(DateTime.Now.ToString() + "deleteSucc", succSql.ToString(), true);
                            DBUtils.ExecuteBatch(ctx, succSql, 100);
                        }
                    }
                }
            }
            else
            {
                //审核失败记录的信息及状态反写回中间表
                List <ValidationErrorInfo> errorUnAuditList = new List <ValidationErrorInfo>();
                errorUnAuditList = UnAuditResult.ValidationErrors;
                List <string> errorSql = new List <string>();
                for (int k = 0; k < errorUnAuditList.Count(); k++)
                {
                    if ("SAL_SaleOrder".Equals(p))
                    {
                        string strSql = string.Format(@"/*dialect*/UPDATE SALE_MAIN@ZyK3Link
                                                                          SET FFLAG = '2', FUPDATEDATE = '{0}', FERRORMESSAGE = '{1}'
                                                                          WHERE FSALBILLNO = (SELECT FBILLNO FROM T_SAL_ORDER WHERE FID = '{2}')
                                                                        ", System.DateTime.Now.ToString(), errorUnAuditList[k].Message, errorUnAuditList[k].BillPKID);
                        errorSql.Add(strSql);
                    }
                    if ("ENG_BOM".Equals(p))
                    {
                        string strSql = string.Format(@"/*dialect*/UPDATE BOM_MAIN@ZyK3Link
                                                                          SET FFLAG = '2', FUPDATEDATE = '{0}', FERRORMESSAGE = '{1}'
                                                                          WHERE FSALBILLNO = (SELECT FNUMBER FROM T_ENG_BOM WHERE FID = '{2}')
                                                                        ", System.DateTime.Now.ToString(), errorUnAuditList[k].Message, errorUnAuditList[k].BillPKID);
                        errorSql.Add(strSql);
                    }
                    if ("BD_MATERIAL".Equals(p))
                    {
                        string strSql = string.Format(@"/*dialect*/UPDATE PRD_MAIN@ZyK3Link
                                                                          SET FFLAG = '2', FUPDATEDATE = '{0}', FERRORMESSAGE = '{1}'
                                                                          WHERE FSALBILLNO = (SELECT FNUMBER FROM T_BD_MATERIAL WHERE FID = '{2}')
                                                                          ", System.DateTime.Now.ToString(), errorUnAuditList[k].Message, errorUnAuditList[k].BillPKID);
                        errorSql.Add(strSql);
                    }
                }
                Kingdee.BOS.Log.Logger.Error(DateTime.Now.ToString() + "UnAuditError", errorSql.ToString(), new Exception());
                DBUtils.ExecuteBatch(ctx, errorSql, 100);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 审核结束自动下推(应付单下推付款申请单)
        /// </summary>
        /// <param name="e"></param>
        public override void AfterExecuteOperationTransaction(AfterExecuteOperationTransaction e)
        {
            base.AfterExecuteOperationTransaction(e);
            try
            {
                string sql = string.Empty;
                if (e.DataEntitys != null && e.DataEntitys.Count <DynamicObject>() > 0)
                {
                    foreach (DynamicObject item in e.DataEntitys)
                    {
                        //收款单id
                        string Fid  = item["Id"].ToString();
                        string sql2 = "";
                        //收款单源单明细
                        DynamicObjectCollection RECEIVEBILLSRCENTRYList = item["RECEIVEBILLSRCENTRY"] as DynamicObjectCollection;
                        foreach (var entry in RECEIVEBILLSRCENTRYList)
                        {
                            //销售订单明细内码
                            string FORDERENTRYID = entry["FSRCORDERENTRYID"].ToString();
                            //本次收款金额
                            decimal FREALRECAMOUNT = Convert.ToDecimal(entry["REALRECAMOUNT"].ToString());
                            if (!string.IsNullOrEmpty(FORDERENTRYID))
                            {
                                //查询采购订单
                                sql = string.Format(@"select a.FBILLNO,b.FENTRYID as 采购订单明细内码 ,f.F_YBG_BUSINESSMODEL as 业务模式  from  t_PUR_POOrder a  
                                                       inner join   t_PUR_POOrderEntry b on a.fID=b.FID 
                                                       inner join T_PUR_POORDERENTRY_LK c on c.FENTRYID=b.FENTRYID 
                                                       left join T_SAL_ORDERENTRY d on d.FENTRYID=c.FSID
                                                       left  join T_SAL_ORDER f on f.FID=d.FID 
                                                       where  FSID='{0}'", FORDERENTRYID);
                                DataSet   ds = DBServiceHelper.ExecuteDataSet(this.Context, sql);
                                DataTable dt = ds.Tables[0];
                                if (dt.Rows.Count > 0)
                                {
                                    for (int i = 0; i < dt.Rows.Count; i++)
                                    {
                                        string F_YBG_BUSINESSMODEL = dt.Rows[i]["采购订单明细内码"].ToString();
                                        if (F_YBG_BUSINESSMODEL == "01" || F_YBG_BUSINESSMODEL == "04") //挂靠的采用自动生成付款申请单
                                        {
                                            string POFENTRYID = dt.Rows[i]["采购订单明细内码"].ToString();
                                            if (string.IsNullOrEmpty(sql2))
                                            {
                                                sql2 += "  FPAYABLEENTRYID='" + POFENTRYID + "' ";
                                            }
                                            else
                                            {
                                                sql2 += "  or  FPAYABLEENTRYID='" + POFENTRYID + "' ";
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        if (!string.IsNullOrEmpty(sql2))
                        {
                            #region  应付单下推付款申请单
                            string           srcFormId  = "AP_Payable";  //应付单
                            string           destFormId = "CN_PAYAPPLY"; //付款申请单
                            IMetaDataService mService   = Kingdee.BOS.App.ServiceHelper.GetService <IMetaDataService>();
                            IViewService     vService   = Kingdee.BOS.App.ServiceHelper.GetService <IViewService>();
                            FormMetadata     destmeta   = mService.Load(this.Context, destFormId) as FormMetadata;
                            //转换规则的唯一标识
                            string ruleKey = "AP_PayableToPayApply";
                            //var rules = ConvertServiceHelper.GetConvertRules(Context, srcFormId, destFormId);
                            //var rule = rules.FirstOrDefault(t => t.IsDefault);
                            ConvertRuleElement     rule    = GetDefaultConvertRule(Context, srcFormId, destFormId, ruleKey);
                            List <ListSelectedRow> lstRows = new List <ListSelectedRow>();
                            string  strsql = "select a.FID , a.FENTRYID  from T_AP_PAYABLEPLAN  a left join T_AP_PAYABLE b on a.FID=b.FID   where b.FDOCUMENTSTATUS='C' and  (" + sql2 + ") ";
                            DataSet ds2    = DBServiceHelper.ExecuteDataSet(Context, strsql);
                            if (ds2.Tables[0].Rows.Count > 0)
                            {
                                HashSet <string> hasset = new HashSet <string>();
                                for (int j = 0; j < ds2.Tables[0].Rows.Count; j++)
                                {
                                    hasset.Add(ds2.Tables[0].Rows[j]["FID"].ToString());
                                    long entryId = Convert.ToInt64(ds2.Tables[0].Rows[j]["FENTRYID"]);
                                    //源单单据标识
                                    ListSelectedRow row = new ListSelectedRow(ds2.Tables[0].Rows[j]["FID"].ToString(), entryId.ToString(), 0, "AP_Payable");
                                    //源单单据体标识
                                    row.EntryEntityKey = "FEntityPlan";
                                    lstRows.Add(row);
                                }

                                PushArgs        pargs      = new PushArgs(rule, lstRows.ToArray());
                                IConvertService cvtService = Kingdee.BOS.App.ServiceHelper.GetService <IConvertService>();
                                OperateOption   option     = OperateOption.Create();
                                option.SetIgnoreWarning(true);
                                option.SetVariableValue("ignoreTransaction", false);
                                option.SetIgnoreInteractionFlag(true);
                                #region 提交审核
                                //OperateOption option2 = OperateOption.Create();
                                //option2.SetIgnoreWarning(true);
                                //option2.SetVariableValue("ignoreTransaction", true);
                                //foreach (var hid in hasset)
                                //{
                                //    //如果应付单没有提交先提交审核
                                //    IMetaDataService BomService = Kingdee.BOS.App.ServiceHelper.GetService<IMetaDataService>();
                                //    //应付单元素包
                                //    FormMetadata APMeta = BomService.Load(Context, "AP_Payable") as FormMetadata;
                                //    IViewService APVService = Kingdee.BOS.App.ServiceHelper.GetService<IViewService>();
                                //    //应付单数据包
                                //    DynamicObject APmd = APVService.LoadSingle(Context, hid, APMeta.BusinessInfo.GetDynamicObjectType());

                                //    DynamicObject[] dy = new DynamicObject[] { APmd };

                                //    object[] items = dy.Select(p => p["Id"]).ToArray();

                                //    ISubmitService submitService = Kingdee.BOS.App.ServiceHelper.GetService<ISubmitService>();
                                //    IOperationResult submitresult = submitService.Submit(Context, APMeta.BusinessInfo, items, "Submit", option2);

                                //    IAuditService auditService = Kingdee.BOS.App.ServiceHelper.GetService<IAuditService>();
                                //    IOperationResult auditresult = auditService.Audit(Context, APMeta.BusinessInfo, items, option2);
                                //}
                                #endregion

                                ConvertOperationResult cvtResult = cvtService.Push(Context, pargs, option, false);
                                if (cvtResult.IsSuccess)
                                {
                                    DynamicObject[] dylist = (from p in cvtResult.TargetDataEntities select p.DataEntity).ToArray();
                                    //修改应收单里面数据
                                    for (int K = 0; K < dylist.Length; K++)
                                    {
                                        //付款原因
                                        dylist[K]["F_YBG_Remarks"] = "供应商付款";
                                        //明细信息
                                        DynamicObjectCollection RECEIVEBILLENTRYList = dylist[K]["FPAYAPPLYENTRY"] as DynamicObjectCollection;
                                        foreach (var Entry in RECEIVEBILLENTRYList)
                                        {
                                            //结算方式
                                            BaseDataField FSETTLETYPEID = destmeta.BusinessInfo.GetField("FSETTLETYPEID") as BaseDataField;
                                            Entry["FSETTLETYPEID_Id"] = 4;
                                            Entry["FSETTLETYPEID"]    = vService.LoadSingle(Context, 4, FSETTLETYPEID.RefFormDynamicObjectType);
                                        }
                                    }
                                    //保存
                                    ISaveService     saveService = Kingdee.BOS.App.ServiceHelper.GetService <ISaveService>();
                                    IOperationResult saveresult  = saveService.Save(Context, destmeta.BusinessInfo, dylist, option);
                                    bool             reult       = CheckResult(saveresult, out string mssg);
                                    if (!reult)
                                    {
                                        throw new Exception("收款款单审核成功,生成付款申请单失败:");
                                    }
                                    else
                                    {
                                        //纪录核销的纪录
                                        OperateResultCollection operateResults = saveresult.OperateResult;
                                        string fnmber = operateResults[0].Number;
                                        string fid    = operateResults[0].PKValue.ToString();
                                    }
                                }
                            }
                            else
                            {
                                throw new KDException("", "应付单不存在或者未审核,下推付款申请单失败");
                            }
                            #endregion
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new KDException("", "应付单下推付款申请单失败:" + ex.ToString());
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 生成方案
        /// </summary>
        /// <returns></returns>
        public ReturnParam GenerateSolutions(ReturnInfo returnInfo, Context context)
        {
            string      sql         = string.Empty;
            ReturnParam returnParam = new ReturnParam();

            try
            {
                string Fnumber = returnInfo.Fnumber;
                int    qty     = returnInfo.Qty;
                string dengji  = returnInfo.FGG;
                //截取等级
                string[] array = Regex.Split(dengji, ",", RegexOptions.IgnoreCase);
                //等级
                List <Level> dj = new List <Level>()
                {
                    new Level()
                    {
                        Id = "100002", FAUXPTYNUMBER = "A"
                    },
                    new Level()
                    {
                        Id = "100003", FAUXPTYNUMBER = "B"
                    },
                    new Level()
                    {
                        Id = "100004", FAUXPTYNUMBER = "F"
                    },
                    new Level()
                    {
                        Id = "100005", FAUXPTYNUMBER = "N"
                    },
                    new Level()
                    {
                        Id = "100006", FAUXPTYNUMBER = "TB"
                    },
                    new Level()
                    {
                        Id = "100007", FAUXPTYNUMBER = "T"
                    },
                    new Level()
                    {
                        Id = "100008", FAUXPTYNUMBER = "P"
                    },
                    new Level()
                    {
                        Id = "100009", FAUXPTYNUMBER = "TB/B"
                    },
                    new Level()
                    {
                        Id = "100010", FAUXPTYNUMBER = "B/F"
                    },
                    new Level()
                    {
                        Id = "100011", FAUXPTYNUMBER = "F/N"
                    },
                };
                string        sqldj = "";
                List <string> vs    = new List <string>();
                for (int j = 0; j < array.Length; j++)
                {
                    Level level = dj.SingleOrDefault(p => p.FAUXPTYNUMBER == array[j].ToString());
                    if (level != null)
                    {
                        if (j == 0)
                        {
                            sqldj += "  t1.FMATERIALID=" + Fnumber + " and t1.FBASEQTY > 0 and t1.FAUXPROPID='" + level.Id + "' ";
                        }
                        else
                        {
                            sqldj += " or t1.FMATERIALID=" + Fnumber + " and t1.FBASEQTY > 0 and t1.FAUXPROPID='" + level.Id + "' ";
                        }
                    }
                }
                double PCSCONVERT = 1;
                double FDXQTY     = 1;
                //获取库存数据
                sql = "select t1.FMATERIALID,t1.FLOT,t2.FNUMBER,t1.FBASEQTY, t4.FDATE ,t5.FPCSCONVERT,t5.FDXQTY,t1.FAUXPROPID   From  T_STK_INVENTORY t1" +
                      " left  join  T_BD_LOTMASTER t2 on t1.FLOT = t2.FLOTID" +
                      " left join T_STK_INSTOCKENTRY t3 on  t3.FLOT = t1.FLOT and t3.FMATERIALID = t1.FMATERIALID" +
                      " left join t_STK_InStock t4 on t3.FID = t4.FID" +
                      " left join  T_BD_MATERIAL t5 on t5.FMATERIALID=t1.FMATERIALID" +
                      " where ";
                string sqlend = " order by t4.FDATE asc";
                if (string.IsNullOrEmpty(dengji))
                {
                    sqldj = "t1.FMATERIALID=" + Fnumber + " and t1.FBASEQTY > 0 " + sqlend;
                    sql   = sql + sqldj;
                }
                else
                {
                    sql = sql + sqldj + sqlend;
                }
                DataSet   ds = DBServiceHelper.ExecuteDataSet(context, sql);
                DataTable dt = ds.Tables[0];
                #region 方法二: 创建视图、模型,模拟手工新增,会触发大部分的表单服务和插件
                FormMetadata             meta = MetaDataServiceHelper.Load(context, "PAEZ_OrderPlan") as FormMetadata;
                BusinessInfo             info = meta.BusinessInfo;
                IResourceServiceProvider formServiceProvider = meta.BusinessInfo.GetForm().GetFormServiceProvider(true);
                IBillViewService         billViewService     = formServiceProvider.GetService(typeof(IDynamicFormView)) as IBillViewService;

                /******创建单据打开参数*************/
                Form form = meta.BusinessInfo.GetForm();
                BillOpenParameter billOpenParameter = new BillOpenParameter(form.Id, meta.GetLayoutInfo().Id);
                billOpenParameter                       = new BillOpenParameter(form.Id, string.Empty);
                billOpenParameter.Context               = context;
                billOpenParameter.ServiceName           = form.FormServiceName;
                billOpenParameter.PageId                = Guid.NewGuid().ToString();
                billOpenParameter.FormMetaData          = meta;
                billOpenParameter.LayoutId              = meta.GetLayoutInfo().Id;
                billOpenParameter.Status                = OperationStatus.ADDNEW;
                billOpenParameter.PkValue               = null;
                billOpenParameter.CreateFrom            = CreateFrom.Default;
                billOpenParameter.ParentId              = 0;
                billOpenParameter.GroupId               = "";
                billOpenParameter.DefaultBillTypeId     = null;
                billOpenParameter.DefaultBusinessFlowId = null;
                billOpenParameter.SetCustomParameter("ShowConfirmDialogWhenChangeOrg", false);
                List <AbstractDynamicFormPlugIn> value = form.CreateFormPlugIns();
                billOpenParameter.SetCustomParameter(FormConst.PlugIns, value);

                ((IDynamicFormViewService)billViewService).Initialize(billOpenParameter, formServiceProvider);

                IBillView bill_view = (IBillView)billViewService;

                bill_view.CreateNewModelData();

                DynamicFormViewPlugInProxy proxy = bill_view.GetService <DynamicFormViewPlugInProxy>();
                proxy.FireOnLoad();
                bill_view.Model.SetItemValueByID("FSaleOrgId", context.CurrentOrganizationInfo.ID, 0);
                bill_view.Model.SetValue("FDate", DateTime.Now.ToString());
                List <OrderPlan> orderPlans = new List <OrderPlan>();
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    OrderPlan order = new OrderPlan();
                    bill_view.Model.CreateNewEntryRow("FEntity");
                    bill_view.Model.SetValue("FMATERIALID", dt.Rows[i]["FMATERIALID"].ToString(), i);
                    string[] str = Regex.Split(dt.Rows[i]["FNUMBER"].ToString(), "_", RegexOptions.IgnoreCase);
                    // string level= dj.Select(x => x.Id = dt.Rows[i]["FAUXPROPID"].ToString()).First();
                    Level level = dj.SingleOrDefault(p => p.Id == dt.Rows[i]["FAUXPROPID"].ToString());
                    if (level != null)
                    {
                        //等级
                        bill_view.Model.SetItemValueByNumber("$$FAUXPROPID__FF100001", level.FAUXPTYNUMBER, i);
                    }
                    bill_view.Model.SetValue("FINVOICE", str[0].ToString(), i);
                    //板号
                    bill_view.Model.SetValue("FBoardNo", str[1].ToString(), i);
                    //箱号
                    bill_view.Model.SetValue("FCartonNo", str[2].ToString(), i);
                    //库存数量
                    bill_view.Model.SetValue("FQTY", dt.Rows[i]["FBASEQTY"].ToString(), i);
                    //入库日期
                    bill_view.Model.SetValue("FInboundDate", dt.Rows[i]["FDATE"].ToString(), i);
                    //下单数量
                    bill_view.Model.SetValue("FOrderQty", qty, i);
                    //批号
                    bill_view.Model.SetValue("FLOT", dt.Rows[i]["FLOT"].ToString(), i);
                    double FPCSCONVERT = 1;
                    if (string.IsNullOrEmpty(dt.Rows[i]["FPCSCONVERT"].ToString()))
                    {
                        FPCSCONVERT = Convert.ToDouble(dt.Rows[i]["FBASEQTY"].ToString());
                    }
                    else
                    {
                        PCSCONVERT  = Convert.ToDouble(dt.Rows[i]["FPCSCONVERT"].ToString());
                        FPCSCONVERT = Convert.ToDouble(dt.Rows[i]["FPCSCONVERT"].ToString()) * Convert.ToDouble(dt.Rows[i]["FBASEQTY"].ToString());
                    }
                    FDXQTY = Convert.ToDouble(dt.Rows[i]["FDXQTY"].ToString());
                    //转化pcs数量
                    bill_view.Model.SetValue("FPCSQTY", FPCSCONVERT, i);
                    //保存数据
                    order.FMATERIALID  = dt.Rows[i]["FMATERIALID"].ToString();
                    order.FINVOICE     = str[0].ToString();
                    order.FBoardNo     = str[1].ToString();
                    order.FCartonNo    = str[2].ToString();
                    order.FQTY         = Convert.ToDouble(dt.Rows[i]["FBASEQTY"].ToString());
                    order.FInboundDate = dt.Rows[i]["FDATE"].ToString();
                    order.FOrderQty    = qty;
                    order.FLOT         = dt.Rows[i]["FLOT"].ToString();
                    order.FPCSCONVERT  = FPCSCONVERT;
                    order.FAUXPROPID   = dt.Rows[i]["FAUXPROPID"].ToString();
                    orderPlans.Add(order);
                }

                //计算出最优方案 1.计算是刚好等于西单数量的 2.计算出最靠近下单数量的

                // 单箱的pcs
                double SingleFCartonNo = PCSCONVERT * FDXQTY;

                int TotalFCartonNo = Convert.ToInt32(Math.Floor(qty / SingleFCartonNo));

                //剩余数量
                double    RemainQty         = qty % SingleFCartonNo;
                OrderPlan order2            = new OrderPlan();
                bool      Isminimum         = false;
                OrderPlan order3            = new OrderPlan();
                double    differenceQty     = 0;
                double    olddifferenceQty  = 0;
                double    newdifferenceQty2 = 0;
                if (RemainQty != 0)
                {
                    #region  计算出最靠近剩余数量的数并多于下单数量(最右原则)
                    foreach (var item in orderPlans)
                    {
                        if (differenceQty == 0 && item.FPCSCONVERT - RemainQty >= 0)
                        {
                            differenceQty       = item.FPCSCONVERT - RemainQty;
                            order2.FMATERIALID  = item.FMATERIALID;
                            order2.FINVOICE     = item.FINVOICE;
                            order2.FBoardNo     = item.FBoardNo;
                            order2.FCartonNo    = item.FCartonNo;
                            order2.FQTY         = item.FQTY;
                            order2.FInboundDate = item.FInboundDate;
                            order2.FOrderQty    = item.FOrderQty;
                            order2.FLOT         = item.FLOT;
                            order2.FAUXPROPID   = item.FAUXPROPID;
                            order2.FPCSCONVERT  = item.FPCSCONVERT;
                        }
                        else
                        {
                            double newdifferenceQty = item.FPCSCONVERT - RemainQty;
                            if (newdifferenceQty > 0 && newdifferenceQty < differenceQty)
                            {
                                differenceQty       = newdifferenceQty;
                                order2.FMATERIALID  = item.FMATERIALID;
                                order2.FINVOICE     = item.FINVOICE;
                                order2.FBoardNo     = item.FBoardNo;
                                order2.FCartonNo    = item.FCartonNo;
                                order2.FQTY         = item.FQTY;
                                order2.FInboundDate = item.FInboundDate;
                                order2.FOrderQty    = item.FOrderQty;
                                order2.FLOT         = item.FLOT;
                                order2.FAUXPROPID   = item.FAUXPROPID;
                                order2.FPCSCONVERT  = item.FPCSCONVERT;
                            }
                        }
                    }

                    #endregion

                    #region  计算最靠近的数量并小于下单数量(最左原则)
                    foreach (var item in orderPlans)
                    {
                        newdifferenceQty2 = item.FPCSCONVERT - RemainQty;
                        if (newdifferenceQty2 <= 0)
                        {
                            if (olddifferenceQty != 0)
                            {
                                if (Math.Abs(newdifferenceQty2) < Math.Abs(olddifferenceQty))
                                {
                                    olddifferenceQty    = newdifferenceQty2;
                                    order3.FMATERIALID  = item.FMATERIALID;
                                    order3.FINVOICE     = item.FINVOICE;
                                    order3.FBoardNo     = item.FBoardNo;
                                    order3.FCartonNo    = item.FCartonNo;
                                    order3.FQTY         = item.FQTY;
                                    order3.FInboundDate = item.FInboundDate;
                                    order3.FOrderQty    = item.FOrderQty;
                                    order3.FLOT         = item.FLOT;
                                    order3.FPCSCONVERT  = item.FPCSCONVERT;
                                    order3.FAUXPROPID   = item.FAUXPROPID;
                                    Isminimum           = true;
                                }
                            }
                            else
                            {
                                olddifferenceQty    = newdifferenceQty2;
                                order3.FMATERIALID  = item.FMATERIALID;
                                order3.FINVOICE     = item.FINVOICE;
                                order3.FBoardNo     = item.FBoardNo;
                                order3.FCartonNo    = item.FCartonNo;
                                order3.FQTY         = item.FQTY;
                                order3.FInboundDate = item.FInboundDate;
                                order3.FOrderQty    = item.FOrderQty;
                                order3.FLOT         = item.FLOT;
                                order3.FAUXPROPID   = item.FAUXPROPID;
                                order3.FPCSCONVERT  = item.FPCSCONVERT;
                                Isminimum           = true;
                            }
                        }
                    }

                    #endregion
                }
                #region 组装数据
                //当前库存不够发
                if (orderPlans.Count < TotalFCartonNo)
                {
                    returnParam.status = true;
                    returnParam.msg    = "当前库存数量不够发货";
                    return(returnParam);
                }
                else
                {
                    //排除非整箱
                    List <OrderPlan> orderPlan  = orderPlans.FindAll(t => t.FLOT != order2.FLOT);
                    List <OrderPlan> orderPlan3 = orderPlans.FindAll(t => t.FLOT != order3.FLOT);
                    int j = 0;
                    #region 最右原则
                    foreach (var item in orderPlan)
                    {
                        if (j == TotalFCartonNo)
                        {
                            break;
                        }
                        else
                        {
                            if (item.FPCSCONVERT == SingleFCartonNo)
                            {
                                bill_view.Model.CreateNewEntryRow("F_PAEZ_Entity");
                                bill_view.Model.SetValue("FMATERIALID2", item.FMATERIALID, j);
                                //等级
                                //bill_view.Model.SetItemValueByID("FAUXPROPID2", item.FAUXPROPID, j);

                                Level level = dj.SingleOrDefault(p => p.Id == item.FAUXPROPID);
                                if (level != null)
                                {
                                    //等级
                                    bill_view.Model.SetItemValueByNumber("$$FAUXPROPID2__FF100001", level.FAUXPTYNUMBER, j);
                                }
                                bill_view.Model.SetValue("FINVOICE2", item.FINVOICE, j);
                                //板号
                                bill_view.Model.SetValue("FBoardNo2", item.FBoardNo, j);
                                //箱号
                                bill_view.Model.SetValue("FCartonNo2", item.FCartonNo, j);
                                //库存数量
                                bill_view.Model.SetValue("FQTY2", item.FQTY, j);
                                //入库日期
                                bill_view.Model.SetValue("FInboundDate2", item.FInboundDate, j);
                                //下单数量
                                bill_view.Model.SetValue("FOrderQty2", item.FOrderQty, j);
                                //批号
                                bill_view.Model.SetValue("FLOT2", item.FLOT, j);
                                //转化pcs数量
                                bill_view.Model.SetValue("FPCSQTY2", item.FPCSCONVERT, j);
                                j++;
                            }
                        }
                    }
                    //加入剩余数量
                    if (RemainQty != 0)
                    {
                        bill_view.Model.CreateNewEntryRow("F_PAEZ_Entity");
                        bill_view.Model.SetValue("FMATERIALID2", order2.FMATERIALID, j);
                        //等级
                        if (!string.IsNullOrEmpty(order2.FAUXPROPID) && order2.FAUXPROPID != "0")
                        {
                            Level level = dj.SingleOrDefault(p => p.Id == order2.FAUXPROPID);
                            //等级
                            bill_view.Model.SetItemValueByNumber("$$FAUXPROPID2__FF100001", level.FAUXPTYNUMBER, j);
                        }
                        bill_view.Model.SetValue("FINVOICE2", order2.FINVOICE, j);
                        //板号
                        bill_view.Model.SetValue("FBoardNo2", order2.FBoardNo, j);
                        //箱号
                        bill_view.Model.SetValue("FCartonNo2", order2.FCartonNo, j);
                        //库存数量
                        bill_view.Model.SetValue("FQTY2", order2.FQTY, j);
                        //入库日期
                        bill_view.Model.SetValue("FInboundDate2", order2.FInboundDate, j);
                        //下单数量
                        bill_view.Model.SetValue("FOrderQty2", order2.FOrderQty, j);
                        //批号
                        bill_view.Model.SetValue("FLOT2", order2.FLOT, j);
                        //转化pcs数量
                        bill_view.Model.SetValue("FPCSQTY2", order2.FPCSCONVERT, j);
                    }

                    #endregion

                    #region 最左原则
                    int a = 0;
                    foreach (var item in orderPlan3)
                    {
                        if (a == TotalFCartonNo)
                        {
                            break;
                        }
                        else
                        {
                            if (item.FPCSCONVERT == SingleFCartonNo)
                            {
                                bill_view.Model.CreateNewEntryRow("F_PAEZ_Entity3");
                                bill_view.Model.SetValue("FMATERIALID3", item.FMATERIALID, a);
                                //等级
                                //bill_view.Model.SetItemValueByID("FAUXPROPID3", item.FAUXPROPID, a);
                                Level level = dj.SingleOrDefault(p => p.Id == item.FAUXPROPID);
                                if (level != null)
                                {
                                    //等级
                                    bill_view.Model.SetItemValueByNumber("$$FAUXPROPID3__FF100001", level.FAUXPTYNUMBER, a);
                                }
                                bill_view.Model.SetValue("FINVOICE3", item.FINVOICE, a);
                                //板号
                                bill_view.Model.SetValue("FBoardNo3", item.FBoardNo, a);
                                //箱号
                                bill_view.Model.SetValue("FCartonNo3", item.FCartonNo, a);
                                //库存数量
                                bill_view.Model.SetValue("FQTY3", item.FQTY, a);
                                //入库日期
                                bill_view.Model.SetValue("FInboundDate3", item.FInboundDate, a);
                                //下单数量
                                bill_view.Model.SetValue("FOrderQty3", item.FOrderQty, a);
                                //批号
                                bill_view.Model.SetValue("FLOT3", item.FLOT, a);
                                //转化pcs数量
                                bill_view.Model.SetValue("FPCSQTY3", item.FPCSCONVERT, a);
                                a++;
                            }
                        }
                    }
                    //加入剩余数量
                    if (RemainQty != 0)
                    {
                        bill_view.Model.CreateNewEntryRow("F_PAEZ_Entity3");
                        bill_view.Model.SetValue("FMATERIALID3", order3.FMATERIALID, a);
                        //等级
                        if (!string.IsNullOrEmpty(order3.FAUXPROPID) && order3.FAUXPROPID != "0")
                        {
                            Level level = dj.SingleOrDefault(p => p.Id == order3.FAUXPROPID);
                            //等级
                            bill_view.Model.SetItemValueByNumber("$$FAUXPROPID3__FF100001", level.FAUXPTYNUMBER, a);
                        }
                        bill_view.Model.SetValue("FINVOICE3", order3.FINVOICE, a);
                        //板号
                        bill_view.Model.SetValue("FBoardNo3", order3.FBoardNo, a);
                        //箱号
                        bill_view.Model.SetValue("FCartonNo3", order3.FCartonNo, a);
                        //库存数量
                        bill_view.Model.SetValue("FQTY3", order3.FQTY, a);
                        //入库日期
                        bill_view.Model.SetValue("FInboundDate3", order3.FInboundDate, a);
                        //下单数量
                        bill_view.Model.SetValue("FOrderQty3", order3.FOrderQty, a);
                        //批号
                        bill_view.Model.SetValue("FLOT3", order3.FLOT, a);
                        //转化pcs数量
                        bill_view.Model.SetValue("FPCSQTY3", order3.FPCSCONVERT, a);
                    }

                    #endregion
                }
                #endregion
                string result = "";

                IOperationResult save_result = bill_view.Model.Save();
                if (save_result.IsSuccess)
                {
                    string fid = string.Empty;
                    OperateResultCollection Collection = save_result.OperateResult;
                    foreach (var item in Collection)
                    {
                        fid = item.PKValue.ToString();
                    }
                    returnParam.FBUSINESSCODE = fid;
                    returnParam.FBIZFORMID    = "PAEZ_OrderPlan";
                    returnParam.msg           = "方案生成功";
                    returnParam.status        = true;
                    return(returnParam);
                }
                else
                {
                    for (int mf = 0; mf < save_result.ValidationErrors.Count; mf++)
                    {
                        result += "\r\n" + save_result.ValidationErrors[mf].Message;
                    }
                }


                #endregion
            }
            catch (Exception ex)
            {
                returnParam.msg    = ex.ToString();
                returnParam.status = false;
                returnParam.msg    = "方案生成失败";
                return(returnParam);
            }
            return(returnParam);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 组装销售订单数据并保存
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public ReturnParam SaleOrder(DataTable dt, DataTable dtbt, int a)
        {
            ReturnParam param = new ReturnParam();

            #region 方法二: 创建视图、模型,模拟手工新增,会触发大部分的表单服务和插件
            FormMetadata             meta = MetaDataServiceHelper.Load(this.Context, "SAL_SaleOrder") as FormMetadata;
            BusinessInfo             info = meta.BusinessInfo;
            IResourceServiceProvider formServiceProvider = meta.BusinessInfo.GetForm().GetFormServiceProvider(true);
            IBillViewService         billViewService     = formServiceProvider.GetService(typeof(IDynamicFormView)) as IBillViewService;

            /******创建单据打开参数*************/
            Form form = meta.BusinessInfo.GetForm();
            BillOpenParameter billOpenParameter = new BillOpenParameter(form.Id, meta.GetLayoutInfo().Id);
            billOpenParameter                       = new BillOpenParameter(form.Id, string.Empty);
            billOpenParameter.Context               = Context;
            billOpenParameter.ServiceName           = form.FormServiceName;
            billOpenParameter.PageId                = Guid.NewGuid().ToString();
            billOpenParameter.FormMetaData          = meta;
            billOpenParameter.LayoutId              = meta.GetLayoutInfo().Id;
            billOpenParameter.Status                = OperationStatus.ADDNEW;
            billOpenParameter.PkValue               = null;
            billOpenParameter.CreateFrom            = CreateFrom.Default;
            billOpenParameter.ParentId              = 0;
            billOpenParameter.GroupId               = "";
            billOpenParameter.DefaultBillTypeId     = null;
            billOpenParameter.DefaultBusinessFlowId = null;
            billOpenParameter.SetCustomParameter("ShowConfirmDialogWhenChangeOrg", false);
            List <AbstractDynamicFormPlugIn> value = form.CreateFormPlugIns();
            billOpenParameter.SetCustomParameter(FormConst.PlugIns, value);

            ((IDynamicFormViewService)billViewService).Initialize(billOpenParameter, formServiceProvider);

            IBillView bill_view = (IBillView)billViewService;

            bill_view.CreateNewModelData();

            DynamicFormViewPlugInProxy proxy = bill_view.GetService <DynamicFormViewPlugInProxy>();
            proxy.FireOnLoad();
            string FID       = string.Empty;
            string updatesql = string.Empty;
            updatesql = "";
            List <string> listsql      = new List <string>();
            string        FProgramCode = "";
            //表头
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                FID          = dt.Rows[i]["FID"].ToString();
                FProgramCode = dt.Rows[i]["FBILLNO"].ToString();
                bill_view.Model.SetItemValueByID("FSaleOrgId", dt.Rows[i]["FSALEORGID"], 0);
                bill_view.Model.SetValue("FDate", DateTime.Now.ToString());
                //客户
                bill_view.Model.SetItemValueByID("FCustId", dt.Rows[i]["FCUSTID"].ToString(), 0);
                //结算币别
                bill_view.InvokeFieldUpdateService("FCustId", 0);
                bill_view.InvokeFieldUpdateService("FSETTLECURRID", 0);
                //销售员
                bill_view.Model.SetValue("FSalerId", dt.Rows[i]["FSALERID"].ToString(), 0);
                bill_view.InvokeFieldUpdateService("FSALEDEPTID", 0);
                //交货方式
                bill_view.Model.SetValue("FHeadDeliveryWay", dt.Rows[i]["FHEADDELIVERYWAY"].ToString());
                //交货地点
                bill_view.Model.SetValue("FHEADLOCID", dt.Rows[i]["FHEADLOCID"].ToString());
            }
            if (a == 1)
            {
                //表体
                for (int i = 0; i < dtbt.Rows.Count; i++)
                {
                    bill_view.Model.CreateNewEntryRow("FSaleOrderEntry");
                    bill_view.Model.SetValue("FMaterialId", dtbt.Rows[i]["FMATERIALID"].ToString(), i);
                    bill_view.InvokeFieldUpdateService("FMATERIALID", i);
                    bill_view.InvokeFieldUpdateService("FUNITID", i);
                    bill_view.InvokeFieldUpdateService("FBASEUNITID", i);
                    // 销售数量
                    bill_view.Model.SetValue("FQty", Convert.ToDouble(dtbt.Rows[i]["FQTY"].ToString()), i);
                    bill_view.InvokeFieldUpdateService("FQty", i);          //
                    bill_view.InvokeFieldUpdateService("FPriceUnitQty", i); //计家数量
                    //含税单价
                    bill_view.Model.SetValue("FTaxPrice", 20, i);
                    bill_view.InvokeFieldUpdateService("FTaxPrice", i);
                    bill_view.InvokeFieldUpdateService("FPrice", i);
                    bill_view.InvokeFieldUpdateService("FAmount", i);
                    bill_view.InvokeFieldUpdateService("FAllAmount", i);
                    bill_view.InvokeFieldUpdateService("FAllAmount", i);
                    //要货日期DateTime.Now.AddDays(10
                    bill_view.Model.SetValue("FDeliveryDate", DateTime.Now.AddDays(10), i);
                    //计划交货日期
                    bill_view.Model.SetValue("FMinPlanDeliveryDate", DateTime.Now.AddDays(10), i);
                    //结算组织
                    bill_view.Model.SetItemValueByID("FSettleOrgIds", this.Context.CurrentOrganizationInfo.ID, i);
                    //批号FLot
                    bill_view.Model.SetValue("FLot", dtbt.Rows[i]["FLOT"].ToString(), i);
                    // bill_view.Model.SetValue("FLOT_TEXT", dtbt.Rows[i]["FINVOICE"].ToString() + "_" + dtbt.Rows[i]["FBOARDNO"].ToString() + "_" + dtbt.Rows[i]["FCARTONNO"].ToString(), i);
                    int FSEQ = i + 1;
                    updatesql = "update T_SAL_ORDERENTRY set FAUXPROPID='" + dtbt.Rows[i]["FAUXPROPID"].ToString() + "',FLOT_TEXT='" + dtbt.Rows[i]["FINVOICE"].ToString() + "_" + dtbt.Rows[i]["FBOARDNO"].ToString() + "_" + dtbt.Rows[i]["FCARTONNO"].ToString() + "',FLOT=" + dtbt.Rows[i]["FLOT"].ToString() + " where FSEQ=" + FSEQ + "";
                    listsql.Add(updatesql);
                }
            }
            else if (a == 2)
            {
                //表体
                for (int i = 0; i < dtbt.Rows.Count; i++)
                {
                    bill_view.Model.CreateNewEntryRow("FSaleOrderEntry");
                    bill_view.Model.SetValue("FMaterialId", dtbt.Rows[i]["FMATERIALID2"].ToString(), i);
                    bill_view.InvokeFieldUpdateService("FMATERIALID", i);
                    bill_view.InvokeFieldUpdateService("FUNITID", i);
                    bill_view.InvokeFieldUpdateService("FBASEUNITID", i);
                    // 销售数量
                    bill_view.Model.SetValue("FQty", Convert.ToDouble(dtbt.Rows[i]["FQTY2"].ToString()), i);
                    bill_view.InvokeFieldUpdateService("FQty", i);          //
                    bill_view.InvokeFieldUpdateService("FPriceUnitQty", i); //计家数量
                                                                            //含税单价
                    bill_view.Model.SetValue("FTaxPrice", 20, i);
                    bill_view.InvokeFieldUpdateService("FTaxPrice", i);
                    bill_view.InvokeFieldUpdateService("FPrice", i);
                    bill_view.InvokeFieldUpdateService("FAmount", i);
                    bill_view.InvokeFieldUpdateService("FAllAmount", i);
                    bill_view.InvokeFieldUpdateService("FAllAmount", i);
                    //要货日期DateTime.Now.AddDays(10
                    bill_view.Model.SetValue("FDeliveryDate", DateTime.Now.AddDays(10), i);
                    //计划交货日期
                    bill_view.Model.SetValue("FMinPlanDeliveryDate", DateTime.Now.AddDays(10), i);
                    //结算组织
                    bill_view.Model.SetItemValueByID("FSettleOrgIds", this.Context.CurrentOrganizationInfo.ID, i);
                    //批号FLot
                    bill_view.Model.SetValue("FLot", dtbt.Rows[i]["FLOT2"].ToString(), i);
                    // bill_view.Model.SetValue("FLOT_TEXT", dtbt.Rows[i]["FINVOICE2"].ToString() + "_" + dtbt.Rows[i]["FBOARDNO2"].ToString() + "_" + dtbt.Rows[i]["FCARTONNO2"].ToString(), i);
                    int FSEQ = i + 1;
                    updatesql = "update T_SAL_ORDERENTRY set FAUXPROPID='" + dtbt.Rows[i]["FAUXPROPID2"].ToString() + "', FLOT_TEXT='" + dtbt.Rows[i]["FINVOICE2"].ToString() + "_" + dtbt.Rows[i]["FBOARDNO2"].ToString() + "_" + dtbt.Rows[i]["FCARTONNO2"].ToString() + "',FLOT =" + dtbt.Rows[i]["FLOT2"].ToString() + " where FSEQ=" + FSEQ + "";
                    listsql.Add(updatesql);
                }
            }
            else if (a == 3)
            {
                //表体
                for (int i = 0; i < dtbt.Rows.Count; i++)
                {
                    bill_view.Model.CreateNewEntryRow("FSaleOrderEntry");
                    bill_view.Model.SetValue("FMaterialId", dtbt.Rows[i]["FMATERIALID3"].ToString(), i);
                    bill_view.InvokeFieldUpdateService("FMATERIALID", i);
                    bill_view.InvokeFieldUpdateService("FUNITID", i);
                    bill_view.InvokeFieldUpdateService("FBASEUNITID", i);
                    // 销售数量
                    bill_view.Model.SetValue("FQty", Convert.ToDouble(dtbt.Rows[i]["FQTY3"].ToString()), i);
                    bill_view.InvokeFieldUpdateService("FQty", i);          //
                    bill_view.InvokeFieldUpdateService("FPriceUnitQty", i); //计家数量
                                                                            //含税单价
                    bill_view.Model.SetValue("FTaxPrice", 20, i);
                    bill_view.InvokeFieldUpdateService("FTaxPrice", i);
                    bill_view.InvokeFieldUpdateService("FPrice", i);
                    bill_view.InvokeFieldUpdateService("FAmount", i);
                    bill_view.InvokeFieldUpdateService("FAllAmount", i);
                    bill_view.InvokeFieldUpdateService("FAllAmount", i);
                    //要货日期DateTime.Now.AddDays(10
                    bill_view.Model.SetValue("FDeliveryDate", DateTime.Now.AddDays(10), i);
                    //计划交货日期
                    bill_view.Model.SetValue("FMinPlanDeliveryDate", DateTime.Now.AddDays(10), i);
                    //结算组织
                    bill_view.Model.SetItemValueByID("FSettleOrgIds", this.Context.CurrentOrganizationInfo.ID, i);
                    //批号FLot
                    bill_view.Model.SetValue("FLot", dtbt.Rows[i]["FLOT3"].ToString(), i);
                    // bill_view.Model.SetValue("FLOT_TEXT", dtbt.Rows[i]["FINVOICE3"].ToString()+"_"+ dtbt.Rows[i]["FBOARDNO3"].ToString()+"_"+ dtbt.Rows[i]["FCARTONNO3"].ToString(), i);
                    int FSEQ = i + 1;
                    updatesql = "update T_SAL_ORDERENTRY set FAUXPROPID='" + dtbt.Rows[i]["FAUXPROPID3"].ToString() + "', FLOT_TEXT='" + dtbt.Rows[i]["FINVOICE3"].ToString() + "_" + dtbt.Rows[i]["FBOARDNO3"].ToString() + "_" + dtbt.Rows[i]["FCARTONNO3"].ToString() + "',FLOT=" + dtbt.Rows[i]["FLOT3"].ToString() + " where FSEQ=" + FSEQ + "";
                    listsql.Add(updatesql);
                }
            }
            string result = "";
            //保存
            IOperationResult save_result = bill_view.Model.Save();
            if (save_result.IsSuccess)
            {
                string fid     = string.Empty;
                string Fnumber = string.Empty;
                OperateResultCollection Collection = save_result.OperateResult;
                foreach (var item in Collection)
                {
                    fid     = item.PKValue.ToString();
                    Fnumber = item.Number.ToString();
                }
                //更新到方案FSalesOrder
                string sql = "update t_OrderPlan set FSalesOrder='" + Fnumber + "'  where  FID=" + FID + ";";
                sql += " update  T_SAL_ORDER set FProgramCode='" + FProgramCode + "'  where  FID=" + fid + ";";
                DBServiceHelper.Execute(this.Context, sql);
                sql = " and FID=" + fid + " ;";
                foreach (var item in listsql)
                {
                    string upsql = item + sql;
                    DBServiceHelper.Execute(this.Context, upsql);
                }
                param.msg    = "生成销售订单成功:" + Fnumber;
                param.status = true;
                return(param);
            }
            else
            {
                for (int mf = 0; mf < save_result.ValidationErrors.Count; mf++)
                {
                    result += "\r\n" + save_result.ValidationErrors[mf].Message;
                }

                param.msg    = "保存失败:" + result;
                param.status = false;
                return(param);
            }
            #endregion
        }