Skip to content

Commit

Permalink
bug fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
BugLordI committed Sep 2, 2022
1 parent ec0cfd7 commit 366d5ac
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 844 deletions.
8 changes: 2 additions & 6 deletions AutoArchive/AutoArchive.sln
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.32510.428
# Visual Studio Version 17
VisualStudioVersion = 17.3.32825.248
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoArchive", "AutoArchive\AutoArchive.csproj", "{B3AB1C35-28E5-4A21-8275-2FA9FF998360}"
EndProject
Project("{54435603-DBB4-11D2-8724-00A0C9A8B90C}") = "AutoArchiveSetup", "AutoArchiveSetup\AutoArchiveSetup.vdproj", "{564CE75F-B2E0-427A-85D5-4E54C1DB0772}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -17,8 +15,6 @@ Global
{B3AB1C35-28E5-4A21-8275-2FA9FF998360}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B3AB1C35-28E5-4A21-8275-2FA9FF998360}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B3AB1C35-28E5-4A21-8275-2FA9FF998360}.Release|Any CPU.Build.0 = Release|Any CPU
{564CE75F-B2E0-427A-85D5-4E54C1DB0772}.Debug|Any CPU.ActiveCfg = Debug
{564CE75F-B2E0-427A-85D5-4E54C1DB0772}.Release|Any CPU.ActiveCfg = Release
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
3 changes: 2 additions & 1 deletion AutoArchive/AutoArchive/Forms/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

144 changes: 80 additions & 64 deletions AutoArchive/AutoArchive/Forms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ public partial class MainForm : Form
/// </summary>
private Source selectedProject;

/// <summary>
/// 数据库相关
/// </summary>
private BaseMapper<Source> mapper;

/// <summary>
/// 备份数据表选中的行
/// </summary>
Expand Down Expand Up @@ -71,36 +66,39 @@ protected override void OnShown(EventArgs e)
}

/// <summary>
/// 窗口关闭时
/// OnFormClosing
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
//保存任务信息
//saveTask
if (selectedProject != null && periodTextBox.Text.Length > 0)
{
var exist = mapper.Entity.Find(this.selectedProject.Id).Task;
if (exist != null)
{
exist.IsOn = openTask.Checked;
exist.TaskPeriod = Convert.ToInt32(periodTextBox.Text);
}
else
using (BaseMapper<Source> mapper = new BaseMapper<Source>())
{
Task task = new Task();
task.Id = Guid.NewGuid().ToString("N");
task.SourceId = selectedProject.Id;
task.TaskPeriod = Convert.ToInt32(periodTextBox.Text);
task.IsOn = openTask.Checked;
mapper.Entity.Find(this.selectedProject.Id).Task = task;
var exist = mapper.Entity.Include(e => e.Task).ToList().Find(e => e.Id.Equals(this.selectedProject.Id)).Task;
if (exist != null)
{
exist.IsOn = openTask.Checked;
exist.TaskPeriod = Convert.ToInt32(periodTextBox.Text);
}
else
{
Task task = new Task();
task.Id = Guid.NewGuid().ToString("N");
task.SourceId = selectedProject.Id;
task.TaskPeriod = Convert.ToInt32(periodTextBox.Text);
task.IsOn = openTask.Checked;
mapper.Entity.Find(this.selectedProject.Id).Task = task;
}
mapper.SaveChanges();
}
mapper.SaveChanges();
}
}

/// <summary>
/// 初始化信息
/// init main page project info
/// </summary>
private void init()
{
Expand All @@ -113,15 +111,18 @@ private void init()
des.Text = selectedProject.TarPath;
toolTip.SetToolTip(des, des.Text);
}
updateBtn.Enabled = selectedProject != null;
}

/// <summary>
/// 查询所有工程
/// find all projects
/// </summary>
private void findProject()
{
mapper = new BaseMapper<Source>();
projects = mapper.Entity.Include(e => e.Targets).Include(e => e.Task).ToList();
using (BaseMapper<Source> mapper = new BaseMapper<Source>())
{
projects = mapper.Entity.Include(e => e.Targets).Include(e => e.Task).ToList();
}
}

/// <summary>
Expand All @@ -142,8 +143,11 @@ private void openProject(Source source)
private List<Source> newProject(Source source)
{
source.Id = Guid.NewGuid().ToString("N");
mapper.add(source);
return mapper.Entity.Include(e => e.Targets).Include(e => e.Task).ToList();
using (BaseMapper<Source> mapper = new BaseMapper<Source>())
{
mapper.add(source);
return mapper.Entity.Include(e => e.Targets).Include(e => e.Task).ToList();
}
}

/// <summary>
Expand Down Expand Up @@ -203,30 +207,33 @@ private void openProjectMenu_Click(object sender, EventArgs e)
}

/// <summary>
/// 开始任务
/// start auto-backup task
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void openTask_CheckedChanged(object sender, EventArgs e)
{
periodTextBox.Enabled = !openTask.Checked;
if (openTask.Checked)
if (!String.IsNullOrEmpty(periodTextBox.Text))
{
min = Convert.ToInt32(periodTextBox.Text);
if (min == 0 || min > 720)
periodTextBox.Enabled = !openTask.Checked;
if (openTask.Checked)
{
openTask.Checked = false;
closeTask.Checked = true;
periodTextBox.Enabled = true;
MessageBox.Show("时间需要大于0分钟并且小于720分钟", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
min = Convert.ToInt32(periodTextBox.Text);
if (min == 0 || min > 720)
{
openTask.Checked = false;
closeTask.Checked = true;
periodTextBox.Enabled = true;
MessageBox.Show("时间需要大于0分钟并且小于720分钟", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
countDownLb.Text = $"还剩{min}分钟";
timer.Start();
}
else
{
timer.Stop();
}
countDownLb.Text = $"还剩{min}分钟";
timer.Start();
}
else
{
timer.Stop();
}
}

Expand All @@ -243,20 +250,25 @@ private void backup(String remark, Boolean isAuto = false)
now.ToString("yyyyMMddHHmmss"));
if (FileUtil.copyDirectory(src, destinationPath))
{
Target target = new Target();
target.Id = Guid.NewGuid().ToString("N");
target.SourceId = this.selectedProject.Id;
target.Remark = remark;
target.DateTimeStamp = DateUtil.toUnixTimestamp(now);
target.Path = destinationPath;
mapper.Entity.Find(this.selectedProject.Id).Targets.Add(target);
mapper.SaveChanges();
initTable(mapper.Entity.Include(e => e.Targets).Include(e => e.Task).ToList().Find(
e => e.Id.Equals(this.selectedProject.Id)
));
if (!isAuto)
using (BaseMapper<Source> mapper = new BaseMapper<Source>())
{
MessageBox.Show("备份成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
Target target = new Target();
target.Id = Guid.NewGuid().ToString("N");
target.SourceId = this.selectedProject.Id;
target.Remark = remark;
target.DateTimeStamp = DateUtil.toUnixTimestamp(now);
target.Path = destinationPath;
var targets = mapper.Entity.Find(this.selectedProject.Id).Targets ?? new List<Target>();
targets.Add(target);
mapper.Entity.Find(this.selectedProject.Id).Targets = targets;
mapper.SaveChanges();
initTable(mapper.Entity.Include(e => e.Targets).Include(e => e.Task).ToList().Find(
e => e.Id.Equals(this.selectedProject.Id)
));
if (!isAuto)
{
MessageBox.Show("备份成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
else
Expand Down Expand Up @@ -399,14 +411,18 @@ private void deleteBtn_Click(object sender, EventArgs e)
{
DirectoryInfo di = new DirectoryInfo(selectedRow.Path);
di.Delete(true);
BaseMapper<Target> baseMapper = new BaseMapper<Target>();
baseMapper.Entity.Remove(selectedRow);
baseMapper.SaveChanges();
mapper = new BaseMapper<Source>();
initTable(mapper.Entity.Include(e => e.Targets).Include(e => e.Task).ToList().Find(
e => e.Id.Equals(this.selectedProject.Id)
));
MessageBox.Show("删除成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
using (BaseMapper<Source> mapper = new BaseMapper<Source>())
{
using (BaseMapper<Target> baseMapper = new BaseMapper<Target>())
{
baseMapper.Entity.Remove(selectedRow);
baseMapper.SaveChanges();
initTable(mapper.Entity.Include(e => e.Targets).Include(e => e.Task).ToList().Find(
e => e.Id.Equals(this.selectedProject.Id)
));
MessageBox.Show("删除成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
}

Expand Down
12 changes: 12 additions & 0 deletions AutoArchive/AutoArchive/Forms/MainForm.resx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@
<metadata name="timer.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>230, 17</value>
</metadata>
<metadata name="toolStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>313, 17</value>
</metadata>
<metadata name="remarkCol.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="dateCol.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="pathCol.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="remarkCol.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
Expand Down
Loading

0 comments on commit 366d5ac

Please sign in to comment.