рефакторинг парметров
This commit is contained in:
parent
7676d47374
commit
4e70b4f7e7
|
|
@ -60,8 +60,8 @@ namespace Reseter2
|
|||
|
||||
treeView1.Nodes.AddRange(WordsList.ListNodes());
|
||||
|
||||
treeView1.SelectedNode.
|
||||
//treeView1.MouseCaptureChanged.;
|
||||
//treeView1.SelectedNode.
|
||||
//treeView1.MouseCaptureChanged.;
|
||||
tabControl1.SelectedIndex = 1;
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -184,9 +184,6 @@
|
|||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Resources\comp.png" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="reseter.ico" />
|
||||
</ItemGroup>
|
||||
|
|
|
|||
Binary file not shown.
|
Before Width: | Height: | Size: 272 B |
|
|
@ -1,4 +1,5 @@
|
|||
using Reseter2.Words;
|
||||
using Reseter2.History;
|
||||
using Reseter2.Words;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
|
@ -7,14 +8,15 @@ using System.Runtime.Serialization.Formatters.Binary;
|
|||
using System.Security.Policy;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Reseter2.Setting
|
||||
{
|
||||
[Serializable]
|
||||
internal static class SGlobalSetting
|
||||
{
|
||||
public static SettingHistory settingHistory
|
||||
public static SettingWords settingWords = new SettingWords();
|
||||
// public static SettingHistory settingHistory
|
||||
public static SettingWords settingWords = new SettingWords();
|
||||
|
||||
public static void LoadSetting()
|
||||
{
|
||||
|
|
@ -66,9 +68,94 @@ namespace Reseter2.Setting
|
|||
return (IComp)Clone((object)input);
|
||||
}
|
||||
|
||||
public static void Save()
|
||||
public static bool SaveClose(WordsCategory output, DialogResult ok = DialogResult.No)
|
||||
{
|
||||
|
||||
BinaryFormatter binaryFormatter = new BinaryFormatter();
|
||||
MemoryStream Memory = new MemoryStream();
|
||||
binaryFormatter.Serialize(Memory, output);
|
||||
FileStream file = null;
|
||||
Memory.Position = 0;
|
||||
if (settingWords.HashCheck(Memory) )
|
||||
{
|
||||
if (ok == DialogResult.OK)
|
||||
{
|
||||
Memory.Close();
|
||||
Memory.Dispose();
|
||||
return Save(output);
|
||||
}
|
||||
else
|
||||
{
|
||||
DialogResult result = MessageBox.Show("Сохранить внесенные изменения?", "Сохранение измененний", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
|
||||
switch (result)
|
||||
{
|
||||
case DialogResult.Yes:
|
||||
|
||||
try
|
||||
{
|
||||
file = new FileStream(settingWords.PathBase, FileMode.OpenOrCreate);
|
||||
Memory.Position = 0;
|
||||
Memory.CopyTo(file);
|
||||
Memory.Close();
|
||||
Memory.Dispose();
|
||||
file.Close();
|
||||
file.Dispose();
|
||||
}
|
||||
catch
|
||||
{
|
||||
Memory.Close();
|
||||
Memory.Dispose();
|
||||
file.Close();
|
||||
file.Dispose();
|
||||
return SaveCheck(output);
|
||||
}
|
||||
|
||||
WordsList.MainCategory = output;
|
||||
return true;
|
||||
case DialogResult.No:
|
||||
return true;
|
||||
case DialogResult.Cancel:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public static bool Save(WordsCategory output)
|
||||
{
|
||||
return Save(settingWords.PathBase, output);
|
||||
}
|
||||
public static bool Save(string path, object output)
|
||||
{
|
||||
BinaryFormatter binaryFormatter = new BinaryFormatter();
|
||||
FileStream file = null;
|
||||
try
|
||||
{
|
||||
file = new FileStream(path, FileMode.OpenOrCreate);
|
||||
binaryFormatter.Serialize(file, output);
|
||||
file.Close();
|
||||
file.Dispose();
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
file.Close();
|
||||
file.Dispose();
|
||||
return SaveCheck(output);
|
||||
|
||||
}
|
||||
}
|
||||
public static bool SaveCheck(object output)
|
||||
{
|
||||
DialogResult result1 = MessageBox.Show("Файл занят другой программой.\nПовторить еще раз?", "Ошибка сохранения", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error);
|
||||
switch (result1)
|
||||
{
|
||||
case (DialogResult.Retry):
|
||||
return SaveCheck(output);
|
||||
case (DialogResult.Abort):
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -35,7 +35,12 @@ namespace Reseter2.Setting
|
|||
hash = Hash.ComputeHash(memory);
|
||||
}
|
||||
|
||||
|
||||
public bool HashCheck(MemoryStream memory)
|
||||
{
|
||||
byte[] hashSave = Hash.ComputeHash(memory);
|
||||
return !hash.SequenceEqual(hashSave);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -49,7 +49,7 @@ namespace Reseter2.Words
|
|||
InitializeComponent();
|
||||
cb_create.Items.Add("Категория");
|
||||
cb_create.Items.Add("Компьютер");
|
||||
cb_create.SelectedIndex = 0;
|
||||
cb_create.SelectedIndex = 1;
|
||||
treeView1.ItemDrag += new ItemDragEventHandler(TreeView1_ItemDrag);
|
||||
treeView1.DragEnter += new DragEventHandler(TreeView1_DragEnter);
|
||||
treeView1.DragOver += new DragEventHandler(TreeView1_DragOver);
|
||||
|
|
@ -295,39 +295,16 @@ namespace Reseter2.Words
|
|||
control.Visible = false;
|
||||
control.Visible = true;
|
||||
}
|
||||
BinaryFormatter binaryFormatter = new BinaryFormatter();
|
||||
MemoryStream Memory = new MemoryStream();
|
||||
binaryFormatter.Serialize(Memory, ChangeCategory);
|
||||
Memory.Position = 0;
|
||||
byte[] hashSave = Hash.ComputeHash(Memory);
|
||||
if (!hash.SequenceEqual(hashSave))
|
||||
|
||||
if (!SGlobalSetting.SaveClose(ChangeCategory, this.DialogResult))
|
||||
{
|
||||
DialogResult result = MessageBox.Show("Сохранить внесенные изменения?", "Сохранение измененний", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
|
||||
switch (result)
|
||||
{
|
||||
case DialogResult.Yes:
|
||||
FileStream file = new FileStream("base.dat", FileMode.OpenOrCreate);
|
||||
Memory.Position = 0;
|
||||
Memory.CopyTo(file);
|
||||
Memory.Close();
|
||||
Memory.Dispose();
|
||||
file.Close();
|
||||
file.Dispose();
|
||||
WordsList.MainCategory = ChangeCategory;
|
||||
this.DialogResult = DialogResult.OK;
|
||||
break;
|
||||
case DialogResult.No:
|
||||
this.DialogResult = DialogResult.Abort;
|
||||
break;
|
||||
case DialogResult.Cancel:
|
||||
e.Cancel = true;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
|
||||
e.Cancel = true;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
WordsList.MainCategory = ChangeCategory;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void bt_deleteItem_Click(object sender, EventArgs e)
|
||||
|
|
@ -411,20 +388,9 @@ namespace Reseter2.Words
|
|||
|
||||
private void bt_saveClose_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (control != null)
|
||||
{
|
||||
control.Visible = false;
|
||||
control.Dispose();
|
||||
}
|
||||
|
||||
BinaryFormatter binaryFormatter = new BinaryFormatter();
|
||||
FileStream file = new FileStream("base.dat", FileMode.OpenOrCreate);
|
||||
binaryFormatter.Serialize(file, ChangeCategory);
|
||||
file.Close();
|
||||
file.Dispose();
|
||||
WordsList.MainCategory = ChangeCategory;
|
||||
this.DialogResult = DialogResult.OK;
|
||||
this.Close();
|
||||
|
||||
}
|
||||
|
||||
private void bt_save_Click(object sender, EventArgs e)
|
||||
|
|
@ -434,13 +400,8 @@ namespace Reseter2.Words
|
|||
control.Visible = false;
|
||||
control.Visible = true;
|
||||
}
|
||||
BinaryFormatter binaryFormatter = new BinaryFormatter();
|
||||
FileStream file = new FileStream("base.dat", FileMode.OpenOrCreate);
|
||||
binaryFormatter.Serialize(file, ChangeCategory);
|
||||
file.Close();
|
||||
file.Dispose();
|
||||
WordsList.MainCategory = ChangeCategory;
|
||||
|
||||
if(SGlobalSetting.Save(ChangeCategory)) WordsList.MainCategory = ChangeCategory;
|
||||
SGlobalSetting.Clone(WordsList.MainCategory);
|
||||
}
|
||||
|
||||
private void bt_close_Click(object sender, EventArgs e)
|
||||
|
|
|
|||
Loading…
Reference in New Issue