You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
697 lines
25 KiB
C#
697 lines
25 KiB
C#
using Rs.Motion.GugaoEcat;
|
|
using Rs.Motion;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using Rs.Controls;
|
|
using Rs.MotionPlat.Flow;
|
|
using Rs.Framework;
|
|
using Rs.Camera;
|
|
using System.Threading;
|
|
using Rs.MotionPlat.Commom;
|
|
using static System.Runtime.CompilerServices.RuntimeHelpers;
|
|
using Rs.Motion.GugaoPulse;
|
|
using Rs.MotionPlat.SysConfig;
|
|
using System.Runtime.InteropServices;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using Rs.MotionPlat.Entitys;
|
|
using Rs.MotionPlat.Flow.SubFlow;
|
|
|
|
namespace Rs.MotionPlat
|
|
{
|
|
public partial class Home : BaseFormHeader
|
|
{
|
|
ButtonEx selectedButton;
|
|
public Home()
|
|
{
|
|
this.StartPosition = FormStartPosition.Manual;
|
|
InitializeComponent();
|
|
this.FormBorderStyle = FormBorderStyle.None;
|
|
this.MaximizedBounds = Screen.PrimaryScreen.WorkingArea;
|
|
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
|
|
}
|
|
|
|
void CloseSubWindow()
|
|
{
|
|
foreach(Control f in panel_main.Controls)
|
|
{
|
|
if(f is Form && ((Form)f).Name!= "FormMain")
|
|
{
|
|
((Form)f).Close();
|
|
}
|
|
}
|
|
panel_main.Controls.Clear();
|
|
}
|
|
protected void Menu_Clicked(object sender, EventArgs e)
|
|
{
|
|
ButtonEx button = (ButtonEx)sender;
|
|
|
|
if (button == btnSystem)
|
|
{
|
|
selectedButton = btnSystem;
|
|
ClearSelectBtn();
|
|
button.Selected = true;
|
|
CloseSubWindow();
|
|
BaseForm from = new SubMenuForm("SysConfig");
|
|
from.TopLevel = false;
|
|
from.Dock = DockStyle.Fill;
|
|
panel_main.Controls.Add(from);
|
|
from.Visible = true;
|
|
}
|
|
|
|
if (button == btnData)
|
|
{
|
|
if (Properties.Settings.Default.DefaultLanguage== "zh-CN")
|
|
{
|
|
LanguageHelper.SetDefaultLanguage("en-US");
|
|
}
|
|
else
|
|
{
|
|
LanguageHelper.SetDefaultLanguage("zh-CN");
|
|
}
|
|
FormCollection forms = Application.OpenForms;
|
|
foreach (Form fm in forms)
|
|
{
|
|
if (fm is SubMenuForm)
|
|
{
|
|
((SubMenuForm)fm).ReloadMenu();
|
|
}
|
|
else
|
|
{
|
|
if(fm.Name!= "Home")
|
|
{
|
|
LanguageHelper.LoadLanguage(fm, fm.GetType());
|
|
}
|
|
else
|
|
{
|
|
ChangeLang();
|
|
}
|
|
|
|
//if (fm is Home)
|
|
//{
|
|
// fm.FormBorderStyle = FormBorderStyle.None;
|
|
// //fm.MaximizedBounds = Screen.PrimaryScreen.WorkingArea;
|
|
// fm.ResumeLayout();
|
|
// fm.WindowState = System.Windows.Forms.FormWindowState.Maximized;
|
|
//}
|
|
}
|
|
|
|
}
|
|
//btnMain.PerformClick();
|
|
//if(selectedButton!=null)
|
|
//{
|
|
// selectedButton.PerformClick();
|
|
//}
|
|
forms = Application.OpenForms;
|
|
foreach (Form fm in forms)
|
|
{
|
|
if (fm is SubMenuForm)
|
|
{
|
|
((SubMenuForm)fm).SelectTab();
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
//ClearSelectBtn();
|
|
//button.Selected = true;
|
|
//CloseSubWindow();
|
|
//BaseForm from = new SubMenuForm("Data");
|
|
//from.TopLevel = false;
|
|
//from.Dock = DockStyle.Fill;
|
|
//panel_main.Controls.Add(from);
|
|
//from.Visible = true;
|
|
}
|
|
|
|
else if (button == btnMain)
|
|
{
|
|
selectedButton = btnMain;
|
|
ClearSelectBtn();
|
|
button.Selected = true;
|
|
CloseSubWindow();
|
|
FormMain form = (FormMain)ActiveForms.Get("FormMain");
|
|
if(form!=null)
|
|
{
|
|
form.ReloadParameters();
|
|
panel_main.Controls.Add(form);
|
|
form.TopLevel = false;
|
|
form.Dock = DockStyle.Fill;
|
|
form.Visible = true;
|
|
}
|
|
else
|
|
{
|
|
form = new FormMain();
|
|
form.Name = "FormMain";
|
|
form.TopLevel = false;
|
|
form.Dock = DockStyle.Fill;
|
|
panel_main.Controls.Add(form);
|
|
form.Visible = true;
|
|
ActiveForms.Add(form);
|
|
}
|
|
|
|
}
|
|
else if (button == btnQuit)
|
|
{
|
|
selectedButton = null;
|
|
button.Selected = false;
|
|
if(WindowsClose())
|
|
{
|
|
System.Environment.Exit(-1);
|
|
}
|
|
}
|
|
else if (button == btnRecipe)
|
|
{
|
|
selectedButton = btnRecipe;
|
|
ClearSelectBtn();
|
|
button.Selected = true;
|
|
CloseSubWindow();
|
|
BaseForm from = new SubMenuForm("Recipe");
|
|
from.TopLevel = false;
|
|
from.Dock = DockStyle.Fill;
|
|
panel_main.Controls.Add(from);
|
|
from.Visible = true;
|
|
}
|
|
else if (button == btnAbout)
|
|
{
|
|
selectedButton = null;
|
|
btnAbout.Enabled = false;
|
|
BaseFormHeader form;
|
|
form = new DebugMove(ShowBtn);
|
|
//form = DebugMove.Instance;
|
|
form.HeaderBackgroundColor = Color.Gray;
|
|
form.TopMost = true;
|
|
form.ShowMax = false;
|
|
form.ShowMin = false;
|
|
form.ShowInTaskbar = false;
|
|
form.Location = new Point(this.Width - form.Width, this.Height - form.Height);
|
|
form.Show(this);
|
|
}
|
|
else if (button == btnPermission)
|
|
{
|
|
if(btnPermission.ShowText.IndexOf("-")>0)
|
|
{
|
|
DialogResult dr = Msg.ShowQuestion("Are you sure to exit login?");
|
|
if(dr== DialogResult.OK)
|
|
{
|
|
GlobalUser.UserName = "";
|
|
btnPermission.ShowText=btnPermission.ShowText.Substring(0,btnPermission.ShowText.IndexOf("-"));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
selectedButton = null;
|
|
UserForm form;
|
|
form = new UserForm();
|
|
form.OnloginSuccessEvent += (uname) => {
|
|
btnPermission.ShowText += $"-({uname})";
|
|
//btnMain.PerformClick();
|
|
};
|
|
form.StartPosition = FormStartPosition.CenterScreen;
|
|
form.Opacity = 1;
|
|
form.TopMost = true;
|
|
form.ShowDialog(this);
|
|
}
|
|
|
|
}
|
|
else if (button == btnLanguage)
|
|
{
|
|
selectedButton = null;
|
|
//if (GlobalUser.IsVender() || GlobalUser.IsSuper())
|
|
{
|
|
ClearSelectBtn();
|
|
button.Selected = true;
|
|
CloseSubWindow();
|
|
BaseForm from = new SubMenuForm("Calib");
|
|
from.TopLevel = false;
|
|
from.Dock = DockStyle.Fill;
|
|
panel_main.Controls.Add(from);
|
|
from.Visible = true;
|
|
}
|
|
|
|
// btnLanguage.Enabled = false;
|
|
//VarConfig vc = new VarConfig(ShowBtn);
|
|
// vc.StartPosition = FormStartPosition.CenterScreen;
|
|
// vc.Show();
|
|
}
|
|
}
|
|
|
|
private void Form_OnloginSuccessEvent(string obj)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
private void ShowBtn(string btnname)
|
|
{
|
|
if(btnname== "DebugMove")
|
|
{
|
|
btnAbout.Enabled = true;
|
|
}
|
|
else if(btnname== "VarConfig")
|
|
{
|
|
btnLanguage.Enabled = true ;
|
|
}
|
|
}
|
|
|
|
private void ClearSelectBtn()
|
|
{
|
|
btnMain.Selected = false;
|
|
btnData.Selected = false;
|
|
btnRecipe.Selected = false;
|
|
btnSystem.Selected = false;
|
|
btnAbout.Selected = false;
|
|
btnPermission.Selected = false;
|
|
btnLanguage.Selected = false;
|
|
btnQuit.Selected = false;
|
|
}
|
|
|
|
private void Home2_Load(object sender, EventArgs e)
|
|
{
|
|
if (GlobalVar.CheckVisionSwOpened)
|
|
{
|
|
while (true)
|
|
{
|
|
string vname = "KImage";
|
|
Process[] progresses = Process.GetProcesses();
|
|
if (progresses.Where(p => p.ProcessName == vname).Count() == 0)
|
|
{
|
|
Msgbox.ShowTipDialog(EButtonType.Retry, "Vision software hasn't open,please open vision software!");
|
|
}
|
|
else
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
string language = Properties.Settings.Default.DefaultLanguage;
|
|
Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(language);
|
|
LanguageHelper.LoadLanguage(this, typeof(Home));
|
|
if(language=="zh-CN")
|
|
{
|
|
btnMain.ShowText = "主页";
|
|
btnRecipe.ShowText = "配方";
|
|
btnSystem.ShowText = "系统配置";
|
|
btnAbout.ShowText = "调试";
|
|
btnData.ShowText = "English";
|
|
btnLanguage.ShowText = "标定";
|
|
btnPermission.ShowText = "用户";
|
|
btnQuit.ShowText = "退出";
|
|
}
|
|
else
|
|
{
|
|
btnMain.ShowText = "Home";
|
|
btnRecipe.ShowText = "Recipe";
|
|
btnSystem.ShowText = "Settings";
|
|
btnAbout.ShowText = "Debuger";
|
|
btnLanguage.ShowText = "Vision calibration";
|
|
btnPermission.ShowText = "User";
|
|
btnQuit.ShowText = "Quit";
|
|
btnData.ShowText = "中文";
|
|
}
|
|
timer1.Enabled = false;
|
|
Ops.Init();
|
|
//SetFormStyle();
|
|
panel_main.Controls.Clear();
|
|
BaseForm form = ActiveForms.Get("FormMain");
|
|
if (form != null)
|
|
{
|
|
panel_main.Controls.Add(form);
|
|
form.TopLevel = false;
|
|
form.Dock = DockStyle.Fill;
|
|
form.Visible = true;
|
|
}
|
|
else
|
|
{
|
|
form = new FormMain();
|
|
form.Name = "FormMain";
|
|
form.TopLevel = false;
|
|
form.Dock = DockStyle.Fill;
|
|
panel_main.Controls.Add(form);
|
|
form.Visible = true;
|
|
ActiveForms.Add(form);
|
|
btnMain.Selected = true;
|
|
}
|
|
timer1.Enabled = true;
|
|
lblVersion.Text ="Version:"+System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
|
|
|
|
new HotKeyManager(Keys.P, 1, (o, arg) => {
|
|
UpCameraHelper.Grab();
|
|
//MonitorTray monitorTray = new MonitorTray();
|
|
//monitorTray.TopMost = true;
|
|
//monitorTray.ShowMax = false;
|
|
//monitorTray.ShowMin = false;
|
|
//monitorTray.ShowInTaskbar = false;
|
|
// monitorTray.Show();
|
|
});
|
|
|
|
new HotKeyManager(Keys.T, 1, (o, arg) => {
|
|
SelectProductFrm selectPro = new SelectProductFrm();
|
|
selectPro.TopMost = true;
|
|
selectPro.ShowInTaskbar = false;
|
|
selectPro.Show();
|
|
});
|
|
|
|
new HotKeyManager(Keys.N, 1, (o, arg) => {
|
|
NozzleStatusFrm nozzleFrm = new NozzleStatusFrm();
|
|
nozzleFrm.TopMost = true;
|
|
nozzleFrm.ShowInTaskbar = false;
|
|
nozzleFrm.Show();
|
|
});
|
|
|
|
new HotKeyManager(Keys.V, 1, (o, arg) => {
|
|
LocationData ld = new LocationData();
|
|
ld.StartPosition= FormStartPosition.CenterScreen;
|
|
ld.HeaderBackgroundColor = Color.Gray;
|
|
ld.Show();
|
|
|
|
//MonitorFlow mf = new MonitorFlow();
|
|
//mf.StartPosition= FormStartPosition.CenterParent;
|
|
//mf.HeaderBackgroundColor = Color.Gray;
|
|
//mf.Show();
|
|
});
|
|
|
|
|
|
timer2.Interval = 500;
|
|
timer2.Enabled = true;
|
|
timer3.Interval = 1000 * 60 * 60 * 2;
|
|
timer3.Enabled = true;
|
|
Task.Run(() =>
|
|
{
|
|
timer3_Tick(null, null);
|
|
});
|
|
if(File.Exists("breakdown.csv"))
|
|
{
|
|
File.Delete("breakdown.csv");
|
|
}
|
|
}
|
|
|
|
void ChangeLang()
|
|
{
|
|
string language = Properties.Settings.Default.DefaultLanguage;
|
|
if (language == "zh-CN")
|
|
{
|
|
btnMain.ShowText = "主页";
|
|
btnMain.Invalidate();
|
|
btnRecipe.ShowText = "配方";
|
|
btnRecipe.Invalidate();
|
|
btnSystem.ShowText = "系统配置";
|
|
btnSystem.Invalidate();
|
|
btnAbout.ShowText = "调试";
|
|
btnAbout.Invalidate();
|
|
btnData.ShowText = "English";
|
|
btnData.Invalidate();
|
|
btnLanguage.ShowText = "标定";
|
|
btnLanguage.Invalidate();
|
|
btnPermission.ShowText = "用户";
|
|
btnPermission.Invalidate();
|
|
btnQuit.ShowText = "退出";
|
|
btnQuit.Invalidate();
|
|
}
|
|
else
|
|
{
|
|
btnMain.ShowText = "Home";
|
|
btnMain.Invalidate();
|
|
btnRecipe.ShowText = "Recipe";
|
|
btnRecipe.Invalidate();
|
|
btnSystem.ShowText = "Settings";
|
|
btnSystem.Invalidate();
|
|
btnAbout.ShowText = "Debugger";
|
|
btnAbout.Invalidate();
|
|
btnLanguage.ShowText = "Vision calibration";
|
|
btnLanguage.Invalidate();
|
|
btnPermission.ShowText = "User";
|
|
btnPermission.Invalidate();
|
|
btnQuit.ShowText = "Quit";
|
|
btnQuit.Invalidate();
|
|
btnData.ShowText = "中文";
|
|
btnData.Invalidate();
|
|
}
|
|
}
|
|
private void SetFormStyle()
|
|
{
|
|
this.StartPosition = FormStartPosition.Manual;
|
|
this.FormBorderStyle = FormBorderStyle.None;//设置无边框
|
|
this.WindowState = FormWindowState.Maximized;//设置窗体最大化显示
|
|
this.MaximizedBounds = Screen.PrimaryScreen.WorkingArea;//设置窗体在无边框和最大化时不遮挡任务栏
|
|
}
|
|
|
|
private void timer1_Tick(object sender, EventArgs e)
|
|
{
|
|
//GC.Collect();
|
|
if(MachineManage.Instance.MachineStatus.ToString()!=lblMachineState.Text)
|
|
{
|
|
if(MachineManage.Instance.MachineStatus== EMachineStatus.NotInit)
|
|
{
|
|
this.panel1.BackColor = Color.Red;
|
|
}
|
|
else if(MachineManage.Instance.MachineStatus== EMachineStatus.Homing || MachineManage.Instance.MachineStatus == EMachineStatus.Stop)
|
|
{
|
|
this.panel1.BackColor = Color.FromArgb(192, 192, 0);
|
|
}
|
|
else
|
|
{
|
|
this.panel1.BackColor = Color.FromArgb(46, 46, 46);
|
|
}
|
|
lblMachineState.Text=MachineManage.Instance.MachineStatus.ToString();
|
|
}
|
|
|
|
if(DischargeFlow.Instance.GetCurStep().ToString()!=lblDischargeFlow.Text.Replace("主流程:", ""))
|
|
{
|
|
lblDischargeFlow.Text = "主流程:"+DischargeFlow.Instance.GetCurStep().ToString();
|
|
}
|
|
|
|
if (StockTakeFlow.Instance.GetCurStep().ToString() != lblStockLoadProductFlow.Text.Replace("料仓上料:", ""))
|
|
{
|
|
lblStockLoadProductFlow.Text = "料仓上料:" + StockTakeFlow.Instance.GetCurStep().ToString();
|
|
}
|
|
|
|
|
|
|
|
if (StockPlaceFlow.Instance.GetCurStep().ToString() != lblStockPlaceFlow.Text.Replace("料仓下料:", ""))
|
|
{
|
|
lblStockPlaceFlow.Text = "料仓下料:" + StockPlaceFlow.Instance.GetCurStep().ToString();
|
|
}
|
|
|
|
if (FixturePlaceFlow.Instance.GetCurStep().ToString() != lblFixturePlaceFlow.Text.Replace("治具上料:", ""))
|
|
{
|
|
lblFixturePlaceFlow.Text = "治具上料:" + FixturePlaceFlow.Instance.GetCurStep().ToString();
|
|
}
|
|
|
|
if (FixtureTakeFlow.Instance.GetCurStep().ToString() != lblFixtureTakeFlow.Text.Replace("治具下料:", ""))
|
|
{
|
|
lblFixtureTakeFlow.Text = "治具下料:" + FixtureTakeFlow.Instance.GetCurStep().ToString();
|
|
}
|
|
|
|
if (MonitorSystemButton.Instance.GetStep() != lblMonitorFlow.Text.Replace("Monitor:", ""))
|
|
{
|
|
lblMonitorFlow.Text = "Monitor:" + MonitorSystemButton.Instance.GetStep();
|
|
}
|
|
|
|
|
|
Process proc = Process.GetCurrentProcess();
|
|
if (proc != null)
|
|
{
|
|
long userdMem = proc.WorkingSet64;
|
|
lblMemory.Text = $"Mem:{(userdMem/1024)/1024} MB";
|
|
}
|
|
}
|
|
|
|
public override bool WindowsClose()
|
|
{
|
|
//DialogResult dr = MessageBox.Show("Are you sure to exit?", "tip", MessageBoxButtons.OKCancel);
|
|
EButtonType btnType = Msgbox.ShowTipDialog(EButtonType.Ok | EButtonType.Cancel, "Are you sure to exit?");
|
|
//if (dr == DialogResult.OK)
|
|
if(btnType== EButtonType.Ok)
|
|
{
|
|
LogHelper.Debug("手动退出软件");
|
|
Ops.Quit();
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
#region 内存回收
|
|
[DllImport("kernel32.dll", EntryPoint = "SetProcessWorkingSetSize")]
|
|
public static extern int SetProcessWorkingSetSize(IntPtr process, int minSize, int maxSize);
|
|
/// <summary>
|
|
/// 释放内存
|
|
/// </summary>
|
|
public static void ClearMemory()
|
|
{
|
|
GC.Collect();
|
|
GC.WaitForPendingFinalizers();
|
|
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
|
|
{
|
|
SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle, -1, -1);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// 离子风扇报警
|
|
/// </summary>
|
|
bool fanAlarm = false;
|
|
/// <summary>
|
|
/// 正压报警
|
|
/// </summary>
|
|
bool pPressvacAlarm = false;
|
|
/// <summary>
|
|
/// 负压报警
|
|
/// </summary>
|
|
bool nPressvacAlarm = false;
|
|
/// <summary>
|
|
/// 安全们报警
|
|
/// </summary>
|
|
bool doorAlarm = false;
|
|
|
|
/// <summary>
|
|
/// 固定气缸报警
|
|
/// </summary>
|
|
bool fixedCylinderAlarm = false;
|
|
private void timer2_Tick(object sender, EventArgs e)
|
|
{
|
|
//ClearMemory();
|
|
if (!GlobalVar.DisableDoor)
|
|
{
|
|
if(MachineManage.Instance.MachineStatus != EMachineStatus.NotInit)
|
|
{
|
|
if (!doorAlarm)
|
|
{
|
|
if (IoManager.Instance.ReadIn("门禁") == 0)
|
|
{
|
|
doorAlarm = true;
|
|
Ops.Stop();
|
|
Msgbox.Show(AlarmCollection.Get(AlarmConstID.安全门禁), EButtonType.None);
|
|
MessageQueue.Instance.Warn($"前安全门禁已触发,{AlarmCollection.Get(AlarmConstID.安全门禁).CN}");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (IoManager.Instance.ReadIn("门禁") == 1)
|
|
{
|
|
doorAlarm = false;
|
|
MessageQueue.Instance.Warn("安全门禁已解除");
|
|
Msgbox.CloseBox(AlarmCollection.Get(AlarmConstID.安全门禁).AlarmID);
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
protected override CreateParams CreateParams
|
|
{
|
|
get
|
|
{
|
|
const int WS_MINIMIZEBOX = 0x00020000; // Winuser.h中定义
|
|
CreateParams cp = base.CreateParams;
|
|
cp.Style = cp.Style | WS_MINIMIZEBOX; // 允许最小化操作
|
|
return cp;
|
|
}
|
|
}
|
|
|
|
private void timer3_Tick(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
string dirpath = string.Empty;
|
|
|
|
dirpath = "D://Communition";
|
|
string[] dirs = Directory.GetDirectories(dirpath);
|
|
if (!Directory.Exists(dirpath))
|
|
{
|
|
Directory.CreateDirectory(dirpath);
|
|
}
|
|
foreach (var dir in dirs)
|
|
{
|
|
DirectoryInfo di = new DirectoryInfo(dir);
|
|
DateTime dtCreate = di.CreationTime;
|
|
if ((DateTime.Now - dtCreate).Days > 5)
|
|
{
|
|
di.Delete(true);
|
|
}
|
|
}
|
|
|
|
|
|
dirpath = "D://软件备份";
|
|
if (!Directory.Exists(dirpath))
|
|
{
|
|
Directory.CreateDirectory(dirpath);
|
|
}
|
|
dirs = Directory.GetDirectories(dirpath);
|
|
foreach (var dir in dirs)
|
|
{
|
|
DirectoryInfo di = new DirectoryInfo(dir);
|
|
DateTime dtCreate = di.CreationTime;
|
|
if ((DateTime.Now - dtCreate).Days > 15)
|
|
{
|
|
di.Delete(true);
|
|
}
|
|
}
|
|
|
|
//配置文件备份
|
|
string workDir = System.Environment.CurrentDirectory;
|
|
string zipFileName = DateTime.Now.ToString("yyyyMMddHH");
|
|
string bakDir = $"d://软件备份//{DateTime.Now.ToString("yyyyMMdd")}//{zipFileName}";
|
|
if (!Directory.Exists(bakDir))
|
|
{
|
|
Directory.CreateDirectory(bakDir);
|
|
CopyDirectory(workDir, bakDir);
|
|
string toDir = Path.Combine(Directory.GetParent(bakDir).FullName, zipFileName + ".zip");
|
|
ZipHelper.ZipDirectory(bakDir, toDir);
|
|
Directory.Delete(bakDir, true);
|
|
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.Error(ex.Message + ex.StackTrace);
|
|
}
|
|
}
|
|
|
|
public static void CopyDirectory(string sourceDir, string targetDir)
|
|
{
|
|
DirectoryInfo dir = new DirectoryInfo(sourceDir);
|
|
DirectoryInfo[] dirs = dir.GetDirectories();
|
|
|
|
// If the source directory does not exist, throw an exception.
|
|
if (!dir.Exists)
|
|
{
|
|
throw new DirectoryNotFoundException($"Source directory does not exist or could not be found: {sourceDir}");
|
|
}
|
|
|
|
// If the destination directory does not exist, create it.
|
|
if (!Directory.Exists(targetDir))
|
|
{
|
|
Directory.CreateDirectory(targetDir);
|
|
}
|
|
|
|
// Get the files in the directory and copy them to the new location.
|
|
FileInfo[] files = dir.GetFiles();
|
|
foreach (FileInfo file in files)
|
|
{
|
|
string tempPath = Path.Combine(targetDir, file.Name);
|
|
file.CopyTo(tempPath, false);
|
|
}
|
|
|
|
// If copying subdirectories, copy them and their contents to the new location.
|
|
foreach (DirectoryInfo subdir in dirs)
|
|
{
|
|
string tempPath = Path.Combine(targetDir, subdir.Name);
|
|
CopyDirectory(subdir.FullName, tempPath);
|
|
}
|
|
}
|
|
}
|
|
}
|