SVN r351
SVN-Revision: r351
This commit is contained in:
@@ -815,6 +815,17 @@ namespace Lskj.PubSpecialImport
|
||||
DataTable columnsTable = gcMain.gridControl.DataSourceTable();
|
||||
DataTable table = gridView.GridControl.DataSourceTable();
|
||||
DataTable sourceDataTable = ExcelToDatatable(fileName, Model.SheetName, FirstRowIndex);
|
||||
DataView filterDataView = new DataView(sourceDataTable);
|
||||
try
|
||||
{
|
||||
if (!string.IsNullOrEmpty(Model.ReadTableCond))
|
||||
{
|
||||
filterDataView.RowFilter = Model.ReadTableCond;
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
List<DataRow> dataRows = columnsTable.Rows.Cast<DataRow>().Where(n => !string.IsNullOrEmpty(n["excelFieldName"] + "") && !string.IsNullOrEmpty(n["clientFieldName"] + "")).ToList();
|
||||
int index = gridView is BandedGridView ? FirstRowIndex + 1 : FirstRowIndex;
|
||||
isBillImport = index == FirstRowIndex ? true : isBillImport;
|
||||
@@ -909,7 +920,7 @@ namespace Lskj.PubSpecialImport
|
||||
ToAssignment = true;
|
||||
CurrentRow = i;
|
||||
DataRow rowSource = sourceDataTable.Rows[i - startRow];
|
||||
if (!ValidateCond(condTxtEdit.Text, rowSource))
|
||||
if (!filterDataView.Cast<DataRowView>().Any(rowView => rowView.Row == rowSource) || !ValidateCond(condTxtEdit.Text, rowSource))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -980,108 +991,40 @@ namespace Lskj.PubSpecialImport
|
||||
GridColumnModel model = col.Tag as GridColumnModel;
|
||||
if (cell != null)
|
||||
{
|
||||
if (cell.CellType == CellType.Blank)
|
||||
try
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (cell.CellType == CellType.Formula)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (cell.CellType == CellType.Numeric && (cell + "").StartsWith("-"))
|
||||
{
|
||||
dataRow[col.FieldName] = cell.NumericCellValue;
|
||||
if (AutoImportCal)
|
||||
if (cell.CellType == CellType.Blank)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(model.UnionFields))
|
||||
{
|
||||
SetUnionValue(model, dataRow[col.FieldName] + "", dataRow);
|
||||
}
|
||||
SetCalcValue(model, dataRow[col.FieldName] + "", dataRow);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (cell.CellType == CellType.Numeric)
|
||||
if (cell.CellType == CellType.Numeric && (cell + "").StartsWith("-"))
|
||||
{
|
||||
|
||||
//GridColumnModel model = col.Tag as GridColumnModel;
|
||||
if (model != null && isDirectImport && (model.FieldType == ControlType.LabDate ||
|
||||
model.FieldType == ControlType.LabDateTime ||
|
||||
model.FieldType == ControlType.LabDateTimeShort ||
|
||||
model.FieldType == ControlType.LabTime ||
|
||||
model.FieldType == ControlType.LabShortTime))
|
||||
dataRow[col.FieldName] = cell.NumericCellValue;
|
||||
if (AutoImportCal)
|
||||
{
|
||||
string fieldValue = ToDateTimeValue(cell.NumericCellValue + "");
|
||||
if (fieldValue != "")
|
||||
if (!string.IsNullOrEmpty(model.UnionFields))
|
||||
{
|
||||
dataRow[col.FieldName] = Convert.ToDateTime(fieldValue);
|
||||
if (AutoImportCal)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(model.UnionFields))
|
||||
{
|
||||
SetUnionValue(model, dataRow[col.FieldName] + "", dataRow);
|
||||
}
|
||||
SetCalcValue(model, dataRow[col.FieldName] + "", dataRow);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dataRow[col.FieldName] = cell.NumericCellValue;
|
||||
if (AutoImportCal)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(model.UnionFields))
|
||||
{
|
||||
SetUnionValue(model, dataRow[col.FieldName] + "", dataRow);
|
||||
}
|
||||
SetCalcValue(model, dataRow[col.FieldName] + "", dataRow);
|
||||
SetUnionValue(model, dataRow[col.FieldName] + "", dataRow);
|
||||
}
|
||||
SetCalcValue(model, dataRow[col.FieldName] + "", dataRow);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//GridColumnModel model = col.Tag as GridColumnModel;
|
||||
if (model != null && isDirectImport && (model.FieldType == ControlType.LabTreeType ||
|
||||
model.FieldType == ControlType.LabComboxValue ||
|
||||
model.FieldType == ControlType.LabComboxValueParam ||
|
||||
model.FieldType == ControlType.LabAutoCompleteValue ||
|
||||
model.FieldType == ControlType.LabAutoCompleteValueParam ||
|
||||
model.FieldType == ControlType.LabMultiSelectValue ||
|
||||
model.FieldType == ControlType.LabMultiSelectValueParam
|
||||
|| model.FieldType == ControlType.LabTreeLookValue
|
||||
))
|
||||
if (cell.CellType == CellType.Numeric)
|
||||
{
|
||||
bool isEmpty = model.CanNull;
|
||||
string fieldValue = GetValueByImportText(dataRow, col.FieldName, cell + "", isBillImport);
|
||||
if ((model.FieldType == ControlType.LabMultiSelectValue ||
|
||||
model.FieldType == ControlType.LabMultiSelectValueParam) && GetCellValue(cell).Contains(","))
|
||||
|
||||
//GridColumnModel model = col.Tag as GridColumnModel;
|
||||
if (model != null && isDirectImport && (model.FieldType == ControlType.LabDate ||
|
||||
model.FieldType == ControlType.LabDateTime ||
|
||||
model.FieldType == ControlType.LabDateTimeShort ||
|
||||
model.FieldType == ControlType.LabTime ||
|
||||
model.FieldType == ControlType.LabShortTime))
|
||||
{
|
||||
string[] cellText = GetCellValue(cell).Split(',');
|
||||
foreach (string cellValue in cellText)
|
||||
string fieldValue = ToDateTimeValue(cell.NumericCellValue + "");
|
||||
if (fieldValue != "")
|
||||
{
|
||||
fieldValue += GetValueByImportText(dataRow, col.FieldName, cellValue, isBillImport) + ',';
|
||||
}
|
||||
fieldValue = fieldValue.TrimEnd(',');
|
||||
}
|
||||
if (string.IsNullOrEmpty(fieldValue))
|
||||
{
|
||||
if (isEmpty)
|
||||
{
|
||||
MessageUtil.Show("该列不允许为空->" + col.Caption + "");
|
||||
}
|
||||
else
|
||||
{
|
||||
GridColumn column = gridView.Columns[col.FieldName];
|
||||
if (column.ColumnType.Name.ToLower().IndexOf("int") >= 0)
|
||||
if (column.ColumnType.Name.ToLower() == "string")
|
||||
dataRow[col.FieldName] = "";
|
||||
if (column.ColumnType.Name.ToLower().IndexOf("char") >= 0)
|
||||
dataRow[col.FieldName] = "";
|
||||
if (column.ColumnType.Name.ToLower().IndexOf("int") >= 0)
|
||||
dataRow[col.FieldName] = 0;
|
||||
if (column.ColumnType.Name.ToLower() == "decimal")
|
||||
dataRow[col.FieldName] = 0;
|
||||
dataRow[col.FieldName] = Convert.ToDateTime(fieldValue);
|
||||
if (AutoImportCal)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(model.UnionFields))
|
||||
@@ -1094,7 +1037,7 @@ namespace Lskj.PubSpecialImport
|
||||
}
|
||||
else
|
||||
{
|
||||
dataRow[col.FieldName] = fieldValue;
|
||||
dataRow[col.FieldName] = cell.NumericCellValue;
|
||||
if (AutoImportCal)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(model.UnionFields))
|
||||
@@ -1107,52 +1050,123 @@ namespace Lskj.PubSpecialImport
|
||||
}
|
||||
else
|
||||
{
|
||||
IRichTextString richTextString = (IRichTextString)cell.RichStringCellValue;
|
||||
if (fileExt == ".xlsx")
|
||||
//GridColumnModel model = col.Tag as GridColumnModel;
|
||||
if (model != null && isDirectImport && (model.FieldType == ControlType.LabTreeType ||
|
||||
model.FieldType == ControlType.LabComboxValue ||
|
||||
model.FieldType == ControlType.LabComboxValueParam ||
|
||||
model.FieldType == ControlType.LabAutoCompleteValue ||
|
||||
model.FieldType == ControlType.LabAutoCompleteValueParam ||
|
||||
model.FieldType == ControlType.LabMultiSelectValue ||
|
||||
model.FieldType == ControlType.LabMultiSelectValueParam
|
||||
|| model.FieldType == ControlType.LabTreeLookValue
|
||||
))
|
||||
{
|
||||
cell.SetCellValue(richTextString);
|
||||
}
|
||||
else if (fileExt == ".xls")
|
||||
{
|
||||
string cellValue = string.Empty;
|
||||
for (int m = 0; m < richTextString.Length; m++)
|
||||
bool isEmpty = model.CanNull;
|
||||
string fieldValue = GetValueByImportText(dataRow, col.FieldName, cell + "", isBillImport);
|
||||
if ((model.FieldType == ControlType.LabMultiSelectValue ||
|
||||
model.FieldType == ControlType.LabMultiSelectValueParam) && GetCellValue(cell).Contains(","))
|
||||
{
|
||||
|
||||
//string aaa = richTextString.String.Substring(m , 1);
|
||||
//short aaa = richTextString.GetFontAtIndex(m);
|
||||
IFont font = sheet.Workbook.GetFontAt(richTextString.GetFontAtIndex(m));//richTextString.GetFontAtIndex(m)
|
||||
|
||||
string str = string.Empty;
|
||||
string code = richTextString.ToString().Substring(m, 1);
|
||||
switch (font.TypeOffset)
|
||||
string[] cellText = GetCellValue(cell).Split(',');
|
||||
foreach (string cellValue in cellText)
|
||||
{
|
||||
case FontSuperScript.Sub:
|
||||
str = ChemistryHelper.GetSubChar(code);
|
||||
break;
|
||||
|
||||
case FontSuperScript.Super:
|
||||
str = ChemistryHelper.GetSuperChar(code);
|
||||
break;
|
||||
default:
|
||||
str = code;
|
||||
break;
|
||||
fieldValue += GetValueByImportText(dataRow, col.FieldName, cellValue, isBillImport) + ',';
|
||||
}
|
||||
cellValue = cellValue + str;
|
||||
fieldValue = fieldValue.TrimEnd(',');
|
||||
}
|
||||
cell.SetCellValue(cellValue);
|
||||
}
|
||||
dataRow[col.FieldName] = GetCellValue(cell);
|
||||
if (AutoImportCal)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(model.UnionFields))
|
||||
if (string.IsNullOrEmpty(fieldValue))
|
||||
{
|
||||
SetUnionValue(model, dataRow[col.FieldName] + "", dataRow);
|
||||
if (isEmpty)
|
||||
{
|
||||
MessageUtil.Show("该列不允许为空->" + col.Caption + "");
|
||||
}
|
||||
else
|
||||
{
|
||||
GridColumn column = gridView.Columns[col.FieldName];
|
||||
if (column.ColumnType.Name.ToLower().IndexOf("int") >= 0)
|
||||
if (column.ColumnType.Name.ToLower() == "string")
|
||||
dataRow[col.FieldName] = "";
|
||||
if (column.ColumnType.Name.ToLower().IndexOf("char") >= 0)
|
||||
dataRow[col.FieldName] = "";
|
||||
if (column.ColumnType.Name.ToLower().IndexOf("int") >= 0)
|
||||
dataRow[col.FieldName] = 0;
|
||||
if (column.ColumnType.Name.ToLower() == "decimal")
|
||||
dataRow[col.FieldName] = 0;
|
||||
if (AutoImportCal)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(model.UnionFields))
|
||||
{
|
||||
SetUnionValue(model, dataRow[col.FieldName] + "", dataRow);
|
||||
}
|
||||
SetCalcValue(model, dataRow[col.FieldName] + "", dataRow);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dataRow[col.FieldName] = fieldValue;
|
||||
if (AutoImportCal)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(model.UnionFields))
|
||||
{
|
||||
SetUnionValue(model, dataRow[col.FieldName] + "", dataRow);
|
||||
}
|
||||
SetCalcValue(model, dataRow[col.FieldName] + "", dataRow);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
IRichTextString richTextString = (IRichTextString)cell.RichStringCellValue;
|
||||
if (fileExt == ".xlsx")
|
||||
{
|
||||
cell.SetCellValue(richTextString);
|
||||
}
|
||||
else if (fileExt == ".xls")
|
||||
{
|
||||
string cellValue = string.Empty;
|
||||
for (int m = 0; m < richTextString.Length; m++)
|
||||
{
|
||||
|
||||
//string aaa = richTextString.String.Substring(m , 1);
|
||||
//short aaa = richTextString.GetFontAtIndex(m);
|
||||
IFont font = sheet.Workbook.GetFontAt(richTextString.GetFontAtIndex(m));//richTextString.GetFontAtIndex(m)
|
||||
|
||||
string str = string.Empty;
|
||||
string code = richTextString.ToString().Substring(m, 1);
|
||||
switch (font.TypeOffset)
|
||||
{
|
||||
case FontSuperScript.Sub:
|
||||
str = ChemistryHelper.GetSubChar(code);
|
||||
break;
|
||||
|
||||
case FontSuperScript.Super:
|
||||
str = ChemistryHelper.GetSuperChar(code);
|
||||
break;
|
||||
default:
|
||||
str = code;
|
||||
break;
|
||||
}
|
||||
cellValue = cellValue + str;
|
||||
}
|
||||
cell.SetCellValue(cellValue);
|
||||
}
|
||||
dataRow[col.FieldName] = GetCellValue(cell);
|
||||
if (AutoImportCal)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(model.UnionFields))
|
||||
{
|
||||
SetUnionValue(model, dataRow[col.FieldName] + "", dataRow);
|
||||
}
|
||||
SetCalcValue(model, dataRow[col.FieldName] + "", dataRow);
|
||||
}
|
||||
SetCalcValue(model, dataRow[col.FieldName] + "", dataRow);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!string.IsNullOrEmpty(specialFieldName) && dataRow.Table.Columns.Contains(specialFieldName))
|
||||
|
||||
Reference in New Issue
Block a user