Commit f014efd8 authored by DailyShana's avatar DailyShana

rewrite undo

parent e72065c5
......@@ -20,7 +20,7 @@ public void SetPath(string gamepath)
luapath = MyPath.Combine(gamepath, "script");
ydkpath = MyPath.Combine(gamepath, "deck");
replaypath = MyPath.Combine(gamepath, "replay");
}
}
/// <summary>游戏目录</summary>
public string gamepath;
/// <summary>大图目录</summary>
......@@ -36,71 +36,63 @@ public void SetPath(string gamepath)
/// <summary>录像目录</summary>
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)
{
return MyPath.Combine(ydkpath, name + ".ydk");
}
//字符串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");
}
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");
}
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");//场地图
}
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");
}
public string[] GetCardfiles(long id, bool bak = false)
public string[] GetCardfiles(long id)
{
string[] files = new string[]{
GetImage(id, bak),//大图
GetImageThum(id, bak),//小图
GetImageField(id, bak),//场地图
GetScript(id, bak)
GetImage(id),//大图
GetImageThum(id),//小图
GetImageField(id),//场地图
GetScript(id)
};
return files;
}
public string[] GetCardfiles(string id, bool bak = false)
public string[] GetCardfiles(string id)
{
string[] files = new string[]{
GetImage(id, bak),//大图
GetImageThum(id, bak),//小图
GetImageField(id, bak),//场地图
GetScript(id, bak)
GetImage(id),//大图
GetImageThum(id),//小图
GetImageField(id),//场地图
GetScript(id)
};
return files;
}
}
}
}
......@@ -11,197 +11,244 @@ namespace DataEditorX.Core
public class CardEdit
{
IDataForm dataform;
public List<string> undoSQL;
public class FileModified
{
public bool modifiled = false;
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 AddCommand addCard;
public ModCommand modCard;
public DelCommand delCard;
public CopyCommand copyCard;
public CardEdit(IDataForm dataform)
{
this.dataform = dataform;
this.undoSQL = new List<string>();
this.undoModified = new List<FileModified>();
this.undoDeleted = new List<FileDeleted>();
this.undoCopied = new List<DBcopied>();
this.addCard = new AddCommand(this);
this.modCard = new ModCommand(this);
this.delCard = new DelCommand(this);
this.copyCard = new CopyCommand(this);
}
#region 添加
//添加
public bool AddCard()
{
if (!dataform.CheckOpen())
return false;
Card c = dataform.GetCard();
if (c.id <= 0)//卡片密码不能小于等于0
{
MyMsg.Error(LMSG.CodeCanNotIsZero);
return false;
}
Card[] cards = dataform.GetCardList(false);
foreach (Card ckey in cards)//卡片id存在
{
if (c.id == ckey.id)
{
MyMsg.Warning(LMSG.ItIsExists);
return false;
}
}
if (DataBase.Command(dataform.GetOpenFile(),
DataBase.GetInsertSQL(c, true)) >= 2)
{
MyMsg.Show(LMSG.AddSucceed);
undoSQL.Add(DataBase.GetDeleteSQL(c));
undoModified.Add(new FileModified());
undoDeleted.Add(new FileDeleted());
undoCopied.Add(new DBcopied());
dataform.Search(true);
dataform.SetCard(c);
return true;
}
MyMsg.Error(LMSG.AddFail);
return false;
}
#endregion
public class AddCommand: IBackableCommand
{
private string _undoSQL;
#region 修改
//修改
public bool ModCard(bool modfiles)
{
if (!dataform.CheckOpen())
return false;
Card c = dataform.GetCard();
Card oldCard = dataform.GetOldCard();
if (c.Equals(oldCard))//没有修改
{
MyMsg.Show(LMSG.ItIsNotChanged);
return false;
}
if (c.id <= 0)
{
MyMsg.Error(LMSG.CodeCanNotIsZero);
return false;
}
string sql;
if (c.id != oldCard.id)//修改了id
{
sql = DataBase.GetInsertSQL(c, false);//插入
bool delold = MyMsg.Question(LMSG.IfDeleteCard);
if (delold)//是否删除旧卡片
{
if (DataBase.Command(dataform.GetOpenFile(),
DataBase.GetDeleteSQL(oldCard)) < 2)
{
//删除失败
MyMsg.Error(LMSG.DeleteFail);
}
else
{//删除成功,添加还原sql
undoSQL.Add(DataBase.GetDeleteSQL(c)+DataBase.GetInsertSQL(oldCard, false));
}
} else
undoSQL.Add(DataBase.GetDeleteSQL(c));//还原就是删除
//如果删除旧卡片,则把资源修改名字,否则复制资源
if (modfiles)
CardEdit cardedit;
IDataForm dataform;
public AddCommand(CardEdit cardedit)
{
this.cardedit = cardedit;
this.dataform = cardedit.dataform;
}
public bool Excute(params object[] args)
{
if (!dataform.CheckOpen())
return false;
Card c = dataform.GetCard();
if (c.id <= 0)//卡片密码不能小于等于0
{
MyMsg.Error(LMSG.CodeCanNotIsZero);
return false;
}
Card[] cards = dataform.GetCardList(false);
foreach (Card ckey in cards)//卡片id存在
{
if (c.id == ckey.id)
{
MyMsg.Warning(LMSG.ItIsExists);
return false;
}
}
if (DataBase.Command(dataform.GetOpenFile(),
DataBase.GetInsertSQL(c, true)) >= 2)
{
MyMsg.Show(LMSG.AddSucceed);
_undoSQL = DataBase.GetDeleteSQL(c);
dataform.Search(true);
dataform.SetCard(c);
return true;
}
MyMsg.Error(LMSG.AddFail);
return false;
}
public void Undo()
{
DataBase.Command(dataform.GetOpenFile(), _undoSQL);
}
public object Clone()
{
return this.MemberwiseClone();
}
}
#endregion
#region 修改
//修改
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())
return false;
bool modfiles = (bool)args[0];
Card c = dataform.GetCard();
Card oldCard = dataform.GetOldCard();
if (c.Equals(oldCard))//没有修改
{
MyMsg.Show(LMSG.ItIsNotChanged);
return false;
}
if (c.id <= 0)
{
MyMsg.Error(LMSG.CodeCanNotIsZero);
return false;
}
string sql;
if (c.id != oldCard.id)//修改了id
{
sql = DataBase.GetInsertSQL(c, false);//插入
bool delold = MyMsg.Question(LMSG.IfDeleteCard);
if (delold)//是否删除旧卡片
{
if (DataBase.Command(dataform.GetOpenFile(),
DataBase.GetDeleteSQL(oldCard)) < 2)
{
//删除失败
MyMsg.Error(LMSG.DeleteFail);
delold = false;
}
else
{//删除成功,添加还原sql
_undoSQL = DataBase.GetDeleteSQL(c) + DataBase.GetInsertSQL(oldCard, false);
}
}
else
_undoSQL = DataBase.GetDeleteSQL(c);//还原就是删除
//如果删除旧卡片,则把资源修改名字,否则复制资源
if(modfiles)
{
if (delold)
YGOUtil.CardRename(c.id, oldCard.id, dataform.GetPath());
else
YGOUtil.CardCopy(c.id, oldCard.id, dataform.GetPath());
this.modifiled = true;
this.oldid = oldCard.id;
this.newid = c.id;
this.delold = delold;
}
}
else
{//更新数据
sql = DataBase.GetUpdateSQL(c);
_undoSQL = DataBase.GetUpdateSQL(oldCard);
}
if (DataBase.Command(dataform.GetOpenFile(), sql) > 0)
{
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());
MyMsg.Show(LMSG.ModifySucceed);
dataform.Search(true);
dataform.SetCard(c);
return true;
}
else
MyMsg.Error(LMSG.ModifyFail);
return false;
}
public void Undo()
{
DataBase.Command(dataform.GetOpenFile(), _undoSQL);
if (this.modifiled)
{
undoModified.Add(new FileModified());
undoDeleted.Add(new FileDeleted());
undoCopied.Add(new DBcopied());
if (this.delold)
YGOUtil.CardRename(this.oldid, this.newid, dataform.GetPath());
else
YGOUtil.CardDelete(this.newid, dataform.GetPath());
}
}
else
{//更新数据
sql = DataBase.GetUpdateSQL(c);
undoSQL.Add(DataBase.GetUpdateSQL(oldCard));
undoModified.Add(new FileModified());
undoDeleted.Add(new FileDeleted());
undoCopied.Add(new DBcopied());
}
if (DataBase.Command(dataform.GetOpenFile(), sql) > 0)
{
MyMsg.Show(LMSG.ModifySucceed);
dataform.Search(true);
dataform.SetCard(c);
return true;
}
else
MyMsg.Error(LMSG.ModifyFail);
return false;
}
}
public object Clone()
{
return this.MemberwiseClone();
}
}
#endregion
#region 删除
//删除
public bool DelCards(bool deletefiles)
{
if (!dataform.CheckOpen())
return false;
Card[] cards = dataform.GetCardList(true);
if (cards == null || cards.Length == 0)
return false;
string undo = "";
if (!MyMsg.Question(LMSG.IfDeleteCard))
return false;
List<string> sql = new List<string>();
FileDeleted delete = new FileDeleted();
foreach (Card c in cards)
{
sql.Add(DataBase.GetDeleteSQL(c));//删除
undo += DataBase.GetInsertSQL(c, true);
//删除资源
if (deletefiles)
{
YGOUtil.CardDelete(c.id, dataform.GetPath(), YGOUtil.DeleteOption.BACKUP);
delete.deleted = true;
delete.ids.Add(c.id);
}
}
if (DataBase.Command(dataform.GetOpenFile(), sql.ToArray()) >= (sql.Count * 2))
{
MyMsg.Show(LMSG.DeleteSucceed);
dataform.Search(true);
undoSQL.Add(undo);
undoDeleted.Add(delete);
undoModified.Add(new FileModified());
undoCopied.Add(new DBcopied());
return true;
}
else
{
MyMsg.Error(LMSG.DeleteFail);
dataform.Search(true);
}
return false;
}
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())
return false;
bool deletefiles = (bool)args[0];
Card[] cards = dataform.GetCardList(true);
if (cards == null || cards.Length == 0)
return false;
string undo = "";
if (!MyMsg.Question(LMSG.IfDeleteCard))
return false;
List<string> sql = new List<string>();
foreach (Card c in cards)
{
sql.Add(DataBase.GetDeleteSQL(c));//删除
undo += DataBase.GetInsertSQL(c, true);
//删除资源
if (deletefiles)
{
YGOUtil.CardDelete(c.id, dataform.GetPath());
}
}
if (DataBase.Command(dataform.GetOpenFile(), sql.ToArray()) >= (sql.Count * 2))
{
MyMsg.Show(LMSG.DeleteSucceed);
dataform.Search(true);
_undoSQL = undo;
return true;
}
else
{
MyMsg.Error(LMSG.DeleteFail);
dataform.Search(true);
}
return false;
}
public void Undo()
{
DataBase.Command(dataform.GetOpenFile(), _undoSQL);
}
public object Clone()
{
return this.MemberwiseClone();
}
}
#endregion
#region 打开脚本
......@@ -249,40 +296,79 @@ public bool OpenScript(bool openinthis)
}
return false;
}
#endregion
#endregion
#region 撤销
//撤销
public void Undo()
{
if (undoSQL.Count == 0)
{
return;
}
DataBase.Command(dataform.GetOpenFile(), undoSQL[undoSQL.Count - 1]);
undoSQL.RemoveAt(undoSQL.Count - 1);
if (undoModified[undoModified.Count - 1].modifiled)
#region 复制卡片
public class CopyCommand : IBackableCommand
{
bool copied = false;
Card[] NewCards;
bool replace;
Card[] OldCards;
CardEdit cardedit;
IDataForm dataform;
public CopyCommand(CardEdit cardedit)
{
FileModified lastmodify = undoModified[undoModified.Count - 1];
YGOUtil.CardRename(lastmodify.oldid, lastmodify.newid, dataform.GetPath(), lastmodify.delold);
this.cardedit = cardedit;
this.dataform = cardedit.dataform;
}
undoModified.RemoveAt(undoModified.Count - 1);
if (undoDeleted[undoDeleted.Count - 1].deleted)
public bool Excute(params object[] args)
{
FileDeleted lastdelete = undoDeleted[undoDeleted.Count - 1];
foreach (long id in lastdelete.ids)
YGOUtil.CardDelete(id, dataform.GetPath(), YGOUtil.DeleteOption.RESTORE);
if (!dataform.CheckOpen())
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;
}
}
}
if (i > 0)
break;
}
}
DataBase.CopyDB(dataform.GetOpenFile(), !replace, cards);
this.copied = true;
this.NewCards = cards;
this.replace = replace;
this.OldCards = oldcards;
return true;
}
undoDeleted.RemoveAt(undoDeleted.Count - 1);
if (undoCopied[undoCopied.Count - 1].copied)
public void Undo()
{
DBcopied lastcopied = undoCopied[undoCopied.Count - 1];
DataBase.DeleteDB(dataform.GetOpenFile(), lastcopied.NewCards);
DataBase.CopyDB(dataform.GetOpenFile(), !lastcopied.replace, lastcopied.OldCards);
DataBase.DeleteDB(dataform.GetOpenFile(), this.NewCards);
DataBase.CopyDB(dataform.GetOpenFile(), !this.replace, this.OldCards);
}
undoCopied.RemoveAt(undoCopied.Count - 1);
dataform.Search(true);
}
#endregion
}
public object Clone()
{
CopyCommand replica = new CopyCommand(cardedit);
replica.copied = this.copied;
replica.NewCards = (Card[])this.NewCards.Clone();
replica.replace = this.replace;
if (this.OldCards != null)
replica.OldCards = (Card[])this.OldCards.Clone();
return replica;
}
}
#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 @@
using System.IO;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using Microsoft.VisualBasic;
using Microsoft.VisualBasic.FileIO;
using System.Configuration;
using DataEditorX.Config;
using System.Windows.Forms;
using DataEditorX.Core.Info;
......@@ -205,59 +204,20 @@ public static string[] ReadImage(string path)
#region 删除资源
//删除资源
public enum DeleteOption
{
BACKUP,
RESTORE,
CLEAN,
NONE,
}
public static void CardDelete(long id, YgoPath ygopath, DeleteOption option)
public static void CardDelete(long id, YgoPath ygopath)
{
string[] files = ygopath.GetCardfiles(id);
string[] bakfiles = ygopath.GetCardfiles(id, true);
switch (option)
for (int i = 0; i < files.Length; i++)
{
case DeleteOption.BACKUP:
for (int i = 0; i < files.Length; i++)
{
if (File.Exists(bakfiles[i]))
File.Delete(bakfiles[i]);
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;
case DeleteOption.CLEAN:
for (int i = 0; i < bakfiles.Length; i++)
{
if (File.Exists(bakfiles[i]))
File.Delete(bakfiles[i]);
}
break;
case DeleteOption.NONE:
for (int i = 0; i < files.Length; i++)
{
if (File.Exists(files[i]))
File.Delete(files[i]);
}
break;
if (FileSystem.FileExists(files[i]))
FileSystem.DeleteFile(files[i], UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin);
}
}
#endregion
#region 资源改名
//资源改名
public static void CardRename(long newid, long oldid, YgoPath ygopath, bool delold)
public static void CardRename(long newid, long oldid, YgoPath ygopath)
{
string[] newfiles = ygopath.GetCardfiles(newid);
string[] oldfiles = ygopath.GetCardfiles(oldid);
......@@ -266,13 +226,32 @@ public static void CardRename(long newid, long oldid, YgoPath ygopath, bool delo
{
if (File.Exists(oldfiles[i]))
{
if (delold)
File.Move(oldfiles[i], newfiles[i]);
else
File.Copy(oldfiles[i], newfiles[i], false);
try {
File.Move(oldfiles[i], newfiles[i]);
}
catch { }
}
}
}
#endregion
#endregion
#region 复制资源
public static void CardCopy(long newid, long oldid, YgoPath ygopath)
{
string[] newfiles = ygopath.GetCardfiles(newid);
string[] oldfiles = ygopath.GetCardfiles(oldid);
for (int i = 0; i < oldfiles.Length; i++)
{
if (File.Exists(oldfiles[i]))
{
try {
File.Copy(oldfiles[i], newfiles[i], false);
}
catch { }
}
}
}
#endregion
}
}
......@@ -55,6 +55,8 @@ public partial class DataEditForm : DockContent, IDataForm
//setcode正在输入
bool[] setcodeIsedit = new bool[5];
CommandManager cmdManager = new CommandManager();
Image m_cover;
MSEConfig msecfg;
......@@ -90,6 +92,13 @@ void Initialize(string datapath)
InitializeComponent();
title = this.Text;
nowCdbFile = "";
cmdManager.UndoStateChanged += delegate (bool val)
{
if (val)
btn_undo.Enabled = true;
else
btn_undo.Enabled = false;
};
}
#endregion
......@@ -147,18 +156,6 @@ void DataEditFormLoad(object sender, EventArgs 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())
{
......@@ -566,7 +563,7 @@ void Lv_cardlistKeyDown(object sender, KeyEventArgs e)
switch (e.KeyCode)
{
case Keys.Delete:
cardedit.DelCards(menuitem_operacardsfile.Checked);
cmdManager.ExcuteCommand(cardedit.delCard, menuitem_operacardsfile.Checked);
break;
case Keys.Right:
Btn_PageDownClick(null, null);
......@@ -730,18 +727,14 @@ void Btn_resetClick(object sender, EventArgs e)
//添加
void Btn_addClick(object sender, EventArgs e)
{
if(cardedit != null)
cardedit.AddCard();
if (cardedit.undoSQL.Count != 0)
btn_undo.Enabled = true;
if (cardedit != null)
cmdManager.ExcuteCommand(cardedit.addCard);
}
//修改
void Btn_modClick(object sender, EventArgs e)
{
if (cardedit != null)
cardedit.ModCard(menuitem_operacardsfile.Checked);
if (cardedit.undoSQL.Count != 0)
btn_undo.Enabled = true;
cmdManager.ExcuteCommand(cardedit.modCard, menuitem_operacardsfile.Checked);
}
//打开脚本
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)
{
if (cardedit != null)
cardedit.DelCards(menuitem_operacardsfile.Checked);
if (cardedit.undoSQL.Count != 0)
btn_undo.Enabled = true;
cmdManager.ExcuteCommand(cardedit.delCard, menuitem_operacardsfile.Checked);
}
//撤销
void Btn_undoClick(object sender, EventArgs e)
{
if (cardedit != null)
cardedit.Undo();
if (cardedit.undoSQL.Count == 0)
btn_undo.Enabled = false;
{
cmdManager.Undo();
Search(true);
}
}
//导入卡图
void Btn_imgClick(object sender, EventArgs e)
......@@ -1105,45 +1098,8 @@ void Menuitem_copyselecttoClick(object sender, EventArgs e)
//保存卡片到当前数据库
public void SaveCards(Card[] cards)
{
if (!CheckOpen())
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);
cmdManager.ExcuteCommand(cardedit.copyCard, cards);
Search(srcCard, true);
btn_undo.Enabled = true;
}
//卡片另存为
void CopyTo(Card[] cards)
......
......@@ -87,6 +87,7 @@
</Compile>
<Compile Include="Common\MyPath.cs" />
<Compile Include="Controls\History.cs" />
<Compile Include="Core\CommandManager.cs" />
<Compile Include="Core\IDataForm.cs" />
<Compile Include="Controls\IEditForm.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