Ejemplo n.º 1
0
 protected virtual void OutToExcel(int minPro, int maxPro, ResultCollection rc)
 {
     if (Output != null)
     {
         Output.SetProgress(minPro, maxPro);
     }
     Output.ProgressEvent += this.OnProgress;
     Output.ToExcel(Group, ExcIns.GetWriter(), rc);
     Output.ProgressEvent -= this.OnProgress;
 }
Ejemplo n.º 2
0
        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();
                            }
                        }
                    }
                }
            }
        }