Пример #1
0
        /// <summary>
        /// 运行代码
        /// </summary>
        /// <param name="total">总进度</param>
        /// <param name="cur">当前进度</param>
        /// <param name="ehDynamic">工作事件</param>
        public void run(int total, int cur, EventHandler ehDynamic)
        {
            Start(new EventHandler <CircleProgressBarEventArgs>(delegate(object thisObject, CircleProgressBarEventArgs argss)
            {
                CircleProgressBarDialog senderDialog = ((CircleProgressBarDialog)thisObject);

                //计算每个进度占比
                progressPercent = (decimal)100 / (decimal)total;

                //显示初始进度
                senderDialog.ReportProgress((int)((decimal)cur * progressPercent), 100);

                //运行工作事件
                if (ehDynamic != null)
                {
                    try
                    {
                        ehDynamic(this, new EventArgs());
                    }
                    catch (Exception ex)
                    {
                        BaseModuleMainFormWithUIConfig.writeLog(ex.ToString());
                    }
                }

                //异常本窗体
                if (senderDialog.IsHandleCreated)
                {
                    senderDialog.Invoke(new MethodInvoker(delegate()
                    {
                        Visible = false;
                    }));
                }

                //检查是否需要显示错误日志
                if (errorCount >= 1 && isNeedShowLog)
                {
                    //错误数量清空
                    errorCount = 0;

                    //日志路径
                    string logFile = System.IO.Path.Combine(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Logs"), string.Format("{0}.txt", DateTime.Now.ToString("yyyyMMdd")));

                    //询问是否需要显示日志
                    if (MessageBox.Show("是否需要打开错误日志文件?", "提示", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
                    {
                        //打开日志文件
                        try
                        {
                            System.Diagnostics.Process.Start(logFile);
                        }
                        catch (Exception ex) { }
                    }
                }
            }));
        }
Пример #2
0
 /// <summary>
 /// 显示进度
 /// </summary>
 /// <param name="progressDialog"></param>
 /// <param name="progress"></param>
 /// <param name="txt"></param>
 /// <param name="sleepTime"></param>
 private static void Report(CircleProgressBarDialog progressDialog, int progress, string txt, int sleepTime)
 {
     progressDialog.ReportProgress(progress, 100);
     progressDialog.ReportInfo(txt);
     try
     {
         Thread.Sleep(sleepTime);
     }
     catch (Exception ex) { }
 }
Пример #3
0
        private void exportPkg(string currentDir, FormClosingEventArgs e)
        {
            if (needExport)
            {
                //检查是否文件被占有了
                bool          acceptExport = true;
                List <string> filesList    = new List <string>();
                filesList.AddRange(Directory.GetFiles(currentDir));
                filesList.AddRange(Directory.GetFiles(Path.Combine(currentDir, "Files")));
                foreach (string s in filesList)
                {
                    if (s != null && s.Contains("static.db"))
                    {
                        continue;
                    }
                    else
                    {
                        if (IsFileInUse(s))
                        {
                            e.Cancel     = true;
                            acceptExport = false;
                            MessageBox.Show("对不起,文件(" + s + ")被占用,无法导出!");
                            break;
                        }
                    }
                }

                //导出
                if (acceptExport)
                {
                    //检查目标文件是否存在,如果存在则删除
                    string destFile = DestZipPath;
                    if (File.Exists(destFile))
                    {
                        try
                        {
                            File.Delete(destFile);
                        }
                        catch (Exception ex) { }
                    }

                    try
                    {
                        CircleProgressBarDialog dialoga = new CircleProgressBarDialog();
                        dialoga.TransparencyKey        = dialoga.BackColor;
                        dialoga.ProgressBar.ForeColor  = Color.Red;
                        dialoga.MessageLabel.ForeColor = Color.Blue;
                        dialoga.FormBorderStyle        = FormBorderStyle.None;
                        dialoga.Start(new EventHandler <CircleProgressBarEventArgs>(delegate(object thisObject, CircleProgressBarEventArgs argss)
                        {
                            CircleProgressBarDialog senderForm = ((CircleProgressBarDialog)thisObject);

                            senderForm.ReportProgress(10, 100);
                            senderForm.ReportInfo("准备导出...");
                            try { System.Threading.Thread.Sleep(1000); }
                            catch (Exception ex) { }

                            #region 尝试关闭Sqlite数据库连接
                            try
                            {
                                dynamic script = CSScriptLibrary.CSScript.LoadCode(
                                    @"using System.Windows.Forms;
                             public class Script
                             {
                                 public void CloseDB()
                                 {
                                     ProjectMilitaryTechnologPlanPlugin.DB.ConnectionManager.Close();
                                 }
                             }")
                                                 .CreateObject("*");
                                script.CloseDB();
                            }
                            catch (Exception ex) { }
                            #endregion

                            senderForm.ReportProgress(20, 100);
                            senderForm.ReportInfo("正在导出...");
                            try { System.Threading.Thread.Sleep(1000); }
                            catch (Exception ex) { }

                            //压缩
                            new PublicReporterLib.Utility.ZipUtil().ZipFileDirectory(currentDir, destFile);

                            senderForm.ReportProgress(90, 100);
                            senderForm.ReportInfo("导出完成...");
                            try { System.Threading.Thread.Sleep(1000); }
                            catch (Exception ex) { }

                            //导出完成事件
                            if (senderForm.IsHandleCreated)
                            {
                                senderForm.Invoke(new MethodInvoker(delegate()
                                {
                                    if (OnExportComplete != null)
                                    {
                                        OnExportComplete(this, new ExportCompleteEventArgs(DestZipPath));
                                    }
                                }));
                            }
                        }));
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("导出失败!Ex:" + ex.ToString());
                    }
                }
            }
        }