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

313 lines
12 KiB
C#

using ryCommon;
using ryCommonDb;
using .Tools.SmartEditor;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using .Manager;
using static ScintillaNET.Style;
using System.IO;
using ryControls;
using static VPKSoft.ScintillaLexers.LexerEnumerations;
using DiffPlex.Model;
using VPKSoft.ScintillaLexers;
using ScintillaDiff;
using RySmartEditor.Controls;
using BrightIdeasSoftware;
namespace GameBackup3H3.DbOp
{
public partial class FrmHistoryView : Form
{
string orderSQL = "order by addTime desc";
string tableName = "History";
string titleName = "历史记录";
public FrmHistoryView()
{
InitializeComponent();
this.LvCbResult.RowHeight = 48;
this.LvCbResult.UseAlternatingBackColors = false;
this.LvCbResult.UseHotItem = false;
this.OlvName.Renderer = CreateDescribedTaskRenderer();
OlvName.AspectGetter = delegate (object x) {
return ((HistoryInfo)x).AddTimeStr;
};
OlvSize.AspectGetter = delegate (object x) { return ((HistoryInfo)x).Size+"字"; };
}
private DescribedTaskRenderer CreateDescribedTaskRenderer()
{
// Let's create an appropriately configured renderer.
DescribedTaskRenderer renderer = new DescribedTaskRenderer();
// Give the renderer its own collection of images.
// If this isn't set, the renderer will use the SmallImageList from the ObjectListView.
// (this is standard Renderer behaviour, not specific to DescribedTaskRenderer).
// Tell the renderer which property holds the text to be used as a description
renderer.DescriptionAspectName = "Name";
renderer.UseCustomCheckboxImages = false;
// Change the formatting slightly
renderer.TitleFont = new Font("Tahoma", 11, FontStyle.Regular);
renderer.DescriptionFont = new Font("Tahoma", 9);
renderer.DescriptionColor = Color.Gray;
renderer.TopSpace = 3;
//renderer.ImageTextSpace = 8;
renderer.TitleDescriptionSpace = 5;
// Use older Gdi renderering, since most people think the text looks clearer
renderer.UseGdiTextRendering = true;
// If you like colours other than black and grey, you could uncomment these
// renderer.TitleColor = Color.DarkBlue;
// renderer.DescriptionColor = Color.CornflowerBlue;
return renderer;
}
#region
private void RySearch1_OnSearch(object sender, EventArgs e)
{
//需要修改此处
LoadDb("(name like @SearchText or content like @SearchText)");
}
private void CtlMyPage1_OnPageChange(object sender, EventArgs e)
{
#region
LvCbResult.ClearObjects();
List<HistoryInfo> list = new List<HistoryInfo>();
IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType);
if (db.ConnDb(Itrycn_Db.History_SQLConn) == 1)
{
DataSet ds = db.ReadData(ctlMyPage1.GetSQLText, ctlMyPage1.T_Parameters);
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
DataRow row = ds.Tables[0].Rows[i];
list.Add(new HistoryInfo()
{
Id=row["id"].ToInt(),
Name = row["name"].ToString(),
Size = row["size"].ToInt64(),
AddTime = row["AddTime"].ToDateTime()
}) ;
}
}
db.Free();
LvCbResult.AddObjects(list);
if(list.Count>0) {
LvCbResult.SelectedObject = list[0];
}
#endregion
}
#endregion
public string FilePath { get; set; } = "";
public string Content { get; set; } = "";
/// <summary>
/// 当前高亮语言
/// </summary>
public LexerType CurHighliteLang
{
get; set;
} = LexerType.Text;
private int FileId { get; set; } = 0;
public void LoadDb(string whereSQL)
{
string _whereSQL = whereSQL;
if (FileId > 0)
{
_whereSQL += " and fileid=" + FileId;
}
else { return; }
IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType);
if (db.ConnDb(Itrycn_Db.History_SQLConn) == 1)
{
#region
db.AddParameter("SearchText", "%" + rySearch1.Text + "%");
ctlMyPage1.RecordCount = db.GetCount(tableName, _whereSQL);
ctlMyPage1.T_Parameters = db.GetParameter();
ctlMyPage1.SQLText= db.GetPageSQL(tableName, _whereSQL, orderSQL);
ctlMyPage1.SQLText2 = db.GetPageSQL2(tableName, _whereSQL, orderSQL);
ctlMyPage1.GotoPageIndex(1);
#endregion
}
db.Free();
}
private void BtnEdit_Click(object sender, EventArgs e)
{
if (LvCbResult.SelectedObject == null) { return; }
this.Enabled = false;
var item = (HistoryInfo)LvCbResult.SelectedObject;
var selectId = item.Id;
FrmTitle frm = new FrmTitle()
{
Text = "修改"+ titleName,
Icon = Icon,
};
frm.TxtTitle.Text = item.Name;
if(frm.ShowDialog()==DialogResult.OK)
{
RyQuickSQL mySQL = new RyQuickSQL("History");
mySQL.AddField("name", frm.TxtTitle.Text);
IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType);
if (db.ConnDb(Itrycn_Db.History_SQLConn) == 1)
{
db.ExecuteNonQuery(mySQL.GetUpdateSQL() + " where id=" + selectId, mySQL);
item.Name=frm.TxtTitle.Text;
LvCbResult.RefreshObject(item);
}
db.Free();
}
frm.Dispose();
this.Enabled = true;
}
private void BtnDel_Click(object sender, EventArgs e)
{
if (LvCbResult.SelectedObject == null) { MessageBox.Show("请先选择要删除的项。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; }
var item = (HistoryInfo)LvCbResult.SelectedObject;
var selectId = item.Id;
switch (MessageBox.Show("确定要删除该项吗?一旦删除将不可恢复。", "询问", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2))
{
case DialogResult.No:
return;
}
//DataProvider mydb = new DataProvider();
IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType);
if (db.ConnDb(Itrycn_Db.History_SQLConn) == 1)
{
db.DelById(tableName, selectId.ToString());
LvCbResult.RemoveObject(item);
}
}
private void FrmView_Load(object sender, EventArgs e)
{
ScintillaLexers.CreateLexer(scintillaDiffControl1.LeftScintilla, CurHighliteLang,false);
ScintillaLexers.CreateLexer(scintillaDiffControl1.RightScintilla, CurHighliteLang, false);
//scintillaDiffControl1.ReInit();
Text = "查看历史记录";
ToolStripMenuItem.Text = "修改" + titleName;
ToolStripMenuItem.Text = "删除" + titleName;
IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType);
if (db.ConnDb(Itrycn_Db.History_SQLConn) == 1)
{
RyQuickSQL mySQL = new RyQuickSQL("Files");
mySQL.AddField("FilePath", FilePath);
var ds = db.ReadData("select * from Files where FilePath=@FilePath", mySQL);
if (ds.HaveData())
{
FileId = ds.GetFirstRowData()["id"].ToInt();
Text = "查看历史记录=>"+FilePath;
}
ds.Dispose();
}
rySearch1.PerformClick();
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
btnEdit.PerformClick();
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
btnDel.PerformClick();
}
public bool SelectModeOn { get; set; } = false;
public HistoryInfo SelectedItem { get; set; }
private void LvCbResult_DoubleClick(object sender, EventArgs e)
{
if(SelectModeOn)
{
if (LvCbResult.SelectedObject == null) { return; }
SelectedItem = (HistoryInfo)LvCbResult.SelectedObject;
DialogResult=DialogResult.OK;
Close();
}
}
private void LvCbResult_SelectionChanged(object sender, EventArgs e)
{
var row = (HistoryInfo)LvCbResult.SelectedObject;
if(row==null)
{
scintillaDiffControl1.TextLeft = "";
scintillaDiffControl1.TextRight ="";
BtnPrev.Enabled = false;
BtnNext.Enabled = false;
return;
}
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=" + row.Id);
if (ds.HaveData())
{
scintillaDiffControl1.TextLeft = Content;
scintillaDiffControl1.TextRight = ds.GetRow(0)["content"].ToString();
}
else
{
scintillaDiffControl1.TextLeft = "";
scintillaDiffControl1.TextRight = "";
}
ds?.Dispose();
}
else
{
scintillaDiffControl1.TextLeft = "";
scintillaDiffControl1.TextRight = "";
}
db.Free();
BtnPrev.Enabled = scintillaDiffControl1.CanGoPrevious;
BtnNext.Enabled = scintillaDiffControl1.CanGoNext;
}
private void BtnPrev_Click(object sender, EventArgs e)
{
scintillaDiffControl1.Previous();
BtnPrev.Enabled = scintillaDiffControl1.CanGoPrevious;
BtnNext.Enabled = scintillaDiffControl1.CanGoNext;
}
private void BtnNext_Click(object sender, EventArgs e)
{
scintillaDiffControl1.Next();
BtnPrev.Enabled = scintillaDiffControl1.CanGoPrevious;
BtnNext.Enabled = scintillaDiffControl1.CanGoNext;
}
}
public class HistoryInfo
{
/// <summary>
/// id
/// </summary>
public int Id{ get; set; }
/// <summary>
/// 名称
/// </summary>
public string Name { get; set; }
/// <summary>
/// 字数
/// </summary>
public long Size { get; set; }
/// <summary>
/// 添加时间
/// </summary>
public DateTime AddTime { get; set; }
/// <summary>
/// 添加时间字符串
/// </summary>
public string AddTimeStr
{
get {
if (AddTime.Date == DateTime.Now.Date) { return "今天 " + AddTime.ToString("HH:mm:ss"); }
if (AddTime.Date == DateTime.Now.Date.AddDays(-1)) { return "昨天 " + AddTime.ToString("HH:mm:ss"); }
return AddTime.ToString("yyyy-MM-dd dddd HH:mm:ss");
}
}
}
}