------ #### SuperDesign V3.0.2412.2001 - *.[新增]新增程序更新日志设置和自动发布功能。 - *.[修复]修复Post数据格式不正确时双击文本框会导致软件闪退的BUG。
410 lines
16 KiB
C#
410 lines
16 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 ryControls;
|
|
using System.Runtime.InteropServices;
|
|
using BrightIdeasSoftware;
|
|
using SuperDesign.Tools.SmartEditor;
|
|
|
|
namespace GameBackup3H3.DbOp
|
|
{
|
|
public partial class FrmFavView : Form
|
|
{
|
|
readonly string orderSQL = "order by addTime desc";
|
|
readonly string tableName = "FavFiles";
|
|
readonly string titleName = "收藏管理";
|
|
public FrmFavView()
|
|
{
|
|
InitializeComponent();
|
|
OlvGroupName.AspectGetter = delegate (object x) { return ((FavInfo)x).Name; };
|
|
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; };
|
|
LoadGroup();
|
|
SetupDragAndDrop();
|
|
}
|
|
private void SetupDragAndDrop()
|
|
{
|
|
|
|
// Make each listview capable of dragging rows out
|
|
this.LvGroup.DragSource = new SimpleDragSource();
|
|
this.LvCbResult.DragSource = new SimpleDragSource();
|
|
SimpleDropSink dropSink = new SimpleDropSink();
|
|
dropSink.CanDropOnItem = true;
|
|
//dropSink.CanDropOnSubItem = true;
|
|
dropSink.FeedbackColor = Color.IndianRed; // just to be different
|
|
this.LvGroup.DropSink = dropSink;
|
|
|
|
// For our purpose here, we will make it that if you drop one or more person
|
|
// onto someone, they all become married.
|
|
dropSink.ModelCanDrop += delegate (object sender, ModelDropEventArgs e) {
|
|
FavInfo item = e.TargetModel as FavInfo;
|
|
if (item == null)
|
|
e.Effect = DragDropEffects.None;
|
|
else
|
|
{
|
|
if (item.Id<0)
|
|
{
|
|
e.Effect = DragDropEffects.None;
|
|
e.InfoMessage = "不能拖放到此处";
|
|
}
|
|
else
|
|
e.Effect = DragDropEffects.Link;
|
|
}
|
|
};
|
|
|
|
dropSink.ModelDropped += delegate (object sender, ModelDropEventArgs e) {
|
|
if (e.TargetModel == null)
|
|
return;
|
|
var item = (FavInfo)e.TargetModel;
|
|
var from_list = e.SourceModels;
|
|
var del_list = new List<FavInfo>();
|
|
IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType);
|
|
if (db.ConnDb(Itrycn_Db.User_SQLConn) == 1)
|
|
{
|
|
for (int i = 0; i < from_list.Count; i++)
|
|
{
|
|
var from_item = (FavInfo)from_list[i];
|
|
if (from_item.GroupId != item.Id)
|
|
{
|
|
del_list.Add(from_item);
|
|
db.ExecuteNonQuery("update FavFiles set GroupId=" + item.Id + " where id=" + from_item.Id);
|
|
}
|
|
}
|
|
}
|
|
var selected_group = (FavInfo)LvGroup.SelectedObject;
|
|
if (selected_group != null && selected_group.GroupId >= 0)
|
|
{
|
|
LvCbResult.RemoveObjects(del_list);
|
|
}
|
|
};
|
|
}
|
|
|
|
#region 需要修改的内容
|
|
private void RySearch1_OnSearch(object sender, EventArgs e)
|
|
{
|
|
//需要修改此处
|
|
LoadDb("(name like @SearchText or FilePath like @SearchText)");
|
|
}
|
|
private void LoadGroup()
|
|
{
|
|
LvGroup.ClearObjects();
|
|
List<FavInfo> list = new List<FavInfo>
|
|
{
|
|
new FavInfo()
|
|
{
|
|
Id =-1,
|
|
Name = "全部收藏",
|
|
AddTime = DateTime.Now
|
|
},
|
|
new FavInfo()
|
|
{
|
|
Id = 0,
|
|
Name = "未分组",
|
|
AddTime = DateTime.Now
|
|
},
|
|
};
|
|
IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType);
|
|
if (db.ConnDb(Itrycn_Db.User_SQLConn) == 1)
|
|
{
|
|
DataSet ds = db.ReadData("select * from FavGroup");
|
|
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(),
|
|
AddTime = row["AddTime"].ToDateTime()
|
|
});
|
|
}
|
|
}
|
|
db.Free();
|
|
LvGroup.AddObjects(list);
|
|
}
|
|
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(),
|
|
FindText = row["FindText"].ToString(),
|
|
GroupId = row["GroupId"].ToInt(),
|
|
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.FindText = row["FindText"].ToString();
|
|
item.FilePath = row["FilePath"].ToString();
|
|
item.GroupId = row["GroupId"].ToInt();
|
|
//添加剩余的项目
|
|
//添加完毕
|
|
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 重新载入数据
|
|
var group =(FavInfo) LvGroup.SelectedObject;
|
|
if(group!=null && group.Id>=0)
|
|
{
|
|
_whereSQL += " and GroupId="+group.Id;
|
|
}
|
|
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,
|
|
GroupId = item.GroupId,
|
|
SelectedId = item.Id,
|
|
FilePath = item.FilePath
|
|
};
|
|
frm.TxtFavName.Text = item.Name;
|
|
frm.TxtFind.Text = item.FindText;
|
|
if(frm.ShowDialog()==DialogResult.OK)
|
|
{
|
|
GetRow(selectId, LvCbResult.SelectedIndex);
|
|
}
|
|
frm.Dispose();
|
|
}
|
|
|
|
private void BtnDel_Click(object sender, EventArgs e)
|
|
{
|
|
if (LvCbResult.SelectedObjects.Count == 0) { MessageBox.Show("请先选择要删除的项。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; }
|
|
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)
|
|
{
|
|
for (int i = 0; i < LvCbResult.SelectedObjects.Count; i++)
|
|
{
|
|
var item = (FavInfo)LvCbResult.SelectedObjects[i];
|
|
var selectId = item.Id;
|
|
db.DelById(tableName, selectId.ToString());
|
|
}
|
|
LvCbResult.RemoveObjects(LvCbResult.SelectedObjects);
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
|
|
private void LvGroup_SelectionChanged(object sender, EventArgs e)
|
|
{
|
|
rySearch1.PerformClick();
|
|
}
|
|
|
|
private void 添加组ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
FrmFavGroup frm = new FrmFavGroup
|
|
{
|
|
Text = "添加组",
|
|
Icon = Icon,
|
|
SelectedId = 0
|
|
};
|
|
if (frm.ShowDialog() == DialogResult.OK)
|
|
{
|
|
LoadGroup();
|
|
}
|
|
frm.Dispose();
|
|
}
|
|
|
|
private void 修改组ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
if (LvGroup.SelectedObject == null) { return; }
|
|
var item = (FavInfo)LvGroup.SelectedObject;
|
|
FrmFavGroup frm = new FrmFavGroup
|
|
{
|
|
Text = "修改组",
|
|
Icon = Icon,
|
|
SelectedId = item.Id
|
|
};
|
|
frm.TxtFavName.Text = item.Name;
|
|
if (frm.ShowDialog() == DialogResult.OK)
|
|
{
|
|
item.Name = frm.TxtFavName.Text;
|
|
LvGroup.RefreshObject(item);
|
|
}
|
|
frm.Dispose();
|
|
}
|
|
|
|
private void 删除组ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
if (LvGroup.SelectedObject == null) { MessageBox.Show("请先选择要删除的项。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; }
|
|
var item = (FavInfo)LvGroup.SelectedObject;
|
|
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)
|
|
{
|
|
var ds = db.ReadData("select * from FavFiles where GroupId="+ item.Id+" limit 1");
|
|
if(ds.HaveData())
|
|
{
|
|
MessageBox.Show("当前组内还有收藏,请删除收藏后再删除组", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
ds.Dispose();
|
|
return;
|
|
}
|
|
ds.Dispose();
|
|
db.DelById("FavGroup", item.Id.ToString());
|
|
LvGroup.RemoveObject(item);
|
|
}
|
|
}
|
|
|
|
private void 打开本分组到编辑器ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
if (LvGroup.SelectedObject == null) { MessageBox.Show("请先选择要打开的组。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; }
|
|
var item = (FavInfo)LvGroup.SelectedObject;
|
|
IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType);
|
|
if (db.ConnDb(Itrycn_Db.User_SQLConn) == 1)
|
|
{
|
|
var ds = db.ReadData("select * from FavFiles where GroupId=" + item.Id);
|
|
List<string> list=new List<string>();
|
|
if (ds.HaveData())
|
|
{
|
|
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
|
|
{
|
|
var row = ds.GetRow(i);
|
|
list.Add(row["FilePath"].ToString());
|
|
}
|
|
}
|
|
ds.Dispose();
|
|
if(list.Count>0)
|
|
{
|
|
FrmMainEditor.MainEditor.OpenFileList(list);
|
|
DialogResult= DialogResult.Yes;
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show("该组没有任何数据", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
public class FavInfo
|
|
{
|
|
/// <summary>
|
|
/// id
|
|
/// </summary>
|
|
public int Id{ get; set; }
|
|
/// <summary>
|
|
/// 名称
|
|
/// </summary>
|
|
public string Name { get; set; }
|
|
/// <summary>
|
|
/// FilePath
|
|
/// </summary>
|
|
public string FilePath { get; set; }
|
|
/// <summary>
|
|
/// FindText
|
|
/// </summary>
|
|
public string FindText { get; set; }
|
|
/// <summary>
|
|
/// 组id
|
|
/// </summary>
|
|
public int GroupId { 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"); }
|
|
}
|
|
}
|
|
}
|