/// <summary> /// 校验修箱信息,返回错误信息 /// </summary> /// <param name="path"></param> /// <returns></returns> public string VerifyExcel(string path) { if (string.IsNullOrEmpty(path)) { return(""); } StringBuilder errorMsg = new StringBuilder(); var dic = NOPI.ExcelToDataTable(path);//EPPlus.ExcelToDataTable(path); if (dic["DM"].Rows.Count == 0 && dic["RP"].Rows.Count == 0 && dic["EA"].Rows.Count == 0) { return("未检测到箱信息,请修正后再上传!"); } foreach (var table in dic) { if (table.Key == "DM" || table.Key == "RP" || table.Key == "EA") { if (table.Value.Rows.Count > 0) { foreach (DataRow dr in table.Value.Rows) { DateTime date = DateTime.MinValue; errorMsg.Append(VerifyData(dr[0], dr[1], dr[2], dr[3], table.Key)); } } } } return(errorMsg.ToString()); }
public string ImportCodeMapping(string filePath, string currentUserName) { Dictionary <string, DataTable> dicImportData = NOPI.ExcelToDataTable(filePath); string checkResult = string.Empty; if (dicImportData.Count > 0) { foreach (var data in dicImportData) { DataTable dtData = data.Value; if (dtData.Rows.Count > 1) { string result = CheckData(dtData); if (!string.IsNullOrWhiteSpace(result)) { checkResult = result; } else { InsertTableFromDataTable(dtData, currentUserName); } } else { checkResult = "请先维护数据再上传。"; } } return(checkResult); } else { return("文件上传失败!"); } }
/// <summary> /// 报文内容 /// </summary> /// <param name="path"></param> /// <returns></returns> public string TransferFileContent(string path, out string date) { date = ""; if (string.IsNullOrEmpty(path)) { return(""); } StringBuilder txtContent = new StringBuilder(); var dic = NOPI.ExcelToDataTable(path); string header = string.Empty; foreach (var table in dic) { if (table.Key == "DM" || table.Key == "RP" || table.Key == "EA") { if (table.Value.Rows.Count > 0) { //分块报文头 “$$X/CNNGB/年月日(8)/类型代码(RP/EA/DM)” txtContent.Append("$$X/CNNGB/"); txtContent.Append(table.Value.Rows[0][2].ToString().Substring(0, 8)); txtContent.Append("/"); txtContent.AppendLine(table.Key); if (string.IsNullOrEmpty(date)) //文件名 取上传内容中时间字段第一条记录的前8位日期的后一日 { DateTime time = new DateTime(Convert.ToInt32(table.Value.Rows[0][2].ToString().Substring(0, 4)), Convert.ToInt32(table.Value.Rows[0][2].ToString().Substring(4, 2)), Convert.ToInt32(table.Value.Rows[0][2].ToString().Substring(6, 2))); //time=time.AddDays(1); date = "RPCNNGBP03" + time.ToString("yyyyMMdd") + "_" + DateTime.Now.ToString("HHmmss") + ".txt"; } foreach (DataRow dr in table.Value.Rows) { if (dr[0] == null || string.IsNullOrEmpty(Convert.ToString(dr[0]))) { continue; } //分块报文体 “箱号/时分(4)//CNNGBP03/ CNNGBP03” txtContent.Append(dr[1].ToString()); txtContent.Append("/"); txtContent.Append(dr[2].ToString().Substring(8, 4)); txtContent.AppendLine("//CNNGBP03/CNNGBP03"); //总报文头 “$$$/NGB/GIC/年月日(8)/年(4)DX月日(4)PM” if (string.IsNullOrEmpty(header)) { header = "$$$/NGB/GIC/" + dr[2].ToString().Substring(0, 8) + "/"; header += "RP" + dr[2].ToString().Substring(0, 4) + "DX"; header += dr[2].ToString().Substring(4, 4) + "PM"; header += Environment.NewLine; } } } } } string result = header + txtContent.ToString(); return(result); }