174 lines
6.7 KiB
C#
174 lines
6.7 KiB
C#
using System;
|
|
using System.Data;
|
|
using WX.CRM.BLL.Base;
|
|
using WX.CRM.Common;
|
|
using WX.CRM.DAL.Util;
|
|
using WX.CRM.IBLL.Util;
|
|
|
|
namespace WX.CRM.BLL.Util
|
|
{
|
|
public class ExcelImport_BL : IExcelImport
|
|
{
|
|
ExcelImport_DAL dal = new ExcelImport_DAL();
|
|
CACHE_BL cacheBiz = new CACHE_BL();
|
|
BAS_EXCELIMPORTLOG_BL excelLog = new BAS_EXCELIMPORTLOG_BL();
|
|
/// <summary>
|
|
///现货excel导入的datable批量导入数据
|
|
/// </summary>
|
|
/// <param name="erros">错误信息</param>
|
|
/// <param name="tableName">表名称</param>
|
|
/// <param name="dataTable">dataTable数据源</param>
|
|
/// <returns>是否成功</returns>
|
|
public bool FxhOracleBulkInsert(ref ValidationErrors erros, string tableName, decimal importId, DataTable tab)
|
|
{
|
|
bool result = true;
|
|
SEQUENCES_BL bl = new SEQUENCES_BL();
|
|
try
|
|
{
|
|
//-------------------移除影藏列------------------------
|
|
DateTime time1 = DateTime.Now;
|
|
//List<string> delHiddenColumn = new List<string>();
|
|
//foreach (DataColumn column in tab.Columns)
|
|
//{
|
|
// if (column.ColumnName.IndexOf("HIDDEN_") > -1)
|
|
// {
|
|
// delHiddenColumn.Add(column.ColumnName);
|
|
// }
|
|
//}
|
|
//foreach (string columnName in delHiddenColumn)
|
|
//{
|
|
// tab.Columns.Remove(columnName);
|
|
//}
|
|
//--------------------end---------------------------
|
|
|
|
bool containPKID = tab.Columns.Contains("PKID");
|
|
bool containIMPORTID = tab.Columns.Contains("IMPORTID");
|
|
//bool containCTIME = tab.Columns.Contains("CTIME");
|
|
//bool containTradeNo = tab.Columns.Contains("TRADENO");
|
|
//创建 公共有的列 然后赋值
|
|
if (!containPKID)
|
|
{
|
|
DataColumn column = new DataColumn("PKID");
|
|
column.Caption = "PKID";
|
|
column.DataType = typeof(System.Decimal);
|
|
tab.Columns.Add(column);
|
|
}
|
|
if (!containIMPORTID)
|
|
{
|
|
DataColumn column2 = new DataColumn("IMPORTID");
|
|
column2.Caption = "IMPORTID";
|
|
column2.DataType = typeof(System.Decimal);
|
|
tab.Columns.Add(column2);
|
|
}
|
|
//if (!containCTIME)
|
|
//{
|
|
// DataColumn column3 = new DataColumn("CTIME");
|
|
// column3.Caption = "创建时间";
|
|
// column3.DataType = typeof(System.DateTime);
|
|
// tab.Columns.Add(column3);
|
|
//}
|
|
//if (tableName == "GJS_IMPORTTRANSACTIONDETAIL" && !containTradeNo)
|
|
//{
|
|
// DataColumn column4 = new DataColumn("TRADENO");
|
|
// column4.Caption = "创建时间";
|
|
// column4.DataType = typeof(System.Decimal);
|
|
// tab.Columns.Add(column4);
|
|
//}
|
|
if (!(containPKID && containIMPORTID))
|
|
{
|
|
foreach (DataRow row in tab.Rows)
|
|
{
|
|
if (!containPKID)
|
|
row["IMPORTID"] = importId;
|
|
if (!containIMPORTID)
|
|
{
|
|
row["PKID"] = bl.Seq_base_get(Model.Enum.PKIDType.LargeTable);
|
|
//if (tableName == "GJS_IMPORTTRANSACTIONDETAIL" && !containTradeNo)
|
|
//{
|
|
// row["TRADENO"] = pkid;
|
|
//}
|
|
}
|
|
//if (!containCTIME)
|
|
// row["CTIME"] = DateTime.Now;
|
|
}
|
|
}
|
|
if (!containPKID)//设置主键验证
|
|
{
|
|
DataColumn[] cols = new DataColumn[] { tab.Columns["PKID"] };
|
|
tab.PrimaryKey = cols;
|
|
}
|
|
|
|
new OracleBulk_DAL().OracleBulkInsert(tableName, tab);
|
|
excelLog.UpdateDateTime(DateTime.Now - time1, importId, 1);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
result = false;
|
|
erros.Add(ex.ToString());
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 计算导入数据操作
|
|
/// </summary>
|
|
/// <param name="erros">错误信息</param>
|
|
/// <param name="type">类型</param>
|
|
/// <param name="importId">导入批次ID</param>
|
|
/// <returns></returns>
|
|
public bool ComputeColnumBeforeGen(ref ValidationErrors erros, Model.Enum.EnumExcelDataType type, decimal importId)
|
|
{
|
|
bool result = true;
|
|
try
|
|
{
|
|
DateTime time1 = DateTime.Now;
|
|
string companyCode = cacheBiz.GetValue_Parameter(Model.Enum.Parameter.Sys_Environment_DeptCode);
|
|
dal.ComputeColnumBeforeGen(type, importId, companyCode);
|
|
DateTime time2 = DateTime.Now;
|
|
excelLog.UpdateDateTime(time2 - time1, importId, 2);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
result = false;
|
|
erros.Add(ex.ToString());
|
|
}
|
|
return result;
|
|
}
|
|
/// <summary>
|
|
/// 生成业务表操作
|
|
/// </summary>
|
|
/// <param name="erros">错误信息</param>
|
|
/// <param name="type">类型</param>
|
|
/// <param name="importId">导入批次ID</param>
|
|
/// <returns></returns>
|
|
public bool GenerateBusinessData(ref ValidationErrors erros, Model.Enum.EnumExcelDataType type, decimal importId)
|
|
{
|
|
bool result = true;
|
|
try
|
|
{
|
|
DateTime time1 = DateTime.Now;
|
|
string companyCode = cacheBiz.GetValue_Parameter(Model.Enum.Parameter.Sys_Environment_DeptCode);
|
|
dal.GenerateBusinessData(type, importId, companyCode);
|
|
DateTime time2 = DateTime.Now;
|
|
excelLog.UpdateDateTime(time2 - time1, importId, 3);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
result = false;
|
|
erros.Add(ex.ToString());
|
|
}
|
|
return result;
|
|
}
|
|
|
|
public void GenDataTable(string tableName, string excelColumn)
|
|
{
|
|
dal.GenDataTable(tableName, excelColumn);
|
|
}
|
|
|
|
public void BackDataTable(string tableOldName, string tableNewName)
|
|
{
|
|
dal.BackDataTable(tableOldName, tableNewName);
|
|
}
|
|
}
|
|
}
|