private void btnOK_Click(object sender, EventArgs e)
        {
            //需要替换的申报包列表
            List <string> importList         = new List <string>();
            List <string> importFileNameList = new List <string>();

            #region 查的需要导入的路径
            foreach (TreeNode tn in tvSubDirs.Nodes)
            {
                //判断是否被选中
                if (tn.Checked)
                {
                    //读取目录名称中的项目编号
                    string projectNumber = tn.Text;

                    //判断是否需要替换
                    if (replaceDict.ContainsKey(projectNumber))
                    {
                        //需要替换

                        //判断是否替换这个项目
                        if (replaceDict[projectNumber])
                        {
                            //需要替换,添加到ImportList列表中
                            importList.Add(Path.Combine(tn.Name, ""));
                            importFileNameList.Add(tn.Text);
                        }
                        else
                        {
                            //不需要替换
                            continue;
                        }
                    }
                    else
                    {
                        //不需要替换
                        importList.Add(Path.Combine(tn.Name, ""));
                        importFileNameList.Add(tn.Text);
                    }
                }
            }
            #endregion

            //开始导入
            ProgressForm pf = new ProgressForm();
            pf.Show();
            pf.run(importList.Count, 0, new EventHandler(delegate(object senders, EventArgs ee)
            {
                //进度数值
                int progressVal = 0;
                int index       = -1;
                //导入
                foreach (string pDir in importList)
                {
                    try
                    {
                        progressVal++;
                        index++;
                        //申报文件名
                        string createFileName     = importFileNameList[index].ToString();
                        string tempname           = createFileName.Substring(0, createFileName.IndexOf("-", 5));
                        List <string> messageList = null;
                        pf.reportProgress(progressVal, createFileName + "_开始解压");
                        bool returnContent = unZipFile(pDir, createFileName, out messageList);
                        if (returnContent)
                        {
                            //报告进度
                            pf.reportProgress(progressVal, createFileName + "_开始导入");
                            MainForm.writeLog("开始导入__" + createFileName);

                            //导入数据库
                            ReporterDBImporter.addOrReplaceProject(createFileName, Path.Combine(Path.Combine(MainForm.Config.UnZipDir, createFileName), "static.db"));

                            //报告进度
                            pf.reportProgress(progressVal, createFileName + "_结束导入");
                            MainForm.writeLog("结束导入__" + createFileName);
                        }
                        pf.reportProgress(progressVal, createFileName + "_结束解压");
                    }
                    catch (Exception ex)
                    {
                        MainForm.writeLog(ex.ToString());
                    }
                }

                //检查是否已创建句柄,并调用委托执行UI方法
                if (pf.IsHandleCreated)
                {
                    pf.Invoke(new MethodInvoker(delegate()
                    {
                        try
                        {
                            //刷新Catalog列表
                            MainForm.Instance.reloadCatalogList();

                            //关闭进度窗口
                            pf.Close();
                        }
                        catch (Exception ex)
                        {
                            MainForm.writeLog(ex.ToString());
                        }
                    }));
                }
            }));

            //关闭窗口
            Close();
        }
Example #2
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            //需要替换的申报包列表
            List <string> importList = new List <string>();

            #region 查的需要导入的路径
            foreach (TreeNode tn in tvSubDirs.Nodes)
            {
                //判断是否被选中
                if (tn.Checked)
                {
                    //读取目录名称中的项目编号
                    string projectNumber = tn.Text.Substring(0, 11);

                    //将需要处理的申报包添加到列表中
                    importList.Add(Path.Combine(MainForm.Config.TotalDir, tn.Text));
                }
            }
            #endregion

            //检查是否已创建句柄,并调用委托执行UI方法
            if (IsHandleCreated)
            {
                Invoke(new MethodInvoker(delegate()
                {
                    //隐藏本窗体
                    Top = Screen.PrimaryScreen.Bounds.Height * 2;
                }));
            }

            //开始导入
            ProgressForm pf = new ProgressForm();
            pf.Show();
            pf.run(importList.Count, 0, new EventHandler(delegate(object senders, EventArgs ee)
            {
                //进度数值
                int progressVal = 0;
                //导入
                foreach (string pDir in importList)
                {
                    try
                    {
                        progressVal++;

                        //读取项目ID
                        string projectNumber = new DirectoryInfo(pDir).Name.Substring(0, 11);

                        //报告进度
                        pf.reportProgress(progressVal, string.Empty);

                        //报告进度
                        pf.reportProgress(progressVal, projectNumber + "_开始解压");

                        //解压ZIP包
                        unZipDocFiles(projectNumber);

                        //报告进度
                        pf.reportProgress(progressVal, projectNumber + "_结束解压");
                    }
                    catch (Exception ex)
                    {
                        MainForm.writeLog(ex.ToString());
                    }
                }

                //检查是否已创建句柄,并调用委托执行UI方法
                if (IsHandleCreated)
                {
                    Invoke(new MethodInvoker(delegate()
                    {
                        try
                        {
                            //关闭进度窗口
                            pf.Close();
                        }
                        catch (Exception ex)
                        {
                            MainForm.writeLog(ex.ToString());
                        }

                        //尝试输出Excel日志
                        if (errorFileList != null && errorFileList.Count >= 1)
                        {
                            writeErrorExcelFile();
                        }

                        //关闭窗口
                        Close();
                    }));
                }
            }));
        }