/// <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) { } }
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()); } } } }