前提:该机构录入的都是和该机构有关的数据,机构下的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. python 多线程要点

    要点整理 多线程 #coding=utf-8 import threading from time import ctime,sleep def music(func): for i in range ...

  2. C程序花括号嵌套层次统计(新)

    [问题描述] 编写程序,统计给定的C源程序中花括号的最大嵌套层次,并输出花括号嵌套序列,该程序没有语法错误. 注意:1)源程序注释(/* … */)中的花括号应被忽略,不参与统计.2)源程序中的字符串 ...

  3. (转)Inno Setup入门(三)——指定压缩方式

    本文转载自:http://blog.csdn.net/augusdi/article/details/8564796 Setup段中的compression指定了采用的压缩方式,较高的压缩率需要较多的 ...

  4. Bootstrap组件系列之福利篇几款好用的组件(推荐)

    引用 :http://www.jb51.net/article/87189.htm 一.时间组件 bootstrap风格的时间组件非常多,你可以在github上面随便搜索“datepicker”关键字 ...

  5. [转]SVN 乱码问题

    以下来自:http://godchenmeng.iteye.com/blog/797727 最近研究SVN.发现在创建补丁包的时候出现这种情况. 在文件顶部不论是什么代码都会变成乱码.在文件中如果有注 ...

  6. idea 破解代码

    下面是idea的破解方法,手动执行对应的main方法即可.亲测Idea 14 完美破解~~废话少说,上代码... package com.jd.serializable; import java.ma ...

  7. js控制电池

    js控制电池 判断设备是否在充电 navigator.getBattery().then(function(battery){ if(battery.charging) { alert("电 ...

  8. R语言可视化学习笔记之添加p-value和显著性标记

    R语言可视化学习笔记之添加p-value和显著性标记 http://www.jianshu.com/p/b7274afff14f?from=timeline   上篇文章中提了一下如何通过ggpubr ...

  9. TCP/IP协议详解之广播和多播

    广播和多播仅应用于 U D P,它们对需将报文同时传往多个接收者的应用来说十分重要.T C P是一个面向连接的协议,它意味着分别运行于两主机(由 I P地址确定)内的两进程(由端口号确定)间存在一条连 ...

  10. 「小程序JAVA实战」小程序头像图片上传(上)(43)

    转自:https://idig8.com/2018/09/08/xiaochengxujavashizhanxiaochengxutouxiangtupianshangchuan40/ 在微信小程序中 ...