示例#1
0
        //定义
        private object CreateTargetBillView(BusinessInfo oBusinessInfo)
        {
            string            formId = oBusinessInfo.GetForm().Id;
            BillOpenParameter param  = new BillOpenParameter(formId, null);

            param.SetCustomParameter("formID", formId);
            param.SetCustomParameter("pk", 0);
            param.SetCustomParameter("status", OperationStatus.ADDNEW);
            param.SetCustomParameter("PlugIns", oBusinessInfo.GetForm().CreateFormPlugIns());
            param.Context      = this.Context;
            param.FormMetaData = ((FormMetadata)Kingdee.BOS.Contracts.ServiceFactory.GetMetaDataService(this.Context).Load(this.Context, formId, true));
            param.LayoutId     = param.FormMetaData.GetLayoutInfo().Id;
            param.PkValue      = 0;
            param.Status       = OperationStatus.ADDNEW;
            object service = oBusinessInfo.GetForm().GetFormServiceProvider(false).GetService(typeof(IDynamicFormView));

            (service as IBillViewService).Initialize(param, oBusinessInfo.GetForm().GetFormServiceProvider(false));
            (service as IBillView).OpenParameter.Status = OperationStatus.ADDNEW;
            try
            {
                (service as IBillViewService).LoadData();
            }
            catch (Exception ex)
            {
            }

            return(service);
        }
        public DynamicObject installCostRequestPackage(Context ctx, string FormID, Action <IDynamicFormViewService> fillBillPropertys, string BillTypeId = "")
        {
            //IMetaDataService metaService = ServiceHelper.GetService<IMetaDataService>();//元数据服务
            //FormMetadata Meta = metaService.Load(ctx, FormID) as FormMetadata;//获取元数据
            FormMetadata            Meta = MetaDataServiceHelper.Load(ctx, FormID) as FormMetadata;//获取元数据
            Form                    form = Meta.BusinessInfo.GetForm();
            IDynamicFormViewService dynamicFormViewService = (IDynamicFormViewService)Activator.CreateInstance(Type.GetType("Kingdee.BOS.Web.Import.ImportBillView,Kingdee.BOS.Web"));
            // 创建视图加载参数对象,指定各种参数,如FormId, 视图(LayoutId)等
            BillOpenParameter openParam = new BillOpenParameter(form.Id, Meta.GetLayoutInfo().Id);

            openParam.Context      = ctx;
            openParam.ServiceName  = form.FormServiceName;
            openParam.PageId       = Guid.NewGuid().ToString();
            openParam.FormMetaData = Meta;
            openParam.Status       = OperationStatus.ADDNEW;
            openParam.CreateFrom   = CreateFrom.Default;
            // 单据类型
            openParam.DefaultBillTypeId = BillTypeId;
            openParam.SetCustomParameter("ShowConfirmDialogWhenChangeOrg", false);
            // 插件
            List <AbstractDynamicFormPlugIn> plugs = form.CreateFormPlugIns();

            openParam.SetCustomParameter(FormConst.PlugIns, plugs);
            PreOpenFormEventArgs args = new PreOpenFormEventArgs(ctx, openParam);

            foreach (var plug in plugs)
            {
                plug.PreOpenForm(args);
            }
            // 动态领域模型服务提供类,通过此类,构建MVC实例
            IResourceServiceProvider provider = form.GetFormServiceProvider(false);

            dynamicFormViewService.Initialize(openParam, provider);
            IBillView billView = dynamicFormViewService as IBillView;

            ((IBillViewService)billView).LoadData();

            // 触发插件的OnLoad事件:
            // 组织控制基类插件,在OnLoad事件中,对主业务组织改变是否提示选项进行初始化。
            // 如果不触发OnLoad事件,会导致主业务组织赋值不成功
            DynamicFormViewPlugInProxy eventProxy = billView.GetService <DynamicFormViewPlugInProxy>();

            eventProxy.FireOnLoad();
            if (fillBillPropertys != null)
            {
                fillBillPropertys(dynamicFormViewService);
            }
            // 设置FormId
            form = billView.BillBusinessInfo.GetForm();
            if (form.FormIdDynamicProperty != null)
            {
                form.FormIdDynamicProperty.SetValue(billView.Model.DataObject, form.Id);
            }
            return(billView.Model.DataObject);
        }
        public static IBillView CreateBillView(this FormMetadata metadata, Context ctx, Action <BillOpenParameter> openParamAction = null)
        {
            //创建用于引入数据的单据view
            Type type     = Type.GetType("Kingdee.BOS.Web.Import.ImportBillView,Kingdee.BOS.Web");
            var  billView = (IDynamicFormViewService)Activator.CreateInstance(type);

            //获取表单元素
            Form form = metadata.BusinessInfo.GetForm();

            //开始初始化billView:
            //创建视图加载参数对象,指定各种参数,如FormId, 视图(LayoutId)等
            //指定FormId, LayoutId
            BillOpenParameter openParam = new BillOpenParameter(form.Id, metadata.GetLayoutInfo().Id);

            openParam.Context               = ctx;                                 //数据库上下文
            openParam.ServiceName           = form.FormServiceName;                //本单据模型使用的MVC框架
            openParam.PageId                = Guid.NewGuid().ToString();           //随机产生一个不重复的PageId,作为视图的标识
            openParam.FormMetaData          = metadata;                            //元数据
            openParam.Status                = OperationStatus.ADDNEW;              //界面状态:新增 (修改、查看)
            openParam.PkValue               = null;                                //单据主键:本案例演示新建物料,不需要设置主键
            openParam.CreateFrom            = CreateFrom.Default;                  //界面创建目的:普通无特殊目的 (为工作流、为下推、为复制等)
            openParam.GroupId               = string.Empty;                        //基础资料分组维度:基础资料允许添加多个分组字段,每个分组字段会有一个分组维度。具体分组维度Id,请参阅 form.FormGroups 属性
            openParam.ParentId              = 0;                                   //基础资料分组:如果需要为新建的基础资料指定所在分组,请设置此属性
            openParam.DefaultBillTypeId     = string.Empty;                        //单据类型
            openParam.DefaultBusinessFlowId = string.Empty;                        //业务流程
            openParam.SetCustomParameter("ShowConfirmDialogWhenChangeOrg", false); //主业务组织改变时,不用弹出提示界面
            openParamAction?.Invoke(openParam);

            //插件
            List <AbstractDynamicFormPlugIn> plugs = form.CreateFormPlugIns();

            openParam.SetCustomParameter(FormConst.PlugIns, plugs);
            PreOpenFormEventArgs args = new PreOpenFormEventArgs(ctx, openParam);

            foreach (var plug in plugs)
            {
                //触发插件PreOpenForm事件,供插件确认是否允许打开界面
                plug.PreOpenForm(args);
            }
            if (args.Cancel == true)
            {
                //插件不允许打开界面
                //本案例不理会插件的诉求,继续....
            }//end if

            //动态领域模型服务提供类,通过此类,构建MVC实例
            var provider = form.GetFormServiceProvider();

            billView.Initialize(openParam, provider);
            return(billView as IBillView);
        }
示例#4
0
文件: Test1.cs 项目: szzend/CLOUDDOC
        private BillOpenParameter CreateOpenParameter(FormMetadata meta)
        {
            Form form = meta.BusinessInfo.GetForm();
            // 指定FormId, LayoutId
            BillOpenParameter openParam = new BillOpenParameter(form.Id, meta.GetLayoutInfo().Id);

            // 数据库上下文
            openParam.Context = this.Context;
            // 本单据模型使用的MVC框架
            openParam.ServiceName = form.FormServiceName;
            // 随机产生一个不重复的PageId,作为视图的标识
            openParam.PageId = Guid.NewGuid().ToString();
            // 元数据
            openParam.FormMetaData = meta;
            // 界面状态:新增 (修改、查看)
            openParam.Status = OperationStatus.ADDNEW;
            // 单据主键:本案例演示新建物料,不需要设置主键
            openParam.PkValue = null;
            // 界面创建目的:普通无特殊目的 (为工作流、为下推、为复制等)
            openParam.CreateFrom = CreateFrom.Default;
            // 基础资料分组维度:基础资料允许添加多个分组字段,每个分组字段会有一个分组维度
            // 具体分组维度Id,请参阅 form.FormGroups 属性
            openParam.GroupId = "";
            // 基础资料分组:如果需要为新建的基础资料指定所在分组,请设置此属性
            openParam.ParentId = 0;
            // 单据类型
            openParam.DefaultBillTypeId = "";
            // 业务流程
            openParam.DefaultBusinessFlowId = "";
            // 主业务组织改变时,不用弹出提示界面
            openParam.SetCustomParameter("ShowConfirmDialogWhenChangeOrg", false);
            // 插件
            List <AbstractDynamicFormPlugIn> plugs = form.CreateFormPlugIns();

            openParam.SetCustomParameter(FormConst.PlugIns, plugs);
            PreOpenFormEventArgs args = new PreOpenFormEventArgs(this.Context, openParam);

            foreach (var plug in plugs)
            {// 触发插件PreOpenForm事件,供插件确认是否允许打开界面
                plug.PreOpenForm(args);
            }
            if (args.Cancel == true)
            {// 插件不允许打开界面
             // 本案例不理会插件的诉求,继续....
            }
            // 返回
            return(openParam);
        }
        private BillOpenParameter CreateOpenParameter(FormMetadata meta)
        {
            Form form = meta.BusinessInfo.GetForm();
            BillOpenParameter openParam = new BillOpenParameter(form.Id, meta.GetLayoutInfo().Id);

            openParam.Context               = this.Context;
            openParam.ServiceName           = form.FormServiceName;
            openParam.PageId                = Guid.NewGuid().ToString();
            openParam.FormMetaData          = meta;
            openParam.Status                = OperationStatus.ADDNEW;
            openParam.PkValue               = null;
            openParam.CreateFrom            = CreateFrom.Default;
            openParam.GroupId               = "";
            openParam.ParentId              = 0;
            openParam.DefaultBillTypeId     = "";
            openParam.DefaultBusinessFlowId = "";
            openParam.SetCustomParameter("ShowConfirmDialogWhenChangeOrg", false);
            List <AbstractDynamicFormPlugIn> plugs = form.CreateFormPlugIns();

            openParam.SetCustomParameter(FormConst.PlugIns, plugs);
            PreOpenFormEventArgs args = new PreOpenFormEventArgs(this.Context, openParam);

            return(openParam);
        }
        /// <summary>
        /// 打开PC的Web页面,暂时不好用
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="FormId"></param>
        /// <param name="pkid"></param>
        /// <returns></returns>
        private IDynamicFormView OpenWebView(Context ctx, string FormId, string pkid = null)
        {
            var          meta = MetaDataServiceHelper.Load(ctx, FormId) as FormMetadata;
            BusinessInfo info = meta.BusinessInfo;
            var          form = info.GetForm();

            BillOpenParameter param = new BillOpenParameter(form.Id, null);

            //param.SetCustomParameter("formID", form.Id);
            //param.SetCustomParameter("status", (pkid != null ? "View" : "AddNew"));
            //param.SetCustomParameter("formID", form.CreateFormPlugIns());
            param.Context               = ctx;
            param.ServiceName           = form.FormServiceName;
            param.PageId                = Guid.NewGuid().ToString();
            param.FormMetaData          = meta;
            param.LayoutId              = param.FormMetaData.GetLayoutInfo().Id;
            param.Status                = pkid != null ? OperationStatus.EDIT : OperationStatus.ADDNEW;
            param.PkValue               = pkid;
            param.CreateFrom            = CreateFrom.Default;
            param.ParentId              = 0;
            param.GroupId               = "";
            param.DefaultBillTypeId     = null;
            param.DefaultBusinessFlowId = null;
            param.SetCustomParameter("ShowConfirmDialogWhenChangeOrg", false);

            //IResourceServiceProvider provider = form.GetFormServiceProvider();
            //IDynamicFormView bv = provider.GetService(typeof(IDynamicFormView)) as IDynamicFormView;
            //(bv as IBillViewService).Initialize(param, provider);
            //(bv as IDynamicFormView).RegisterPlugIn(getFormStatePlugIn);
            Type             type = Type.GetType("Kingdee.BOS.Web.Import.ImportBillView,Kingdee.BOS.Web");
            IDynamicFormView bv   = (IDynamicFormView)Activator.CreateInstance(type);
            var provider          = form.GetFormServiceProvider();

            (bv as IBillViewService).Initialize(param, provider);
            (bv as IBillView).CreateNewModelData();
            if (param.Status != OperationStatus.ADDNEW)
            {
                (bv as IBillViewService).LoadData();
            }
            return(bv);
        }
示例#7
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);
        }
示例#8
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
        }