Exemplo n.º 1
0
        private static SAPWebServiceEntity Node2WebServiceEntity(XmlNode node)
        {
            SAPWebServiceEntity entity = new SAPWebServiceEntity();

            entity.m_Url      = node.Attributes["Url"].Value;
            entity.m_UserName = node.Attributes["UserName"].Value;
            entity.m_Password = node.Attributes["Password"].Value;
            return(entity);
        }
Exemplo n.º 2
0
        public object Create(object parent, object configContext, System.Xml.XmlNode section)
        {
            SAPWebServiceEntity webServiceEntity = new SAPWebServiceEntity();

            try
            {
                XmlElement element = null;
                element          = (XmlElement)section;
                webServiceEntity = SAPWebServiceEntity.Parse(element);
            }
            catch
            {
                throw new System.Configuration.ConfigurationErrorsException("Invalid service entity configuration");
            }
            return(webServiceEntity);
        }
Exemplo n.º 3
0
        public ServiceResult Run(RunMethod runMethod)
        {
            /*------ Get WebService URL and UserName and Password ------*/
            SAPWebServiceEntity webServiceEntity = System.Configuration.ConfigurationManager.GetSection("MOBOMTransferConfig") as SAPWebServiceEntity;

            if (webServiceEntity == null)
            {
                return(new ServiceResult(false, "没有维护MOBOMTransferConfig对应的Service地址", this.m_Argument.TransactionCode));
            }

            #region Begin for Prepare input Paremente
            // Prepare input parameter
            DT_MES_POBOM_REQ moBOMParameter = new DT_MES_POBOM_REQ();
            moBOMParameter.Mocode           = this.m_Argument.MOCodeList;
            moBOMParameter.Transaction_code = this.m_Argument.TransactionCode;
            #endregion

            // Serialize the Input Parameter
            string xmlFilePath = SerializeUtil.SerializeFile(this.m_Argument.TransactionCode + "_Request.xml",
                                                             typeof(DT_MES_POBOM_REQ), moBOMParameter);

            #region For Request Log
            DBDateTime         requestDateTime = FormatHelper.GetNowDBDateTime(this.DataProvider);
            SAPDataTransferLog log             = new SAPDataTransferLog();
            // new trans
            TransferFacade transferFacade = new TransferFacade(DomainDataProviderManager.DomainDataProvider());
            log.JobID               = TransferFacade.MOMaterialTransferJobID;
            log.TransactionCode     = this.m_Argument.TransactionCode;
            log.TransactionSequence = 1;
            log.RequestDate         = requestDateTime.DBDate;
            log.RequestTime         = requestDateTime.DBTime;
            log.RequestContent      = xmlFilePath;
            log.OrganizationID      = InternalVariables.MS_OrganizationID;
            log.SendRecordCount     = 1;
            transferFacade.AddSAPDataTransferLog(log);
            #endregion

            #region Begin for Calling WebService
            // Call Web Service through MaterialServiceClientProxy
            DT_MES_POBOM_RESP returnValue;
            try
            {
                MOBOMServiceClientProxy clientProxy = new MOBOMServiceClientProxy();
                clientProxy.RequestEncoding = Encoding.UTF8;
                clientProxy.Timeout         = InternalVariables.MS_TimeOut * 1000;
                clientProxy.Url             = webServiceEntity.Url;
                clientProxy.PreAuthenticate = true;
                System.Uri uri = new Uri(clientProxy.Url);
                clientProxy.Credentials = new NetworkCredential(webServiceEntity.UserName, webServiceEntity.Password).GetCredential(uri, "");
                returnValue             = clientProxy.MI_MES_POBOM_REQ(moBOMParameter);
                clientProxy.Dispose();
                clientProxy = null;

                //Serialize the output Parameter
                xmlFilePath = SerializeUtil.SerializeFile(this.m_Argument.TransactionCode + "_Response.xml",
                                                          typeof(DT_MES_POBOM_RESP), returnValue);

                // Update Log
                DBDateTime responseDateTime = FormatHelper.GetNowDBDateTime(this.DataProvider);
                log.ResponseDate    = responseDateTime.DBDate;
                log.ResponseTime    = responseDateTime.DBTime;
                log.ResponseContent = xmlFilePath;
                transferFacade.UpdateSAPDataTransferLog(log);
            }
            catch (Exception e)
            {
                log.Result       = "Fail";
                log.ErrorMessage = e.Message;
                transferFacade.UpdateSAPDataTransferLog(log);
                return(new ServiceResult(false, e.Message, log.TransactionCode));
            }
            #endregion

            if (string.Compare(returnValue.FLAG, "Y", true) == 0)
            {
                int moBOMCount = returnValue.POCONFIRM_LIST.Length;

                if (runMethod == RunMethod.Manually)
                {
                    ((BenQGuru.eMES.Common.DomainDataProvider.SQLDomainDataProvider)DataProvider).PersistBroker.AutoCloseConnection = false;
                    ((BenQGuru.eMES.Common.DomainDataProvider.SQLDomainDataProvider)DataProvider).PersistBroker.OpenConnection();
                    this.DataProvider.BeginTransaction();
                }

                try
                {
                    #region Main flow
                    MOFacade moBOMFacade = new MOFacade(this.DataProvider);
                    MOBOM    moBOM;
                    DT_MES_POBOM_RESPPOCONFIRM_LIST moBOMObject;

                    for (int j = 0; j < this.m_Argument.MOCodeList.Length; j++)
                    {
                        moBOMFacade.DeleteMOBOMByMOCode(this.m_Argument.MOCodeList[j].ToUpper());

                        for (int i = 0; i < moBOMCount; i++)
                        {
                            if (string.Compare(returnValue.POCONFIRM_LIST[i].MOCODE, this.m_Argument.MOCodeList[j], true) != 0)
                            {
                                continue;
                            }
                            else
                            {
                                moBOMObject = returnValue.POCONFIRM_LIST[i];

                                moBOM               = moBOMFacade.CreateNewMOBOM();
                                moBOM.MOCode        = moBOMObject.MOCODE;
                                moBOM.ItemCode      = InternalVariables.MatchItemCode(moBOMObject.ITEMCODE);
                                moBOM.MOBOMItemCode = InternalVariables.MatchItemCode(moBOMObject.MOBITEMCODE);
                                //moBOM.MOBOMItemName = moBOMObject.MOBITEMDESC;
                                //moBOM.MOBOMItemDescription = moBOMObject.MOBITEMDESC;
                                moBOM.MOBOMItemName          = "";
                                moBOM.MOBOMItemDescription   = "";
                                moBOM.MOBOMItemQty           = decimal.Parse(moBOMObject.MOBITEMQTY);
                                moBOM.MOBOMSourceItemCode    = InternalVariables.MatchItemCode(moBOMObject.MOBITEMCODE);
                                moBOM.MOBOMItemUOM           = moBOMObject.MOBOMITEMUOM;
                                moBOM.Sequence               = moBOMFacade.GetMOBOMMaxSequence(moBOMObject.MOCODE);
                                moBOM.MOBOMItemStatus        = "0";
                                moBOM.MOBOMItemEffectiveDate = 20080101;
                                moBOM.MOBOMItemEffectiveTime = 1;
                                moBOM.MOBOMItemInvalidDate   = 29991231;
                                moBOM.MOBOMItemInvalidTime   = 1;
                                moBOM.MaintainUser           = "******";
                                moBOM.MOBOMItemECN           = "";
                                moBOM.MOBOMItemLocation      = "";
                                moBOM.MOBOMItemVersion       = "";
                                moBOM.MOBOMItemControlType   = "";
                                moBOM.EAttribute1            = "";
                                moBOM.OPCode     = "";
                                moBOM.MoBOM      = moBOMObject.MOBOM;
                                moBOM.MOBOMLine  = moBOMObject.MOBOMLINE;
                                moBOM.MOFactory  = moBOMObject.MOFAC;
                                moBOM.MOResource = moBOMObject.MORESOURCE;

                                moBOMFacade.AddMOBOM(moBOM);
                            }
                        }
                    }

                    if (runMethod == RunMethod.Manually)
                    {
                        this.DataProvider.CommitTransaction();
                    }
                    #endregion

                    log.Result       = "OK";
                    log.ErrorMessage = "";
                }
                catch (Exception ex)
                {
                    if (runMethod == RunMethod.Manually)
                    {
                        this.DataProvider.RollbackTransaction();
                    }

                    // Log
                    log.Result       = "Fail";
                    log.ErrorMessage = ex.Message;
                }
                finally
                {
                    if (runMethod == RunMethod.Manually)
                    {
                        ((BenQGuru.eMES.Common.DomainDataProvider.SQLDomainDataProvider)DataProvider).PersistBroker.CloseConnection();
                        ((BenQGuru.eMES.Common.DomainDataProvider.SQLDomainDataProvider)DataProvider).PersistBroker.AutoCloseConnection = true;
                    }
                }

                log.ReceivedRecordCount = moBOMCount;
                DBDateTime finishedDateTime = FormatHelper.GetNowDBDateTime(this.DataProvider);
                log.FinishedDate = finishedDateTime.DBDate;
                log.FinishedTime = finishedDateTime.DBTime;
                transferFacade.UpdateSAPDataTransferLog(log);

                if (log.Result == "OK")
                {
                    return(new ServiceResult(true, "", log.TransactionCode));
                }
                else
                {
                    return(new ServiceResult(false, log.ErrorMessage, log.TransactionCode));
                }
            }
            else //  status!="OK"
            {
                log.Result              = "Fail";
                log.ErrorMessage        = returnValue.message;
                log.ReceivedRecordCount = 0;
                transferFacade.UpdateSAPDataTransferLog(log);
                return(new ServiceResult(false, log.ErrorMessage, log.TransactionCode));
            }
        }
Exemplo n.º 4
0
        private ServiceResult RunOne(SAPWebServiceEntity webServiceEntity, SAPMaterialTrans sapMaterialTrans, DT_MES_TRANSFERPOST_REQ req)
        {
            string xmlFilePath = SerializeUtil.SerializeFile(this.m_Argument.TransactionCode + "_Request.xml",
                                                             typeof(DT_MES_TRANSFERPOST_REQ), req);

            #region TransferLog

            DBDateTime         dateTime         = FormatHelper.GetNowDBDateTime(this.DataProvider);
            SAPDataTransferLog materialIssueLog = new SAPDataTransferLog();
            TransferFacade     transferFacade   = new TransferFacade(this.DataProvider);

            materialIssueLog.JobID               = TransferFacade.MaterialIssueJobID;
            materialIssueLog.TransactionCode     = this.m_Argument.TransactionCode;
            materialIssueLog.TransactionSequence = 1;
            materialIssueLog.RequestDate         = dateTime.DBDate;
            materialIssueLog.RequestTime         = dateTime.DBTime;
            materialIssueLog.RequestContent      = xmlFilePath;
            materialIssueLog.OrganizationID      = 2000;
            materialIssueLog.SendRecordCount     = 1;

            transferFacade.AddSAPDataTransferLog(materialIssueLog);

            #endregion

            #region Begin for Calling WebService

            try
            {
                MaterialIssueServiceClientProxy clientProxy = new MaterialIssueServiceClientProxy();
                clientProxy.RequestEncoding = Encoding.UTF8;
                clientProxy.Timeout         = InternalVariables.MS_TimeOut * 1000;
                clientProxy.Url             = webServiceEntity.Url;
                clientProxy.PreAuthenticate = true;
                System.Uri uri = new Uri(clientProxy.Url);
                clientProxy.Credentials = new NetworkCredential(webServiceEntity.UserName, webServiceEntity.Password).GetCredential(uri, "");
                clientProxy.MI_MES_TRANSFERPOST_REQ(req);
                clientProxy.Dispose();
                clientProxy = null;
            }
            catch (Exception e)
            {
                materialIssueLog.Result       = "Fail";
                materialIssueLog.ErrorMessage = e.Message;
                transferFacade.UpdateSAPDataTransferLog(materialIssueLog);
                return(new ServiceResult(false, e.Message, materialIssueLog.TransactionCode));
            }

            #endregion

            #region Update tblsapmaterialtrans

            if (sapMaterialTrans != null)
            {
                InventoryFacade inventoryFacade = new InventoryFacade(this.DataProvider);
                try
                {
                    sapMaterialTrans.Flag            = FlagStatus.FlagStatus_POST;
                    sapMaterialTrans.TransactionCode = this.m_Argument.TransactionCode;
                    inventoryFacade.UpdateSAPMaterialTrans(sapMaterialTrans);
                }
                catch (Exception ex)
                {
                    return(new ServiceResult(false, ex.Message, this.m_Argument.TransactionCode));
                }
            }

            #endregion

            return(new ServiceResult(true, "", this.m_Argument.TransactionCode));
        }
Exemplo n.º 5
0
        public ServiceResult Run(RunMethod runMethod)
        {
            ServiceResult returnValue = null;

            SAPWebServiceEntity webServiceEntity = System.Configuration.ConfigurationManager.GetSection("MaterialIssueTransferConfig") as SAPWebServiceEntity;

            if (webServiceEntity == null)
            {
                return(new ServiceResult(false, "没有维护MaterialIssueTransfer对应的Service地址", this.m_Argument.TransactionCode));
            }

            if (runMethod == RunMethod.Auto)
            {
                InventoryFacade inventoryFacade      = new InventoryFacade(this.DataProvider);
                object[]        sapMaterialTransList = inventoryFacade.QuerySAPMaterialTransNotDealed(100);
                if (sapMaterialTransList == null)
                {
                    return(new ServiceResult(true, "", this.m_Argument.TransactionCode));
                }

                foreach (SAPMaterialTrans materialTrans in sapMaterialTransList)
                {
                    System.Threading.Thread.Sleep(10);
                    this.NewTransactionCode();

                    List <DT_MES_TRANSFERPOST_REQTRANSFERITEM> transferItemList = new List <DT_MES_TRANSFERPOST_REQTRANSFERITEM>();
                    DT_MES_TRANSFERPOST_REQTRANSFERITEM        transferItem     = new DT_MES_TRANSFERPOST_REQTRANSFERITEM();
                    transferItem.PSTNG_DATE = materialTrans.AccountDate.ToString();
                    transferItem.DOC_DATE   = materialTrans.VoucherDate.ToString();
                    transferItem.MATERIAL   = materialTrans.ItemCode;
                    transferItem.PLANT      = materialTrans.OrganizationID.ToString();
                    transferItem.STGE_LOC   = materialTrans.FRMStorageID;
                    transferItem.MOVE_STLOC = materialTrans.TOStorageID;
                    transferItem.ENTRY_QNT  = materialTrans.TransQTY.ToString();
                    transferItem.ENTRY_UOM  = materialTrans.Unit;
                    transferItem.HEADER_TXT = materialTrans.ReceiveMemo;
                    transferItem.VENDOR     = materialTrans.VendorCode;
                    transferItem.REF_DOC_NO = materialTrans.MoCode;

                    //transferItem.MOVE_TYPE = "411";
                    transferItem.MOVE_TYPE = materialTrans.SAPCode;

                    transferItemList.Add(transferItem);

                    DT_MES_TRANSFERPOST_REQ materialIssueParameter = new DT_MES_TRANSFERPOST_REQ();
                    materialIssueParameter.TRANSCODE    = this.m_Argument.TransactionCode;
                    materialIssueParameter.TRANSFERITEM = transferItemList.ToArray();

                    returnValue = RunOne(webServiceEntity, materialTrans, materialIssueParameter);
                    if (!returnValue.Result)
                    {
                        break;
                    }
                }
            }
            else if (runMethod == RunMethod.Manually)
            {
                DT_MES_TRANSFERPOST_REQ materialIssueParameter = new DT_MES_TRANSFERPOST_REQ();
                materialIssueParameter.TRANSCODE    = this.m_Argument.TransactionCode;
                materialIssueParameter.TRANSFERITEM = this.m_Argument.InventoryList.ToArray();

                returnValue = RunOne(webServiceEntity, null, materialIssueParameter);
            }

            if (returnValue == null)
            {
                returnValue = new ServiceResult(true, "", this.m_Argument.TransactionCode);
            }

            return(returnValue);
        }
Exemplo n.º 6
0
        public ServiceResult Run(RunMethod runMethod)
        {
            /*====Get WebService URL and UserName and Password====*/
            SAPWebServiceEntity webServiceEntity = System.Configuration.ConfigurationManager.GetSection("MaterialTransferConfig") as SAPWebServiceEntity;

            if (webServiceEntity == null)
            {
                return(new ServiceResult(false, "没有维护MaterialTransferConfig对应的Service地址", this.m_Argument.TransactionCode));
            }

            #region Begin for Prepare input Paremente
            // Prepare input parameter
            DT_MES_MATERIAL_REQ materialParameter = new DT_MES_MATERIAL_REQ();
            materialParameter.MaintainDate_B   = this.m_Argument.MaintainDate_B.Date.ToString("yyyyMMdd", new System.Globalization.CultureInfo("en-US"));
            materialParameter.MaintainDate_E   = this.m_Argument.MaintainDate_E.Date.ToString("yyyyMMdd", new System.Globalization.CultureInfo("en-US"));
            materialParameter.OrgID            = this.m_Argument.OrgID.ToString();
            materialParameter.Transaction_code = this.m_Argument.TransactionCode;
            #endregion

            // Serialize the Input Parameter
            string xmlFilePath = SerializeUtil.SerializeFile(this.m_Argument.TransactionCode + "_Request.xml",
                                                             typeof(DT_MES_MATERIAL_REQ), materialParameter);

            #region For Request Log
            DBDateTime         requestDateTime = FormatHelper.GetNowDBDateTime(this.DataProvider);
            SAPDataTransferLog log             = new SAPDataTransferLog();
            TransferFacade     transferFacade  = new TransferFacade(this.DataProvider);
            log.JobID               = TransferFacade.MaterialTransferJobID;
            log.TransactionCode     = this.m_Argument.TransactionCode;
            log.TransactionSequence = 1;
            log.RequestDate         = requestDateTime.DBDate;
            log.RequestTime         = requestDateTime.DBTime;
            log.RequestContent      = xmlFilePath;
            log.OrganizationID      = this.m_Argument.OrgID;
            log.SendRecordCount     = 1;
            transferFacade.AddSAPDataTransferLog(log);
            #endregion

            #region Begin for Calling WebService
            // Call Web Service through MaterialServiceClientProxy
            DT_MES_MATERIAL_RESP returnValue;
ReTryLabel:
            m_RetriedTimes++;
            try
            {
                MaterialServiceClientProxy clientProxy = new MaterialServiceClientProxy();
                clientProxy.RequestEncoding = Encoding.UTF8;
                clientProxy.Timeout         = InternalVariables.MS_TimeOut * 1000;
                clientProxy.Url             = webServiceEntity.Url;
                clientProxy.PreAuthenticate = true;
                System.Uri uri = new Uri(clientProxy.Url);
                clientProxy.Credentials = new NetworkCredential(webServiceEntity.UserName, webServiceEntity.Password).GetCredential(uri, "");
                returnValue             = clientProxy.MI_MES_MATERIAL_REQ(materialParameter);
                clientProxy.Dispose();
                clientProxy = null;

                //Serialize the output Parameter
                xmlFilePath = SerializeUtil.SerializeFile(this.m_Argument.TransactionCode + "_Response.xml",
                                                          typeof(DT_MES_MATERIAL_RESP), returnValue);

                // Update Log
                DBDateTime responseDateTime = FormatHelper.GetNowDBDateTime(this.DataProvider);
                log.ResponseDate    = responseDateTime.DBDate;
                log.ResponseTime    = responseDateTime.DBTime;
                log.ResponseContent = xmlFilePath;
                transferFacade.UpdateSAPDataTransferLog(log);
            }
            catch (Exception e)
            {
                #region Retry or log it
                if (e.Message.IndexOf("Server Error", StringComparison.CurrentCultureIgnoreCase) >= 0)
                {
                    if (m_RetriedTimes < InternalVariables.MS_ReTryTimes)
                    {
                        System.Threading.Thread.Sleep(InternalVariables.MS_ReTryInterval * 1000);
                        goto ReTryLabel;
                    }
                    else
                    {
                        log.Result       = "Fail";
                        log.ErrorMessage = e.Message;
                        transferFacade.UpdateSAPDataTransferLog(log);
                        return(new ServiceResult(false, e.Message, log.TransactionCode));
                    }
                }
                else
                {
                    if (e is System.Net.WebException)
                    {
                        if (((System.Net.WebException)e).Status == WebExceptionStatus.Timeout)
                        {
                            if (m_RetriedTimes < InternalVariables.MS_ReTryTimes)
                            {
                                System.Threading.Thread.Sleep(InternalVariables.MS_ReTryInterval * 1000);
                                goto ReTryLabel;
                            }
                            else
                            {
                                log.Result       = "Fail";
                                log.ErrorMessage = e.Message;
                                transferFacade.UpdateSAPDataTransferLog(log);
                                return(new ServiceResult(false, e.Message, log.TransactionCode));
                            }
                        }
                        else
                        {
                            log.Result       = "Fail";
                            log.ErrorMessage = e.Message;
                            transferFacade.UpdateSAPDataTransferLog(log);
                            return(new ServiceResult(false, e.Message, log.TransactionCode));
                        }
                    }
                    else
                    {
                        log.Result       = "Fail";
                        log.ErrorMessage = e.Message;
                        transferFacade.UpdateSAPDataTransferLog(log);
                        return(new ServiceResult(false, e.Message, log.TransactionCode));
                    }
                }
                #endregion
            }
            #endregion

            // Generate Material Object and Save it
            if (string.Compare(returnValue.FLAG, "Y", true) == 0)
            {
                int materialCount = returnValue.Material_Tab.Length;

                ((BenQGuru.eMES.Common.DomainDataProvider.SQLDomainDataProvider)DataProvider).PersistBroker.AutoCloseConnection = false;
                ((BenQGuru.eMES.Common.DomainDataProvider.SQLDomainDataProvider)DataProvider).PersistBroker.OpenConnection();
                this.DataProvider.BeginTransaction();

                try
                {
                    ItemFacade  itemFacade  = new ItemFacade(this.DataProvider);
                    ModelFacade modelFacade = new ModelFacade(this.DataProvider);
                    BenQGuru.eMES.Domain.MOModel.Material material;
                    DT_MES_MATERIAL_TAB_RESP materialObj;
                    DBDateTime currentDateTime = FormatHelper.GetNowDBDateTime(this.DataProvider);

                    #region Get Parameters
                    // Get CheckOPCode and LotSize
                    SystemSettingFacade ssf      = new SystemSettingFacade(this.DataProvider);
                    string finishGoodCheckOPCode = "AWGJC1";
                    object para = ssf.GetParameter("FINISHEDPRODUCTOPCODE", "ITEMCHECKOP");
                    if (para != null)
                    {
                        finishGoodCheckOPCode = (para as Parameter).ParameterAlias.Trim().ToUpper();
                    }
                    string semiGoodCheckOPCode = "ATSH1";
                    para = ssf.GetParameter("SEMIMANUFACTUREOPCODE", "ITEMCHECKOP");
                    if (para != null)
                    {
                        semiGoodCheckOPCode = (para as Parameter).ParameterAlias.Trim().ToUpper();
                    }
                    int finishGoodLotSize = 200;
                    para = ssf.GetParameter("FINISHEDPRODUCTLOTSIZE", "ITEMLOTSIZE");
                    if (para != null)
                    {
                        finishGoodLotSize = int.Parse((para as Parameter).ParameterAlias.Trim());
                    }
                    int semiGoodLotSize = 500;
                    para = ssf.GetParameter("SEMIMANUFACTURELOTSIZE", "ITEMLOTSIZE");
                    if (para != null)
                    {
                        semiGoodLotSize = int.Parse((para as Parameter).ParameterAlias.Trim());
                    }

                    // Get NeedCheckCarton and NeedCheckAccessory from parameter table
                    string importFGCheckCarton = "1";
                    para = ssf.GetParameter("FGIMPORTCHKCARTON", "CHECKPACKING");
                    if (para != null)
                    {
                        importFGCheckCarton = (para as Parameter).ParameterAlias.Trim();
                    }
                    string exportFGCheckCarton = "1";
                    para = ssf.GetParameter("FGEXPORTCHKCARTON", "CHECKPACKING");
                    if (para != null)
                    {
                        exportFGCheckCarton = (para as Parameter).ParameterAlias.Trim();
                    }
                    string importFGCheckAccessory = "1";
                    para = ssf.GetParameter("FGIMPORTCHKACCESSORY", "CHECKPACKING");
                    if (para != null)
                    {
                        importFGCheckAccessory = (para as Parameter).ParameterAlias.Trim();
                    }
                    string exportFGCheckAccessory = "0";
                    para = ssf.GetParameter("FGEXPORTCHKACCESSORY", "CHECKPACKING");
                    if (para != null)
                    {
                        exportFGCheckAccessory = (para as Parameter).ParameterAlias.Trim();
                    }
                    #endregion

                    for (int i = 0; i < materialCount; i++)
                    {
                        #region Material Object
                        bool needAddNew = false;
                        materialObj = returnValue.Material_Tab[i];
                        object oldMaterial = itemFacade.GetMaterial(InternalVariables.MatchItemCode(materialObj.Itemcode.ToUpper()), int.Parse(materialObj.OrgID.Trim()));

                        if (oldMaterial == null)
                        {
                            material = itemFacade.CreateNewMaterial();
                            material.MaintainUser       = "******";
                            material.EAttribute1        = "";
                            material.CheckStatus        = "";
                            material.MaterialParseType  = "";
                            material.MaterialCheckType  = "";
                            material.MaterialModelGroup = "";

                            if (string.Compare(materialObj.ITEMCONTROL, "A", true) == 0 ||
                                string.Compare(materialObj.ITEMCONTROL, "B", true) == 0)
                            {
                                material.MaterialCheckType = OPBOMDetailCheckType.CHECK_LINKBARCODE;
                            }

                            needAddNew = true;
                        }
                        else
                        {
                            material   = oldMaterial as BenQGuru.eMES.Domain.MOModel.Material;
                            needAddNew = false;
                        }

                        #region 属性赋值
                        /*---------------------  Web Service 节点数据 ---------------------*/
                        material.MaterialCode        = InternalVariables.MatchItemCode(materialObj.Itemcode.ToUpper());
                        material.OrganizationID      = int.Parse(materialObj.OrgID);
                        material.MaterialName        = materialObj.itemname.ToUpper();
                        material.MaterialDescription = materialObj.itemname.ToUpper();
                        material.MaterialUOM         = materialObj.ITEMUOM;

                        if (string.Compare(materialObj.ITEMTYPE, "FERT", true) == 0)
                        {
                            material.MaterialType = ItemType.ITEMTYPE_FINISHEDPRODUCT;
                        }
                        else if (string.Compare(materialObj.ITEMTYPE, "HALB", true) == 0)
                        {
                            material.MaterialType = ItemType.ITEMTYPE_SEMIMANUFACTURE;
                        }
                        else if (string.Compare(materialObj.ITEMTYPE, "ROH", true) == 0)
                        {
                            material.MaterialType = ItemType.ITEMTYPE_RAWMATERIAL;
                        }
                        else
                        {
                            continue;
                        }

                        material.MaterialMachineType      = materialObj.ItemMachineType;
                        material.MaterialVolume           = materialObj.Itemvolume;
                        material.MaterialGroup            = materialObj.ItemGroup;
                        material.MaterialGroupDescription = materialObj.ItemGroupDesc.ToUpper();
                        material.MaterialModelGroup       = "";

                        if (string.Compare(materialObj.ITEMCONTROL, "A", true) == 0)
                        {
                            material.MaterialControlType = BOMItemControlType.ITEM_CONTROL_KEYPARTS;
                        }
                        else if (string.Compare(materialObj.ITEMCONTROL, "B", true) == 0)
                        {
                            material.MaterialControlType = BOMItemControlType.ITEM_CONTROL_LOT;
                        }
                        else
                        {
                            material.MaterialControlType = BOMItemControlType.ITEM_CONTROL_NOCONTROL;
                        }

                        if (materialObj.itemname.Split('.').Length > 3)
                        {
                            material.MaterialModelCode = materialObj.itemname.Split('.')[2];
                        }
                        else
                        {
                            material.MaterialModelCode = "";
                        }

                        if (materialObj.itemname.Contains("中国"))
                        {
                            material.MaterialExportImport = "IMPORT";
                        }
                        else
                        {
                            material.MaterialExportImport = "EXPORT";
                        }

                        if (material.MaterialDescription.Length >= 3)
                        {
                            if (string.Compare(material.MaterialDescription.Substring(material.MaterialDescription.Length - 3, 3),
                                               "ROH", true) == 0)
                            {
                                material.ROHS = "Y";
                            }
                            else
                            {
                                material.ROHS = "";
                            }
                        }
                        else
                        {
                            material.ROHS = "";
                        }
                        #endregion

                        // Save
                        if (needAddNew)
                        {
                            itemFacade.AddMaterial(material);
                        }
                        else
                        {
                            itemFacade.UpdateMaterial(material);
                        }
                        #endregion

                        #region Finish Good & Semi Finish Good
                        /*------------ 如果ItemType是半成品或者成品,则同时更新或插入tblitem----------*/
                        if (material.MaterialType == ItemType.ITEMTYPE_FINISHEDPRODUCT ||
                            material.MaterialType == ItemType.ITEMTYPE_SEMIMANUFACTURE)
                        {
                            needAddNew = false;
                            BenQGuru.eMES.Domain.MOModel.Item item;
                            object oldItem = itemFacade.GetItem(material.MaterialCode.ToUpper(), material.OrganizationID);

                            if (oldItem == null)
                            {
                                item = itemFacade.CreateNewItem();

                                /*-------------- 固定数据 ----------*/
                                item.ItemVersion             = "";
                                item.MaintainUser            = "******";
                                item.ItemUser                = "******";
                                item.ItemDate                = currentDateTime.DBDate;
                                item.EAttribute1             = "";
                                item.ItemConfigration        = "";
                                item.ItemCartonQty           = 1;
                                item.ItemBurnInQty           = 0;
                                item.ElectricCurrentMaxValue = 0;
                                item.ElectricCurrentMinValue = 0;
                                item.ItemProductCode         = "";

                                if (material.MaterialType == ItemType.ITEMTYPE_FINISHEDPRODUCT)
                                {
                                    item.CheckItemOP = finishGoodCheckOPCode;
                                    item.LotSize     = finishGoodLotSize;
                                }
                                else if (material.MaterialType == ItemType.ITEMTYPE_SEMIMANUFACTURE)
                                {
                                    item.CheckItemOP = semiGoodCheckOPCode;
                                    item.LotSize     = semiGoodLotSize;
                                }

                                if (material.MaterialType == ItemType.ITEMTYPE_FINISHEDPRODUCT)
                                {
                                    if (material.MaterialExportImport == "IMPORT")
                                    {
                                        item.NeedCheckCarton    = importFGCheckCarton;
                                        item.NeedCheckAccessory = importFGCheckAccessory;
                                    }
                                    else
                                    {
                                        item.NeedCheckCarton    = exportFGCheckCarton;
                                        item.NeedCheckAccessory = exportFGCheckAccessory;
                                    }
                                }
                                else
                                {
                                    item.NeedCheckCarton    = "0";
                                    item.NeedCheckAccessory = "0";
                                }

                                needAddNew = true;
                            }
                            else
                            {
                                item = oldItem as Item;

                                needAddNew = false;
                            }

                            /*----- Web Service 节点数据 -----*/
                            item.ItemCode        = material.MaterialCode;
                            item.OrganizationID  = material.OrganizationID;
                            item.ItemName        = material.MaterialName.ToUpper();
                            item.ItemDescription = material.MaterialName.ToUpper();
                            item.ItemUOM         = material.MaterialUOM;
                            item.ItemType        = material.MaterialType;
                            item.ItemControlType = material.MaterialControlType;

                            if (needAddNew)
                            {
                                itemFacade.AddItem(item);
                            }
                            else
                            {
                                itemFacade.UpdateItem(item);
                            }

                            // ItemSNCheck
                            if (itemFacade.GetItem2SNCheck(item.ItemCode, ItemCheckType.ItemCheckType_SERIAL) == null)
                            {
                                Item2SNCheck item2SNCheck = new Item2SNCheck();
                                item2SNCheck.ItemCode     = item.ItemCode;
                                item2SNCheck.EAttribute1  = "";
                                item2SNCheck.MaintainUser = "******";
                                if (material.MaterialType == ItemType.ITEMTYPE_FINISHEDPRODUCT)
                                {
                                    item2SNCheck.SNLength = 24;
                                    item2SNCheck.SNPrefix = item.ItemCode;
                                }
                                else // ITEMTYPE_SEMIMANUFACTURE
                                {
                                    item2SNCheck.SNLength = 10;
                                    item2SNCheck.SNPrefix = "";
                                }
                                item2SNCheck.SNContentCheck = "Y";
                                item2SNCheck.Type           = "SERIAL";
                                itemFacade.AddItem2SNCheck(item2SNCheck);
                            }

                            /*----------- 物料所属物料别插入tblmodel2item中,取物料料号的第二位为物料别 ---------*/
                            object oldModel2Item = modelFacade.GetModel2Item(item.ItemCode.Substring(1, 1), item.ItemCode, item.OrganizationID);
                            if (oldModel2Item == null)
                            {
                                Model2Item model2Item = new Model2Item();
                                model2Item.ModelCode      = item.ItemCode.Substring(1, 1);
                                model2Item.ItemCode       = item.ItemCode;
                                model2Item.OrganizationID = item.OrganizationID;
                                model2Item.MaintainUser   = "******";

                                modelFacade.AddModel2Item(model2Item);
                            }

                            /*---- 在tblmodel2item中Distinct tblmodel2item.modelcode,如果不存在于tblmodel中,则插入tblmodel ----*/
                            object oldModel = modelFacade.GetModel(item.ItemCode.Substring(1, 1), item.OrganizationID);
                            if (oldModel == null)
                            {
                                Model model = new Model();
                                model.ModelCode        = item.ItemCode.Substring(1, 1);
                                model.OrganizationID   = item.OrganizationID;
                                model.MaintainUser     = "******";
                                model.ModelDescription = model.ModelCode;
                                model.DataLinkQty      = 0;
                                model.DimQty           = 0;
                                model.EAttribute1      = "";
                                model.IsCheckDataLink  = "0";
                                model.IsDim            = "0";
                                model.IsInventory      = "1";
                                model.IsReflow         = "0";

                                modelFacade.AddModel(model);
                            }
                        }
                        #endregion
                    }

                    this.DataProvider.CommitTransaction();

                    log.Result       = "OK";
                    log.ErrorMessage = "";
                }
                catch (Exception ex)
                {
                    this.DataProvider.RollbackTransaction();
                    // Log
                    log.Result       = "Fail";
                    log.ErrorMessage = ex.Message;
                }
                finally
                {
                    ((BenQGuru.eMES.Common.DomainDataProvider.SQLDomainDataProvider)DataProvider).PersistBroker.CloseConnection();
                    ((BenQGuru.eMES.Common.DomainDataProvider.SQLDomainDataProvider)DataProvider).PersistBroker.AutoCloseConnection = true;
                }

                log.ReceivedRecordCount = materialCount;
                DBDateTime finishedDateTime = FormatHelper.GetNowDBDateTime(this.DataProvider);
                log.FinishedDate = finishedDateTime.DBDate;
                log.FinishedTime = finishedDateTime.DBTime;
                transferFacade.UpdateSAPDataTransferLog(log);

                if (log.Result == "OK")
                {
                    return(new ServiceResult(true, "", log.TransactionCode));
                }
                else
                {
                    return(new ServiceResult(false, log.ErrorMessage, log.TransactionCode));
                }
            }
            else //  status!="OK"
            {
                log.Result              = "Fail";
                log.ErrorMessage        = returnValue.message;
                log.ReceivedRecordCount = 0;
                transferFacade.UpdateSAPDataTransferLog(log);
                return(new ServiceResult(false, log.ErrorMessage, log.TransactionCode));
            }
        }
Exemplo n.º 7
0
        private ServiceResult RunOne(SAPWebServiceEntity webServiceEntity, MaterialReceive materialReceive, DT_MES_SOURCESTOCK_REQ materialPOParameter)
        {
            IQCFacade iqcFacade = new IQCFacade(this.DataProvider);

            string xmlFilePath = SerializeUtil.SerializeFile(this.m_Argument.TransactionCode + "_Request.xml",
                                                             typeof(DT_MES_SOURCESTOCK_REQ), materialPOParameter);

            #region TransferLog

            DBDateTime         dateTime       = FormatHelper.GetNowDBDateTime(this.DataProvider);
            SAPDataTransferLog materialPOLog  = new SAPDataTransferLog();
            TransferFacade     transferFacade = new TransferFacade(this.DataProvider);

            materialPOLog.JobID               = TransferFacade.MaterialPOJobID;
            materialPOLog.TransactionCode     = this.m_Argument.TransactionCode;
            materialPOLog.TransactionSequence = 1;
            materialPOLog.RequestDate         = dateTime.DBDate;
            materialPOLog.RequestTime         = dateTime.DBTime;
            materialPOLog.RequestContent      = xmlFilePath;
            materialPOLog.OrganizationID      = 2000;
            materialPOLog.SendRecordCount     = 1;

            transferFacade.AddSAPDataTransferLog(materialPOLog);

            #endregion

            #region Begin for Calling WebService

            try
            {
                MaterialPOServiceClientProxy clientProxy = new MaterialPOServiceClientProxy();
                clientProxy.RequestEncoding = Encoding.UTF8;
                clientProxy.Timeout         = InternalVariables.MS_TimeOut * 1000;
                clientProxy.Url             = webServiceEntity.Url;
                clientProxy.PreAuthenticate = true;
                System.Uri uri = new Uri(clientProxy.Url);
                clientProxy.Credentials = new NetworkCredential(webServiceEntity.UserName, webServiceEntity.Password).GetCredential(uri, "");
                clientProxy.MI_MES_SOURCESTOCK_REQ(materialPOParameter);
                clientProxy.Dispose();
                clientProxy = null;
            }
            catch (Exception e)
            {
                materialPOLog.Result       = "Fail";
                materialPOLog.ErrorMessage = e.Message;
                transferFacade.UpdateSAPDataTransferLog(materialPOLog);
                return(new ServiceResult(false, e.Message, materialPOLog.TransactionCode));
            }

            #endregion

            #region UPDATE tblmaterialreceive

            try
            {
                this.DataProvider.BeginTransaction();

                foreach (DT_MES_SOURCESTOCK_REQLIST post in materialPOParameter.LIST)
                {
                    materialReceive = (MaterialReceive)iqcFacade.GetMaterialReceive(materialReceive.IQCNo, materialReceive.STLine);
                    if (materialReceive != null)
                    {
                        materialReceive.Flag            = FlagStatus.FlagStatus_POST;
                        materialReceive.TransactionCode = this.m_Argument.TransactionCode;
                        iqcFacade.UpdateMaterialReceive(materialReceive);
                    }
                }

                this.DataProvider.CommitTransaction();
            }
            catch (Exception ex)
            {
                this.DataProvider.RollbackTransaction();
                return(new ServiceResult(false, ex.Message, this.m_Argument.TransactionCode));
            }

            #endregion

            return(new ServiceResult(true, "", this.m_Argument.TransactionCode));
        }
Exemplo n.º 8
0
        public ServiceResult Run(RunMethod runMethod)
        {
            ServiceResult returnValue = null;

            SAPWebServiceEntity webServiceEntity = System.Configuration.ConfigurationManager.GetSection("MaterialPOTransferConfig") as SAPWebServiceEntity;

            if (webServiceEntity == null)
            {
                if (System.Configuration.ConfigurationManager.AppSettings["MPOWebServiceUrl"] != null &&
                    System.Configuration.ConfigurationManager.AppSettings["MPOWebServiceUserName"] != null &&
                    System.Configuration.ConfigurationManager.AppSettings["MPOWebServicePassword"] != null)
                {
                    webServiceEntity          = new SAPWebServiceEntity();
                    webServiceEntity.Url      = System.Configuration.ConfigurationManager.AppSettings["MPOWebServiceUrl"];
                    webServiceEntity.UserName = System.Configuration.ConfigurationManager.AppSettings["MPOWebServiceUserName"];
                    webServiceEntity.Password = System.Configuration.ConfigurationManager.AppSettings["MPOWebServicePassword"];
                }
                else
                {
                    return(new ServiceResult(false, "没有维护MaterialPOTransfer对应的Service地址", this.m_Argument.TransactionCode));
                }
            }

            #region Begin for Prepare input Paremeter

            IQCFacade iqcFacade = new IQCFacade(this.DataProvider);

            object[] materialReceiveList = null;
            if (runMethod == RunMethod.Auto)
            {
                materialReceiveList = iqcFacade.QueryMaterialReceiveNotConfirmed(100);
            }
            else if (runMethod == RunMethod.Manually)
            {
                MaterialReceive materialReceive = (MaterialReceive)iqcFacade.GetMaterialReceive(m_Argument.IQCNo, m_Argument.STLine);

                if (materialReceive != null && materialReceive.Flag == FlagStatus.FlagStatus_MES)
                {
                    materialReceiveList = new MaterialReceive[] { materialReceive };
                }
            }

            #endregion

            if (materialReceiveList != null)
            {
                List <DT_MES_SOURCESTOCK_REQLIST> inventoryList = new List <DT_MES_SOURCESTOCK_REQLIST>();
                foreach (MaterialReceive materialReceive in materialReceiveList)
                {
                    System.Threading.Thread.Sleep(500);

                    this.NewTransactionCode();
                    inventoryList.Clear();

                    DT_MES_SOURCESTOCK_REQLIST post = new DT_MES_SOURCESTOCK_REQLIST();
                    post.PSTNG_DATE = materialReceive.AccountDate.ToString();
                    post.DOC_DATE   = materialReceive.VoucherDate.ToString();
                    post.PO_NUMBER  = materialReceive.OrderNo;
                    post.PO_ITEM    = materialReceive.OrderLine.ToString();
                    post.MATERIAL   = materialReceive.ItemCode;
                    post.PLANT      = materialReceive.OrganizationID.ToString();
                    post.STGE_LOC   = materialReceive.StorageID;
                    post.ENTRY_QNT  = materialReceive.RealReceiveQty.ToString();
                    post.ENTRY_UOM  = materialReceive.Unit;
                    post.HEADER_TXT = materialReceive.ReceiveMemo;
                    post.MOVE_TYPE  = "101";

                    inventoryList.Add(post);

                    DT_MES_SOURCESTOCK_REQ materialPOParameter = new DT_MES_SOURCESTOCK_REQ();
                    materialPOParameter.TRANSCODE = this.m_Argument.TransactionCode;
                    materialPOParameter.LIST      = inventoryList.ToArray();

                    returnValue = RunOne(webServiceEntity, materialReceive, materialPOParameter);
                    if (!returnValue.Result)
                    {
                        break;
                    }
                }
            }

            if (returnValue == null)
            {
                returnValue = new ServiceResult(true, "", this.m_Argument.TransactionCode);
            }
            return(returnValue);
        }
Exemplo n.º 9
0
        public ServiceResult Run(RunMethod runMethod)
        {
            /*====Get WebService URL and UserName and Password====*/
            SAPWebServiceEntity webServiceEntity = System.Configuration.ConfigurationManager.GetSection("DNTransferConfig") as SAPWebServiceEntity;

            if (webServiceEntity == null)
            {
                return(new ServiceResult(false, "没有维护DNTransfer对应的Service地址", this.m_Argument.TransactionCode));
            }

            #region Begin for Prepare input Paremente
            // Prepare input parameter
            DT_MES_DN_REQ dnParameter = new DT_MES_DN_REQ();
            dnParameter.TRANS = this.m_Argument.TransactionCode;

            if (this.m_Argument.DNCode.Trim().Length == 0)
            {
                dnParameter.DATE_B = this.m_Argument.MaintainDate_B.Date.ToString("yyyyMMdd", new System.Globalization.CultureInfo("en-US"));
                dnParameter.DATE_E = this.m_Argument.MaintainDate_E.Date.ToString("yyyyMMdd", new System.Globalization.CultureInfo("en-US"));
                dnParameter.WERKS  = this.m_Argument.OrgList;
                dnParameter.VBELN  = "";
            }
            else
            {
                dnParameter.DATE_B = "";
                dnParameter.DATE_E = "";
                dnParameter.WERKS  = null;
                dnParameter.VBELN  = this.m_Argument.DNCode.Trim().ToUpper();
            }
            #endregion

            // Serialize the Input Parameter
            string xmlFilePath = SerializeUtil.SerializeFile(this.m_Argument.TransactionCode + "_Request.xml",
                                                             typeof(DT_MES_DN_REQ), dnParameter);

            #region For Request Log
            DBDateTime         requestDateTime = FormatHelper.GetNowDBDateTime(this.DataProvider);
            SAPDataTransferLog log             = new SAPDataTransferLog();
            TransferFacade     transferFacade  = new TransferFacade(this.DataProvider);
            log.JobID               = TransferFacade.DNTransferJobID;
            log.TransactionCode     = this.m_Argument.TransactionCode;
            log.TransactionSequence = 1;
            log.RequestDate         = requestDateTime.DBDate;
            log.RequestTime         = requestDateTime.DBTime;
            log.RequestContent      = xmlFilePath;
            log.OrganizationID      = 2000;
            log.SendRecordCount     = 1;
            transferFacade.AddSAPDataTransferLog(log);
            #endregion

            #region Begin for Calling WebService
            // Call Web Service through DNServiceClientProxy
            try
            {
                DNServiceClientProxy clientProxy = new DNServiceClientProxy();
                clientProxy.RequestEncoding = Encoding.UTF8;
                clientProxy.Timeout         = InternalVariables.MS_TimeOut * 1000;
                clientProxy.Url             = webServiceEntity.Url;
                clientProxy.PreAuthenticate = true;
                System.Uri uri = new Uri(clientProxy.Url);
                clientProxy.Credentials = new NetworkCredential(webServiceEntity.UserName, webServiceEntity.Password).GetCredential(uri, "");
                clientProxy.MI_MES_DN_REQ(dnParameter);
                clientProxy.Dispose();
                clientProxy = null;
            }
            catch (Exception e)
            {
                log.Result       = "Fail";
                log.ErrorMessage = e.Message;
                transferFacade.UpdateSAPDataTransferLog(log);
                return(new ServiceResult(false, e.Message, log.TransactionCode));
            }
            #endregion

            return(new ServiceResult(true, "", this.m_Argument.TransactionCode));
        }
Exemplo n.º 10
0
        public ServiceResult Run(RunMethod runMethod)
        {
            /*--------- Get WebService URL and UserName and Password ---------*/
            SAPWebServiceEntity webServiceEntity = System.Configuration.ConfigurationManager.GetSection("MOHeaderTransferConfig") as SAPWebServiceEntity;

            if (webServiceEntity == null)
            {
                return(new ServiceResult(false, "没有维护MOHeaderTransferConfig对应的Service地址", this.m_Argument.TransactionCode));
            }

            #region Begin for Prepare input Paremente
            // Prepare input parameter
            DT_MES_PO_REQ moParameter = new DT_MES_PO_REQ();
            moParameter.Trsaction_Code = this.m_Argument.TransactionCode;
            if (this.m_Argument.MOCode.Trim().Length == 0)
            {
                moParameter.MaintainDate_B = this.m_Argument.MaintainDate_B.Date.ToString("yyyyMMdd", new System.Globalization.CultureInfo("en-US"));
                moParameter.MaintainDate_E = this.m_Argument.MaintainDate_E.Date.ToString("yyyyMMdd", new System.Globalization.CultureInfo("en-US"));
                moParameter.OrgID          = this.m_Argument.OrgID.ToString();
                moParameter.Mocode         = "";
            }
            else
            {
                moParameter.MaintainDate_B = "";
                moParameter.MaintainDate_E = "";
                moParameter.OrgID          = "";
                moParameter.Mocode         = this.m_Argument.MOCode.ToUpper().Trim();
            }
            #endregion

            // Serialize the Input Parameter
            string xmlFilePath = SerializeUtil.SerializeFile(this.m_Argument.TransactionCode + "_Request.xml",
                                                             typeof(DT_MES_PO_REQ), moParameter);

            #region For Request Log
            DBDateTime         requestDateTime = FormatHelper.GetNowDBDateTime(this.DataProvider);
            SAPDataTransferLog log             = new SAPDataTransferLog();
            TransferFacade     transferFacade  = new TransferFacade(this.DataProvider);
            log.JobID               = TransferFacade.MOHeaderTransferJobID;
            log.TransactionCode     = this.m_Argument.TransactionCode;
            log.TransactionSequence = 1;
            log.RequestDate         = requestDateTime.DBDate;
            log.RequestTime         = requestDateTime.DBTime;
            log.RequestContent      = xmlFilePath;
            log.OrganizationID      = this.m_Argument.OrgID;
            log.SendRecordCount     = 1;
            transferFacade.AddSAPDataTransferLog(log);
            #endregion

            #region Begin for Calling WebService
            // Call Web Service through MOServiceClientProxy
            DT_MES_PO_RESP returnValue;
            try
            {
                MOServiceClientProxy clientProxy = new MOServiceClientProxy();
                clientProxy.RequestEncoding = Encoding.UTF8;
                clientProxy.Timeout         = InternalVariables.MS_TimeOut * 1000;
                clientProxy.Url             = webServiceEntity.Url;
                clientProxy.PreAuthenticate = true;
                System.Uri uri = new Uri(clientProxy.Url);
                clientProxy.Credentials = new NetworkCredential(webServiceEntity.UserName, webServiceEntity.Password).GetCredential(uri, "");
                returnValue             = clientProxy.MI_MES_PO_REQ(moParameter);
                clientProxy.Dispose();
                clientProxy = null;

                //Serialize the output Parameter
                xmlFilePath = SerializeUtil.SerializeFile(this.m_Argument.TransactionCode + "_Response.xml",
                                                          typeof(DT_MES_PO_RESP), returnValue);

                // Update Log
                DBDateTime responseDateTime = FormatHelper.GetNowDBDateTime(this.DataProvider);
                log.ResponseDate    = responseDateTime.DBDate;
                log.ResponseTime    = responseDateTime.DBTime;
                log.ResponseContent = xmlFilePath;
                transferFacade.UpdateSAPDataTransferLog(log);
            }
            catch (Exception e)
            {
                log.Result       = "Fail";
                log.ErrorMessage = e.Message;
                transferFacade.UpdateSAPDataTransferLog(log);
                return(new ServiceResult(false, e.Message, log.TransactionCode));
            }
            #endregion

            // Generate MO Object and Save it
            if (string.Compare(returnValue.FLAG, "Y", true) == 0)
            {
                int    moCount = returnValue.POLIST.Length;
                string moList  = "";

                ((BenQGuru.eMES.Common.DomainDataProvider.SQLDomainDataProvider)DataProvider).PersistBroker.AutoCloseConnection = false;
                ((BenQGuru.eMES.Common.DomainDataProvider.SQLDomainDataProvider)DataProvider).PersistBroker.OpenConnection();
                this.DataProvider.BeginTransaction();

                try
                {
                    MOFacade             moFacade   = new MOFacade(this.DataProvider);
                    ItemFacade           itemFacade = new ItemFacade(this.DataProvider);
                    MO                   mo;
                    DT_MES_PO_RESPPOLIST moObject;
                    DBDateTime           currentDateTime = FormatHelper.GetNowDBDateTime(this.DataProvider);

                    for (int i = 0; i < moCount; i++)
                    {
                        moObject = returnValue.POLIST[i];
                        moList  += moObject.MOCODE + "|";

                        if (moFacade.GetMO(moObject.MOCODE) != null)
                        {
                            continue;
                        }

                        mo = moFacade.CreateNewMO();

                        /*---------------------  Web Service 节点数据 ---------------------*/
                        mo.MOCode          = moObject.MOCODE;
                        mo.MOType          = moObject.MoType;
                        mo.MOPlanQty       = decimal.Parse(moObject.MOPlanQty);
                        mo.MOPlanStartDate = int.Parse(moObject.MOPlanstart);
                        mo.MOPlanEndDate   = int.Parse(moObject.MOPlanEndDate);
                        mo.ItemCode        = InternalVariables.MatchItemCode(moObject.ItemCode);
                        mo.OrganizationID  = int.Parse(moObject.ORGID);
                        mo.BOMVersion      = moObject.MOBOM;
                        mo.MOOP            = moObject.MOOP;
                        mo.EAttribute2     = moObject.StorNo;

                        /*-------------- 固定数据 ----------*/
                        object material = itemFacade.GetMaterial(mo.ItemCode, int.Parse(moObject.ORGID));
                        if (material == null)
                        {
                            mo.MaterialDescription = "";
                        }
                        else
                        {
                            mo.MaterialDescription = (material as BenQGuru.eMES.Domain.MOModel.Material).MaterialDescription;
                        }
                        mo.MOMemo            = "";
                        mo.MODescription     = "";
                        mo.MOInputQty        = 0;
                        mo.MOScrapQty        = 0;
                        mo.MOActualQty       = 0;
                        mo.MOActualStartDate = 0;
                        mo.MOActualEndDate   = 0;
                        mo.Factory           = mo.OrganizationID.ToString();
                        mo.OrderSequence     = 0;
                        mo.MOUser            = "******";
                        mo.MODownloadDate    = currentDateTime.DBDate;
                        mo.MOStatus          = MOManufactureStatus.MOSTATUS_INITIAL;
                        mo.MOVersion         = "1.0";
                        mo.IsControlInput    = "1";
                        mo.IsBOMPass         = "******";
                        mo.IDMergeRule       = 1;
                        mo.MaintainUser      = "******";
                        mo.MOReleaseDate     = 0;
                        mo.MOReleaseTime     = 0;
                        mo.MOPendingCause    = " ";
                        mo.MOImportDate      = currentDateTime.DBDate;
                        mo.MOImportTime      = currentDateTime.DBTime;
                        mo.CustomerCode      = "";
                        mo.CustomerName      = "";
                        mo.CustomerOrderNO   = "";
                        mo.CustomerItemCode  = "";
                        mo.OrderNO           = "";
                        mo.EAttribute1       = "";
                        mo.MOOffQty          = 0;
                        mo.IsCompareSoft     = 0;
                        mo.RMABillCode       = "";
                        mo.MOSeq             = 0;
                        mo.MOPCBAVersion     = "";
                        mo.MOBIOSVersion     = "";

                        moFacade.AddMO(mo);
                    }

                    // Call MOBOM Logic in one transaction
                    if (moList.Trim().Length > 0)
                    {
                        moList = moList.Substring(0, moList.Length - 1);
                        int                   requestCount  = this.GetRequestCount(moList);
                        MOBOMTransfer         moBOMTransfer = new MOBOMTransfer(this.DataProvider);
                        MOBOMTransferArgument moBOMArgument = new MOBOMTransferArgument(this.DataProvider);
                        ServiceResult         sr;
                        for (int j = 0; j < requestCount; j++)
                        {
                            moBOMArgument.GenerateNewTransactionCode(this.DataProvider);
                            moBOMArgument.MOCodeList = this.GetMOListPerRequest(moList, j);
                            moBOMTransfer.SetArguments(moBOMArgument);
                            sr = moBOMTransfer.Run(RunMethod.Auto);
                            if (sr.Result == false)
                            {
                                throw new Exception(sr.Message);
                            }
                        }
                    }

                    this.DataProvider.CommitTransaction();
                    log.Result       = "OK";
                    log.ErrorMessage = "";
                }
                catch (Exception ex)
                {
                    this.DataProvider.RollbackTransaction();
                    // Log
                    log.Result       = "Fail";
                    log.ErrorMessage = ex.Message;
                }
                finally
                {
                    ((BenQGuru.eMES.Common.DomainDataProvider.SQLDomainDataProvider)DataProvider).PersistBroker.CloseConnection();
                    ((BenQGuru.eMES.Common.DomainDataProvider.SQLDomainDataProvider)DataProvider).PersistBroker.AutoCloseConnection = true;
                }

                log.ReceivedRecordCount = moCount;
                DBDateTime finishedDateTime = FormatHelper.GetNowDBDateTime(this.DataProvider);
                log.FinishedDate = finishedDateTime.DBDate;
                log.FinishedTime = finishedDateTime.DBTime;
                transferFacade.UpdateSAPDataTransferLog(log);

                if (log.Result == "OK")
                {
                    return(new ServiceResult(true, "", log.TransactionCode));
                }
                else
                {
                    return(new ServiceResult(false, log.ErrorMessage, log.TransactionCode));
                }
            }
            else //  status!="OK"
            {
                log.Result              = "Fail";
                log.ErrorMessage        = returnValue.Message;
                log.ReceivedRecordCount = 0;
                transferFacade.UpdateSAPDataTransferLog(log);
                return(new ServiceResult(false, log.ErrorMessage, log.TransactionCode));
            }
        }
Exemplo n.º 11
0
        public ServiceResult Run(RunMethod runMethod)
        {
            /*---------- Get WebService URL and UserName and Password -------------*/
            SAPWebServiceEntity webServiceEntity = System.Configuration.ConfigurationManager.GetSection("MOConfirmConfig") as SAPWebServiceEntity;

            if (webServiceEntity == null)
            {
                if (System.Configuration.ConfigurationManager.AppSettings["WebServiceUrl"] != null &&
                    System.Configuration.ConfigurationManager.AppSettings["WebServiceUserName"] != null &&
                    System.Configuration.ConfigurationManager.AppSettings["WebServicePassword"] != null)
                {
                    webServiceEntity          = new SAPWebServiceEntity();
                    webServiceEntity.Url      = System.Configuration.ConfigurationManager.AppSettings["WebServiceUrl"];
                    webServiceEntity.UserName = System.Configuration.ConfigurationManager.AppSettings["WebServiceUserName"];
                    webServiceEntity.Password = System.Configuration.ConfigurationManager.AppSettings["WebServicePassword"];
                }
                else
                {
                    return(new ServiceResult(false, "没有维护MOConfirmConfig对应的Service地址", this.m_Argument.TransactionCode));
                }
            }

            #region Begin for Prepare input Paremeter
            // Prepare input parameter
            DT_MES_POCONFIRM_REQ moInputParas = new DT_MES_POCONFIRM_REQ();
            moInputParas.Trsaction_code = this.m_Argument.TransactionCode;
            moInputParas.POLIST         = new DT_MES_POCONFIRM_REQPOLIST[this.m_Argument.MOList.Count];
            for (int i = 0; i < this.m_Argument.MOList.Count; i++)
            {
                moInputParas.POLIST[i] = this.m_Argument.MOList[i];
            }
            #endregion

            // Serialize the Input Parameter
            string inputXmlFilePath = SerializeUtil.SerializeFile(this.m_Argument.TransactionCode + "_Request.xml",
                                                                  typeof(DT_MES_POCONFIRM_REQ), moInputParas);
            DBDateTime requestDateTime = FormatHelper.GetNowDBDateTime(this.DataProvider);

            TransferFacade     transferFacade = new TransferFacade(this.DataProvider);
            SAPDataTransferLog log;

            #region Begin for Calling WebService
            // Call Web Service through StandardBOMServiceClientProxy
            DT_MES_POCONFIRM_RESP returnValue;
            string     outputXmlFilePath;
            DBDateTime responseDateTime;
            try
            {
                MOConfirmServiceClientProxy clientProxy = new MOConfirmServiceClientProxy();
                clientProxy.RequestEncoding = Encoding.UTF8;
                clientProxy.Timeout         = InternalVariables.MS_TimeOut * 1000;
                clientProxy.Url             = webServiceEntity.Url;
                clientProxy.PreAuthenticate = true;
                System.Uri uri = new Uri(clientProxy.Url);
                clientProxy.Credentials = new NetworkCredential(webServiceEntity.UserName, webServiceEntity.Password).GetCredential(uri, "");
                returnValue             = clientProxy.MI_MES_POCONFIRM_REQ(moInputParas);
                clientProxy.Dispose();
                clientProxy = null;
            }
            catch (Exception e)
            {
                log                     = new SAPDataTransferLog();
                log.JobID               = TransferFacade.MOCompleteTransferJobID;
                log.TransactionCode     = this.m_Argument.TransactionCode;
                log.TransactionSequence = 1;
                log.RequestDate         = requestDateTime.DBDate;
                log.RequestTime         = requestDateTime.DBTime;
                log.RequestContent      = inputXmlFilePath;
                log.OrganizationID      = this.m_Argument.OrgID;
                log.SendRecordCount     = this.m_Argument.MOList.Count;
                log.ReceivedRecordCount = 0;
                log.ResponseDate        = 0;
                log.ResponseTime        = 0;
                log.ResponseContent     = "";
                log.FinishedDate        = 0;
                log.FinishedTime        = 0;
                log.Result              = "Fail";
                log.ErrorMessage        = e.Message;
                transferFacade.AddSAPDataTransferLog(log);
                return(new ServiceResult(false, e.Message, log.TransactionCode));
            }
            #endregion

            //Serialize the output Parameter
            outputXmlFilePath = SerializeUtil.SerializeFile(this.m_Argument.TransactionCode + "_Response.xml",
                                                            typeof(DT_MES_POCONFIRM_RESP), returnValue);
            // Update Log
            responseDateTime = FormatHelper.GetNowDBDateTime(this.DataProvider);

            Dictionary <string, List <DT_MES_POCONFIRM> > result = this.ParseMOResult(returnValue.PO_lIST);

            int sMOCount = result.Count;
            List <DT_MES_POCONFIRM> moMessageList;
            DBDateTime finishedDateTime;
            MOFacade   moFacade = new MOFacade(this.DataProvider);
            MO2SAPLog  mo2saplog;
            int        counter = 0;
            foreach (string moCode in result.Keys)
            {
                moMessageList = result[moCode];

                // Add log for Single MO
                log                     = new SAPDataTransferLog();
                log.JobID               = TransferFacade.MOCompleteTransferJobID;
                log.TransactionCode     = this.m_Argument.TransactionCode;
                log.TransactionSequence = counter + 1;
                log.RequestDate         = requestDateTime.DBDate;
                log.RequestTime         = requestDateTime.DBTime;
                log.RequestContent      = inputXmlFilePath;
                log.OrganizationID      = this.m_Argument.OrgID;
                log.SendRecordCount     = 1;
                log.ReceivedRecordCount = moMessageList.Count;
                log.ResponseDate        = responseDateTime.DBDate;
                log.ResponseTime        = responseDateTime.DBTime;
                log.ResponseContent     = outputXmlFilePath;
                log.Result              = "OK";
                log.ErrorMessage        = "";
                finishedDateTime        = FormatHelper.GetNowDBDateTime(this.DataProvider);
                log.FinishedDate        = finishedDateTime.DBDate;
                log.FinishedTime        = finishedDateTime.DBTime;
                transferFacade.AddSAPDataTransferLog(log);

                ((BenQGuru.eMES.Common.DomainDataProvider.SQLDomainDataProvider)DataProvider).PersistBroker.AutoCloseConnection = false;
                ((BenQGuru.eMES.Common.DomainDataProvider.SQLDomainDataProvider)DataProvider).PersistBroker.OpenConnection();
                this.DataProvider.BeginTransaction();
                try
                {
                    if (moMessageList.Count == 1)
                    {
                        DT_MES_POCONFIRM moConfirm = moMessageList[0];
                        if (string.Compare(moConfirm.FLAG, "Y", true) == 0)
                        {
                            // Update MO2SAP.Flag
                            moFacade.UpdateMO2SAPFlag(moConfirm.MOCode, decimal.Parse(moConfirm.PostSeq));
                        }
                        else
                        {
                            // Fail
                            // Insert new MO2SAPLog
                            mo2saplog                = new MO2SAPLog();
                            mo2saplog.MOCode         = moConfirm.MOCode;
                            mo2saplog.Active         = "Y";
                            mo2saplog.ErrorMessage   = moConfirm.message;
                            mo2saplog.MaintainDate   = finishedDateTime.DBDate;
                            mo2saplog.MaintainTime   = finishedDateTime.DBTime;
                            mo2saplog.MaintainUser   = "******";
                            mo2saplog.OrganizationID = this.m_Argument.OrgID;
                            mo2saplog.PostSequence   = decimal.Parse(moConfirm.PostSeq);
                            mo2saplog.Sequence       = moFacade.GetMaxMO2SAPSequence(mo2saplog.MOCode, mo2saplog.PostSequence);
                            moFacade.AddMO2SAPLog(mo2saplog);
                        }
                    }
                    else // 返回的是ErrorMessage
                    {
                        foreach (DT_MES_POCONFIRM moConfirm in moMessageList)
                        {
                            // Insert New MO2SAPLog
                            mo2saplog                = new MO2SAPLog();
                            mo2saplog.MOCode         = moConfirm.MOCode;
                            mo2saplog.Active         = "Y";
                            mo2saplog.ErrorMessage   = moConfirm.message;
                            mo2saplog.MaintainDate   = finishedDateTime.DBDate;
                            mo2saplog.MaintainTime   = finishedDateTime.DBTime;
                            mo2saplog.MaintainUser   = "******";
                            mo2saplog.OrganizationID = this.m_Argument.OrgID;
                            mo2saplog.PostSequence   = decimal.Parse(moConfirm.PostSeq);
                            mo2saplog.Sequence       = moFacade.GetMaxMO2SAPSequence(mo2saplog.MOCode, mo2saplog.PostSequence);
                            moFacade.AddMO2SAPLog(mo2saplog);
                        }
                    }
                    this.DataProvider.CommitTransaction();
                }
                catch (Exception ex)
                {
                    this.DataProvider.RollbackTransaction();
                    return(new ServiceResult(false, ex.Message, this.m_Argument.TransactionCode));
                }
                finally
                {
                    ((BenQGuru.eMES.Common.DomainDataProvider.SQLDomainDataProvider)DataProvider).PersistBroker.CloseConnection();
                    ((BenQGuru.eMES.Common.DomainDataProvider.SQLDomainDataProvider)DataProvider).PersistBroker.AutoCloseConnection = true;
                }

                counter++;
            }

            return(new ServiceResult(true, "", this.m_Argument.TransactionCode));
        }
Exemplo n.º 12
0
        public ServiceResult Run(RunMethod runMethod)
        {
            /*---------- Get WebService URL and UserName and Password -------------*/
            SAPWebServiceEntity webServiceEntity = System.Configuration.ConfigurationManager.GetSection("StandardBOMTransferConfig") as SAPWebServiceEntity;

            if (webServiceEntity == null)
            {
                return(new ServiceResult(false, "没有维护StandardBOMTransferConfig对应的Service地址", this.m_Argument.TransactionCode));
            }

            #region Begin for Prepare input Paremente
            // Prepare input parameter
            DT_MES_MATBOM_REQ standardBOMParameter = new DT_MES_MATBOM_REQ();
            standardBOMParameter.Trsactioncode = this.m_Argument.TransactionCode.ToString();
            standardBOMParameter.OrgID         = this.m_Argument.OrgID.ToString();
            if (this.m_Argument.MaterialCode.Trim().Length == 0)
            {
                standardBOMParameter.MaintainDate_B = this.m_Argument.MaintainDate_B.Date.ToString("yyyyMMdd", new System.Globalization.CultureInfo("en-US"));
                standardBOMParameter.MaintainDate_E = this.m_Argument.MaintainDate_E.Date.ToString("yyyyMMdd", new System.Globalization.CultureInfo("en-US"));
                standardBOMParameter.MaterialCode   = "";
            }
            else
            {
                standardBOMParameter.MaintainDate_B = "";
                standardBOMParameter.MaintainDate_E = "";
                standardBOMParameter.MaterialCode   = this.m_Argument.MaterialCode.Trim().ToUpper();
            }
            #endregion

            // Serialize the Input Parameter
            string xmlFilePath = SerializeUtil.SerializeFile(this.m_Argument.TransactionCode + "_Request.xml",
                                                             typeof(DT_MES_MATBOM_REQ), standardBOMParameter);

            #region For Request Log
            DBDateTime         requestDateTime = FormatHelper.GetNowDBDateTime(this.DataProvider);
            SAPDataTransferLog log             = new SAPDataTransferLog();
            TransferFacade     transferFacade  = new TransferFacade(this.DataProvider);
            log.JobID               = TransferFacade.StandardBOMTransferJobID;
            log.TransactionCode     = this.m_Argument.TransactionCode;
            log.TransactionSequence = 1;
            log.RequestDate         = requestDateTime.DBDate;
            log.RequestTime         = requestDateTime.DBTime;
            log.RequestContent      = xmlFilePath;
            log.OrganizationID      = this.m_Argument.OrgID;
            log.SendRecordCount     = 1;
            transferFacade.AddSAPDataTransferLog(log);
            #endregion

            #region Begin for Calling WebService
            // Call Web Service through StandardBOMServiceClientProxy
            DT_MES_MATBOM_RSP returnValue;
            try
            {
                StandardBOMServiceClientProxy clientProxy = new StandardBOMServiceClientProxy();
                clientProxy.RequestEncoding = Encoding.UTF8;
                clientProxy.Timeout         = InternalVariables.MS_TimeOut * 1000;
                clientProxy.Url             = webServiceEntity.Url;
                clientProxy.PreAuthenticate = true;
                System.Uri uri = new Uri(clientProxy.Url);
                clientProxy.Credentials = new NetworkCredential(webServiceEntity.UserName, webServiceEntity.Password).GetCredential(uri, "");
                returnValue             = clientProxy.MI_MES_MATBOM(standardBOMParameter);
                clientProxy.Dispose();
                clientProxy = null;

                //Serialize the output Parameter
                xmlFilePath = SerializeUtil.SerializeFile(this.m_Argument.TransactionCode + "_Response.xml",
                                                          typeof(DT_MES_MATBOM_RSP), returnValue);

                // Update Log
                DBDateTime responseDateTime = FormatHelper.GetNowDBDateTime(this.DataProvider);
                log.ResponseDate    = responseDateTime.DBDate;
                log.ResponseTime    = responseDateTime.DBTime;
                log.ResponseContent = xmlFilePath;
                transferFacade.UpdateSAPDataTransferLog(log);
            }
            catch (Exception e)
            {
                log.Result       = "Fail";
                log.ErrorMessage = e.Message;
                transferFacade.UpdateSAPDataTransferLog(log);
                return(new ServiceResult(false, e.Message, log.TransactionCode));
            }
            #endregion

            /*--- 获取Flag字段,如果FLAG字段值是DEL的话,删除该条;FLAG是空,则判断是否有该数据,有则更新,否则插入该条 ----*/
            if (string.Compare(returnValue.FLAG, "Y", true) == 0)
            {
                int sBOMCount = returnValue.ITEM.Length;

                ((BenQGuru.eMES.Common.DomainDataProvider.SQLDomainDataProvider)DataProvider).PersistBroker.AutoCloseConnection = false;
                ((BenQGuru.eMES.Common.DomainDataProvider.SQLDomainDataProvider)DataProvider).PersistBroker.OpenConnection();
                this.DataProvider.BeginTransaction();

                try
                {
                    SBOMFacade            sBOMFacade = new SBOMFacade(this.DataProvider);
                    SBOM                  sBOM;
                    DT_MES_MATBOM_RSPITEM sBOMObject;

                    bool needAddNew = false;
                    for (int i = 0; i < sBOMCount; i++)
                    {
                        sBOMObject = returnValue.ITEM[i];

                        if (sBOMObject.ItemCode == null || sBOMObject.ItemCode == string.Empty ||
                            sBOMObject.SBItemCode == null || sBOMObject.SBItemCode == string.Empty ||
                            sBOMObject.SBOMVer == null || sBOMObject.SBOMVer == string.Empty ||
                            sBOMObject.SBItemProject == null || sBOMObject.SBItemProject == string.Empty ||
                            sBOMObject.SBItemSeq == null || sBOMObject.SBItemSeq == string.Empty)
                        {
                            continue;
                        }

                        object oldSBOM = sBOMFacade.GetSBOM(InternalVariables.MatchItemCode(sBOMObject.ItemCode).ToUpper(),
                                                            InternalVariables.MatchItemCode(sBOMObject.SBItemCode).ToUpper(),
                                                            sBOMObject.SBOMVer, sBOMObject.SBItemProject, sBOMObject.SBItemSeq, int.Parse(standardBOMParameter.OrgID));

                        if (string.Compare(sBOMObject.FLAG, "DEL", true) == 0)  //如果FLAG字段值是DEL的,执行删除操作
                        {
                            if (oldSBOM != null)
                            {
                                sBOMFacade.DeleteSBOM(oldSBOM as SBOM);
                            }
                        }
                        else if (string.Compare(sBOMObject.FLAG, "", true) == 0) //如果FLAG字段值是空,执行Insert/Update tblsbom操作
                        {
                            if (oldSBOM == null)                                 //如果为空,则Insert tblsbom
                            {
                                sBOM = sBOMFacade.CreateSBOM();

                                sBOM.SBOMItemEffectiveDate = 20080101;
                                sBOM.SBOMWH                = "";
                                sBOM.Sequence              = sBOMFacade.GetSBOMMaxSequence(sBOM.ItemCode, sBOM.SBOMVersion);
                                sBOM.SBOMItemECN           = "";
                                sBOM.SBOMItemStatus        = "0";
                                sBOM.SBOMItemLocation      = "";
                                sBOM.SBOMItemEffectiveTime = 1;
                                sBOM.SBOMItemInvalidDate   = 29991231;
                                sBOM.SBOMItemInvalidTime   = 1;
                                sBOM.SBOMItemVersion       = "";
                                sBOM.SBOMItemControlType   = "";
                                sBOM.SBOMParentItemCode    = "";
                                sBOM.ALPGR        = "";
                                sBOM.MaintainUser = "******";
                                sBOM.EAttribute1  = "";

                                needAddNew = true;
                            }
                            else
                            {
                                sBOM = oldSBOM as SBOM;

                                needAddNew = false;
                            }

                            sBOM.ItemCode           = InternalVariables.MatchItemCode(sBOMObject.ItemCode); //tblsbom 的 PK
                            sBOM.SBOMItemCode       = InternalVariables.MatchItemCode(sBOMObject.SBItemCode);
                            sBOM.SBOMSourceItemCode = InternalVariables.MatchItemCode(sBOMObject.SBItemCode);
                            sBOM.SBOMItemQty        = decimal.Parse(sBOMObject.SBItemQTY);
                            sBOM.OrganizationID     = int.Parse(standardBOMParameter.OrgID);
                            sBOM.SBOMVersion        = sBOMObject.SBOMVer;
                            //sBOM.SBOMItemName = sBOMObject.SBItemDesc;
                            //sBOM.SBOMItemDescription = sBOMObject.SBItemDesc;
                            sBOM.SBOMItemName        = "";
                            sBOM.SBOMItemDescription = "";
                            sBOM.SBOMItemUOM         = sBOMObject.SBItemUOM;
                            //sBOM.ItemDescription = sBOMObject.ItemDesc;
                            sBOM.ItemDescription  = "";
                            sBOM.SBOMFactory      = sBOMObject.SBFactory;
                            sBOM.SBOMUsage        = sBOMObject.SBUsage;
                            sBOM.SBOMItemProject  = sBOMObject.SBItemProject;
                            sBOM.SBOMItemSequence = sBOMObject.SBItemSeq;
                            sBOM.Location         = sBOMObject.SBItemPotx1;

                            if (needAddNew)
                            {
                                sBOMFacade.AddSBOM(sBOM);
                            }
                            else
                            {
                                sBOMFacade.UpdateSBOM(sBOM);
                            }
                        }
                    }
                    this.DataProvider.CommitTransaction();
                    log.Result       = "OK";
                    log.ErrorMessage = "";
                }
                catch (Exception ex)
                {
                    this.DataProvider.RollbackTransaction();
                    // Log
                    log.Result       = "Fail";
                    log.ErrorMessage = ex.Message;
                }
                finally
                {
                    ((BenQGuru.eMES.Common.DomainDataProvider.SQLDomainDataProvider)DataProvider).PersistBroker.CloseConnection();
                    ((BenQGuru.eMES.Common.DomainDataProvider.SQLDomainDataProvider)DataProvider).PersistBroker.AutoCloseConnection = true;
                }

                log.ReceivedRecordCount = sBOMCount;
                DBDateTime finishedDateTime = FormatHelper.GetNowDBDateTime(this.DataProvider);
                log.FinishedDate = finishedDateTime.DBDate;
                log.FinishedTime = finishedDateTime.DBTime;
                transferFacade.UpdateSAPDataTransferLog(log);

                if (log.Result == "OK")
                {
                    return(new ServiceResult(true, "", log.TransactionCode));
                }
                else
                {
                    return(new ServiceResult(false, log.ErrorMessage, log.TransactionCode));
                }
            }
            else  //FLAG != "Y"
            {
                log.Result              = "Fail";
                log.ErrorMessage        = returnValue.message;
                log.ReceivedRecordCount = 0;
                transferFacade.UpdateSAPDataTransferLog(log);
                return(new ServiceResult(false, log.ErrorMessage, log.TransactionCode));
            }
        }
Exemplo n.º 13
0
        public ServiceResult Run(RunMethod runMethod)
        {
            /*====Get WebService URL and UserName and Password====*/
            SAPWebServiceEntity webServiceEntity = System.Configuration.ConfigurationManager.GetSection("DNConfirmConfig") as SAPWebServiceEntity;

            if (webServiceEntity == null)
            {
                return(new ServiceResult(false, "没有维护DNConfirm对应的Service地址", this.m_Argument.TransactionCode));
            }

            DeliveryFacade deliveryFacade = new DeliveryFacade(this.DataProvider);

            #region Begin for Prepare input Paremeter

            DT_MES_DNPOST_REQ inputParameter = new DT_MES_DNPOST_REQ();

            if (runMethod == RunMethod.Auto)
            {
                this.NewTransactionCode();
                this.m_Argument.DNList.Clear();

                object[] deliveryNoteList = deliveryFacade.QueryDNNotConfirmed();
                if (deliveryNoteList != null)
                {
                    foreach (DeliveryNote deliveryNote in deliveryNoteList)
                    {
                        DT_MES_DNPOST post = new DT_MES_DNPOST();
                        post.VBELN   = deliveryNote.DNCode;
                        post.POSNR   = deliveryNote.DNLine;
                        post.MATNR   = deliveryNote.ItemCode;
                        post.G_LFIMG = deliveryNote.RealQuantity.ToString();
                        post.LGORT   = deliveryNote.SAPStorage;

                        this.m_Argument.DNList.Add(post);
                    }
                }
            }

            if (this.m_Argument.DNList == null || this.m_Argument.DNList.Count <= 0)
            {
                return(new ServiceResult(true, "", this.m_Argument.TransactionCode));
            }

            inputParameter.TRANS   = this.m_Argument.TransactionCode;
            inputParameter.DNPARAM = this.m_Argument.DNList.ToArray();

            #endregion

            string xmlFilePath = SerializeUtil.SerializeFile(this.m_Argument.TransactionCode + "_Request.xml",
                                                             typeof(DT_MES_DNPOST_REQ), inputParameter);

            #region TransferLog

            DBDateTime         requestDataTime = FormatHelper.GetNowDBDateTime(this.DataProvider);
            SAPDataTransferLog transferLog     = new SAPDataTransferLog();
            TransferFacade     transferFacade  = new TransferFacade(this.DataProvider);

            transferLog.JobID               = TransferFacade.DNConfirmJobID;
            transferLog.TransactionCode     = this.m_Argument.TransactionCode;
            transferLog.TransactionSequence = 1;
            transferLog.RequestDate         = requestDataTime.DBDate;
            transferLog.RequestTime         = requestDataTime.DBTime;
            transferLog.RequestContent      = xmlFilePath;
            transferLog.OrganizationID      = 2000;
            transferLog.SendRecordCount     = 1;

            transferFacade.AddSAPDataTransferLog(transferLog);

            #endregion

            #region Begin for Calling WebService

            try
            {
                DNConfirmServiceClientProxy clientProxy = new DNConfirmServiceClientProxy();
                clientProxy.RequestEncoding = Encoding.UTF8;
                clientProxy.Timeout         = InternalVariables.MS_TimeOut * 1000;
                clientProxy.Url             = webServiceEntity.Url;
                clientProxy.PreAuthenticate = true;
                System.Uri uri = new Uri(clientProxy.Url);
                clientProxy.Credentials = new NetworkCredential(webServiceEntity.UserName, webServiceEntity.Password).GetCredential(uri, "");
                clientProxy.MI_MES_DNPOST_REQ(inputParameter);
                clientProxy.Dispose();
                clientProxy = null;
            }
            catch (Exception e)
            {
                transferLog.Result       = "Fail";
                transferLog.ErrorMessage = e.Message;
                transferFacade.UpdateSAPDataTransferLog(transferLog);
                return(new ServiceResult(false, e.Message, transferLog.TransactionCode));
            }

            #endregion

            #region Update tbldn

            try
            {
                this.DataProvider.BeginTransaction();
                foreach (DT_MES_DNPOST post in this.m_Argument.DNList)
                {
                    DeliveryNote deliveryNote = (DeliveryNote)deliveryFacade.GetDeliveryNote(post.VBELN, post.POSNR);
                    if (deliveryNote != null)
                    {
                        deliveryNote.Flag            = FlagStatus.FlagStatus_POST;
                        deliveryNote.TransactionCode = this.m_Argument.TransactionCode;
                        deliveryFacade.UpdateDeliveryNote(deliveryNote);
                    }
                }
                this.DataProvider.CommitTransaction();
            }
            catch (Exception ex)
            {
                this.DataProvider.RollbackTransaction();
                return(new ServiceResult(false, ex.Message, this.m_Argument.TransactionCode));
            }

            #endregion

            return(new ServiceResult(true, "", this.m_Argument.TransactionCode));
        }
Exemplo n.º 14
0
        public ServiceResult Run(RunMethod runMethod)
        {
            SAPWebServiceEntity webServiceEntity = System.Configuration.ConfigurationManager.GetSection("InventoryTransferConfig") as SAPWebServiceEntity;

            if (webServiceEntity == null)
            {
                return(new ServiceResult(false, "没有维护InvertoryTransferConfig对应的Service地址", this.m_Argument.TransactionCode));
            }

            InventoryFacade invFacade = new InventoryFacade(this.DataProvider);

            #region Begin for Prepare input Paremeter

            DT_MES_MATSTARCE_REQ inventoryParameter  = new DT_MES_MATSTARCE_REQ();
            object[]             sapStorageQueryList = null;

            if (runMethod == RunMethod.Auto)
            {
                sapStorageQueryList = invFacade.QuerySAPStorageQueryNotDealed(1);

                if (sapStorageQueryList == null)
                {
                    return(new ServiceResult(true, "", this.m_Argument.TransactionCode));
                }

                SAPStorageQuery query = (SAPStorageQuery)sapStorageQueryList[0];
                inventoryParameter.LGORT = query.StorageID.Split(',');
                inventoryParameter.MATNR = query.ItemCode;
                inventoryParameter.TRANS = this.m_Argument.TransactionCode;
                inventoryParameter.WERKS = query.OrganizationID.Split(',');
            }
            else if (runMethod == RunMethod.Manually)
            {
                inventoryParameter.LGORT = this.m_Argument.Location;
                inventoryParameter.MATNR = this.m_Argument.MaterialNumber;
                inventoryParameter.TRANS = this.m_Argument.TransactionCode;
                inventoryParameter.WERKS = this.m_Argument.OrgList;
            }

            invFacade.DeleteSAPStorageInfo(inventoryParameter.WERKS, inventoryParameter.LGORT, inventoryParameter.MATNR);

            #endregion

            string xmlFilePath = SerializeUtil.SerializeFile(this.m_Argument.TransactionCode + "_Request.xml",
                                                             typeof(DT_MES_MATSTARCE_REQ), inventoryParameter);

            #region InventoryLog

            DBDateTime         dateTime       = FormatHelper.GetNowDBDateTime(this.DataProvider);
            SAPDataTransferLog inventoryLog   = new SAPDataTransferLog();
            TransferFacade     transferFacade = new TransferFacade(this.DataProvider);

            inventoryLog.JobID               = TransferFacade.InvertoryJobID;
            inventoryLog.TransactionCode     = inventoryParameter.TRANS;
            inventoryLog.TransactionSequence = 1;
            inventoryLog.RequestDate         = dateTime.DBDate;
            inventoryLog.RequestTime         = dateTime.DBTime;
            inventoryLog.RequestContent      = xmlFilePath;
            inventoryLog.OrganizationID      = 2000;
            inventoryLog.SendRecordCount     = 1;

            transferFacade.AddSAPDataTransferLog(inventoryLog);

            #endregion

            #region Begin for Calling WebService

            try
            {
                //Delete sapstorageInfo
                //invFacade.DeleteSAPStorageInfoByItemCode(this.m_Argument.MaterialNumber.ToUpper());

                InvertoryServiceClientProxy clientProxy = new InvertoryServiceClientProxy();
                clientProxy.RequestEncoding = Encoding.UTF8;
                clientProxy.Timeout         = InternalVariables.MS_TimeOut * 1000;
                clientProxy.Url             = webServiceEntity.Url;
                clientProxy.PreAuthenticate = true;
                System.Uri uri = new Uri(clientProxy.Url);
                clientProxy.Credentials = new NetworkCredential(webServiceEntity.UserName, webServiceEntity.Password).GetCredential(uri, "");
                clientProxy.MI_MES_MATSTARCE_REQ(inventoryParameter);
                clientProxy.Dispose();
                clientProxy = null;
            }
            catch (Exception e)
            {
                inventoryLog.Result       = "Fail";
                inventoryLog.ErrorMessage = e.Message;
                transferFacade.UpdateSAPDataTransferLog(inventoryLog);
                return(new ServiceResult(false, e.Message, inventoryLog.TransactionCode));
            }

            if (runMethod == RunMethod.Auto && sapStorageQueryList != null)
            {
                try
                {
                    SAPStorageQuery query = (SAPStorageQuery)sapStorageQueryList[0];
                    query.Flag            = FlagStatus.FlagStatus_POST;
                    query.TransactionCode = this.m_Argument.TransactionCode;
                    invFacade.UpdateSAPStorageQuery(query);
                }
                catch (Exception ex)
                {
                    return(new ServiceResult(false, ex.Message, this.m_Argument.TransactionCode));
                }
            }

            #endregion

            return(new ServiceResult(true, "", this.m_Argument.TransactionCode));
        }