Exemplo n.º 1
0
        private void dgvCatalogs_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            //检查是否点击的是删除的那一列
            if (e.ColumnIndex == dgvCatalogs.Columns.Count - 1)
            {
                //获得要删除的项目ID,项目编号
                string projectId     = ((Catalog)dgvCatalogs.Rows[e.RowIndex].Tag).CatalogID;
                string projectNumber = ((Catalog)dgvCatalogs.Rows[e.RowIndex].Tag).CatalogNumber;

                //显示删除提示框
                if (MessageBox.Show("真的要删除吗?", "提示", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
                {
                    //删除项目数据
                    ReporterDBImporter.deleteProject(projectId);

                    //删除申报包缓存
                    try
                    {
                        System.IO.Directory.Delete(System.IO.Path.Combine(PackageDir, projectNumber), true);
                    }
                    catch (Exception ex) { MainForm.writeLog(ex.ToString()); }

                    //刷新GridView
                    reloadCatalogList();
                }
            }
        }
        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();
        }