using NPOI.SS.UserModel;
using System.Collections.Generic;
using System.Data;
using System.Web;
using WX.CRM.Common;
using WX.CRM.Model.Entity;
using WX.CRM.Model.Enum;
namespace WX.CRM.WebHelper.ExcelImport.QH
{
public class Qh_CustomerPositionsUploadTool : ComUploadTool
{
#region method
public override EnumExcelDataType ExcelDataType { get { return EnumExcelDataType.Qh_CustomerPositions; } }
#endregion
#region 继承函数
///
/// 获取错误的datable数据(续子类重写)
///
/// 错误数据的Datatable,如果没有(Datatable.Count=0 和message="" 和 errMsg.Count==0)=>数据验证通过
/// 自定义的提示信息
/// 报错信息
///
protected override DataTable CheckErroDataTable(DataTable tab, out string message, ref ValidationErrors errMsg)
{
DataTable errTab = tab.Clone();
message = string.Empty;
//营业部样本验证
if (!DeptTradeCodeCheck(ref message, tab))
{
return null;
}
foreach (DataRow row in tab.Rows)
{
if (!CheckCellData(ref errMsg, row))
{
errTab.ImportRow(row);
}
}
return errTab;
}
///
/// 单元格数据格式化
///
/// 表字典
/// 这行excel数据
/// 该单元格字典对象
/// 存储excel 的列 和对应索引
///
protected override object CustomFormatColnum(List dictList, IRow excelRow, BAS_EXCELIMPORTDICT dictModel, Dictionary excelDic)
{
object obj = new object();
if (dictModel.DB_COLNAME == "TRADECODE")//--交易商代码
{
obj = GetTradcode(excelRow, dictModel);
}
return obj;
}
///
/// 获取 form表单数据
///
/// request对象
/// 该单元格字段对象
///
public override object FormDataFormat(HttpRequestBase Request, BAS_EXCELIMPORTDICT dictModel)
{
object obj = new object();
if (dictModel.DB_COLNAME == "EXPORTTIME")//--交易商代码
{
obj = Request.Form["txtExportTime"];
}
return obj;
}
#endregion
#region 其他处理函数
///
/// 验证 这条数据是否符合条件
///
/// 错误信息
/// 行数据
///
protected bool CheckCellData(ref ValidationErrors errMsg, DataRow row)
{
bool result = true;
//if (row["TRADECODE"].ToString() == "")
//{
// result = false;
//}
return result;
}
///
/// 获取交易商代码
///
///
///
///
private string GetTradcode(IRow excelRow, BAS_EXCELIMPORTDICT dictModel)
{
string obj = "";
string temp = excelRow.Cells[dictModel.ColumnIndex].ToString().Trim();
if (temp.Length < 8 || temp.Length > 9)
obj = "";
else if (temp.Length == 9)
{
obj = temp;
}
else if (temp.Length == 8)
{
if (temp.IndexOf("45") == 0)
obj = "0" + temp;
else
obj = "";
}
return obj;
}
#endregion
}
}