private void ThreadCheckHeartTime() { while (bIsRunning) { int TimeLimit = ConfigHelper.GetConfigInt("TimeLimit"); if (dtHeartTime < DateTime.Now.AddSeconds(-TimeLimit) && ImportTemplateID > 0) { IPT_UploadTemplateBLL _bll = new IPT_UploadTemplateBLL(ImportTemplateID); _bll.Model.State = 3; _bll.Model.Remark = "导入出错,导入超时,请确认文件没有损坏或病毒再上传!"; _bll.Model.ImportTime = DateTime.Now; _bll.Update(); if (th_ImportService != null && th_ImportService.ThreadState == System.Threading.ThreadState.Running) { this.ImportTemplateID = 0; th_ImportService.Abort(); th_ImportService.Join(5000); th_ImportService = new Thread(new ThreadStart(UploadExcel)); th_ImportService.Start(); } } Thread.Sleep(50000); } }
private void ThreadCheckHeartTime() { while (bIsRunning) { int TimeLimit = ConfigHelper.GetConfigInt("TimeLimit"); if (dtHeartTime < DateTime.Now.AddSeconds(-TimeLimit) && ImportTemplateID > 0) { IPT_UploadTemplateBLL _bll = new IPT_UploadTemplateBLL(ImportTemplateID); _bll.Model.State = 3; _bll.Model.Remark = "导入出错,导入超时,请确认文件没有损坏或病毒再上传!"; _bll.Model.ImportTime = DateTime.Now; _bll.Update(); if (th_ImportService != null && th_ImportService.ThreadState == System.Threading.ThreadState.Running) { this.ImportTemplateID = 0; th_ImportService.Abort(); th_ImportService.Join(5000); th_ImportService = new Thread(new ThreadStart(UploadExcel)); th_ImportService.Start(); } } Thread.Sleep(50000); } }
private void ImportBaseClientInfo(int templateid, string path) { IPT_UploadTemplateBLL _bll = new IPT_UploadTemplateBLL(templateid); if (_bll.Model.State != 1) return;//模版作废 string message = ""; int State = 0;//五个Sheet导入结果的合计 #region 导入Excel文件 if (!File.Exists(path)) { message += "Excel在当前路径中不存在!\r\n"; State = 20; } else { try { FileStream fs = new FileStream(path, FileMode.Open); IWorkbook _ibook = WorkbookFactory.Create(fs); if (_ibook.GetSheet("商品资料") == null || _ibook.GetSheet("客户资料") == null || _ibook.GetSheet("供货单位信息") == null || _ibook.GetSheet("期初库存") == null) { message += "Excel表格缺少Sheet表单\r\n"; State = 20; } else { ClientInit _ClientInit = new ClientInit(); int _State = 0; message += _ClientInit.DoImportProduct(templateid, _bll.Model.ClientID, _ibook.GetSheet("商品资料"), out _State); message += "\r\n"; State += _State; message += _ClientInit.DoImportClient(templateid, _bll.Model.ClientID, _ibook.GetSheet("客户资料"), out _State); message += "\r\n"; State += _State; message += _ClientInit.DoImportSupplier(templateid, _bll.Model.ClientID, _ibook.GetSheet("供货单位信息"), out _State); message += "\r\n"; State += _State; message += _ClientInit.DoImportInventory(templateid, _bll.Model.ClientID, _ibook.GetSheet("期初库存"), out _State); message += "\r\n"; State += _State; fs.Close(); fs.Dispose(); } } catch (System.Exception err) { string error = "Message:" + err.Message + "<br/>" + "Source:" + err.Source + "<br/>" + "StackTrace:" + err.StackTrace + "<br/>"; message += "系统错误-4!" + err.Message; _bll.Model.Remark = message; } } #endregion if (State == 15) _bll.Model.State = 3; else if (State == 20) _bll.Model.State = 4; else _bll.Model.State = 5; _bll.Update(); this.SendMessage("UploadExcel.导入提示!", message); }
public void UploadExcel() { while (bIsRunning) { try { #region 获取最迟的销量月份 int JXCDelayDays = ConfigHelper.GetConfigInt("JXCDelayDays"); #endregion IList<IPT_UploadTemplate> uplists = IPT_UploadTemplateBLL.GetModelList("State=1"); if (uplists.Count == 0) { System.Threading.Thread.Sleep(2000); continue; } foreach (IPT_UploadTemplate m in uplists) { dtHeartTime = DateTime.Now; ImportTemplateID = m.ID; try { #region 组织文件路径及文件名 string path = m.FullFileName; if (path.EndsWith("\\")) path = path + "\\"; string filename = m.ShortFileName; #endregion SendMessage("UploadExcel.UploadExcel", "开始处理文件" + filename); switch (m.FileType) { case 1: this.ImportBaseClientInfo(m.ID, path); break; default: break; } this.ImportTemplateID = 0; } catch (System.Exception err) { IPT_UploadTemplateBLL _bll = new IPT_UploadTemplateBLL(m.ID); _bll.Model.State = 3; _bll.Model.Remark = "导入出错,异常:" + err.Message; _bll.Model.ImportTime = DateTime.Now; _bll.Update(); this.ImportTemplateID = 0; } } } catch (ThreadAbortException e) { this.SendMessage("UploadExcel.ThreadAbortException", this.ImportTemplateID.ToString() + e.Message); Thread.Sleep(10000); continue; } catch (Exception ex) { this.SendMessage("UploadExcel.Exception", ex.Message); Thread.Sleep(10000); continue; } } }
private void ImportBaseClientInfo(int templateid, string path) { IPT_UploadTemplateBLL _bll = new IPT_UploadTemplateBLL(templateid); if (_bll.Model.State != 1) { return; //模版作废 } string message = ""; int State = 0;//五个Sheet导入结果的合计 #region 导入Excel文件 if (!File.Exists(path)) { message += "Excel在当前路径中不存在!\r\n"; State = 20; } else { try { FileStream fs = new FileStream(path, FileMode.Open); IWorkbook _ibook = WorkbookFactory.Create(fs); if (_ibook.GetSheet("商品资料") == null || _ibook.GetSheet("客户资料") == null || _ibook.GetSheet("供货单位信息") == null || _ibook.GetSheet("期初库存") == null) { message += "Excel表格缺少Sheet表单\r\n"; State = 20; } else { ClientInit _ClientInit = new ClientInit(); int _State = 0; message += _ClientInit.DoImportProduct(templateid, _bll.Model.ClientID, _ibook.GetSheet("商品资料"), out _State); message += "\r\n"; State += _State; message += _ClientInit.DoImportClient(templateid, _bll.Model.ClientID, _ibook.GetSheet("客户资料"), out _State); message += "\r\n"; State += _State; message += _ClientInit.DoImportSupplier(templateid, _bll.Model.ClientID, _ibook.GetSheet("供货单位信息"), out _State); message += "\r\n"; State += _State; message += _ClientInit.DoImportInventory(templateid, _bll.Model.ClientID, _ibook.GetSheet("期初库存"), out _State); message += "\r\n"; State += _State; fs.Close(); fs.Dispose(); } } catch (System.Exception err) { string error = "Message:" + err.Message + "<br/>" + "Source:" + err.Source + "<br/>" + "StackTrace:" + err.StackTrace + "<br/>"; message += "系统错误-4!" + err.Message; _bll.Model.Remark = message; } } #endregion if (State == 15) { _bll.Model.State = 3; } else if (State == 20) { _bll.Model.State = 4; } else { _bll.Model.State = 5; } _bll.Update(); this.SendMessage("UploadExcel.导入提示!", message); }
public void UploadExcel() { while (bIsRunning) { try { #region 获取最迟的销量月份 int JXCDelayDays = ConfigHelper.GetConfigInt("JXCDelayDays"); #endregion IList <IPT_UploadTemplate> uplists = IPT_UploadTemplateBLL.GetModelList("State=1"); if (uplists.Count == 0) { System.Threading.Thread.Sleep(2000); continue; } foreach (IPT_UploadTemplate m in uplists) { dtHeartTime = DateTime.Now; ImportTemplateID = m.ID; try { #region 组织文件路径及文件名 string path = m.FullFileName; if (path.EndsWith("\\")) { path = path + "\\"; } string filename = m.ShortFileName; #endregion SendMessage("UploadExcel.UploadExcel", "开始处理文件" + filename); switch (m.FileType) { case 1: this.ImportBaseClientInfo(m.ID, path); break; default: break; } this.ImportTemplateID = 0; } catch (System.Exception err) { IPT_UploadTemplateBLL _bll = new IPT_UploadTemplateBLL(m.ID); _bll.Model.State = 3; _bll.Model.Remark = "导入出错,异常:" + err.Message; _bll.Model.ImportTime = DateTime.Now; _bll.Update(); this.ImportTemplateID = 0; } } } catch (ThreadAbortException e) { this.SendMessage("UploadExcel.ThreadAbortException", this.ImportTemplateID.ToString() + e.Message); Thread.Sleep(10000); continue; } catch (Exception ex) { this.SendMessage("UploadExcel.Exception", ex.Message); Thread.Sleep(10000); continue; } } }