using ICS.WCF.Base;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.ServiceModel;
using System.Text;
using System.Threading.Tasks;
using UFSoft.UBF.Business.BusinessEntity;
using UFSoft.UBF.Service;
using UFSoft.UBF.Util.Context;
using www.ufida.org.EntityData;
using ICSSoft.Entity;
using Newtonsoft.Json;
using ICS.CreateLotMaster;

namespace UFIDA.ISV.CreateBFTransferFormForItem
{

    public class CustCreateBFFormTransferSrvSub
    {
        //private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
        private static string connString = System.Configuration.ConfigurationManager.AppSettings["ERPConnStr"];
        private static string ERPDB = System.Configuration.ConfigurationManager.AppSettings["ERPDB"];
        public Result CustCreateBFFormTransfer(List<ICSAssemVouch> infos)
        {
            Result res = new Result();
            var datalist = new List<ICSAssemVouch>();
            List<rtnRcvInfo> rtnpos = new List<rtnRcvInfo>();
            foreach (ICSAssemVouch model in infos)
            {
                string TransferTypeCode = "";
                long TransferTypeID = 0;
                rCVhead rCVInfo = new rCVhead();
                rCVInfo.TransferType = model.TransferType;// "TransForm009";
                rCVInfo.StorageType = 4;
                rCVInfo.OrgCode = model.WorkPoint;
                rCVInfo.Memo = "";
                rCVInfo.lines = new List<rCVLine>();
                var group = model.details.GroupBy(e => e.GroupNO);
                foreach (var data in group)
                {
                    rCVLine rCV = new rCVLine();
                    foreach (var dataDetail in data)
                    {
                        if (dataDetail.Type == "转换前")
                        {
                            rCV.Sequence = dataDetail.Sequence;
                            rCV.ItemCodeBefore = dataDetail.InvCode;
                            rCV.LotBefore = dataDetail.BatchCode;
                            rCV.ProjectBefroe = dataDetail.ProjectCode;
                            rCV.TransferQTYBefore = dataDetail.Quantity;
                            rCV.WHCode = dataDetail.WHCode;
                            rCV.ItemVersionBefore = dataDetail.Version;

                            rCV.cFree1 = dataDetail.cFree1;
                            rCV.cFree2 = dataDetail.cFree2;
                            rCV.cFree3 = dataDetail.cFree3;
                            rCV.cFree4 = dataDetail.cFree4;
                            rCV.cFree5 = dataDetail.cFree5;
                            rCV.cFree6 = dataDetail.cFree6;
                            rCV.cFree7 = dataDetail.cFree7;
                            rCV.cFree8 = dataDetail.cFree8;
                            rCV.cFree9 = dataDetail.cFree9;
                            rCV.cFree10 = dataDetail.cFree10;
                        }
                        else
                        {
                            rCV.Sequence = dataDetail.Sequence;
                            rCV.ItemCodeAfter = dataDetail.InvCode;
                            rCV.LotAfter = dataDetail.BatchCode;
                            rCV.ProjectAfter = dataDetail.ProjectCode;
                            rCV.TranferQTYAfter = dataDetail.Quantity;
                            rCV.WHCode = dataDetail.WHCode;
                            rCV.ProductDate = dataDetail.ProductDate;
                            rCV.ItemVersionAfter = dataDetail.Version;

                            rCV.AftercFree1 = dataDetail.cFree1;
                            rCV.AftercFree2 = dataDetail.cFree2;
                            rCV.AftercFree3 = dataDetail.cFree3;
                            rCV.AftercFree4 = dataDetail.cFree4;
                            rCV.AftercFree5 = dataDetail.cFree5;
                            rCV.AftercFree6 = dataDetail.cFree6;
                            rCV.AftercFree7 = dataDetail.cFree7;
                            rCV.AftercFree8 = dataDetail.cFree8;
                            rCV.AftercFree9 = dataDetail.cFree9;
                            rCV.AftercFree10 = dataDetail.cFree10;

                        }
                    }

                    rCV.SupplierCode = model.SupplierCode;
                    rCVInfo.lines.Add(rCV);
                }



                #region 服务调用框架结构
                UFIDAU9ISVTransferFormISVICommonCreateTransferFormSRVClient client = new UFIDAU9ISVTransferFormISVICommonCreateTransferFormSRVClient();
                //服务返回结果
                UFIDAU9CBOPubControllerCommonArchiveDataDTOData[] returnItems;
                //返回异常信息，目前还没有使用此属性
                UFSoft.UBF.Exceptions1.MessageBase[] returnMsg;
                //上下文信息
                object context;
                //传入 参数
                UFIDAU9ISVTransferFormISVIC_TransferFormDTOData[] pOList;
                //空
                string[] splitBy = new string[] { };
                //int DocLine = 10;
                long WHID = 0;
                string DocNo = "";
                string OrgID = "";
                List<DataLine> list = new List<DataLine>();
                try
                {

                    long PickID = 0;
                    long ItemID = 0;
                    if (rCVInfo == null)
                    {

                        throw new Exception("传入参数不能为空");
                    }
                    if (rCVInfo.StorageType == null)
                    {
                        throw new Exception("存储类型不能为空");
                    }

                    string orgsql = @"select ID from Base_Organization
                                  where Code='{0}'";
                    orgsql = string.Format(orgsql, rCVInfo.OrgCode);
                    DataTable orgdt = DBhlper.Query(orgsql, connString);
                    if (orgdt.Rows.Count != 0)
                    {
                        OrgID = orgdt.Rows[0]["ID"].ToString();
                    }
                    else
                    {
                        throw new Exception("组织编码:" + rCVInfo.OrgCode + "不存在!");
                    }
                    foreach (rCVLine item in rCVInfo.lines)
                    {
                        if (item == null)
                        {
                            throw new Exception("传入行信息不能为空");
                        }
                        if (item.TransferQTYBefore == 0)
                        {
                            throw new Exception("转换前数量不能为0");
                        }
                        if (item.TranferQTYAfter == 0)
                        {
                            throw new Exception("转换后数量不能为0");
                        }
                        string whsql = @"select ID from CBO_Wh
                                     where Code='{0}' and org ='{1}'";
                        whsql = string.Format(whsql, item.WHCode, OrgID);
                        DataTable whdt = DBhlper.Query(whsql, connString);
                        if (whdt.Rows.Count == 0)
                        {
                            throw new Exception("仓库不存在");
                        }

                        WHID = long.Parse(whdt.Rows[0]["ID"].ToString());

                        //验证转换前信息是否正确

                        #region 根据传入数据判断形态转换单类型
                        bool ItemTransfer = false;
                        bool LotTransfer = false;
                        bool ProjectTrasnfer = false;
                        bool QtyTransfer = false;
                        bool ItemVersion = false;
                        string DocTypestr = "";
                        if (item.ItemCodeBefore != item.ItemCodeAfter)
                        {
                            DocTypestr += " AND IsChangeItem='true'";
                            ItemTransfer = true;
                        }
                        else
                        {
                            DocTypestr += " AND IsChangeItem='false'";
                        }

                        if (item.ItemVersionBefore != item.ItemVersionAfter)
                        {
                            DocTypestr += " AND IsChangeItemVer='true'";
                            ItemVersion = true;
                        }
                        else
                        {
                            DocTypestr += " AND IsChangeItemVer='false'";
                        }


                        if (item.LotBefore != item.LotAfter)
                        {
                            DocTypestr += " AND IsChangeLot='true'";
                            LotTransfer = true;
                        }
                        else
                        {
                            DocTypestr += " AND IsChangeLot='false'";
                        }
                        if (item.ProjectBefroe != item.ProjectAfter)
                        {
                            DocTypestr += " AND IsChangeProject='true'";
                            ProjectTrasnfer = true;
                        }
                        else
                        {
                            DocTypestr += " AND IsChangeProject='false'";
                        }
                        if (ItemTransfer == false && LotTransfer == false && ProjectTrasnfer == false && item.TransferQTYBefore != item.TranferQTYAfter)
                        {
                            DocTypestr += " AND IsSTorCoQty='true'";
                            QtyTransfer = true;
                        }
                        else
                        {
                            DocTypestr += " AND IsSTorCoQty='false'";
                        }
                        if (ItemTransfer == false && LotTransfer == false && ProjectTrasnfer == false && QtyTransfer == false && ItemVersion == false)
                        {
                            throw new Exception("传入料号:" + item.ItemCodeBefore + "转换前后数据完全相同，无法进行形态转换，请重新维护单据!");
                        }
                        string typesql = @"select ID,Code from InvDoc_TransferFormDocType
                                           where Org='{0}'";
                        typesql = string.Format(typesql, OrgID);
                        typesql += DocTypestr;
                        DataTable typedt = DBhlper.Query(typesql, connString);
                        if (typedt.Rows.Count == 0)
                        {
                            throw new Exception("传入数据对应的U9形态转换单单据类型未维护，请先维护对应的单据类型!");
                        }
                        else
                        {
                            TransferTypeCode = typedt.Rows[0]["Code"].ToString();
                            TransferTypeID = long.Parse(typedt.Rows[0]["ID"].ToString());
                        }
                        #endregion
                    }


                    //给上下文信息赋值
                    context = CreateContextObj(OrgID);


                    List<UFIDAU9ISVTransferFormISVIC_TransferFormDTOData> transferList = new List<UFIDAU9ISVTransferFormISVIC_TransferFormDTOData>();
                    List<UFIDAU9ISVTransferFormISVIC_TransferFormLDTOData> transferLineList = new List<UFIDAU9ISVTransferFormISVIC_TransferFormLDTOData>();
                    UFIDAU9ISVTransferFormISVIC_TransferFormDTOData transferinfo = new UFIDAU9ISVTransferFormISVIC_TransferFormDTOData();
                    transferinfo.m_transferFormTransType = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
                    transferinfo.m_transferFormTransType.m_iD = TransferTypeID;
                    transferinfo.m_transferFormTransType.m_code = TransferTypeCode;
                    transferinfo.m_org = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
                    transferinfo.m_org.m_iD = long.Parse(OrgID);
                    transferinfo.m_org.m_code = rCVInfo.OrgCode;
                    transferinfo.m_memo = rCVInfo.Memo;
                    foreach (rCVLine line in rCVInfo.lines)
                    {
                        long CPID = 0;
                        string CPCode = "";
                        string CPName = "";
                        long SupplierID = 0;
                        string SupplierName = "";
                        var doclino = int.Parse(line.Sequence) * 10;
                        #region 厂牌查询
                        string cpsql = @"select B.Code,C.Name,B.ID from CBO_ItemMaster A
                                     LEFT JOIN CBO_Supplier B ON B.ID=A.TradeMark
                                     LEFT JOIN CBO_Supplier_Trl C ON C.ID=B.ID
                                     where A.Code='{0}' AND A.Org='{1}' AND ISNULL(A.TradeMark,'')!='' and a.Version ='{2}'";
                        cpsql = string.Format(cpsql, line.ItemCodeBefore, OrgID, line.ItemVersionBefore);
                        DataTable cpdt = DBhlper.Query(cpsql, connString);
                        if (cpdt.Rows.Count == 0)
                        {
                            CPID = 0;
                            CPCode = "";
                            CPName = "";
                        }
                        else
                        {
                            CPID = long.Parse(cpdt.Rows[0]["ID"].ToString());
                            CPCode = cpdt.Rows[0]["Code"].ToString();
                            CPName = cpdt.Rows[0]["Name"].ToString();
                        }
                        #endregion
                        if (!string.IsNullOrEmpty(line.SupplierCode))
                        {
                            string suppliersql = @"select A.ID,B.Name from CBO_Supplier A
                                               LEFT JOIN CBO_Supplier_Trl B ON B.ID=A.ID
                                               where A.Code='{0}' AND A.Org='{1}'";
                            suppliersql = string.Format(suppliersql, line.SupplierCode, OrgID);
                            DataTable supplierdt = DBhlper.Query(suppliersql, connString);
                            if (supplierdt.Rows.Count == 0)
                            {
                                res.Success = false;
                                res.Message = "供应商编码:" + line.SupplierCode + "不存在!";

                                return res;
                            }
                            else
                            {
                                SupplierID = long.Parse(supplierdt.Rows[0]["ID"].ToString());
                                SupplierName = supplierdt.Rows[0]["Name"].ToString();
                            }
                        }
                        UFIDAU9ISVTransferFormISVIC_TransferFormLDTOData transferlineinfo = new UFIDAU9ISVTransferFormISVIC_TransferFormLDTOData();
                        //转换前信息
                        transferlineinfo.m_transferType = 0;
                        transferlineinfo.m_isCostDependent = true;
                        transferlineinfo.m_docLineNo = doclino.ToString();
                        transferlineinfo.m_storeType = 4;
                        if (!string.IsNullOrEmpty(line.SupplierCode))
                        {
                            transferlineinfo.m_supplierInfo = new UFIDAU9CBOSCMSupplierSupplierMISCInfoData();
                            transferlineinfo.m_supplierInfo.Supplier = SupplierID;
                            transferlineinfo.m_supplierInfo.m_code = line.SupplierCode;
                            transferlineinfo.m_supplierInfo.Name = SupplierName;
                            transferlineinfo.m_supplierInfo.Supplier_SKey = new EntityKey();
                            transferlineinfo.m_supplierInfo.Supplier_SKey.ID = SupplierID;

                        }
                        if (CPID != 0)
                        {
                            transferlineinfo.m_manufacturerInfo = new UFIDAU9CBOSCMSupplierSupplierMISCInfoData();
                            transferlineinfo.m_manufacturerInfo.Supplier = CPID;
                            transferlineinfo.m_manufacturerInfo.Supplier_SKey = new EntityKey();
                            transferlineinfo.m_manufacturerInfo.Supplier_SKey.ID = CPID;
                            transferlineinfo.m_manufacturerInfo.m_code = CPCode;
                            transferlineinfo.m_manufacturerInfo.Name = CPName;
                        }


                        string sqlitemcheck = @"select a.ID from CBO_ItemMaster a
                                left join CBO_ItemMasterVersion b on a.ID = b.Item
                                where a.Code ='" + line.ItemCodeBefore + "' and a.Org =" + OrgID;

                        if (!string.IsNullOrEmpty(line.ItemVersionBefore))
                        {
                            sqlitemcheck += "' and b.Version ='" + line.ItemVersionBefore + "'";
                        }

                        //string sqlitemcheck = "select ID from CBO_ItemMaster where Code ='" + line.ItemCodeBefore + "' and Version ='" + line.cFree1 + "' and Org ='" + OrgID + "'";
                        DataTable itemcheckdt = DBhlper.Query(sqlitemcheck, connString);
                        if (itemcheckdt.Rows.Count == 0)
                        {
                            throw new Exception("转换前料品编码:" + line.ItemCodeBefore + "不存在!");
                        }

                        long ItemBfID = long.Parse(itemcheckdt.Rows[0]["ID"].ToString());


                        sqlitemcheck = @"select a.ID from CBO_ItemMaster a
                                left join CBO_ItemMasterVersion b on a.ID = b.Item
                                where a.Code ='" + line.ItemCodeAfter + "' and a.Org =" + OrgID;


                        if (!string.IsNullOrEmpty(line.ItemVersionAfter))
                        {
                            sqlitemcheck += "' and b.Version ='" + line.ItemVersionAfter + "'";
                        }

                        //sqlitemcheck = "select ID from CBO_ItemMaster where Code ='" + line.ItemCodeAfter + "' and Version ='" + line.AftercFree1 + "' and Org ='" + OrgID + "'";
                        itemcheckdt = DBhlper.Query(sqlitemcheck, connString);
                        if (itemcheckdt.Rows.Count == 0)
                        {
                            throw new Exception("转换后料品编码:" + line.ItemCodeAfter + "不存在!");
                        }

                        long ItemAfID = long.Parse(itemcheckdt.Rows[0]["ID"].ToString());

                        transferlineinfo.m_itemInfo = new UFIDAU9CBOSCMItemItemInfoData();
                        transferlineinfo.m_itemInfo.m_itemCode = line.ItemCodeBefore;
                        transferlineinfo.m_itemInfo.ItemID = ItemBfID;
                        transferlineinfo.m_lotInfo = new UFIDAU9LotLotMasterInfoData();
                        if (!String.IsNullOrEmpty(line.LotBefore))
                        {
                            transferlineinfo.m_lotInfo.m_lotCode = line.LotBefore;
                        }

                        transferlineinfo.m_project = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
                        if (!String.IsNullOrEmpty(line.ProjectBefroe))
                        {
                            transferlineinfo.m_project.m_code = line.ProjectBefroe;
                        }

                        transferlineinfo.m_storeUOMQty = line.TransferQTYBefore;
                        transferlineinfo.m_wh = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
                        transferlineinfo.m_wh.m_iD = WHID;


                        transferlineinfo.m_descFlexSegments = new UFIDAU9BaseFlexFieldDescFlexFieldDescFlexSegmentsData();
                        transferlineinfo.m_descFlexSegments.m_privateDescSeg30 = line.LogIds;
                        transferlineinfo.m_isCostDependent = true;

                        //转换后信息
                        List<UFIDAU9ISVTransferFormISVIC_TransferFormSLDTOData> transferAfterList = new List<UFIDAU9ISVTransferFormISVIC_TransferFormSLDTOData>();
                        UFIDAU9ISVTransferFormISVIC_TransferFormSLDTOData transferAfterInfo = new UFIDAU9ISVTransferFormISVIC_TransferFormSLDTOData();
                        transferAfterInfo.m_transferType = 1;
                        transferAfterInfo.m_itemInfo = new UFIDAU9CBOSCMItemItemInfoData();
                        transferAfterInfo.m_itemInfo.m_itemCode = line.ItemCodeAfter;
                        transferAfterInfo.m_itemInfo.ItemID = ItemAfID;
                        transferAfterInfo.m_storeType = 4;
                        if (!string.IsNullOrEmpty(line.SupplierCode))
                        {
                            transferAfterInfo.m_supplierInfo = new UFIDAU9CBOSCMSupplierSupplierMISCInfoData();
                            transferAfterInfo.m_supplierInfo.Supplier = SupplierID;
                            transferAfterInfo.m_supplierInfo.m_code = line.SupplierCode;
                            transferAfterInfo.m_supplierInfo.Name = SupplierName;
                            transferAfterInfo.m_supplierInfo.Supplier_SKey = new EntityKey();
                            transferAfterInfo.m_supplierInfo.Supplier_SKey.ID = SupplierID;
                        }
                        if (CPID != 0)
                        {
                            transferAfterInfo.m_manufacturerInfo = new UFIDAU9CBOSCMSupplierSupplierMISCInfoData();
                            transferAfterInfo.m_manufacturerInfo.Supplier = CPID;
                            transferAfterInfo.m_manufacturerInfo.Supplier_SKey = new EntityKey();
                            transferAfterInfo.m_manufacturerInfo.Supplier_SKey.ID = CPID;
                            transferAfterInfo.m_manufacturerInfo.m_code = CPCode;
                            transferAfterInfo.m_manufacturerInfo.Name = CPName;
                        }
                        transferAfterInfo.m_lotInfo = new UFIDAU9LotLotMasterInfoData();
                        if (!String.IsNullOrEmpty(line.LotAfter))
                        {
                            string lotsql = @"  select A.ID from Lot_LotMaster A
                                                LEFT JOIN CBO_ItemMaster B ON B.ID=A.Item
                                                WHERE A.LotCode='{0}' AND B.Code='{1}' AND B.Org='{2}'";
                            lotsql = string.Format(lotsql, line.LotAfter, line.ItemCodeAfter, OrgID);
                            DataTable lotdt = DBhlper.Query(lotsql, connString);
                            if (lotdt.Rows.Count != 0)
                            {
                                transferAfterInfo.m_lotInfo.m_lotCode = line.LotAfter;
                            }
                            else
                            {
                                if (string.IsNullOrEmpty(line.ProductDate))
                                {
                                    #region 先创建批号(不传入批号生效日期的情况)
                                    string LotID = "";
                                    CustCreateLotMaster LotMasterCreate = new CustCreateLotMaster();
                                    string lotWHCode = line.WHCode;
                                    string lotItemCode = line.ItemCodeAfter;
                                    string LotCode = line.LotAfter;
                                    LotMasterCreate.CustCreateRCVLotMaster(lotWHCode, lotItemCode, LotCode, OrgID, ref LotID);
                                    if (LotID == "")
                                    {
                                        res.Success = false;
                                        res.Message = "新批号创建失败!";
                                        return res;
                                    }
                                    else
                                    {
                                        transferAfterInfo.m_lotInfo.LotMaster = long.Parse(LotID);
                                        transferAfterInfo.m_lotInfo.m_lotCode = line.LotAfter;
                                    }
                                    #endregion
                                }
                                else
                                {
                                    #region 先创建批号
                                    string LotID = "";
                                    CustCreateLotMaster LotMasterCreate = new CustCreateLotMaster();
                                    string lotWHCode = line.WHCode;
                                    string lotItemCode = line.ItemCodeAfter;
                                    string LotCode = line.LotAfter;
                                    LotMasterCreate.CreateLotMasterWithProductDate(lotWHCode, lotItemCode, LotCode, line.ProductDate, OrgID, ref LotID);
                                    if (LotID == "")
                                    {
                                        res.Success = false;
                                        res.Message = "新批号创建失败!";
                                        return res;
                                    }
                                    else
                                    {
                                        transferAfterInfo.m_lotInfo.LotMaster = long.Parse(LotID);
                                        transferAfterInfo.m_lotInfo.m_lotCode = line.LotAfter;
                                    }
                                    #endregion
                                }
                            }
                        }

                        transferAfterInfo.m_project = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
                        if (!String.IsNullOrEmpty(line.ProjectAfter))
                        {
                            transferAfterInfo.m_project.m_code = line.ProjectAfter;
                        }
                        transferAfterInfo.m_storeUOMQty = line.TranferQTYAfter;
                        transferAfterInfo.m_wh = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
                        transferAfterInfo.m_wh.m_iD = WHID;
                        transferAfterInfo.m_docSubLineNo = doclino.ToString();


                        transferAfterList.Add(transferAfterInfo);
                        transferlineinfo.m_transferFormSubLine = transferAfterList.ToArray();
                        transferLineList.Add(transferlineinfo);
                        transferinfo.m_transferFormLine = transferLineList.ToArray();
                    }
                    transferList.Add(transferinfo);
                    pOList = transferList.ToArray();

                    (client.Endpoint.Binding as BasicHttpBinding).MaxReceivedMessageSize = int.MaxValue;
                    (client.Endpoint.Binding as BasicHttpBinding).MaxBufferSize = int.MaxValue;

                    returnItems = client.Do(out returnMsg, context, pOList);



                    string rtnsql = @" select DocNo, bb.Name,c.ID,d.ID ShipID from InvDoc_TransferForm a
                                LEFT JOIN InvDoc_TransferFormDocType b ON a.TransferFormDocType = b.ID
                                LEFT JOIN InvDoc_TransferFormDocType_Trl bb ON bb.ID = b.ID
                        LEFT JOIN InvDoc_TransferFormL c ON c.TransferForm=a.ID
                        LEFT JOIN InvDoc_TransferFormSL d ON d.TransferFormL=c.ID
                                 where a.ID='{0}'";

                    rtnsql = string.Format(rtnsql, returnItems[0].m_iD);
                    DataTable rtndt = DBhlper.Query(rtnsql, connString);
                    if (rtndt.Rows.Count != 0)
                    {
                        DocNo = rtndt.Rows[0]["DocNo"].ToString();

                        if (rtndt.Rows[0]["Name"].ToString().Contains("数量"))
                        {
                            foreach (DataRow item in rtndt.Rows)
                            {
                                if (!string.IsNullOrEmpty(item["ID"].ToString()))
                                {
                                    string updatesql = @"UPDATE InvDoc_TransferFormL set IsCostDependent=1  where ID='{0}'";
                                    updatesql = string.Format(updatesql, item["ID"].ToString());
                                    DBhlper.EXecute(updatesql, Appconfig.GetU9ConnStr());

                                    string updatesqlship = @"UPDATE InvDoc_TransferFormSL set IsCostDependent=1  where ID='{0}'";
                                    updatesqlship = string.Format(updatesqlship, item["ShipID"].ToString());
                                    DBhlper.EXecute(updatesqlship, Appconfig.GetU9ConnStr());
                                }
                            }

                        }



                        #region MyRegion
                        //Data _data = new Data();
                        //List<DataLine> list = new List<DataLine>();
                        //string rtnsqlQ = @" select a.DocNo TransCode,a.ID, c.id DetailID,c.DocLineNo Sequence,c.ItemInfo_ItemCode InvCode,c.LotInfo_LotCode cBatch, 
                        //c.DescFlexSegments_PrivateDescSeg1 cFree1,c.DescFlexSegments_PrivateDescSeg2 cFree2,c.DescFlexSegments_PrivateDescSeg3 cFree3,
                        //c.DescFlexSegments_PrivateDescSeg4 cFree4,c.DescFlexSegments_PrivateDescSeg5 cFree5,c.DescFlexSegments_PrivateDescSeg6 cFree6,
                        //c.DescFlexSegments_PrivateDescSeg7 cFree7,c.DescFlexSegments_PrivateDescSeg8 cFree8,c.DescFlexSegments_PrivateDescSeg9 cFree9,
                        //c.DescFlexSegments_PrivateDescSeg10 cFree10
                        //                     from InvDoc_TransferForm a
                        //                     LEFT JOIN InvDoc_TransferFormL c ON c.TransferForm=a.ID
                        //                        where a.ID='{0}'";
                        //rtnsqlQ = string.Format(rtnsqlQ, returnItems[0].m_iD);
                        //DataTable rtndtQ = DBhlper.Query(rtnsqlQ, connString);
                        //if (rtndtQ.Rows.Count != 0)
                        //{
                        //    foreach (DataRow item in rtndtQ.Rows)
                        //    {
                        //        DataLine _DataLine = new DataLine();
                        //        _data.ID = item["ID"].ToString();
                        //        _data.TransCode = returnItems[0].m_code;
                        //        _DataLine.DetailID = item["DetailID"].ToString();
                        //        _DataLine.Sequence = Int32.Parse(item["Sequence"].ToString());
                        //        //_DataLine.Quantity = Decimal.Parse(item["Quantity"].ToString());
                        //        _DataLine.InvCode = item["InvCode"].ToString();
                        //        _DataLine.cBatch = item["cBatch"].ToString();
                        //        _DataLine.cFree1 = item["cFree1"].ToString();
                        //        _DataLine.cFree2 = item["cFree2"].ToString();
                        //        _DataLine.cFree3 = item["cFree3"].ToString();
                        //        _DataLine.cFree4 = item["cFree4"].ToString();
                        //        _DataLine.cFree5 = item["cFree5"].ToString();
                        //        _DataLine.cFree6 = item["cFree6"].ToString();
                        //        _DataLine.cFree7 = item["cFree7"].ToString();
                        //        _DataLine.cFree8 = item["cFree8"].ToString();
                        //        _DataLine.cFree9 = item["cFree9"].ToString();
                        //        _DataLine.cFree10 = item["cFree10"].ToString();

                        //        list.Add(_DataLine);
                        //    }
                        //}
                        #endregion



                        UFIDA.ISV.BFTransferFormCommit.CustBFTransFromCommit.ReturnValue1 commitresult = UFIDA.ISV.BFTransferFormCommit.CustBFTransFromCommit.CustApproveRec(rtndt.Rows[0]["DocNo"].ToString(), OrgID);
                        if (commitresult.IsSuccess)
                        {

                            res.Success = true;
                            res.Message = "形态转换单审核成功";
                            rtnRcv rtnRcv = new rtnRcv();
                            rtnRcv.ID = returnItems[0].m_iD.ToString();
                            rtnRcv.TransCode = rtndt.Rows[0]["DocNo"].ToString();
                            rtnRcv.details = new List<rtnRcvLine>();

                            string linesql = @"select ID,DocLineNo from InvDoc_TransferFormL 
                                  where  TransferForm ='{0}'";
                            linesql = string.Format(linesql, returnItems[0].m_iD);
                            DataTable lineData = DBhlper.Query(linesql, connString);
                            if (lineData.Rows.Count != 0)
                            {

                                for (int i = 0; i < lineData.Rows.Count; i++)
                                {
                                    rtnRcvLine rtnRcvLine = new rtnRcvLine();
                                    rtnRcvLine.ID = lineData.Rows[i]["ID"].ToString();
                                    rtnRcvLine.Sequence = lineData.Rows[i]["DocLineNo"].ToString();
                                    rtnRcvLine.LogId = "";
                                    rtnRcv.details.Add(rtnRcvLine);
                                }
                            }
                            res.Data = JsonConvert.SerializeObject(rtnRcv);
                            UFIDA.ISV.BFTransferFormApprove.CustBFTransFromApprove.ReturnValue1 result = UFIDA.ISV.BFTransferFormApprove.CustBFTransFromApprove.CustApproveRec(rtndt.Rows[0]["DocNo"].ToString(), OrgID);
                            if (result.IsSuccess)
                            {

                                rtnRcvInfo rtnpo = new rtnRcvInfo();
                                rtnpo.DocNo = rtndt.Rows[0]["DocNo"].ToString();
                                rtnpo.IsSuccess = true;
                                rtnpo.Message = "形态转换单审核成功";
                                rtnpos.Add(rtnpo);
                                #region 审核后修改单据审核人
                                string usersql = @"select Name from Base_User
                                                   where Code='{0}'";
                                usersql = string.Format(usersql, infos[0].User);
                                DataTable userdt = DBhlper.Query(usersql, Appconfig.GetU9ConnStr());
                                if (userdt.Rows.Count != 0)
                                {
                                    usersql = @"update InvDoc_TransferForm set CreatedBy='{0}',ApprovedBy='{0}',ModifiedBy='{0}'
                                    where DocNo ='{1}' AND Org='{2}'
                                    update InvDoc_TransferFormL set CreatedBy='{0}',ModifiedBy='{0}'
                                    where TransferForm = (select ID from InvDoc_TransferForm
								    where DocNo = '{1}' AND Org='{2}')";
                                    usersql = string.Format(usersql, userdt.Rows[0]["Name"].ToString(), rtndt.Rows[0]["DocNo"].ToString(), OrgID);
                                    DBhlper.Query(usersql, Appconfig.GetU9ConnStr());
                                }
                                #endregion


                                foreach (rCVLine item in rCVInfo.lines)
                                {
                                    var line = int.Parse(item.Sequence) * 10;

                                    string sql = @"select  a.DocLineNo,a.DescFlexSegments_PrivateDescSeg30,* from InvDoc_TransferFormL a
                                                join InvDoc_TransferForm b on a.TransferForm = b.ID
                                                where b.ID ='" + returnItems[0].m_iD.ToString() + "' and a.DocLineNo ='" + line + "'";
                                    DataTable dt = DBhlper.Query(sql, connString);
                                    if (dt.Rows.Count > 0)
                                    {
                                        var linelist = new List<ICSAssemVouchs>();
                                        foreach (DataRow dr in dt.Rows)
                                        {
                                            linelist.Add(new ICSAssemVouchs
                                            {
                                                Sequence = dr["DocLineNo"].ToString(),
                                                LogIds = dr["DescFlexSegments_PrivateDescSeg30"].ToString()
                                            });
                                        }

                                        datalist.Add(new ICSAssemVouch
                                        {
                                            IsSuccess = true,
                                            Message = "单据创建成功",
                                            details = linelist
                                        });
                                    }
                                }
                            }
                            else
                            {
                                throw new Exception("审核失败：" + commitresult.Mes);
                            }
                        }
                        else
                        {
                            throw new Exception("提交失败：" + commitresult.Mes);
                        }
                    }
                    return res;
                }
                catch (Exception ex)
                {
                    if (!string.IsNullOrEmpty(DocNo))
                    {
                        BFTransFromDelete.CustBFTransFormDelete.CustDeleteTransFrom(DocNo, OrgID);


                        var linelist = new List<ICSAssemVouchs>();
                        foreach (var item in model.details)
                        {
                            linelist.Add(new ICSAssemVouchs
                            {
                                Sequence = item.Sequence,
                                LogIds = item.LogIds
                            });
                        }

                        datalist.Add(new ICSAssemVouch
                        {
                            IsSuccess = false,
                            Message = "单据创建成功，提交审核失败，单据已删除，异常：" + GetExceptionMessage(ex),
                            details = linelist
                        });

                    }
                    else
                    {
                        var linelist = new List<ICSAssemVouchs>();
                        foreach (var item in model.details)
                        {
                            linelist.Add(new ICSAssemVouchs
                            {
                                Sequence = item.Sequence,
                                LogIds = item.LogIds
                            });
                        }

                        datalist.Add(new ICSAssemVouch
                        {
                            IsSuccess = false,
                            Message = "单据创建失败，异常：" + GetExceptionMessage(ex),
                            details = linelist
                        });
                    }
                }
                #endregion

            }
            res.Success = true;
            res.Message = "成功";
            res.Data = datalist;
            return res;

        }

        //形态转换（冻结/可用转换）
        public Result CustCreateTransferFormForFreeze(List<ICSAssemVouch> infos)
        {
            var res = new Result();
            var datalist = new List<ICSAssemVouch>();
            List<rtnRcvInfo> rtnpos = new List<rtnRcvInfo>();
            foreach (ICSAssemVouch model in infos)
            {
                rCVhead rCVInfo = new rCVhead();
                rCVInfo.TransferType = model.TransferType;// "TransForm009";
                rCVInfo.OrgCode = model.WorkPoint;
                rCVInfo.StorageType = 4;
                rCVInfo.Memo = "";
                rCVInfo.lines = new List<rCVLine>();
                var group = model.details.GroupBy(e => e.GroupNO);
                foreach (var data in group)
                {
                    foreach (var dataDetail in data)
                    {
                        rCVLine rCV = new rCVLine();
                        rCV.Sequence = dataDetail.Sequence;
                        rCV.WHCode = dataDetail.WHCode;

                        rCV.ItemCodeBefore = dataDetail.InvCode;
                        rCV.LotBefore = dataDetail.BatchCode;
                        rCV.ProjectBefroe = dataDetail.ProjectCode;
                        rCV.TransferQTYBefore = dataDetail.Quantity;
                        if (dataDetail.Type == "冻结")
                        {
                            rCV.StorageTypeBefore = 4;
                            rCV.StorageTypeAfter = 5;
                        }
                        else
                        {
                            rCV.StorageTypeBefore = 5;
                            rCV.StorageTypeAfter = 4;
                        }

                        rCV.ItemCodeAfter = dataDetail.InvCode;
                        rCV.LotAfter = dataDetail.BatchCode;
                        rCV.ProjectAfter = dataDetail.ProjectCode;
                        rCV.TranferQTYAfter = dataDetail.Quantity;

                        rCV.cFree1 = dataDetail.cFree1;
                        rCV.cFree2 = dataDetail.cFree2;
                        rCV.cFree3 = dataDetail.cFree3;
                        rCV.cFree4 = dataDetail.cFree4;
                        rCV.cFree5 = dataDetail.cFree5;
                        rCV.cFree6 = dataDetail.cFree6;
                        rCV.cFree7 = dataDetail.cFree7;
                        rCV.cFree8 = dataDetail.cFree8;
                        rCV.cFree9 = dataDetail.cFree9;
                        rCV.cFree10 = dataDetail.cFree10;

                        rCV.AftercFree1 = dataDetail.cFree1;
                        rCV.AftercFree2 = dataDetail.cFree2;
                        rCV.AftercFree3 = dataDetail.cFree3;
                        rCV.AftercFree4 = dataDetail.cFree4;
                        rCV.AftercFree5 = dataDetail.cFree5;
                        rCV.AftercFree6 = dataDetail.cFree6;
                        rCV.AftercFree7 = dataDetail.cFree7;
                        rCV.AftercFree8 = dataDetail.cFree8;
                        rCV.AftercFree9 = dataDetail.cFree9;
                        rCV.AftercFree10 = dataDetail.cFree10;
                        //rCV.WHCode = model.InWhCode;
                        rCV.SupplierCode = model.SupplierCode;// "100000";
                        rCVInfo.lines.Add(rCV);
                    }
                }


                #region 测试新增日志
                StringBuilder begionstrlog = new StringBuilder();
                begionstrlog.AppendLine("传入数据日志开始");
                begionstrlog.AppendLine("*****************************************************");
                begionstrlog.AppendLine("形态转换单类型:" + rCVInfo.TransferType);
                begionstrlog.AppendLine("表体行数:" + rCVInfo.lines.Count());
                begionstrlog.AppendLine("存储类型:" + rCVInfo.StorageType);
                begionstrlog.AppendLine("组织编码:" + rCVInfo.OrgCode);
                begionstrlog.AppendLine("转换原因:" + rCVInfo.Memo);
                foreach (rCVLine line in rCVInfo.lines)
                {
                    begionstrlog.AppendLine("转换前料品:" + line.ItemCodeBefore);
                    begionstrlog.AppendLine("转换后料品:" + line.ItemCodeAfter);
                    begionstrlog.AppendLine("转换前批号:" + line.LotBefore);
                    begionstrlog.AppendLine("转换后批号:" + line.LotAfter);
                    begionstrlog.AppendLine("转换前项目:" + line.ProjectBefroe);
                    begionstrlog.AppendLine("转换后项目:" + line.ProjectAfter);
                    begionstrlog.AppendLine("转换前数量:" + line.TransferQTYBefore);
                    begionstrlog.AppendLine("转换后数量:" + line.TranferQTYAfter);
                    begionstrlog.AppendLine("转换仓库:" + line.WHCode);
                    begionstrlog.AppendLine("转换供应商:" + line.SupplierCode);
                    begionstrlog.AppendLine("转换前存储类型:" + line.StorageTypeBefore);
                    begionstrlog.AppendLine("转换后存储类型:" + line.StorageTypeAfter);

                    begionstrlog.AppendLine("转换前私有1:" + line.cFree1);
                    begionstrlog.AppendLine("转换前私有2:" + line.cFree2);
                    begionstrlog.AppendLine("转换前私有3:" + line.cFree3);
                    begionstrlog.AppendLine("转换前私有4:" + line.cFree4);
                    begionstrlog.AppendLine("转换前私有5:" + line.cFree5);
                    begionstrlog.AppendLine("转换前私有6:" + line.cFree6);
                    begionstrlog.AppendLine("转换前私有7:" + line.cFree7);
                    begionstrlog.AppendLine("转换前私有8:" + line.cFree8);
                    begionstrlog.AppendLine("转换前私有9:" + line.cFree9);
                    begionstrlog.AppendLine("转换前私有10:" + line.cFree10);
                    begionstrlog.AppendLine("转换后私有1:" + line.AftercFree1);
                    begionstrlog.AppendLine("转换后私有2:" + line.AftercFree2);
                    begionstrlog.AppendLine("转换后私有3:" + line.AftercFree3);
                    begionstrlog.AppendLine("转换后私有4:" + line.AftercFree4);
                    begionstrlog.AppendLine("转换后私有5:" + line.AftercFree5);
                    begionstrlog.AppendLine("转换后私有6:" + line.AftercFree6);
                    begionstrlog.AppendLine("转换后私有7:" + line.AftercFree7);
                    begionstrlog.AppendLine("转换后私有8:" + line.AftercFree8);
                    begionstrlog.AppendLine("转换后私有9:" + line.AftercFree9);
                    begionstrlog.AppendLine("转换后私有10:" + line.AftercFree10);

                }
                begionstrlog.AppendLine("*****************************************************");
                Appconfig.WriteLogFile(begionstrlog.ToString(), "创建形态转换单(冻结)");
                #endregion
                #region 服务调用框架结构
                UFIDAU9ISVTransferFormISVICommonCreateTransferFormSRVClient client = new UFIDAU9ISVTransferFormISVICommonCreateTransferFormSRVClient();
                //服务返回结果
                UFIDAU9CBOPubControllerCommonArchiveDataDTOData[] returnItems;
                //返回异常信息，目前还没有使用此属性
                UFSoft.UBF.Exceptions1.MessageBase[] returnMsg;
                //上下文信息
                object context;
                //传入 参数
                UFIDAU9ISVTransferFormISVIC_TransferFormDTOData[] pOList;
                //空
                string[] splitBy = new string[] { };
                //int DocLine = 10;
                long WHID = 0;
                try
                {
                    //List<rtnRcvInfo> rtnpos = new List<rtnRcvInfo>();
                    long PickID = 0;
                    long ItemID = 0;
                    if (rCVInfo == null)
                    {
                        res.Success = false;
                        res.Message = "传入参数不能为空";

                        return res;
                    }
                    if (rCVInfo.StorageType == null)
                    {
                        res.Success = false;
                        res.Message = "存储类型不能为空";

                        return res;
                    }
                    string OrgID = "";
                    string orgsql = @"select ID from Base_Organization
                                  where Code='{0}'";
                    orgsql = string.Format(orgsql, rCVInfo.OrgCode);
                    DataTable orgdt = DBhlper.Query(orgsql, connString);
                    if (orgdt.Rows.Count != 0)
                    {
                        OrgID = orgdt.Rows[0]["ID"].ToString();
                    }
                    else
                    {

                        res.Success = false;
                        res.Message = "组织编码:" + rCVInfo.OrgCode + "不存在!";
                        return res;

                    }
                    foreach (rCVLine item in rCVInfo.lines)
                    {
                        if (item == null)
                        {

                            res.Success = false;
                            res.Message = "传入行信息不能为空";
                            return res;
                        }
                        if (item.TransferQTYBefore == 0)
                        {

                            res.Success = false;
                            res.Message = "转换前数量不能为0";

                            return res;
                        }
                        if (item.TranferQTYAfter == 0)
                        {
                            res.Success = false;
                            res.Message = "转换后数量不能为0";
                            return res;
                        }
                        string whsql = @"select ID from CBO_Wh
                                     where Code='{0}'";
                        whsql = string.Format(whsql, item.WHCode);
                        DataTable whdt = DBhlper.Query(whsql, connString);
                        if (whdt.Rows.Count == 0)
                        {
                            res.Success = false;
                            res.Message = "仓库不存在!";

                            return res;
                        }
                        else
                        {
                            WHID = long.Parse(whdt.Rows[0]["ID"].ToString());
                        }
                        //验证转换前信息是否正确
                    }


                    //给上下文信息赋值
                    context = CreateContextObj(OrgID);
                    //给传入参数赋值

                    //pOList = SetrCVDtos(rCVInfoList);
                    StringBuilder strlog = new StringBuilder();
                    strlog.AppendLine("创建形态转换单");
                    strlog.AppendLine("*****************************************************");
                    strlog.AppendLine("形态转换单据类型:" + rCVInfo.TransferType);
                    strlog.AppendLine("组织编码:" + rCVInfo.OrgCode);
                    strlog.AppendLine("存储类型:" + rCVInfo.StorageType);
                    List<UFIDAU9ISVTransferFormISVIC_TransferFormDTOData> transferList = new List<UFIDAU9ISVTransferFormISVIC_TransferFormDTOData>();
                    List<UFIDAU9ISVTransferFormISVIC_TransferFormLDTOData> transferLineList = new List<UFIDAU9ISVTransferFormISVIC_TransferFormLDTOData>();
                    UFIDAU9ISVTransferFormISVIC_TransferFormDTOData transferinfo = new UFIDAU9ISVTransferFormISVIC_TransferFormDTOData();
                    transferinfo.m_transferFormTransType = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
                    transferinfo.m_transferFormTransType.m_code = rCVInfo.TransferType;
                    transferinfo.m_org = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
                    transferinfo.m_org.m_iD = long.Parse(OrgID);
                    transferinfo.m_org.m_code = rCVInfo.OrgCode;
                    transferinfo.m_memo = rCVInfo.Memo;
                    foreach (rCVLine line in rCVInfo.lines)
                    {
                        long CPID = 0;
                        string CPCode = "";
                        string CPName = "";
                        long SupplierID = 0;
                        string SupplierName = "";
                        #region 厂牌查询
                        string cpsql = @"select B.Code,C.Name,B.ID from CBO_ItemMaster A
                                     LEFT JOIN CBO_Supplier B ON B.ID=A.TradeMark
                                     LEFT JOIN CBO_Supplier_Trl C ON C.ID=B.ID
                                     where A.Code='{0}' AND A.Org='{1}' AND ISNULL(A.TradeMark,'')!=''";
                        cpsql = string.Format(cpsql, line.ItemCodeBefore, OrgID);
                        DataTable cpdt = DBhlper.Query(cpsql, connString);
                        if (cpdt.Rows.Count == 0)
                        {
                            CPID = 0;
                            CPCode = "";
                            CPName = "";
                        }
                        else
                        {
                            CPID = long.Parse(cpdt.Rows[0]["ID"].ToString());
                            CPCode = cpdt.Rows[0]["Code"].ToString();
                            CPName = cpdt.Rows[0]["Name"].ToString();
                        }
                        #endregion
                        if (!string.IsNullOrEmpty(line.SupplierCode))
                        {
                            string suppliersql = @"select A.ID,B.Name from CBO_Supplier A
                                               LEFT JOIN CBO_Supplier_Trl B ON B.ID=A.ID
                                               where A.Code='{0}' AND A.Org='{1}'";
                            suppliersql = string.Format(suppliersql, line.SupplierCode, OrgID);
                            DataTable supplierdt = DBhlper.Query(suppliersql, connString);
                            if (supplierdt.Rows.Count == 0)
                            {
                                res.Success = false;
                                res.Message = "供应商编码:" + line.SupplierCode + "不存在!";

                                return res;
                            }
                            else
                            {
                                SupplierID = long.Parse(supplierdt.Rows[0]["ID"].ToString());
                                SupplierName = supplierdt.Rows[0]["Name"].ToString();
                            }
                        }
                        UFIDAU9ISVTransferFormISVIC_TransferFormLDTOData transferlineinfo = new UFIDAU9ISVTransferFormISVIC_TransferFormLDTOData();
                        //转换前信息
                        transferlineinfo.m_transferType = 0;
                        transferlineinfo.m_isCostDependent = true;
                        transferlineinfo.m_docLineNo = line.Sequence;
                        transferlineinfo.m_storeType = line.StorageTypeBefore;
                        if (!string.IsNullOrEmpty(line.SupplierCode))
                        {
                            transferlineinfo.m_supplierInfo = new UFIDAU9CBOSCMSupplierSupplierMISCInfoData();
                            transferlineinfo.m_supplierInfo.Supplier = SupplierID;
                            transferlineinfo.m_supplierInfo.m_code = line.SupplierCode;
                            transferlineinfo.m_supplierInfo.Name = SupplierName;
                            transferlineinfo.m_supplierInfo.Supplier_SKey = new EntityKey();
                            transferlineinfo.m_supplierInfo.Supplier_SKey.ID = SupplierID;

                        }
                        if (CPID != 0)
                        {
                            transferlineinfo.m_manufacturerInfo = new UFIDAU9CBOSCMSupplierSupplierMISCInfoData();
                            transferlineinfo.m_manufacturerInfo.Supplier = CPID;
                            transferlineinfo.m_manufacturerInfo.Supplier_SKey = new EntityKey();
                            transferlineinfo.m_manufacturerInfo.Supplier_SKey.ID = CPID;
                            transferlineinfo.m_manufacturerInfo.m_code = CPCode;
                            transferlineinfo.m_manufacturerInfo.Name = CPName;
                        }
                        transferlineinfo.m_itemInfo = new UFIDAU9CBOSCMItemItemInfoData();
                        transferlineinfo.m_itemInfo.m_itemCode = line.ItemCodeBefore;
                        transferlineinfo.m_lotInfo = new UFIDAU9LotLotMasterInfoData();
                        if (!String.IsNullOrEmpty(line.LotBefore))
                        {
                            transferlineinfo.m_lotInfo.m_lotCode = line.LotBefore;
                        }

                        transferlineinfo.m_project = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
                        if (!String.IsNullOrEmpty(line.ProjectBefroe))
                        {
                            transferlineinfo.m_project.m_code = line.ProjectBefroe;
                        }

                        transferlineinfo.m_storeUOMQty = line.TransferQTYBefore;
                        transferlineinfo.m_wh = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
                        transferlineinfo.m_wh.m_iD = WHID;


                        transferlineinfo.m_descFlexSegments = new UFIDAU9BaseFlexFieldDescFlexFieldDescFlexSegmentsData();
                        transferlineinfo.m_descFlexSegments.m_privateDescSeg1 = line.cFree1;
                        transferlineinfo.m_descFlexSegments.m_privateDescSeg2 = line.cFree2;
                        transferlineinfo.m_descFlexSegments.m_privateDescSeg3 = line.cFree3;
                        transferlineinfo.m_descFlexSegments.m_privateDescSeg4 = line.cFree4;
                        transferlineinfo.m_descFlexSegments.m_privateDescSeg5 = line.cFree5;
                        transferlineinfo.m_descFlexSegments.m_privateDescSeg6 = line.cFree6;
                        transferlineinfo.m_descFlexSegments.m_privateDescSeg7 = line.cFree7;
                        transferlineinfo.m_descFlexSegments.m_privateDescSeg8 = line.cFree8;
                        transferlineinfo.m_descFlexSegments.m_privateDescSeg9 = line.cFree9;
                        transferlineinfo.m_descFlexSegments.m_privateDescSeg10 = line.cFree10;
                        transferlineinfo.m_isCostDependent = true;

                        //转换后信息
                        List<UFIDAU9ISVTransferFormISVIC_TransferFormSLDTOData> transferAfterList = new List<UFIDAU9ISVTransferFormISVIC_TransferFormSLDTOData>();
                        UFIDAU9ISVTransferFormISVIC_TransferFormSLDTOData transferAfterInfo = new UFIDAU9ISVTransferFormISVIC_TransferFormSLDTOData();
                        transferAfterInfo.m_transferType = 1;
                        transferAfterInfo.m_itemInfo = new UFIDAU9CBOSCMItemItemInfoData();
                        transferAfterInfo.m_itemInfo.m_itemCode = line.ItemCodeAfter;
                        transferAfterInfo.m_storeType = line.StorageTypeAfter;
                        if (!string.IsNullOrEmpty(line.SupplierCode))
                        {
                            transferAfterInfo.m_supplierInfo = new UFIDAU9CBOSCMSupplierSupplierMISCInfoData();
                            transferAfterInfo.m_supplierInfo.Supplier = SupplierID;
                            transferAfterInfo.m_supplierInfo.m_code = line.SupplierCode;
                            transferAfterInfo.m_supplierInfo.Name = SupplierName;
                            transferAfterInfo.m_supplierInfo.Supplier_SKey = new EntityKey();
                            transferAfterInfo.m_supplierInfo.Supplier_SKey.ID = SupplierID;
                        }
                        if (CPID != 0)
                        {
                            transferAfterInfo.m_manufacturerInfo = new UFIDAU9CBOSCMSupplierSupplierMISCInfoData();
                            transferAfterInfo.m_manufacturerInfo.Supplier = CPID;
                            transferAfterInfo.m_manufacturerInfo.Supplier_SKey = new EntityKey();
                            transferAfterInfo.m_manufacturerInfo.Supplier_SKey.ID = CPID;
                            transferAfterInfo.m_manufacturerInfo.m_code = CPCode;
                            transferAfterInfo.m_manufacturerInfo.Name = CPName;
                        }
                        transferAfterInfo.m_lotInfo = new UFIDAU9LotLotMasterInfoData();
                        if (!String.IsNullOrEmpty(line.LotAfter))
                        {
                            transferAfterInfo.m_lotInfo.m_lotCode = line.LotAfter;
                        }

                        transferAfterInfo.m_project = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
                        if (!String.IsNullOrEmpty(line.ProjectAfter))
                        {
                            transferAfterInfo.m_project.m_code = line.ProjectAfter;
                        }
                        transferAfterInfo.m_storeUOMQty = line.TranferQTYAfter;
                        transferAfterInfo.m_wh = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
                        transferAfterInfo.m_wh.m_iD = WHID;
                        transferAfterInfo.m_docSubLineNo = line.Sequence;


                        transferAfterList.Add(transferAfterInfo);
                        transferlineinfo.m_transferFormSubLine = transferAfterList.ToArray();
                        transferLineList.Add(transferlineinfo);
                        transferinfo.m_transferFormLine = transferLineList.ToArray();

                        strlog.AppendLine("转换前料品:" + line.ItemCodeBefore);
                        strlog.AppendLine("转换后料品:" + line.ItemCodeAfter);
                        strlog.AppendLine("转换前批号:" + line.LotBefore);
                        strlog.AppendLine("转换后批号:" + line.LotAfter);
                        strlog.AppendLine("转换前项目:" + line.ProjectBefroe);
                        strlog.AppendLine("转换后项目:" + line.ProjectAfter);
                        strlog.AppendLine("转换前数量:" + line.TransferQTYBefore);
                        strlog.AppendLine("转换后数量:" + line.TranferQTYAfter);
                        strlog.AppendLine("转换仓库:" + line.WHCode);
                        strlog.AppendLine("转换供应商:" + line.SupplierCode);

                    }
                    transferList.Add(transferinfo);
                    pOList = transferList.ToArray();

                    (client.Endpoint.Binding as BasicHttpBinding).MaxReceivedMessageSize = int.MaxValue;
                    (client.Endpoint.Binding as BasicHttpBinding).MaxBufferSize = int.MaxValue;

                    returnItems = client.Do(out returnMsg, context, pOList);

                    string rtnsql = @" select DocNo, bb.Name,c.ID,d.ID ShipID from InvDoc_TransferForm a
                                LEFT JOIN InvDoc_TransferFormDocType b ON a.TransferFormDocType = b.ID
                                LEFT JOIN InvDoc_TransferFormDocType_Trl bb ON bb.ID = b.ID
                        LEFT JOIN InvDoc_TransferFormL c ON c.TransferForm=a.ID
                        LEFT JOIN InvDoc_TransferFormSL d ON d.TransferFormL=c.ID
                                 where a.ID='{0}'";

                    rtnsql = string.Format(rtnsql, returnItems[0].m_iD);
                    DataTable rtndt = DBhlper.Query(rtnsql, connString);
                    if (rtndt.Rows.Count != 0)
                    {
                        if (rtndt.Rows[0]["Name"].ToString().Contains("数量"))
                        {
                            foreach (DataRow item in rtndt.Rows)
                            {
                                if (!string.IsNullOrEmpty(item["ID"].ToString()))
                                {
                                    string updatesql = @"UPDATE InvDoc_TransferFormL set IsCostDependent=1  where ID='{0}'";
                                    updatesql = string.Format(updatesql, item["ID"].ToString());
                                    DBhlper.EXecute(updatesql, Appconfig.GetU9ConnStr());

                                    string updatesqlship = @"UPDATE InvDoc_TransferFormSL set IsCostDependent=1  where ID='{0}'";
                                    updatesqlship = string.Format(updatesqlship, item["ShipID"].ToString());
                                    DBhlper.EXecute(updatesqlship, Appconfig.GetU9ConnStr());
                                }
                            }

                        }

                        strlog.AppendLine("开始调用提交形态转换单接口------------");
                        UFIDA.ISV.BFTransferFormCommit.CustBFTransFromCommit.ReturnValue1 commitresult = UFIDA.ISV.BFTransferFormCommit.CustBFTransFromCommit.CustApproveRec(rtndt.Rows[0]["DocNo"].ToString(), OrgID);
                        if (commitresult.IsSuccess)
                        {
                            strlog.AppendLine("形态转换单提交成功------------");
                            res.Success = true;
                            res.Message = "形态转换单审核成功";
                            rtnRcv rtnRcv = new rtnRcv();
                            rtnRcv.ID = returnItems[0].m_iD.ToString();
                            rtnRcv.TransCode = rtndt.Rows[0]["DocNo"].ToString();
                            rtnRcv.details = new List<rtnRcvLine>();

                            string linesql = @"select ID,DocLineNo from InvDoc_TransferFormL 
                                  where  TransferForm ='{0}'";
                            linesql = string.Format(linesql, returnItems[0].m_iD);
                            DataTable lineData = DBhlper.Query(linesql, connString);
                            if (lineData.Rows.Count != 0)
                            {

                                for (int i = 0; i < lineData.Rows.Count; i++)
                                {
                                    rtnRcvLine rtnRcvLine = new rtnRcvLine();
                                    rtnRcvLine.ID = lineData.Rows[i]["ID"].ToString();
                                    rtnRcvLine.Sequence = lineData.Rows[i]["DocLineNo"].ToString();
                                    rtnRcv.details.Add(rtnRcvLine);
                                }
                            }
                            res.Data = JsonConvert.SerializeObject(rtnRcv);
                            UFIDA.ISV.BFTransferFormApprove.CustBFTransFromApprove.ReturnValue1 result = UFIDA.ISV.BFTransferFormApprove.CustBFTransFromApprove.CustApproveRec(rtndt.Rows[0]["DocNo"].ToString(), OrgID);
                            if (result.IsSuccess)
                            {
                                strlog.AppendLine("形态转换单审核成功------------");
                                rtnRcvInfo rtnpo = new rtnRcvInfo();
                                rtnpo.DocNo = rtndt.Rows[0]["DocNo"].ToString();
                                rtnpo.IsSuccess = true;
                                rtnpo.Message = "形态转换单审核成功";
                                rtnpos.Add(rtnpo);
                            }
                            else
                            {
                                strlog.AppendLine("形态转换单审核失败------------");
                                BFTransFromDelete.CustBFTransFormDelete.CustDeleteTransFrom(rtndt.Rows[0]["DocNo"].ToString(), OrgID);
                                rtnRcvInfo rtnpo = new rtnRcvInfo();
                                rtnpo.IsSuccess = false;
                                rtnpo.Message = result.Mes;
                                rtnpos.Add(rtnpo);
                                res.Success = false;
                                res.Message = result.Mes;
                            }
                        }
                        else
                        {
                            strlog.AppendLine("形态转换单提交失败------------");
                            BFTransFromDelete.CustBFTransFormDelete.CustDeleteTransFrom(rtndt.Rows[0]["DocNo"].ToString(), OrgID);
                            rtnRcvInfo rtnpo = new rtnRcvInfo();
                            rtnpo.IsSuccess = false;
                            rtnpo.Message = commitresult.Mes;
                            rtnpos.Add(rtnpo);
                        }
                    }

                    strlog.AppendLine("返回数据:");
                    foreach (var info in rtnpos)
                    {
                        strlog.AppendLine("单号:" + info.DocNo);
                        strlog.AppendLine("结果:" + info.IsSuccess);
                        strlog.AppendLine("返回消息:" + info.Message);
                        //foreach (var _line in info.rtnLines)
                        //{
                        //    strlog.AppendLine("行号:" + _line.LineNo);
                        //}
                    }
                    strlog.AppendLine("*****************************************************");
                    Appconfig.WriteLogFile(strlog.ToString(), "创建形态转换单（冻结）");

                    //return rtnpos;
                    //res.Data = JsonConvert.SerializeObject(rtnpos);
                    return res;
                }
                catch (Exception ex)
                {
                    //异常信息捕获
                    //List<rtnRcvInfo> rtnpos = new List<rtnRcvInfo>();
                    res.Success = false;
                    res.Message = GetExceptionMessage(ex);
                    StringBuilder strlog = new StringBuilder();
                    strlog.AppendLine("创建形态转换单");
                    strlog.AppendLine("*****************************************************");
                    strlog.AppendLine("形态转换单类型:" + rCVInfo.TransferType);
                    strlog.AppendLine("组织编码:" + rCVInfo.OrgCode);
                    strlog.AppendLine("存储类型:" + rCVInfo.StorageType);
                    foreach (rCVLine line in rCVInfo.lines)
                    {
                        strlog.AppendLine("转换前料品:" + line.ItemCodeBefore);
                        strlog.AppendLine("转换后料品:" + line.ItemCodeAfter);
                        strlog.AppendLine("转换前批号:" + line.LotBefore);
                        strlog.AppendLine("转换后批号:" + line.LotAfter);
                        strlog.AppendLine("转换前项目:" + line.ProjectBefroe);
                        strlog.AppendLine("转换后项目:" + line.ProjectAfter);
                        strlog.AppendLine("转换前数量:" + line.TransferQTYBefore);
                        strlog.AppendLine("转换后数量:" + line.TranferQTYAfter);
                        strlog.AppendLine("转换仓库:" + line.WHCode);
                        strlog.AppendLine("转换供应商:" + line.SupplierCode);
                    }
                    strlog.AppendLine("返回消息：" + res.Message);
                    strlog.AppendLine("*****************************************************");
                    Appconfig.WriteLogFile(strlog.ToString(), "创建形态转换单（冻结）");

                    return res;
                }
                #endregion

            }
            return res;

        }

        #region 20231213

        //public Result CustCreateBFFormTransfer_bak(List<ICSAssemVouch> infos)
        //{

        //    //List<ICSAssemVouch> infos = new List<ICSAssemVouch>();
        //    //rCVhead rCVInfo=new rCVhead();
        //    Result res = new Result();
        //    //List<rtnRcv> rtnRcvs = new List<rtnRcv>();  
        //    List<rtnRcvInfo> rtnpos = new List<rtnRcvInfo>();
        //    //rtnRcvInfo rtnpo = new rtnRcvInfo();
        //    foreach (ICSAssemVouch model in infos)
        //    {
        //        rCVhead rCVInfo = new rCVhead();
        //        rCVInfo.TransferType = "TransForm009";
        //        rCVInfo.StorageType = 4;
        //        rCVInfo.OrgCode = model.WorkPoint;
        //        rCVInfo.Memo = "";
        //        rCVInfo.lines = new List<rCVLine>();
        //        var group = model.details.GroupBy(e => e.GroupNO);
        //        foreach (var data in group)
        //        {
        //            rCVLine rCV = new rCVLine();
        //            foreach (var dataDetail in data)
        //            {
        //                if (dataDetail.Type == "转换前")
        //                {
        //                    rCV.Sequence = dataDetail.Sequence;
        //                    rCV.ItemCodeBefore = dataDetail.InvCode;
        //                    rCV.LotBefore = dataDetail.BatchCode;
        //                    rCV.ProjectBefroe = dataDetail.ProjectCode;
        //                    rCV.TransferQTYBefore = dataDetail.Quantity;
        //                }
        //                else
        //                {
        //                    rCV.Sequence = dataDetail.Sequence;
        //                    rCV.ItemCodeAfter = dataDetail.InvCode;
        //                    rCV.LotAfter = dataDetail.BatchCode;
        //                    rCV.ProjectAfter = dataDetail.ProjectCode;
        //                    rCV.TranferQTYAfter = dataDetail.Quantity;
        //                }



        //            }
        //            rCV.WHCode = model.InWhCode;
        //            rCV.SupplierCode = "100000";
        //            rCVInfo.lines.Add(rCV);


        //        }




        //        #region 测试新增日志
        //        StringBuilder begionstrlog = new StringBuilder();
        //        begionstrlog.AppendLine("传入数据日志开始");
        //        begionstrlog.AppendLine("*****************************************************");
        //        begionstrlog.AppendLine("形态转换单类型:" + rCVInfo.TransferType);
        //        begionstrlog.AppendLine("表体行数:" + rCVInfo.lines.Count());
        //        begionstrlog.AppendLine("存储类型:" + rCVInfo.StorageType);
        //        begionstrlog.AppendLine("组织编码:" + rCVInfo.OrgCode);
        //        begionstrlog.AppendLine("转换原因:" + rCVInfo.Memo);
        //        foreach (rCVLine line in rCVInfo.lines)
        //        {
        //            begionstrlog.AppendLine("转换前料品:" + line.ItemCodeBefore);
        //            begionstrlog.AppendLine("转换后料品:" + line.ItemCodeAfter);
        //            begionstrlog.AppendLine("转换前批号:" + line.LotBefore);
        //            begionstrlog.AppendLine("转换后批号:" + line.LotAfter);
        //            begionstrlog.AppendLine("转换前项目:" + line.ProjectBefroe);
        //            begionstrlog.AppendLine("转换后项目:" + line.ProjectAfter);
        //            begionstrlog.AppendLine("转换前数量:" + line.TransferQTYBefore);
        //            begionstrlog.AppendLine("转换后数量:" + line.TranferQTYAfter);
        //            begionstrlog.AppendLine("转换仓库:" + line.WHCode);
        //            begionstrlog.AppendLine("转换供应商:" + line.SupplierCode);
        //        }
        //        begionstrlog.AppendLine("*****************************************************");
        //        Appconfig.WriteLogFile(begionstrlog.ToString(), "创建形态转换单");
        //        #endregion
        //        #region 服务调用框架结构
        //        UFIDAU9ISVTransferFormISVICommonCreateTransferFormSRVClient client = new UFIDAU9ISVTransferFormISVICommonCreateTransferFormSRVClient();
        //        //服务返回结果
        //        UFIDAU9CBOPubControllerCommonArchiveDataDTOData[] returnItems;
        //        //返回异常信息，目前还没有使用此属性
        //        UFSoft.UBF.Exceptions1.MessageBase[] returnMsg;
        //        //上下文信息
        //        object context;
        //        //传入 参数
        //        UFIDAU9ISVTransferFormISVIC_TransferFormDTOData[] pOList;
        //        //空
        //        string[] splitBy = new string[] { };
        //        //int DocLine = 10;
        //        long WHID = 0;
        //        try
        //        {
        //            //List<rtnRcvInfo> rtnpos = new List<rtnRcvInfo>();
        //            long PickID = 0;
        //            long ItemID = 0;
        //            if (rCVInfo == null)
        //            {
        //                res.Success = false;
        //                res.Message = "传入参数不能为空";

        //                return res;
        //            }
        //            if (rCVInfo.StorageType == null)
        //            {
        //                res.Success = false;
        //                res.Message = "存储类型不能为空";

        //                return res;
        //            }
        //            string OrgID = "";
        //            string orgsql = @"select ID from Base_Organization
        //                          where Code='{0}'";
        //            orgsql = string.Format(orgsql, rCVInfo.OrgCode);
        //            DataTable orgdt = DBhlper.Query(orgsql, connString);
        //            if (orgdt.Rows.Count != 0)
        //            {
        //                OrgID = orgdt.Rows[0]["ID"].ToString();
        //            }
        //            else
        //            {

        //                res.Success = false;
        //                res.Message = "组织编码:" + rCVInfo.OrgCode + "不存在!";
        //                return res;

        //            }
        //            foreach (rCVLine item in rCVInfo.lines)
        //            {
        //                if (item == null)
        //                {

        //                    res.Success = false;
        //                    res.Message = "传入行信息不能为空";
        //                    return res;
        //                }
        //                if (item.TransferQTYBefore == 0)
        //                {

        //                    res.Success = false;
        //                    res.Message = "转换前数量不能为0";

        //                    return res;
        //                }
        //                if (item.TranferQTYAfter == 0)
        //                {
        //                    res.Success = false;
        //                    res.Message = "转换后数量不能为0";
        //                    return res;
        //                }
        //                string whsql = @"select ID from CBO_Wh
        //                             where Code='{0}'";
        //                whsql = string.Format(whsql, item.WHCode);
        //                DataTable whdt = DBhlper.Query(whsql, connString);
        //                if (whdt.Rows.Count == 0)
        //                {
        //                    res.Success = false;
        //                    res.Message = "仓库不存在!";

        //                    return res;
        //                }
        //                else
        //                {
        //                    WHID = long.Parse(whdt.Rows[0]["ID"].ToString());
        //                }
        //                //验证转换前信息是否正确
        //            }


        //            //给上下文信息赋值
        //            context = CreateContextObj(OrgID);
        //            //给传入参数赋值

        //            //pOList = SetrCVDtos(rCVInfoList);
        //            StringBuilder strlog = new StringBuilder();
        //            strlog.AppendLine("创建形态转换单");
        //            strlog.AppendLine("*****************************************************");
        //            strlog.AppendLine("形态转换单据类型:" + rCVInfo.TransferType);
        //            strlog.AppendLine("组织编码:" + rCVInfo.OrgCode);
        //            strlog.AppendLine("存储类型:" + rCVInfo.StorageType);
        //            List<UFIDAU9ISVTransferFormISVIC_TransferFormDTOData> transferList = new List<UFIDAU9ISVTransferFormISVIC_TransferFormDTOData>();
        //            List<UFIDAU9ISVTransferFormISVIC_TransferFormLDTOData> transferLineList = new List<UFIDAU9ISVTransferFormISVIC_TransferFormLDTOData>();
        //            UFIDAU9ISVTransferFormISVIC_TransferFormDTOData transferinfo = new UFIDAU9ISVTransferFormISVIC_TransferFormDTOData();
        //            transferinfo.m_transferFormTransType = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
        //            transferinfo.m_transferFormTransType.m_code = rCVInfo.TransferType;
        //            transferinfo.m_org = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
        //            transferinfo.m_org.m_iD = long.Parse(OrgID);
        //            transferinfo.m_org.m_code = rCVInfo.OrgCode;
        //            transferinfo.m_memo = rCVInfo.Memo;
        //            foreach (rCVLine line in rCVInfo.lines)
        //            {
        //                long CPID = 0;
        //                string CPCode = "";
        //                string CPName = "";
        //                long SupplierID = 0;
        //                string SupplierName = "";
        //                #region 厂牌查询
        //                string cpsql = @"select B.Code,C.Name,B.ID from CBO_ItemMaster A
        //                             LEFT JOIN CBO_Supplier B ON B.ID=A.TradeMark
        //                             LEFT JOIN CBO_Supplier_Trl C ON C.ID=B.ID
        //                             where A.Code='{0}' AND A.Org='{1}' AND ISNULL(A.TradeMark,'')!=''";
        //                cpsql = string.Format(cpsql, line.ItemCodeBefore, OrgID);
        //                DataTable cpdt = DBhlper.Query(cpsql, connString);
        //                if (cpdt.Rows.Count == 0)
        //                {
        //                    CPID = 0;
        //                    CPCode = "";
        //                    CPName = "";
        //                }
        //                else
        //                {
        //                    CPID = long.Parse(cpdt.Rows[0]["ID"].ToString());
        //                    CPCode = cpdt.Rows[0]["Code"].ToString();
        //                    CPName = cpdt.Rows[0]["Name"].ToString();
        //                }
        //                #endregion
        //                if (line.SupplierCode != "")
        //                {
        //                    string suppliersql = @"select A.ID,B.Name from CBO_Supplier A
        //                                       LEFT JOIN CBO_Supplier_Trl B ON B.ID=A.ID
        //                                       where A.Code='{0}' AND A.Org='{1}'";
        //                    suppliersql = string.Format(suppliersql, line.SupplierCode, OrgID);
        //                    DataTable supplierdt = DBhlper.Query(suppliersql, connString);
        //                    if (supplierdt.Rows.Count == 0)
        //                    {
        //                        res.Success = false;
        //                        res.Message = "供应商编码:" + line.SupplierCode + "不存在!";

        //                        return res;
        //                    }
        //                    else
        //                    {
        //                        SupplierID = long.Parse(supplierdt.Rows[0]["ID"].ToString());
        //                        SupplierName = supplierdt.Rows[0]["Name"].ToString();
        //                    }
        //                }
        //                UFIDAU9ISVTransferFormISVIC_TransferFormLDTOData transferlineinfo = new UFIDAU9ISVTransferFormISVIC_TransferFormLDTOData();
        //                //转换前信息
        //                transferlineinfo.m_transferType = 0;
        //                transferlineinfo.m_isCostDependent = true;
        //                transferlineinfo.m_docLineNo = line.Sequence;
        //                transferlineinfo.m_storeType = 4;
        //                if (line.SupplierCode != "")
        //                {
        //                    transferlineinfo.m_supplierInfo = new UFIDAU9CBOSCMSupplierSupplierMISCInfoData();
        //                    transferlineinfo.m_supplierInfo.Supplier = SupplierID;
        //                    transferlineinfo.m_supplierInfo.m_code = line.SupplierCode;
        //                    transferlineinfo.m_supplierInfo.Name = SupplierName;
        //                    transferlineinfo.m_supplierInfo.Supplier_SKey = new EntityKey();
        //                    transferlineinfo.m_supplierInfo.Supplier_SKey.ID = SupplierID;

        //                }
        //                if (CPID != 0)
        //                {
        //                    transferlineinfo.m_manufacturerInfo = new UFIDAU9CBOSCMSupplierSupplierMISCInfoData();
        //                    transferlineinfo.m_manufacturerInfo.Supplier = CPID;
        //                    transferlineinfo.m_manufacturerInfo.Supplier_SKey = new EntityKey();
        //                    transferlineinfo.m_manufacturerInfo.Supplier_SKey.ID = CPID;
        //                    transferlineinfo.m_manufacturerInfo.m_code = CPCode;
        //                    transferlineinfo.m_manufacturerInfo.Name = CPName;
        //                }
        //                transferlineinfo.m_itemInfo = new UFIDAU9CBOSCMItemItemInfoData();
        //                transferlineinfo.m_itemInfo.m_itemCode = line.ItemCodeBefore;
        //                transferlineinfo.m_lotInfo = new UFIDAU9LotLotMasterInfoData();
        //                if (!String.IsNullOrEmpty(line.LotBefore))
        //                {
        //                    transferlineinfo.m_lotInfo.m_lotCode = line.LotBefore;
        //                }

        //                transferlineinfo.m_project = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
        //                if (!String.IsNullOrEmpty(line.ProjectBefroe))
        //                {
        //                    transferlineinfo.m_project.m_code = line.ProjectBefroe;
        //                }

        //                transferlineinfo.m_storeUOMQty = line.TransferQTYBefore;
        //                transferlineinfo.m_wh = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
        //                transferlineinfo.m_wh.m_iD = WHID;
        //                //转换后信息
        //                List<UFIDAU9ISVTransferFormISVIC_TransferFormSLDTOData> transferAfterList = new List<UFIDAU9ISVTransferFormISVIC_TransferFormSLDTOData>();
        //                UFIDAU9ISVTransferFormISVIC_TransferFormSLDTOData transferAfterInfo = new UFIDAU9ISVTransferFormISVIC_TransferFormSLDTOData();
        //                transferAfterInfo.m_transferType = 1;
        //                transferAfterInfo.m_itemInfo = new UFIDAU9CBOSCMItemItemInfoData();
        //                transferAfterInfo.m_itemInfo.m_itemCode = line.ItemCodeAfter;
        //                transferAfterInfo.m_storeType = 4;
        //                if (line.SupplierCode != "")
        //                {
        //                    transferAfterInfo.m_supplierInfo = new UFIDAU9CBOSCMSupplierSupplierMISCInfoData();
        //                    transferAfterInfo.m_supplierInfo.Supplier = SupplierID;
        //                    transferAfterInfo.m_supplierInfo.m_code = line.SupplierCode;
        //                    transferAfterInfo.m_supplierInfo.Name = SupplierName;
        //                    transferAfterInfo.m_supplierInfo.Supplier_SKey = new EntityKey();
        //                    transferAfterInfo.m_supplierInfo.Supplier_SKey.ID = SupplierID;
        //                }
        //                if (CPID != 0)
        //                {
        //                    transferAfterInfo.m_manufacturerInfo = new UFIDAU9CBOSCMSupplierSupplierMISCInfoData();
        //                    transferAfterInfo.m_manufacturerInfo.Supplier = CPID;
        //                    transferAfterInfo.m_manufacturerInfo.Supplier_SKey = new EntityKey();
        //                    transferAfterInfo.m_manufacturerInfo.Supplier_SKey.ID = CPID;
        //                    transferAfterInfo.m_manufacturerInfo.m_code = CPCode;
        //                    transferAfterInfo.m_manufacturerInfo.Name = CPName;
        //                }
        //                transferAfterInfo.m_lotInfo = new UFIDAU9LotLotMasterInfoData();
        //                if (!String.IsNullOrEmpty(line.LotAfter))
        //                {
        //                    transferAfterInfo.m_lotInfo.m_lotCode = line.LotAfter;
        //                }

        //                transferAfterInfo.m_project = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
        //                if (!String.IsNullOrEmpty(line.ProjectAfter))
        //                {
        //                    transferAfterInfo.m_project.m_code = line.ProjectAfter;
        //                }
        //                transferAfterInfo.m_storeUOMQty = line.TranferQTYAfter;
        //                transferAfterInfo.m_wh = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
        //                transferAfterInfo.m_wh.m_iD = WHID;
        //                transferAfterInfo.m_docSubLineNo = line.Sequence;



        //                transferAfterList.Add(transferAfterInfo);
        //                transferlineinfo.m_transferFormSubLine = transferAfterList.ToArray();
        //                transferLineList.Add(transferlineinfo);
        //                transferinfo.m_transferFormLine = transferLineList.ToArray();

        //                strlog.AppendLine("转换前料品:" + line.ItemCodeBefore);
        //                strlog.AppendLine("转换后料品:" + line.ItemCodeAfter);
        //                strlog.AppendLine("转换前批号:" + line.LotBefore);
        //                strlog.AppendLine("转换后批号:" + line.LotAfter);
        //                strlog.AppendLine("转换前项目:" + line.ProjectBefroe);
        //                strlog.AppendLine("转换后项目:" + line.ProjectAfter);
        //                strlog.AppendLine("转换前数量:" + line.TransferQTYBefore);
        //                strlog.AppendLine("转换后数量:" + line.TranferQTYAfter);
        //                strlog.AppendLine("转换仓库:" + line.WHCode);
        //                strlog.AppendLine("转换供应商:" + line.SupplierCode);

        //            }
        //            transferList.Add(transferinfo);
        //            pOList = transferList.ToArray();

        //            (client.Endpoint.Binding as BasicHttpBinding).MaxReceivedMessageSize = int.MaxValue;
        //            (client.Endpoint.Binding as BasicHttpBinding).MaxBufferSize = int.MaxValue;

        //            returnItems = client.Do(out returnMsg, context, pOList);

        //            string rtnsql = @"select DocNo from InvDoc_TransferForm 
        //                          where ID='{0}'";
        //            rtnsql = string.Format(rtnsql, returnItems[0].m_iD);
        //            DataTable rtndt = DBhlper.Query(rtnsql, connString);
        //            if (rtndt.Rows.Count != 0)
        //            {
        //                strlog.AppendLine("开始调用提交形态转换单接口------------");
        //                UFIDA.ISV.BFTransferFormCommit.CustBFTransFromCommit.ReturnValue1 commitresult = UFIDA.ISV.BFTransferFormCommit.CustBFTransFromCommit.CustApproveRec(rtndt.Rows[0]["DocNo"].ToString(), OrgID);
        //                if (commitresult.IsSuccess)
        //                {
        //                    strlog.AppendLine("形态转换单提交成功------------");
        //                    res.Success = true;
        //                    res.Message = "形态转换单审核成功";
        //                    rtnRcv rtnRcv = new rtnRcv();
        //                    rtnRcv.ID = returnItems[0].m_iD.ToString();
        //                    rtnRcv.MTCode = rtndt.Rows[0]["DocNo"].ToString();
        //                    rtnRcv.details = new List<rtnRcvLine>();

        //                    string linesql = @"select ID,DocLineNo from InvDoc_TransferFormL 
        //                          where  TransferForm ='{0}'";
        //                    linesql = string.Format(linesql, returnItems[0].m_iD);
        //                    DataTable lineData = DBhlper.Query(linesql, connString);
        //                    if (lineData.Rows.Count != 0)
        //                    {

        //                        for (int i = 0; i < lineData.Rows.Count; i++)
        //                        {
        //                            rtnRcvLine rtnRcvLine = new rtnRcvLine();
        //                            rtnRcvLine.ID = lineData.Rows[i]["ID"].ToString();
        //                            rtnRcvLine.Sequence = lineData.Rows[i]["DocLineNo"].ToString();
        //                            rtnRcv.details.Add(rtnRcvLine);
        //                        }
        //                    }
        //                    res.Data = JsonConvert.SerializeObject(rtnRcv);
        //                    UFIDA.ISV.BFTransferFormApprove.CustBFTransFromApprove.ReturnValue1 result = UFIDA.ISV.BFTransferFormApprove.CustBFTransFromApprove.CustApproveRec(rtndt.Rows[0]["DocNo"].ToString(), OrgID);
        //                    if (result.IsSuccess)
        //                    {
        //                        strlog.AppendLine("形态转换单审核成功------------");
        //                        rtnRcvInfo rtnpo = new rtnRcvInfo();
        //                        rtnpo.DocNo = rtndt.Rows[0]["DocNo"].ToString();
        //                        rtnpo.IsSuccess = true;
        //                        rtnpo.Message = "形态转换单审核成功";
        //                        rtnpos.Add(rtnpo);
        //                    }
        //                    else
        //                    {
        //                        strlog.AppendLine("形态转换单审核失败------------");
        //                        BFTransFromDelete.CustBFTransFormDelete.CustDeleteTransFrom(rtndt.Rows[0]["DocNo"].ToString(), OrgID);
        //                        rtnRcvInfo rtnpo = new rtnRcvInfo();
        //                        rtnpo.IsSuccess = false;
        //                        rtnpo.Message = result.Mes;
        //                        rtnpos.Add(rtnpo);
        //                    }
        //                }
        //                else
        //                {
        //                    strlog.AppendLine("形态转换单提交失败------------");
        //                    BFTransFromDelete.CustBFTransFormDelete.CustDeleteTransFrom(rtndt.Rows[0]["DocNo"].ToString(), OrgID);
        //                    rtnRcvInfo rtnpo = new rtnRcvInfo();
        //                    rtnpo.IsSuccess = false;
        //                    rtnpo.Message = commitresult.Mes;
        //                    rtnpos.Add(rtnpo);
        //                }
        //            }

        //            strlog.AppendLine("返回数据:");
        //            foreach (var info in rtnpos)
        //            {
        //                strlog.AppendLine("单号:" + info.DocNo);
        //                strlog.AppendLine("结果:" + info.IsSuccess);
        //                strlog.AppendLine("返回消息:" + info.Message);
        //                //foreach (var _line in info.rtnLines)
        //                //{
        //                //    strlog.AppendLine("行号:" + _line.LineNo);
        //                //}
        //            }
        //            strlog.AppendLine("*****************************************************");
        //            Appconfig.WriteLogFile(strlog.ToString(), "创建形态转换单");

        //            //return rtnpos;
        //        }
        //        catch (Exception ex)
        //        {
        //            //异常信息捕获
        //            //List<rtnRcvInfo> rtnpos = new List<rtnRcvInfo>();
        //            res.Success = false;
        //            res.Message = GetExceptionMessage(ex);
        //            StringBuilder strlog = new StringBuilder();
        //            strlog.AppendLine("创建形态转换单");
        //            strlog.AppendLine("*****************************************************");
        //            strlog.AppendLine("形态转换单类型:" + rCVInfo.TransferType);
        //            strlog.AppendLine("组织编码:" + rCVInfo.OrgCode);
        //            strlog.AppendLine("存储类型:" + rCVInfo.StorageType);
        //            foreach (rCVLine line in rCVInfo.lines)
        //            {
        //                strlog.AppendLine("转换前料品:" + line.ItemCodeBefore);
        //                strlog.AppendLine("转换后料品:" + line.ItemCodeAfter);
        //                strlog.AppendLine("转换前批号:" + line.LotBefore);
        //                strlog.AppendLine("转换后批号:" + line.LotAfter);
        //                strlog.AppendLine("转换前项目:" + line.ProjectBefroe);
        //                strlog.AppendLine("转换后项目:" + line.ProjectAfter);
        //                strlog.AppendLine("转换前数量:" + line.TransferQTYBefore);
        //                strlog.AppendLine("转换后数量:" + line.TranferQTYAfter);
        //                strlog.AppendLine("转换仓库:" + line.WHCode);
        //                strlog.AppendLine("转换供应商:" + line.SupplierCode);
        //            }
        //            strlog.AppendLine("返回消息：" + res.Message);
        //            strlog.AppendLine("*****************************************************");
        //            Appconfig.WriteLogFile(strlog.ToString(), "创建形态转换单");

        //            return res;
        //        }
        //        #endregion

        //    }
        //    return res;

        //}

        #endregion
        //public List<rtnRcvInfo> CustCreateBFFormTransfer(List<ICSAssemVouch> infos)
        //{



        //    //rCVhead rCVInfo=new rCVhead();
        //    foreach (ICSAssemVouch model in infos)
        //    {
        //        List<rtnRcvInfo> rtnpos = new List<rtnRcvInfo>();
        //        if (model == null)
        //        {
        //            rtnRcvInfo rtnpo = new rtnRcvInfo();
        //            rtnpo.IsSuccess = false;
        //            rtnpo.Message = "传入参数不能为空";
        //            rtnpos.Add(rtnpo);
        //            return rtnpos;
        //        }
        //        //rCVInfo.TransferType = "TransForm009";
        //        //rCVInfo.StorageType = 4;
        //        //rCVInfo.OrgCode = model.WorkPoint;
        //        //rCVInfo.Memo = "";

        //        StringBuilder begionstrlog = new StringBuilder();
        //        begionstrlog.AppendLine("传入数据日志开始");
        //        begionstrlog.AppendLine("*****************************************************");
        //        begionstrlog.AppendLine("形态转换单类型:" + "TransForm009");
        //        begionstrlog.AppendLine("表体行数:" + (model.details.Count())/2);
        //        begionstrlog.AppendLine("存储类型:" + 4);
        //        begionstrlog.AppendLine("组织编码:" + model.WorkPoint);
        //        begionstrlog.AppendLine("转换原因:" + "");

        //        rCVLine rCV = new rCVLine();
        //        foreach (var data in model.details)
        //        {
        //            if (data == null)
        //            {
        //                rtnRcvInfo rtnpo = new rtnRcvInfo();
        //                rtnpo.IsSuccess = false;
        //                rtnpo.Message = "传入行信息不能为空";
        //                rtnpos.Add(rtnpo);
        //                return rtnpos;
        //            }

        //            if (data.Type == "转换前")
        //            {
        //                //rCV.ItemCodeBefore = data.InvCode;
        //                //rCV.LotBefore = data.BatchCode;
        //                //rCV.ProjectBefroe = data.ProjectCode;
        //                //rCV.TransferQTYBefore = data.Quantity;
        //                begionstrlog.AppendLine("转换前料品:" + data.InvCode);
        //                begionstrlog.AppendLine("转换前批号:" + data.BatchCode);
        //                begionstrlog.AppendLine("转换前项目:" + data.ProjectCode);
        //                begionstrlog.AppendLine("转换前数量:" + data.Quantity);
        //                if (data.Quantity == 0)
        //                {
        //                    rtnRcvInfo rtnpo = new rtnRcvInfo();
        //                    rtnpo.IsSuccess = false;
        //                    rtnpo.Message = "转换前数量不能为0";
        //                    rtnpos.Add(rtnpo);
        //                    return rtnpos;
        //                }
        //            }
        //            else
        //            {
        //                //rCV.ItemCodeAfter = data.InvCode;
        //                //rCV.LotAfter = data.BatchCode;
        //                //rCV.ProjectAfter = data.ProjectCode;
        //                //rCV.TranferQTYAfter = data.Quantity;
        //                begionstrlog.AppendLine("转换前料品:" + data.InvCode);
        //                begionstrlog.AppendLine("转换后料品:" + data.BatchCode);
        //                begionstrlog.AppendLine("转换后项目:" + data.ProjectCode);
        //                begionstrlog.AppendLine("转换后数量:" + data.Quantity);
        //                if (data.Quantity == 0)
        //                {
        //                    rtnRcvInfo rtnpo = new rtnRcvInfo();
        //                    rtnpo.IsSuccess = false;
        //                    rtnpo.Message = "转换后数量不能为0";
        //                    rtnpos.Add(rtnpo);
        //                    return rtnpos;
        //                }
        //            }

        //            rCV.WHCode = model.InWhCode;
        //            rCV.SupplierCode = "";

        //            #region 测试新增日志
        //            //foreach (rCVLine line in rCVInfo.lines)
        //            //{

        //                begionstrlog.AppendLine("转换仓库:" + model.InWhCode);
        //                begionstrlog.AppendLine("转换供应商:" +"");
        //            //}
        //            begionstrlog.AppendLine("*****************************************************");
        //            Appconfig.WriteLogFile(begionstrlog.ToString(), "创建形态转换单");
        //            #endregion
        //            #region 服务调用框架结构
        //            UFIDAU9ISVTransferFormISVICommonCreateTransferFormSRVClient client = new UFIDAU9ISVTransferFormISVICommonCreateTransferFormSRVClient();
        //            //服务返回结果
        //            UFIDAU9CBOPubControllerCommonArchiveDataDTOData[] returnItems;
        //            //返回异常信息，目前还没有使用此属性
        //            UFSoft.UBF.Exceptions1.MessageBase[] returnMsg;
        //            //上下文信息
        //            object context;
        //            //传入 参数
        //            UFIDAU9ISVTransferFormISVIC_TransferFormDTOData[] pOList;
        //            //空
        //            string[] splitBy = new string[] { };
        //            //int DocLine = 10;
        //            long WHID = 0;
        //            try
        //            {

        //                long PickID = 0;
        //                long ItemID = 0;
        //                if (model == null)
        //                {
        //                    rtnRcvInfo rtnpo = new rtnRcvInfo();
        //                    rtnpo.IsSuccess = false;
        //                    rtnpo.Message = "传入参数不能为空";
        //                    rtnpos.Add(rtnpo);
        //                    return rtnpos;
        //                }
        //                //if (rCVInfo.StorageType == null)
        //                //{
        //                //    rtnRcvInfo rtnpo = new rtnRcvInfo();
        //                //    rtnpo.IsSuccess = false;
        //                //    rtnpo.Message = "存储类型不能为空";
        //                //    rtnpos.Add(rtnpo);
        //                //    return rtnpos;
        //                //}
        //                string OrgID = "";
        //                string orgsql = @"select ID from Base_Organization
        //                          where Code='{0}'";
        //                orgsql = string.Format(orgsql, model.WorkPoint);
        //                DataTable orgdt = DBhlper.Query(orgsql, Appconfig.GetU9ConnStr());
        //                if (orgdt.Rows.Count != 0)
        //                {
        //                    OrgID = orgdt.Rows[0]["ID"].ToString();
        //                }
        //                else
        //                {
        //                    rtnRcvInfo rtnpo = new rtnRcvInfo();
        //                    rtnpo.IsSuccess = false;
        //                    rtnpo.Message = "组织编码:" + model.WorkPoint + "不存在!";
        //                    rtnpos.Add(rtnpo);
        //                    return rtnpos;
        //                }

        //                    string whsql = @"select ID from CBO_Wh
        //                             where Code='{0}'";
        //                    whsql = string.Format(whsql, data.WHCode);
        //                    DataTable whdt = DBhlper.Query(whsql, Appconfig.GetU9ConnStr());
        //                    if (whdt.Rows.Count == 0)
        //                    {
        //                        rtnRcvInfo rtnpo = new rtnRcvInfo();
        //                        rtnpo.IsSuccess = false;
        //                        rtnpo.Message = "仓库不存在!";
        //                        rtnpos.Add(rtnpo);
        //                        return rtnpos;
        //                    }
        //                    else
        //                    {
        //                        WHID = long.Parse(whdt.Rows[0]["ID"].ToString());
        //                    }
        //                    //验证转换前信息是否正确



        //                //给上下文信息赋值
        //                context = CreateContextObj(OrgID);
        //                //给传入参数赋值

        //                //pOList = SetrCVDtos(rCVInfoList);
        //                StringBuilder strlog = new StringBuilder();
        //                strlog.AppendLine("创建形态转换单");
        //                strlog.AppendLine("*****************************************************");
        //                strlog.AppendLine("形态转换单据类型:" + "TransForm009");
        //                strlog.AppendLine("组织编码:" + model.WorkPoint);
        //                strlog.AppendLine("存储类型:" + "");
        //                List<UFIDAU9ISVTransferFormISVIC_TransferFormDTOData> transferList = new List<UFIDAU9ISVTransferFormISVIC_TransferFormDTOData>();
        //                List<UFIDAU9ISVTransferFormISVIC_TransferFormLDTOData> transferLineList = new List<UFIDAU9ISVTransferFormISVIC_TransferFormLDTOData>();
        //                UFIDAU9ISVTransferFormISVIC_TransferFormDTOData transferinfo = new UFIDAU9ISVTransferFormISVIC_TransferFormDTOData();
        //                transferinfo.m_transferFormTransType = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
        //                transferinfo.m_transferFormTransType.m_code = "TransForm009";
        //                transferinfo.m_org = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
        //                transferinfo.m_org.m_iD = long.Parse(OrgID);
        //                transferinfo.m_org.m_code = model.WorkPoint;
        //                transferinfo.m_memo = "";
        //                foreach (rCVLine line in rCVInfo.lines)
        //                {
        //                    long CPID = 0;
        //                    string CPCode = "";
        //                    string CPName = "";
        //                    long SupplierID = 0;
        //                    string SupplierName = "";
        //                    #region 厂牌查询
        //                    string cpsql = @"select B.Code,C.Name,B.ID from CBO_ItemMaster A
        //                             LEFT JOIN CBO_Supplier B ON B.ID=A.TradeMark
        //                             LEFT JOIN CBO_Supplier_Trl C ON C.ID=B.ID
        //                             where A.Code='{0}' AND A.Org='{1}' AND ISNULL(A.TradeMark,'')!=''";
        //                    cpsql = string.Format(cpsql, line.ItemCodeBefore, OrgID);
        //                    DataTable cpdt = DBhlper.Query(cpsql, Appconfig.GetU9ConnStr());
        //                    if (cpdt.Rows.Count == 0)
        //                    {
        //                        CPID = 0;
        //                        CPCode = "";
        //                        CPName = "";
        //                    }
        //                    else
        //                    {
        //                        CPID = long.Parse(cpdt.Rows[0]["ID"].ToString());
        //                        CPCode = cpdt.Rows[0]["Code"].ToString();
        //                        CPName = cpdt.Rows[0]["Name"].ToString();
        //                    }
        //                    #endregion
        //                    if (line.SupplierCode != "")
        //                    {
        //                        string suppliersql = @"select A.ID,B.Name from CBO_Supplier A
        //                                       LEFT JOIN CBO_Supplier_Trl B ON B.ID=A.ID
        //                                       where A.Code='{0}' AND A.Org='{1}'";
        //                        suppliersql = string.Format(suppliersql, line.SupplierCode, OrgID);
        //                        DataTable supplierdt = DBhlper.Query(suppliersql, Appconfig.GetU9ConnStr());
        //                        if (supplierdt.Rows.Count == 0)
        //                        {
        //                            rtnRcvInfo rtnpo = new rtnRcvInfo();
        //                            rtnpo.IsSuccess = false;
        //                            rtnpo.Message = "供应商编码:" + line.SupplierCode + "不存在!";
        //                            rtnpos.Add(rtnpo);
        //                            return rtnpos;
        //                        }
        //                        else
        //                        {
        //                            SupplierID = long.Parse(supplierdt.Rows[0]["ID"].ToString());
        //                            SupplierName = supplierdt.Rows[0]["Name"].ToString();
        //                        }
        //                    }
        //                    UFIDAU9ISVTransferFormISVIC_TransferFormLDTOData transferlineinfo = new UFIDAU9ISVTransferFormISVIC_TransferFormLDTOData();
        //                    //转换前信息
        //                    transferlineinfo.m_transferType = 0;
        //                    transferlineinfo.m_isCostDependent = true;
        //                    transferlineinfo.m_docLineNo = data.Sequence;
        //                    transferlineinfo.m_storeType = 4;
        //                    if (line.SupplierCode != "")
        //                    {
        //                        transferlineinfo.m_supplierInfo = new UFIDAU9CBOSCMSupplierSupplierMISCInfoData();
        //                        transferlineinfo.m_supplierInfo.Supplier = SupplierID;
        //                        transferlineinfo.m_supplierInfo.m_code = line.SupplierCode;
        //                        transferlineinfo.m_supplierInfo.Name = SupplierName;
        //                        transferlineinfo.m_supplierInfo.Supplier_SKey = new EntityKey();
        //                        transferlineinfo.m_supplierInfo.Supplier_SKey.ID = SupplierID;

        //                    }
        //                    if (CPID != 0)
        //                    {
        //                        transferlineinfo.m_manufacturerInfo = new UFIDAU9CBOSCMSupplierSupplierMISCInfoData();
        //                        transferlineinfo.m_manufacturerInfo.Supplier = CPID;
        //                        transferlineinfo.m_manufacturerInfo.Supplier_SKey = new EntityKey();
        //                        transferlineinfo.m_manufacturerInfo.Supplier_SKey.ID = CPID;
        //                        transferlineinfo.m_manufacturerInfo.m_code = CPCode;
        //                        transferlineinfo.m_manufacturerInfo.Name = CPName;
        //                    }
        //                    transferlineinfo.m_itemInfo = new UFIDAU9CBOSCMItemItemInfoData();
        //                    transferlineinfo.m_itemInfo.m_itemCode = line.ItemCodeBefore;
        //                    transferlineinfo.m_lotInfo = new UFIDAU9LotLotMasterInfoData();
        //                    transferlineinfo.m_lotInfo.m_lotCode = line.LotBefore;
        //                    transferlineinfo.m_project = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
        //                    transferlineinfo.m_project.m_code = line.ProjectBefroe;
        //                    transferlineinfo.m_storeUOMQty = line.TransferQTYBefore;
        //                    transferlineinfo.m_wh = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
        //                    transferlineinfo.m_wh.m_iD = WHID;
        //                    //转换后信息
        //                    List<UFIDAU9ISVTransferFormISVIC_TransferFormSLDTOData> transferAfterList = new List<UFIDAU9ISVTransferFormISVIC_TransferFormSLDTOData>();
        //                    UFIDAU9ISVTransferFormISVIC_TransferFormSLDTOData transferAfterInfo = new UFIDAU9ISVTransferFormISVIC_TransferFormSLDTOData();
        //                    transferAfterInfo.m_transferType = 1;
        //                    transferAfterInfo.m_itemInfo = new UFIDAU9CBOSCMItemItemInfoData();
        //                    transferAfterInfo.m_itemInfo.m_itemCode = line.ItemCodeAfter;
        //                    transferAfterInfo.m_storeType = 4;
        //                    if (line.SupplierCode != "")
        //                    {
        //                        transferAfterInfo.m_supplierInfo = new UFIDAU9CBOSCMSupplierSupplierMISCInfoData();
        //                        transferAfterInfo.m_supplierInfo.Supplier = SupplierID;
        //                        transferAfterInfo.m_supplierInfo.m_code = line.SupplierCode;
        //                        transferAfterInfo.m_supplierInfo.Name = SupplierName;
        //                        transferAfterInfo.m_supplierInfo.Supplier_SKey = new EntityKey();
        //                        transferAfterInfo.m_supplierInfo.Supplier_SKey.ID = SupplierID;
        //                    }
        //                    if (CPID != 0)
        //                    {
        //                        transferAfterInfo.m_manufacturerInfo = new UFIDAU9CBOSCMSupplierSupplierMISCInfoData();
        //                        transferAfterInfo.m_manufacturerInfo.Supplier = CPID;
        //                        transferAfterInfo.m_manufacturerInfo.Supplier_SKey = new EntityKey();
        //                        transferAfterInfo.m_manufacturerInfo.Supplier_SKey.ID = CPID;
        //                        transferAfterInfo.m_manufacturerInfo.m_code = CPCode;
        //                        transferAfterInfo.m_manufacturerInfo.Name = CPName;
        //                    }
        //                    transferAfterInfo.m_lotInfo = new UFIDAU9LotLotMasterInfoData();
        //                    transferAfterInfo.m_lotInfo.m_lotCode = line.LotAfter;
        //                    transferAfterInfo.m_project = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
        //                    transferAfterInfo.m_project.m_code = line.ProjectAfter;
        //                    transferAfterInfo.m_storeUOMQty = line.TranferQTYAfter;
        //                    transferAfterInfo.m_wh = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
        //                    transferAfterInfo.m_wh.m_iD = WHID;
        //                    transferAfterInfo.m_docSubLineNo = "10";



        //                    transferAfterList.Add(transferAfterInfo);
        //                    transferlineinfo.m_transferFormSubLine = transferAfterList.ToArray();
        //                    transferLineList.Add(transferlineinfo);
        //                    transferinfo.m_transferFormLine = transferLineList.ToArray();

        //                    strlog.AppendLine("转换前料品:" + line.ItemCodeBefore);
        //                    strlog.AppendLine("转换后料品:" + line.ItemCodeAfter);
        //                    strlog.AppendLine("转换前批号:" + line.LotBefore);
        //                    strlog.AppendLine("转换后批号:" + line.LotAfter);
        //                    strlog.AppendLine("转换前项目:" + line.ProjectBefroe);
        //                    strlog.AppendLine("转换后项目:" + line.ProjectAfter);
        //                    strlog.AppendLine("转换前数量:" + line.TransferQTYBefore);
        //                    strlog.AppendLine("转换后数量:" + line.TranferQTYAfter);
        //                    strlog.AppendLine("转换仓库:" + line.WHCode);
        //                    strlog.AppendLine("转换供应商:" + line.SupplierCode);
        //                    //DocLine++;
        //                }
        //                transferList.Add(transferinfo);
        //                pOList = transferList.ToArray();

        //                (client.Endpoint.Binding as BasicHttpBinding).MaxReceivedMessageSize = int.MaxValue;
        //                (client.Endpoint.Binding as BasicHttpBinding).MaxBufferSize = int.MaxValue;

        //                returnItems = client.Do(out returnMsg, context, pOList);

        //                string rtnsql = @"select DocNo from InvDoc_TransferForm 
        //                          where ID='{0}'";
        //                rtnsql = string.Format(rtnsql, returnItems[0].m_iD);
        //                DataTable rtndt = DBhlper.Query(rtnsql, Appconfig.GetU9ConnStr());
        //                if (rtndt.Rows.Count != 0)
        //                {
        //                    strlog.AppendLine("开始调用提交形态转换单接口------------");
        //                    UFIDA.ISV.BFTransferFormCommit.CustBFTransFromCommit.ReturnValue1 commitresult = UFIDA.ISV.BFTransferFormCommit.CustBFTransFromCommit.CustApproveRec(rtndt.Rows[0]["DocNo"].ToString(), OrgID);
        //                    if (commitresult.IsSuccess)
        //                    {
        //                        strlog.AppendLine("形态转换单提交成功------------");
        //                        rtnRcvInfo rtnpo = new rtnRcvInfo();
        //                        rtnpo.DocNo = rtndt.Rows[0]["DocNo"].ToString();
        //                        rtnpo.IsSuccess = true;
        //                        rtnpo.Message = "形态转换单审核成功";
        //                        rtnpos.Add(rtnpo);
        //                        //UFIDA.ISV.BFTransferFormApprove.CustBFTransFromApprove.ReturnValue1 result = UFIDA.ISV.BFTransferFormApprove.CustBFTransFromApprove.CustApproveRec(rtndt.Rows[0]["DocNo"].ToString(),OrgID);
        //                        //if (result.IsSuccess)
        //                        //{
        //                        //    strlog.AppendLine("形态转换单审核成功------------");
        //                        //    rtnRcvInfo rtnpo = new rtnRcvInfo();
        //                        //    rtnpo.DocNo = rtndt.Rows[0]["DocNo"].ToString();
        //                        //    rtnpo.IsSuccess = true;
        //                        //    rtnpo.Message = "形态转换单审核成功";
        //                        //    rtnpos.Add(rtnpo);
        //                        //}
        //                        //else
        //                        //{
        //                        //    strlog.AppendLine("形态转换单审核失败------------");
        //                        //    BFTransFromDelete.CustBFTransFormDelete.CustDeleteTransFrom(rtndt.Rows[0]["DocNo"].ToString(),OrgID);
        //                        //    rtnRcvInfo rtnpo = new rtnRcvInfo();
        //                        //    rtnpo.IsSuccess = false;
        //                        //    rtnpo.Message = result.Mes;
        //                        //    rtnpos.Add(rtnpo);
        //                        //}
        //                    }
        //                    else
        //                    {
        //                        strlog.AppendLine("形态转换单提交失败------------");
        //                        BFTransFromDelete.CustBFTransFormDelete.CustDeleteTransFrom(rtndt.Rows[0]["DocNo"].ToString(), OrgID);
        //                        rtnRcvInfo rtnpo = new rtnRcvInfo();
        //                        rtnpo.IsSuccess = false;
        //                        rtnpo.Message = commitresult.Mes;
        //                        rtnpos.Add(rtnpo);
        //                    }
        //                }

        //                strlog.AppendLine("返回数据:");
        //                foreach (var info in rtnpos)
        //                {
        //                    strlog.AppendLine("单号:" + info.DocNo);
        //                    strlog.AppendLine("结果:" + info.IsSuccess);
        //                    strlog.AppendLine("返回消息:" + info.Message);
        //                    //foreach (var _line in info.rtnLines)
        //                    //{
        //                    //    strlog.AppendLine("行号:" + _line.LineNo);
        //                    //}
        //                }
        //                strlog.AppendLine("*****************************************************");
        //                Appconfig.WriteLogFile(strlog.ToString(), "创建形态转换单");

        //                return rtnpos;
        //            }
        //            catch (Exception ex)
        //            {
        //                //异常信息捕获
        //                List<rtnRcvInfo> rtnpos = new List<rtnRcvInfo>();
        //                rtnRcvInfo rtnpo = new rtnRcvInfo();
        //                rtnpo.IsSuccess = false;
        //                rtnpo.Message = GetExceptionMessage(ex);
        //                rtnpos.Add(rtnpo);

        //                StringBuilder strlog = new StringBuilder();
        //                strlog.AppendLine("创建形态转换单");
        //                strlog.AppendLine("*****************************************************");
        //                strlog.AppendLine("形态转换单类型:" + rCVInfo.TransferType);
        //                strlog.AppendLine("组织编码:" + rCVInfo.OrgCode);
        //                strlog.AppendLine("存储类型:" + rCVInfo.StorageType);
        //                foreach (rCVLine line in rCVInfo.lines)
        //                {
        //                    strlog.AppendLine("转换前料品:" + line.ItemCodeBefore);
        //                    strlog.AppendLine("转换后料品:" + line.ItemCodeAfter);
        //                    strlog.AppendLine("转换前批号:" + line.LotBefore);
        //                    strlog.AppendLine("转换后批号:" + line.LotAfter);
        //                    strlog.AppendLine("转换前项目:" + line.ProjectBefroe);
        //                    strlog.AppendLine("转换后项目:" + line.ProjectAfter);
        //                    strlog.AppendLine("转换前数量:" + line.TransferQTYBefore);
        //                    strlog.AppendLine("转换后数量:" + line.TranferQTYAfter);
        //                    strlog.AppendLine("转换仓库:" + line.WHCode);
        //                    strlog.AppendLine("转换供应商:" + line.SupplierCode);
        //                }
        //                strlog.AppendLine("返回消息：" + rtnpo.Message);
        //                strlog.AppendLine("*****************************************************");
        //                Appconfig.WriteLogFile(strlog.ToString(), "创建形态转换单");

        //               return rtnpos;
        //            } 

        //            #endregion
        //}






        //}
        //}


        public List<rtnRcvInfo> CustCreateBFFormTransfer(Freezehead rCVInfo)
        {
            #region 测试新增日志
            StringBuilder begionstrlog = new StringBuilder();
            begionstrlog.AppendLine("传入数据日志开始");
            begionstrlog.AppendLine("*****************************************************");
            begionstrlog.AppendLine("形态转换单类型:" + rCVInfo.TransferType);
            begionstrlog.AppendLine("表体行数:" + rCVInfo.lines.Count());
            begionstrlog.AppendLine("组织编码:" + rCVInfo.OrgCode);
            begionstrlog.AppendLine("转换原因:" + rCVInfo.Memo);
            foreach (FreezeLine line in rCVInfo.lines)
            {
                begionstrlog.AppendLine("转换前料品:" + line.ItemCodeBefore);
                begionstrlog.AppendLine("转换后料品:" + line.ItemCodeAfter);
                begionstrlog.AppendLine("转换前批号:" + line.LotBefore);
                begionstrlog.AppendLine("转换后批号:" + line.LotAfter);
                begionstrlog.AppendLine("转换前项目:" + line.ProjectBefroe);
                begionstrlog.AppendLine("转换后项目:" + line.ProjectAfter);
                begionstrlog.AppendLine("转换前数量:" + line.TransferQTYBefore);
                begionstrlog.AppendLine("转换后数量:" + line.TranferQTYAfter);
                begionstrlog.AppendLine("转换前存储类型:" + line.StorageTypeBefore);
                begionstrlog.AppendLine("转换后存储类型:" + line.StorageTypeAfter);
                begionstrlog.AppendLine("转换仓库:" + line.WHCode);
                begionstrlog.AppendLine("转换供应商:" + line.SupplierCode);
            }
            begionstrlog.AppendLine("*****************************************************");
            Appconfig.WriteLogFile(begionstrlog.ToString(), "创建形态转换单(条码冻结)");
            #endregion
            #region 服务调用框架结构
            UFIDAU9ISVTransferFormISVICommonCreateTransferFormSRVClient client = new UFIDAU9ISVTransferFormISVICommonCreateTransferFormSRVClient();
            //服务返回结果
            UFIDAU9CBOPubControllerCommonArchiveDataDTOData[] returnItems;
            //返回异常信息，目前还没有使用此属性
            UFSoft.UBF.Exceptions1.MessageBase[] returnMsg;
            //上下文信息
            object context;
            //传入 参数
            UFIDAU9ISVTransferFormISVIC_TransferFormDTOData[] pOList;
            //空
            string[] splitBy = new string[] { };
            int DocLine = 10;
            long WHID = 0;
            try
            {
                List<rtnRcvInfo> rtnpos = new List<rtnRcvInfo>();
                long PickID = 0;
                long ItemID = 0;
                if (rCVInfo == null)
                {
                    rtnRcvInfo rtnpo = new rtnRcvInfo();
                    rtnpo.IsSuccess = false;
                    rtnpo.Message = "传入参数不能为空";
                    rtnpos.Add(rtnpo);
                    return rtnpos;
                }
                string OrgID = "";
                string orgsql = @"select ID from Base_Organization
                                  where Code='{0}'";
                orgsql = string.Format(orgsql, rCVInfo.OrgCode);
                DataTable orgdt = DBhlper.Query(orgsql, connString);
                if (orgdt.Rows.Count != 0)
                {
                    OrgID = orgdt.Rows[0]["ID"].ToString();
                }
                else
                {
                    rtnRcvInfo rtnpo = new rtnRcvInfo();
                    rtnpo.IsSuccess = false;
                    rtnpo.Message = "组织编码:" + rCVInfo.OrgCode + "不存在!";
                    rtnpos.Add(rtnpo);
                    return rtnpos;
                }
                foreach (FreezeLine item in rCVInfo.lines)
                {
                    if (item == null)
                    {
                        rtnRcvInfo rtnpo = new rtnRcvInfo();
                        rtnpo.IsSuccess = false;
                        rtnpo.Message = "传入行信息不能为空";
                        rtnpos.Add(rtnpo);
                        return rtnpos;
                    }
                    if (item.TransferQTYBefore == 0)
                    {
                        rtnRcvInfo rtnpo = new rtnRcvInfo();
                        rtnpo.IsSuccess = false;
                        rtnpo.Message = "转换前数量不能为0";
                        rtnpos.Add(rtnpo);
                        return rtnpos;
                    }
                    if (item.TranferQTYAfter == 0)
                    {
                        rtnRcvInfo rtnpo = new rtnRcvInfo();
                        rtnpo.IsSuccess = false;
                        rtnpo.Message = "转换后数量不能为0";
                        rtnpos.Add(rtnpo);
                        return rtnpos;
                    }
                    if (item.StorageTypeBefore == 0)
                    {
                        rtnRcvInfo rtnpo = new rtnRcvInfo();
                        rtnpo.IsSuccess = false;
                        rtnpo.Message = "转换前存储类型不能为空";
                        rtnpos.Add(rtnpo);
                        return rtnpos;
                    }
                    if (item.StorageTypeAfter == 0)
                    {
                        rtnRcvInfo rtnpo = new rtnRcvInfo();
                        rtnpo.IsSuccess = false;
                        rtnpo.Message = "转换后存储类型不能为空";
                        rtnpos.Add(rtnpo);
                        return rtnpos;
                    }
                    //验证转换前信息是否正确
                }


                //给上下文信息赋值
                context = CreateContextObj(OrgID);
                //给传入参数赋值

                //pOList = SetrCVDtos(rCVInfoList);
                StringBuilder strlog = new StringBuilder();
                strlog.AppendLine("创建形态转换单");
                strlog.AppendLine("*****************************************************");
                strlog.AppendLine("形态转换单据类型:" + rCVInfo.TransferType);
                strlog.AppendLine("组织编码:" + rCVInfo.OrgCode);
                List<UFIDAU9ISVTransferFormISVIC_TransferFormDTOData> transferList = new List<UFIDAU9ISVTransferFormISVIC_TransferFormDTOData>();
                List<UFIDAU9ISVTransferFormISVIC_TransferFormLDTOData> transferLineList = new List<UFIDAU9ISVTransferFormISVIC_TransferFormLDTOData>();
                UFIDAU9ISVTransferFormISVIC_TransferFormDTOData transferinfo = new UFIDAU9ISVTransferFormISVIC_TransferFormDTOData();
                transferinfo.m_transferFormTransType = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
                transferinfo.m_transferFormTransType.m_code = rCVInfo.TransferType;
                transferinfo.m_org = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
                transferinfo.m_org.m_iD = long.Parse(OrgID);
                transferinfo.m_org.m_code = rCVInfo.OrgCode;
                transferinfo.m_memo = rCVInfo.Memo;
                foreach (FreezeLine line in rCVInfo.lines)
                {
                    long CPID = 0;
                    string CPCode = "";
                    string CPName = "";
                    long SupplierID = 0;
                    string SupplierName = "";
                    #region 厂牌查询
                    string cpsql = @"select B.Code,C.Name,B.ID from CBO_ItemMaster A
                                     LEFT JOIN CBO_Supplier B ON B.ID=A.TradeMark
                                     LEFT JOIN CBO_Supplier_Trl C ON C.ID=B.ID
                                     where A.Code='{0}' AND A.Org='{1}' AND ISNULL(A.TradeMark,'')!=''";
                    cpsql = string.Format(cpsql, line.ItemCodeBefore, OrgID);
                    DataTable cpdt = DBhlper.Query(cpsql, connString);
                    if (cpdt.Rows.Count == 0)
                    {
                        CPID = 0;
                        CPCode = "";
                        CPName = "";
                    }
                    else
                    {
                        CPID = long.Parse(cpdt.Rows[0]["ID"].ToString());
                        CPCode = cpdt.Rows[0]["Code"].ToString();
                        CPName = cpdt.Rows[0]["Name"].ToString();
                    }
                    #endregion
                    if (line.SupplierCode != "")
                    {
                        string suppliersql = @"select A.ID,B.Name from CBO_Supplier A
                                               LEFT JOIN CBO_Supplier_Trl B ON B.ID=A.ID
                                               where A.Code='{0}' AND A.Org='{1}'";
                        suppliersql = string.Format(suppliersql, line.SupplierCode, OrgID);
                        DataTable supplierdt = DBhlper.Query(suppliersql, connString);
                        if (supplierdt.Rows.Count == 0)
                        {
                            rtnRcvInfo rtnpo = new rtnRcvInfo();
                            rtnpo.IsSuccess = false;
                            rtnpo.Message = "供应商编码:" + line.SupplierCode + "不存在!";
                            rtnpos.Add(rtnpo);
                            return rtnpos;
                        }
                        else
                        {
                            SupplierID = long.Parse(supplierdt.Rows[0]["ID"].ToString());
                            SupplierName = supplierdt.Rows[0]["Name"].ToString();
                        }
                    }
                    string whsql = @"select ID from CBO_Wh
                                     where Code='{0}'";
                    whsql = string.Format(whsql, line.WHCode);
                    DataTable whdt = DBhlper.Query(whsql, connString);
                    if (whdt.Rows.Count == 0)
                    {
                        rtnRcvInfo rtnpo = new rtnRcvInfo();
                        rtnpo.IsSuccess = false;
                        rtnpo.Message = "传入仓库:" + line.WHCode + "不存在!";
                        rtnpos.Add(rtnpo);
                        return rtnpos;
                    }
                    else
                    {
                        WHID = long.Parse(whdt.Rows[0]["ID"].ToString());
                    }
                    UFIDAU9ISVTransferFormISVIC_TransferFormLDTOData transferlineinfo = new UFIDAU9ISVTransferFormISVIC_TransferFormLDTOData();
                    //转换前信息
                    transferlineinfo.m_transferType = 0;
                    transferlineinfo.m_isCostDependent = true;
                    transferlineinfo.m_docLineNo = DocLine.ToString();
                    transferlineinfo.m_storeType = line.StorageTypeBefore;
                    if (line.SupplierCode != "")
                    {
                        transferlineinfo.m_supplierInfo = new UFIDAU9CBOSCMSupplierSupplierMISCInfoData();
                        transferlineinfo.m_supplierInfo.Supplier = SupplierID;
                        transferlineinfo.m_supplierInfo.m_code = line.SupplierCode;
                        transferlineinfo.m_supplierInfo.Name = SupplierName;
                        transferlineinfo.m_supplierInfo.Supplier_SKey = new EntityKey();
                        transferlineinfo.m_supplierInfo.Supplier_SKey.ID = SupplierID;

                    }
                    if (CPID != 0)
                    {
                        transferlineinfo.m_manufacturerInfo = new UFIDAU9CBOSCMSupplierSupplierMISCInfoData();
                        transferlineinfo.m_manufacturerInfo.Supplier = CPID;
                        transferlineinfo.m_manufacturerInfo.Supplier_SKey = new EntityKey();
                        transferlineinfo.m_manufacturerInfo.Supplier_SKey.ID = CPID;
                        transferlineinfo.m_manufacturerInfo.m_code = CPCode;
                        transferlineinfo.m_manufacturerInfo.Name = CPName;
                    }
                    transferlineinfo.m_itemInfo = new UFIDAU9CBOSCMItemItemInfoData();
                    transferlineinfo.m_itemInfo.m_itemCode = line.ItemCodeBefore;
                    transferlineinfo.m_lotInfo = new UFIDAU9LotLotMasterInfoData();
                    transferlineinfo.m_lotInfo.m_lotCode = line.LotBefore;
                    transferlineinfo.m_project = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
                    transferlineinfo.m_project.m_code = line.ProjectBefroe;
                    transferlineinfo.m_storeUOMQty = line.TransferQTYBefore;
                    transferlineinfo.m_wh = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
                    transferlineinfo.m_wh.m_iD = WHID;
                    //转换后信息
                    List<UFIDAU9ISVTransferFormISVIC_TransferFormSLDTOData> transferAfterList = new List<UFIDAU9ISVTransferFormISVIC_TransferFormSLDTOData>();
                    UFIDAU9ISVTransferFormISVIC_TransferFormSLDTOData transferAfterInfo = new UFIDAU9ISVTransferFormISVIC_TransferFormSLDTOData();
                    transferAfterInfo.m_transferType = 1;
                    transferAfterInfo.m_itemInfo = new UFIDAU9CBOSCMItemItemInfoData();
                    transferAfterInfo.m_itemInfo.m_itemCode = line.ItemCodeAfter;
                    transferAfterInfo.m_storeType = line.StorageTypeAfter;
                    if (line.SupplierCode != "")
                    {
                        transferAfterInfo.m_supplierInfo = new UFIDAU9CBOSCMSupplierSupplierMISCInfoData();
                        transferAfterInfo.m_supplierInfo.Supplier = SupplierID;
                        transferAfterInfo.m_supplierInfo.m_code = line.SupplierCode;
                        transferAfterInfo.m_supplierInfo.Name = SupplierName;
                        transferAfterInfo.m_supplierInfo.Supplier_SKey = new EntityKey();
                        transferAfterInfo.m_supplierInfo.Supplier_SKey.ID = SupplierID;
                    }
                    if (CPID != 0)
                    {
                        transferAfterInfo.m_manufacturerInfo = new UFIDAU9CBOSCMSupplierSupplierMISCInfoData();
                        transferAfterInfo.m_manufacturerInfo.Supplier = CPID;
                        transferAfterInfo.m_manufacturerInfo.Supplier_SKey = new EntityKey();
                        transferAfterInfo.m_manufacturerInfo.Supplier_SKey.ID = CPID;
                        transferAfterInfo.m_manufacturerInfo.m_code = CPCode;
                        transferAfterInfo.m_manufacturerInfo.Name = CPName;
                    }
                    transferAfterInfo.m_lotInfo = new UFIDAU9LotLotMasterInfoData();
                    transferAfterInfo.m_lotInfo.m_lotCode = line.LotAfter;
                    transferAfterInfo.m_project = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
                    transferAfterInfo.m_project.m_code = line.ProjectAfter;
                    transferAfterInfo.m_storeUOMQty = line.TranferQTYAfter;
                    transferAfterInfo.m_wh = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
                    transferAfterInfo.m_wh.m_iD = WHID;
                    transferAfterInfo.m_docSubLineNo = "10";



                    transferAfterList.Add(transferAfterInfo);
                    transferlineinfo.m_transferFormSubLine = transferAfterList.ToArray();
                    transferLineList.Add(transferlineinfo);
                    transferinfo.m_transferFormLine = transferLineList.ToArray();

                    strlog.AppendLine("转换前料品:" + line.ItemCodeBefore);
                    strlog.AppendLine("转换后料品:" + line.ItemCodeAfter);
                    strlog.AppendLine("转换前批号:" + line.LotBefore);
                    strlog.AppendLine("转换后批号:" + line.LotAfter);
                    strlog.AppendLine("转换前项目:" + line.ProjectBefroe);
                    strlog.AppendLine("转换后项目:" + line.ProjectAfter);
                    strlog.AppendLine("转换前数量:" + line.TransferQTYBefore);
                    strlog.AppendLine("转换后数量:" + line.TranferQTYAfter);
                    strlog.AppendLine("转换前存储类型:" + line.StorageTypeBefore);
                    strlog.AppendLine("转换后存储类型:" + line.StorageTypeAfter);
                    strlog.AppendLine("转换仓库:" + line.WHCode);
                    strlog.AppendLine("转换供应商:" + line.SupplierCode);
                    DocLine++;
                }
                transferList.Add(transferinfo);
                pOList = transferList.ToArray();

                (client.Endpoint.Binding as BasicHttpBinding).MaxReceivedMessageSize = int.MaxValue;
                (client.Endpoint.Binding as BasicHttpBinding).MaxBufferSize = int.MaxValue;

                returnItems = client.Do(out returnMsg, context, pOList);

                string rtnsql = @"select DocNo from InvDoc_TransferForm 
                                  where ID='{0}'";
                rtnsql = string.Format(rtnsql, returnItems[0].m_iD);
                DataTable rtndt = DBhlper.Query(rtnsql, connString);
                if (rtndt.Rows.Count != 0)
                {
                    strlog.AppendLine("开始调用提交形态转换单接口------------");
                    UFIDA.ISV.BFTransferFormCommit.CustBFTransFromCommit.ReturnValue1 commitresult = UFIDA.ISV.BFTransferFormCommit.CustBFTransFromCommit.CustApproveRec(rtndt.Rows[0]["DocNo"].ToString(), OrgID);
                    if (commitresult.IsSuccess)
                    {
                        strlog.AppendLine("形态转换单提交成功------------");
                        //rtnRcvInfo rtnpo = new rtnRcvInfo();
                        //rtnpo.DocNo = rtndt.Rows[0]["DocNo"].ToString();
                        //rtnpo.IsSuccess = true;
                        //rtnpo.Message = "形态转换单审核成功";
                        //rtnpos.Add(rtnpo);
                        UFIDA.ISV.BFTransferFormApprove.CustBFTransFromApprove.ReturnValue1 result = UFIDA.ISV.BFTransferFormApprove.CustBFTransFromApprove.CustApproveRec(rtndt.Rows[0]["DocNo"].ToString(), OrgID);
                        if (result.IsSuccess)
                        {
                            strlog.AppendLine("形态转换单审核成功------------");
                            rtnRcvInfo rtnpo = new rtnRcvInfo();
                            rtnpo.DocNo = rtndt.Rows[0]["DocNo"].ToString();
                            rtnpo.IsSuccess = true;
                            rtnpo.Message = "形态转换单审核成功";
                            rtnpos.Add(rtnpo);
                        }
                        else
                        {
                            strlog.AppendLine("形态转换单审核失败------------");
                            BFTransFromDelete.CustBFTransFormDelete.CustDeleteTransFrom(rtndt.Rows[0]["DocNo"].ToString(), OrgID);
                            rtnRcvInfo rtnpo = new rtnRcvInfo();
                            rtnpo.IsSuccess = false;
                            rtnpo.Message = result.Mes;
                            rtnpos.Add(rtnpo);
                        }
                    }
                    else
                    {
                        strlog.AppendLine("形态转换单提交失败------------");
                        BFTransFromDelete.CustBFTransFormDelete.CustDeleteTransFrom(rtndt.Rows[0]["DocNo"].ToString(), OrgID);
                        rtnRcvInfo rtnpo = new rtnRcvInfo();
                        rtnpo.IsSuccess = false;
                        rtnpo.Message = commitresult.Mes;
                        rtnpos.Add(rtnpo);
                    }
                }

                strlog.AppendLine("返回数据:");
                foreach (var info in rtnpos)
                {
                    strlog.AppendLine("单号:" + info.DocNo);
                    strlog.AppendLine("结果:" + info.IsSuccess);
                    strlog.AppendLine("返回消息:" + info.Message);
                    //foreach (var _line in info.rtnLines)
                    //{
                    //    strlog.AppendLine("行号:" + _line.LineNo);
                    //}
                }
                strlog.AppendLine("*****************************************************");
                Appconfig.WriteLogFile(strlog.ToString(), "创建形态转换单(条码冻结)");

                return rtnpos;
            }
            catch (Exception ex)
            {
                //异常信息捕获
                List<rtnRcvInfo> rtnpos = new List<rtnRcvInfo>();
                rtnRcvInfo rtnpo = new rtnRcvInfo();
                rtnpo.IsSuccess = false;
                rtnpo.Message = GetExceptionMessage(ex);
                rtnpos.Add(rtnpo);

                StringBuilder strlog = new StringBuilder();
                strlog.AppendLine("创建形态转换单");
                strlog.AppendLine("*****************************************************");
                strlog.AppendLine("形态转换单类型:" + rCVInfo.TransferType);
                strlog.AppendLine("组织编码:" + rCVInfo.OrgCode);
                foreach (FreezeLine line in rCVInfo.lines)
                {
                    strlog.AppendLine("转换前料品:" + line.ItemCodeBefore);
                    strlog.AppendLine("转换后料品:" + line.ItemCodeAfter);
                    strlog.AppendLine("转换前批号:" + line.LotBefore);
                    strlog.AppendLine("转换后批号:" + line.LotAfter);
                    strlog.AppendLine("转换前项目:" + line.ProjectBefroe);
                    strlog.AppendLine("转换后项目:" + line.ProjectAfter);
                    strlog.AppendLine("转换前数量:" + line.TransferQTYBefore);
                    strlog.AppendLine("转换后数量:" + line.TranferQTYAfter);
                    strlog.AppendLine("转换前存储类型:" + line.StorageTypeBefore);
                    strlog.AppendLine("转换后存储类型:" + line.StorageTypeAfter);
                    strlog.AppendLine("转换仓库:" + line.WHCode);
                    strlog.AppendLine("转换供应商:" + line.SupplierCode);
                }
                strlog.AppendLine("返回消息：" + rtnpo.Message);
                strlog.AppendLine("*****************************************************");
                Appconfig.WriteLogFile(strlog.ToString(), "创建形态转换单(条码冻结)");

                return rtnpos;
            }
            #endregion
        }

        #region 表头类
        public class rCVhead
        {
            private List<rCVLine> _lines;
            private string _TransferType;
            private int _StorageType;
            private string _OrgCode;
            private string _Memo;

            public string TransferType
            {
                get { return _TransferType; }
                set { _TransferType = value; }
            }

            public int StorageType
            {
                get { return _StorageType; }
                set { _StorageType = value; }
            }

            public string OrgCode
            {
                get { return _OrgCode; }
                set { _OrgCode = value; }
            }

            public string Memo
            {
                get { return _Memo; }
                set { _Memo = value; }
            }

            public List<rCVLine> lines
            {
                get { return _lines; }
                set { _lines = value; }
            }
        }
        #endregion

        #region 表体类
        public class rCVLine
        {
            /// <summary>
            /// 行号
            /// </summary>
            public string Sequence { get; set; }
            /// <summary>
            /// 转换前料品
            /// </summary>
            public string ItemCodeBefore { get; set; }

            /// <summary>
            /// 转换前料品版本
            /// </summary>
            public string ItemVersionBefore { get; set; }
            /// <summary>
            /// 转换后料品
            /// </summary>
            public string ItemCodeAfter { get; set; }

            /// <summary>
            /// 转换后料品版本
            /// </summary>
            public string ItemVersionAfter { get; set; }
            /// <summary>
            /// 转换前批号
            /// </summary>
            public string LotBefore { get; set; }
            /// <summary>
            /// 转换后批号
            /// </summary>
            public string LotAfter { get; set; }
            /// <summary>
            /// 转换前项目
            /// </summary>
            public string ProjectBefroe { get; set; }
            /// <summary>
            /// 转换后项目
            /// </summary>
            public string ProjectAfter { get; set; }
            /// <summary>
            /// 转换前数量
            /// </summary>
            public decimal TransferQTYBefore { get; set; }
            /// <summary>
            /// 转换后数量
            /// </summary>
            public decimal TranferQTYAfter { get; set; }
            /// <summary>
            /// 转换前存储类型
            /// </summary>
            public int StorageTypeBefore { get; set; }
            /// <summary>
            /// 转换后存储类型
            /// </summary>
            public int StorageTypeAfter { get; set; }
            /// <summary>
            /// 条码所在仓库
            /// </summary>
            public string WHCode { get; set; }
            /// <summary>
            /// 生产日期
            /// </summary>
            public string ProductDate { get; set; }
            /// <summary>
            /// 条码供应商
            /// </summary>
            public string SupplierCode { get; set; }


            public string cFree1 { get; set; }
            public string cFree2 { get; set; }
            public string cFree3 { get; set; }
            public string cFree4 { get; set; }
            public string cFree5 { get; set; }
            public string cFree6 { get; set; }
            public string cFree7 { get; set; }
            public string cFree8 { get; set; }
            public string cFree9 { get; set; }
            public string cFree10 { get; set; }


            public string AftercFree1 { get; set; }
            public string AftercFree2 { get; set; }
            public string AftercFree3 { get; set; }
            public string AftercFree4 { get; set; }
            public string AftercFree5 { get; set; }
            public string AftercFree6 { get; set; }
            public string AftercFree7 { get; set; }
            public string AftercFree8 { get; set; }
            public string AftercFree9 { get; set; }
            public string AftercFree10 { get; set; }

            public string LogIds { get; set; }
        }
        #endregion

        #region 表头类（条码冻结用）
        public class Freezehead
        {
            private FreezeLine[] _lines;
            private string _TransferType;
            private string _OrgCode;
            private string _Memo;

            public string TransferType
            {
                get { return _TransferType; }
                set { _TransferType = value; }
            }


            public string OrgCode
            {
                get { return _OrgCode; }
                set { _OrgCode = value; }
            }

            public string Memo
            {
                get { return _Memo; }
                set { _Memo = value; }
            }

            public FreezeLine[] lines
            {
                get { return _lines; }
                set { _lines = value; }
            }
        }
        #endregion

        #region 表体类（条码冻结用）
        public class FreezeLine
        {
            /// <summary>
            /// 转换前料品
            /// </summary>
            public string ItemCodeBefore { get; set; }
            /// <summary>
            /// 转换后料品
            /// </summary>
            public string ItemCodeAfter { get; set; }
            /// <summary>
            /// 转换前批号
            /// </summary>
            public string LotBefore { get; set; }
            /// <summary>
            /// 转换后批号
            /// </summary>
            public string LotAfter { get; set; }
            /// <summary>
            /// 转换前项目
            /// </summary>
            public string ProjectBefroe { get; set; }
            /// <summary>
            /// 转换后项目
            /// </summary>
            public string ProjectAfter { get; set; }
            /// <summary>
            /// 转换前数量
            /// </summary>
            public decimal TransferQTYBefore { get; set; }
            /// <summary>
            /// 转换后数量
            /// </summary>
            public decimal TranferQTYAfter { get; set; }
            /// <summary>
            /// 条码所在仓库
            /// </summary>
            public string WHCode { get; set; }
            /// <summary>
            /// 条码供应商
            /// </summary>
            public string SupplierCode { get; set; }
            /// <summary>
            /// 转换前存储类型
            /// </summary>
            public int StorageTypeBefore { get; set; }
            /// <summary>
            /// 转换后存储类型
            /// </summary>
            public int StorageTypeAfter { get; set; }
        }
        #endregion


        #region 提取异常信息
        /// <summary>
        /// 提取异常信息
        /// </summary>
        /// <param name="ex"></param>
        private string GetExceptionMessage(Exception ex)
        {
            string faultMessage = "未知错误，请查看ERP日志！";

            System.TimeoutException timeoutEx = ex as System.TimeoutException;
            if (timeoutEx != null)
            {
                faultMessage = "访问服务超时，请修改配置信息！";
            }
            else
            {
                FaultException<ServiceException> faultEx = ex as FaultException<ServiceException>;
                if (faultEx == null)
                {
                    faultMessage = ex.Message;
                }
                else
                {
                    ServiceException serviceEx = faultEx.Detail;
                    if (serviceEx != null && !string.IsNullOrEmpty(serviceEx.Message)
                        && !serviceEx.Message.Equals("fault", StringComparison.OrdinalIgnoreCase))
                    {
                        // 错误信息在faultEx.Message中，请提取，
                        // 格式为"Fault:料品不能为空，请录入\n 在....."
                        int startIndex = serviceEx.Message.IndexOf(":");
                        int endIndex = serviceEx.Message.IndexOf("\n");
                        if (endIndex == -1)
                            endIndex = serviceEx.Message.Length;
                        if (endIndex > 0 && endIndex > startIndex + 1)
                        {
                            faultMessage = serviceEx.Message.Substring(startIndex + 1, endIndex - startIndex - 1);
                        }
                        else
                        {
                            faultMessage = serviceEx.Message;
                        }
                    }
                }
            }
            return faultMessage;
        }
        #endregion

        #region 给上下文信息赋值
        /// <summary>
        /// 给上下文信息赋值
        /// </summary>
        /// <returns></returns>
        private ThreadContext CreateContextObj(string OrgID)
        {
            // 实例化应用上下文对象
            ThreadContext thContext = new ThreadContext();

            System.Collections.Generic.Dictionary<object, object> ns = new Dictionary<object, object>();
            ns.Add("OrgID", OrgID);
            ns.Add("UserID", ConfigurationManager.AppSettings["userID"].ToString());
            ns.Add("UserCode", ConfigurationManager.AppSettings["userCode"].ToString());
            ns.Add("Datetime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
            ns.Add("CultureName", ConfigurationManager.AppSettings["cultureName"].ToString());
            ns.Add("EnterpriseID", ConfigurationManager.AppSettings["enterpriseID"].ToString());
            ns.Add("DefaultCultureName", ConfigurationManager.AppSettings["cultureName"].ToString());
            ns.Add("Support_CultureName_List", ConfigurationManager.AppSettings["cultureName"].ToString());
            thContext.nameValueHas = ns;

            return thContext;
        }
        #endregion

        #region 时间戳方法
        private DateTime TimestampToDateTime(long timestamp)
        {
            DateTime dateTimeStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
            long lTime = timestamp * 10000000;
            TimeSpan nowTimeSpan = new TimeSpan(lTime);
            DateTime resultDateTime = dateTimeStart.Add(nowTimeSpan);
            return resultDateTime;
        }
        #endregion
    }

    #region 上下文类信息
    public class contextInfo
    {
        private long _OrgID;
        private string _OrgCode;
        private long _UserID;
        private string _UserCode;
        private DateTime _Datetime;
        private string _CultureName;
        private string _EnterpriseID;


        /// <summary>
        /// 组织ID
        /// </summary>
        public long OrgID
        {
            get { return _OrgID; }
            set { _OrgID = value; }
        }

        /// <summary>
        /// 组织编码
        /// </summary>
        public string OrgCode
        {
            get { return _OrgCode; }
            set { _OrgCode = value; }
        }

        /// <summary>
        /// 操作员ID
        /// </summary>
        public long UserID
        {
            get { return _UserID; }
            set { _UserID = value; }
        }

        /// <summary>
        /// 操作员编码
        /// </summary>
        public string UserCode
        {
            get { return _UserCode; }
            set { _UserCode = value; }
        }

        /// <summary>
        /// 时间
        /// </summary>
        public DateTime Datetime
        {
            get { return _Datetime; }
            set { _Datetime = value; }
        }

        /// <summary>
        /// 语言
        /// </summary>
        public string CultureName
        {
            get { return _CultureName; }
            set { _CultureName = value; }
        }

        /// <summary>
        /// 企业ID号
        /// </summary>
        public string EnterpriseID
        {
            get { return _EnterpriseID; }
            set { _EnterpriseID = value; }
        }

        public contextInfo()
        {
            CultureName = "zh_CN";
            Datetime = DateTime.Now;
        }
    }
    #endregion



    #region 返回信息类
    public class rtnRcvInfo
    {
        public string DocNo { get; set; }
        public bool Success { get; set; }
        public bool IsSuccess { get; set; }
        public string Message { get; set; }
        //public rtnRcvLine[] rtnLines { get; set; }
        public Data data { get; set; }
    }

    public class Data
    {
        public string ID { get; set; }
        public string TransCode { get; set; }
        public string FromDepCode { get; set; }
        public string FromDepName { get; set; }
        public string FromWHCode { get; set; }
        public string FromWHName { get; set; }
        public string ToDepCode { get; set; }
        public string ToDepName { get; set; }
        public string ToWHCode { get; set; }
        public string TACode { get; set; }
        public string demo { get; set; }
        public string Checker { get; set; }
        public DateTime CreateDateTime { get; set; }
        public DateTime CheckDateTime { get; set; }
        public List<DataLine> details { get; set; }
    }

    public class DataLine
    {
        public string DetailID { get; set; }
        public int Sequence { get; set; }
        public string InvCode { get; set; }
        public Decimal Quantity { get; set; }
        public string ProjectCode { get; set; }
        public Decimal Amount { get; set; }
        public string cBatch { get; set; }
        public string brand { get; set; }
        public string cFree1 { get; set; }
        public string cFree2 { get; set; }
        public string cFree3 { get; set; }
        public string cFree4 { get; set; }
        public string cFree5 { get; set; }
        public string cFree6 { get; set; }
        public string cFree7 { get; set; }
        public string cFree8 { get; set; }
        public string cFree9 { get; set; }
        public string cFree10 { get; set; }
    }


    public class rtnRcvLine
    {
        //public int LineNo { get; set; }
        public string ID { get; set; }
        public string Sequence { get; set; }

        public string LogId { get; set; }

        //public string srcDocNo { get; set; }

        //public int srcLineNo { get; set; }

        //public decimal reqQty { get; set; }

        //public string proCode { get; set; }
    }
    public class rtnRcv
    {
        public string ID { get; set; }

        public string TransCode { get; set; }
        public List<rtnRcvLine> details { get; set; }
        //public Data data { get; set; }

    }
    #endregion


    #region 表体类
    //public class rCVLine
    //{
    //    /// <summary>
    //    ///  来源采购订单
    //    /// </summary>
    //    public string srcDocPONo { get; set; }

    //    private int _srcDocPOLineNo;
    //    private decimal _reqQty;
    //    public string WhCode { get; set; }

    //    /// <summary>
    //    /// 炉号
    //    /// </summary>
    //    public string FurnaceNo { get; set; }

    //    /// <summary>
    //    /// 数量
    //    /// </summary>
    //    public decimal ReqQty
    //    {
    //        get { return _reqQty; }
    //        set { _reqQty = value; }
    //    }

    //    /// <summary>
    //    /// 来源采购订单行
    //    /// </summary>
    //    public int srcDocPOLineNo
    //    {
    //        get { return _srcDocPOLineNo; }
    //        set { _srcDocPOLineNo = value; }
    //    }
    //}
    #endregion


}
