`C+V?yikC2hxsA7CeHP^Rn-|^t#vCu;$HOtJHl7lzq1a1KS?j
ziF)7O*Snoh$xrN(*Myh1^MFI~?dML^yDgjH*8*!Wzd1s1yvs)yu?Xg`yZ;U}Uww*VJ
zy0_hSes;{PwyTo=NSoU;GuTXOXdYzGhx!w^QV(=fznHDS%+zTu?uy7f%U4EAGY
z+?TV2pD2=bB%Juauc)p2+MIp7!MBCc(hW#R81R3}mDjC^rq4V5QaCML@v+mPm1~w4
z(_eMAv|2y@EOoZ@a|w9yqz%w&NfdtGUwFFAf)pN#SMb8{&yzp)$NTAJhE`TfsQmJ3
zA!|^NH2&&i_^UT9cl77ehTxB`bb1kJWBj$t9rD?cy!aF8@Ru*GgQcI3oulwaRxh`=
zwF6qL-r(yaj2AzD{4BkP23{e-OQP=|B?i@XtD@`6_xw`EEp_zqLB&43Y>mYG@;+ax
zN~`w~KepWc8pY|$JACO+S-rzqiH~|b&*}}%D=qi?>9GCPL(?r?x%{&*MSFFQV9PI;7*X&p%-&&K7{)}>27
z&f2{-*DfczE{7(3d6zE}WLNJpyKUw1*QCpS|6OQ!zIvDC@bZ(&WJ@dtzc?64!tl>b
KcM`u^Nd6C|Df3+b
literal 0
HcmV?d00001
diff --git a/PEIS/Utils/ExcelHelper.cs b/PEIS/Utils/ExcelHelper.cs
index f30adb3..ce1d20d 100644
--- a/PEIS/Utils/ExcelHelper.cs
+++ b/PEIS/Utils/ExcelHelper.cs
@@ -1,10 +1,10 @@
using System;
using System.Collections.Generic;
-using System.Globalization;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using NPOI.HSSF.UserModel;
+using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using PEIS.Entity;
@@ -12,9 +12,9 @@ namespace PEIS.Utils
{
public class ExcelHelper
{
-
+ private int StartRow = 4;
public List SuccessList = new List();
- public List ErrorList = new List();
+ public List ErrorList = new List();
public void ReadOrgPatientList()
{
try
@@ -24,17 +24,7 @@ namespace PEIS.Utils
dialog.Filter = @"Excel文件 (*.xls;*.xlsx)|*.xls;*.xlsx";
if (dialog.ShowDialog() != DialogResult.OK) return;
var excelFilePath = dialog.FileName;
- var fileExtension = Path.GetExtension(excelFilePath);
- switch (fileExtension)
- {
- case ".xls":
- ReadXLS(excelFilePath);
- break;
-
- case ".xlsx":
- ReadXLSX(excelFilePath);
- break;
- }
+ ReadExcelData(excelFilePath);
}
catch (Exception e)
{
@@ -42,215 +32,117 @@ namespace PEIS.Utils
Global.Msg("err", e.Message);
}
}
-
///
- /// 读取Excel XLS文件
+ /// 读取Excel文件
///
- ///
- public void ReadXLS(string excelFilePath)
+ /// 指定 .xlsx/.xls 文件的路径
+ public void ReadExcelData(string excelFilePath)
{
+ var fileExtension = Path.GetExtension(excelFilePath);
+ if (fileExtension != ".xls" && fileExtension != ".xlsx") return;
using (var fileStream = new FileStream(excelFilePath, FileMode.Open, FileAccess.Read))
{
-
- // 使用 HSSFWorkbook 打开 .xls 文件
- var workbook = new HSSFWorkbook(fileStream);
- // 选择工作表 第一个工作表
- var sheet = workbook.GetSheetAt(0);
- // 获取工作表的行数
- var rowCount = sheet.PhysicalNumberOfRows;
- int continuousEmpty = 0;
- // 遍历工作表并读取数据
- for (var row = 3; row < rowCount; row++)
+ var sheet = GetSheet(fileStream, fileExtension); // 第一个工作表
+ for (int startIndex = 0; startIndex < StartRow; startIndex++)
{
- if (continuousEmpty == 3)
- {
- break; // 如果连续三个错误,停止循环
- }
- var dataRow = sheet.GetRow(row);
-
- var name = dataRow.GetCell(0).ToString();
- var cardNo = dataRow.GetCell(4)?.ToString();
-
- if (string.IsNullOrEmpty(dataRow.GetCell(0).ToString())
- || !string.IsNullOrEmpty(cardNo) && cardNo.Length != 18
- || (cardNo?.Length == 18 && !DateTime.TryParseExact(cardNo.Substring(6, 8), "yyyyMMdd", null,
- DateTimeStyles.None, out _)))
- {
- continuousEmpty++;
- ErrorList.Add(new BasePatient()
- {
- ID = row,
- Name = dataRow.GetCell(0).ToString(),
- Sex = dataRow.GetCell(1).ToString(),
- Marriage = dataRow.GetCell(2).ToString(),
- Nation = dataRow.GetCell(3).ToString(),
- CardNo = dataRow.GetCell(4).ToString(),
- CardType = "居民身份证",
- Education = dataRow.GetCell(5).ToString(),
- Tel1 = dataRow.GetCell(6).ToString(),
- Address1 = dataRow.GetCell(7).ToString(),
- DeptName = dataRow.GetCell(8).ToString(),
- });
- continue;
- }
-
- SuccessList.Add(new BasePatient()
- {
- Name = name,
- Sex = dataRow.GetCell(1).ToString(),
- Marriage = dataRow.GetCell(2).ToString(),
- Nation = dataRow.GetCell(3).ToString(),
- CardNo = cardNo,
- CardType = "居民身份证",
- Education = dataRow.GetCell(5).ToString(),
- Tel1 = dataRow.GetCell(6).ToString(),
- Address1 = dataRow.GetCell(7).ToString(),
- DeptName = dataRow.GetCell(8).ToString(),
- });
- continuousEmpty = 0;
+ ErrorList.Add(new ExcelRowModel(startIndex, sheet.GetRow(startIndex)));
}
- };
- }
-
- ///
- /// 读取Excel XLSX文件
- ///
- /// 指定 .xlsx 文件的路径
- public void ReadXLSX(string excelFilePath)
- {
- using (var fileStream = new FileStream(excelFilePath, FileMode.Open, FileAccess.Read))
- {
- var workbook = new XSSFWorkbook(fileStream);
- var sheet = workbook.GetSheetAt(0); // 第一个工作表
-
// 获取工作表的行数和列数
var rowCount = sheet.PhysicalNumberOfRows;
-
int continuousEmpty = 0;
// 遍历工作表并读取数据
- for (var row = 2; row < rowCount; row++)
+ for (var row = StartRow; row < rowCount; row++)
{
- if (continuousEmpty == 3)
+ if (continuousEmpty == 5)
{
- break; // 如果连续三个错误,停止循环
+ break; // 如果连续5行错误,停止循环
}
var dataRow = sheet.GetRow(row);
- var name = dataRow.GetCell(0).ToString();
- var cardNo = dataRow.GetCell(4)?.ToString();
- if (string.IsNullOrEmpty(dataRow.GetCell(0).ToString()) || !string.IsNullOrEmpty(cardNo) && cardNo.Length != 18 || (cardNo?.Length == 18 && !DateTime.TryParseExact(cardNo.Substring(6, 8), "yyyyMMdd", null,
- DateTimeStyles.None, out _)))
+ var readPatient = ReadRowToBasePatient(dataRow);
+ var isBasePatient = readPatient.Validate();
+ if (!isBasePatient || SuccessList.Any(p => p.CardNo == readPatient.CardNo))
{
continuousEmpty++;
- ErrorList.Add(new BasePatient()
- {
- ID = row,
- Name = dataRow.GetCell(0).ToString(),
- Sex = dataRow.GetCell(1).ToString(),
- Marriage = dataRow.GetCell(2).ToString(),
- Nation = dataRow.GetCell(3).ToString(),
- CardNo = dataRow.GetCell(4).ToString(),
- CardType = "居民身份证",
- Education = dataRow.GetCell(5).ToString(),
- Tel1 = dataRow.GetCell(6).ToString(),
- Address1 = dataRow.GetCell(7).ToString(),
- DeptName = dataRow.GetCell(8).ToString(),
- });
+ ErrorList.Add(new ExcelRowModel(row, dataRow));
continue;
}
-
- SuccessList.Add(new BasePatient()
- {
- Name = name,
- Sex = dataRow.GetCell(1).ToString(),
- Marriage = dataRow.GetCell(2).ToString(),
- Nation = dataRow.GetCell(3).ToString(),
- CardNo = cardNo,
- CardType = "居民身份证",
- Education = dataRow.GetCell(5).ToString(),
- Tel1 = dataRow.GetCell(6).ToString(),
- Address1 = dataRow.GetCell(7).ToString(),
- DeptName = dataRow.GetCell(8).ToString(),
- });
+ SuccessList.Add(readPatient);
continuousEmpty = 0;
}
};
}
-
- // ///
- // /// 导出Excel
- // ///
- // ///
- // ///
- // ///
- // private MemoryStream ExportExcel(List list, string propertyStr)
- // {
- // var properties = propertyStr.Split(',').ToList();
- // using (var package = new ExcelPackage())
- // {
- // // 添加工作表
- // var worksheet = package.Workbook.Worksheets.Add($"{DateTime.Now:yyyyMMdd}");
- // // 将列名添加到第一行
- // for (var i = 0; i < properties.Count; i++)
- // {
- // if (Properties.ContainsKey(properties[i]))
- // worksheet.Cells[1, i + 1].Value = Properties[(properties[i])];
- // }
- // // 将数据写入单元格
- // for (var row = 0; row < list.Count; row++)
- // {
- // for (var col = 0; col < properties.Count; col++)
- // {
- // worksheet.Cells[row + 2, col + 1].Value = GetValueByPropertyNameHandle(list[row], properties[col]);
- // }
- // }
- // // 自动调整列宽
- // worksheet.Cells.AutoFitColumns();
- // // 保存文件到 MemoryStream
- // var memoryStream = new MemoryStream(package.GetAsByteArray());
- // // 设置流的位置为起始位置
- // memoryStream.Seek(0, SeekOrigin.Begin);
- // // 返回 Excel 文件
- // return memoryStream;
- // }
- // }
-
- ///
- /// 可选字段
- ///
- private static Dictionary Properties = new Dictionary()
+ private static ISheet GetSheet(FileStream fileStream, string fileExtension)
{
- {"Id", "id"},
- {"CriticalName", "项目名称"},
- {"CriticalCode", "项目代码"},
- {"CriticalValue", "危急值"},
- {"Description", "描述"},
- {"Unit", "单位"},
- };
+ if (fileExtension == ".xls")
+ return new HSSFWorkbook(fileStream).GetSheetAt(0);
-
- ///
- /// 根据属性名获取对象的属性值
- ///
- ///
- ///
- ///
- private string GetValueByPropertyNameHandle(EnrollmentPatient patient, string propertyName)
+ if (fileExtension == ".xlsx")
+ return new XSSFWorkbook(fileStream).GetSheetAt(0); // 第一个工作表
+ return null;
+ }
+ private static BasePatient ReadRowToBasePatient(IRow dataRow)
{
- switch (propertyName)
+ var sex = dataRow.GetCell(2)?.ToString()??"";
+ return new BasePatient()
{
- case "Id":
- return patient.ID.ToString();
- case "Name":
- return patient.Name;
- case "Age":
- return patient.Age + " " + patient.AgeClass;
- default:
- return "";
- }
+ // A-0-序号,B-1-姓名,C-2-性别,D-3-民族,E-4-婚姻,F-5-身份证号,G-6-住址,H-7-电话,I-8-部门,J-9备注
+ Name = dataRow.GetCell(1)?.ToString(),
+ Sex = sex.Contains("女")?"2":"1",
+ Nation = dataRow.GetCell(3)?.ToString(),
+ Marriage = dataRow.GetCell(4)?.ToString(),
+ CardNo = dataRow.GetCell(5)?.ToString(),
+ CardType = "居民身份证",
+ Address1 = dataRow.GetCell(6)?.ToString(),
+ Tel1 = dataRow.GetCell(7)?.ToString(),
+ DeptName = dataRow.GetCell(8)?.ToString(),
+ };
}
+ }
-}
+ public class ExcelRowModel
+ {
+ public int RowCount { get; set; }
+ public string ColumnA { get; set; }
+ public string ColumnB { get; set; }
+ public string ColumnC { get; set; }
+ public string ColumnD { get; set; }
+ public string ColumnE { get; set; }
+ public string ColumnF { get; set; }
+ public string ColumnG { get; set; }
+ public string ColumnH { get; set; }
+ public string ColumnI { get; set; }
+ public string ColumnJ { get; set; }
+ public ExcelRowModel()
+ {
+ }
+ public ExcelRowModel(int rowCount, IRow row)
+ {
+ RowCount = rowCount + 1;
+ ColumnA = row.GetCell(0)?.ToString()??"";
+ ColumnB = row.GetCell(1)?.ToString()??"";
+ ColumnC = row.GetCell(2)?.ToString()??"";
+ ColumnD = row.GetCell(3)?.ToString()??"";
+ ColumnE = row.GetCell(4)?.ToString()??"";
+ ColumnF = row.GetCell(5)?.ToString()??"";
+ ColumnG = row.GetCell(6)?.ToString()??"";
+ ColumnH = row.GetCell(7)?.ToString()??"";
+ ColumnI = row.GetCell(8)?.ToString()??"";
+ ColumnJ = row.GetCell(9)?.ToString()??"";
+ }
+ public ExcelRowModel(BasePatient p)
+ {
+ ColumnA = p.Name;
+ ColumnB = p.Sex;
+ ColumnC = p.Nation;
+ ColumnD = p.Marriage;
+ ColumnE = p.CardNo;
+ ColumnF = p.CardType;
+ ColumnG = p.Address1;
+ ColumnH = p.Tel1;
+ ColumnI = p.DeptName;
+ }
+ }
}
\ No newline at end of file
diff --git a/PEIS/View/Base/PatientImportForm.Designer.cs b/PEIS/View/Base/PatientImportForm.Designer.cs
index 87278ad..adf0993 100644
--- a/PEIS/View/Base/PatientImportForm.Designer.cs
+++ b/PEIS/View/Base/PatientImportForm.Designer.cs
@@ -65,15 +65,6 @@
this.DgcError = new DevExpress.XtraGrid.GridControl();
this.DgvError = new DevExpress.XtraGrid.Views.Grid.GridView();
this.colNo = new DevExpress.XtraGrid.Columns.GridColumn();
- this.gridColumn7 = new DevExpress.XtraGrid.Columns.GridColumn();
- this.gridColumn8 = new DevExpress.XtraGrid.Columns.GridColumn();
- this.gridColumn14 = new DevExpress.XtraGrid.Columns.GridColumn();
- this.gridColumn15 = new DevExpress.XtraGrid.Columns.GridColumn();
- this.gridColumn16 = new DevExpress.XtraGrid.Columns.GridColumn();
- this.gridColumn17 = new DevExpress.XtraGrid.Columns.GridColumn();
- this.gridColumn19 = new DevExpress.XtraGrid.Columns.GridColumn();
- this.gridColumn21 = new DevExpress.XtraGrid.Columns.GridColumn();
- this.gridColumn27 = new DevExpress.XtraGrid.Columns.GridColumn();
this.repositoryItemComboBox1 = new DevExpress.XtraEditors.Repository.RepositoryItemComboBox();
this.repositoryItemComboBox2 = new DevExpress.XtraEditors.Repository.RepositoryItemComboBox();
this.repositoryItemComboBox3 = new DevExpress.XtraEditors.Repository.RepositoryItemComboBox();
@@ -90,6 +81,15 @@
this.gridColumn36 = new DevExpress.XtraGrid.Columns.GridColumn();
this.panel2 = new System.Windows.Forms.Panel();
this.label1 = new System.Windows.Forms.Label();
+ this.gridColumn7 = new DevExpress.XtraGrid.Columns.GridColumn();
+ this.gridColumn8 = new DevExpress.XtraGrid.Columns.GridColumn();
+ this.gridColumn14 = new DevExpress.XtraGrid.Columns.GridColumn();
+ this.gridColumn15 = new DevExpress.XtraGrid.Columns.GridColumn();
+ this.gridColumn16 = new DevExpress.XtraGrid.Columns.GridColumn();
+ this.gridColumn17 = new DevExpress.XtraGrid.Columns.GridColumn();
+ this.gridColumn19 = new DevExpress.XtraGrid.Columns.GridColumn();
+ this.gridColumn21 = new DevExpress.XtraGrid.Columns.GridColumn();
+ this.gridColumn27 = new DevExpress.XtraGrid.Columns.GridColumn();
this.gridColumn37 = new DevExpress.XtraGrid.Columns.GridColumn();
this.panel1.SuspendLayout();
this.OpsPatient.SuspendLayout();
@@ -582,133 +582,11 @@
// colNo
//
this.colNo.Caption = "Excel行号";
- this.colNo.FieldName = "id";
+ this.colNo.FieldName = "RowCount";
this.colNo.Name = "colNo";
this.colNo.Visible = true;
this.colNo.VisibleIndex = 0;
//
- // gridColumn7
- //
- this.gridColumn7.AppearanceCell.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
- this.gridColumn7.AppearanceCell.Options.UseFont = true;
- this.gridColumn7.Caption = "姓名";
- this.gridColumn7.FieldName = "Name";
- this.gridColumn7.Name = "gridColumn7";
- this.gridColumn7.OptionsColumn.AllowGroup = DevExpress.Utils.DefaultBoolean.False;
- this.gridColumn7.OptionsColumn.AllowSort = DevExpress.Utils.DefaultBoolean.False;
- this.gridColumn7.OptionsColumn.ReadOnly = true;
- this.gridColumn7.OptionsFilter.AllowFilter = false;
- this.gridColumn7.Visible = true;
- this.gridColumn7.VisibleIndex = 1;
- this.gridColumn7.Width = 100;
- //
- // gridColumn8
- //
- this.gridColumn8.AppearanceCell.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
- this.gridColumn8.AppearanceCell.Options.UseFont = true;
- this.gridColumn8.Caption = "性别";
- this.gridColumn8.FieldName = "Sex";
- this.gridColumn8.Name = "gridColumn8";
- this.gridColumn8.OptionsColumn.AllowGroup = DevExpress.Utils.DefaultBoolean.False;
- this.gridColumn8.OptionsColumn.AllowSort = DevExpress.Utils.DefaultBoolean.False;
- this.gridColumn8.OptionsColumn.ReadOnly = true;
- this.gridColumn8.OptionsFilter.AllowFilter = false;
- this.gridColumn8.Visible = true;
- this.gridColumn8.VisibleIndex = 2;
- this.gridColumn8.Width = 50;
- //
- // gridColumn14
- //
- this.gridColumn14.AppearanceCell.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
- this.gridColumn14.AppearanceCell.Options.UseFont = true;
- this.gridColumn14.Caption = "婚况";
- this.gridColumn14.FieldName = "Marriage";
- this.gridColumn14.Name = "gridColumn14";
- this.gridColumn14.OptionsColumn.AllowGroup = DevExpress.Utils.DefaultBoolean.False;
- this.gridColumn14.OptionsColumn.AllowSort = DevExpress.Utils.DefaultBoolean.False;
- this.gridColumn14.OptionsColumn.ReadOnly = true;
- this.gridColumn14.OptionsFilter.AllowFilter = false;
- this.gridColumn14.Visible = true;
- this.gridColumn14.VisibleIndex = 3;
- this.gridColumn14.Width = 60;
- //
- // gridColumn15
- //
- this.gridColumn15.Caption = "民族";
- this.gridColumn15.FieldName = "Nation";
- this.gridColumn15.Name = "gridColumn15";
- this.gridColumn15.OptionsColumn.AllowGroup = DevExpress.Utils.DefaultBoolean.False;
- this.gridColumn15.OptionsColumn.AllowSort = DevExpress.Utils.DefaultBoolean.False;
- this.gridColumn15.OptionsColumn.ReadOnly = true;
- this.gridColumn15.Visible = true;
- this.gridColumn15.VisibleIndex = 4;
- this.gridColumn15.Width = 100;
- //
- // gridColumn16
- //
- this.gridColumn16.Caption = "身份证号";
- this.gridColumn16.FieldName = "CardNo";
- this.gridColumn16.Name = "gridColumn16";
- this.gridColumn16.OptionsColumn.AllowGroup = DevExpress.Utils.DefaultBoolean.False;
- this.gridColumn16.OptionsColumn.AllowSort = DevExpress.Utils.DefaultBoolean.False;
- this.gridColumn16.OptionsColumn.ReadOnly = true;
- this.gridColumn16.OptionsFilter.AllowFilter = false;
- this.gridColumn16.Visible = true;
- this.gridColumn16.VisibleIndex = 5;
- this.gridColumn16.Width = 140;
- //
- // gridColumn17
- //
- this.gridColumn17.AppearanceCell.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
- this.gridColumn17.AppearanceCell.Options.UseFont = true;
- this.gridColumn17.Caption = "教育程度";
- this.gridColumn17.FieldName = "Education";
- this.gridColumn17.Name = "gridColumn17";
- this.gridColumn17.OptionsColumn.AllowEdit = false;
- this.gridColumn17.OptionsColumn.AllowGroup = DevExpress.Utils.DefaultBoolean.False;
- this.gridColumn17.OptionsColumn.AllowSort = DevExpress.Utils.DefaultBoolean.False;
- this.gridColumn17.OptionsColumn.ReadOnly = true;
- this.gridColumn17.OptionsFilter.AllowFilter = false;
- this.gridColumn17.Summary.AddRange(new DevExpress.XtraGrid.GridSummaryItem[] {
- new DevExpress.XtraGrid.GridColumnSummaryItem(DevExpress.Data.SummaryItemType.Count, "BloodCode", "合计:{0} 个血袋")});
- this.gridColumn17.Visible = true;
- this.gridColumn17.VisibleIndex = 6;
- this.gridColumn17.Width = 93;
- //
- // gridColumn19
- //
- this.gridColumn19.Caption = "联系电话";
- this.gridColumn19.FieldName = "Tel1";
- this.gridColumn19.Name = "gridColumn19";
- this.gridColumn19.OptionsColumn.AllowGroup = DevExpress.Utils.DefaultBoolean.False;
- this.gridColumn19.OptionsColumn.AllowSort = DevExpress.Utils.DefaultBoolean.False;
- this.gridColumn19.OptionsColumn.ReadOnly = true;
- this.gridColumn19.Visible = true;
- this.gridColumn19.VisibleIndex = 7;
- this.gridColumn19.Width = 100;
- //
- // gridColumn21
- //
- this.gridColumn21.Caption = "联系地址";
- this.gridColumn21.FieldName = "Address1";
- this.gridColumn21.MinWidth = 200;
- this.gridColumn21.Name = "gridColumn21";
- this.gridColumn21.OptionsColumn.AllowGroup = DevExpress.Utils.DefaultBoolean.False;
- this.gridColumn21.OptionsColumn.AllowSort = DevExpress.Utils.DefaultBoolean.False;
- this.gridColumn21.OptionsColumn.ReadOnly = true;
- this.gridColumn21.Visible = true;
- this.gridColumn21.VisibleIndex = 8;
- this.gridColumn21.Width = 300;
- //
- // gridColumn27
- //
- this.gridColumn27.Caption = "部门";
- this.gridColumn27.FieldName = "DeptName";
- this.gridColumn27.Name = "gridColumn27";
- this.gridColumn27.Visible = true;
- this.gridColumn27.VisibleIndex = 9;
- this.gridColumn27.Width = 187;
- //
// repositoryItemComboBox1
//
this.repositoryItemComboBox1.AutoHeight = false;
@@ -877,18 +755,85 @@
this.label1.Text = "导入失败列表:";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
+ // gridColumn7
+ //
+ this.gridColumn7.Caption = "A";
+ this.gridColumn7.FieldName = "ColumnA";
+ this.gridColumn7.Name = "gridColumn7";
+ this.gridColumn7.Visible = true;
+ this.gridColumn7.VisibleIndex = 1;
+ //
+ // gridColumn8
+ //
+ this.gridColumn8.Caption = "B";
+ this.gridColumn8.FieldName = "ColumnB";
+ this.gridColumn8.Name = "gridColumn8";
+ this.gridColumn8.Visible = true;
+ this.gridColumn8.VisibleIndex = 2;
+ //
+ // gridColumn14
+ //
+ this.gridColumn14.Caption = "C";
+ this.gridColumn14.FieldName = "ColumnC";
+ this.gridColumn14.Name = "gridColumn14";
+ this.gridColumn14.Visible = true;
+ this.gridColumn14.VisibleIndex = 3;
+ //
+ // gridColumn15
+ //
+ this.gridColumn15.Caption = "D";
+ this.gridColumn15.FieldName = "ColumnD";
+ this.gridColumn15.Name = "gridColumn15";
+ this.gridColumn15.Visible = true;
+ this.gridColumn15.VisibleIndex = 4;
+ //
+ // gridColumn16
+ //
+ this.gridColumn16.Caption = "E";
+ this.gridColumn16.FieldName = "ColumnE";
+ this.gridColumn16.Name = "gridColumn16";
+ this.gridColumn16.Visible = true;
+ this.gridColumn16.VisibleIndex = 5;
+ //
+ // gridColumn17
+ //
+ this.gridColumn17.Caption = "F";
+ this.gridColumn17.FieldName = "ColumnF";
+ this.gridColumn17.Name = "gridColumn17";
+ this.gridColumn17.Visible = true;
+ this.gridColumn17.VisibleIndex = 6;
+ //
+ // gridColumn19
+ //
+ this.gridColumn19.Caption = "G";
+ this.gridColumn19.FieldName = "ColumnG";
+ this.gridColumn19.Name = "gridColumn19";
+ this.gridColumn19.Visible = true;
+ this.gridColumn19.VisibleIndex = 7;
+ //
+ // gridColumn21
+ //
+ this.gridColumn21.Caption = "H";
+ this.gridColumn21.FieldName = "ColumnH";
+ this.gridColumn21.Name = "gridColumn21";
+ this.gridColumn21.Visible = true;
+ this.gridColumn21.VisibleIndex = 8;
+ //
+ // gridColumn27
+ //
+ this.gridColumn27.Caption = "I";
+ this.gridColumn27.FieldName = "ColumnI";
+ this.gridColumn27.Name = "gridColumn27";
+ this.gridColumn27.Visible = true;
+ this.gridColumn27.VisibleIndex = 9;
+ //
// gridColumn37
//
- this.gridColumn37.Caption = "失败原因";
- this.gridColumn37.FieldName = "ImportErrorInfo";
+ this.gridColumn37.Caption = "J";
+ this.gridColumn37.FieldName = "ColumnJ";
this.gridColumn37.Name = "gridColumn37";
- this.gridColumn37.OptionsColumn.AllowEdit = false;
- this.gridColumn37.OptionsColumn.AllowSort = DevExpress.Utils.DefaultBoolean.False;
- this.gridColumn37.OptionsColumn.ReadOnly = true;
- this.gridColumn37.OptionsFilter.AllowFilter = false;
this.gridColumn37.Visible = true;
this.gridColumn37.VisibleIndex = 10;
- this.gridColumn37.Width = 125;
//
// PatientImportForm
//
@@ -965,15 +910,6 @@
private DevExpress.XtraGrid.GridControl DgcError;
private DevExpress.XtraGrid.Views.Grid.GridView DgvError;
private DevExpress.XtraGrid.Columns.GridColumn colNo;
- private DevExpress.XtraGrid.Columns.GridColumn gridColumn7;
- private DevExpress.XtraGrid.Columns.GridColumn gridColumn8;
- private DevExpress.XtraGrid.Columns.GridColumn gridColumn14;
- private DevExpress.XtraGrid.Columns.GridColumn gridColumn15;
- private DevExpress.XtraGrid.Columns.GridColumn gridColumn16;
- private DevExpress.XtraGrid.Columns.GridColumn gridColumn17;
- private DevExpress.XtraGrid.Columns.GridColumn gridColumn19;
- private DevExpress.XtraGrid.Columns.GridColumn gridColumn21;
- private DevExpress.XtraGrid.Columns.GridColumn gridColumn27;
private DevExpress.XtraEditors.Repository.RepositoryItemComboBox repositoryItemComboBox1;
private DevExpress.XtraEditors.Repository.RepositoryItemComboBox repositoryItemComboBox2;
private DevExpress.XtraEditors.Repository.RepositoryItemComboBox repositoryItemComboBox3;
@@ -990,6 +926,15 @@
private DevExpress.XtraGrid.Columns.GridColumn gridColumn36;
private System.Windows.Forms.Panel panel2;
private System.Windows.Forms.Label label1;
+ private DevExpress.XtraGrid.Columns.GridColumn gridColumn7;
+ private DevExpress.XtraGrid.Columns.GridColumn gridColumn8;
+ private DevExpress.XtraGrid.Columns.GridColumn gridColumn14;
+ private DevExpress.XtraGrid.Columns.GridColumn gridColumn15;
+ private DevExpress.XtraGrid.Columns.GridColumn gridColumn16;
+ private DevExpress.XtraGrid.Columns.GridColumn gridColumn17;
+ private DevExpress.XtraGrid.Columns.GridColumn gridColumn19;
+ private DevExpress.XtraGrid.Columns.GridColumn gridColumn21;
+ private DevExpress.XtraGrid.Columns.GridColumn gridColumn27;
private DevExpress.XtraGrid.Columns.GridColumn gridColumn37;
}
}
\ No newline at end of file
diff --git a/PEIS/View/Base/PatientImportForm.cs b/PEIS/View/Base/PatientImportForm.cs
index 6cb796e..b946734 100644
--- a/PEIS/View/Base/PatientImportForm.cs
+++ b/PEIS/View/Base/PatientImportForm.cs
@@ -14,11 +14,11 @@ namespace PEIS.View.Base
{
public partial class PatientImportForm : ViewBase
{
-
protected override object CreatePresenter()
{
return new Presenter(this);
}
+
private List _lstPatient = new List();
// 定义一个委托
@@ -44,18 +44,21 @@ namespace PEIS.View.Base
private void TsmiDown_Click(object sender, EventArgs e)
{
- var file = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ReportFiles", "体检基本信息登记表.xls");
+ // var file = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ReportFiles", "体检基本信息登记表.xls");
+ var file = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ReportFiles", "医院体检人员信息收集样表.xlsx");
if (!File.Exists(file))
{
Global.MsgErr(@"未找到模板文件!");
return;
}
+
// 创建文件目标路径(用户选择的位置)
using (var folderDialog = new FolderBrowserDialog())
{
if (folderDialog.ShowDialog() != DialogResult.OK) return;
var targetFolderPath = folderDialog.SelectedPath;
- var targetFilePath = Path.Combine(targetFolderPath, "体检基本信息登记表.xls");
+ // var targetFilePath = Path.Combine(targetFolderPath, "体检基本信息登记表.xls");
+ var targetFilePath = Path.Combine(targetFolderPath, "医院体检人员信息收集样表.xlsx");
try
{
// 复制文件
@@ -83,100 +86,77 @@ namespace PEIS.View.Base
Global.MsgInfo($"数据为空,请导入数据!");
return;
}
+
int succeedCount = 0;
- var errorList = new List();
+ var errorList = new List();
_lstPatient = new List();
var createTime = DateTime.Now;
foreach (var item in _patients)
{
try
{
- var birthday = DateTime.Today;
- if (item.CardNo.Length == 18 && DateTime.TryParseExact(item.CardNo.Substring(6, 8), "yyyyMMdd", null,
- DateTimeStyles.None, out DateTime result))
- {
- birthday = result;
- }
-
- var basePatient = new BasePatient()
- {
- Name = item.Name?.Trim(),
- Sex = item.Sex == "女" ? "2" : "1",
- Nation = item.Nation,
- Birthday = birthday,
- CardType = "居民身份证",
- CardNo = item.CardNo,
- Marriage = item.Marriage,
- Occupation = item.Occupation,
- Education = item.Education,
- Contactor1 = item.Name,
- Contactor2 = item.Contactor2,
- Tel1 = item.Tel1,
- Tel2 = item.Tel2,
- Address1 = item.Address1,
- Address2 = item.Address2,
- Description = item.Description,
- CreateTime = createTime,
- Creator = Global.currentUser.Name,
- CreatorCode = Global.currentUser.Code
- };
-
+ var basePatient = item;
+ basePatient.CreateTime = createTime;
+ basePatient.Creator = Global.currentUser.Name;
+ basePatient.CreatorCode = Global.currentUser.Code;
if (!basePatient.Exits())
{
- // item.ImportErrorInfo = "身份证号已存在";
- // errorList.Add(item);
- // continue;
if (!basePatient.Save())
{
item.ImportErrorInfo = "信息保存失败";
- errorList.Add(item);
+ errorList.Add(new ExcelRowModel(item));
continue;
}
}
-
- succeedCount++;
- var sql = $@"SELECT ID,Name,Sex,CardNo, CardType, Birthday, Education, Nation, Tel1, Tel2,Marriage,Address1
+ succeedCount++;
+ var sql =
+ $@"SELECT ID,Name,Sex,CardNo, CardType, Birthday, Education, Nation, Tel1, Tel2,Marriage,Address1
FROM Base_Patient WHERE Name='{basePatient.Name}' AND CardNo = '{basePatient.CardNo}' ";
var add = (DAOHelp.GetDataBySQL(sql).FirstOrDefault());
- if (add != null)
- _lstPatient?.Add(new BaseOrgPatient
- {
- OID = _org.ID,
- PID = add.ID,
- Seq = _lstPatient.Count + 1,
- Name = add.Name,
- Sex = add.Sex == "1" ? "男" : "女",
- CardNo = add.CardNo,
- CardType = add.CardType,
- Birthday = add.Birthday,
- Education = add.Education,
- Nation = add.Nation,
- Tel1 = add.Tel1,
- Tel2 = add.Tel2,
- Marriage = add.Marriage,
- DeptName = item.DeptName,
- Address1 = add.Address1
- });
+ if (add == null)
+ {
+ errorList.Add(new ExcelRowModel(item));
+ continue;
+ }
+
+ _lstPatient?.Add(new BaseOrgPatient
+ {
+ OID = _org.ID,
+ PID = add.ID,
+ Seq = _lstPatient.Count + 1,
+ Name = add.Name,
+ Sex = add.Sex == "1" ? "男" : "女",
+ CardNo = add.CardNo,
+ CardType = add.CardType,
+ Birthday = add.Birthday,
+ Education = add.Education,
+ Nation = add.Nation,
+ Tel1 = add.Tel1,
+ Tel2 = add.Tel2,
+ Marriage = add.Marriage,
+ DeptName = item.DeptName,
+ Address1 = add.Address1
+ });
}
catch (Exception ex)
{
item.ImportErrorInfo = "错误:" + ex.Message;
- errorList.Add(item);
+ errorList.Add(new ExcelRowModel(item));
}
}
if (errorList.Count > 0)
{
- Global.MsgErr($"添加成功:{succeedCount},添加失败:{ errorList.Count}。");
+ Global.MsgErr($"添加成功:{succeedCount},添加失败:{errorList.Count}。");
DgcPatient.DataSource = null;
DgcError.DataSource = errorList;
}
else
{
- Global.MsgInfo($"添加成功!");
+ Global.MsgInfo($"添加成功:{succeedCount}!");
ImportFormClosed?.Invoke(_lstPatient);
Close();
}
@@ -191,10 +171,12 @@ FROM Base_Patient WHERE Name='{basePatient.Name}' AND CardNo = '{basePatient.Car
{
var excel = new ExcelHelper();
excel.ReadOrgPatientList();
- var list = excel.SuccessList.Where(p=>!string.IsNullOrEmpty(p.CardNo)).ToList().Distinct().ToList();
+ var list = excel.SuccessList;
_patients = list.Count > 0 ? list : new List();
+ label1.Text = "导入失败列表:" + $@"(已从Excel成功读取到 {excel.SuccessList.Count}行 数据)";
DgcPatient.DataSource = _patients;
DgcError.DataSource = excel.ErrorList.Distinct();
+ DgvError.BestFitColumns();
}
}
}
\ No newline at end of file