public void Receive(MATISSUE_REQ request)
        {
            ((SQLDomainDataProvider)DataProvider).PersistBroker.AutoCloseConnection = false;
            ((SQLDomainDataProvider)DataProvider).PersistBroker.OpenConnection();
            try
            {
                TransferFacade     transferFacade = new TransferFacade(this.DataProvider);
                SAPDataTransferLog log;
                DBDateTime         currentDateTime = FormatHelper.GetNowDBDateTime(this.DataProvider);
                string             xmlFilePath;
                if (request.TransactionCode == null || request.TransactionCode == string.Empty)
                {
                    // New Log
                    log = transferFacade.CreateNewSAPDataTransferLog();
                    //log.ErrorMessage
                    //log.FinishedDate
                    //log.FinishedTime
                    log.JobID               = TransferFacade.MaterialIssueJobID;
                    log.OrganizationID      = 2000;
                    log.ReceivedRecordCount = (request.IssueList == null || request.IssueList.Count == 0) ? 0 : request.IssueList.Count;
                    log.TransactionCode     = TransferFacade.MaterialIssueJobID + "_"
                                              + currentDateTime.DBDate.ToString() + "_"
                                              + currentDateTime.DBTime.ToString()
                                              + DateTime.Now.Millisecond.ToString();
                    log.TransactionSequence = 1;
                    xmlFilePath             = SerializeUtil.SerializeFile(log.TransactionCode + "_Response.xml",
                                                                          typeof(MATISSUE_REQ), request);
                    log.RequestContent = xmlFilePath;
                    log.RequestDate    = currentDateTime.DBDate;
                    log.RequestTime    = currentDateTime.DBTime;
                    //log.Result
                    log.SendRecordCount = 0;
                    transferFacade.AddSAPDataTransferLog(log);

                    request.TransactionCode = log.TransactionCode;
                }
                else
                {
                    // Update log
                    log = transferFacade.GetSAPDataTransferLog(request.TransactionCode, 1) as SAPDataTransferLog;
                    //log.ErrorMessage
                    //log.FinishedDate
                    //log.FinishedTime
                    log.ReceivedRecordCount = (request.IssueList == null || request.IssueList.Count == 0) ? 0 : request.IssueList.Count;
                    xmlFilePath             = SerializeUtil.SerializeFile(log.TransactionCode + "_Response.xml",
                                                                          typeof(MATISSUE_REQ), request);
                    log.ResponseContent = xmlFilePath;
                    log.ResponseDate    = currentDateTime.DBDate;
                    log.ResponseTime    = currentDateTime.DBTime;
                    //log.Result
                    transferFacade.UpdateSAPDataTransferLog(log);
                }

                if (request.IssueList == null || request.IssueList.Count == 0)
                {
                    log.Result       = "Fail";
                    log.ErrorMessage = "Raw Issue list is null.";
                    log.FinishedDate = 0;
                    log.FinishedTime = 0;

                    transferFacade.UpdateSAPDataTransferLog(log);
                    return;
                }
                else
                {
                    MaterialStockFacade msf = new MaterialStockFacade(this.DataProvider);
                    RawIssue4SAP        rawIssue4SAP;
                    InventoryFacade     inventoryFacade = new InventoryFacade(this.DataProvider);

                    List <SAPMaterialTrans> confirmSAPMaterialTransList = new List <SAPMaterialTrans>();

                    try
                    {
                        this.DataProvider.BeginTransaction();

                        foreach (MES_MATISSUE matIssue in request.IssueList)
                        {
                            rawIssue4SAP = msf.CreateNewRawIssue4SAP();
                            rawIssue4SAP.ErrorMessage         = matIssue.ErrorMessage;
                            rawIssue4SAP.Flag                 = matIssue.Flag;
                            rawIssue4SAP.MaintainDate         = currentDateTime.DBDate;
                            rawIssue4SAP.MaintainTime         = currentDateTime.DBTime;
                            rawIssue4SAP.MaintainUser         = "******";
                            rawIssue4SAP.MaterialDocument     = matIssue.MaterialDocument;
                            rawIssue4SAP.MaterialDocumentYear = matIssue.MaterialDocumentYear;
                            rawIssue4SAP.TransactionCode      = request.TransactionCode;
                            rawIssue4SAP.VendorCode           = matIssue.VendorCode;

                            msf.AddRawIssue4SAP(rawIssue4SAP);

                            if (string.Compare(matIssue.Flag, "Y", true) == 0)  // Post OK
                            {
                                object[] sapMaterialTransList = inventoryFacade.QuerySAPMaterialTrans(request.TransactionCode);

                                if (sapMaterialTransList != null)
                                {
                                    foreach (SAPMaterialTrans sapMaterialTrans in sapMaterialTransList)
                                    {
                                        if (sapMaterialTrans.Flag == FlagStatus.FlagStatus_POST)
                                        {
                                            confirmSAPMaterialTransList.Add(sapMaterialTrans);
                                        }
                                    }
                                }
                            }
                        }

                        this.DataProvider.CommitTransaction();
                    }
                    catch (Exception ex)
                    {
                        this.DataProvider.RollbackTransaction();

                        log.Result       = "Fail";
                        log.ErrorMessage = ex.Message;
                        log.FinishedDate = 0;
                        log.FinishedTime = 0;

                        transferFacade.UpdateSAPDataTransferLog(log);
                    }

                    try
                    {
                        log.Result       = "OK";
                        log.ErrorMessage = "";
                        currentDateTime  = FormatHelper.GetNowDBDateTime(this.DataProvider);
                        log.FinishedDate = currentDateTime.DBDate;
                        log.FinishedTime = currentDateTime.DBTime;

                        transferFacade.UpdateSAPDataTransferLog(log);

                        foreach (SAPMaterialTrans sapMaterialTrans in confirmSAPMaterialTransList)
                        {
                            sapMaterialTrans.Flag = FlagStatus.FlagStatus_SAP;
                            inventoryFacade.UpdateSAPMaterialTrans(sapMaterialTrans);
                        }
                    }
                    catch (Exception ex)
                    {
                        this.DataProvider.RollbackTransaction();

                        log.Result       = "Fail";
                        log.ErrorMessage = ex.Message;
                        log.FinishedDate = 0;
                        log.FinishedTime = 0;

                        transferFacade.UpdateSAPDataTransferLog(log);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                ((SQLDomainDataProvider)DataProvider).PersistBroker.CloseConnection();
                ((SQLDomainDataProvider)DataProvider).PersistBroker.AutoCloseConnection = true;
            }
        }
Exemple #2
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));
            }
        }
Exemple #3
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));
            }
        }
        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));
        }
Exemple #5
0
        public void Receive(DNRecive_REQ request)
        {
            ((SQLDomainDataProvider)DataProvider).PersistBroker.AutoCloseConnection = false;
            ((SQLDomainDataProvider)DataProvider).PersistBroker.OpenConnection();
            try
            {
                TransferFacade     transferFacade = new TransferFacade(this.DataProvider);
                SAPDataTransferLog log;
                DBDateTime         currentDateTime = FormatHelper.GetNowDBDateTime(this.DataProvider);
                string             xmlFilePath;
                if (request.TransactionCode == null || request.TransactionCode == string.Empty)
                {
                    // New Log
                    log = transferFacade.CreateNewSAPDataTransferLog();
                    //log.ErrorMessage
                    //log.FinishedDate
                    //log.FinishedTime
                    log.JobID               = TransferFacade.DNTransferJobID;
                    log.OrganizationID      = 2000;
                    log.ReceivedRecordCount = (request.DNList == null || request.DNList.Count == 0) ? 0 : request.DNList.Count;
                    log.TransactionCode     = TransferFacade.DNTransferJobID + "_"
                                              + currentDateTime.DBDate.ToString() + "_"
                                              + currentDateTime.DBTime.ToString()
                                              + DateTime.Now.Millisecond.ToString();
                    log.TransactionSequence = 1;
                    xmlFilePath             = SerializeUtil.SerializeFile(log.TransactionCode + "_Response.xml",
                                                                          typeof(DNRecive_REQ), request);
                    log.RequestContent = xmlFilePath;
                    log.RequestDate    = currentDateTime.DBDate;
                    log.RequestTime    = currentDateTime.DBTime;
                    //log.Result
                    log.SendRecordCount = 0;
                    transferFacade.AddSAPDataTransferLog(log);

                    request.TransactionCode = log.TransactionCode;
                }
                else
                {
                    // Update log
                    log = transferFacade.GetSAPDataTransferLog(request.TransactionCode, 1) as SAPDataTransferLog;
                    //log.ErrorMessage
                    //log.FinishedDate
                    //log.FinishedTime
                    log.ReceivedRecordCount = (request.DNList == null || request.DNList.Count == 0) ? 0 : request.DNList.Count;
                    xmlFilePath             = SerializeUtil.SerializeFile(log.TransactionCode + "_Response.xml",
                                                                          typeof(DNRecive_REQ), request);
                    log.ResponseContent = xmlFilePath;
                    log.ResponseDate    = currentDateTime.DBDate;
                    log.ResponseTime    = currentDateTime.DBTime;
                    //log.Result
                    transferFacade.UpdateSAPDataTransferLog(log);
                }

                if (string.Compare(request.Flag, "Y", true) == 0)
                {
                    if (request.DNList == null || request.DNList.Count == 0)
                    {
                        log.Result       = "Fail";
                        log.ErrorMessage = "DN list is null.";
                        log.FinishedDate = 0;
                        log.FinishedTime = 0;

                        transferFacade.UpdateSAPDataTransferLog(log);
                        return;
                    }
                    else
                    {
                        this.DataProvider.BeginTransaction();
                        try
                        {
                            this.DealDN(request.DNList, currentDateTime);

                            this.DataProvider.CommitTransaction();

                            log.Result       = "OK";
                            log.ErrorMessage = "";
                            currentDateTime  = FormatHelper.GetNowDBDateTime(this.DataProvider);
                            log.FinishedDate = currentDateTime.DBDate;
                            log.FinishedTime = currentDateTime.DBTime;

                            transferFacade.UpdateSAPDataTransferLog(log);
                        }
                        catch (Exception ex)
                        {
                            this.DataProvider.RollbackTransaction();

                            log.Result       = "Fail";
                            log.ErrorMessage = ex.Message;
                            log.FinishedDate = 0;
                            log.FinishedTime = 0;

                            transferFacade.UpdateSAPDataTransferLog(log);
                        }
                    }
                }
                else
                {
                    log.Result       = "Fail";
                    log.ErrorMessage = request.Message;
                    log.FinishedDate = 0;
                    log.FinishedTime = 0;

                    transferFacade.UpdateSAPDataTransferLog(log);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                ((SQLDomainDataProvider)DataProvider).PersistBroker.CloseConnection();
                ((SQLDomainDataProvider)DataProvider).PersistBroker.AutoCloseConnection = true;
            }
        }
Exemple #6
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));
        }
Exemple #7
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));
            }
        }
Exemple #8
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));
        }
Exemple #9
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));
            }
        }
Exemple #10
0
        public void Receive(DNCONFIRM_REQ request)
        {
            ((SQLDomainDataProvider)DataProvider).PersistBroker.AutoCloseConnection = false;
            ((SQLDomainDataProvider)DataProvider).PersistBroker.OpenConnection();
            try
            {
                TransferFacade     transferFacade = new TransferFacade(this.DataProvider);
                SAPDataTransferLog log;
                DBDateTime         currentDateTime = FormatHelper.GetNowDBDateTime(this.DataProvider);
                string             xmlFilePath;
                if (request.TransactionCode == null || request.TransactionCode == string.Empty)
                {
                    // New Log
                    log = transferFacade.CreateNewSAPDataTransferLog();
                    //log.ErrorMessage
                    //log.FinishedDate
                    //log.FinishedTime
                    log.JobID               = TransferFacade.InvertoryJobID;
                    log.OrganizationID      = 2000;
                    log.ReceivedRecordCount = (request.DNConfirmList == null || request.DNConfirmList.Count == 0) ? 0 : request.DNConfirmList.Count;
                    log.TransactionCode     = TransferFacade.DNConfirmJobID + "_"
                                              + currentDateTime.DBDate.ToString() + "_"
                                              + currentDateTime.DBTime.ToString()
                                              + DateTime.Now.Millisecond.ToString();
                    log.TransactionSequence = 1;
                    xmlFilePath             = SerializeUtil.SerializeFile(log.TransactionCode + "_Response.xml",
                                                                          typeof(DNCONFIRM_REQ), request);
                    log.RequestContent = xmlFilePath;
                    log.RequestDate    = currentDateTime.DBDate;
                    log.RequestTime    = currentDateTime.DBTime;
                    //log.Result
                    log.SendRecordCount = 0;
                    transferFacade.AddSAPDataTransferLog(log);

                    request.TransactionCode = log.TransactionCode;
                }
                else
                {
                    // Update log
                    log = transferFacade.GetSAPDataTransferLog(request.TransactionCode, 1) as SAPDataTransferLog;
                    //log.ErrorMessage
                    //log.FinishedDate
                    //log.FinishedTime
                    log.ReceivedRecordCount = (request.DNConfirmList == null || request.DNConfirmList.Count == 0) ? 0 : request.DNConfirmList.Count;
                    xmlFilePath             = SerializeUtil.SerializeFile(log.TransactionCode + "_Response.xml",
                                                                          typeof(DNCONFIRM_REQ), request);
                    log.ResponseContent = xmlFilePath;
                    log.ResponseDate    = currentDateTime.DBDate;
                    log.ResponseTime    = currentDateTime.DBTime;
                    //log.Result
                    transferFacade.UpdateSAPDataTransferLog(log);
                }

                this.DataProvider.BeginTransaction();
                try
                {
                    DeliveryFacade deliveryFacade = new DeliveryFacade(this.DataProvider);
                    DN2SAP         dn2sap;
                    foreach (MES_DNConfirm dnconfirm in request.DNConfirmList)
                    {
                        dn2sap              = deliveryFacade.CreateNewDN2SAP();
                        dn2sap.Active       = "Y";
                        dn2sap.DNCode       = dnconfirm.DNNo;
                        dn2sap.ErrorMessage = dnconfirm.Message;
                        dn2sap.Flag         = dnconfirm.Flag;
                        dn2sap.MaintainDate = currentDateTime.DBDate;
                        dn2sap.MaintainTime = currentDateTime.DBTime;
                        dn2sap.MaintainUser = "******";

                        deliveryFacade.UpdateDN2SAPStatusByDNNo(dn2sap.DNCode.ToUpper());

                        deliveryFacade.AddDN2SAP(dn2sap);

                        if (string.Compare(dnconfirm.Flag, "Y", true) == 0)  // Post OK
                        {
                            // Update tbldn.flag to SAP
                            deliveryFacade.UpdateDNFlag(dnconfirm.DNNo, FlagStatus.FlagStatus_SAP);
                        }
                    }

                    this.DataProvider.CommitTransaction();

                    log.Result       = "OK";
                    log.ErrorMessage = "";
                    currentDateTime  = FormatHelper.GetNowDBDateTime(this.DataProvider);
                    log.FinishedDate = currentDateTime.DBDate;
                    log.FinishedTime = currentDateTime.DBTime;

                    transferFacade.UpdateSAPDataTransferLog(log);
                }
                catch (Exception ex)
                {
                    this.DataProvider.RollbackTransaction();

                    log.Result       = "Fail";
                    log.ErrorMessage = ex.Message;
                    log.FinishedDate = 0;
                    log.FinishedTime = 0;

                    transferFacade.UpdateSAPDataTransferLog(log);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                ((SQLDomainDataProvider)DataProvider).PersistBroker.CloseConnection();
                ((SQLDomainDataProvider)DataProvider).PersistBroker.AutoCloseConnection = true;
            }
        }
Exemple #11
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));
        }
Exemple #12
0
        public void Receive(INVReceive_REQ request)
        {
            ((SQLDomainDataProvider)DataProvider).PersistBroker.AutoCloseConnection = false;
            ((SQLDomainDataProvider)DataProvider).PersistBroker.OpenConnection();
            try
            {
                TransferFacade     transferFacade = new TransferFacade(this.DataProvider);
                SAPDataTransferLog log;
                DBDateTime         currentDateTime = FormatHelper.GetNowDBDateTime(this.DataProvider);
                string             xmlFilePath;
                if (request.TransactionCode == null || request.TransactionCode == string.Empty)
                {
                    // New Log
                    log = transferFacade.CreateNewSAPDataTransferLog();
                    //log.ErrorMessage
                    //log.FinishedDate
                    //log.FinishedTime
                    log.JobID               = TransferFacade.InvertoryJobID;
                    log.OrganizationID      = 2000;
                    log.ReceivedRecordCount = (request.INVList == null || request.INVList.Count == 0) ? 0 : request.INVList.Count;
                    log.TransactionCode     = TransferFacade.InvertoryJobID + "_"
                                              + currentDateTime.DBDate.ToString() + "_"
                                              + currentDateTime.DBTime.ToString()
                                              + DateTime.Now.Millisecond.ToString();
                    log.TransactionSequence = 1;
                    xmlFilePath             = SerializeUtil.SerializeFile(log.TransactionCode + "_Response.xml",
                                                                          typeof(INVReceive_REQ), request);
                    log.RequestContent = xmlFilePath;
                    log.RequestDate    = currentDateTime.DBDate;
                    log.RequestTime    = currentDateTime.DBTime;
                    //log.Result
                    log.SendRecordCount = 0;
                    transferFacade.AddSAPDataTransferLog(log);

                    request.TransactionCode = log.TransactionCode;
                }
                else
                {
                    // Update log
                    log = transferFacade.GetSAPDataTransferLog(request.TransactionCode, 1) as SAPDataTransferLog;
                    //log.ErrorMessage
                    //log.FinishedDate
                    //log.FinishedTime
                    log.ReceivedRecordCount = (request.INVList == null || request.INVList.Count == 0) ? 0 : request.INVList.Count;
                    xmlFilePath             = SerializeUtil.SerializeFile(log.TransactionCode + "_Response.xml",
                                                                          typeof(INVReceive_REQ), request);
                    log.ResponseContent = xmlFilePath;
                    log.ResponseDate    = currentDateTime.DBDate;
                    log.ResponseTime    = currentDateTime.DBTime;
                    //log.Result
                    transferFacade.UpdateSAPDataTransferLog(log);
                }

                if (string.Compare(request.Flag, "Y", true) == 0)
                {
                    if (request.INVList == null || request.INVList.Count == 0)
                    {
                        log.Result       = "Fail";
                        log.ErrorMessage = "Inventory list is null.";
                        log.FinishedDate = 0;
                        log.FinishedTime = 0;

                        transferFacade.UpdateSAPDataTransferLog(log);
                        return;
                    }
                    else
                    {
                        this.DataProvider.BeginTransaction();
                        try
                        {
                            InventoryFacade inventoryFacade = new InventoryFacade(this.DataProvider);
                            SAPStorageInfo  sapStorageInfo;
                            foreach (MES_INV inv in request.INVList)
                            {
                                sapStorageInfo           = inventoryFacade.CreateNewSAPStorageInfo();
                                sapStorageInfo.ItemCode  = inv.ItemCode;
                                sapStorageInfo.OrgID     = inv.OrgID;
                                sapStorageInfo.StorageID = inv.StorageID;
                                sapStorageInfo.CINSMQty  = inv.CINSMQTY;
                                sapStorageInfo.CLABSQty  = inv.CLABSQTY;
                                sapStorageInfo.CSPEMQty  = inv.CSPEMQTY;
                                sapStorageInfo.CUMLQty   = inv.CUMLQTY;
                                sapStorageInfo.Division  = inv.Division;
                                //sapStorageInfo.ItemDescription = inv.ItemDescription;
                                sapStorageInfo.ItemDescription = "";
                                sapStorageInfo.ItemGrade       = inv.ItemGrade;
                                sapStorageInfo.ModelCode       = string.Empty;
                                sapStorageInfo.StorageName     = inv.StorageName;
                                sapStorageInfo.MaintainDate    = currentDateTime.DBDate;
                                sapStorageInfo.MaintainTime    = currentDateTime.DBTime;
                                sapStorageInfo.MaintainUser    = "******";

                                object oldStorageInfo = inventoryFacade.GetSAPStorageInfo(inv.ItemCode.ToUpper(), inv.OrgID, inv.StorageID.ToUpper(), inv.ItemGrade.ToUpper());

                                if (oldStorageInfo == null)
                                {
                                    inventoryFacade.AddSAPStorageInfo(sapStorageInfo);
                                }
                                else
                                {
                                    inventoryFacade.DeleteSAPStorageInfo(oldStorageInfo as SAPStorageInfo);
                                    inventoryFacade.AddSAPStorageInfo(sapStorageInfo);
                                }
                            }

                            object[] queryList = inventoryFacade.QuerySAPStorageQuery(string.Empty, request.TransactionCode);
                            if (queryList != null)
                            {
                                foreach (SAPStorageQuery query in queryList)
                                {
                                    query.Flag = FlagStatus.FlagStatus_SAP;
                                    inventoryFacade.UpdateSAPStorageQuery(query);
                                }
                            }

                            this.DataProvider.CommitTransaction();

                            log.Result       = "OK";
                            log.ErrorMessage = "";
                            currentDateTime  = FormatHelper.GetNowDBDateTime(this.DataProvider);
                            log.FinishedDate = currentDateTime.DBDate;
                            log.FinishedTime = currentDateTime.DBTime;

                            transferFacade.UpdateSAPDataTransferLog(log);
                        }
                        catch (Exception ex)
                        {
                            this.DataProvider.RollbackTransaction();

                            log.Result       = "Fail";
                            log.ErrorMessage = ex.Message;
                            log.FinishedDate = 0;
                            log.FinishedTime = 0;

                            transferFacade.UpdateSAPDataTransferLog(log);
                        }
                    }
                }
                else
                {
                    log.Result       = "Fail";
                    log.ErrorMessage = request.Message;
                    log.FinishedDate = 0;
                    log.FinishedTime = 0;

                    transferFacade.UpdateSAPDataTransferLog(log);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                ((SQLDomainDataProvider)DataProvider).PersistBroker.CloseConnection();
                ((SQLDomainDataProvider)DataProvider).PersistBroker.AutoCloseConnection = true;
            }
        }
Exemple #13
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));
        }