Beispiel #1
0
        public List<PropertyModel> GetParams(string spName, DbContext db)
        {
            List<PropertyModel> dt = new List<PropertyModel>();

            string dbName = db.getSchema();

            byte[] temp = db.sql("SELECT param_list FROM mysql.proc p WHERE db=? AND name=?", dbName, spName)
                            .getValue<byte[]>(null);

            if (temp != null)
            {
                string paramS = Encoding.UTF8.GetString(temp);

                foreach (string p in paramS.Split(','))
                {
                    string p1 = p.Trim();

                    if (p.Length > 2)
                    {
                        //Name,Type,IsKey(关键字或输出项),Note,Default
                        string[] p2 = p1.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                        if (p2.Length == 3)
                            dt.Add(new PropertyModel(p2[1],
                                p2[2],
                                p2[0].ToLower().IndexOf("out") >= 0,
                                "",
                                ""));
                        else
                            dt.Add(new PropertyModel(p2[0],
                                p2[1],
                                false,
                                "",
                                ""));

                    }
                }
            }
            return dt;
        }
Beispiel #2
0
 public DbTran(DbContext context)
 {
     _context = context;
 }
Beispiel #3
0
        /// <summary>
        /// 添加或替换项目
        /// </summary>
        /// <param name="catalogNumber">catalogNumber</param>
        /// <param name="sourceFile">源文件</param>
        /// <returns>CatalogID</returns>
        public static string addOrReplaceProject(string catalogNumber, string sourceFile)
        {
            //SQLite数据库工厂
            System.Data.SQLite.SQLiteFactory factory = new System.Data.SQLite.SQLiteFactory();

            //NDEY数据库连接
            Noear.Weed.DbContext context = new Noear.Weed.DbContext("main", "Data Source = " + sourceFile, factory);
            //是否在执入后执行查询(主要针对Sqlite)
            context.IsSupportInsertAfterSelectIdentity = false;
            //是否在Dispose后执行GC用于解决Dispose后无法删除的问题(主要针对Sqlite)
            context.IsSupportGCAfterDispose = true;

            try
            {
                //提取所有旧的Project数据
                List <Project> oldProjects = context.table("Project").select("*").getList <Project>(new Project());

                //项目信息
                Project mainProject = context.table("Project").where ("Type = '项目'").select("*").getItem <Project>(new Project());

                //判断数据库是否有内容
                if (oldProjects != null && oldProjects.Count >= 1 && !string.IsNullOrEmpty(mainProject.ID))
                {
                    //项目名称
                    string projectName = mainProject.Name;
                    //申请人
                    string projectCreater = context.table("Person").where ("ID in (select PersonID from Task where Type = '项目' and Role = '负责人')").select("Name").getValue <string>(string.Empty);

                    //目录ID
                    string currentCatalogID = string.Empty;

                    //查询Catalog记录
                    Catalog catalogItem = ConnectionManager.Context.table("Catalog").where ("ProjectName='" + projectName + "' and ProjectCreater='" + projectCreater + "'").select("*").getItem <Catalog>(new Catalog());
                    //如果没有找到则添加新的
                    if (string.IsNullOrEmpty(catalogItem.CatalogID))
                    {
                        //创建一个CatalogID
                        currentCatalogID = Guid.NewGuid().ToString();

                        //添加记录
                        catalogItem.CatalogID            = currentCatalogID;
                        catalogItem.CatalogNumber        = catalogNumber;
                        catalogItem.ProjectName          = projectName;
                        catalogItem.ProjectCreater       = projectCreater;
                        catalogItem.ProjectCreaterUnitID = mainProject.UnitID;
                        catalogItem.copyTo(ConnectionManager.Context.table("Catalog")).insert();
                    }
                    else
                    {
                        //设置CatalogID
                        currentCatalogID = catalogItem.CatalogID;

                        //更新记录
                        catalogItem.CatalogNumber        = catalogNumber;
                        catalogItem.ProjectCreaterUnitID = mainProject.UnitID;
                        catalogItem.copyTo(ConnectionManager.Context.table("Catalog")).where ("CatalogID = '" + currentCatalogID + "'").update();
                    }

                    //根据CatalogID清空本地数据库(除了Catalog表)
                    clearProjectDataWithCatalogID(currentCatalogID);

                    //先导入除Task表之外的所有表格

                    #region 直接导入Project ExtFileList MoneyAndYear Step ProjectAndStep WhiteList 这些表格的数据
                    //插入Project表
                    foreach (Project p in oldProjects)
                    {
                        //设置CatalogID
                        p.CatalogID = currentCatalogID;

                        //插入Project
                        p.copyTo(ConnectionManager.Context.table("Project")).insert();
                    }

                    //插入ExtFileList表
                    List <ExtFileList> oldExtFileLists = context.table("ExtFileList").select("*").getList <ExtFileList>(new ExtFileList());
                    foreach (ExtFileList efl in oldExtFileLists)
                    {
                        //设置CatalogID
                        efl.CatalogID = currentCatalogID;

                        //插入ExtFileList
                        efl.copyTo(ConnectionManager.Context.table("ExtFileList")).insert();
                    }

                    //插入MoneyAndYear表
                    List <MoneyAndYear> oldMoneyAndYears = context.table("MoneyAndYear").select("*").getList <MoneyAndYear>(new MoneyAndYear());
                    foreach (MoneyAndYear efl in oldMoneyAndYears)
                    {
                        //设置CatalogID
                        efl.CatalogID = currentCatalogID;

                        //插入MoneyAndYear
                        efl.copyTo(ConnectionManager.Context.table("MoneyAndYear")).insert();
                    }

                    //插入ProjectAndStep表
                    List <ProjectAndStep> oldProjectAndSteps = context.table("ProjectAndStep").select("*").getList <ProjectAndStep>(new ProjectAndStep());
                    foreach (ProjectAndStep efl in oldProjectAndSteps)
                    {
                        //设置CatalogID
                        efl.CatalogID = currentCatalogID;

                        //插入ProjectAndStep
                        efl.copyTo(ConnectionManager.Context.table("ProjectAndStep")).insert();
                    }

                    //插入Step表
                    List <Step> oldSteps = context.table("Step").select("*").getList <Step>(new Step());
                    foreach (Step efl in oldSteps)
                    {
                        //设置CatalogID
                        efl.CatalogID = currentCatalogID;

                        //插入Step
                        efl.copyTo(ConnectionManager.Context.table("Step")).insert();
                    }

                    //插入WhiteList表
                    List <WhiteList> oldWhiteLists = context.table("WhiteList").select("*").getList <WhiteList>(new WhiteList());
                    foreach (WhiteList efl in oldWhiteLists)
                    {
                        //设置CatalogID
                        efl.CatalogID = currentCatalogID;

                        //插入WhiteList
                        efl.copyTo(ConnectionManager.Context.table("WhiteList")).insert();
                    }
                    #endregion

                    #region 对于Person和Unit表进行选择性导入
                    //插入Person表
                    List <Person> oldPersons = context.table("Person").select("*").getList <Person>(new Person());
                    foreach (Person efl in oldPersons)
                    {
                        //设置CatalogID
                        efl.CatalogID = currentCatalogID;

                        try
                        {
                            //是否被使用
                            object objResult = context.table("Task").where ("PersonID = '" + efl.ID + "'").select("count(*)").getValue();
                            if (objResult != null && int.Parse(objResult.ToString()) >= 1)
                            {
                                //有被使用,直接插入Person就好
                                efl.copyTo(ConnectionManager.Context.table("Person")).insert();
                            }
                        }
                        catch (Exception ex) { }
                    }

                    //插入Unit表
                    List <Unit> oldUnits = context.table("Unit").select("*").getList <Unit>(new Unit());
                    foreach (Unit efl in oldUnits)
                    {
                        //设置CatalogID
                        efl.CatalogID = currentCatalogID;

                        //查询Person,Project,WhiteList检查Unit有没有被使用
                        object objUnitExist11 = context.table("Person").where ("UnitID='" + efl.ID + "'").select("count(*)").getValue();
                        object objUnitExist22 = context.table("Project").where ("UnitID='" + efl.ID + "'").select("count(*)").getValue();
                        object objUnitExist33 = context.table("WhiteList").where ("UnitID='" + efl.ID + "'").select("count(*)").getValue();

                        int useUnitCount = 0;
                        try
                        {
                            if (objUnitExist11 != null && int.Parse(objUnitExist11.ToString()) >= 1)
                            {
                                useUnitCount++;
                            }
                        }
                        catch (Exception ex) { }
                        try
                        {
                            if (objUnitExist22 != null && int.Parse(objUnitExist22.ToString()) >= 1)
                            {
                                useUnitCount++;
                            }
                        }
                        catch (Exception ex) { }
                        try
                        {
                            if (objUnitExist33 != null && int.Parse(objUnitExist33.ToString()) >= 1)
                            {
                                useUnitCount++;
                            }
                        }
                        catch (Exception ex) { }

                        if (useUnitCount >= 1)
                        {
                            //插入Unit
                            efl.copyTo(ConnectionManager.Context.table("Unit")).insert();
                        }
                    }
                    #endregion

                    //处理Task表

                    #region 处理Task错误

                    /**
                     * 第一步先检查Task表是否正常(Role字段是否只有成员或负责人这二个词)
                     *    如果正常直接导入
                     *    如果不正常则尝试修复,操作如下:
                     *      优先处理负责人
                     *         先找到正确的那条负责人记录,以这条记录为基准,把错误的那条记录的任务分工和每年工作时间(月)往这个里面合并
                     *      再处理成员
                     *         先找到正确的那条成员记录,以这条记录为基准,把错误的那条记录的任务分工和每年工作时间(月)往这个里面合并
                     */

                    //取出所有旧的Task记录
                    List <Task> oldTasks = context.table("Task").select("*").getList <Task>(new Task());

                    //正确的职务信息数量
                    int rightPersonCount = 0;

                    //给所有记录设置CatalogID并且检查数据是否正常或被修复过
                    foreach (Task t in oldTasks)
                    {
                        //设置CatalogID
                        t.CatalogID = currentCatalogID;

                        //判断Role里的数值是否正确并计数
                        if (t.Role == "成员" || t.Role == "负责人")
                        {
                            rightPersonCount++;
                        }
                    }

                    //判断数据库是否正常或被修复过
                    if (rightPersonCount == oldTasks.Count)
                    {
                        #region 可以正常导入
                        //1 导入项目负责人
                        foreach (Task t in oldTasks)
                        {
                            if (t.Type == "项目" && t.Role == "负责人")
                            {
                                t.copyTo(ConnectionManager.Context.table("Task")).insert();
                                break;
                            }
                        }

                        //2 导入课题负责人
                        foreach (Project p in oldProjects)
                        {
                            if (p.ID == mainProject.ID)
                            {
                                //忽略项目
                                continue;
                            }
                            else
                            {
                                foreach (Task t in oldTasks)
                                {
                                    if (t.Type == "课题" && t.Role == "负责人" && t.ProjectID == p.ID)
                                    {
                                        t.copyTo(ConnectionManager.Context.table("Task")).insert();
                                        break;
                                    }
                                }
                            }
                        }

                        //3 导入课题成员
                        foreach (Project p in oldProjects)
                        {
                            if (p.ID == mainProject.ID)
                            {
                                //忽略项目
                                continue;
                            }
                            else
                            {
                                foreach (Task t in oldTasks)
                                {
                                    if (t.Type == "课题" && t.Role == "成员" && t.ProjectID == p.ID)
                                    {
                                        object objExistResult = ConnectionManager.Context.table("Task").where ("IDCard='" + t.IDCard + "' and ProjectID = '" + t.ProjectID + "'").select("count(*)").getValue();

                                        if (objExistResult != null && int.Parse(objExistResult.ToString()) >= 1)
                                        {
                                            continue;
                                        }
                                        else
                                        {
                                            t.copyTo(ConnectionManager.Context.table("Task")).insert();
                                        }
                                    }
                                }
                            }
                        }
                        #endregion
                    }
                    else
                    {
                        List <Task> tempTasks = new List <Task>();
                        tempTasks.AddRange(oldTasks);
                        oldTasks.Clear();

                        #region 修复课题负责人及成员

                        //过滤出项目负责人和课题成员
                        foreach (Task t in tempTasks)
                        {
                            if (t.Type == "项目")
                            {
                                if (t.Role == "负责人")
                                {
                                    oldTasks.Add(t);
                                }
                            }
                            else if (t.Type == "课题")
                            {
                                if (t.Role.Contains("成员"))
                                {
                                    t.Role = "成员";
                                    oldTasks.Add(t);
                                }
                            }
                            else
                            {
                                throw new Exception("对不起,数据库中Task表有错误,请检查!文件路径:" + sourceFile);
                            }
                        }
                        //修复课题负责人
                        foreach (Project p in oldProjects)
                        {
                            if (p.Type == "项目")
                            {
                                continue;
                            }

                            Task        master     = null;
                            List <Task> masterList = new List <Task>();
                            foreach (Task t in tempTasks)
                            {
                                if (t.ProjectID == p.ID && t.Type == "课题" && t.Role.Contains("负责人"))
                                {
                                    if (t.Role == "负责人")
                                    {
                                        master = t;
                                    }
                                    else
                                    {
                                        masterList.Add(t);
                                    }
                                }
                            }

                            //如果没有找到不正常的负责人,只有一个正常的那就直接添加进去
                            if (masterList.Count == 0 && master != null)
                            {
                                oldTasks.Add(master);
                            }
                            else
                            {
                                //判断是不是有角色名称包括负责人的记录
                                if (masterList.Count >= 1)
                                {
                                    //如果没有找到正确的记录,就取最后一个
                                    if (master == null && masterList.Count >= 1)
                                    {
                                        //取最后一个记录
                                        master = masterList[masterList.Count - 1];

                                        //删除这个记录
                                        masterList.Remove(master);
                                    }

                                    //设置Role为负责人
                                    master.Role = "负责人";

                                    //如果只有一个不正常的负责人,那就把Role替换成负责人直接加进去
                                    if (masterList.Count == 0 && master != null)
                                    {
                                        oldTasks.Add(master);
                                    }
                                    else
                                    {
                                        //反转MasterList,从最后一个记录开始取数
                                        masterList.Reverse();

                                        //检查课题金额、工作时间(月)、任务分工这三个属性是否需要填充,这个时候就需要从错的那些记录里找金额
                                        foreach (Task t in masterList)
                                        {
                                            //检查是否需要填充金额
                                            if (t.TotalMoney > 0 && master.TotalMoney <= 0)
                                            {
                                                master.TotalMoney = t.TotalMoney;
                                            }

                                            //检查是否需要填充工作时间
                                            if (t.TotalTime > 0 && master.TotalTime <= 0)
                                            {
                                                master.TotalTime = t.TotalTime;
                                            }

                                            //检查是否需要填充任务分工
                                            if (t.Content != null && t.Content.Trim().Length >= 1 && string.IsNullOrEmpty(master.Content))
                                            {
                                                master.Content = t.Content;
                                            }
                                        }

                                        //将修改过的负责人添加到列表中
                                        oldTasks.Add(master);
                                    }
                                }
                                else
                                {
                                    throw new Exception("对不起,数据库中Task表有错误,请检查!文件路径:" + sourceFile);
                                }
                            }
                        }
                        #endregion

                        #region 导入数据
                        //1 导入项目负责人
                        foreach (Task t in oldTasks)
                        {
                            if (t.Type == "项目" && t.Role == "负责人")
                            {
                                t.copyTo(ConnectionManager.Context.table("Task")).insert();
                                break;
                            }
                        }

                        //2 导入课题负责人
                        foreach (Project p in oldProjects)
                        {
                            if (p.ID == mainProject.ID)
                            {
                                //忽略项目
                                continue;
                            }
                            else
                            {
                                foreach (Task t in oldTasks)
                                {
                                    if (t.Type == "课题" && t.Role == "负责人" && t.ProjectID == p.ID)
                                    {
                                        t.copyTo(ConnectionManager.Context.table("Task")).insert();
                                        break;
                                    }
                                }
                            }
                        }

                        //3 导入课题成员
                        foreach (Project p in oldProjects)
                        {
                            if (p.ID == mainProject.ID)
                            {
                                //忽略项目
                                continue;
                            }
                            else
                            {
                                foreach (Task t in oldTasks)
                                {
                                    if (t.Type == "课题" && t.Role == "成员" && t.ProjectID == p.ID)
                                    {
                                        object objExistResult = ConnectionManager.Context.table("Task").where ("IDCard='" + t.IDCard + "' and ProjectID = '" + t.ProjectID + "'").select("count(*)").getValue();

                                        if (objExistResult != null && int.Parse(objExistResult.ToString()) >= 1)
                                        {
                                            continue;
                                        }
                                        else
                                        {
                                            t.copyTo(ConnectionManager.Context.table("Task")).insert();
                                        }
                                    }
                                }
                            }
                        }
                        #endregion
                    }
                    #endregion

                    return(currentCatalogID);
                }
                else
                {
                    //空数据库
                    throw new Exception("对不起,数据库有错误,请检查!文件路径:" + sourceFile);
                }
            }
            finally
            {
                factory.Dispose();
                context.Dispose();
            }
        }
Beispiel #4
0
        /// <summary>
        /// 导入数据库
        /// </summary>
        /// <param name="catalogNumber"></param>
        /// <param name="sourceFile"></param>
        /// <param name="localContext"></param>
        /// <returns></returns>
        protected override string importDB(string catalogNumber, string sourceFile, Noear.Weed.DbContext localContext)
        {
            Dictionary <string, Subject> subjectDict = new Dictionary <string, Subject>();

            //数据库版本号
            string catalogVersionStr = "v1.1";

            //附件目录
            string filesDir = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(sourceFile), "Files");

            //处理项目信息
            DataItem diProject = localContext.table("JiBenXinXiBiao").select("*").getDataItem();

            if (diProject != null && diProject.count() >= 1)
            {
                #region 读取版本号并更新Catalog信息
                //读取版本号
                try
                {
                    catalogVersionStr = localContext.table("Version").select("VersionNum").getValue <string>(catalogVersionStr);
                }
                catch (Exception ex) { }

                //更新Catalog
                Catalog catalog = updateAndClearCatalog(catalogNumber, getValueWithDefault <string>(diProject.get("HeTongMingCheng"), string.Empty), "合同书", catalogVersionStr, false, string.Empty, System.IO.Path.GetDirectoryName(sourceFile));
                #endregion

                #region 导入项目及课题信息
                //处理项目信息
                Project proj = new Project();
                proj.ProjectID   = catalog.CatalogID;
                proj.CatalogID   = catalog.CatalogID;
                proj.ProjectName = catalog.CatalogName;
                proj.SecretLevel = getValueWithDefault <string>(diProject.get("HeTongMiJi"), string.Empty);
                proj.TotalMoney  = diProject.get("HeTongJiaKuan") != null?decimal.Parse(diProject.get("HeTongJiaKuan").ToString()) : 0;

                proj.ProjectNumber = getValueWithDefault <string>(diProject.get("HeTongBianHao"), string.Empty);
                proj.IsNeedHide    = "0";

                int totalYear = 0;
                try
                {
                    DateTime startTime = diProject.getDateTime("HeTongKaiShiShiJian");
                    DateTime endTime   = diProject.getDateTime("HeTongJieShuShiJian");
                    totalYear = (endTime.Year + 1) - startTime.Year;
                }
                catch (Exception ex) { }
                proj.TotalTime      = totalYear;
                proj.DutyNormalUnit = string.Empty;

                //导入1.3版之后版本新添加的字段
                switch (catalogVersionStr)
                {
                case "v1.1":
                    break;

                case "v1.2":
                    break;

                case "v1.3":
                    break;

                case "v1.4":
                    proj.Keywords        = getValueWithDefault <string>(diProject.get("HeTongGuanJianZi"), string.Empty);
                    proj.Domains         = getValueWithDefault <string>(diProject.get("HeTongSuoShuLingYu"), string.Empty);
                    proj.DutyUnit        = getValueWithDefault <string>(diProject.get("HeTongFuZeDanWei"), string.Empty);
                    proj.DutyUnitOrg     = getValueWithDefault <string>(diProject.get("HeTongSuoShuBuMen"), string.Empty);
                    proj.DutyUnitAddress = getAddress(getValueWithDefault <string>(diProject.get("HeTongSuoShuDiDian"), string.Empty));
                    break;

                case "v1.5":
                    proj.Keywords        = getValueWithDefault <string>(diProject.get("HeTongGuanJianZi"), string.Empty);
                    proj.Domains         = getValueWithDefault <string>(diProject.get("HeTongSuoShuLingYu"), string.Empty);
                    proj.DutyUnit        = getValueWithDefault <string>(diProject.get("HeTongFuZeDanWei"), string.Empty);
                    proj.DutyUnitOrg     = getValueWithDefault <string>(diProject.get("HeTongSuoShuBuMen"), string.Empty);
                    proj.DutyUnitAddress = getAddress(getValueWithDefault <string>(diProject.get("HeTongSuoShuDiDian"), string.Empty));

                    proj.DutyNormalUnit = getValueWithDefault <string>(diProject.get("HeTongFuZeDanWeiChangYongMingCheng"), string.Empty);
                    break;
                }

                proj.copyTo(ConnectionManager.Context.table("Project")).insert();

                //处理课题列表
                DataList dlSubject = localContext.table("KeTiBiao").orderBy("ZhuangTai,ModifyTime").select("*").getDataList();
                foreach (DataItem di in dlSubject.getRows())
                {
                    Subject obj = new Subject();
                    obj.SubjectID   = getValueWithDefault <string>(di.get("BianHao"), string.Empty);
                    obj.CatalogID   = proj.CatalogID;
                    obj.ProjectID   = proj.ProjectID;
                    obj.SubjectName = getValueWithDefault <string>(di.get("KeTiMingCheng"), string.Empty);
                    //obj.TotalMoney = di.get("") != null ? decimal.Parse(di.get("").ToString()) : 0;
                    obj.WorkDest    = getValueWithDefault <string>(di.get("KeTiYanJiuMuBiao"), string.Empty);
                    obj.WorkContent = getValueWithDefault <string>(di.get("KeTiYanJiuNeiRong"), string.Empty);
                    obj.WorkTask    = getValueWithDefault <string>(di.get("KeTiCanJiaDanWeiFenGong"), string.Empty);
                    obj.SecretLevel = "公开";
                    obj.TotalMoney  = 0;

                    //导入1.3版之后版本新添加的字段
                    switch (catalogVersionStr)
                    {
                    case "v1.1":
                        break;

                    case "v1.2":
                        break;

                    case "v1.3":
                        break;

                    case "v1.4":
                        obj.DutyUnit        = getValueWithDefault <string>(di.get("KeTiFuZeDanWei"), string.Empty);
                        obj.DutyUnitOrg     = getValueWithDefault <string>(di.get("KeTiSuoShuBuMen"), string.Empty);
                        obj.DutyUnitAddress = getAddress(getValueWithDefault <string>(di.get("KeTiSuoShuDiDian"), string.Empty));

                        //处理参加单位分工
                        StringBuilder sbWorkTask = new StringBuilder();
                        DataList      items      = localContext.table("RenWuBiao").where ("KeTiBianHao='" + getValueWithDefault <string>(di.get("BianHao"), string.Empty) + "'").select("*").getDataList();
                        if (items.getRowCount() >= 1)
                        {
                            sbWorkTask.Append("该课题由").Append(getValueWithDefault <string>(items.getRow(0).get("DanWeiMing"), string.Empty)).Append("单位负责,承担").Append(getValueWithDefault <string>(items.getRow(0).get("RenWuFenGong"), string.Empty)).Append("等任务;").AppendLine();
                        }
                        for (int kk = 1; kk < items.getRowCount(); kk++)
                        {
                            DataItem rwb = items.getRow(kk);
                            sbWorkTask.Append(getValueWithDefault <string>(rwb.get("DanWeiMing"), string.Empty)).Append("单位参加,承担").Append(getValueWithDefault <string>(rwb.get("RenWuFenGong"), string.Empty)).Append("等任务;\n");
                        }
                        if (sbWorkTask.Length >= 1)
                        {
                            sbWorkTask.Remove(sbWorkTask.Length - 1, 1);
                        }
                        obj.WorkTask = sbWorkTask.ToString();
                        break;

                    case "v1.5":
                        obj.DutyUnit        = getValueWithDefault <string>(di.get("KeTiFuZeDanWei"), string.Empty);
                        obj.DutyUnitOrg     = getValueWithDefault <string>(di.get("KeTiSuoShuBuMen"), string.Empty);
                        obj.DutyUnitAddress = getAddress(getValueWithDefault <string>(di.get("KeTiSuoShuDiDian"), string.Empty));

                        //处理参加单位分工
                        sbWorkTask = new StringBuilder();
                        items      = localContext.table("RenWuBiao").where ("KeTiBianHao='" + getValueWithDefault <string>(di.get("BianHao"), string.Empty) + "'").select("*").getDataList();
                        if (items.getRowCount() >= 1)
                        {
                            sbWorkTask.Append("该课题由").Append(getValueWithDefault <string>(items.getRow(0).get("DanWeiMing"), string.Empty)).Append("单位负责,承担").Append(getValueWithDefault <string>(items.getRow(0).get("RenWuFenGong"), string.Empty)).Append("等任务;").AppendLine();
                        }
                        for (int kk = 1; kk < items.getRowCount(); kk++)
                        {
                            DataItem rwb = items.getRow(kk);
                            sbWorkTask.Append(getValueWithDefault <string>(rwb.get("DanWeiMing"), string.Empty)).Append("单位参加,承担").Append(getValueWithDefault <string>(rwb.get("RenWuFenGong"), string.Empty)).Append("等任务;\n");
                        }
                        if (sbWorkTask.Length >= 1)
                        {
                            sbWorkTask.Remove(sbWorkTask.Length - 1, 1);
                        }
                        obj.WorkTask = sbWorkTask.ToString();

                        obj.SecretLevel = getValueWithDefault <string>(di.get("KeTiBaoMiDengJi"), string.Empty);
                        break;
                    }

                    obj.copyTo(ConnectionManager.Context.table("Subject")).insert();

                    subjectDict[obj.SubjectID] = obj;
                }
                #endregion

                #region 判断是否需要隐藏建议书-proj.ProjectNumber
                //string contactNumber = string.Empty;

                //if (proj.ProjectNumber.EndsWith("-00"))
                //{
                //    contactNumber = proj.ProjectNumber.Replace("-00", string.Empty);
                //}
                //else
                //{
                //    contactNumber = proj.ProjectNumber;
                //}

                //Catalog catalogReporter = ConnectionManager.Context.table("Catalog").where("CatalogNumber like '%" + contactNumber + "%' and CatalogType = '建议书'").select("*").getItem<Catalog>(new Catalog());
                //if (!string.IsNullOrEmpty(catalogReporter.CatalogID))
                //{
                //    catalogReporter.IsNeedHide = "1";
                //    catalogReporter.copyTo(ConnectionManager.Context.table("Catalog").where("CatalogNumber like '%" + contactNumber + "%' and CatalogType = '建议书'")).update();

                //    Project projReporter = ConnectionManager.Context.table("Project").where("CatalogID='" + catalogReporter.CatalogID + "'").select("*").getItem<Project>(new Project());
                //    if (!string.IsNullOrEmpty(projReporter.ProjectID))
                //    {
                //        projReporter.IsNeedHide = "1";
                //        projReporter.copyTo(ConnectionManager.Context.table("Project").where("CatalogID='" + catalogReporter.CatalogID + "'")).update();
                //    }
                //}
                #endregion

                #region 更新项目编号字段
                catalog.CatalogNumber = proj.ProjectNumber;
                catalog.copyTo(ConnectionManager.Context.table("Catalog").where ("CatalogID='" + catalog.CatalogID + "'")).update();
                #endregion

                #region 导入人员信息
                //处理人员信息
                DataList dlPerson = localContext.table("RenYuanBiao").orderBy("ZhuangTai").select("*").getDataList();
                foreach (DataItem di in dlPerson.getRows())
                {
                    Person obj = new Person();
                    obj.PersonID        = Guid.NewGuid().ToString();
                    obj.CatalogID       = proj.CatalogID;
                    obj.ProjectID       = proj.ProjectID;
                    obj.SubjectID       = getValueWithDefault <string>(di.get("KeTiBiaoHao"), string.Empty);
                    obj.PersonName      = getValueWithDefault <string>(di.get("XingMing"), string.Empty);
                    obj.PersonIDCard    = getValueWithDefault <string>(di.get("ShenFenZhengHao"), string.Empty);
                    obj.PersonSex       = getValueWithDefault <string>(di.get("XingBie"), string.Empty);
                    obj.PersonJob       = getValueWithDefault <string>(di.get("ZhiCheng"), string.Empty);
                    obj.PersonSpecialty = getValueWithDefault <string>(di.get("ZhuanYe"), string.Empty);
                    obj.TotalTime       = di.getInt("MeiNianTouRuShiJian");
                    obj.TaskContent     = getValueWithDefault <string>(di.get("RenWuFenGong"), string.Empty);
                    obj.WorkUnit        = getValueWithDefault <string>(di.get("GongZuoDanWei"), string.Empty);
                    obj.Telephone       = di.exists("DianHua") ? getValueWithDefault <string>(di.get("DianHua"), string.Empty) : string.Empty;
                    obj.Mobilephone     = di.exists("ShouJi") ? getValueWithDefault <string>(di.get("ShouJi"), string.Empty) : string.Empty;

                    //设置项目中职务
                    obj.JobInProject = getValueWithDefault <string>(di.get("ZhiWu"), string.Empty);

                    //是否为项目负责人
                    switch (getValueWithDefault <string>(di.get("ShiXiangMuFuZeRen"), string.Empty))
                    {
                    case "rbIsOnlyProject":
                        obj.PersonID        = Guid.NewGuid().ToString();
                        obj.SubjectID       = string.Empty;
                        obj.IsProjectMaster = "true";
                        //插入数据
                        obj.copyTo(ConnectionManager.Context.table("Person")).insert();
                        break;

                    case "rbIsProjectAndSubject":
                        string oldSubjectID = obj.SubjectID;

                        //保存项目负责人
                        obj.PersonID        = Guid.NewGuid().ToString();
                        obj.SubjectID       = string.Empty;
                        obj.IsProjectMaster = "true";
                        //插入数据
                        obj.copyTo(ConnectionManager.Context.table("Person")).insert();

                        //保存课题负责人
                        obj.PersonID        = Guid.NewGuid().ToString();
                        obj.SubjectID       = oldSubjectID;
                        obj.IsProjectMaster = "false";
                        //插入数据
                        obj.copyTo(ConnectionManager.Context.table("Person")).insert();
                        break;

                    case "rbIsOnlySubject":
                        //保存课题负责人或成员
                        obj.PersonID        = Guid.NewGuid().ToString();
                        obj.IsProjectMaster = "false";
                        //插入数据
                        obj.copyTo(ConnectionManager.Context.table("Person")).insert();
                        break;
                    }
                }
                #endregion

                #region 写入金额数据
                DataList dlMoneys = localContext.table("YuSuanBiao").select("*").getDataList();
                if (dlMoneys != null && dlMoneys.getRowCount() >= 1)
                {
                    foreach (DataItem di in dlMoneys.getRows())
                    {
                        //添加字典
                        addDict(catalog, proj, "Money,Info", (di.get("MingCheng") != null ? di.get("MingCheng").ToString() : string.Empty), (di.get("ShuJu") != null ? di.get("ShuJu").ToString() : string.Empty), string.Empty);
                    }
                }
                #endregion

                #region 写入研究进度安排
                DataList dlProgress = localContext.table("JinDuBiao").orderBy("ZhuangTai,ModifyTime").select("*").getDataList();
                foreach (DataItem diProgress in dlProgress.getRows())
                {
                    try
                    {
                        WorkSteps ws = new WorkSteps();
                        ws.WSID           = Guid.NewGuid().ToString();
                        ws.CatalogID      = catalog.CatalogID;
                        ws.ProjectID      = proj.ProjectID;
                        ws.WorkTime       = DateTime.Parse(diProgress.get("ShiJian") != null ? diProgress.get("ShiJian").ToString() : DateTime.MinValue.ToString());
                        ws.DestAndContent = diProgress.get("JieDuanMuBiao") != null?diProgress.get("JieDuanMuBiao").ToString() : string.Empty;

                        ws.ResultMethod = diProgress.get("JieDuanChengGuo") != null?diProgress.get("JieDuanChengGuo").ToString() : string.Empty;

                        ws.copyTo(ConnectionManager.Context.table("WorkSteps")).insert();
                    }
                    catch (Exception ex) { }
                }
                #endregion

                //节点字典(Key=名称,Value=记录ID)
                Dictionary <string, string> nodeDict = new Dictionary <string, string>();

                #region 写入拨付约定
                int      nodeIndexx = 0;
                DataList dlRules    = localContext.table("BoFuBiao").orderBy("ZhuangTai,ModifyTime").select("*").getDataList();
                foreach (DataItem diRule in dlRules.getRows())
                {
                    nodeIndexx++;

                    try
                    {
                        MoneySends ms = new MoneySends();
                        ms.MSID = diRule.get("BianHao") != null?diRule.get("BianHao").ToString() : Guid.NewGuid().ToString();

                        ms.CatalogID = catalog.CatalogID;
                        ms.ProjectID = proj.ProjectID;
                        ms.NodeIndex = nodeIndexx;
                        ms.SendRule  = diRule.get("BoFuTiaoJian") != null?diRule.get("BoFuTiaoJian").ToString() : string.Empty;

                        ms.WillTime   = DateTime.Parse(diRule.get("YuJiShiJian") != null ? diRule.get("YuJiShiJian").ToString() : DateTime.MinValue.ToString());
                        ms.TotalMoney = decimal.Parse(diRule.get("JingFeiJinQian") != null ? diRule.get("JingFeiJinQian").ToString() : "0");
                        ms.MemoText   = diRule.get("BeiZhu") != null?diRule.get("BeiZhu").ToString() : string.Empty;

                        ms.copyTo(ConnectionManager.Context.table("MoneySends")).insert();

                        if (string.IsNullOrEmpty(ms.SendRule))
                        {
                            continue;
                        }
                        else
                        {
                            nodeDict[ms.SendRule] = ms.MSID;
                        }
                    }
                    catch (Exception ex) { }
                }
                #endregion

                try
                {
                    //尝试写入1.5中新加的课题节点经费和单位节点经费表

                    #region 写入课题节点经费
                    DataList dlSubjectMoneys = localContext.table("KeTiJieDianJingFeiBiao").orderBy("ZhuangTai,ModifyTime").select("*").getDataList();
                    foreach (DataItem di in dlSubjectMoneys.getRows())
                    {
                        string oldSubjectId = di.get("KeTiBianHao") != null?di.get("KeTiBianHao").ToString() : string.Empty;

                        string oldNodeId = di.get("BoFuBianHao") != null?di.get("BoFuBianHao").ToString() : string.Empty;

                        string moduleName  = "current";
                        string moduleValue = di.get("JingFei") != null?di.get("JingFei").ToString() : string.Empty;

                        string oldSubjectName = localContext.table("KeTiBiao").where ("BianHao='" + oldSubjectId + "'").select("KeTiMingCheng").getValue <string>(string.Empty);
                        string newSubjectID   = ConnectionManager.Context.table("Subject").where ("SubjectName='" + oldSubjectName + "'").select("SubjectID").getValue <string>(string.Empty);

                        string oldNodeName = localContext.table("BoFuBiao").where ("BianHao='" + oldNodeId + "'").select("BoFuTiaoJian").getValue <string>(string.Empty);
                        string newNodeID   = oldNodeId;
                        if (nodeDict.ContainsKey(oldNodeName))
                        {
                            newNodeID = nodeDict[oldNodeName];

                            SubjectMoneys obj = new SubjectMoneys();
                            obj.SMID      = Guid.NewGuid().ToString();
                            obj.CatalogID = catalog.CatalogID;
                            obj.ProjectID = catalog.CatalogID;
                            obj.SubjectID = newSubjectID;
                            obj.NodeID    = newNodeID;
                            obj.SMName    = moduleName;
                            obj.SMValue   = moduleValue;
                            obj.copyTo(ConnectionManager.Context.table("SubjectMoneys")).insert();

                            decimal nodeMoney = 0;
                            try
                            {
                                nodeMoney = decimal.Parse(obj.SMValue);
                            }
                            catch (Exception ex) { }
                            if (subjectDict.ContainsKey(obj.SubjectID))
                            {
                                subjectDict[obj.SubjectID].TotalMoney += nodeMoney;
                            }
                        }
                    }
                    #endregion

                    #region 写入单位节点经费
                    DataList dlUnitMoneys = localContext.table("DanWeiJieDianJingFeiBiao").orderBy("ZhuangTai,ModifyTime").select("*").getDataList();
                    foreach (DataItem di in dlUnitMoneys.getRows())
                    {
                        string unitName = di.get("DanWeiMingCheng") != null?di.get("DanWeiMingCheng").ToString() : string.Empty;

                        string oldNodeId = di.get("BoFuBianHao") != null?di.get("BoFuBianHao").ToString() : string.Empty;

                        string moduleName  = "current";
                        string moduleValue = di.get("JingFei") != null?di.get("JingFei").ToString() : string.Empty;

                        string oldNodeName = localContext.table("BoFuBiao").where ("BianHao='" + oldNodeId + "'").select("BoFuTiaoJian").getValue <string>(string.Empty);
                        string newNodeID   = oldNodeId;
                        if (nodeDict.ContainsKey(oldNodeName))
                        {
                            newNodeID = nodeDict[oldNodeName];

                            UnitMoneys obj = new UnitMoneys();
                            obj.UMID      = Guid.NewGuid().ToString();
                            obj.CatalogID = catalog.CatalogID;
                            obj.ProjectID = catalog.CatalogID;
                            obj.NodeID    = newNodeID;
                            obj.UnitName  = unitName;
                            obj.UMName    = moduleName;
                            obj.UMValue   = moduleValue;
                            obj.copyTo(ConnectionManager.Context.table("UnitMoneys")).insert();
                        }
                    }
                    #endregion

                    #region 更新课题总经费
                    foreach (Subject subObj in subjectDict.Values)
                    {
                        subObj.copyTo(ConnectionManager.Context.table("Subject").where ("CatalogID = '" + subObj.CatalogID + "' and SubjectID = '" + subObj.SubjectID + "'")).update();
                    }
                    #endregion
                }
                catch (Exception ex)
                {
                    System.Console.WriteLine(ex.ToString());
                }

                #region 处理归一化单位列
                int checkCount = 0;
                int errorCount = 0;

                checkCount++;
                proj.DutyNormalUnit = getNormalNameWithDutyUnit(proj.DutyUnit);
                proj.copyTo(ConnectionManager.Context.table("Project")).where ("ProjectID='" + proj.ProjectID + "'").update();
                if (proj.DutyNormalUnit == "未匹配")
                {
                    errorCount++;
                }

                List <Subject> subjectList22 = ConnectionManager.Context.table("Subject").where ("ProjectID='" + proj.ProjectID + "' and ProjectID = '" + proj.ProjectID + "'").select("*").getList <Subject>(new Subject());
                foreach (Subject sub22 in subjectList22)
                {
                    checkCount++;

                    sub22.DutyNormalUnit = getNormalNameWithDutyUnit(sub22.DutyUnit);
                    sub22.copyTo(ConnectionManager.Context.table("Subject")).where ("SubjectID='" + sub22.SubjectID + "' and ProjectID = '" + proj.ProjectID + "'").update();

                    if (sub22.DutyNormalUnit == "未匹配")
                    {
                        errorCount++;
                    }
                }

                List <Person> personList22 = ConnectionManager.Context.table("Person").where ("ProjectID='" + proj.ProjectID + "'").select("*").getList <Person>(new Person());
                foreach (Person per22 in personList22)
                {
                    checkCount++;

                    per22.WorkNormalUnit = getNormalNameWithDutyUnit(per22.WorkUnit);
                    per22.copyTo(ConnectionManager.Context.table("Person")).where ("PersonID='" + per22.PersonID + "' and ProjectID = '" + proj.ProjectID + "'").update();

                    if (per22.WorkNormalUnit == "未匹配")
                    {
                        errorCount++;
                    }
                }

                catalog.IsCheckUnitComplete = errorCount == 0 ? "通过" : "不通过";
                proj.IsCheckUnitComplete    = errorCount == 0 ? "通过" : "不通过";

                proj.copyTo(ConnectionManager.Context.table("Project")).where ("ProjectID='" + proj.ProjectID + "'").update();
                catalog.copyTo(ConnectionManager.Context.table("Catalog")).where ("CatalogID='" + catalog.CatalogID + "'").update();
                #endregion

                return(catalog.CatalogID);
            }
            else
            {
                return(string.Empty);
            }
        }
Beispiel #5
0
        /// <summary>
        /// 导入数据库
        /// </summary>
        /// <param name="catalogNumber"></param>
        /// <param name="sourceFile"></param>
        /// <param name="localContext"></param>
        /// <returns></returns>
        protected override string importDB(string catalogNumber, string sourceFile, Noear.Weed.DbContext localContext)
        {
            //数据库版本号
            string catalogVersionStr = "v1.1";

            //附件目录
            string filesDir = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(sourceFile), "Files");

            //处理项目信息
            DataItem diProject = localContext.table("Project").where ("Type = '项目'").select("*").getDataItem();

            if (diProject != null && diProject.count() >= 1)
            {
                #region 读取版本号并更新Catalog信息
                //读取版本号
                try
                {
                    catalogVersionStr = localContext.table("Version").select("VersionNum").getValue <string>(catalogVersionStr);
                }
                catch (Exception ex) { }

                //更新Catalog
                Catalog catalog = updateAndClearCatalog(catalogNumber, getValueWithDefault <string>(diProject.get("Name"), string.Empty), "建议书", catalogVersionStr, false, string.Empty, System.IO.Path.GetDirectoryName(sourceFile));
                #endregion

                #region 导入项目及课题信息
                //添加项目信息
                Project proj = new Project();
                proj.ProjectID   = catalog.CatalogID;
                proj.CatalogID   = catalog.CatalogID;
                proj.ProjectName = catalog.CatalogName;
                proj.SecretLevel = getValueWithDefault <string>(diProject.get("SecretLevel"), string.Empty);
                proj.TotalMoney  = diProject.get("TotalMoney") != null?decimal.Parse(diProject.get("TotalMoney").ToString()) : 0;

                proj.Keywords       = getValueWithDefault <string>(diProject.get("Keywords"), string.Empty);
                proj.Domains        = getValueWithDefault <string>(diProject.get("Domain"), string.Empty);
                proj.DutyUnit       = localContext.table("Unit").where ("ID='" + diProject.get("UnitID") + "'").select("UnitName").getValue <string>("未知");
                proj.DutyNormalUnit = localContext.table("Unit").where ("ID='" + diProject.get("UnitID") + "'").select("NormalName").getValue <string>("未知");
                //proj.DutyUnitOrg = "未知";
                proj.DutyUnitAddress = localContext.table("Unit").where ("ID='" + diProject.get("UnitID") + "'").select("Address").getValue <string>("未知");
                proj.ProjectNumber   = string.Empty;
                proj.TotalTime       = diProject.getInt("TotalTime");
                proj.IsNeedHide      = "0";
                proj.ProjectNumber   = catalogNumber;
                proj.copyTo(ConnectionManager.Context.table("Project")).insert();

                //处理课题列表
                DataList dlSubject = localContext.table("Project").where ("Type = '课题'").select("*").getDataList();
                foreach (DataItem di in dlSubject.getRows())
                {
                    Subject obj = new Subject();
                    obj.SubjectID   = getValueWithDefault <string>(di.get("ID"), string.Empty);
                    obj.CatalogID   = proj.CatalogID;
                    obj.ProjectID   = proj.ProjectID;
                    obj.SubjectName = getValueWithDefault <string>(di.get("Name"), string.Empty);
                    obj.SecretLevel = getValueWithDefault <string>(di.get("SecretLevel"), string.Empty);

                    object objMoney = localContext.table("Task").where ("Role='负责人' and Type = '课题' and ProjectID = '" + obj.SubjectID + "'").select("TotalMoney").getValue();
                    obj.TotalMoney = objMoney != null?decimal.Parse(objMoney.ToString()) : 0;

                    obj.WorkDest    = System.IO.Path.Combine(filesDir, "课题详细_" + obj.SubjectName + "_研究目标" + ".doc");
                    obj.WorkContent = System.IO.Path.Combine(filesDir, "课题详细_" + obj.SubjectName + "_研究内容" + ".doc");
                    obj.WorkTask    = string.Empty;

                    obj.DutyUnit = localContext.table("Unit").where ("ID='" + di.get("UnitID") + "'").select("UnitName").getValue <string>("未知");
                    //obj.DutyUnitOrg = "未知";
                    //obj.DutyUnitAddress = localContext.table("Unit").where("ID='" + di.get("UnitID") + "'").select("Address").getValue<string>("未知");

                    obj.copyTo(ConnectionManager.Context.table("Subject")).insert();
                }
                #endregion

                #region 判断是否需要隐藏建议书-proj.ProjectNumber
                //string contactNumber = proj.ProjectNumber;

                //Catalog catalogReporter = ConnectionManager.Context.table("Catalog").where("CatalogNumber like '%" + contactNumber + "%' and CatalogType = '合同书'").select("*").getItem<Catalog>(new Catalog());
                //if (!string.IsNullOrEmpty(catalogReporter.CatalogID))
                //{
                //    catalog.IsNeedHide = "1";
                //    catalog.copyTo(ConnectionManager.Context.table("Catalog").where("CatalogID='" + catalog.CatalogID + "'")).update();

                //    if (!string.IsNullOrEmpty(proj.ProjectID))
                //    {
                //        proj.IsNeedHide = "1";
                //        proj.copyTo(ConnectionManager.Context.table("Project").where("CatalogID='" + catalog.CatalogID + "'")).update();
                //    }
                //}
                #endregion

                #region 导入人员信息
                //处理人员信息
                DataList dlTask = localContext.table("Task").orderBy("DisplayOrder").select("*").getDataList();
                foreach (DataItem diTask in dlTask.getRows())
                {
                    DataItem diPerson = localContext.table("Person").where ("ID = '" + diTask.get("PersonID") + "'").select("*").getDataItem();
                    if (diPerson != null && diPerson.count() >= 1)
                    {
                        Person obj = new Person();
                        obj.PersonID        = Guid.NewGuid().ToString();
                        obj.CatalogID       = proj.CatalogID;
                        obj.ProjectID       = proj.ProjectID;
                        obj.SubjectID       = getValueWithDefault <string>(diTask.get("ProjectID"), string.Empty);
                        obj.PersonName      = getValueWithDefault <string>(diPerson.get("Name"), string.Empty);
                        obj.PersonIDCard    = getValueWithDefault <string>(diPerson.get("IDCard"), string.Empty);
                        obj.PersonSex       = getValueWithDefault <string>(diPerson.get("Sex"), string.Empty);
                        obj.PersonJob       = getValueWithDefault <string>(diPerson.get("Job"), string.Empty);
                        obj.PersonSpecialty = getValueWithDefault <string>(diPerson.get("Specialty"), string.Empty);
                        obj.TotalTime       = diTask.getInt("TotalTime");
                        obj.TaskContent     = getValueWithDefault <string>(diTask.get("Content"), string.Empty);
                        obj.Telephone       = getValueWithDefault <string>(diPerson.get("Telephone"), string.Empty);
                        obj.Mobilephone     = getValueWithDefault <string>(diPerson.get("MobilePhone"), string.Empty);

                        DataItem diUnit = localContext.table("Unit").where ("ID='" + diPerson.get("UnitID") + "'").select("*").getDataItem();
                        if (diUnit != null && diUnit.count() >= 1)
                        {
                            obj.WorkUnit = getValueWithDefault <string>(diUnit.get("UnitName"), string.Empty);
                        }
                        else
                        {
                            obj.WorkUnit = "未知";
                        }

                        //设置项目中职务
                        obj.JobInProject = getValueWithDefault <string>(diTask.get("Role"), string.Empty);

                        //是否为项目负责人
                        obj.IsProjectMaster = diTask.get("Type").ToString() == "项目" ? "true" : "false";

                        //如果是项目负责人就清空课题ID
                        if (obj.IsProjectMaster == "true")
                        {
                            obj.SubjectID = string.Empty;
                        }

                        //插入数据
                        obj.copyTo(ConnectionManager.Context.table("Person")).insert();
                    }
                }
                #endregion

                #region 导入经费信息表
                DataList dlMoneys = localContext.table("MoneyAndYear").select("*").getDataList();
                if (dlMoneys != null && dlMoneys.getRowCount() >= 1)
                {
                    //关键字映射表
                    Dictionary <string, string> nameDicts = new Dictionary <string, string>();
                    nameDicts["ProjectRFA"]        = "Money1";
                    nameDicts["ProjectRFA1"]       = "Money2";
                    nameDicts["ProjectRFA1_1"]     = "Money3";
                    nameDicts["ProjectRFA1_1_1"]   = "Money3_1";
                    nameDicts["ProjectRFA1_1_2"]   = "Money3_2";
                    nameDicts["ProjectRFA1_1_3"]   = "Money3_3";
                    nameDicts["ProjectRFA1_2"]     = "Money4";
                    nameDicts["ProjectRFA1_3"]     = "Money5";
                    nameDicts["ProjectRFA1_3_1"]   = "Money5_1";
                    nameDicts["ProjectRFA1_3_2"]   = "Money5_2";
                    nameDicts["ProjectRFA1_4"]     = "Money6";
                    nameDicts["ProjectRFA1_5"]     = "Money7";
                    nameDicts["ProjectRFA1_6"]     = "Money8";
                    nameDicts["ProjectRFA1_7"]     = "Money9";
                    nameDicts["ProjectRFA1_8"]     = "Money10";
                    nameDicts["ProjectRFA1_9"]     = "Money11";
                    nameDicts["ProjectRFA2"]       = "Money12";
                    nameDicts["ProjectRFA2_1"]     = "Money12_1";
                    nameDicts["Projectoutlay1"]    = "Year1";
                    nameDicts["Projectoutlay2"]    = "Year2";
                    nameDicts["Projectoutlay3"]    = "Year3";
                    nameDicts["Projectoutlay4"]    = "Year4";
                    nameDicts["Projectoutlay5"]    = "Year5";
                    nameDicts["ProjectRFArm"]      = "Info1";
                    nameDicts["ProjectRFA1rm"]     = "Info2";
                    nameDicts["ProjectRFA1_1rm"]   = "Info3";
                    nameDicts["ProjectRFA1_1_1rm"] = "Info3_1";
                    nameDicts["ProjectRFA1_1_2rm"] = "Info3_2";
                    nameDicts["ProjectRFA1_1_3rm"] = "Info3_3";
                    nameDicts["ProjectRFA1_2rm"]   = "Info4";
                    nameDicts["ProjectRFA1_3rm"]   = "Info5";
                    nameDicts["ProjectRFA1_3_1rm"] = "Info5_1";
                    nameDicts["ProjectRFA1_3_2rm"] = "Info5_2";
                    nameDicts["ProjectRFA1_4rm"]   = "Info6";
                    nameDicts["ProjectRFA1_5rm"]   = "Info7";
                    nameDicts["ProjectRFA1_6rm"]   = "Info8";
                    nameDicts["ProjectRFA1_7rm"]   = "Info9";
                    nameDicts["ProjectRFA1_8rm"]   = "Info10";
                    nameDicts["ProjectRFA1_9rm"]   = "Info11";
                    nameDicts["ProjectRFA2rm"]     = "Info12";
                    nameDicts["ProjectRFA2_1rm"]   = "Info12_1";

                    foreach (DataItem di in dlMoneys.getRows())
                    {
                        try
                        {
                            //添加字典
                            addDict(catalog, proj, "Money,Info", nameDicts[getValueWithDefault <string>(di.get("Name"), string.Empty)], getValueWithDefault <string>(di.get("Value"), string.Empty), string.Empty);
                        }
                        catch (Exception ex) { }
                    }
                }
                #endregion

                #region 处理归一化单位列
                int checkCount = 0;
                int errorCount = 0;

                checkCount++;
                proj.DutyNormalUnit = getNormalNameWithDutyUnit(proj.DutyUnit);
                proj.copyTo(ConnectionManager.Context.table("Project")).where ("ProjectID='" + proj.ProjectID + "'").update();
                if (proj.DutyNormalUnit == "未匹配")
                {
                    errorCount++;
                }

                List <Subject> subjectList22 = ConnectionManager.Context.table("Subject").where ("ProjectID='" + proj.ProjectID + "' and ProjectID = '" + proj.ProjectID + "'").select("*").getList <Subject>(new Subject());
                foreach (Subject sub22 in subjectList22)
                {
                    checkCount++;

                    sub22.DutyNormalUnit = getNormalNameWithDutyUnit(sub22.DutyUnit);
                    sub22.copyTo(ConnectionManager.Context.table("Subject")).where ("SubjectID='" + sub22.SubjectID + "' and ProjectID = '" + proj.ProjectID + "'").update();

                    if (sub22.DutyNormalUnit == "未匹配")
                    {
                        errorCount++;
                    }
                }

                List <Person> personList22 = ConnectionManager.Context.table("Person").where ("ProjectID='" + proj.ProjectID + "'").select("*").getList <Person>(new Person());
                foreach (Person per22 in personList22)
                {
                    checkCount++;

                    per22.WorkNormalUnit = getNormalNameWithDutyUnit(per22.WorkUnit);
                    per22.copyTo(ConnectionManager.Context.table("Person")).where ("PersonID='" + per22.PersonID + "' and ProjectID = '" + proj.ProjectID + "'").update();

                    if (per22.WorkNormalUnit == "未匹配")
                    {
                        errorCount++;
                    }
                }

                catalog.IsCheckUnitComplete = errorCount == 0 ? "通过" : "不通过";
                proj.IsCheckUnitComplete    = errorCount == 0 ? "通过" : "不通过";

                proj.copyTo(ConnectionManager.Context.table("Project")).where ("ProjectID='" + proj.ProjectID + "'").update();
                catalog.copyTo(ConnectionManager.Context.table("Catalog")).where ("CatalogID='" + catalog.CatalogID + "'").update();
                #endregion

                return(catalog.CatalogID);
            }
            else
            {
                return(string.Empty);
            }
        }
Beispiel #6
0
        /// <summary>
        /// 从申报包中解压文档
        /// </summary>
        /// <param name="projectNumber">项目编号</param>
        private void unZipDocFiles(string projectNumber)
        {
            try
            {
                //查找指定申报包
                string[] subDirs = Directory.GetDirectories(MainForm.Config.TotalDir);
                if (subDirs != null)
                {
                    //循环子目录,查找与项目编号相符的目录名称
                    foreach (string s in subDirs)
                    {
                        //获得目录信息
                        DirectoryInfo di = new DirectoryInfo(s);

                        //判断目录是否符合条件
                        if (di.Name.Contains(projectNumber) && di.Name.Length >= 12)
                        {
                            MainForm.writeLog("开始进行项目" + projectNumber + "的解包......");

                            //查找子文件
                            string[] subFiless = Directory.GetFiles(s);
                            if (subFiless != null && subFiless.Length >= 1)
                            {
                                //解压这个Zip包
                                string pkgDir = Path.Combine(MainForm.Config.UnZipDir, projectNumber);

                                //删除解压目录
                                try
                                {
                                    if (Directory.Exists(pkgDir))
                                    {
                                        Directory.Delete(pkgDir, true);
                                    }
                                }
                                catch (Exception ex) { MainForm.writeLog(ex.ToString()); }

                                //创建解压目录
                                try
                                {
                                    Directory.CreateDirectory(pkgDir);
                                }
                                catch (Exception ex) { MainForm.writeLog(ex.ToString()); }

                                //ZIP文件
                                string pkgZipFile = string.Empty;

                                //查找ZIP文件
                                foreach (string sssss in subFiless)
                                {
                                    if (sssss.EndsWith(".zip"))
                                    {
                                        pkgZipFile = sssss;
                                        break;
                                    }
                                }

                                //判断ZIP文件是否存在
                                if (pkgZipFile != null && pkgZipFile.EndsWith(".zip"))
                                {
                                    MainForm.writeLog("项目" + projectNumber + "的解包操作,开始ZIP文件解压");

                                    //解压这个包
                                    new NdeyDocFilesUnZip().UnZipFile(pkgZipFile, pkgDir, string.Empty, true);

                                    MainForm.writeLog("项目" + projectNumber + "的解包操作,结束ZIP文件解压");

                                    //文件目录
                                    string fileDir = pkgDir;

                                    //判断申报包是否有效
                                    //生成DB文件路径
                                    string dbFile = System.IO.Path.Combine(fileDir, "myData.db");
                                    //判断文件是否存在
                                    if (System.IO.File.Exists(dbFile))
                                    {
                                        //SQLite数据库工厂
                                        System.Data.SQLite.SQLiteFactory factory = new System.Data.SQLite.SQLiteFactory();
                                        //NDEY数据库连接
                                        Noear.Weed.DbContext context = new Noear.Weed.DbContext("main", "Data Source = " + dbFile, factory);

                                        try
                                        {
                                            MainForm.writeLog("项目" + projectNumber + "的解包操作,读取论文详细,科技奖项,专利情况信息...");

                                            //提取论文详细
                                            DataList dlRTreatises = context.table("RTreatises").orderBy("RTreatisesOrder desc").select("RTreatisesName,RTreatisesPDF").getDataList();
                                            //提取科技奖项
                                            DataList dlTechnologyAwards = context.table("TechnologyAwards").orderBy("TechnologyAwardsOrder desc").select("TechnologyAwardsPName,TechnologyAwardsPDF").getDataList();
                                            //提取专利情况
                                            DataList dlNDPatent = context.table("NDPatent").orderBy("NDPatentOrder desc").select("NDPatentName,NDPatentPDF").getDataList();
                                            //提取推荐意见
                                            DataList dlBaseInfor = context.table("BaseInfor").select("UnitRecommend,ExpertRecommend1,ExpertRecommend2,ExpertRecommend3").getDataList();

                                            //提取UnitID
                                            string unitID = context.table("BaseInfor").select("UnitID").getValue <string>(string.Empty);

                                            string personName = context.table("BaseInfor").select("UserName").getValue <string>(string.Empty);

                                            //需要删除的文件列表
                                            List <string> needDeleteList = new List <string>();
                                            needDeleteList.AddRange(Directory.GetFiles(fileDir));

                                            //移除正常的申报包文件,把不属于本次申报内容的文件留下
                                            needDeleteList.Remove(dbFile);

                                            MainForm.writeLog("项目" + projectNumber + "的解包操作,开始替换附件名称...");
                                            //附件序号
                                            int fileIndex = 0;
                                            //整理附件名称
                                            foreach (DataItem item in dlRTreatises.getRows())
                                            {
                                                //移除正常的申报包文件,把不属于本次申报内容的文件留下
                                                needDeleteList.Remove(Path.Combine(fileDir, item.getString("RTreatisesPDF")));

                                                //获得文件扩展名
                                                string extName = new FileInfo(Path.Combine(fileDir, item.getString("RTreatisesPDF"))).Extension;

                                                //文件序号+1
                                                fileIndex++;

                                                //文件重命名
                                                try
                                                {
                                                    renameFile(Path.Combine(fileDir, item.getString("RTreatisesPDF")), fileIndex, item.getString("RTreatisesName"), extName);
                                                }
                                                catch (Exception ex)
                                                {
                                                    MainForm.writeLog(ex.ToString());

                                                    addErrorFile(projectNumber, item.getString("RTreatisesPDF"));
                                                }
                                            }
                                            foreach (DataItem item in dlTechnologyAwards.getRows())
                                            {
                                                //移除正常的申报包文件,把不属于本次申报内容的文件留下
                                                needDeleteList.Remove(Path.Combine(fileDir, item.getString("TechnologyAwardsPDF")));

                                                //获得文件扩展名
                                                string extName = new FileInfo(Path.Combine(fileDir, item.getString("TechnologyAwardsPDF"))).Extension;

                                                //文件序号+1
                                                fileIndex++;

                                                //文件重命名
                                                try
                                                {
                                                    renameFile(Path.Combine(fileDir, item.getString("TechnologyAwardsPDF")), fileIndex, item.getString("TechnologyAwardsPName"), extName);
                                                }
                                                catch (Exception ex)
                                                {
                                                    MainForm.writeLog(ex.ToString());

                                                    addErrorFile(projectNumber, item.getString("TechnologyAwardsPDF"));
                                                }
                                            }
                                            foreach (DataItem item in dlNDPatent.getRows())
                                            {
                                                //移除正常的申报包文件,把不属于本次申报内容的文件留下
                                                needDeleteList.Remove(Path.Combine(fileDir, item.getString("NDPatentPDF")));

                                                //获得文件扩展名
                                                string extName = new FileInfo(Path.Combine(fileDir, item.getString("NDPatentPDF"))).Extension;

                                                //文件序号+1
                                                fileIndex++;

                                                //文件重命名
                                                try
                                                {
                                                    renameFile(Path.Combine(fileDir, item.getString("NDPatentPDF")), fileIndex, item.getString("NDPatentName"), extName);
                                                }
                                                catch (Exception ex)
                                                {
                                                    MainForm.writeLog(ex.ToString());

                                                    addErrorFile(projectNumber, item.getString("NDPatentPDF"));
                                                }
                                            }

                                            //整理推荐意见附件
                                            string unitFileA = dlBaseInfor.getRow(0).get("UnitRecommend") != null?dlBaseInfor.getRow(0).get("UnitRecommend").ToString() : string.Empty;

                                            string personFileA = dlBaseInfor.getRow(0).get("ExpertRecommend1") != null?dlBaseInfor.getRow(0).get("ExpertRecommend1").ToString() : string.Empty;

                                            string personFileB = dlBaseInfor.getRow(0).get("ExpertRecommend2") != null?dlBaseInfor.getRow(0).get("ExpertRecommend2").ToString() : string.Empty;

                                            string personFileC = dlBaseInfor.getRow(0).get("ExpertRecommend3") != null?dlBaseInfor.getRow(0).get("ExpertRecommend3").ToString() : string.Empty;

                                            //查找单位推荐意见附件
                                            if (File.Exists(Path.Combine(fileDir, unitFileA)))
                                            {
                                                //移除正常的申报包文件,把不属于本次申报内容的文件留下
                                                needDeleteList.Remove(Path.Combine(fileDir, unitFileA));

                                                //文件序号+1
                                                fileIndex++;

                                                //文件重命名
                                                try
                                                {
                                                    renameFile(Path.Combine(fileDir, unitFileA), fileIndex, "单位推荐意见", new FileInfo(Path.Combine(fileDir, unitFileA)).Extension);
                                                }
                                                catch (Exception ex)
                                                {
                                                    MainForm.writeLog(ex.ToString());

                                                    addErrorFile(projectNumber, unitFileA);
                                                }
                                            }

                                            //查找专家提名附件
                                            if (File.Exists(Path.Combine(fileDir, personFileA)))
                                            {
                                                //移除正常的申报包文件,把不属于本次申报内容的文件留下
                                                needDeleteList.Remove(Path.Combine(fileDir, personFileA));

                                                //文件序号+1
                                                fileIndex++;

                                                //文件重命名
                                                try
                                                {
                                                    renameFile(Path.Combine(fileDir, personFileA), fileIndex, "专家提名", new FileInfo(Path.Combine(fileDir, personFileA)).Extension);
                                                }
                                                catch (Exception ex)
                                                {
                                                    MainForm.writeLog(ex.ToString());

                                                    addErrorFile(projectNumber, personFileA);
                                                }
                                            }

                                            //查找专家提名附件
                                            if (File.Exists(Path.Combine(fileDir, personFileB)))
                                            {
                                                //移除正常的申报包文件,把不属于本次申报内容的文件留下
                                                needDeleteList.Remove(Path.Combine(fileDir, personFileB));

                                                //文件序号+1
                                                fileIndex++;

                                                //文件重命名
                                                try
                                                {
                                                    renameFile(Path.Combine(fileDir, personFileB), fileIndex, "专家提名", new FileInfo(Path.Combine(fileDir, personFileB)).Extension);
                                                }
                                                catch (Exception ex)
                                                {
                                                    MainForm.writeLog(ex.ToString());

                                                    addErrorFile(projectNumber, personFileB);
                                                }
                                            }

                                            //查找专家提名附件
                                            if (File.Exists(Path.Combine(fileDir, personFileC)))
                                            {
                                                //移除正常的申报包文件,把不属于本次申报内容的文件留下
                                                needDeleteList.Remove(Path.Combine(fileDir, personFileC));

                                                //文件序号+1
                                                fileIndex++;

                                                //文件重命名
                                                try
                                                {
                                                    renameFile(Path.Combine(fileDir, personFileC), fileIndex, "专家提名", new FileInfo(Path.Combine(fileDir, personFileC)).Extension);
                                                }
                                                catch (Exception ex)
                                                {
                                                    MainForm.writeLog(ex.ToString());

                                                    addErrorFile(projectNumber, personFileC);
                                                }
                                            }

                                            MainForm.writeLog("项目" + projectNumber + "的解包操作,结束替换附件名称...");

                                            MainForm.writeLog("项目" + projectNumber + "的解包操作,开始处理保密资质附件和申报书文档转PDF...");

                                            //是否已经找到Doc文件
                                            bool isFoundDocFile = false;

                                            //上一个保密资质修改时间
                                            DateTime lastExtFileModifyTime = DateTime.MinValue;

                                            //整理保密资质命名,查找Doc文件
                                            string[] extFiles = Directory.GetFiles(fileDir);
                                            foreach (string sss in extFiles)
                                            {
                                                FileInfo fii = new FileInfo(sss);
                                                if (fii.Name.StartsWith("extFile_"))
                                                {
                                                    try
                                                    {
                                                        //查看最后创建的文件
                                                        if (fii.LastWriteTime > lastExtFileModifyTime)
                                                        {
                                                            //只有第一个extFile才分配文件序号
                                                            if (lastExtFileModifyTime == DateTime.MinValue)
                                                            {
                                                                //文件序号+1
                                                                fileIndex++;
                                                            }

                                                            //记录当前创建时间
                                                            lastExtFileModifyTime = fii.LastWriteTime;
                                                        }
                                                        else
                                                        {
                                                            continue;
                                                        }

                                                        //移除正常的申报包文件,把不属于本次申报内容的文件留下
                                                        needDeleteList.Remove(sss);

                                                        //移动文件
                                                        renameFile(sss, fileIndex, "保密资质复印件", ".png");
                                                    }
                                                    catch (Exception ex)
                                                    {
                                                        MainForm.writeLog(ex.ToString());

                                                        addErrorFile(projectNumber, fii.Name);
                                                    }
                                                }
                                                else if (fii.Name.EndsWith(".doc"))
                                                {
                                                    //移除正常的申报包文件,把不属于本次申报内容的文件留下
                                                    needDeleteList.Remove(sss);

                                                    if (fii.Name.StartsWith(unitID) && fii.Name.Contains(personName))
                                                    {
                                                        //找到Doc文件
                                                        isFoundDocFile = true;

                                                        //真实的申报书路径
                                                        string destDocFile = Path.Combine(fii.DirectoryName, "项目申报书.doc");

                                                        //文件改名
                                                        try
                                                        {
                                                            File.Move(sss, destDocFile);
                                                        }
                                                        catch (Exception ex)
                                                        {
                                                            MainForm.writeLog(ex.ToString());

                                                            addErrorFile(projectNumber, fii.Name);
                                                        }

                                                        //转换成PDF
                                                        convertToPDF(projectNumber, destDocFile);
                                                    }
                                                    else
                                                    {
                                                        if (fii.Name.EndsWith("项目申报书.doc"))
                                                        {
                                                            try
                                                            {
                                                                File.Delete(sss);
                                                            }
                                                            catch (Exception ex) { MainForm.writeLog(ex.ToString()); }
                                                        }
                                                    }
                                                }
                                            }

                                            //判断是否存在不属于本次申报包的文件
                                            if (needDeleteList != null && needDeleteList.Count >= 1)
                                            {
                                                MainForm.writeLog("项目" + projectNumber + "的解包操作,开始移除不属于本次申报包的文件");
                                                //删除不属于本次申报包的内容
                                                foreach (string needdelete in needDeleteList)
                                                {
                                                    try
                                                    {
                                                        File.Delete(needdelete);
                                                    }
                                                    catch (Exception ex)
                                                    {
                                                        MainForm.writeLog(ex.ToString());
                                                    }
                                                }
                                                MainForm.writeLog("项目" + projectNumber + "的解包操作,开始移除不属于本次申报包的文件");
                                            }

                                            //判断是否找到Doc文件
                                            if (isFoundDocFile)
                                            {
                                                //找到DOC文件
                                                //MainForm.writeLog("项目申报书已找到!");
                                            }
                                            else
                                            {
                                                //没有找到Doc文件
                                                MainForm.writeLog("对不起,没有找到项目申报书!");
                                                //输出缺失的文件
                                                addErrorFile(projectNumber, "项目申报书.doc");
                                            }

                                            MainForm.writeLog("项目" + projectNumber + "的解包操作,结束处理保密资质附件和申报书文档转PDF...");
                                        }
                                        catch (Exception ex)
                                        {
                                            MainForm.writeLog(ex.ToString());
                                        }
                                        finally
                                        {
                                            factory.Dispose();
                                            context.Dispose();
                                            context = null;

                                            //**链接close()和dispose()之后任然不能释放与db文件的连接,原因是sqlite在执行SQLiteConnectionHandle.Dispose()操作时候,其实并没有真正的释放连接,只有显式调用 CLR垃圾回收之后才能真正释放连接
                                            GC.Collect();
                                            GC.WaitForPendingFinalizers();

                                            //删除数据库文件
                                            try
                                            {
                                                File.Delete(dbFile);
                                            }
                                            catch (Exception ex) { }
                                        }
                                    }
                                    else
                                    {
                                        MainForm.writeLog("没有找到DB文件__" + projectNumber);
                                    }
                                }
                                else
                                {
                                    MainForm.writeLog("没有找到ZIP文件__" + projectNumber);
                                }
                            }
                            else
                            {
                                MainForm.writeLog("没有找到ZIP文件__" + projectNumber);
                            }

                            MainForm.writeLog("结束进行项目" + projectNumber + "的解包......");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MainForm.writeLog("项目编号" + projectNumber + "解包错误,Ex:" + ex.ToString());
            }
        }
        /// <summary>
        /// 导入数据库
        /// </summary>
        /// <returns></returns>
        protected override string importDB(string zipFile, string catalogNumber, string sourceFile, Noear.Weed.DbContext localContext)
        {
            //数据库版本号
            string catalogVersionStr = "v1.0";

            //附件目录
            string filesDir = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(sourceFile), "Files");

            //处理项目信息
            DataItem diProject = localContext.table("Projects").select("*").getDataItem();

            if (diProject != null && diProject.count() >= 1)
            {
                #region 读取版本号并更新Catalog信息
                //读取版本号
                try
                {
                    catalogVersionStr = localContext.table("Version").select("VersionNum").getValue <string>(catalogVersionStr);
                }
                catch (Exception ex) { }

                //更新Catalog
                Catalog catalog = updateAndClearCatalog(catalogNumber, diProject.getString("ProjectName"), "战略先导", catalogVersionStr, zipFile);
                #endregion

                #region 导入项目
                //添加项目信息
                Project proj = new Project();
                proj.ProjectID   = catalog.CatalogID;
                proj.CatalogID   = catalog.CatalogID;
                proj.ProjectName = catalog.CatalogName;

                try
                {
                    proj.ProjectTopic = diProject.get("ProjectTopic") != null?diProject.get("ProjectTopic").ToString() : string.Empty;
                }
                catch (Exception ex) { }

                try
                {
                    proj.ProjectDirection = diProject.get("ProjectDirection") != null?diProject.get("ProjectDirection").ToString() : string.Empty;
                }
                catch (Exception ex) { }

                try
                {
                    proj.ProjectSecretLevel = diProject.get("ProjectSecretLevel") != null?diProject.get("ProjectSecretLevel").ToString() : string.Empty;
                }
                catch (Exception ex) { }

                try
                {
                    proj.ProjectMasterName = diProject.get("ProjectMasterName") != null?diProject.get("ProjectMasterName").ToString() : string.Empty;
                }
                catch (Exception ex) { }

                try
                {
                    proj.ProjectMasterSex = diProject.get("ProjectMasterSex") != null?diProject.get("ProjectMasterSex").ToString() : string.Empty;
                }
                catch (Exception ex) { }

                try
                {
                    proj.ProjectMasterBirthday = diProject.get("ProjectMasterBirthday") != null?DateTime.Parse(diProject.get("ProjectMasterBirthday").ToString()) : DateTime.Now;
                }
                catch (Exception ex) { }

                try
                {
                    proj.ProjectMasterJob = diProject.get("ProjectMasterJob") != null?diProject.get("ProjectMasterJob").ToString() : string.Empty;
                }
                catch (Exception ex) { }

                try
                {
                    proj.ProjectMasterTelephone = diProject.get("ProjectMasterTelephone") != null?diProject.get("ProjectMasterTelephone").ToString() : string.Empty;
                }
                catch (Exception ex) { }

                try
                {
                    proj.ProjectMasterMobilephone = diProject.get("ProjectMasterMobilephone") != null?diProject.get("ProjectMasterMobilephone").ToString() : string.Empty;
                }
                catch (Exception ex) { }

                try
                {
                    proj.TeamContactName = diProject.get("TeamContactName") != null?diProject.get("TeamContactName").ToString() : string.Empty;
                }
                catch (Exception ex) { }

                try
                {
                    proj.TeamContactSex = diProject.get("TeamContactSex") != null?diProject.get("TeamContactSex").ToString() : string.Empty;
                }
                catch (Exception ex) { }

                try
                {
                    proj.TeamContactBirthday = diProject.get("TeamContactBirthday") != null?DateTime.Parse(diProject.get("TeamContactBirthday").ToString()) : DateTime.Now;
                }
                catch (Exception ex) { }

                try
                {
                    proj.TeamContactJob = diProject.get("TeamContactJob") != null?diProject.get("TeamContactJob").ToString() : string.Empty;
                }
                catch (Exception ex) { }

                try
                {
                    proj.TeamContactTelephone = diProject.get("TeamContactTelephone") != null?diProject.get("TeamContactTelephone").ToString() : string.Empty;
                }
                catch (Exception ex) { }

                try
                {
                    proj.TeamContactMobilephone = diProject.get("TeamContactMobilephone") != null?diProject.get("TeamContactMobilephone").ToString() : string.Empty;
                }
                catch (Exception ex) { }

                try
                {
                    proj.TeamContactAddress = diProject.get("TeamContactAddress") != null?diProject.get("TeamContactAddress").ToString() : string.Empty;
                }
                catch (Exception ex) { }

                try
                {
                    proj.UnitName = diProject.get("UnitName") != null?diProject.get("UnitName").ToString() : string.Empty;
                }
                catch (Exception ex) { }

                try
                {
                    proj.UnitRealName = diProject.get("UnitRealName") != null?diProject.get("UnitRealName").ToString() : string.Empty;
                }
                catch (Exception ex) { }

                try
                {
                    proj.UnitAddress = diProject.get("UnitAddress") != null?diProject.get("UnitAddress").ToString() : string.Empty;
                }
                catch (Exception ex) { }

                try
                {
                    proj.UnitType2 = diProject.get("UnitType2") != null?diProject.get("UnitType2").ToString() : string.Empty;
                }
                catch (Exception ex) { }

                try
                {
                    proj.UnitContact = diProject.get("UnitContact") != null?diProject.get("UnitContact").ToString() : string.Empty;
                }
                catch (Exception ex) { }

                try
                {
                    proj.UnitContactJob = diProject.get("UnitContactJob") != null?diProject.get("UnitContactJob").ToString() : string.Empty;
                }
                catch (Exception ex) { }

                try
                {
                    proj.UnitContactPhone = diProject.get("UnitContactPhone") != null?diProject.get("UnitContactPhone").ToString() : string.Empty;
                }
                catch (Exception ex) { }

                try
                {
                    proj.TotalTime = diProject.get("TotalTime") != null?int.Parse(diProject.get("TotalTime").ToString()) : 0;
                }
                catch (Exception ex) { }

                try
                {
                    proj.TotalMoney = diProject.get("TotalMoney") != null?decimal.Parse(diProject.get("TotalMoney").ToString()) : 0;
                }
                catch (Exception ex) { }

                try
                {
                    proj.RequestTime = diProject.get("RequestTime") != null?DateTime.Parse(diProject.get("RequestTime").ToString()) : DateTime.Now;
                }
                catch (Exception ex) { }

                try
                {
                    string   workDestDocFile     = System.IO.Path.Combine(filesDir, "研究目标.doc");
                    string   workDestDestTxtFile = System.IO.Path.Combine(filesDir, "研究目标.txt");
                    Document doc = new Document(workDestDocFile);
                    doc.Save(workDestDestTxtFile);
                    proj.WorkDest = System.IO.File.ReadAllText(workDestDestTxtFile);
                }
                catch (Exception ex) { }

                proj.copyTo(ConnectionManager.Context.table("Project")).insert();
                #endregion

                #region 导入课题
                DataList dlSubjects = localContext.table("Subjects").select("*").getDataList();
                foreach (DataItem diSubject in dlSubjects.getRows())
                {
                    Subject subjectObj = new Subject();
                    subjectObj.SubjectID = Guid.NewGuid().ToString();
                    subjectObj.CatalogID = proj.CatalogID;
                    subjectObj.ProjectID = proj.ProjectID;

                    try
                    {
                        subjectObj.SubjectName = diSubject.get("SubjectName") != null?diSubject.get("SubjectName").ToString() : string.Empty;
                    }
                    catch (Exception ex) { }

                    try
                    {
                        subjectObj.SecretLevel = diSubject.get("SecretLevel") != null?diSubject.get("SecretLevel").ToString() : string.Empty;
                    }
                    catch (Exception ex) { }

                    try
                    {
                        subjectObj.TotalTime = int.Parse(diSubject.get("TotalTime") != null ? diSubject.get("TotalTime").ToString() : string.Empty);
                    }
                    catch (Exception ex) { }

                    try
                    {
                        subjectObj.TotalMoney = decimal.Parse(diSubject.get("TotalMoney") != null ? diSubject.get("TotalMoney").ToString() : string.Empty);
                    }
                    catch (Exception ex) { }

                    try
                    {
                        subjectObj.UnitName = diSubject.get("UnitName") != null?diSubject.get("UnitName").ToString() : string.Empty;
                    }
                    catch (Exception ex) { }

                    try
                    {
                        subjectObj.UnitAddress = diSubject.get("UnitAddress") != null?diSubject.get("UnitAddress").ToString() : string.Empty;
                    }
                    catch (Exception ex) { }

                    try
                    {
                        subjectObj.UnitType2 = diSubject.get("UnitType2") != null?diSubject.get("UnitType2").ToString() : string.Empty;
                    }
                    catch (Exception ex) { }

                    try
                    {
                        subjectObj.UnitContact = diSubject.get("UnitContact") != null?diSubject.get("UnitContact").ToString() : string.Empty;
                    }
                    catch (Exception ex) { }

                    try
                    {
                        subjectObj.UnitContactJob = diSubject.get("UnitContactJob") != null?diSubject.get("UnitContactJob").ToString() : string.Empty;
                    }
                    catch (Exception ex) { }

                    try
                    {
                        subjectObj.UnitContactPhone = diSubject.get("UnitContactPhone") != null?diSubject.get("UnitContactPhone").ToString() : string.Empty;
                    }
                    catch (Exception ex) { }

                    subjectObj.copyTo(ConnectionManager.Context.table("Subject")).insert();
                }
                #endregion

                return(catalog.CatalogID);
            }
            else
            {
                return(string.Empty);
            }
        }
Beispiel #8
0
 /*查询语句*/
 public DbQuery(DbContext context) : base(context)
 {
 }