protected override void InsertToCollection(int minPro, int maxPro, string[] paths) { if (JoinDb) { using (IDbQuery query = DbIns.GetQuery("Cq")) { query.Open(); List <Record> cqs = query.SelectToList <Record>(null); SetProgress(0, 40); Tag = "读数据库"; double single = 40d / cqs.Count; foreach (Record cq in cqs) { CqHelper.InsertToCollection(cq, Group); Progress += single; } } base.InsertToCollection(40, maxPro, paths); } else { base.InsertToCollection(0, maxPro, paths); } }
protected virtual void Each_FileHandleEvent(FileInfo info) { //判断文件是否符合要求 bool meet = true; meet = !info.Name.Contains("~$") && (EvFile?.IsMeet(info.Name) ?? false); if (meet) { //生成MD5 string md5 = ToGenerateMD5(info); MF file = new MF() { FID = md5, FileName = info.Name, Date = Convert.ToDateTime(EvFile.Extract(info.Name)) }; //查询数据库,判断是否已经读取过 bool readed = false; if (JoinDb) { using (IDbQuery query = DbIns.GetQuery("Cq")) { if (query != null) { query.Open(); object obj = query.SelectToValue(new QueryArgs() { Where = "FID=@FID", Rows = "Count(1)", Param = new DbParams[] { new DbParams("FID", md5) }, Group = "FID" }); int count = Convert.ToInt32(obj); readed = count > 0; } } } //循环读取 if (!readed) { using (IExcReader reader = ExcIns.GetReader()) { bool isopen = reader?.Open(info.FullName) ?? false; if (CellHelper != null && isopen) { CellHelper.ToObtainColumn = new string[] { "Target", "Sample", "Cq" }; using (IDbAlter alter = DbIns.GetAlter("Cq")) { alter.Open(); IDbTrans trans = DbIns.GetTrans(); trans.Begin(); while (reader.Read()) { Record cq = null; //如果列索引为空则查找索引 if (!CellHelper.IsFindColumn) { CellHelper.FindColumnIndex(reader.Columns); } //不为空则将单元格转化为 Cq ; else { CellArgs args = CellHelper.GetArgs(reader); args.File = file; cq = CqHelper.ConvertToCq(args); } //将 Cq 插入到分类集合中 if (cq != null) { if (JoinDb) { try { alter.Insert(cq, "ID"); } catch { trans.Rollback(); } } CqHelper?.InsertToCollection(cq, Group); } } trans.Commit(); } } } } } }