SuperDesign/Source/RySmartEditor/SmartEditor/FrmFileEditor.cs
zilinsoft 993f1ca1a9 ### 2024-12-20 星期五更新
------
#### SuperDesign    V3.0.2412.2001
- *.[新增]新增程序更新日志设置和自动发布功能。
- *.[修复]修复Post数据格式不正确时双击文本框会导致软件闪退的BUG。
2024-12-20 08:15:19 +08:00

928 lines
37 KiB
C#

using ryCommon;
using ryCommonDb;
using .Manager.FTP;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Security.Policy;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Linq;
using WeifenLuo.WinFormsUI.Docking;
using .Manager;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Window;
using static System.Net.Mime.MediaTypeNames;
using System.IO;
using ryControls;
using SuperDesign.Tools.SmartEditor;
using GameBackup3H3.DbOp;
using MyPage;
using ObjectListViewDemo;
namespace .Tools.SmartEditor
{
public partial class FrmFileEditor : DockContent
{
public FrmFileEditor()
{
InitializeComponent();
AutoScaleMode = AutoScaleMode.Dpi;
highlightEditor1.TextChanged += HighlightEditor1_TextChanged;
highlightEditor1.OnSaveKeyHappen += HighlightEditor1_OnSaveKeyHappen;
List<string> autoc_list = new List<string>();
highlightEditor1.Font = new Font("Consolas",12f);
autoc_list.AddRange(RyFiles.ReadAllLines(System.Windows.Forms.Application.StartupPath + "\\SysDb\\AutoComplete\\editor.txt"));
highlightEditor1.SetAutoCompleteList(autoc_list);
}
private void HighlightEditor1_OnSaveKeyHappen(object sender, EventArgs e)
{
OnSaveKeyHappen?.Invoke(this, e);
}
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == (Keys.Control | Keys.R))
{
if (FilePath.Length == 0)
{
return true;
}
}
return base.ProcessCmdKey(ref msg, keyData);//这里就是返回没有重写的键位,也就是这个函数原本的处理方式 //其余键位默认处理
}
/// <summary>
/// 未保存状态改变
/// </summary>
[Description("未保存状态改变")]
public event EventHandler OnUnSaveChanged;
/// <summary>
/// 保存热键发生时
/// </summary>
[Description("保存热键发生时")]
public event EventHandler OnSaveKeyHappen;
/// <summary>
/// 打开其它站点文件
/// </summary>
[Description("打开其它站点文件")]
public event EventHandler OnOpenOtherSiteFile;
private void HighlightEditor1_TextChanged(object sender, EventArgs e)
{
if (!IsChanged)
{
IsChanged = true;
OnUnSaveChanged?.Invoke(this, new EventArgs());
}
}
/// <summary>
/// 对应的Site
/// </summary>
public SiteInfo SiteInfo { get; set; } = new SiteInfo();
private Encoding encoding = Encoding.UTF8;
/// <summary>
/// 当前文件格式
/// </summary>
public Encoding Encoding {
get { return encoding; }
set
{
encoding = value;
IsChanged = true;
OnUnSaveChanged?.Invoke(this, new EventArgs());
}
}
/// <summary>
/// 加载的文件大小
/// </summary>
public long FileSize { get; private set; } = 0;
/// <summary>
/// 文件写入时间
/// </summary>
public long FileWriteTime { get; private set; } = 0;
/// <summary>
/// 文件创建时间
/// </summary>
public long FileCreateTime { get; private set; } = 0;
/// <summary>
/// 当前选择的文件路径
/// </summary>
public string FilePath { get; set; } = "";
/// <summary>
/// 文件改变是否进行提醒,保存文件后会重新进行提醒
/// </summary>
public bool Fileinfo_Changed_Tip { get; set; } = true;
/// <summary>
/// 当前选择的FTP远程文件路径,只有当FilePath为空时才生效
/// </summary>
public string FTPRemotePath { get; set; } = "";
public void GetFileInfo(string path)
{
FileSize = RyFiles.GetFileSize(path);
var dt = RyFiles.GetFileDate(path);
FileWriteTime = dt.LastWriteTime.ToInt64();
FileCreateTime = dt.CreateTime.ToInt64();
}
public string InitFilePath { get; set; } = "";
public string InitCacheText { get; set; } = "";
public int FirstVisibleLine { get; set; } = 0;
public void LoadInitFile(string path, string CacheText = "")
{
if (!System.IO.File.Exists(path))
{
MessageBox.Show("文件不存在=>" + path, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.Close();
return;
}
InitFilePath = path;
InitCacheText = CacheText;
FilePath = path;
GetSites();
IsChanged = CacheText.Length > 0;
UpdateTitle();
this.Icon = ShellUtilities.GetFileIcon(path, true, true);
}
private void GetSites()
{
IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType);
if (db.ConnDb(Itrycn_Db.User_SQLConn) == 1)
{
DataSet ds = db.ReadData("select * from Site");
if (ds.HaveData())
{
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
DataRow reader = ds.Tables[0].Rows[i];
if (FilePath.IndexOfEx(reader["localPath"].ToString()) < 0)
{
continue;
}
#region
SiteInfo.Name = reader["name"].ToString();
SiteInfo.LocalPath = reader["localPath"].ToString();
SiteInfo.FtpDir = reader["ftpDir"].ToString();
SiteInfo.FtpId = reader["ftpId"].ToInt();
SiteInfo.Id = reader["Id"].ToInt();
break;
#endregion
}
}
ds.Dispose();
}
db.Free();
}
public int LoadFile(string path,string CacheText="")
{
if (!System.IO.File.Exists(path)) {
MessageBox.Show("文件不存在=>"+path, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.Close();
return -1;
}
Encoding = TxtFileEncoder.GetEncoding(path,Encoding.GetEncoding("GB2312"));
highlightEditor1.SetHightlightText(CacheText.Length==0? RyFiles.ReadAllText(path,Encoding): CacheText, System.IO.Path.GetFileName(path));
GetFileInfo(path);
FilePath = path;
SiteInfo.FtpId=0;
SiteInfo.Id = 0;
GetSites();
IsChanged = CacheText.Length>0;
UpdateTitle();
highlightEditor1.Editor.EmptyUndoBuffer();
this.Icon = ShellUtilities.GetFileIcon(path, true, true);
OnUnSaveChanged?.Invoke(this, new EventArgs());
return 1;
}
public void UpdateTitle()
{
if (FilePath.Length == 0 && FTPRemotePath.Length==0) {
return;
}
var text = System.IO.Path.GetFileName(FilePath.Length == 0 ?FTPRemotePath: FilePath);
if(SiteInfo.FtpId>0)
{
if (FilePath.Length == 0)
{
text = "[" + SiteInfo.Name + "][FTP]" + text;
}
else
{
text = "[" + SiteInfo.Name + "]" + text;
}
}
if (IsChanged) { text = "*" + text; }
Text = text;
}
/// <summary>
/// FTP远程路径
/// </summary>
public string RemotePath
{
get
{
if (FilePath.Length == 0 && SiteInfo.FtpId > 0)
{
return FTPRemotePath;
}
else
{
return SiteInfo.FtpDir.Trim('/') + "/" + XDPath.Replace("\\", "/");
}
}
}
/// <summary>
/// 相对路径
/// </summary>
public string XDPath
{
get
{
if (FilePath.Length == 0) { return ""; }
if (SiteInfo.LocalPath.Length == 0) { return ""; }
return FilePath.Replace(SiteInfo.LocalPath, "", true).Trim('\\');
}
}
public int UploadFTP()
{
if (SiteInfo.FtpId <= 0) { return -1; }
var result = -2;
var uploadinfo = GetUploadInfo();
if (uploadinfo == null) { return -1; }
FrmUploadProg frm = new FrmUploadProg();
frm.UploadList.Add(uploadinfo);
if (frm.ShowDialog() == DialogResult.OK)
{
result = 1;
}
frm.Dispose();
return result;
}
/// <summary>
/// 获取FTP上传信息
/// </summary>
/// <returns></returns>
public UploadInfo GetUploadInfo()
{
UploadInfo uploadinfo = null;
IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType);
if (db.ConnDb(Itrycn_Db.User_SQLConn) == 1)
{
DataSet ds = db.ReadData("select * from Ftp where Id=" + SiteInfo.FtpId);
if (ds.HaveData())
{
DataRow row = ds.Tables[0].Rows[0];
var FtpInfo = new GameBackup3H3.DbOp.FTPInfo()
{
Id = row["id"].ToInt(),
Name = row["name"].ToString(),
IP = row["ip"].ToString(),
Port = row["port"].ToInt(),
RemoteDir = SiteInfo.FtpDir,
UserName = row["username"].ToString(),
Pwd = row["pwd"].ToString(),
Encrypt = row["encrypt"].ToInt(0, 2, 0),
AddTime = row["AddTime"].ToDateTime()
};
uploadinfo = new UploadInfo() {
FtpInfo = FtpInfo,
RemotePath = RemotePath,
LocalPath = FilePath,
Content = highlightEditor1.Text,
Encoding = Encoding
};
}
ds.Dispose();
}
db.Free();
return uploadinfo;
}
public int UploadFTPByAllSite()
{
if (SiteInfo.FtpId <= 0) { return -1; }
var result = -2;
IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType);
if (db.ConnDb(Itrycn_Db.User_SQLConn) == 1)
{
DataSet ds = db.ReadData("select * from Site");
if (ds.HaveData())
{
FrmUploadProg frm = new FrmUploadProg();
var xd_path = XDPath;
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
DataRow reader = ds.Tables[0].Rows[i];
if(!System.IO.File.Exists(reader["localPath"].ToString() + "\\" + xd_path)) { continue; }
DataSet ds_ftp = db.ReadData("select * from Ftp where Id=" + reader["ftpId"].ToInt());
if (ds_ftp.HaveData())
{
DataRow row = ds_ftp.Tables[0].Rows[0];
var FtpInfo = new GameBackup3H3.DbOp.FTPInfo()
{
Id = row["id"].ToInt(),
Name = row["name"].ToString(),
IP = row["ip"].ToString(),
Port = row["port"].ToInt(),
RemoteDir = reader["ftpDir"].ToString(),
UserName = row["username"].ToString(),
Pwd = row["pwd"].ToString(),
Encrypt = row["encrypt"].ToInt(0, 2, 0),
AddTime = row["AddTime"].ToDateTime()
};
var remotepath = reader["ftpDir"].ToString().Trim('/') + "/" + xd_path.Replace("\\", "/").Trim('/');
frm.UploadList.Add(new UploadInfo() { FtpInfo = FtpInfo, RemotePath = remotepath, LocalPath = reader["localPath"].ToString()+"\\"+ xd_path });
}
ds_ftp.Dispose();
}
if (frm.ShowDialog() == DialogResult.OK)
{
result = 1;
}
frm.Dispose();
}
ds.Dispose();
}
db.Free();
return result;
}
/// <summary>
/// 保存
/// </summary>
public int Save()
{
Fileinfo_Changed_Tip = true;
if(InitFilePath.Length>0)
{
LoadFile(InitFilePath,InitCacheText);
InitFilePath = "";
InitCacheText = "";
}
if(FilePath.Length==0)
{
if (SiteInfo.FtpId > 0)
{
var result = -1;
var uploadinfo = GetUploadInfo();
if (uploadinfo == null) { return -1; }
FrmUploadProg frm = new FrmUploadProg();
frm.UploadList.Add(uploadinfo);
if (frm.ShowDialog() == DialogResult.OK)
{
result = 1;
Itrycn_Db.AddHistory("[FTP:"+ SiteInfo.FtpId + "]"+uploadinfo.RemotePath, highlightEditor1.Text);
IsChanged = false;
//FrmMainEditor.MainEditor.UpdateFTPFileState(uploadinfo.FtpInfo.Id, uploadinfo.RemotePath, uploadinfo.FileWriteTime, uploadinfo.FileSize);
OnUnSaveChanged?.Invoke(this, new EventArgs());
}
frm.Dispose();
return result;
//Itrycn_Db.AddHistory(dialog.FileName, highlightEditor1.Text);
}
else
{
SaveFileDialog dialog = new SaveFileDialog
{
FileName = "新建文档.txt",
Filter = "常用格式|*.php;*.cs;*.txt;*.pas;*.js;*.html;*.htm;*.css;*.ini;*.json;*.xml;*.java;*.vbs;*.asp;*.aspx|所有文件|*.*"
};
if (dialog.ShowDialog() == DialogResult.OK)
{
FilePath = dialog.FileName;
try
{
RyFiles.WriteAllText(dialog.FileName, highlightEditor1.Text, Encoding);
}
catch (Exception ex)
{
MessageBox.Show(FilePath + "\r\n" + ex.Message, "出错", MessageBoxButtons.OK, MessageBoxIcon.Error);
return -1;
}
Itrycn_Db.AddHistory(dialog.FileName, highlightEditor1.Text);
GetFileInfo(dialog.FileName);
FrmMainEditor.MainEditor.UpdateFileState(FilePath);
IsChanged = false;
OnUnSaveChanged?.Invoke(this, new EventArgs());
return 1;
}
}
}
else
{
try
{
RyFiles.WriteAllText(FilePath, highlightEditor1.Text, Encoding);
}
catch(Exception ex) {
MessageBox.Show(FilePath+"\r\n" +ex.Message, "出错", MessageBoxButtons.OK, MessageBoxIcon.Error);
return -1;
}
Itrycn_Db.AddHistory(FilePath, highlightEditor1.Text);
GetFileInfo(FilePath);
IsChanged = false;
FrmMainEditor.MainEditor.UpdateFileState(FilePath);
OnUnSaveChanged?.Invoke(this, new EventArgs());
return 1;
}
return -1;
}
/// <summary>
/// 是否内容改变
/// </summary>
public bool IsChanged { get; internal set; } = true;
/// <summary>
/// 保存
/// </summary>
/// <param name="path"></param>
public void Save(string path)
{
RyFiles.WriteAllText(path, highlightEditor1.Text, Encoding);
Itrycn_Db.AddHistory(path, highlightEditor1.Text);
IsChanged = false;
Fileinfo_Changed_Tip = true;
FrmMainEditor.MainEditor.UpdateFileState(FilePath);
OnUnSaveChanged?.Invoke(this, new EventArgs());
}
/// <summary>
/// 删除重复行
/// </summary>
public void DeleteRepeatLine()
{
var lines = highlightEditor1.Text.Replace("\r", "").Split('\n');
var txt = "";
var dict=new Dictionary<string, int>();
for (int i = 0; i < lines.Length; i++)
{
var line = lines[i];
if (line.Length == 0) { continue; }
if (dict.ContainsKey(line)) { continue; }
if (txt.Length != 0) { txt += "\r\n"; }
txt+= line;
dict[line] = i;
}
highlightEditor1.Text = txt;
}
/// <summary>
/// 删除空白行
/// </summary>
public void DeleteWhiteLine()
{
var lines = highlightEditor1.Text.Replace("\r", "").Split('\n');
var txt = "";
for (int i = 0; i < lines.Length; i++)
{
var line = lines[i];
if (line.Trim().Length == 0) { continue; }
if (txt.Length != 0) { txt += "\r\n"; }
txt += line;
}
highlightEditor1.Text = txt;
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
switch (MessageBox.Show("是否确定要关闭?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question))
{
case DialogResult.Cancel:
return;
}
DockContentCollection contents = this.DockPanel.Contents;
int num = 0;
while (num < contents.Count)
{
var content = contents[num];
if (content.DockHandler.DockState == DockState.Document && this.DockPanel.ActiveContent != content)
{
var canClose = true;
if (content is FrmFileEditor frm)
{
if(frm.IsChanged)
{
switch (MessageBox.Show("是否要保存文档?\r\n\r\n是:保存该文档并关闭。\r\n否:不保存该文档并关闭。\r\n取消:取消关闭该文档。", "询问", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2))
{
case DialogResult.Cancel:
canClose = false;
break;
case DialogResult.No:
break;
case DialogResult.Yes:
if(frm.Save()!=1)
{
canClose = false;
}
break;
}
}
}
if (canClose) {
content.DockHandler.Close();
}
else { num++; }
}
else
{
num++;
}
}
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (FilePath.Length == 0) { return; }
bool isAdd = false;
if (ToolStripMenuItem.Text.IndexOfEx("取消") >= 0)
{
switch (MessageBox.Show("是否确定要取消收藏?\r\n选是:取消收藏\r\n选否:新建收藏。\r\n选取消:不再取消收藏。", "询问", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2))
{
case DialogResult.Yes:
break;
case DialogResult.No:
isAdd = true;
break;
default:
return;
}
if (!isAdd)
{
RyQuickSQL mySQL = new RyQuickSQL("FavFiles");
mySQL.AddField("FilePath", FilePath);
IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType);
if (db.ConnDb(Itrycn_Db.User_SQLConn) == 1)
{
db.ExecuteNonQuery("delete from FavFiles where FilePath=@FilePath and GroupId=0", mySQL);
}
db.Free();
return;
}
}
else
{
isAdd = true;
}
if(isAdd)
{
FrmFavFile frm = new FrmFavFile
{
FilePath = FilePath
};
frm.SelectedId = 0;
frm.TxtFind.Text = this.highlightEditor1.GetNearestFunLineStr(this.highlightEditor1, out _);
frm.TxtFavName.Text = System.IO.Path.GetFileName(FilePath);
if (frm.ShowDialog() == DialogResult.OK)
{
}
frm.Dispose();
}
}
private void ContextMenuStrip1_Opening(object sender, CancelEventArgs e)
{
ToolStripMenuItem.Enabled = FilePath.Length > 0;
ToolStripMenuItem.Enabled = FilePath.Length > 0;
ToolStripMenuItem.Enabled =FTPRemotePath.Length>0 || FilePath.Length > 0;
ToolStripMenuItem.Enabled = SiteInfo.FtpId > 0 && FilePath.Length>0;
ToolStripMenuItem.Enabled = FilePath.Length > 0;
ToolStripMenuItem.Enabled = FilePath.Length > 0;
ToolStripMenuItem.Enabled = FilePath.Length > 0;
ToolStripMenuItem.Enabled = FilePath.Length > 0;
ToolStripMenuItem.Enabled = FilePath.Length > 0;
FTP上的对应文件ToolStripMenuItem.Enabled=FilePath.Length > 0 && SiteInfo.FtpId>0;
FTP上的对应文件ToolStripMenuItem.Enabled = FilePath.Length > 0 && SiteInfo.FtpId > 0;
if (FrmMainEditor.MainEditor.CompareTitle1.Length > 0)
{ 1ToolStripMenuItem.Text = "比对文本1=>" + FrmMainEditor.MainEditor.CompareTitle1; }
else
{
1ToolStripMenuItem.Text = "比对文本1";
}
if (FrmMainEditor.MainEditor.CompareTitle2.Length > 0)
{ 2ToolStripMenuItem.Text = "比对文本2=>" + FrmMainEditor.MainEditor.CompareTitle2; }
else
{
2ToolStripMenuItem.Text = "比对文本2";
}
RyQuickSQL mySQL = new RyQuickSQL("FavFiles");
mySQL.AddField("FilePath", FilePath);
IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType);
if (db.ConnDb(Itrycn_Db.User_SQLConn) == 1)
{
var ds = db.ReadData("select * from FavFiles where FilePath=@FilePath and GroupId=0 limit 1", mySQL);
if(ds.HaveData())
{
ToolStripMenuItem.Text = "取消该文件收藏";
}
else
{
ToolStripMenuItem.Text = "收藏该文件";
}
ds.Dispose();
}
db.Free();
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
if(FilePath.Length > 0)
{
RyFiles.OpenFolderGotoFile(FilePath);
}
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (FilePath.Length == 0) { return; }
RyFiles.CopyToClip(FilePath);
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (FilePath.Length == 0) { return; }
RyFiles.CopyToClip(System.IO.Path.GetFileName(FilePath));
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (FilePath.Length == 0) { return; }
RyFiles.CopyToClip(System.IO.Path.GetDirectoryName(FilePath));
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
FrmFileInfo frm = new FrmFileInfo();
frm.LoadInfo(FilePath,SiteInfo);
frm.ShowDialog();
frm.Dispose();
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (SiteInfo.Id == 0) { return; }
OnOpenOtherSiteFile?.Invoke(this, EventArgs.Empty);
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
DockContentCollection contents = this.DockPanel.Contents;
int num = 0;
FrmFileBrowser_New first_visible=null;
while (num < contents.Count)
{
var content = contents[num];
if (content.DockHandler.DockState == DockState.DockLeft)
{
if(content is FrmFileBrowser frm)
{
if (frm.Visible)
{
frm.GotoPath(FilePath);
break;
}
else
{
num++;
}
}
else if (content is FrmFileBrowser_New frm2) {
if(this.SiteInfo.Name.IndexOfEx(frm2.Text)>=0 || frm2.Text.IndexOfEx(this.SiteInfo.Name)>=0)
{
frm2.Show(FrmMainEditor.MainEditor.dockPanel, DockState.DockLeft);
//frm2.BringToFront();
frm2.GotoPath(System.IO.Path.GetDirectoryName(FilePath), FilePath);
first_visible = null;
break;
}
else if (frm2.Visible) {
first_visible = frm2;
//frm2.GotoPath(System.IO.Path.GetDirectoryName(FilePath), FilePath);
//break;
}
num++;
}
else {
num++;
}
}
else
{
num++;
}
}
if (first_visible != null)
{
first_visible.GotoPath(System.IO.Path.GetDirectoryName(FilePath), FilePath);
}
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
FrmHistoryView frm = new FrmHistoryView
{
FilePath = FilePath.Length==0?"[FTP:"+SiteInfo.FtpId+"]"+ FTPRemotePath : FilePath,
Content = highlightEditor1.Text,
CurHighliteLang = highlightEditor1.CurHighliteLang,
SelectModeOn = true,
TopMost = this.TopMost
};
frm.FormClosed += delegate (object sender_item, FormClosedEventArgs e1) {
if (frm.DialogResult == DialogResult.OK)
{
if (!this.IsDisposed)
{
if (IsChanged)
{
switch (MessageBox.Show("当前记录未保存,是否要替换成历史记录?", "询问", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2))
{
case DialogResult.No:
frm.Dispose();
return;
}
Itrycn_Db.AddHistory(FilePath.Length == 0 ? "[FTP:" + SiteInfo.FtpId + "]" + FTPRemotePath : FilePath, highlightEditor1.Text);
}
IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType);
if (db.ConnDb(Itrycn_Db.History_SQLConn) == 1)
{
DataSet ds = db.ReadData("select * from History where id=" + frm.SelectedItem.Id);
if (ds.HaveData())
{
highlightEditor1.Text = ds.GetFirstRowData()["content"].ToString();
}
ds?.Dispose();
}
db.Free();
}
else
{
MessageBox.Show("窗口已经被关闭,无法加载历史记录。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
};
frm.Show();
}
private void Frm_FormClosed(object sender, FormClosedEventArgs e)
{
throw new NotImplementedException();
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
switch (MessageBox.Show("是否确定要关闭?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question))
{
case DialogResult.Cancel:
return;
}
DockContentCollection contents = this.DockPanel.Contents;
int num = 0;
while (num < contents.Count)
{
var content = contents[num];
if (content == this)
{
break;
}
if (content.DockHandler.DockState == DockState.Document)
{
var canClose = true;
if (content is FrmFileEditor frm)
{
if (frm.IsChanged)
{
switch (MessageBox.Show("是否要保存文档?\r\n" + frm.FilePath + "\r\n\r\n是:保存该文档并关闭。\r\n否:不保存该文档并关闭。\r\n取消:取消关闭该文档。", "询问", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2))
{
case DialogResult.Cancel:
canClose = false;
break;
case DialogResult.No:
break;
case DialogResult.Yes:
if (frm.Save() != 1)
{
canClose = false;
}
break;
}
}
}
if (canClose) {
content.DockHandler.Close();
}
else { num++; }
}
else
{
num++;
}
}
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
switch (MessageBox.Show("是否确定要关闭?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question))
{
case DialogResult.Cancel:
return;
}
DockContentCollection contents = this.DockPanel.Contents;
int num = 0;
var start = false;
while (num < contents.Count)
{
var content = contents[num];
if (content == this)
{
start = true;
num++;
continue;
}
if (content.DockHandler.DockState == DockState.Document && start)
{
var canClose = true;
if (content is FrmFileEditor frm)
{
if (frm.IsChanged)
{
switch (MessageBox.Show("是否要保存文档?\r\n" + frm.FilePath + "\r\n\r\n是:保存该文档并关闭。\r\n否:不保存该文档并关闭。\r\n取消:取消关闭该文档。", "询问", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2))
{
case DialogResult.Cancel:
canClose = false;
break;
case DialogResult.No:
break;
case DialogResult.Yes:
if (frm.Save() != 1)
{
canClose = false;
}
break;
}
}
}
if (canClose) {
content.DockHandler.Close();
}
else { num++; }
}
else
{
num++;
}
}
}
private void FTP上的对应文件ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (FilePath.Length > 0)
_ = FrmMainEditor.MainEditor.OpenFTPFileByNewForm(SiteInfo, RemotePath);
}
private void FTP上的对应文件ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (FilePath.Length > 0)
FrmMainEditor.MainEditor.CompareFTPFile(SiteInfo, RemotePath,this);
}
private void 1ToolStripMenuItem_Click(object sender, EventArgs e)
{
FrmMainEditor.MainEditor.CompareText1 = highlightEditor1.Text;
FrmMainEditor.MainEditor.CompareTitle1 = this.Text;
if (FrmMainEditor.MainEditor.CompareText2.Length>0)
{
FrmCompare frm2 = new FrmCompare
{
CurHighliteLang = highlightEditor1.CurHighliteLang,
TextLeft = FrmMainEditor.MainEditor.CompareText1,
TextRight = FrmMainEditor.MainEditor.CompareText2,
TitleLeft = FrmMainEditor.MainEditor.CompareTitle1,
TitleRight = FrmMainEditor.MainEditor.CompareTitle2
};
frm2.ShowDialog(FrmMainEditor.MainEditor);
frm2.Dispose();
}
}
private void 2ToolStripMenuItem_Click(object sender, EventArgs e)
{
FrmMainEditor.MainEditor.CompareText2 = highlightEditor1.Text;
FrmMainEditor.MainEditor.CompareTitle2 = this.Text;
if (FrmMainEditor.MainEditor.CompareText1.Length > 0)
{
FrmCompare frm2 = new FrmCompare
{
CurHighliteLang = highlightEditor1.CurHighliteLang,
TextLeft = FrmMainEditor.MainEditor.CompareText1,
TextRight = FrmMainEditor.MainEditor.CompareText2,
TitleLeft = FrmMainEditor.MainEditor.CompareTitle1,
TitleRight = FrmMainEditor.MainEditor.CompareTitle2
};
frm2.ShowDialog(FrmMainEditor.MainEditor);
frm2.Dispose();
}
}
}
}