前提:该机构录入的都是和该机构有关的数据,机构下的funmental(idcard唯一)和creditinfo(funmentalid唯一)不能重复所以推出以下结论:
1.根据userid(机构)=》allfunmental 和 allInfo
2.标示唯一 funmetal以idcard allinfo以funmentalid,所以做出对应的字典allfdic allinfodic
3.if(allfdic.containskey(idcard))取出该数据 funmental,为字典重新赋值(在保存之前就重新赋值因为是引用类型,反之info也一样),然后标记为脏数据,如果不存在则new 出一个funmental,加入字典不管 三七二十一给他们赋值,最后saveorupdate funmental

4.info表的保存
creditinfo=null;
if(allinfodic.containskey(funmetalid))从字典取出该数据,然后重新赋值(引用类型结论和前面的一样),如果字典里没有加入字典,
然后为creditinfo.funmentalid=funmental.id 之后不管三七二十一saveorupdate

private void Import()
{
QueryInfo info=new QueryInfo("SysDict");
info.AddParam("TypeCode","SECTOR_TYPE");
List<SysDict> IndustryDic = Holworth.Utility.Utility.ListToT<SysDict>(Dao.FindList(info)).ToList();
var dics = (from s in IndustryDic select s).ToDictionary(x => x.Name);
StringBuilder sbError = new StringBuilder();
if (string.IsNullOrEmpty(fileup.FileName))
{
ScriptHelper.MessageBox(false, "不能上传空文件。", 0);
return;
}
string excelName = fileup.FileName;
string fileName = Server.MapPath("~/upload/" + excelName);
this.fileup.SaveAs(fileName);
List<CcrPersonalFundamental> fundamentals = new List<CcrPersonalFundamental>();
List<CcrPersonalCreditInfo> creditInfos=new List<CcrPersonalCreditInfo>();
string sql = "begin\n" ;
DataSet ds = new DataSet();
DataTable dt = new DataTable();
ds = ExcelHelper.ReadExcelAllSheets(fileName, 0, false);
dt = ds.Tables[0];
QueryInfo allfunInfo = new QueryInfo("CcrPersonalFundamental");
allfunInfo.AddParam("UserId", int.Parse(CurrentUser.UserId));
var allf =
Holworth.Utility.Utility.ListToT<CcrPersonalFundamental>(
Dao.FindList(allfunInfo)).ToList();
var allfDic = (from s in allf select s).ToDictionary(x => x.IdCard);

// info dic
QueryInfo allCreditInfoDic = new QueryInfo("CcrPersonalCreditInfo");
allCreditInfoDic.AddParam("UserId", int.Parse(CurrentUser.UserId));
var allInfo =
Holworth.Utility.Utility.ListToT<CcrPersonalCreditInfo>(
Dao.FindList(allCreditInfoDic)).ToList();
var allInfoDic = (from s in allInfo select s).ToDictionary(x => x.FundamentalId);

//
for (int i = 0; i < dt.Rows.Count; i++)
{
DataRow row = dt.Rows[i];
var idcard = row[0].ToString().Trim().ToUpper().Trim();
var findf = false;
CcrPersonalFundamental fundamental = null;
if (allfDic.ContainsKey(idcard))
{
findf = true;
fundamental = allfDic[idcard];
fundamental.State.MarkDirty();

}
else
{
fundamental = new CcrPersonalFundamental();
findf = false;
fundamental.State.MarkNew();

}

CcrPersonalCreditInfo creditInfo=null;
fundamental.IdCard = idcard;
fundamental.Marriage = row[7].ToString().Trim();
fundamental.PersonalName = row[1].ToString().Trim();

fundamental.Address = row[8].ToString().Trim();
fundamental.MobilePhone = row[2].ToString().Trim();
fundamental.Industry = dics[row[9].ToString().Trim()].Code;

fundamental.Sex = row[3].ToString().Trim();
fundamental.CompanySize = row[10].ToString().Trim();
fundamental.Birthday = DateTime.Parse(row[4].ToString().Trim());

fundamental.Position = row[11].ToString().Trim();
fundamental.Education = row[5].ToString().Trim();
fundamental.MonthlyIncome =row[12].ToString().Trim();
fundamental.School = row[6].ToString().Trim();
fundamental.UserId = int.Parse(CurrentUser.UserId);
//通过判断身份证IdCard和机构账号UserId判断是否新纪录,新纪录插入,旧记录更新,还要判断信息是否完整
//QueryInfo histroyFundamentalInfo=new QueryInfo();
//histroyFundamentalInfo.QueryObject = "CcrPersonalFundamental";
//histroyFundamentalInfo.AddParam("UserId",int.Parse(CurrentUser.UserId));
//histroyFundamentalInfo.AddParam("IdCard",fundamental.IdCard);

// List<CcrPersonalFundamental> historyFundamentalList = Holworth.Utility.Utility.ListToT<CcrPersonalFundamental>(Dao.FindList(histroyFundamentalInfo)).ToList();
//如果已经存在这个机构下的身份证,则更新改数据

Dao.SaveOrUpdate(fundamental);
//CcrPersonalFundamental importFundamental=Dao.SaveOrUpdate(fundamental) as CcrPersonalFundamental;
if (!findf)
{
allfDic.Add(idcard, fundamental);
}
else
{
allfDic[idcard] = fundamental;
}
//通过上一步的身份证IdCard和机构账号UserId查询出funmentalId,再根据当前的UserId,判断这个funmetal是否存在如果存在判断info表里的userid和funmetalid是否已经存在更新,不存在新增

var findC = false;
if (allInfoDic.ContainsKey(fundamental.Id))
{
findC = true;
creditInfo = allInfoDic[fundamental.Id];

creditInfo.State.MarkDirty();

}
else
{
creditInfo = new CcrPersonalCreditInfo();
findC = false;
creditInfo.State.MarkNew();
}

creditInfo.PresentResidenceSince = row[23].ToString().Trim();
creditInfo.AccountStatus = row[14].ToString().Trim();
creditInfo.Propety = row[24].ToString().Trim();
creditInfo.DurationInMonth =row[15].ToString().Trim();
creditInfo.AgeInYear =row[25].ToString().Trim();
creditInfo.CreditHistory = row[13].ToString().Trim();
creditInfo.OtherInstallmentPlans =row[26].ToString().Trim();
creditInfo.Purpose = row[16].ToString().Trim();
creditInfo.Hounsing = row[27].ToString().Trim();
creditInfo.CreditAmount =row[17].ToString().Trim();
creditInfo.NumberOfCreditcard =row[28].ToString().Trim();
creditInfo.SavingsAccount = row[18].ToString().Trim();
creditInfo.Job =row[29].ToString().Trim();
creditInfo.PresentEmploymentSince = row[19].ToString().Trim();
creditInfo.NumberOfPeopleSupport = row[30].ToString().Trim();
creditInfo.DisposableIncome = row[20].ToString().Trim();
creditInfo.Telphone = row[31].ToString().Trim();
creditInfo.PersonalStatusAndSex =row[21].ToString().Trim();
creditInfo.ForeignWorkder = row[32].ToString().Trim();
creditInfo.OtherGuarantor = row[22].ToString().Trim();
creditInfo.UserId = int.Parse(CurrentUser.UserId);
creditInfo.CreditRate = row[33].ToString().Trim();
creditInfo.Usage = "train";

if ( !findC)
{
creditInfo.FundamentalId = fundamental.Id;
}

var obj = Dao.SaveOrUpdate(creditInfo);
if (!findC)
{
allInfoDic.Add(creditInfo.FundamentalId,creditInfo);
}

}

System.IO.File.Delete(fileName);

//记录日志 成功几条 失败几条
Contract.Domain.EtlLog log = new EtlLog();
log.TableName = "ccr_personal_fundamental,ccr_personal_credit_info";
log.CreateUname = CurrentUser.UserName;
log.Status = "插入成功";
log.FileName = fileName;
log.Remark = string.Format("共导入{0}条", creditInfos.Count);
if (dt.Rows.Count -1- creditInfos.Count > 0)
log.Remark += string.Format("失败{0}条因为{1}", dt.Rows.Count - 1 - creditInfos.Count, sbError.ToString() + "\n");
log.CreateDate = DateTime.Now;
log.State.MarkNew();
Dao.SaveOrUpdate(log);
Page.ClientScript.RegisterClientScriptBlock(JSUtil.CurrentPage.GetType(), Util.NewGuid(), @"<script>$.messager.alert('操作提示', '导入成功', 'info', function () {
artDialog.open.origin.JDataGrid.GridSearch();
artDialog.close();
});</script>");

}

excel判断新增使用字典作为页面级数据库,减少io的更多相关文章

  1. js 获取当前焦点所在的元素、给元素和input控件添加键盘监听事件、添加页面级的键盘监听事件

    页面级的键盘监听事件 document.onkeydown = function (event) { var e = event || window.event || arguments.callee ...

  2. 不同浏览器对document.documentElement和document.body的scrollheight ,scrollTop,clientHeight以及判断滚动条是否滚动到页面最底部 【转载】

    前段时间学习怎么写一个瀑布流的时候,就接触到document.documentElement和document.body的区别,然后今天查资料的时候看到这篇博客,遂转载记录在此. 两种特殊的文档属性可 ...

  3. 利用HTML5判断用户是否正在浏览页面技巧

    现在,HTML5里页面可见性接口就提供给了程序员一个方法,让他们使用visibilitychange页面事件来判断当前页面可见性的状态,并针对性的执行某些任务.同时还有新的document.hidde ...

  4. js判断用户是否离开当前页面

    简介 VisibilityChange 事件:用于判断用户是否离开当前页面 Code // 页面的 visibility 属性可能返回三种状态 // prerender,visible 和 hidde ...

  5. DataGridView使用技巧三:不显示最下面的新行、判断新增行

    一.DataGridView不显示下面的新行 通常DataGridView的最下面一行是用户新追加的行(行头显示*).如果不想让用户新追加行即不想显示该新行,可以将DataGridView对象的All ...

  6. excel判断单元格包含指定内容的函数用=IF(COUNTIF(A1,"*内容*"),"0","1")

    前面我们聊过怎样将Excel包含某字符的单元格填充颜色,这边我们用另外一种方法来实现:excel判断单元格包含指定内容的函数 选中需要显示结果的单元格,假设我们要判断第一行第一列的单元格A1是否含有“ ...

  7. js判断滚动条是否已到页面最底部或顶部实例

    原文 本文实例讲述了js判断滚动条是否已到页面最底部或顶部的方法.分享给大家供大家参考.具体分析如下: 我们经常会看到很多的网站一个返回顶部效果就是当我们滚动条到指定位置时返回顶部出来了,否则就自动隐 ...

  8. 数据库SQL优化大总结之 百万级数据库优化方案(转载)

    网上关于SQL优化的教程很多,但是比较杂乱.近日有空整理了一下,写出来跟大家分享一下,其中有错误和不足的地方,还请大家纠正补充. 这篇文章我花费了大量的时间查找资料.修改.排版,希望大家阅读之后,感觉 ...

  9. mysql 百万级数据库优化方案

    https://blog.csdn.net/Kaitiren/article/details/80307828 一.百万级数据库优化方案 1.对查询进行优化,要尽量避免全表扫描,首先应考虑在 wher ...

随机推荐

  1. linux(7)

    第十七单元 Samba服务 [本节内容]1. 掌握samba的功能: samba是一个网络服务器,用于Linux和Windows之间共享文件.2. 掌握samba服务的启动.停止.重启service ...

  2. Appium ios新的定位方式FindsByIosNSPredicate (没有试 先记录在这里) 有个 driver.find_element_by_ios_uiautomation() 研究下 ios的定位

    这个定位方式需要用java-client -5.0.版本,4.x的版本没有这个定位方式 //输入账号和密码 driver.findElementByIosNsPredicate("value ...

  3. Java中的三元运算:a = (a > b)?a:b

    格式:逻辑值 ? 表达式1 : 表达式2 执行顺序:先执行逻辑值,如果逻辑值为true,则执行表达式1:反之则执行表达式2 a = (a > b)?a:b 如果a>b成立,返回a: 如果a ...

  4. 第十一章 Helm-kubernetes的包管理器(上)

    Helm - K8s的包管理器 11.1 Why Helm K8s能够很好的组织和编排容器,但它缺少一个更高层次的应用打包工具,Helm就是干这个的. 比如对于一个MySQL服务,K8s需要部署如下对 ...

  5. 新学一招,使用热门的Git

    1.安装Git 1.本文所用版本为Git-1.8.0-preview20121022.exe  , http://msysgit.googlecode.com/files/Git-1.8.0-prev ...

  6. zabbix 报警方式之 邮件报警(4)

    一.为什么要自定义邮件脚本报警? 灵活,方便.可以自定义过滤信息. 下面是使用不同方式的邮件报警,一个是利用sendEmail程序来发送报警邮件,第二个是利用python脚本来发送邮件. 二.send ...

  7. SqlServer 获得存储过程的返回值(参数返回),别玩了output

    declare @dingdanid int declare @fanhuizhi int set @dingdanid = 1 exec 检测订单出库资格 @dingdanid ,@fanhuizh ...

  8. pipenv 简要指南

    pipenv 简要指南 pipenv是requests作者的一个项目, 整合了virtualenv, pip, pipfile, 用于更方便地为项目建立虚拟环境并管理虚拟环境中的第三方模块. 安装 直 ...

  9. Django models拆分

    大多数Django教程都是将models放在models.py文件(模块)中, 然而随着models类的增加, 将类放在一个文件中太混乱了, 于是将models做成一个package: 这样就可以将m ...

  10. 如何将查出的日期Data类型以Json格式输出到前端

    方法一 在返回的实体的属性中加上注解 // 创建时间    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")    private ...