/// <summary> /// 打印失败的操作 /// </summary> /// <param name="printInfo"></param> /// <param name="ex"></param> private void DoByPrintResultFailure(PrintInfoModel printInfo, Exception ex) { if (printInfo.delFlag == false) { DoByPrintResult(false, printInfo, ex.Message); } }
private List <PrintInfoModel> DataTableToListForNeedPrint(DataTable dt) { List <PrintInfoModel> modelList = new List <PrintInfoModel>(); int rowsCount = dt.Rows.Count; if (rowsCount > 0) { PrintInfoModel model; for (int n = 0; n < rowsCount; n++) { model = new PrintInfoModel(); model.id = Convert.ToInt32(dt.Rows[n]["id"].ToString()); model.processCardNumber = dt.Rows[n]["processCardNumber"].ToString(); model.tempName = dt.Rows[n]["tempName"].ToString(); model.printJson = dt.Rows[n]["printJson"].ToString(); model.printType = dt.Rows[n]["printType"].ToString(); model.printerName = dt.Rows[n]["printerName"].ToString(); model.printArea = dt.Rows[n]["printArea"].ToString(); if (dt.Rows[n]["delFlag"].ToString() != "") { model.delFlag = Convert.ToBoolean(dt.Rows[n]["delFlag"].ToString()); } modelList.Add(model); } } return(modelList); }
/// <summary> /// 打印成功的操作 /// </summary> /// <param name="printInfo"></param> private void DoByPrintResultSuccess(PrintInfoModel printInfo) { if (printInfo.delFlag == false) { DoByPrintResult(true, printInfo); } else {//只打印 } }
/// <summary> /// 打印操作 /// </summary> /// <param name="workbook"></param> /// <param name="printInfo"></param> /// <returns></returns> public void Print(string json_cellList, PrintInfoModel printInfo, PageOrientationType orientation) { IDictionary <string, object> logDict = new Dictionary <string, object>(); logDict.Add("json_cellList", json_cellList); logDict.Add("printInfo", printInfo); logDict.Add("orientation", orientation); ExceptionInfoEntity exception = WipLogHelper.GetExceptionInfo <IDictionary <string, object> >(namespaceName, "Print", logDict , "", printInfo == null ? "" : printInfo.processCardNumber, ExceptionSource.WIPPost, ExceptionLevel.BusinessError, wipSource); try { //创建文件 List <ExcelSheetModel> sheetModelList = new List <ExcelSheetModel>(); List <ExcelCellModel> cellModelList = JsonConvert.DeserializeObject <List <ExcelCellModel> >(json_cellList); ExcelSheetModel sheetModel = new ExcelSheetModel() { sheetName = this.workbook.GetSheetAt(0).SheetName, dataList = cellModelList, sheetType = "", }; sheetModelList.Add(sheetModel); byte[] bytes = ExcelUtil.writeExcelToFile(this.workbook, sheetModelList, printInfo.tempName); //修改为“打印中” var result = UpdatePrintStatusToPrinting(printInfo.id); if (!result) { throw new Exception("更新状态为打印中失败,printInfo.id:" + printInfo.id.ToString()); } PrintHelper.PrintExcel(bytes, printInfo.printerName, orientation); //打印成功 this.DoByPrintResultSuccess(printInfo); } catch (Exception ex) { WipLogHelper.GetExceptionInfoForError(ex, ref exception); WipLogHelper.WriteExceptionInfo(exception); //打印失败 this.DoByPrintResultFailure(printInfo, ex); } }
/// <summary> /// 获取更新打印结果的sql参数 /// </summary> /// <param name="printResult"></param> /// <param name="printInfo"></param> /// <param name="errMsg"></param> /// <returns></returns> private SqlParameter[] GetSqlParamForUpdatePrintResult(bool printResult, PrintInfoModel printInfo, string errMsg) { var isPrintProcessCard = "0"; //是否是打印流转卡 var isPrintSuccess = "0"; //是否打印成功 var processCardPrintQueueId = 0; if (printInfo.delFlag == false && printInfo.printType == Convert.ToInt32(PrintType.ProcessCardForBuffer).ToString() || printInfo.printType == Convert.ToInt32(PrintType.ProcessCardForPostHeatStorageOut).ToString()) { isPrintProcessCard = "1"; processCardPrintQueueId = 0;//模拟写死 } if (printResult) {//打印成功 isPrintSuccess = "1"; } SqlParameter[] parameters = { new SqlParameter("@printResult", SqlDbType.VarChar, 2), new SqlParameter("@printInfoId", SqlDbType.Int), new SqlParameter("@printErrMsg", SqlDbType.NVarChar, 100), new SqlParameter("@isPrintProcessCard", SqlDbType.VarChar, 2), new SqlParameter("@processCardPrintQueueId", SqlDbType.Int), new SqlParameter("@printTime", SqlDbType.DateTime), new SqlParameter("@processCardNumber", SqlDbType.NVarChar, 50) }; parameters[0].Value = isPrintSuccess; parameters[1].Value = printInfo.id; parameters[2].Value = errMsg; parameters[3].Value = isPrintProcessCard; parameters[4].Value = processCardPrintQueueId; parameters[5].Value = DateTime.Now; parameters[6].Value = printInfo.processCardNumber; return(parameters); }
public override bool DoByPrintResult(bool printResult, PrintInfoModel printInfo, string errMsg = "") { return(base.DoByPrintResult(printResult, printInfo, errMsg)); }
/// <summary> /// 处理打印结果 /// </summary> /// <param name="printResult">打印结果</param> /// <param name="printInfo">打印信息</param> /// <param name="errMsg">错误信息</param> /// <returns></returns> public virtual bool DoByPrintResult(bool printResult, PrintInfoModel printInfo, string errMsg = "") { var retResult = false;//返回结果 IDictionary <string, object> logDict = new Dictionary <string, object>(); logDict.Add("printResult", printResult); logDict.Add("printInfo", printInfo); ExceptionInfoEntity exception = WipLogHelper.GetExceptionInfo <IDictionary <string, object> >(namespaceName, "DoByPrintResult", logDict , "", printInfo == null ? "" : printInfo.processCardNumber, ExceptionSource.WIPPost, ExceptionLevel.BusinessError, wipSource); try { #region 准备数据 SqlParameter[] parameters_UpdatePrintResult = this.GetSqlParamForUpdatePrintResult(printResult, printInfo, errMsg); #endregion #region 事务处理 using (SqlConnection conn = new SqlConnection(SQLServerHelper.connectionString)) { conn.Open(); using (SqlTransaction trans = conn.BeginTransaction()) { TransactionModel transModel = new TransactionModel() { conn = conn, trans = trans }; try { var execResult = WIPDataAccess.CreateDAL <IPrintInfoDAL>("PrintInfoDAL").UpdatePrintResult(parameters_UpdatePrintResult, transModel); if (execResult != 1) {//返回1代表执行成功,返回-1代表失败 throw new Exception("处理打印结果失败,parameters:" + JsonConvert.SerializeObject(parameters_UpdatePrintResult) + ",execResult:" + execResult.ToString()); } trans.Commit(); retResult = true; } catch { retResult = false; trans.Rollback(); throw; } } } #endregion } catch (Exception ex) { retResult = false; WipLogHelper.GetExceptionInfoForError(ex, ref exception); WipLogHelper.WriteExceptionInfo(exception); } return(retResult); }