// 得到销售订单dto
        /// <summary>
        /// 得到销售订单dto
        /// </summary>
        /// <param name="bpObj"></param>
        /// <returns></returns>
        private System.Collections.Generic.List <SaleOrderDTOData> GetSaleOrderDTODataList(CreateApprovedSaleOrderSV bpObj, out List <SO> lstExist)
        {
            lstExist = new List <SO>();

            System.Collections.Generic.List <SaleOrderDTOData> list = new System.Collections.Generic.List <SaleOrderDTOData>();
            System.Collections.Generic.Dictionary <string, System.Collections.Generic.List <SoLineDTO> > dic = new System.Collections.Generic.Dictionary <string, System.Collections.Generic.List <SoLineDTO> >();
            foreach (SoLineDTO solinedto in bpObj.SoLineDto)
            {
                if (!dic.ContainsKey(solinedto.SpitOrderFlag))
                {
                    dic.Add(solinedto.SpitOrderFlag, new System.Collections.Generic.List <SoLineDTO>());
                }
                dic[solinedto.SpitOrderFlag].Add(solinedto);
            }
            foreach (string key in dic.Keys)
            {
                List <SoLineDTO> listLineDTO = dic[key];

                if (listLineDTO != null &&
                    listLineDTO.Count > 0
                    )
                {
                    SoLineDTO firstDTO = listLineDTO.GetFirst <SoLineDTO>();

                    SO so = SO.Finder.Find("DescFlexField.PubDescSeg5=@DmsSaleNum"
                                           , new OqlParam(firstDTO.DmsSaleNo)
                                           );

                    // 订单存在,添加到订单清单里
                    if (so != null)
                    {
                        lstExist.Add(so);
                    }
                    //
                    else
                    {
                        SaleOrderDTOData sodto = new SaleOrderDTOData();
                        sodto.DocumentType      = (new CommonArchiveDataDTOData());
                        sodto.DocumentType.Code = (firstDTO.OrderType);
                        sodto.OrderBy           = (new CustomerMISCInfoData());
                        sodto.OrderBy.Code      = (firstDTO.DealerCode);
                        sodto.SOSrcType         = (SOSourceTypeEnum.Manual.Value);
                        sodto.TC = (new CommonArchiveDataDTOData());
                        //sodto.TC.Code = (string.IsNullOrEmpty(firstDTO.Currency) ? "C001" : firstDTO.Currency);
                        sodto.TC.Code                   = (string.IsNullOrEmpty(firstDTO.Currency) ? HBHCommon.DefaultCurrencyCode : firstDTO.Currency);
                        sodto.DescFlexField             = (new DescFlexSegmentsData());
                        sodto.DescFlexField.PubDescSeg5 = (firstDTO.DmsSaleNo);
                        //string RecTerm = "01";
                        string   RecTerm  = HBHCommon.DefaultRecTermCode;
                        Customer customer = Customer.Finder.Find(string.Format("Org={0} and Code='{1}'", Context.LoginOrg.ID, firstDTO.DealerCode), new OqlParam[0]);

                        sodto.SaleDepartment = new CommonArchiveDataDTOData();
                        sodto.Seller         = new CommonArchiveDataDTOData();
                        if (customer != null)
                        {
                            sodto.ConfirmTerm = (new CommonArchiveDataDTOData());
                            if (customer.ARConfirmTerm != null)
                            {
                                sodto.ConfirmTerm.Code = (customer.ARConfirmTerm.Code);
                            }
                            else
                            {
                                sodto.ConfirmTerm.Code = HBHCommon.DefaultConfirmTermCode;  // ("01");
                            }
                            sodto.BargainMode = (customer.Bargain.Value);
                            sodto.ShipRule    = (new CommonArchiveDataDTOData());
                            if (customer.ShippmentRuleKey != null)
                            {
                                sodto.ShipRule.Code = (customer.ShippmentRule.Code);
                            }
                            else
                            {
                                sodto.ShipRule.Code = HBHCommon.DefaultShipRuleCode;    // ("C001");
                            }
                            if (customer.RecervalTermKey != null)
                            {
                                RecTerm = customer.RecervalTerm.Code;
                            }

                            if (customer.SaleserKey != null)
                            {
                                sodto.Seller.ID = customer.SaleserKey.ID;
                                //Operators opeator = Operators.Finder.Find(string.Format("Org={0} and Code='{1}'", Context.LoginOrg.ID.ToString(), HBHCommon.DefaultShipOperatorCode), new OqlParam[0]);
                                //if (opeator != null)
                                //{
                                //    shipdto.SaleDept.ID = (opeator.DeptKey.ID);
                                //}
                            }
                            if (customer.DepartmentKey != null)
                            {
                                sodto.SaleDepartment.ID = customer.DepartmentKey.ID;
                            }
                        }
                        else
                        {
                            sodto.ShipRule.Code    = HBHCommon.DefaultShipRuleCode;    // ("C001");
                            sodto.BargainMode      = HBHCommon.DefaultBargainMode;     // (0);
                            sodto.ConfirmTerm      = (new CommonArchiveDataDTOData());
                            sodto.ConfirmTerm.Code = HBHCommon.DefaultConfirmTermCode; // ("01");
                        }
                        sodto.SOLines = new List <ISV.SM.SOLineDTOData>();
                        foreach (SoLineDTO srcsolinedto in dic[key])
                        {
                            UFIDA.U9.ISV.SM.SOLineDTOData solinedto2 = new UFIDA.U9.ISV.SM.SOLineDTOData();
                            solinedto2.ItemInfo          = (new ItemInfoData());
                            solinedto2.ItemInfo.ItemCode = (srcsolinedto.ErpMaterialCode);
                            if (!string.IsNullOrEmpty(srcsolinedto.FinalPrice))
                            {
                                solinedto2.FinallyPriceTC = (decimal.Parse(srcsolinedto.FinalPrice));
                            }
                            if (!string.IsNullOrEmpty(srcsolinedto.Number))
                            {
                                solinedto2.OrderByQtyPU = (decimal.Parse(srcsolinedto.Number));
                            }
                            else
                            {
                                solinedto2.OrderByQtyPU = (1m);
                            }
                            if (!string.IsNullOrEmpty(srcsolinedto.Money))
                            {
                                solinedto2.TotalMoneyTC = (decimal.Parse(srcsolinedto.Money));
                            }
                            solinedto2.Project       = (new CommonArchiveDataDTOData());
                            solinedto2.Project.Code  = (srcsolinedto.DmsSaleNo);
                            solinedto2.SrcDocType    = (SOSourceTypeEnum.Manual.Value);
                            solinedto2.RecTerm       = (new CommonArchiveDataDTOData());
                            solinedto2.RecTerm.Code  = (RecTerm);
                            solinedto2.DescFlexField = (new DescFlexSegmentsData());
                            solinedto2.DescFlexField.PrivateDescSeg1 = (srcsolinedto.MaterialCode);
                            solinedto2.SOShiplines = (new System.Collections.Generic.List <SOShipLineDTOData>());
                            SOShipLineDTOData soshipliendto = new SOShipLineDTOData();
                            soshipliendto.Project           = (new CommonArchiveDataDTOData());
                            soshipliendto.Project.Code      = (srcsolinedto.DmsSaleNo);
                            soshipliendto.ItemInfo          = (new ItemInfoData());
                            soshipliendto.ItemInfo.ItemCode = (srcsolinedto.ErpMaterialCode);
                            soshipliendto.IsMRPRequire      = (true);
                            soshipliendto.RequireDate       = (string.IsNullOrEmpty(srcsolinedto.DeliveryDate) ? System.DateTime.Now : System.Convert.ToDateTime(srcsolinedto.DeliveryDate));
                            solinedto2.SOShiplines.Add(soshipliendto);
                            sodto.SOLines.Add(solinedto2);
                        }
                        list.Add(sodto);
                    }
                }
            }
            return(list);
        }
        // 得到销售订单dto
        /// <summary>
        /// 得到销售订单dto
        /// </summary>
        /// <param name="bpObj"></param>
        /// <returns></returns>
        private System.Collections.Generic.List<SaleOrderDTOData> GetSaleOrderDTODataList(CreateApprovedSaleOrderSV bpObj,out List<SO> lstExist)
        {
            lstExist = new List<SO>();

            System.Collections.Generic.List<SaleOrderDTOData> list = new System.Collections.Generic.List<SaleOrderDTOData>();
            System.Collections.Generic.Dictionary<string, System.Collections.Generic.List<SoLineDTO>> dic = new System.Collections.Generic.Dictionary<string, System.Collections.Generic.List<SoLineDTO>>();
            foreach (SoLineDTO solinedto in bpObj.SoLineDto)
            {
                if (!dic.ContainsKey(solinedto.SpitOrderFlag))
                {
                    dic.Add(solinedto.SpitOrderFlag, new System.Collections.Generic.List<SoLineDTO>());
                }
                dic[solinedto.SpitOrderFlag].Add(solinedto);
            }
            foreach (string key in dic.Keys)
            {
                List<SoLineDTO> listLineDTO = dic[key];

                if (listLineDTO != null
                    && listLineDTO.Count > 0
                    )
                {
                    SoLineDTO firstDTO = listLineDTO.GetFirst<SoLineDTO>();

                    SO so = SO.Finder.Find("DescFlexField.PubDescSeg5=@DmsSaleNum"
                        , new OqlParam(firstDTO.DmsSaleNo)
                        );

                    // 订单存在,添加到订单清单里
                    if (so != null)
                    {
                        lstExist.Add(so);
                    }
                    //
                    else
                    {
                        SaleOrderDTOData sodto = new SaleOrderDTOData();
                        sodto.DocumentType = (new CommonArchiveDataDTOData());
                        sodto.DocumentType.Code = (firstDTO.OrderType);
                        sodto.OrderBy = (new CustomerMISCInfoData());
                        sodto.OrderBy.Code = (firstDTO.DealerCode);
                        sodto.SOSrcType = (SOSourceTypeEnum.Manual.Value);
                        sodto.TC = (new CommonArchiveDataDTOData());
                        //sodto.TC.Code = (string.IsNullOrEmpty(firstDTO.Currency) ? "C001" : firstDTO.Currency);
                        sodto.TC.Code = (string.IsNullOrEmpty(firstDTO.Currency) ? HBHCommon.DefaultCurrencyCode : firstDTO.Currency);
                        sodto.DescFlexField = (new DescFlexSegmentsData());
                        sodto.DescFlexField.PubDescSeg5 = (firstDTO.DmsSaleNo);
                        //string RecTerm = "01";
                        string RecTerm = HBHCommon.DefaultRecTermCode;
                        Customer customer = Customer.Finder.Find(string.Format("Org={0} and Code='{1}'", Context.LoginOrg.ID, firstDTO.DealerCode), new OqlParam[0]);

                        sodto.SaleDepartment = new CommonArchiveDataDTOData();
                        sodto.Seller = new CommonArchiveDataDTOData();
                        if (customer != null)
                        {
                            sodto.ConfirmTerm = (new CommonArchiveDataDTOData());
                            if (customer.ARConfirmTerm != null)
                            {
                                sodto.ConfirmTerm.Code = (customer.ARConfirmTerm.Code);
                            }
                            else
                            {
                                sodto.ConfirmTerm.Code = HBHCommon.DefaultConfirmTermCode;  // ("01");
                            }
                            sodto.BargainMode = (customer.Bargain.Value);
                            sodto.ShipRule = (new CommonArchiveDataDTOData());
                            if (customer.ShippmentRuleKey != null)
                            {
                                sodto.ShipRule.Code = (customer.ShippmentRule.Code);
                            }
                            else
                            {
                                sodto.ShipRule.Code = HBHCommon.DefaultShipRuleCode;    // ("C001");
                            }
                            if (customer.RecervalTermKey != null)
                            {
                                RecTerm = customer.RecervalTerm.Code;
                            }

                            if (customer.SaleserKey != null)
                            {
                                sodto.Seller.ID = customer.SaleserKey.ID;
                                //Operators opeator = Operators.Finder.Find(string.Format("Org={0} and Code='{1}'", Context.LoginOrg.ID.ToString(), HBHCommon.DefaultShipOperatorCode), new OqlParam[0]);
                                //if (opeator != null)
                                //{
                                //    shipdto.SaleDept.ID = (opeator.DeptKey.ID);
                                //}
                            }
                            if (customer.DepartmentKey != null)
                            {
                                sodto.SaleDepartment.ID = customer.DepartmentKey.ID;
                            }
                        }
                        else
                        {
                            sodto.ShipRule.Code = HBHCommon.DefaultShipRuleCode;    // ("C001");
                            sodto.BargainMode = HBHCommon.DefaultBargainMode;    // (0);
                            sodto.ConfirmTerm = (new CommonArchiveDataDTOData());
                            sodto.ConfirmTerm.Code = HBHCommon.DefaultConfirmTermCode;  // ("01");
                        }
                        sodto.SOLines = new List<ISV.SM.SOLineDTOData>();
                        foreach (SoLineDTO srcsolinedto in dic[key])
                        {
                            UFIDA.U9.ISV.SM.SOLineDTOData solinedto2 = new UFIDA.U9.ISV.SM.SOLineDTOData();
                            solinedto2.ItemInfo = (new ItemInfoData());
                            solinedto2.ItemInfo.ItemCode = (srcsolinedto.ErpMaterialCode);
                            if (!string.IsNullOrEmpty(srcsolinedto.FinalPrice))
                            {
                                solinedto2.FinallyPriceTC = (decimal.Parse(srcsolinedto.FinalPrice));
                            }
                            if (!string.IsNullOrEmpty(srcsolinedto.Number))
                            {
                                solinedto2.OrderByQtyPU = (decimal.Parse(srcsolinedto.Number));
                            }
                            else
                            {
                                solinedto2.OrderByQtyPU = (1m);
                            }
                            if (!string.IsNullOrEmpty(srcsolinedto.Money))
                            {
                                solinedto2.TotalMoneyTC = (decimal.Parse(srcsolinedto.Money));
                            }
                            solinedto2.Project = (new CommonArchiveDataDTOData());
                            solinedto2.Project.Code = (srcsolinedto.DmsSaleNo);
                            solinedto2.SrcDocType = (SOSourceTypeEnum.Manual.Value);
                            solinedto2.RecTerm = (new CommonArchiveDataDTOData());
                            solinedto2.RecTerm.Code = (RecTerm);
                            solinedto2.DescFlexField = (new DescFlexSegmentsData());
                            solinedto2.DescFlexField.PrivateDescSeg1 = (srcsolinedto.MaterialCode);
                            solinedto2.SOShiplines = (new System.Collections.Generic.List<SOShipLineDTOData>());
                            SOShipLineDTOData soshipliendto = new SOShipLineDTOData();
                            soshipliendto.Project = (new CommonArchiveDataDTOData());
                            soshipliendto.Project.Code = (srcsolinedto.DmsSaleNo);
                            soshipliendto.ItemInfo = (new ItemInfoData());
                            soshipliendto.ItemInfo.ItemCode = (srcsolinedto.ErpMaterialCode);
                            soshipliendto.IsMRPRequire = (true);
                            soshipliendto.RequireDate = (string.IsNullOrEmpty(srcsolinedto.DeliveryDate) ? System.DateTime.Now : System.Convert.ToDateTime(srcsolinedto.DeliveryDate));
                            solinedto2.SOShiplines.Add(soshipliendto);
                            sodto.SOLines.Add(solinedto2);
                        }
                        list.Add(sodto);
                    }
                }
            }
            return list;
        }