ComplianceServer/oldcode/WebHelper/ExcelImport/QH/Qh_CustomerPositionsUploadT...

128 lines
4.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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
/// <summary>
/// 获取错误的datable数据(续子类重写)
/// </summary>
/// <param name="tab">错误数据的Datatable如果没有(Datatable.Count=0 和message="" 和 errMsg.Count==0)=>数据验证通过</param>
/// <param name="message">自定义的提示信息</param>
/// <param name="errMsg">报错信息</param>
/// <returns></returns>
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;
}
/// <summary>
/// 单元格数据格式化
/// </summary>
/// <param name="dictList">表字典</param>
/// <param name="excelRow">这行excel数据</param>
/// <param name="dictModel">该单元格字典对象</param>
/// <param name="dictModel">存储excel 的列 和对应索引</param>
/// <returns></returns>
protected override object CustomFormatColnum(List<BAS_EXCELIMPORTDICT> dictList, IRow excelRow, BAS_EXCELIMPORTDICT dictModel, Dictionary<string, int> excelDic)
{
object obj = new object();
if (dictModel.DB_COLNAME == "TRADECODE")//--交易商代码
{
obj = GetTradcode(excelRow, dictModel);
}
return obj;
}
/// <summary>
/// 获取 form表单数据
/// </summary>
/// <param name="Request">request对象</param>
/// <param name="dictModel">该单元格字段对象</param>
/// <returns></returns>
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
/// <summary>
/// 验证 这条数据是否符合条件
/// </summary>
/// <param name="errMsg">错误信息</param>
/// <param name="row">行数据</param>
/// <returns></returns>
protected bool CheckCellData(ref ValidationErrors errMsg, DataRow row)
{
bool result = true;
//if (row["TRADECODE"].ToString() == "")
//{
// result = false;
//}
return result;
}
/// <summary>
/// 获取交易商代码
/// </summary>
/// <param name="excelRow"></param>
/// <param name="dictModel"></param>
/// <returns></returns>
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
}
}