SVN r739
SVN-Revision: r739
This commit is contained in:
@@ -55,7 +55,7 @@ namespace Lskj.PubBomImportNew
|
||||
/// <summary>
|
||||
/// 模块编号
|
||||
/// </summary>
|
||||
public string ModelCode = "";
|
||||
public string UnionModelCode = "";
|
||||
/// <summary>
|
||||
/// 主键名
|
||||
/// </summary>
|
||||
@@ -78,7 +78,7 @@ namespace Lskj.PubBomImportNew
|
||||
{
|
||||
if (args.Length > 5 && !string.IsNullOrWhiteSpace(args[5]))
|
||||
{
|
||||
ModelCode = args[5] + "";
|
||||
UnionModelCode = args[5] + "";
|
||||
}
|
||||
if (args.Length > 6 && !string.IsNullOrWhiteSpace(args[6]))
|
||||
{
|
||||
|
||||
@@ -124,11 +124,11 @@ namespace Lskj.PubBomImportNew
|
||||
{
|
||||
this.Opacity = 1;
|
||||
int.TryParse(Model.stratRowHand + "", out FirstRowIndex);
|
||||
DataRow modelRow = MainImpl.GetSystemdllTab(Model.ModuleCode);//获取模块信息
|
||||
DataRow modelRow = MainImpl.GetSystemdllTab(Model.UnionModelCode);//获取模块信息
|
||||
if (modelRow != null)
|
||||
{
|
||||
this.SysModel = new ModuleModel(modelRow);
|
||||
InitializeControl(this.SysModel.MenuTable, this.Model.ModuleCode, _parmaryKey, this.gcMain, this.SysModel.PrefixKey, this.Model.primkey, this.Model.keyvalue, this.Model.FormText, this.SysModel.ConcatenatedPrefix);
|
||||
InitializeControl(this.SysModel.MenuTable, this.Model.UnionModelCode, _parmaryKey, this.gcMain, this.SysModel.PrefixKey, this.Model.primkey, this.Model.keyvalue, this.Model.FormText, this.SysModel.ConcatenatedPrefix);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -325,25 +325,49 @@ namespace Lskj.PubBomImportNew
|
||||
/// <param name="row"></param>
|
||||
/// <param name="fieldName"></param>
|
||||
/// <param name="text"></param>
|
||||
/// <param name="isBillImport"></param>
|
||||
/// <returns></returns>
|
||||
public string GetValueByImportText(DataRow row, string fieldName, string text, bool isBillImport = false)
|
||||
string GetValueByImportText(DataRow row, string fieldName, string text)
|
||||
{
|
||||
string value = text;
|
||||
foreach (GridColumnModel model in ValueGridColumnTable.Keys)
|
||||
foreach (GridColumnModel model in this.ValueGridColumnTable.Keys)
|
||||
{
|
||||
if (model.FieldName.Equals(fieldName, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
string selWhere = "1=1";
|
||||
DataTable table = ValueGridColumnTable[model];
|
||||
if (table != null && table.Rows.Count > 0)
|
||||
DataTable table = this.ValueGridColumnTable[model];
|
||||
if (model.FieldType == ControlType.LabMultiSelectValue || model.FieldType == ControlType.LabMultiSelectValueNew || model.FieldType == ControlType.LabMultiSelectValueParam)
|
||||
{
|
||||
DataRow rowItemValue = table.Rows.Cast<DataRow>().FirstOrDefault(x => x[model.TextMember] + "" == text);
|
||||
DataRow rowItemText = table.Rows.Cast<DataRow>().FirstOrDefault(x => x[model.ValueMember] + "" == text);
|
||||
value = rowItemValue != null ? rowItemValue[isBillImport ? model.ValueMember : model.TextMember] + "" : rowItemText != null ? rowItemText[isBillImport ? model.ValueMember : model.TextMember] + "" : "";
|
||||
string[] splitString = text.Split(',');
|
||||
string nemValue = string.Empty;
|
||||
foreach (string newText in splitString)
|
||||
{
|
||||
if (table != null && table.Rows.Count > 0)
|
||||
{
|
||||
DataRow rowItemValue = table.Rows.Cast<DataRow>().FirstOrDefault(x => x[model.TextMember] + "" == newText);
|
||||
DataRow rowItemText = table.Rows.Cast<DataRow>().FirstOrDefault(x => x[model.ValueMember] + "" == newText);
|
||||
value = rowItemValue != null ? rowItemValue[model.ValueMember] + "" : rowItemText != null ? rowItemText[model.ValueMember] + "" : "";
|
||||
}
|
||||
else
|
||||
{
|
||||
value = "";
|
||||
}
|
||||
nemValue += value + ',';
|
||||
}
|
||||
value = nemValue.TrimEnd(',');
|
||||
}
|
||||
else
|
||||
value = "";
|
||||
{
|
||||
|
||||
if (table != null && table.Rows.Count > 0)
|
||||
{
|
||||
DataRow rowItemValue = table.Rows.Cast<DataRow>().FirstOrDefault(x => x[model.TextMember] + "" == text);
|
||||
DataRow rowItemText = table.Rows.Cast<DataRow>().FirstOrDefault(x => x[model.ValueMember] + "" == text);
|
||||
value = rowItemValue != null ? rowItemValue[model.ValueMember] + "" : rowItemText != null ? rowItemText[model.ValueMember] + "" : "";
|
||||
}
|
||||
else
|
||||
value = "";
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
return value;
|
||||
@@ -535,16 +559,28 @@ namespace Lskj.PubBomImportNew
|
||||
|
||||
|
||||
|
||||
if (string.IsNullOrEmpty(this._primkey))
|
||||
{
|
||||
if (datatb.Columns.Contains(_primkey) && !string.IsNullOrWhiteSpace(_keyvalue))
|
||||
{
|
||||
if (string.IsNullOrEmpty(tmpRow[_primkey] + "") || (tmpRow[_keyvalue] + "").Equals("0"))
|
||||
{
|
||||
tmpRow[_primkey] = _keyvalue;
|
||||
}
|
||||
}
|
||||
}
|
||||
//if (this.concatenatedPrefix)
|
||||
//{
|
||||
// if (datatb.Columns.Contains(_qzKey + _leftField) && !string.IsNullOrWhiteSpace(_leftValue) && SysModel.AssociationLeft)
|
||||
// {
|
||||
// if (string.IsNullOrEmpty(tmpRow[_qzKey + _leftField] + "") || (tmpRow[_qzKey + _leftField] + "").Equals("0"))
|
||||
// {
|
||||
// tmpRow[_qzKey + _leftField] = _leftValue;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// if (datatb.Columns.Contains(_leftField) && !string.IsNullOrWhiteSpace(_leftValue) && SysModel.AssociationLeft)
|
||||
// {
|
||||
// if (string.IsNullOrEmpty(tmpRow[_qzKey + _leftField] + "") || (tmpRow[_qzKey + _leftField] + "").Equals("0"))
|
||||
// {
|
||||
// tmpRow[_qzKey + _leftField] = _leftValue;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
|
||||
foreach (GridColumn gc in gcMain.GridView.VisibleColumns)
|
||||
{
|
||||
@@ -711,141 +747,6 @@ namespace Lskj.PubBomImportNew
|
||||
*/
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:保存导入的数据</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-11-15 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
private void SaveImportData(DataTable table)
|
||||
{
|
||||
if (table != null && table.Rows.Count > 0)
|
||||
{
|
||||
if (string.IsNullOrEmpty(this._tableName))
|
||||
{
|
||||
MessageUtil.Show(ResourceKeys.MenuTableNameIsNull);
|
||||
return;
|
||||
}
|
||||
|
||||
List<BaseSaveModel> mList = new List<BaseSaveModel>();
|
||||
|
||||
GridColumnCollection gridColumns = this._gridEx.GridView.Columns;
|
||||
//DataColumnCollection columns = (this._gridEx.GridControl.DataSourceTable() as DataTable).Columns;
|
||||
foreach (DataRow row in table.Rows)
|
||||
{
|
||||
string insertSql = "insert into {0}({1}) values({2});";
|
||||
string insertFields = string.Empty;
|
||||
string insertValues = string.Empty;
|
||||
|
||||
foreach (DataColumn col in SourceColumns)
|
||||
{
|
||||
//处理表中的计算列
|
||||
if (_calcFields.IndexOf(col.ColumnName) != -1)
|
||||
continue;
|
||||
if (col.ColumnName.Equals("id", StringComparison.OrdinalIgnoreCase) || col.ColumnName.Equals(_qzKey + "id", StringComparison.OrdinalIgnoreCase))
|
||||
continue;
|
||||
if (col.ColumnName.EndsWith("operatorid", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
insertFields += col.ColumnName + ",";
|
||||
insertValues += ERPInfo.Instance.UserId + ",";
|
||||
}
|
||||
else if (col.ColumnName.EndsWith("operatename", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
insertFields += col.ColumnName + ",";
|
||||
insertValues += "'" + ERPInfo.Instance.UserName + "',";
|
||||
}
|
||||
else if (col.ColumnName.EndsWith("operatedate", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
insertFields += col.ColumnName + ",";
|
||||
insertValues += "'" + DateTime.Now + "',"; ;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (table.Columns.Contains(col.ColumnName))
|
||||
{
|
||||
string dataType = col.DataType.ToString().ToLower();
|
||||
string fieldValue = GetValueByImportText(row, col.ColumnName, row[col.ColumnName] + "");
|
||||
|
||||
if (_checkColumns.IndexOf(col.ColumnName.ToLower()) != -1)
|
||||
{
|
||||
fieldValue = fieldValue.Equals("是") ? "1" : "0";
|
||||
}
|
||||
|
||||
insertFields += col.ColumnName + ",";
|
||||
insertValues += string.IsNullOrWhiteSpace(fieldValue) && (dataType.Contains("decimal") || dataType.Contains("datetime")) ? "NULL," : "N'" + fieldValue + "',";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!string.IsNullOrEmpty(_treeColumnName) && col.ColumnName.ToLower() == _treeColumnName.ToLower())
|
||||
{
|
||||
insertFields += col.ColumnName + ",";
|
||||
insertValues += "N'" + _keyvalue + "',";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
insertFields = insertFields.TrimEnd(',');
|
||||
insertValues = insertValues.TrimEnd(',');
|
||||
|
||||
mList.Add(new BaseSaveModel()
|
||||
{
|
||||
MenuCode = _menuCode,
|
||||
TableName = _tableName,
|
||||
KeyField = _parmaryKey,
|
||||
FieldValue = row.Table.Columns.Contains(_parmaryKey) ? row[_parmaryKey] + "" : "",
|
||||
BaseSaveType = SaveType.Add,
|
||||
BaseSql = string.Format(insertSql, _tableName, insertFields, insertValues),
|
||||
row = row
|
||||
});
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// 批量保存数据
|
||||
if (BaseModuleImpl.SaveBaseGridData(mList))
|
||||
{
|
||||
table.Rows.Clear();
|
||||
MessageUtil.Show(ResourceKeys.ImportSuccess);
|
||||
}
|
||||
else
|
||||
{
|
||||
int[] records = new int[mList.Count];
|
||||
for (int i = 0; i < mList.Count; i++)
|
||||
{
|
||||
BaseSaveModel model = mList[i];
|
||||
records[i] = Convert.ToInt32(model.Success);
|
||||
if (!model.Success)
|
||||
{
|
||||
model.row["import_errormsg"] = model.FaultMsg;
|
||||
LogHelper.Instance.WriteLog(model.FaultMsg + "(" + model.BaseSql + ")", ResourceKeys.ImportFault);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 移除导入成功的数据行
|
||||
if (table.Rows.IndexOf(model.row) != -1)
|
||||
table.Rows.Remove(model.row);
|
||||
else
|
||||
MessageBox.Show(model.row[0] + "");
|
||||
}
|
||||
}
|
||||
int successCount = records.Where(x => x == 1).Count();
|
||||
int faultCount = records.Where(x => x == 0).Count();
|
||||
|
||||
MessageUtil.Show(ResourceKeys.ImportSuccess + "" + successCount + "条\r\n" + ResourceKeys.ImportFault + "" + faultCount + "条\r\n" + "具体原因请查看错误信息.");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageUtil.Show(ResourceKeys.ImportFault + "\r\n" + ex.Message);
|
||||
LogHelper.Instance.WriteError(ex);
|
||||
string Message = ErrorMessage.PromptErrorMessage(ex);
|
||||
//MessageUtil.Show(Message,ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>说明:读取Excel</para>
|
||||
@@ -864,7 +765,7 @@ namespace Lskj.PubBomImportNew
|
||||
{
|
||||
if (BaseImpl.HasExistsTable("P_SpecialImportTab"))
|
||||
{
|
||||
string searchSql = string.Format("select * from P_SpecialImportTab where moduleId = '{0}' and rightMenuName = '{1}'", Model.ModuleCode, Model.ModuleId);
|
||||
string searchSql = string.Format("select * from P_SpecialImportTab where moduleId = '{0}' and rightMenuName = '{1}'", Model.ModuleCode, Model.UnionModelCode);
|
||||
DataTable dataTable = SqlHelper.ExecuteDataTable(searchSql);
|
||||
if (dataTable == null || dataTable.Rows.Count == 0)
|
||||
{
|
||||
@@ -1366,14 +1267,14 @@ namespace Lskj.PubBomImportNew
|
||||
/// <param name="isDirectImport"></param>
|
||||
/// <param name="isBillImport"></param>
|
||||
/// <returns></returns>
|
||||
public DataTable ToExcelDataTable(string fileName, out int count, out int errorCount, bool isDirectImport = false, bool isBillImport = false)
|
||||
public DataTable ToExcelDataTable(string fileName, out int count, out int errorCount, bool isDirectImport = false)
|
||||
{
|
||||
count = 0;
|
||||
errorCount = 0;
|
||||
GridView gridView = gcMain.GridView;
|
||||
|
||||
DataTable columnsTable = new DataTable();
|
||||
string searchSql = string.Format("select * from P_SpecialImportTab where moduleId = '{0}' and rightMenuName = '{1}'", Model.ModuleCode, Model.ModuleId);
|
||||
string searchSql = string.Format("select * from P_SpecialImportTab where moduleId = '{0}' and rightMenuName = '{1}'", Model.ModuleCode, Model.UnionModelCode);
|
||||
DataTable dataTable = SqlHelper.ExecuteDataTable(searchSql);
|
||||
if (dataTable != null && dataTable.Rows.Count > 0)
|
||||
{
|
||||
@@ -1399,7 +1300,6 @@ namespace Lskj.PubBomImportNew
|
||||
}
|
||||
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;
|
||||
string fileExt = Path.GetExtension(fileName).ToLower();
|
||||
|
||||
int CurrentRow = 0;//当前行数
|
||||
@@ -1632,14 +1532,14 @@ namespace Lskj.PubBomImportNew
|
||||
))
|
||||
{
|
||||
bool isEmpty = model.CanNull;
|
||||
string fieldValue = GetValueByImportText(dataRow, col.FieldName, cell + "", isBillImport);
|
||||
string fieldValue = GetValueByImportText(dataRow, col.FieldName, cell + "");
|
||||
if ((model.FieldType == ControlType.LabMultiSelectValue ||
|
||||
model.FieldType == ControlType.LabMultiSelectValueParam) && GetCellValue(cell).Contains(","))
|
||||
{
|
||||
string[] cellText = GetCellValue(cell).Split(',');
|
||||
foreach (string cellValue in cellText)
|
||||
{
|
||||
fieldValue += GetValueByImportText(dataRow, col.FieldName, cellValue, isBillImport) + ',';
|
||||
fieldValue += GetValueByImportText(dataRow, col.FieldName, cellValue) + ',';
|
||||
}
|
||||
fieldValue = fieldValue.TrimEnd(',');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user