193 lines
7.0 KiB
C#
193 lines
7.0 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;
|
|
|
|
namespace GameBackup3H3.DbOp
|
|
{
|
|
public partial class FrmFavView : Form
|
|
{
|
|
string orderSQL = "order by addTime desc";
|
|
string tableName = "FavFiles";
|
|
string titleName = "收藏管理";
|
|
public FrmFavView()
|
|
{
|
|
InitializeComponent();
|
|
OlvName.AspectGetter = delegate (object x) { return ((FavInfo)x).Name; };
|
|
OlvFilePath.AspectGetter = delegate (object x) { return ((FavInfo)x).FilePath; };
|
|
OlvAddTime.AspectGetter = delegate (object x) { return ((FavInfo)x).AddTimeStr; };
|
|
}
|
|
#region 需要修改的内容
|
|
private void RySearch1_OnSearch(object sender, EventArgs e)
|
|
{
|
|
//需要修改此处
|
|
LoadDb("(name like @SearchText or FilePath like @SearchText)");
|
|
}
|
|
|
|
private void CtlMyPage1_OnPageChange(object sender, EventArgs e)
|
|
{
|
|
#region 重新载入数据
|
|
LvCbResult.ClearObjects();
|
|
List<FavInfo> list = new List<FavInfo>();
|
|
IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType);
|
|
if (db.ConnDb(Itrycn_Db.User_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 FavInfo()
|
|
{
|
|
Id=row["id"].ToInt(),
|
|
Name = row["name"].ToString(),
|
|
FilePath = row["FilePath"].ToString(),
|
|
AddTime = row["AddTime"].ToDateTime()
|
|
}) ;
|
|
}
|
|
}
|
|
db.Free();
|
|
LvCbResult.AddObjects(list);
|
|
#endregion
|
|
}
|
|
private void GetRow(int id, int index)
|
|
{
|
|
#region 重新载入数据
|
|
DataProvider mydb = new DataProvider();
|
|
IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType);
|
|
if (db.ConnDb(Itrycn_Db.User_SQLConn) == 1)
|
|
{
|
|
DataSet ds = db.ReadData("select * from " + tableName + " where id=" + id);
|
|
if (mydb.HaveData(ds))
|
|
{
|
|
DataRow row = ds.Tables[0].Rows[0];
|
|
var item=(FavInfo) LvCbResult.GetModelObject(index);
|
|
item.Name = row["name"].ToString();
|
|
item.FilePath = row["FilePath"].ToString();
|
|
//添加剩余的项目
|
|
//添加完毕
|
|
LvCbResult.UpdateObject(item);
|
|
}
|
|
}
|
|
db.Free();
|
|
#endregion
|
|
}
|
|
#endregion
|
|
public void LoadDb(string whereSQL)
|
|
{
|
|
string _whereSQL = whereSQL;
|
|
IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType);
|
|
if (db.ConnDb(Itrycn_Db.User_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; }
|
|
var item = (FavInfo)LvCbResult.SelectedObject;
|
|
var selectId = item.Id;
|
|
FrmFavFile frm = new FrmFavFile()
|
|
{
|
|
Text = "修改"+ titleName,
|
|
Icon = Icon,
|
|
};
|
|
frm.FilePath = item.FilePath;
|
|
frm.TxtFavName.Text = item.Name;
|
|
if(frm.ShowDialog()==DialogResult.OK)
|
|
{
|
|
GetRow(selectId, LvCbResult.SelectedIndex);
|
|
}
|
|
frm.Dispose();
|
|
}
|
|
|
|
private void BtnDel_Click(object sender, EventArgs e)
|
|
{
|
|
if (LvCbResult.SelectedObject == null) { MessageBox.Show("请先选择要删除的项。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; }
|
|
var item = (FavInfo)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.User_SQLConn) == 1)
|
|
{
|
|
db.DelById(tableName, selectId.ToString());
|
|
LvCbResult.RemoveObject(item);
|
|
}
|
|
}
|
|
|
|
private void FrmView_Load(object sender, EventArgs e)
|
|
{
|
|
Text = "浏览"+ titleName;
|
|
修改数据ToolStripMenuItem.Text = "修改" + titleName;
|
|
删除数据ToolStripMenuItem.Text = "删除" + titleName;
|
|
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 FavInfo SelectedItem { get; set; }
|
|
private void LvCbResult_DoubleClick(object sender, EventArgs e)
|
|
{
|
|
if(SelectModeOn)
|
|
{
|
|
if (LvCbResult.SelectedObject == null) { return; }
|
|
SelectedItem = (FavInfo)LvCbResult.SelectedObject;
|
|
DialogResult=DialogResult.OK;
|
|
}
|
|
}
|
|
}
|
|
public class FavInfo
|
|
{
|
|
/// <summary>
|
|
/// id
|
|
/// </summary>
|
|
public int Id{ get; set; }
|
|
/// <summary>
|
|
/// 名称
|
|
/// </summary>
|
|
public string Name { get; set; }
|
|
/// <summary>
|
|
/// IP
|
|
/// </summary>
|
|
public string FilePath { get; set; }
|
|
/// <summary>
|
|
/// 添加时间
|
|
/// </summary>
|
|
public DateTime AddTime { get; set; }
|
|
/// <summary>
|
|
/// 添加时间字符串
|
|
/// </summary>
|
|
public string AddTimeStr
|
|
{
|
|
get { return AddTime.ToString("yyyy-MM-dd dddd HH:mm:ss"); }
|
|
}
|
|
}
|
|
}
|