Commit f014efd8 authored by DailyShana's avatar DailyShana

rewrite undo

parent e72065c5
...@@ -36,69 +36,61 @@ public void SetPath(string gamepath) ...@@ -36,69 +36,61 @@ public void SetPath(string gamepath)
/// <summary>录像目录</summary> /// <summary>录像目录</summary>
public string replaypath; public string replaypath;
public string GetImage(long id, bool bak = false) public string GetImage(long id)
{ {
return GetImage(id.ToString(), bak); return GetImage(id.ToString());
} }
public string GetImageThum(long id, bool bak = false) public string GetImageThum(long id)
{ {
return GetImageThum(id.ToString(), bak); return GetImageThum(id.ToString());
} }
public string GetImageField(long id, bool bak = false) public string GetImageField(long id)
{ {
return GetImageField(id.ToString(), bak);//场地图 return GetImageField(id.ToString());//场地图
} }
public string GetScript(long id, bool bak = false) public string GetScript(long id)
{ {
return GetScript(id.ToString(), bak); return GetScript(id.ToString());
} }
public string GetYdk(string name) public string GetYdk(string name)
{ {
return MyPath.Combine(ydkpath, name + ".ydk"); return MyPath.Combine(ydkpath, name + ".ydk");
} }
//字符串id //字符串id
public string GetImage(string id, bool bak = false) public string GetImage(string id)
{ {
if (bak)
return MyPath.Combine(picpath, id + ".jpg.bak");
return MyPath.Combine(picpath, id + ".jpg"); return MyPath.Combine(picpath, id + ".jpg");
} }
public string GetImageThum(string id, bool bak = false) public string GetImageThum(string id)
{ {
if (bak)
return MyPath.Combine(picpath2, id + ".jpg.bak");
return MyPath.Combine(picpath2, id + ".jpg"); return MyPath.Combine(picpath2, id + ".jpg");
} }
public string GetImageField(string id, bool bak = false) public string GetImageField(string id)
{ {
if (bak)
return MyPath.Combine(fieldpath, id + ".png.bak");
return MyPath.Combine(fieldpath, id+ ".png");//场地图 return MyPath.Combine(fieldpath, id+ ".png");//场地图
} }
public string GetScript(string id, bool bak = false) public string GetScript(string id)
{ {
if (bak)
return MyPath.Combine(luapath, "c" + id + ".lua.bak");
return MyPath.Combine(luapath, "c" + id + ".lua"); return MyPath.Combine(luapath, "c" + id + ".lua");
} }
public string[] GetCardfiles(long id, bool bak = false) public string[] GetCardfiles(long id)
{ {
string[] files = new string[]{ string[] files = new string[]{
GetImage(id, bak),//大图 GetImage(id),//大图
GetImageThum(id, bak),//小图 GetImageThum(id),//小图
GetImageField(id, bak),//场地图 GetImageField(id),//场地图
GetScript(id, bak) GetScript(id)
}; };
return files; return files;
} }
public string[] GetCardfiles(string id, bool bak = false) public string[] GetCardfiles(string id)
{ {
string[] files = new string[]{ string[] files = new string[]{
GetImage(id, bak),//大图 GetImage(id),//大图
GetImageThum(id, bak),//小图 GetImageThum(id),//小图
GetImageField(id, bak),//场地图 GetImageField(id),//场地图
GetScript(id, bak) GetScript(id)
}; };
return files; return files;
} }
......
...@@ -11,41 +11,35 @@ namespace DataEditorX.Core ...@@ -11,41 +11,35 @@ namespace DataEditorX.Core
public class CardEdit public class CardEdit
{ {
IDataForm dataform; IDataForm dataform;
public List<string> undoSQL; public AddCommand addCard;
public class FileModified public ModCommand modCard;
{ public DelCommand delCard;
public bool modifiled = false; public CopyCommand copyCard;
public long oldid;
public long newid;
public bool delold;
}
public class FileDeleted
{
public bool deleted = false;
public List<long> ids = new List<long>();
}
public class DBcopied
{
public bool copied = false;
public Card[] NewCards;
public bool replace;
public Card[] OldCards;
}
public List<FileModified> undoModified;
public List<FileDeleted> undoDeleted;
public List<DBcopied> undoCopied;
public CardEdit(IDataForm dataform) public CardEdit(IDataForm dataform)
{ {
this.dataform = dataform; this.dataform = dataform;
this.undoSQL = new List<string>(); this.addCard = new AddCommand(this);
this.undoModified = new List<FileModified>(); this.modCard = new ModCommand(this);
this.undoDeleted = new List<FileDeleted>(); this.delCard = new DelCommand(this);
this.undoCopied = new List<DBcopied>(); this.copyCard = new CopyCommand(this);
} }
#region 添加 #region 添加
//添加 //添加
public bool AddCard() public class AddCommand: IBackableCommand
{
private string _undoSQL;
CardEdit cardedit;
IDataForm dataform;
public AddCommand(CardEdit cardedit)
{
this.cardedit = cardedit;
this.dataform = cardedit.dataform;
}
public bool Excute(params object[] args)
{ {
if (!dataform.CheckOpen()) if (!dataform.CheckOpen())
return false; return false;
...@@ -68,10 +62,7 @@ public bool AddCard() ...@@ -68,10 +62,7 @@ public bool AddCard()
DataBase.GetInsertSQL(c, true)) >= 2) DataBase.GetInsertSQL(c, true)) >= 2)
{ {
MyMsg.Show(LMSG.AddSucceed); MyMsg.Show(LMSG.AddSucceed);
undoSQL.Add(DataBase.GetDeleteSQL(c)); _undoSQL = DataBase.GetDeleteSQL(c);
undoModified.Add(new FileModified());
undoDeleted.Add(new FileDeleted());
undoCopied.Add(new DBcopied());
dataform.Search(true); dataform.Search(true);
dataform.SetCard(c); dataform.SetCard(c);
return true; return true;
...@@ -79,14 +70,42 @@ public bool AddCard() ...@@ -79,14 +70,42 @@ public bool AddCard()
MyMsg.Error(LMSG.AddFail); MyMsg.Error(LMSG.AddFail);
return false; return false;
} }
public void Undo()
{
DataBase.Command(dataform.GetOpenFile(), _undoSQL);
}
public object Clone()
{
return this.MemberwiseClone();
}
}
#endregion #endregion
#region 修改 #region 修改
//修改 //修改
public bool ModCard(bool modfiles) public class ModCommand: IBackableCommand
{
private string _undoSQL;
private bool modifiled = false;
private long oldid;
private long newid;
private bool delold;
CardEdit cardedit;
IDataForm dataform;
public ModCommand(CardEdit cardedit)
{
this.cardedit = cardedit;
this.dataform = cardedit.dataform;
}
public bool Excute(params object[] args)
{ {
if (!dataform.CheckOpen()) if (!dataform.CheckOpen())
return false; return false;
bool modfiles = (bool)args[0];
Card c = dataform.GetCard(); Card c = dataform.GetCard();
Card oldCard = dataform.GetOldCard(); Card oldCard = dataform.GetOldCard();
if (c.Equals(oldCard))//没有修改 if (c.Equals(oldCard))//没有修改
...@@ -111,40 +130,32 @@ public bool ModCard(bool modfiles) ...@@ -111,40 +130,32 @@ public bool ModCard(bool modfiles)
{ {
//删除失败 //删除失败
MyMsg.Error(LMSG.DeleteFail); MyMsg.Error(LMSG.DeleteFail);
delold = false;
} }
else else
{//删除成功,添加还原sql {//删除成功,添加还原sql
undoSQL.Add(DataBase.GetDeleteSQL(c)+DataBase.GetInsertSQL(oldCard, false)); _undoSQL = DataBase.GetDeleteSQL(c) + DataBase.GetInsertSQL(oldCard, false);
} }
} else
undoSQL.Add(DataBase.GetDeleteSQL(c));//还原就是删除
//如果删除旧卡片,则把资源修改名字,否则复制资源
if (modfiles)
{
YGOUtil.CardRename(c.id, oldCard.id, dataform.GetPath(), delold);
FileModified modify = new FileModified();
modify.modifiled = true;
modify.oldid = oldCard.id;
modify.newid = c.id;
modify.delold = delold;
undoModified.Add(modify);
undoDeleted.Add(new FileDeleted());
undoCopied.Add(new DBcopied());
} }
else else
_undoSQL = DataBase.GetDeleteSQL(c);//还原就是删除
//如果删除旧卡片,则把资源修改名字,否则复制资源
if(modfiles)
{ {
undoModified.Add(new FileModified()); if (delold)
undoDeleted.Add(new FileDeleted()); YGOUtil.CardRename(c.id, oldCard.id, dataform.GetPath());
undoCopied.Add(new DBcopied()); else
YGOUtil.CardCopy(c.id, oldCard.id, dataform.GetPath());
this.modifiled = true;
this.oldid = oldCard.id;
this.newid = c.id;
this.delold = delold;
} }
} }
else else
{//更新数据 {//更新数据
sql = DataBase.GetUpdateSQL(c); sql = DataBase.GetUpdateSQL(c);
undoSQL.Add(DataBase.GetUpdateSQL(oldCard)); _undoSQL = DataBase.GetUpdateSQL(oldCard);
undoModified.Add(new FileModified());
undoDeleted.Add(new FileDeleted());
undoCopied.Add(new DBcopied());
} }
if (DataBase.Command(dataform.GetOpenFile(), sql) > 0) if (DataBase.Command(dataform.GetOpenFile(), sql) > 0)
{ {
...@@ -157,14 +168,46 @@ public bool ModCard(bool modfiles) ...@@ -157,14 +168,46 @@ public bool ModCard(bool modfiles)
MyMsg.Error(LMSG.ModifyFail); MyMsg.Error(LMSG.ModifyFail);
return false; return false;
} }
public void Undo()
{
DataBase.Command(dataform.GetOpenFile(), _undoSQL);
if (this.modifiled)
{
if (this.delold)
YGOUtil.CardRename(this.oldid, this.newid, dataform.GetPath());
else
YGOUtil.CardDelete(this.newid, dataform.GetPath());
}
}
public object Clone()
{
return this.MemberwiseClone();
}
}
#endregion #endregion
#region 删除 #region 删除
//删除 //删除
public bool DelCards(bool deletefiles) public class DelCommand : IBackableCommand
{
private string _undoSQL;
CardEdit cardedit;
IDataForm dataform;
public DelCommand(CardEdit cardedit)
{
this.cardedit = cardedit;
this.dataform = cardedit.dataform;
}
public bool Excute(params object[] args)
{ {
if (!dataform.CheckOpen()) if (!dataform.CheckOpen())
return false; return false;
bool deletefiles = (bool)args[0];
Card[] cards = dataform.GetCardList(true); Card[] cards = dataform.GetCardList(true);
if (cards == null || cards.Length == 0) if (cards == null || cards.Length == 0)
return false; return false;
...@@ -172,7 +215,6 @@ public bool DelCards(bool deletefiles) ...@@ -172,7 +215,6 @@ public bool DelCards(bool deletefiles)
if (!MyMsg.Question(LMSG.IfDeleteCard)) if (!MyMsg.Question(LMSG.IfDeleteCard))
return false; return false;
List<string> sql = new List<string>(); List<string> sql = new List<string>();
FileDeleted delete = new FileDeleted();
foreach (Card c in cards) foreach (Card c in cards)
{ {
sql.Add(DataBase.GetDeleteSQL(c));//删除 sql.Add(DataBase.GetDeleteSQL(c));//删除
...@@ -180,19 +222,14 @@ public bool DelCards(bool deletefiles) ...@@ -180,19 +222,14 @@ public bool DelCards(bool deletefiles)
//删除资源 //删除资源
if (deletefiles) if (deletefiles)
{ {
YGOUtil.CardDelete(c.id, dataform.GetPath(), YGOUtil.DeleteOption.BACKUP); YGOUtil.CardDelete(c.id, dataform.GetPath());
delete.deleted = true;
delete.ids.Add(c.id);
} }
} }
if (DataBase.Command(dataform.GetOpenFile(), sql.ToArray()) >= (sql.Count * 2)) if (DataBase.Command(dataform.GetOpenFile(), sql.ToArray()) >= (sql.Count * 2))
{ {
MyMsg.Show(LMSG.DeleteSucceed); MyMsg.Show(LMSG.DeleteSucceed);
dataform.Search(true); dataform.Search(true);
undoSQL.Add(undo); _undoSQL = undo;
undoDeleted.Add(delete);
undoModified.Add(new FileModified());
undoCopied.Add(new DBcopied());
return true; return true;
} }
else else
...@@ -202,6 +239,16 @@ public bool DelCards(bool deletefiles) ...@@ -202,6 +239,16 @@ public bool DelCards(bool deletefiles)
} }
return false; return false;
} }
public void Undo()
{
DataBase.Command(dataform.GetOpenFile(), _undoSQL);
}
public object Clone()
{
return this.MemberwiseClone();
}
}
#endregion #endregion
#region 打开脚本 #region 打开脚本
...@@ -251,37 +298,76 @@ public bool OpenScript(bool openinthis) ...@@ -251,37 +298,76 @@ public bool OpenScript(bool openinthis)
} }
#endregion #endregion
#region 撤销 #region 复制卡片
//撤销 public class CopyCommand : IBackableCommand
public void Undo()
{ {
if (undoSQL.Count == 0) bool copied = false;
Card[] NewCards;
bool replace;
Card[] OldCards;
CardEdit cardedit;
IDataForm dataform;
public CopyCommand(CardEdit cardedit)
{ {
return; this.cardedit = cardedit;
this.dataform = cardedit.dataform;
} }
DataBase.Command(dataform.GetOpenFile(), undoSQL[undoSQL.Count - 1]);
undoSQL.RemoveAt(undoSQL.Count - 1); public bool Excute(params object[] args)
if (undoModified[undoModified.Count - 1].modifiled)
{ {
FileModified lastmodify = undoModified[undoModified.Count - 1]; if (!dataform.CheckOpen())
YGOUtil.CardRename(lastmodify.oldid, lastmodify.newid, dataform.GetPath(), lastmodify.delold); return false;
Card[] cards = (Card[])args[0];
if (cards == null || cards.Length == 0)
return false;
bool replace = false;
Card[] oldcards = DataBase.Read(dataform.GetOpenFile(), true, "");
if (oldcards != null && oldcards.Length != 0)
{
int i = 0;
foreach (Card oc in oldcards)
{
foreach (Card c in cards)
{
if (c.id == oc.id)
{
i += 1;
if (i == 1)
{
replace = MyMsg.Question(LMSG.IfReplaceExistingCard);
break;
} }
undoModified.RemoveAt(undoModified.Count - 1); }
if (undoDeleted[undoDeleted.Count - 1].deleted) }
if (i > 0)
break;
}
}
DataBase.CopyDB(dataform.GetOpenFile(), !replace, cards);
this.copied = true;
this.NewCards = cards;
this.replace = replace;
this.OldCards = oldcards;
return true;
}
public void Undo()
{ {
FileDeleted lastdelete = undoDeleted[undoDeleted.Count - 1]; DataBase.DeleteDB(dataform.GetOpenFile(), this.NewCards);
foreach (long id in lastdelete.ids) DataBase.CopyDB(dataform.GetOpenFile(), !this.replace, this.OldCards);
YGOUtil.CardDelete(id, dataform.GetPath(), YGOUtil.DeleteOption.RESTORE);
} }
undoDeleted.RemoveAt(undoDeleted.Count - 1);
if (undoCopied[undoCopied.Count - 1].copied) public object Clone()
{ {
DBcopied lastcopied = undoCopied[undoCopied.Count - 1]; CopyCommand replica = new CopyCommand(cardedit);
DataBase.DeleteDB(dataform.GetOpenFile(), lastcopied.NewCards); replica.copied = this.copied;
DataBase.CopyDB(dataform.GetOpenFile(), !lastcopied.replace, lastcopied.OldCards); replica.NewCards = (Card[])this.NewCards.Clone();
replica.replace = this.replace;
if (this.OldCards != null)
replica.OldCards = (Card[])this.OldCards.Clone();
return replica;
} }
undoCopied.RemoveAt(undoCopied.Count - 1);
dataform.Search(true);
} }
#endregion #endregion
} }
......
using System;
using System.Collections.Generic;
namespace DataEditorX.Core
{
public delegate void StatusBool(bool val);
public interface ICommand : ICloneable
{
bool Excute(params object[] args);
}
public interface IBackableCommand : ICommand
{
void Undo();
}
public interface ICommandManager
{
void ExcuteCommand(ICommand command, params object[] args);
void Undo();
void ReverseUndo();//反撤销
event StatusBool UndoStateChanged;
}
public class CommandManager : ICommandManager
{
private Stack<ICommand> undoStack = new Stack<ICommand>();
private Stack<ICommand> reverseStack = new Stack<ICommand>();
public event StatusBool UndoStateChanged;
public CommandManager()
{
UndoStateChanged += new StatusBool(CommandManager_UndoStateChanged);
UndoStateChanged += new StatusBool(CommandManager_ReverseUndoStateChanged);
}
private void CommandManager_UndoStateChanged(bool val)
{
}
private void CommandManager_ReverseUndoStateChanged(bool val)
{
}
#region ICommandManager 成员
public void ExcuteCommand(ICommand command, params object[] args)
{
if(!command.Excute(args)) return;
reverseStack.Clear();
if (command is IBackableCommand)
{
undoStack.Push((ICommand)command.Clone());
}
else
{
undoStack.Clear();
}
UndoStateChanged(undoStack.Count > 0);
}
public void Undo()
{
IBackableCommand command = (IBackableCommand)undoStack.Pop();
if (command == null)
{
return;
}
command.Undo();
reverseStack.Push((ICommand)command.Clone());
UndoStateChanged(undoStack.Count > 0);
//UndoStateChanged(reverseStack.Count > 0);
}
public void ReverseUndo()
{
IBackableCommand command = (IBackableCommand)reverseStack.Pop();
if (command == null)
{
return;
}
command.Excute();
undoStack.Push((ICommand)command.Clone());
UndoStateChanged(undoStack.Count > 0);
}
#endregion
}
}
...@@ -3,10 +3,9 @@ ...@@ -3,10 +3,9 @@
using System.IO; using System.IO;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Microsoft.VisualBasic; using Microsoft.VisualBasic.FileIO;
using System.Configuration; using System.Configuration;
using DataEditorX.Config; using DataEditorX.Config;
using System.Windows.Forms;
using DataEditorX.Core.Info; using DataEditorX.Core.Info;
...@@ -205,59 +204,39 @@ public static string[] ReadImage(string path) ...@@ -205,59 +204,39 @@ public static string[] ReadImage(string path)
#region 删除资源 #region 删除资源
//删除资源 //删除资源
public enum DeleteOption public static void CardDelete(long id, YgoPath ygopath)
{
BACKUP,
RESTORE,
CLEAN,
NONE,
}
public static void CardDelete(long id, YgoPath ygopath, DeleteOption option)
{ {
string[] files = ygopath.GetCardfiles(id); string[] files = ygopath.GetCardfiles(id);
string[] bakfiles = ygopath.GetCardfiles(id, true);
switch (option)
{
case DeleteOption.BACKUP:
for (int i = 0; i < files.Length; i++) for (int i = 0; i < files.Length; i++)
{ {
if (File.Exists(bakfiles[i])) if (FileSystem.FileExists(files[i]))
File.Delete(bakfiles[i]); FileSystem.DeleteFile(files[i], UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin);
if (File.Exists(files[i]))
File.Move(files[i], files[i] + ".bak");
} }
break;
case DeleteOption.RESTORE:
for (int i = 0; i < bakfiles.Length; i++)
{
if (File.Exists(files[i]))
File.Delete(files[i]);
if (File.Exists(bakfiles[i]))
File.Move(bakfiles[i], bakfiles[i].Replace("bak", ""));
} }
break; #endregion
case DeleteOption.CLEAN:
for (int i = 0; i < bakfiles.Length; i++) #region 资源改名
//资源改名
public static void CardRename(long newid, long oldid, YgoPath ygopath)
{ {
if (File.Exists(bakfiles[i])) string[] newfiles = ygopath.GetCardfiles(newid);
File.Delete(bakfiles[i]); string[] oldfiles = ygopath.GetCardfiles(oldid);
}
break; for (int i = 0; i < oldfiles.Length; i++)
case DeleteOption.NONE:
for (int i = 0; i < files.Length; i++)
{ {
if (File.Exists(files[i])) if (File.Exists(oldfiles[i]))
File.Delete(files[i]); {
try {
File.Move(oldfiles[i], newfiles[i]);
}
catch { }
} }
break;
} }
} }
#endregion #endregion
#region 资源改名 #region 复制资源
//资源改名 public static void CardCopy(long newid, long oldid, YgoPath ygopath)
public static void CardRename(long newid, long oldid, YgoPath ygopath, bool delold)
{ {
string[] newfiles = ygopath.GetCardfiles(newid); string[] newfiles = ygopath.GetCardfiles(newid);
string[] oldfiles = ygopath.GetCardfiles(oldid); string[] oldfiles = ygopath.GetCardfiles(oldid);
...@@ -266,11 +245,11 @@ public static void CardRename(long newid, long oldid, YgoPath ygopath, bool delo ...@@ -266,11 +245,11 @@ public static void CardRename(long newid, long oldid, YgoPath ygopath, bool delo
{ {
if (File.Exists(oldfiles[i])) if (File.Exists(oldfiles[i]))
{ {
if (delold) try {
File.Move(oldfiles[i], newfiles[i]);
else
File.Copy(oldfiles[i], newfiles[i], false); File.Copy(oldfiles[i], newfiles[i], false);
} }
catch { }
}
} }
} }
#endregion #endregion
......
...@@ -55,6 +55,8 @@ public partial class DataEditForm : DockContent, IDataForm ...@@ -55,6 +55,8 @@ public partial class DataEditForm : DockContent, IDataForm
//setcode正在输入 //setcode正在输入
bool[] setcodeIsedit = new bool[5]; bool[] setcodeIsedit = new bool[5];
CommandManager cmdManager = new CommandManager();
Image m_cover; Image m_cover;
MSEConfig msecfg; MSEConfig msecfg;
...@@ -90,6 +92,13 @@ void Initialize(string datapath) ...@@ -90,6 +92,13 @@ void Initialize(string datapath)
InitializeComponent(); InitializeComponent();
title = this.Text; title = this.Text;
nowCdbFile = ""; nowCdbFile = "";
cmdManager.UndoStateChanged += delegate (bool val)
{
if (val)
btn_undo.Enabled = true;
else
btn_undo.Enabled = false;
};
} }
#endregion #endregion
...@@ -147,18 +156,6 @@ void DataEditFormLoad(object sender, EventArgs e) ...@@ -147,18 +156,6 @@ void DataEditFormLoad(object sender, EventArgs e)
//窗体关闭 //窗体关闭
void DataEditFormFormClosing(object sender, FormClosingEventArgs e) void DataEditFormFormClosing(object sender, FormClosingEventArgs e)
{ {
//清理备份文件
List<long> delids = new List<long>();
foreach (CardEdit.FileDeleted deleted in cardedit.undoDeleted)
{
if (deleted != null && deleted.deleted)
delids.AddRange(deleted.ids);
}
if (delids.Count != 0)
{
foreach (long id in delids)
YGOUtil.CardDelete(id, GetPath(), YGOUtil.DeleteOption.CLEAN);
}
//当前有任务执行,是否结束 //当前有任务执行,是否结束
if (tasker != null && tasker.IsRuning()) if (tasker != null && tasker.IsRuning())
{ {
...@@ -566,7 +563,7 @@ void Lv_cardlistKeyDown(object sender, KeyEventArgs e) ...@@ -566,7 +563,7 @@ void Lv_cardlistKeyDown(object sender, KeyEventArgs e)
switch (e.KeyCode) switch (e.KeyCode)
{ {
case Keys.Delete: case Keys.Delete:
cardedit.DelCards(menuitem_operacardsfile.Checked); cmdManager.ExcuteCommand(cardedit.delCard, menuitem_operacardsfile.Checked);
break; break;
case Keys.Right: case Keys.Right:
Btn_PageDownClick(null, null); Btn_PageDownClick(null, null);
...@@ -730,18 +727,14 @@ void Btn_resetClick(object sender, EventArgs e) ...@@ -730,18 +727,14 @@ void Btn_resetClick(object sender, EventArgs e)
//添加 //添加
void Btn_addClick(object sender, EventArgs e) void Btn_addClick(object sender, EventArgs e)
{ {
if(cardedit != null) if (cardedit != null)
cardedit.AddCard(); cmdManager.ExcuteCommand(cardedit.addCard);
if (cardedit.undoSQL.Count != 0)
btn_undo.Enabled = true;
} }
//修改 //修改
void Btn_modClick(object sender, EventArgs e) void Btn_modClick(object sender, EventArgs e)
{ {
if (cardedit != null) if (cardedit != null)
cardedit.ModCard(menuitem_operacardsfile.Checked); cmdManager.ExcuteCommand(cardedit.modCard, menuitem_operacardsfile.Checked);
if (cardedit.undoSQL.Count != 0)
btn_undo.Enabled = true;
} }
//打开脚本 //打开脚本
void Btn_luaClick(object sender, EventArgs e) void Btn_luaClick(object sender, EventArgs e)
...@@ -753,16 +746,16 @@ void Btn_luaClick(object sender, EventArgs e) ...@@ -753,16 +746,16 @@ void Btn_luaClick(object sender, EventArgs e)
void Btn_delClick(object sender, EventArgs e) void Btn_delClick(object sender, EventArgs e)
{ {
if (cardedit != null) if (cardedit != null)
cardedit.DelCards(menuitem_operacardsfile.Checked); cmdManager.ExcuteCommand(cardedit.delCard, menuitem_operacardsfile.Checked);
if (cardedit.undoSQL.Count != 0)
btn_undo.Enabled = true;
} }
//撤销
void Btn_undoClick(object sender, EventArgs e) void Btn_undoClick(object sender, EventArgs e)
{ {
if (cardedit != null) if (cardedit != null)
cardedit.Undo(); {
if (cardedit.undoSQL.Count == 0) cmdManager.Undo();
btn_undo.Enabled = false; Search(true);
}
} }
//导入卡图 //导入卡图
void Btn_imgClick(object sender, EventArgs e) void Btn_imgClick(object sender, EventArgs e)
...@@ -1105,45 +1098,8 @@ void Menuitem_copyselecttoClick(object sender, EventArgs e) ...@@ -1105,45 +1098,8 @@ void Menuitem_copyselecttoClick(object sender, EventArgs e)
//保存卡片到当前数据库 //保存卡片到当前数据库
public void SaveCards(Card[] cards) public void SaveCards(Card[] cards)
{ {
if (!CheckOpen()) cmdManager.ExcuteCommand(cardedit.copyCard, cards);
return;
if (cards == null || cards.Length == 0)
return;
bool replace = false;
Card[] oldcards = DataBase.Read(nowCdbFile, true, "");
if (oldcards != null && oldcards.Length != 0)
{
int i = 0;
foreach (Card oc in oldcards)
{
foreach (Card c in cards)
{
if (c.id == oc.id)
{
i += 1;
if (i == 1)
{
replace = MyMsg.Question(LMSG.IfReplaceExistingCard);
break;
}
}
}
if (i > 0)
break;
}
}
cardedit.undoSQL.Add("");
cardedit.undoModified.Add(new CardEdit.FileModified());
cardedit.undoDeleted.Add(new CardEdit.FileDeleted());
DataBase.CopyDB(nowCdbFile, !replace, cards);
CardEdit.DBcopied copied = new CardEdit.DBcopied();
copied.copied = true;
copied.NewCards = cards;
copied.replace = replace;
copied.OldCards = oldcards;
cardedit.undoCopied.Add(copied);
Search(srcCard, true); Search(srcCard, true);
btn_undo.Enabled = true;
} }
//卡片另存为 //卡片另存为
void CopyTo(Card[] cards) void CopyTo(Card[] cards)
......
...@@ -87,6 +87,7 @@ ...@@ -87,6 +87,7 @@
</Compile> </Compile>
<Compile Include="Common\MyPath.cs" /> <Compile Include="Common\MyPath.cs" />
<Compile Include="Controls\History.cs" /> <Compile Include="Controls\History.cs" />
<Compile Include="Core\CommandManager.cs" />
<Compile Include="Core\IDataForm.cs" /> <Compile Include="Core\IDataForm.cs" />
<Compile Include="Controls\IEditForm.cs" /> <Compile Include="Controls\IEditForm.cs" />
<Compile Include="Controls\IMainForm.cs" /> <Compile Include="Controls\IMainForm.cs" />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment