TG.WXCRM.V4/WebHelper/ExcelImport/QH/Qh_DiscrepancyGoldUploadToo...

146 lines
5.0 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.Linq;
using WX.CRM.Common;
using WX.CRM.Model.Entity;
using WX.CRM.Model.Enum;
namespace WX.CRM.WebHelper.ExcelImport.QH
{
public class Qh_DiscrepancyGoldUploadTool : ComUploadTool
{
#region method
public override EnumExcelDataType ExcelDataType { get { return EnumExcelDataType.Qh_DiscrepancyGold; } }
#endregion
#region
/// <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();
return obj;
}
/// <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;
}
#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["RESID"].ToString() == "")
//{
// result = false;
//}
//if (row["TRADECODE"].ToString() == "")
//{
// result = false;
//}
//if (row["NUMBER_LAST4"].ToString() == "")
//{
// result = false;
//}
//if (Convert.ToInt32(row["COMMISSIONRATE"]) == 0)
//{
// result = false;
//}
//if (row["SCHEDULESTATUS"] != DBNull.Value && Convert.ToInt32(row["SCHEDULESTATUS"]) == 0)
//{
// result = false;
//}
return result;
}
/// <summary>
/// 获取正确的电话号码
/// </summary>
/// <returns></returns>
private string GetTruePhone(List<BAS_EXCELIMPORTDICT> dictList, IRow excelRow, Dictionary<string, int> excelDic)
{
string temp = "";
BAS_EXCELIMPORTDICT entry = dictList.FirstOrDefault(m => m.EXCEL_COLNAME == "手机号码");
temp = entry != null ? excelRow.Cells[entry.ColumnIndex].ToString().Trim() : "";
temp = temp.Replace("T", "").Replace("'", "");//--去除"T"和"'"
bool result = Utility.ChekMobile(temp);
if (!result)// 取电话号码
{
if (excelDic.ContainsKey("联系电话"))
{
temp = excelRow.Cells[excelDic["联系电话"]].ToString().Trim();
}
temp = temp.Replace("T", "").Replace("'", "");//--去除"T"和"'"
result = Utility.ChekMobile(temp);
}
temp = result ? temp : "";
return temp;
}
/// <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
}
}