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 list = new List(); 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; } = ""; /// /// 当前高亮语言 /// 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 { /// /// id /// public int Id{ get; set; } /// /// 名称 /// public string Name { get; set; } /// /// 字数 /// public long Size { get; set; } /// /// 添加时间 /// public DateTime AddTime { get; set; } /// /// 添加时间字符串 /// 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"); } } } }