コード例 #1
0
        private int RunItemImportByPage(DataName _dataName, IDomainDataProvider _sapDataProvider, IDomainDataProvider _mesDataProvider, int currentPage)
        {
            #region 从sap数据库获取数据
            //从sap数据库获取数据
            SAPMapper mapper   = new SAPMapper();
            ArrayList mesItems = new ArrayList();

            SAPDataGeter dateGetter = new SAPDataGeter(_sapDataProvider);
            int          inclusive  = this.page_exclusive * (currentPage - 1) + 1;
            int          exclusive  = this.page_exclusive * currentPage;
            sapItems = dateGetter.GetSAPData(_dataName, inclusive, exclusive);
            #endregion

            #region  射数据
            //映射产品
            if (sapItems != null && sapItems.Length > 0)
            {
                mesItems = mapper.MapSAPData(this.sapItems);
            }
            #endregion

            #region 导入数据

            //导入到MES数据库
            SAPImporter sapImpoter = new SAPImporter(_mesDataProvider);
            sapImpoter.importLogger = this.importLogger;                //日志写入器
            sapImpoter.pageCountNum = currentPage;                      //导入的当前页
            sapImpoter.Import(mesItems);

            if (sapItems != null && sapItems.Length > 0 && sapItems[0].GetType() == typeof(SAPBOM))
            {
                //如果是SAPBOM,特殊处理首选料问题
                sapImpoter.UpdateSBom(sapItems);
            }

            return(sapImpoter.SucceedImportNum);

            #endregion
        }
コード例 #2
0
        private void Import(DataName _dataName)
        {
            DateTime jobLogStartTime = DateTime.Now;                            //JobLog日志开始时间

            #region 从sap数据库获取数据
            //从sap数据库获取数据
            IDomainDataProvider _sapDataProvider = DomainDataProviderManager.DomainDataProvider(DBName.SAP);
            IDomainDataProvider _mesDataProvider = DomainDataProviderManager.DomainDataProvider(DBName.MES);

            if (_sapDataProvider != null && ((SQLDomainDataProvider)_sapDataProvider).PersistBroker != null)
            {
                importLogger.Write(string.Format("已经连接到SAP的数据库 {0}", _dataName));
                System.Console.WriteLine(string.Format("已经连接到SAP的数据库 {0}", _dataName));
            }
            else
            {
                importLogger.Write(string.Format("连接到SAP的数据库失败 {0}", _dataName));
                System.Console.WriteLine(string.Format("连接到SAP的数据库失败 {0}", _dataName));
            }

            if (_mesDataProvider != null && ((SQLDomainDataProvider)_mesDataProvider).PersistBroker != null)
            {
                importLogger.Write(string.Format("已经连接到MES的数据库 {0}", _dataName));
                System.Console.WriteLine(string.Format("已经连接到MES的数据库 {0}", _dataName));
            }
            else
            {
                importLogger.Write(string.Format("连接到MES的数据库失败 {0}", _dataName));
                System.Console.WriteLine(string.Format("连接到MES的数据库失败 {0}", _dataName));
            }

            importLogger.Write("");
            System.Console.WriteLine("");

            bool isImportSuccess = true;             //导入是否成功
            try
            {
                SAPDataGeter dateGetter = new SAPDataGeter(_sapDataProvider);
                int          count      = dateGetter.GetImportCount(_dataName);
                importLogger.Write(string.Format("获取到{0}数据 {1}条", _dataName, count.ToString()));

                if (count > 0)
                {
                    int pageCount = (int)Math.Floor(Convert.ToDecimal(count / this.page_exclusive)) + 1;                   //获取总页数
                    importLogger.Write(string.Format("将要分成{0}页进行导入,每页数据{1}条", pageCount.ToString(), page_exclusive.ToString()));
                    importLogger.Write(string.Format("正在导入{0}数据 ", _dataName));
                    System.Console.WriteLine(string.Format("正在导入{0}数据 ", _dataName));
                    int SucceedNum = 0;                                 //成功导入的数据
                    for (int i = 1; i < pageCount + 1; i++)
                    {
                        if (i == 1)
                        {
                            System.Console.WriteLine(string.Format("将要分成{0}页进行导入,每页数据{1}条", pageCount.ToString(), page_exclusive.ToString()));
                        }
                        SucceedNum += this.RunItemImportByPage(_dataName, _sapDataProvider, _mesDataProvider, i);
                        System.Console.WriteLine(string.Format("正在导入{0}第{1}页数据", _dataName, i.ToString()));
                    }
                    importLogger.Write(string.Format("成功导入{0}  {1}条数据 ", _dataName, SucceedNum));
                    System.Console.WriteLine(string.Format("成功导入{0}  {1}条数据 ", _dataName, SucceedNum));
                    System.Console.WriteLine("");
                }
            }
            catch (Exception ex)
            {
                importLogger.Write(string.Format("导入{0}数据 出错,详细信息为{1}", _dataName, ex.Message));
                isImportSuccess = false;
            }
            finally
            {
                if (_sapDataProvider != null)
                {
                    ((SQLDomainDataProvider)_sapDataProvider).PersistBroker.CloseConnection();
                }
                if (_mesDataProvider != null)
                {
                    ((SQLDomainDataProvider)_mesDataProvider).PersistBroker.CloseConnection();
                }
            }

            #endregion

            //#region 写JobLog

            IDomainDataProvider _JobLogDataProvider = DomainDataProviderManager.DomainDataProvider(DBName.SAP);

            if (_JobLogDataProvider != null && ((SQLDomainDataProvider)_JobLogDataProvider).PersistBroker != null)
            {
                importLogger.Write("已经连接到JobLog的数据库");
                System.Console.WriteLine("已经连接到JobLog的数据库");
            }
            else
            {
                importLogger.Write("连接到JobLog的数据库失败");
                System.Console.WriteLine("连接到JobLog的数据库失败");
            }

            try
            {
                DateTime jobLogEndTime = DateTime.Now;                                  //JobLog日志结束时间
                importLogger.Write(string.Format("正在写{0} JobLog", _dataName));
                SAPDataGeter JobLogWriter = new SAPDataGeter(_JobLogDataProvider);

                if (isImportSuccess)
                {
                    JobLogWriter.AddSuccessJobLog(this.getJobName(_dataName), jobLogStartTime, jobLogEndTime);
                }
                else
                {
                    JobLogWriter.AddFailedJobLog(this.getJobName(_dataName), jobLogStartTime, jobLogEndTime);
                }

                importLogger.Write(string.Format("写入{0} JobLog 完成", _dataName));
                importLogger.Write("");
            }
            catch (Exception ex)
            {
                importLogger.Write(string.Format("写入{0} JobLog 失败,,详细信息为{1}", _dataName, ex.Message));
            }
            finally
            {
                if (_JobLogDataProvider != null)
                {
                    ((SQLDomainDataProvider)_JobLogDataProvider).PersistBroker.CloseConnection();
                }
            }

            //#endregion
        }