//从Excel导入数据 private void ImportExcel() { OpenFileDialog openDialog = new OpenFileDialog(); openDialog.Filter = "Execl files (*.xls)|*.xls|(*.xlsx)|*.xlsx"; openDialog.FilterIndex = 0; openDialog.RestoreDirectory = true; openDialog.Title = "打开Excel文件"; string fileName = string.Empty;//要上传的文件名 if (openDialog.ShowDialog() == DialogResult.OK) { WinFileTransporter wFile = new WinFileTransporter(); fileName = openDialog.FileName; string uriFiles = string.Empty;//保存到服务器路径 string folderName = Application.StartupPath + "\\importFiles"; if (!Directory.Exists(folderName))//如果路径不存在则创建 { Directory.CreateDirectory(folderName); } try { if (wFile.UpLoadFile(fileName, folderName, out uriFiles, true)) { DataTable dt = new DataTable(); string errorStr = string.Empty; AsposeExcelTools.ExcelFileToDataTable(uriFiles, out dt, out errorStr);//读取表格数据,转换为datatable List <DATestmap> errorList = new List <DATestmap>(); List <DATestmap> testmapList = new List <DATestmap>(); if (dt != null && dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { DATestmap testmap = new DATestmap(); testmap.Customertestcode = dt.Rows[i]["医院项目代码(项目导入唯一标识)"].ToString().Trim(); testmap.Customertestname = dt.Rows[i]["医院项目名称(作为对应参考,不做导入标识)"].ToString().Trim(); testmap.Datestcode = dt.Rows[i]["达安项目代码(项目导入唯一标识)"].ToString().Trim(); testmap.Datestname = dt.Rows[i]["达安项目名称(作为对应参考,不做导入标识)"].ToString().Trim(); if (testmap.Customertestcode == string.Empty) { errorList.Add(testmap); errorStr += "导入错误:医院项目代码为空,"; continue; } if (testmap.Datestcode == string.Empty) { errorList.Add(testmap); errorStr += "导入错误:达安项目代码为空,"; continue; } if (testmap.Customertestname == string.Empty) { errorList.Add(testmap); errorStr += "导入错误:医院项目名称为空,"; continue; } if (testmap.Datestname == string.Empty) { errorList.Add(testmap); errorStr += "导入错误:达安项目名称为空,"; continue; } if (!IsExistHosp(testmap.Customertestcode, testmap.Customertestname)) { errorList.Add(testmap); errorStr += "导入错误:医院项目信息不存在,"; continue; } if (!IsExistDaan(testmap.Datestcode, testmap.Datestname)) { errorList.Add(testmap); errorStr += "导入错误:达安项目信息不存在,"; continue; } //如果在testmap表已经存在医院项目代码的记录,记录对象及错误信息 //if (IsExist(testmap.Customertestcode)) //{ // errorList.Add(testmap); // errorStr += "导入失败:该医院项目已存在对应的匹配信息,"; // continue; //} errorList.Add(testmap); errorStr += "导入成功,"; testmapList.Add(testmap); } //if (testmapBll.ImportDaTestmap(testmapList)) if (testmapBll.SaveDATestmapList(testmapList)) { //弹出错误信息 //if (errorList != null) //{ FrmItemHoapitalAndDaanImportError errorFrm = new FrmItemHoapitalAndDaanImportError(); errorFrm.StrFailed = errorStr; errorFrm.testmapList = errorList; errorFrm.StartPosition = FormStartPosition.CenterScreen; errorFrm.ShowDialog(); BindData(); //} //else //{ // ShowMessageHelper.ShowBoxMsg("导入成功!"); //} } else { ShowMessageHelper.ShowBoxMsg("导入失败!"); } } else { ShowMessageHelper.ShowBoxMsg("没有数据导入!"); } } } catch (Exception e) { ShowMessageHelper.ShowBoxMsg("导入的过程中发生了异常:" + e.Message); } finally { //删除文件 if (File.Exists(uriFiles)) { File.Delete(uriFiles); } } } }
/// <summary>预览</summary> /// <param name="sendstring"></param> private void BindWebBrower(string sendstring) { if (sendstring != "" && sendstring != null) { #region >>>> zhangw 显示报告 //删除其他PDF文件 正在显示的不删除 WinFileTransporter.DeleteFolder(FileOrPath); Createfile(); //创建PDF文件夹 string FilePath = FileOrPath; string filename = FilePath + " 预览:" + sendstring + ".pdf"; //打包后的PDF文件名称 bool isA4 = true; ArrayList fileList = new ArrayList(); Hashtable ha = new Hashtable(); ha.Add("Hospsampleid", sendstring); //达安条码 List <DAReport> da = new DAReportBLL().SelectDAReportByRequestcode(ha); //是否存在多个报告单 //显示报告控件 this.webPdfReader.Visible = true; string PDFPath = string.Empty; if (da.Count == 0) { #region 没有报告 this.webPdfReader.Visible = false; ShowMessageHelper.ShowBoxMsg("没有报告预览!"); this.Close(); return; #endregion } else if (da.Count == 1) { #region 单个报告 string pdfFilePath = FileOrPath + sendstring + ".PDF"; //文件存在则更换名称 if (File.Exists(pdfFilePath)) { pdfFilePath = FileOrPath + sendstring + "_1.PDF"; } byte[] buff = da[0].Reportdata; if (da[0].Reportdata == null) { this.webPdfReader.Visible = false; ShowMessageHelper.ShowBoxMsg("没有报告预览!"); this.Close(); return; } CreatPath(pdfFilePath, buff); PDFPath = pdfFilePath; #endregion } else if (da.Count > 1) { #region 多份报告 合并 for (int i = 0; i < da.Count; i++) { fileList.Add(da[i].Requestcode + "_" + i); } String[] files = new string[fileList.Count]; for (int i = 0; i < fileList.Count; i++) { #region // string FilePath = Application.StartupPath + "\\PDF打印\\";; //设置PDF路径 files[i] = FilePath + fileList[i].ToString() + ".PDF"; //设置PDF文件名称 string path = files[i]; //打开PDF路径 if (fileList[i].ToString().Contains("_")) //设置路径是否包含多个 { if (da.Count > 1) { for (int m = 0; m < da.Count; m++) { if (fileList[i].ToString() == da[m].Requestcode + "_" + m) { path = FilePath + da[m].Requestcode + "_" + m + ".PDF"; byte[] buff = da[m].Reportdata; CreatPath(path, buff); } } } else { byte[] buff = da[0].Reportdata; CreatPath(path, buff); } } else { if (da.Count != 0) { byte[] buff = da[0].Reportdata; CreatPath(path, buff); } } #endregion } mergePDFFiles(files, filename, isA4); PDFPath = filename; #endregion } this.webPdfReader.Navigate(PDFPath); //预览PDF #endregion } }