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 继承函数 /// /// 单元格数据格式化 /// /// 表字典 /// 这行excel数据 /// 该单元格字典对象 /// 存储excel 的列 和对应索引 /// protected override object CustomFormatColnum(List dictList, IRow excelRow, BAS_EXCELIMPORTDICT dictModel, Dictionary excelDic) { object obj = new object(); return obj; } /// /// 获取错误的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; } #endregion #region 其他处理函数 /// /// 验证 这条数据是否符合条件 /// /// 错误信息 /// 行数据 /// 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; } /// /// 获取正确的电话号码 /// /// private string GetTruePhone(List dictList, IRow excelRow, Dictionary 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; } /// /// 获取交易商代码 /// /// /// /// 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 } }