VSoft/Source/VSoft_Dll/FrmVSoft.cs
zilinsoft c773aa54bc ## 📅2025-09-11 星期四更新
### DyLine    V2.0.2509.1101
- *.[改进]消息发送机制采用Unicode。
### VSoft    V2.0.2509.1101
- *.[新增]支持对启动软件设置是否开机启动。
- *.[改进]防止快速点击分类时激活拖放功能。
- *.[改进]主窗体软件版本号改为默认从VSoft.dll获取。
- *.[改进]针对调用流程软件的功能,直接通过主程序实现,提升打开速度。
- *.[修复]修复添加内置功能后不能直接打开,需要二次启动后才能打开的BUG。
- *.[修复]修复拖放文件到列表,图标可能无法正常显示的BUG。
- *.[修复]修复从桌面拖放到列表,图标无法马上显示的BUG。
- *.[修复]修改软件后缓存图标不会更新的BUG。
2025-09-11 10:19:51 +08:00

2357 lines
100 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Newtonsoft.Json.Linq;
using ryCommon;
using ryCommonDb;
using ryControls;
using SysFuns;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using VSoft.Config;
using VSoft.Prams;
using VSoft.Skins;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Tab;
namespace VSoft
{
public partial class FrmVSoft : SKinForm
{
readonly string[] prog_args;
readonly string SQLConnStr = Itrycn_Db.SQLConnStr;
readonly MouseHook mouse = new MouseHook();
public FrmVSoft(string[] args)
{
InitializeComponent();
prog_args = args;
//配置软件信息
notifyIcon1.Text = Config.Soft_Info.Soft_Title;
if (System.IO.File.Exists(Application.StartupPath + "\\VSoft.dll"))
{
Text = Config.Soft_Info.Soft_Title + " V" + RySoft.GetVersionStr(Application.StartupPath + "\\VSoft.dll");
}
else
{
Text = Config.Soft_Info.Soft_Title + " V" + RySoft.GetVersionStr(Application.ExecutablePath);
}
#if TEST
Text +=" V内部测试版";
#endif
if (!Config.Soft_Info.ShowTray) { notifyIcon1.Visible = false; }
#if DY
ToolStripMenuItem.Text = "关于";
#else
if (!Config.Soft_Info.DonateVisabled) { ToolStripMenuItem.Text = "关于"; } else { ToolStripMenuItem.Text = "捐助/关于"; }
#endif
if (Config.Soft_Info.Soft_Url.Length == 0) { ToolStripMenuItem.PerformClick(); }
notifyIcon1.Icon = Icon;
var backcolor = SystemColors.Control;
TabList_Column.BackColor = backcolor;
TabList_Type.BackColor = backcolor;
//pictureBox1.BackColor = backcolor;
PnlLeft.BackColor = backcolor;
}
private readonly System.Windows.Forms.ToolTip lvTp = new System.Windows.Forms.ToolTip();
private void FrmVSoft_FormClosed(object sender, FormClosedEventArgs e)
{
mouse.Stop();
}
DateTime dt_lastMouse = DateTime.Now;
int clickcount = 1;
private void Mouse_OnMouseActivity(object sender, MouseEventArgs e)
{
if (!Soft_Config.ShowMainMouseKeyOn) { return; }
var button = MouseButtons.Middle;
if(Soft_Config.ShowMainMouseKey==1)
{
button = MouseButtons.XButton1;
}
else if (Soft_Config.ShowMainMouseKey == 2)
{
button = MouseButtons.XButton2;
}
if (e.Button== button)
{
//ryCommon.RyFiles.WriteAllText(Application.StartupPath+"\\1.txt",e.Button.ToString(),Encoding.UTF8);
if(Math.Abs((dt_lastMouse-DateTime.Now).TotalMilliseconds)<500)
{
clickcount++;
if (clickcount == 2)
{
ShowOrHideUI();
}
clickcount = 1;
}
else
{
clickcount = 1;
}
dt_lastMouse = DateTime.Now;
}
// Msg.ShowMsg(e.Button.ToString());
// e.Button == MouseButtons.Middle;
}
private bool IsProcUse = false;
private void LoadDb()
{
LoadDb(false);
}
readonly Dictionary<string, Image> dictCacheImg = new Dictionary<string, Image>();
private void LoadDb(bool isSearch)
{
IconViewEx1.Items.Clear();
IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType);
if (db.ConnDb(SQLConnStr) == 1)
{
var id = GetCurColumnId();
RyQuickSQL mySQL = new RyQuickSQL("Softs");
mySQL.AddField("SearchText", "%" + rySearch1.Text + "%");
var sql = "select * from Softs where (Name like @SearchText or Path like @SearchText or Des like @SearchText or PinYin like @SearchText)";
if (isSearch)
{
IsProcUse = true;
TabList_Column.SelectedItems.Clear();
TabList_Type.Items.Clear();
TabList_Type.Items.Add("默认分类").Tag = 0;
IsProcUse = false;
}
else
{
if (id > 0)
{
sql += " and ColumnId=" + id;
}
else { sql += " and ColumnId<=0"; }
}
DataSet ds = db.ReadData(sql + " order by sortindex asc,AddTime desc", mySQL);
IconViewEx1.BeginUpdate();
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
DataRow row = ds.Tables[0].Rows[i];
SoftInfo info = new SoftInfo
{
Id = row["id"].ToInt(),
SoftType = row["SoftType"].ToInt(),
ColumnId = row["ColumnId"].ToInt(),
Name = row["Name"].ToString(),
Path = row["Path"].ToString(),
RunPram = row["RunPram"].ToString(),
SetJson = row["SetJson"].ToString(),
StartPath = row["StartPath"].ToString(),
WinStartRun = row["WinStartRun"].ToInt()==1,
IconPath = row["IconPath"].ToString()
};
string img_path;
if (info.IconPath.Length == 0)
{
img_path = info.TruePath;
}
else
{
img_path = RyFiles.GetRealPath(info.IconPath);
}
if(dictCacheImg.ContainsKey(img_path))
{
info.Image = dictCacheImg[img_path];
}
else
{
info.Image = API.GetImg(img_path, 128);
dictCacheImg.Add(img_path, info.Image);
}
Application.DoEvents();
IconViewEx1.Items.Add(info.Name).Tag = info ;
}
IconViewEx1.EndUpdate();
db.Free();
if(IconViewEx1.Items.Count==0)
{
LblEmpty.Visible = true;
}
else { LblEmpty.Visible = false; }
}
db.Free();
}
private void LoadColumn()
{
TabList_Column.Items.Clear();
try
{
JArray jarr = JArray.Parse(Itrycn_Db.GetSetting("SelectedCache", ""));
for (int i = 0; i < jarr.Count; i++)
{
var item = jarr[i];
dict_cache_type[item.GetJsonValue("ColumnId", -1)] = new SelectInfo()
{
SelectedTypeId = item.GetJsonValue("SelectedTypeId", -1),
IconVisibleIndex = item.GetJsonValue("IconVisibleIndex", -1),
IconSelectedIndex = item.GetJsonValue("IconSelectedIndex", -1),
};
}
}
catch { }
DataProvider mydb = new DataProvider();
IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType);
if (db.ConnDb(SQLConnStr) == 1)
{
TabList_Column.BeginUpdate();
DataSet ds = db.ReadData("select * from Columns where parentId=0 order by sortindex asc");
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
DataRow row = ds.Tables[0].Rows[i];
TabList_Column.Items.Add(row["Name"].ToString()).Tag = row["id"].ToInt();
}
if(ds.Tables[0].Rows.Count==0)
{
#region ,
RyQuickSQL mySQL = new RyQuickSQL("Columns");
mySQL.AddField("Name", "默认栏目");
mySQL.AddField("editTime", DateTime.Now);
mySQL.AddField("sortindex", 1);
mySQL.AddField("parentId", 0);
mySQL.AddField("addTime", DateTime.Now);
var ds_c = db.ReadData(mySQL.GetInsertSQL() + ";select last_insert_rowid();", mySQL);
if (mydb.HaveData(ds_c))
{
var ParentId = mydb.GetValue(ds_c);
RyQuickSQL mySQL2 = new RyQuickSQL("Columns");
mySQL2.AddField("Name", "默认分类");
mySQL2.AddField("Des", "");
mySQL2.AddField("editTime", DateTime.Now);
mySQL2.AddField("sortindex", Itrycn_Db.GetColumnCount(db, ParentId) + 1);
mySQL2.AddField("parentId", ParentId);
mySQL2.AddField("addTime", DateTime.Now);
db.ExecuteNonQuery(mySQL2.GetInsertSQL(), mySQL2);
}
ds_c.Dispose();
DataSet ds2 = db.ReadData("select * from Columns where parentId=0 order by sortindex asc");
for (int i = 0; i < ds2.Tables[0].Rows.Count; i++)
{
DataRow row = ds2.Tables[0].Rows[i];
TabList_Column.Items.Add(row["Name"].ToString()).Tag = row["id"].ToInt();
}
ds2.Dispose();
#endregion
}
ds.Dispose();
TabList_Column.EndUpdate();
db.Free();
}
if(TabList_Column.Items.Count>0)
{
ryCommon.Ini ini = new ryCommon.Ini(Soft_Info.UserDataFolder + "\\Win.dat");
var ColumnId = ini.ReadIni(VSoft.Config.Soft_Info.Soft_Id, "ColumnId", -1);
var TypeId = ini.ReadIni(VSoft.Config.Soft_Info.Soft_Id, "TypeId", -1);
if (!dict_cache_type.ContainsKey(ColumnId))
{
dict_cache_type[ColumnId] = new SelectInfo()
{
SelectedTypeId = TypeId,
};
}
for (int i = 0; i < TabList_Column.Items.Count; i++)
{
if (TabList_Column.Items[i].Tag.ToInt() == ColumnId)
{
TabList_Column.Items[i].Selected = true;
break;
}
}
if (TabList_Column.SelectedItems.Count == 0)
{
TabList_Column.Items[0].Selected = true;
}
}
}
private readonly Dictionary<int, SelectInfo> dict_cache_type = new Dictionary<int, SelectInfo>();
private void LoadTypeColumn(int id)
{
TabList_Type.Items.Clear();
//TabList_Type.Items.Add("默认分类").Tag = 0;
IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType);
if (db.ConnDb(SQLConnStr) == 1)
{
DataSet ds = db.ReadData("select * from Columns where parentId="+ id + " order by sortindex asc");
TabList_Type.BeginUpdate();
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
DataRow row = ds.Tables[0].Rows[i];
TabList_Type.Items.Add(row["Name"].ToString()).Tag = row["id"].ToInt();
}
ds.Dispose();
TabList_Type.EndUpdate();
db.Free();
}
if (TabList_Type.Items.Count > 0)
{
if(dict_cache_type.ContainsKey(id))
{
var cache_selected=dict_cache_type[id];
if (cache_selected.SelectedTypeId> 0)
{
for (int i = 0; i < TabList_Type.Items.Count; i++)
{
if(TabList_Type.Items[i].Tag.ToInt()== cache_selected.SelectedTypeId)
{
TabList_Type.Items[i].Selected = true;
//IconViewEx1.EnsureVisible(cache_selected.IconVisibleIndex);
if (cache_selected.IconSelectedIndex.IsInRange(0, IconViewEx1.Items.Count - 1))
{
IconViewEx1.Items[cache_selected.IconSelectedIndex].Selected = true;
IconViewEx1.Items[cache_selected.IconSelectedIndex].EnsureVisible();
}
if (cache_selected.IconVisibleIndex.IsInRange(0, IconViewEx1.Items.Count - 1))
{
IconViewEx1.Items[cache_selected.IconVisibleIndex].EnsureVisible();
//IconViewEx1.TopItem = IconViewEx1.Items[cache_selected.IconVisibleIndex];
}
break;
}
}
if(TabList_Type.SelectedItems.Count==0)
{
TabList_Type.Items[0].Selected = true;
}
}
else
{
TabList_Type.Items[0].Selected = true;
}
}
else
{
TabList_Type.Items[0].Selected = true;
}
}
}
int hot_index = 0;
/// <summary>
/// 注册热键
/// </summary>
private void RegisterHotkey()
{
hotkey.UnHotKey();
IDbInterface db2 = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType);
if (db2.ConnDb(SQLConnStr) == 1)
{
var index = 100;
HotkeyValue hot = new HotkeyValue(Soft_Config.ShowMainHotKey);
hotkey.RegHotKey(100, hot.Modifiers_Int, hot.KeyCode);
var ds_type = db2.ReadData("select * from Columns where Hotkey<>''");
if (ds_type.HaveData())
{
for (int i = 0; i < ds_type.Tables[0].Rows.Count; i++)
{
index++;
var item = ds_type.GetRow(i);
hot.LoadHotKeyStr(item["HotKey"].ToString());
hotkey.RegHotKey(index, "type_" + item["id"].ToInt(), hot.Modifiers_Int, hot.KeyCode);
}
}
ds_type.Dispose();
var ds = db2.ReadData("select * from Softs where Hotkey<>''");
if (ds.HaveData())
{
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
index++;
var item = ds.GetRow(i);
hot.LoadHotKeyStr(item["HotKey"].ToString());
hotkey.RegHotKey(index, "soft_" + item["id"].ToInt(), hot.Modifiers_Int, hot.KeyCode);
}
}
ds.Dispose();
hot_index = index;
}
db2.Free();
}
/// <summary>
/// 开机启动
/// </summary>
private void WinStart()
{
IDbInterface db2 = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType);
if (db2.ConnDb(SQLConnStr) == 1)
{
var ds = db2.ReadData("select * from Softs where WinStartRun=1");
if (ds.HaveData())
{
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
var row = ds.GetRow(i);
SoftInfo info = new SoftInfo
{
Id = row["id"].ToInt(),
SoftType = row["SoftType"].ToInt(),
ColumnId = row["ColumnId"].ToInt(),
Name = row["Name"].ToString(),
Path = row["Path"].ToString(),
RunPram = row["RunPram"].ToString(),
SetJson = row["SetJson"].ToString(),
StartPath = row["StartPath"].ToString(),
WinStartRun = row["WinStartRun"].ToInt() == 1,
IconPath = row["IconPath"].ToString()
};
Json json = new Json(row["SetJson"].ToString());
var WinRunDelay=json.GetJsonValue("WinRunDelay", 0,10, 0);
if (WinRunDelay == 0)
{
VSoft.Prams.Run.Open(info, false);
}
else
{
Task.Run(() =>
{
Task.Delay(WinRunDelay*1000);
VSoft.Prams.Run.Open(info, false);
});
}
}
}
ds.Dispose();
}
db2.Free();
}
SysFuns.WinHotReg hotkey;
private void FrmVSoft_Load(object sender, EventArgs e)
{
//IconViewEx1.SetInterval(100, 100);
Config.Soft_Config.MainForm = this;
MinimumSize = new Size(400, 200);
LblEmpty.Left =((panelEx1.Width - LblEmpty.Width) / 2);
Config.Soft_Info.UserDataFolder = ryCommon.RyFiles.GetRealPath(Config.Soft_Info.UserDataFolder);
Itrycn_Db.SQLConnStr = Soft_Info.UserDataFolder + "\\Softs.dat|";
Itrycn_Db.SQLConnStr_Logs = Soft_Info.UserDataFolder + "\\logs.dat|";
VSoft.Prams.Itrycn_Db.CreateTable();
var dbver = Itrycn_Db.GetDbVer();
if (dbver == 2) //当前要求的数据库
{
}
else //不是符合的数据库
{
DataProvider mydb = new DataProvider();
IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType);
if (db.ConnDb(SQLConnStr) == 1)
{
if (dbver == 1)
{
DataSet ds = db.ReadData("select * from Columns where parentId=0 order by sortindex asc");
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
DataRow row = ds.Tables[0].Rows[i];
#region
RyQuickSQL mySQL2 = new RyQuickSQL("Columns");
mySQL2.AddField("Name", "默认分类");
mySQL2.AddField("Des", "");
mySQL2.AddField("editTime", DateTime.Now);
mySQL2.AddField("sortindex", Itrycn_Db.GetColumnCount(db, row["id"].ToInt()) + 1);
mySQL2.AddField("parentId", row["id"].ToInt());
mySQL2.AddField("addTime", DateTime.Now);
var ds_id = db.ReadData(mySQL2.GetInsertSQL() + ";select last_insert_rowid();", mySQL2);
var type_id = mydb.GetValue(ds_id);
#endregion
RyQuickSQL mySQL3 = new RyQuickSQL("Softs");
mySQL3.AddField("ColumnId", type_id);//将直属分类修改为默认分类
db.ExecuteNonQuery(mySQL3.GetUpdateSQL()+ " where ColumnId="+ row["id"].ToInt(), mySQL3);
}
ds.Dispose();
Itrycn_Db.SetDbVer(2);
}
else
{
db.Free();
Msg.ShowMsg("不支持当前数据库版本,这可能是以下原因导致的:\r\n1.数据库已损坏;'\r\n2.当前数据库是由新版软件创建的(请更新软件后重试)。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
Application.Exit();
return;
}
}
db.Free();
}
VSoft.Config.Soft_Config.LoadSetting();
LoadColumn();
//rySearch1.PerformClick();
//if(RySoft.IsAdministrator())
//{
// Msg.ShowMsg("管理员模式下启动本软件,可能会导致无法拖放图标到本软件。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
//}
hotkey = new SysFuns.WinHotReg(Handle);
hotkey.OnHotkey += Hotkey_OnHotkey;
RegisterHotkey();
#region
IDbInterface db2 = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType);
if (db2.ConnDb(SQLConnStr) == 1)
{
DataSet ds = db2.ReadData("select * from Softs");
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
DataRow row = ds.Tables[0].Rows[i];
var IconPath = row["IconPath"].ToString();
var TruePath = RyFiles.GetRealPath(row["Path"].ToString());
string img_path;
Image image;
if (IconPath.Length == 0)
{
img_path = TruePath;
}
else
{
img_path = RyFiles.GetRealPath(IconPath);
}
if (!dictCacheImg.ContainsKey(img_path))
{
image = API.GetImg(img_path, 128);
dictCacheImg.Add(img_path, image);
}
}
}
db2.Free();
#endregion
ryCommon.RyRegedit.RegRoot = Microsoft.Win32.RegistryHive.CurrentUser;
//如果开机启动没有启动
if(!ryCommon.RyRegedit.IsAutoRun(Soft_Info.Soft_Id, "\"" + Application.ExecutablePath.Replace("/", "\\") + "\" " + Soft_Info.Soft_Pram))
{
switch (Msg.ShowMsg("您暂未设置开机启动,下次开机后软件将无法自动运行。\r\n设置过程中可能会遇到安全软件提示,请选择允许。\r\n\r\n是否要设置开机启动", "开机启动", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2))
{
case DialogResult.Yes:
ryCommon.RyRegedit.SetAutoRun(true, Soft_Info.Soft_Id, "\"" + Application.ExecutablePath.Replace("/", "\\") + "\" " + Soft_Info.Soft_Pram);
break;
}
}
ShowInCenter(null);
#if DY
#else
LiveUpdate.RyUpdate update = new LiveUpdate.RyUpdate(Soft_Info.Update_Url);
update.CheckUpdate();
#endif
mouse.OnMouseActivity += Mouse_OnMouseActivity;
mouse.Start();
if(prog_args.Length>0)
{
if (prog_args[0]==Soft_Info.Soft_Pram)
{
WinStart();
}
}
}
private void Hotkey_OnHotkey(int HotKeyID)
{
switch (HotKeyID)
{
case 100:
ShowOrHideUI();
break;
default:
var ids=hotkey.GetTag(HotKeyID);
if(ids.IndexOfEx("type_")==0)
{
#region
var id = ids.Substring(5).ToInt();
IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType);
if (db.ConnDb(SQLConnStr) == 1)
{
//var sql = "select * from Columns where id=" + id;
DataSet ds = db.ReadData("select * from Columns where id=" + id);
if (ds.HaveData())
{
DataRow row = ds.GetFirstRowData();
var parentId=row["parentId"].ToInt();
if(parentId>0)
{
for (int i = 0; i < TabList_Column.Items.Count; i++)
{
if (TabList_Column.Items[i].Tag.ToInt()==parentId)
{
TabList_Column.Items[i].Selected = true;
for (int m = 0; m < TabList_Type.Items.Count; m++)
{
if (TabList_Type.Items[m].Tag.ToInt() == row["id"].ToInt())
{
TabList_Type.Items[m].Selected = true;
ShowOrHideUI(true);
break;
}
}
break;
}
}
}
}
db.Free();
}
db.Free();
#endregion
}
else if (ids.IndexOfEx("soft_") == 0)
{
#region
var id = ids.Substring(5).ToInt();
IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType);
if (db.ConnDb(SQLConnStr) == 1)
{
//var sql = "select * from Softs where id=" + id;
DataSet ds = db.ReadData("select * from Softs where id=" + id);
if (ds.HaveData())
{
DataRow row = ds.GetFirstRowData();
SoftInfo info = new SoftInfo
{
Id = row["id"].ToInt(),
SoftType = row["SoftType"].ToInt(),
ColumnId = row["ColumnId"].ToInt(),
Name = row["Name"].ToString(),
Path = row["Path"].ToString(),
RunPram = row["RunPram"].ToString(),
SetJson = row["SetJson"].ToString(),
StartPath = row["StartPath"].ToString(),
IconPath = row["IconPath"].ToString()
};
VSoft.Prams.Run.Open(info, false);
}
db.Free();
}
db.Free();
#endregion
}
break;
}
}
[System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "SetForegroundWindow")]
public static extern bool SetF(IntPtr hWnd); //设置此窗体为活动窗体
/// <summary>
/// 显示或隐藏UI
/// </summary>
private void ShowOrHideUI(bool ForceShow=false)
{
if (this.Visible && RyForm.GetActiveWindow() == Handle && !ForceShow)
{
this.Hide();
}
else
{
this.WindowState = FormWindowState.Normal;
var topmost = this.TopMost;
this.TopMost = true;
var screen = Screen.FromPoint(MousePosition);
if (!screen.WorkingArea.Contains(this.Location) || !screen.WorkingArea.Contains(this.Left+this.Width,this.Top+this.Height))
{
RyForm.ShowCenter(this, null);
}
this.Show();
this.TopMost = topmost;
if (RyForm.GetActiveWindow() != this.Handle)
{
//this.TopMost = topmost;
this.BringToFront();
this.Select();
this.Focus();
//RyForm.BringToTop(Handle);
RyForm.SetActiveWindow(Handle);
//this.TopMost = topmost;
rySearch1.Focus();
using (var bg = new BackgroundWorker())
{
bg.DoWork += delegate { System.Threading.Thread.Sleep(100); };//1秒后
bg.RunWorkerCompleted += delegate
{
this.Invoke(new Action(() =>
{
this.TopMost = topmost;
SetF(Handle);
}));
}; // 线程执行完成后会执行 RunWorkerCompleted 事伯的代码块
bg.RunWorkerAsync();
}
}
}
}
protected override void WndProc(ref System.Windows.Forms.Message msg)
{
switch (msg.Msg)
{
case 17189: //处理消息
{
#region
switch (msg.WParam.ToInt32())
{
case 100://
#region
if ((int)msg.LParam.ToInt32() == 100)
{
this.Show();
this.WindowState = FormWindowState.Normal;
this.Top = (Screen.PrimaryScreen.WorkingArea.Height - this.Height) / 2;
this.Left = (Screen.PrimaryScreen.WorkingArea.Width - this.Width) / 2;
//RyForm.SetActiveWindow(Handle);
RyForm.BringToTop(Handle);
ToolStripMenuItem.PerformClick();
this.BringToFront();
this.Select();
this.Focus();
RyForm.BringToTop(Handle);
rySearch1.Focus();
}
#endregion
break;
}
#endregion
}
break;
default:
base.WndProc(ref msg);//调用基类函数处理非自定义消息。
break;
}
}
private void RySearch1_OnSearch(object sender, EventArgs e)
{
if(rySearch1.Text.Length==0)
{
Msg.ShowMsg("请输入内容。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
LoadDb(true);
}
#region
/// <summary>
/// 将栏目列表中的第几个栏目修改
/// </summary>
/// <param name="id"></param>
/// <param name="index"></param>
private void SetColumnRow(int id, int index)
{
#region
DataProvider mydb = new DataProvider();
IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType);
if (db.ConnDb(SQLConnStr) == 1)
{
DataSet ds = db.ReadData("select * from Columns where id=" + id);
if (mydb.HaveData(ds))
{
DataRow row = ds.Tables[0].Rows[0];
var item = TabList_Column.Items[index];
item.Text = row["Name"].ToString();
}
db.Free();
}
#endregion
}
private void BtnAddColumn_Click(object sender, EventArgs e)
{
FrmAddColumn frm = new FrmAddColumn
{
TopMost = TopMost
};
frm.ShowInCenter(this);
if (frm.ShowDialog(this) == DialogResult.OK)
{
IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType);
if (db.ConnDb(SQLConnStr) == 1)
{
DataSet ds = db.ReadData("select * from Columns where parentId=0 order by sortindex desc limit 1");
TabList_Column.BeginUpdate();
if (ds.Tables[0].Rows.Count > 0)
{
DataRow row = ds.Tables[0].Rows[0];
TabList_Column.Items.Add(row["Name"].ToString()).Tag = row["id"].ToInt();
}
TabList_Column.EndUpdate();
db.Free();
}
}
frm.Dispose();
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (TabList_Column.SelectedItems.Count == 0) { return; }
FrmAddColumn frm = new FrmAddColumn
{
TopMost = TopMost,
IsAdd = 0
};
frm.GetInfo(TabList_Column.SelectedItems[0].Tag.ToInt());
frm.ShowInCenter(this);
if (frm.ShowDialog(this) == DialogResult.OK)
{
SetColumnRow(TabList_Column.SelectedItems[0].Tag.ToInt(), TabList_Column.SelectedItems[0].Index);
}
frm.Dispose();
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (TabList_Column.SelectedItems.Count == 0) { return; }
if (Msg.ShowMsg("确定要删除选定项吗?一旦删除将不可恢复。", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.No)
{
return;
}
if (TabList_Column.Items.Count ==1) {
Msg.ShowMsg("请至少保留一个栏目。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
DataProvider mydb = new DataProvider();
IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType);
if (db.ConnDb(SQLConnStr) == 1)
{
var column_id = TabList_Column.SelectedItems[0].Tag.ToInt();
var ds = db.ReadData("select count(*) from Columns where parentId=" + column_id);
if (mydb.HaveData(ds))
{
if (mydb.GetValue(ds) > 0)
{
ds.Dispose();
Msg.ShowMsg("当前栏目下还有分类,请先移除再删除栏目。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
db.Free();
return;
}
}
ds.Dispose();
db.DelById("Columns", column_id.ToString());
TabList_Column.SelectedItems[0].Remove();
db.BeginTransaction();
for (int i = 1; i < TabList_Column.Items.Count; i++)
{
var id = TabList_Column.Items[i].Tag.ToInt();
RyQuickSQL mySQL = new RyQuickSQL("Columns");
mySQL.AddField("sortindex", i);
db.ExecuteNonQuery(mySQL.GetUpdateSQL() + " where id=" + id, mySQL);
}
db.Commit();
}
db.Free();
}
#endregion
#region
/// <summary>
///将分类列表中的第几个分类进行修改
/// </summary>
/// <param name="id"></param>
/// <param name="index"></param>
private void SetTypeRow(int id, int index)
{
#region
DataProvider mydb = new DataProvider();
IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType);
if (db.ConnDb(SQLConnStr) == 1)
{
DataSet ds = db.ReadData("select * from Columns where id=" + id);
if (mydb.HaveData(ds))
{
DataRow row = ds.Tables[0].Rows[0];
var item = TabList_Type.Items[index];
item.Text = row["Name"].ToString();
}
db.Free();
}
#endregion
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (TabList_Column.SelectedItems.Count == 0)
{
Msg.ShowMsg("请先选择一个栏目。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
var id = TabList_Column.SelectedItems[0].Tag.ToInt();
FrmAddType frm = new FrmAddType
{
TopMost = TopMost,
ParentId = id
};
frm.ShowInCenter(this);
if (frm.ShowDialog(this) == DialogResult.OK)
{
IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType);
if (db.ConnDb(SQLConnStr) == 1)
{
hot_index++;
HotkeyValue hot = new HotkeyValue(frm.hotkeyTextBox1.HotKey);
hotkey.RegHotKey(hot_index,"type_"+frm.Op_Id, hot.Modifiers_Int, hot.KeyCode);
DataSet ds = db.ReadData("select * from Columns where parentId=" + id + " order by sortindex desc limit 1");
TabList_Type.BeginUpdate();
if(ds.Tables[0].Rows.Count>0)
{
DataRow row = ds.Tables[0].Rows[0];
TabList_Type.Items.Add(row["Name"].ToString()).Tag = row["id"].ToInt();
}
ds.Dispose();
TabList_Type.EndUpdate();
db.Free();
}
}
frm.Dispose();
}
private void Menu修改分类_Click(object sender, EventArgs e)
{
if (TabList_Column.SelectedItems.Count == 0)
{
Msg.ShowMsg("请先选择一个栏目。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (TabList_Type.SelectedItems.Count == 0)
{
Msg.ShowMsg("请先选择一个分类。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
var id = TabList_Type.SelectedItems[0].Tag.ToInt();
if (id == 0) {
Msg.ShowMsg("默认分类不支持修改", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
FrmAddType frm = new FrmAddType
{
TopMost = TopMost,
IsAdd = 0
};
frm.GetInfo(id);
frm.ShowInCenter(this);
if (frm.ShowDialog(this) == DialogResult.OK)
{
SetTypeRow(id, TabList_Type.SelectedItems[0].Index);
HotkeyValue hot = new HotkeyValue(frm.hotkeyTextBox1.HotKey);
var index = hotkey.GetHotId("type_" + frm.Op_Id);
if (index >= 0)
{
hotkey.UnHotKey(index);
if (frm.hotkeyTextBox1.HaveHotKey)
{
hotkey.RegHotKey(index, "type_" + frm.Op_Id, hot.Modifiers_Int, hot.KeyCode);
}
}
else
{
if (frm.hotkeyTextBox1.HaveHotKey)
{
hot_index++;
hotkey.RegHotKey(hot_index, "type_" + frm.Op_Id, hot.Modifiers_Int, hot.KeyCode);
}
}
}
frm.Dispose();
}
private void Menu删除分类_Click(object sender, EventArgs e)
{
if (TabList_Type.SelectedItems.Count == 0) { return; }
if (Msg.ShowMsg("确定要删除选定项吗?一旦删除将不可恢复。", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.No)
{
return;
}
if (TabList_Type.SelectedItems.Count == 0) { return; }
var column_id = TabList_Type.SelectedItems[0].Tag.ToInt();
if (column_id == 0) {
Msg.ShowMsg("默认分类不支持删除", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
DataProvider mydb = new DataProvider();
IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType);
if (db.ConnDb(SQLConnStr) == 1)
{
var ds = db.ReadData("select count(*) from Softs where ColumnId=" + column_id);
if (mydb.HaveData(ds))
{
if (mydb.GetValue(ds) > 0)
{
ds.Dispose();
Msg.ShowMsg("当前分类下还有软件,请先移除再删除分类。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
db.Free();
return;
}
}
ds.Dispose();
var index = hotkey.GetHotId("type_" + column_id);
if (index >= 0)
{
hotkey.UnHotKey(index);
}
db.DelById("Columns", column_id.ToString());
TabList_Type.SelectedItems[0].Remove();
db.BeginTransaction();
for (int i = 0; i < TabList_Type.Items.Count; i++)
{
var id = TabList_Type.Items[i].Tag.ToInt();
RyQuickSQL mySQL = new RyQuickSQL("Columns");
mySQL.AddField("sortindex", i);
db.ExecuteNonQuery(mySQL.GetUpdateSQL() + " where id=" + id, mySQL);
}
db.Commit();
}
db.Free();
}
#endregion
#region
private void SetSoftRow(int id, int index)
{
#region
DataProvider mydb = new DataProvider();
IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType);
if (db.ConnDb(SQLConnStr) == 1)
{
DataSet ds = db.ReadData("select * from Softs where id=" + id);
if (mydb.HaveData(ds))
{
DataRow row = ds.Tables[0].Rows[0];
var item = IconViewEx1.Items[index];
SoftInfo info = (SoftInfo)item.Tag;
info.Id = row["id"].ToInt();
info.Name = row["Name"].ToString();
info.Path = row["Path"].ToString();
info.RunPram = row["RunPram"].ToString();
info.SetJson = row["SetJson"].ToString();
info.StartPath = row["StartPath"].ToString();
info.IconPath = row["IconPath"].ToString();
info.SoftType = row["SoftType"].ToInt();
info.WinStartRun = row["WinStartRun"].ToInt()==1;
if (info.IconPath.Length == 0)
{
info.Image = API.GetImg(info.TruePath, 128);
}
else
{
info.Image = API.GetImg(RyFiles.GetRealPath(row["IconPath"].ToString()), 128);
}
string img_path;
if (info.IconPath.Length == 0)
{
img_path = info.TruePath;
}
else
{
img_path = RyFiles.GetRealPath(info.IconPath);
}
if (!dictCacheImg.ContainsKey(img_path))
{
dictCacheImg.Add(img_path, info.Image);
}
else
{
dictCacheImg[img_path] = info.Image;
}
item.Text = row["Name"].ToString();
}
db.Free();
}
#endregion
}
/// <summary>
/// 获取当前页面所属的分类或栏目ID
/// </summary>
/// <returns></returns>
private int GetCurColumnId()
{
var ColumnId = 0;
if (TabList_Type.SelectedItems.Count > 0)
{
ColumnId = TabList_Type.SelectedItems[0].Tag.ToInt();
}
if (ColumnId == 0)
{
if (TabList_Column.SelectedItems.Count > 0)
{
ColumnId = TabList_Column.SelectedItems[0].Tag.ToInt();
}
}
return ColumnId;
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
var ColumnId = GetCurColumnId();
if (ColumnId == 0)
{
Msg.ShowMsg("当前模式下不支持添加软件。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
FrmAddSoft frm = new FrmAddSoft
{
TopMost = TopMost,
ColumnId = ColumnId
};
frm.ShowInCenter(this);
if (frm.ShowDialog(this) == DialogResult.OK)
{
hot_index++;
HotkeyValue hot = new HotkeyValue(frm.hotkeyTextBox1.HotKey);
hotkey.RegHotKey(hot_index, "soft_" + frm.Op_Id, hot.Modifiers_Int, hot.KeyCode);
IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType);
if (db.ConnDb(SQLConnStr) == 1)
{
var ds = db.ReadData("select * from Softs where id="+frm.Op_Id);
if (ds.HaveData())
{
var row=ds.GetRow(0);
SoftInfo info = new SoftInfo
{
Id = frm.Op_Id,
SoftType = row["SoftType"].ToInt(),
ColumnId = row["ColumnId"].ToInt(),
Name = row["Name"].ToString(),
Path = row["Path"].ToString(),
RunPram = row["RunPram"].ToString(),
SetJson = row["SetJson"].ToString(),
StartPath = row["StartPath"].ToString(),
WinStartRun = row["WinStartRun"].ToInt()==1,
IconPath = row["IconPath"].ToString()
};
string img_path;
if (info.IconPath.Length == 0)
{
img_path = info.TruePath;
}
else
{
img_path = RyFiles.GetRealPath(info.IconPath);
}
if (dictCacheImg.ContainsKey(img_path))
{
info.Image = dictCacheImg[img_path];
}
else
{
info.Image = API.GetImg(img_path, 128);
dictCacheImg.Add(img_path, info.Image);
}
AddSoft(info);
}
ds?.Dispose();
}
db.Free();
}
frm.Dispose();
this.Focus();
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (IconViewEx1.SelectedItems.Count == 0) { return; }
var info = (SoftInfo)IconViewEx1.SelectedItems[0].Tag;
FrmAddSoft frm = new FrmAddSoft
{
TopMost = TopMost,
SelectId = info.Id,
IsAdd = 0
};
frm.GetInfo(info.Id);
frm.ShowInCenter(this);
if (frm.ShowDialog(this) == DialogResult.OK)
{
HotkeyValue hot = new HotkeyValue(frm.hotkeyTextBox1.HotKey);
var index = hotkey.GetHotId("soft_" + frm.Op_Id);
if (index >= 0)
{
hotkey.UnHotKey(index);
if (frm.hotkeyTextBox1.HaveHotKey)
{
hotkey.RegHotKey(index, "soft_" + frm.Op_Id, hot.Modifiers_Int, hot.KeyCode);
}
}
else
{
if (frm.hotkeyTextBox1.HaveHotKey)
{
hot_index++;
hotkey.RegHotKey(hot_index, "soft_" + frm.Op_Id, hot.Modifiers_Int, hot.KeyCode);
}
}
SetSoftRow(info.Id, IconViewEx1.SelectedItems[0].Index);
}
frm.Dispose();
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (IconViewEx1.SelectedItems.Count == 0) { return; }
if (Msg.ShowMsg("确定要删除选定项吗?一旦删除将不可恢复。", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.No)
{
return;
}
IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType);
if (db.ConnDb(SQLConnStr) == 1)
{
for (int i = IconViewEx1.SelectedItems.Count - 1; i >= 0; i--)
{
var info = (SoftInfo)IconViewEx1.SelectedItems[i].Tag;
if(info.IconPath.Length>0 && info.IconPath.StartsWith("<app>\\UserDb\\SoftLogos", StringComparison.OrdinalIgnoreCase))
{
RyFiles.DeleteFile(RyFiles.GetRealPath(info.IconPath));
}
var index = hotkey.GetHotId("soft_" + info.Id);
if (index >= 0)
{
hotkey.UnHotKey(index);
}
db.DelById("Softs", info.Id.ToString());
IconViewEx1.SelectedItems[i].Remove();
if (IconViewEx1.Items.Count == 0)
{
LblEmpty.Visible = true;
}
else { LblEmpty.Visible = false; }
}
ReSortSoftByList(db);
}
db.Free();
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
RunByListSelected(true);
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (IconViewEx1.SelectedItems.Count == 0) { return; }
var info = (SoftInfo)IconViewEx1.SelectedItems[0].Tag;
if (System.IO.File.Exists(info.TruePath) || System.IO.Directory.Exists(info.TruePath))
{
RyFiles.OpenFolderGotoFile(info.TruePath);
}
else
{
Msg.ShowMsg("没有找到文件。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
private void RunByListSelected(bool RunasAdmin)
{
if (IconViewEx1.SelectedItems.Count == 0) { return; }
var info = (SoftInfo)IconViewEx1.SelectedItems[0].Tag;
if (VSoft.Config.Soft_Config.HideAfterRun)
{
this.Hide();
}
Thread th = new Thread(Start);
th.Start();
void Start()
{
var result = VSoft.Prams.Run.Open(info, RunasAdmin);
if (result > 36 && VSoft.Config.Soft_Config.HideAfterRun) {
this.Invoke(new Action(() =>
{
this.Hide();
}));
}
else
{
this.Invoke(new Action(() =>
{
this.Show();
}));
}
}
}
private void IconViewEx1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
RunByListSelected(false);
}
else if (e.KeyCode == Keys.Up)
{
if (IconViewEx1.SelectedItems.Count == 0) { return; }
var item = IconViewEx1.SelectedItems[0];
if(item.Position.Y== IconViewEx1.Items[0].Position.Y)
{
IconViewEx1.SelectedItems.Clear();
if (TabList_Column.SelectedItems.Count == 0)
{
TabList_Column.Items[0].Selected = true;
}
TabList_Column.Focus();
var color = TabList_Column.SelectedStartBackColor;
TabList_Column.SelectedStartBackColor = Color.LightYellow;
using (var bg = new BackgroundWorker())
{
bg.DoWork += delegate { System.Threading.Thread.Sleep(500); };//180秒后,3分钟
bg.RunWorkerCompleted += delegate {
this.Invoke(new Action(() =>
{
TabList_Column.SelectedStartBackColor = color;
}));
}; // 线程执行完成后会执行 RunWorkerCompleted 事伯的代码块
bg.RunWorkerAsync();
}
}
}
else if (e.KeyCode == Keys.Left)
{
if (IconViewEx1.SelectedItems.Count == 0) { return; }
var item = IconViewEx1.SelectedItems[0];
if (item.Index==0 || item.Position.X== IconViewEx1.Items[0].Position.X)
{
IconViewEx1.SelectedItems.Clear();
if (TabList_Type.SelectedItems.Count == 0)
{
TabList_Type.Items[0].Selected = true;
}
TabList_Type.Focus();
var color = TabList_Type.SelectedStartBackColor;
TabList_Type.SelectedStartBackColor = Color.LightYellow;
using (var bg = new BackgroundWorker())
{
bg.DoWork += delegate { System.Threading.Thread.Sleep(500); };//180秒后,3分钟
bg.RunWorkerCompleted += delegate {
this.Invoke(new Action(() =>
{
TabList_Type.SelectedStartBackColor = color;
}));
}; // 线程执行完成后会执行 RunWorkerCompleted 事伯的代码块
bg.RunWorkerAsync();
}
}
}
}
private void IconViewEx1_MouseDoubleClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
if (Soft_Config.OpenByClick) { return; }
RunByListSelected(false);
}
}
#endregion
#region
private void IconViewEx1_ItemDrag(object sender, ItemDragEventArgs e)
{
this.DoDragDrop(e.Item, DragDropEffects.Move);
}
private void IconViewEx1_DragEnter(object sender, DragEventArgs e)
{
ListViewItem lvi = (ListViewItem)e.Data.GetData(typeof(ListViewItem));
if (lvi != null)
{
if (lvi.ListView != IconViewEx1)
{
e.Effect = DragDropEffects.None;
return;
}
}
e.Effect = DragDropEffects.Move;
}
private void IconViewEx1_DragDrop(object sender, DragEventArgs e)
{
Point pt;
pt = ((IconViewEx)(sender)).PointToClient(new Point(e.X, e.Y));
var to_item = IconViewEx1.GetItemAt(pt.X, pt.Y);
IconViewEx1.InsertionMark.Index = -1;
TabList_Type.InsertionMark.Index = -1;
TabList_Column.InsertionMark.Index = -1;
var filedrop = e.Data.GetData(DataFormats.FileDrop);
if (filedrop != null)
{
#region
var ColumnId = 0;
if (TabList_Type.SelectedItems.Count > 0)
{
ColumnId = TabList_Type.SelectedItems[0].Tag.ToInt();
}
if (ColumnId == 0)
{
if (TabList_Column.SelectedItems.Count > 0)
{
IDbInterface db2 = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType);
if (db2.ConnDb(SQLConnStr) == 1)
{
ColumnId = Itrycn_Db.GetFirstColumnId(db2, TabList_Column.SelectedItems[0].Tag.ToInt());
}
db2.Free();
}
}
if (ColumnId <= 0)
{
Msg.ShowMsg("当前模式下不支持添加软件。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
IDbInterface db3 = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType);
if (db3.ConnDb(SQLConnStr) == 1)
{
var filelist = (string[])filedrop;
for (int f = 0; f < filelist.Length; f++)
{
var path = filelist[f];
var pram = "";
var StartPath = "";
var des = "";
var icon = "";
var name = System.IO.Path.GetFileNameWithoutExtension(path);
if (System.IO.Path.GetExtension(path).ToLower() == ".lnk")
{
var shortcut = API.ReadShortcut(path);
path = shortcut.TargetPath;
pram = shortcut.Arguments;
StartPath = shortcut.WorkDir;
if(StartPath.Trim('\\')==System.IO.Path.GetDirectoryName(path).Trim('\\'))
{
StartPath = "";
}
if (shortcut.IconLocation != path)
{
icon = shortcut.IconLocation;
}
des = shortcut.Description;
}
else
{
path = RyFiles.GetRelativePath(path);
}
RyQuickSQL mySQL = new RyQuickSQL("Softs");
mySQL.AddField("Name", name);
mySQL.AddField("CmdId", "");
mySQL.AddField("Path", path);
mySQL.AddField("RunPram", pram);
mySQL.AddField("StartPath", StartPath);//起始路径
mySQL.AddField("IconPath", icon);//图标路径
Json json = new Json("");
json.Add("RunAsAdmin", false);
mySQL.AddField("SetJson", json.Text);//设置
mySQL.AddField("Des", des);//备注
mySQL.AddField("Pinyin", ryCommon.PinYin.Convert(name) + "\r\n" + ryCommon.PinYin.ConvertFirstPY(name));
mySQL.AddField("editTime", DateTime.Now);
mySQL.AddField("SoftType", 0);//0表示运行文件,1表示执行快速命令,2表示执行脚本
mySQL.AddField("ClickCount", 0);//点击量
mySQL.AddField("ColumnId", ColumnId);
mySQL.AddField("sortindex", Itrycn_Db.GetSoftCount(db3, ColumnId) + 1);
mySQL.AddField("addTime", DateTime.Now);
var ds = db3.ReadData(mySQL.GetInsertSQL() + ";select last_insert_rowid();", mySQL);
SoftInfo info = new SoftInfo
{
Id = ds.Tables[0].Rows[0][0].ToInt(),
SoftType = 0,
ColumnId = ColumnId,
Name = name,
Path = path,
RunPram = pram,
SetJson = json.Text,
StartPath = StartPath,
IconPath = icon
};
string img_path = icon;
if (img_path.Length == 0) { img_path=path; }
if (dictCacheImg.ContainsKey(img_path))
{
info.Image = dictCacheImg[img_path];
}
else
{
info.Image = API.GetImg(img_path, 128);
dictCacheImg.Add(img_path, info.Image);
}
InsertSoft(to_item==null?-1:to_item.Index, info);
}
ReSortSoftByList(db3);
}
db3.Free();
return;
#endregion
}
if (to_item == null) { return; }
//获得拖放中的项
ListViewItem lvi = (ListViewItem)e.Data.GetData(typeof(ListViewItem));
if (lvi == null) { return; }
if (lvi.ListView!=IconViewEx1) { return; }
if (lvi.Index == to_item.Index) { return; }
InsertSoft(to_item.Index, lvi);
IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType);
if (db.ConnDb(SQLConnStr) == 1)
{
ReSortSoftByList(db);
}
db.Free();
}
private void AddSoft(SoftInfo soft)
{
IconViewEx1.BeginUpdate();
IconViewEx1.View = View.List;
IconViewEx1.Items.Add(soft.Name).Tag = soft;
IconViewEx1.View = View.Tile;
IconViewEx1.EndUpdate();
var rect = IconViewEx1.GetItemRect(IconViewEx1.Items.Count - 1);
if (!IconViewEx1.Bounds.Contains(rect.Location))
{
IconViewEx1.EnsureVisible(IconViewEx1.Items.Count - 1);
}
}
private void InsertSoft(int index, SoftInfo soft)
{
IconViewEx1.BeginUpdate();
IconViewEx1.View = View.List;
if (index == -1 || index==IconViewEx1.Items.Count-1)
{
IconViewEx1.Items.Add(soft.Name).Tag = soft;
}
else
{
IconViewEx1.Items.Insert(index, soft.Name).Tag = soft;
}
IconViewEx1.View = View.Tile;
IconViewEx1.EndUpdate();
if (index == -1)
{
var rect = IconViewEx1.GetItemRect(IconViewEx1.Items.Count - 1);
if (!IconViewEx1.Bounds.Contains(rect.Location))
{
IconViewEx1.EnsureVisible(IconViewEx1.Items.Count - 1);
}
}
else
{
var rect = IconViewEx1.GetItemRect(index);
if (!IconViewEx1.Bounds.Contains(rect.Location))
{
IconViewEx1.EnsureVisible(index);
}
}
}
private void InsertSoft(int index,ListViewItem lvi)
{
IconViewEx1.BeginUpdate();
IconViewEx1.View = View.List;
IconViewEx1.Items.RemoveAt(lvi.Index);
IconViewEx1.Items.Insert(index, lvi);
IconViewEx1.View = View.Tile;
IconViewEx1.EndUpdate();
var rect = IconViewEx1.GetItemRect(index);
if (!IconViewEx1.Bounds.Contains(rect.Location))
{
IconViewEx1.EnsureVisible(index);
}
}
private void IconViewEx1_DragOver(object sender, DragEventArgs e)
{
if (sender is IconViewEx list)
{
var filedrop = e.Data.GetData(DataFormats.FileDrop);
//if (filedrop != null)
//{
// list.InsertionMark.Index = -1;
// return;
//}
var lvi = e.Data.GetData(typeof(ListViewItem));
if (filedrop != null)
{
}
else if(lvi != null)
{
var lvi2 = (ListViewItem)lvi;
if (lvi2.ListView != IconViewEx1)
{
list.InsertionMark.Index = -1;
return;
}
}
else
{
list.InsertionMark.Index = -1;
return;
}
var pt = list.PointToClient(new Point(e.X, e.Y));
int targetIndex = list.InsertionMark.NearestIndex(pt);
if (targetIndex > -1)
{
// Determine whether the mouse pointer is to the left or
// the right of the midpoint of the closest item and set
// the InsertionMark.AppearsAfterItem property accordingly.
Rectangle itemBounds = list.GetItemRect(targetIndex);
if (pt.X < list.Left + itemBounds.Width)
{
targetIndex--;
list.InsertionMark.AppearsAfterItem = true;
}
else
{
list.InsertionMark.AppearsAfterItem = false;
}
}
list.InsertionMark.Index = targetIndex;
list.InsertionMark.Color = Color.Black;
//list.InsertionMark.a = ListViewInsertionMarkAppearance.Largest;
//list.InsertionMark.Color = Color.Transparent;
//// 清除旧的插入标记
//list.Invalidate();
//var item = list.GetItemAt(pt.X, pt.Y);
//// 绘制新的插入标记
//DrawInsertionMark(list, list.CreateGraphics(), item, pt);
//item = list.GetItemAt(pt.X, pt.Y);
}
else if (sender is TabList list2)
{
var pt = list2.PointToClient(new Point(e.X, e.Y));
int targetIndex = list2.InsertionMark.NearestIndex(pt);
if (targetIndex > -1)
{
// Rectangle itemBounds = list2.GetItemRect(targetIndex);
list2.InsertionMark.AppearsAfterItem = false;
}
list2.InsertionMark.Index = targetIndex;
list2.InsertionMark.Color = Color.Black; ;
}
}
#endregion
#region
private void TabList_Column_DragEnter(object sender, DragEventArgs e)
{
//判定是否现在拖动的数据是LISTVIEW项
ListViewItem lvi = (ListViewItem)e.Data.GetData(typeof(ListViewItem));
if (lvi != null)
{
e.Effect = DragDropEffects.Move;
}
}
private void TabList_Column_DragDrop(object sender, DragEventArgs e)
{
Point pt;
IconViewEx1.InsertionMark.Index = -1;
TabList_Type.InsertionMark.Index = -1;
TabList_Column.InsertionMark.Index = -1;
pt = ((TabList)(sender)).PointToClient(new Point(e.X, e.Y));
var item = TabList_Column.GetItemAt(pt.X, pt.Y);
if (item == null) { return; }
var columnid = item.Tag.ToInt();
//获得拖放中的项
var drag_item = e.Data.GetData(typeof(ListViewItem));
if (drag_item == null) { return; }
ListViewItem lvi = (ListViewItem)drag_item;
if (lvi.ListView == IconViewEx1)
{
#region
var info = (SoftInfo)lvi.Tag;
IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType);
if (db.ConnDb(SQLConnStr) == 1)
{
var id = Itrycn_Db.GetFirstColumnId(db, columnid);
if(id<=0)
{
return;
}
RyQuickSQL mySQL = new RyQuickSQL("Softs");
mySQL.AddField("ColumnId", id);
mySQL.AddField("editTime", DateTime.Now);
mySQL.AddField("sortindex", Itrycn_Db.GetSoftCount(db, id) + 1);
db.ExecuteNonQuery(mySQL.GetUpdateSQL() + " where id=" + info.Id, mySQL);
if (TabList_Column.SelectedItems.Count > 0)
{
if (TabList_Type.SelectedItems.Count > 0 && TabList_Type.SelectedItems[0].Tag.ToInt() > 0 && TabList_Type.SelectedItems[0].Tag.ToInt()!=id)
{
lvi.Remove();
}
}
else
{
lvi.Remove();
}
ReSortSoftByList(db);
}
db.Free();
#endregion
}
else if (lvi.ListView == TabList_Column)
{
if (lvi.Index == item.Index) { return; }
TabList_Column.BeginUpdate();
TabList_Column.View = View.List;
TabList_Column.Items.RemoveAt(lvi.Index);
TabList_Column.Items.Insert(item.Index, lvi);
TabList_Column.View = View.Tile;
TabList_Column.EndUpdate();
IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType);
if (db.ConnDb(SQLConnStr) == 1)
{
db.BeginTransaction();
for (int i = 0; i < TabList_Column.Items.Count; i++)
{
var id = TabList_Column.Items[i].Tag.ToInt();
RyQuickSQL mySQL = new RyQuickSQL("Columns");
mySQL.AddField("sortindex", i + 1);
db.ExecuteNonQuery(mySQL.GetUpdateSQL() + " where id=" + id, mySQL);
}
db.Commit();
}
db.Free();
}
}
private void TabList_Column_ItemDrag(object sender, ItemDragEventArgs e)
{
this.DoDragDrop(e.Item, DragDropEffects.Move);
}
#endregion
#region
private DateTime dt_type_drag_time = DateTime.MinValue;
private void TabList_Type_DragEnter(object sender, DragEventArgs e)
{
dt_type_drag_time = DateTime.Now;
//判定是否现在拖动的数据是LISTVIEW项
ListViewItem lvi = (ListViewItem)e.Data.GetData(typeof(ListViewItem));
if (lvi != null)
{
e.Effect = DragDropEffects.Move;
}
}
private void TabList_Type_DragDrop(object sender, DragEventArgs e)
{
IconViewEx1.InsertionMark.Index = -1;
TabList_Type.InsertionMark.Index = -1;
TabList_Column.InsertionMark.Index = -1;
if (dt_type_drag_time.AddMilliseconds(300)>DateTime.Now)
{
return;
}
Point pt;
pt = ((TabList)(sender)).PointToClient(new Point(e.X, e.Y));
var item = TabList_Type.GetItemAt(pt.X, pt.Y);
if (item == null) { return; }
var columnid = item.Tag.ToInt();
if (columnid == 0)
{
return;
}
//获得拖放中的项
var drag_item = e.Data.GetData(typeof(ListViewItem));
if (drag_item == null) { return; }
ListViewItem lvi = (ListViewItem)drag_item;
if (lvi.ListView == IconViewEx1)
{
#region
var info = (SoftInfo)lvi.Tag;
RyQuickSQL mySQL = new RyQuickSQL("Softs");
mySQL.AddField("ColumnId", columnid);
mySQL.AddField("editTime", DateTime.Now);
IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType);
if (db.ConnDb(SQLConnStr) == 1)
{
mySQL.AddField("sortindex", Itrycn_Db.GetSoftCount(db, columnid) + 1);
db.ExecuteNonQuery(mySQL.GetUpdateSQL() + " where id=" + info.Id, mySQL);
if (TabList_Type.SelectedItems.Count > 0)
{
if (TabList_Type.SelectedItems[0].Tag.ToInt() != columnid)
{
lvi.Remove();
}
}
else { lvi.Remove(); }
ReSortSoftByList(db);
}
db.Free();
#endregion
}
else if (lvi.ListView == TabList_Type)
{
if (lvi.Index == item.Index) { return; }
TabList_Type.BeginUpdate();
TabList_Type.View = View.List;
TabList_Type.Items.RemoveAt(lvi.Index);
TabList_Type.Items.Insert(item.Index, lvi);
TabList_Type.View = View.Tile;
TabList_Type.EndUpdate();
IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType);
if (db.ConnDb(SQLConnStr) == 1)
{
db.BeginTransaction();
for (int i = 0; i < TabList_Type.Items.Count; i++)
{
var id = TabList_Type.Items[i].Tag.ToInt();
RyQuickSQL mySQL = new RyQuickSQL("Columns");
mySQL.AddField("sortindex", i+1);
db.ExecuteNonQuery(mySQL.GetUpdateSQL() + " where id=" +id, mySQL);
}
db.Commit();
}
db.Free();
}
}
private void TabList_Type_ItemDrag(object sender, ItemDragEventArgs e)
{
this.DoDragDrop(e.Item, DragDropEffects.Move);
}
#endregion
private void TabList_Type_SelectedIndexChanged(object sender, EventArgs e)
{
if (IsProcUse) { return; }
if(TabList_Type.SelectedItems.Count==0) { return; }
if (TabList_Column.SelectedItems.Count == 0) { return; }
LoadDb();
}
private int LastSelected = -1;
private void SaveSelected(int column_id,int SelectedTypeId,int IconVisibleIndex,int IconSelectedIndex)
{
if (dict_cache_type.ContainsKey(column_id))
{
var item = dict_cache_type[column_id];
item.SelectedTypeId = SelectedTypeId;
item.IconVisibleIndex = IconVisibleIndex;
item.IconSelectedIndex = IconSelectedIndex;
}
else
{
dict_cache_type[column_id] = new SelectInfo()
{
SelectedTypeId = SelectedTypeId,
IconVisibleIndex = IconVisibleIndex,
IconSelectedIndex = IconSelectedIndex
};
}
}
private void TabList_Column_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
{
if (IsProcUse) { return; }
if(LastSelected>=0)
{
var column_id = TabList_Column.Items[LastSelected].Tag.ToInt();
SaveSelected(column_id, GetCurColumnId(), IconViewEx1.GetFirstVisibleIndex(), IconViewEx1.SelectedItems.Count >= 1 ? IconViewEx1.SelectedItems[0].Index : -1);
}
LastSelected = TabList_Column.SelectedItems[0].Index;
if (TabList_Column.SelectedItems.Count > 0)
{
LoadTypeColumn(TabList_Column.SelectedItems[0].Tag.ToInt());
}
else
{
LoadTypeColumn(-1);
}
//LoadDb();
}
/// <summary>
/// 将当前列表中的软件在数据库中排序
/// </summary>
/// <param name="db"></param>
private void ReSortSoftByList(IDbInterface db)
{
db.BeginTransaction();
for (int i = 0; i < IconViewEx1.Items.Count; i++)
{
var info = (SoftInfo)IconViewEx1.Items[i].Tag;
RyQuickSQL mySQL = new RyQuickSQL("Softs");
mySQL.AddField("sortindex", i + 1);
db.ExecuteNonQuery(mySQL.GetUpdateSQL() + " where id=" + info.Id, mySQL);
}
db.Commit();
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Normal;
var topmost = this.TopMost;
this.TopMost = true;
this.Show();
this.TopMost = topmost;
var opens = Application.OpenForms;
for (int i = 0; i < opens.Count; i++)
{
if (opens[i].Modal)
{
if(opens[i].Owner==this)
{
opens[i].Show();
}
}
}
}
private void 退ToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
ryCommon.RyFiles.OpenUrl(Config.Soft_Info.Soft_Url);
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
#if DY
Msg.ShowMsg(Config.Soft_Info.AboutText.Replace("#softname#", Config.Soft_Info.Soft_Title).Replace("#ver#", "V" + RySoft.VersionStr), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
#else
if (Config.Soft_Info.DonateVisabled)
{
FrmAbout frm = new FrmAbout();
frm.TopMost = TopMost;
frm.ShowDialog();
frm.Dispose();
}
else
{
Msg.ShowMsg(Config.Soft_Info.AboutText.Replace("#softname#", Config.Soft_Info.Soft_Title).Replace("#ver#", "V" + RySoft.VersionStr), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
#endif
}
private void ShowSetting(bool ShowInScreenCenter)
{
hotkey.Enabled = false;
FrmSetting frm = new FrmSetting
{
TopMost = TopMost
};
if (!ShowInScreenCenter)
{
frm.ShowInCenter(this);
}
if (frm.ShowDialog(this) == DialogResult.OK)
{
VSoft.Config.Soft_Config.LoadSetting();
hotkey.UnHotKey(100);
HotkeyValue hot = new HotkeyValue(Soft_Config.ShowMainHotKey);
hotkey.RegHotKey(100, hot.Modifiers_Int, hot.KeyCode);
}
frm.Dispose();
hotkey.Enabled = true;
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
ShowSetting(true);
}
int hideCount = 0;
private void FrmVSoft_FormClosing(object sender, FormClosingEventArgs e)
{
if (Soft_Info.ShowTray && Soft_Config.HideByCloseBtn && e.CloseReason == CloseReason.UserClosing)
{
e.Cancel = true;
this.Hide();
hideCount++;
if (hideCount <= 2)
{
notifyIcon1.ShowBalloonTip(3000, Soft_Info.Soft_Title, "软件已经最小化到此处,请右击托盘图标进行关闭。", ToolTipIcon.Info);
}
return;
}
SaveSelected(TabList_Column.SelectedItems[0].Tag.ToInt(), GetCurColumnId(), IconViewEx1.GetFirstVisibleIndex(), IconViewEx1.SelectedItems.Count >= 1 ? IconViewEx1.SelectedItems[0].Index : -1);
ryCommon.Ini ini = new Ini(VSoft.Config.Soft_Info.UserDataFolder + "\\Win.dat");
ini.WriteIni(VSoft.Config.Soft_Info.Soft_Id, "width", Width);
ini.WriteIni(VSoft.Config.Soft_Info.Soft_Id, "height", Height);
JArray jarr = new JArray();
foreach (var item in dict_cache_type)
{
JObject jo = new JObject
{
{ "ColumnId", item.Key },
{ "IconSelectedIndex", item.Value.IconSelectedIndex },
{ "IconVisibleIndex", item.Value.IconVisibleIndex },
{ "SelectedTypeId", item.Value.SelectedTypeId }
};
jarr.Add(jo);
}
Itrycn_Db.SetSetting("SelectedCache", jarr.ToString());
ini.WriteIni(VSoft.Config.Soft_Info.Soft_Id, "ColumnId", TabList_Column.SelectedItems[0].Tag.ToInt());
ini.WriteIni(VSoft.Config.Soft_Info.Soft_Id, "TypeId", TabList_Type.SelectedItems[0].Tag.ToInt());
}
private void TabList_Column_KeyDown(object sender, KeyEventArgs e)
{
if(e.KeyCode==Keys.Down)
{
if(IconViewEx1.Items.Count>0)
{
if(IconViewEx1.SelectedItems.Count==0)
{
IconViewEx1.Items[0].Selected = true ;
}
IconViewEx1.Focus();
}
}
else if (e.KeyCode == Keys.Up)
{
rySearch1.Focus();
}
}
private void TabList_Type_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Right)
{
if (IconViewEx1.Items.Count > 0)
{
if (IconViewEx1.SelectedItems.Count == 0)
{
IconViewEx1.Items[0].Selected = true;
}
IconViewEx1.Focus();
}
}
}
private void RySearch1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Down)
{
if (TabList_Column.SelectedItems.Count == 0)
{
if (IconViewEx1.Items.Count > 0)
{
if (IconViewEx1.SelectedItems.Count == 0)
{
IconViewEx1.Items[0].Selected = true;
}
IconViewEx1.Focus();
return;
}
else
{
TabList_Column.Items[0].Selected = true;
}
}
TabList_Column.Focus();
var color = TabList_Column.SelectedStartBackColor;
TabList_Column.SelectedStartBackColor = Color.LightYellow;
using (var bg = new BackgroundWorker())
{
bg.DoWork += delegate { System.Threading.Thread.Sleep(500); };//0.5秒
bg.RunWorkerCompleted += delegate {
this.Invoke(new Action(() =>
{
TabList_Column.SelectedStartBackColor = color;
}));
}; // 线程执行完成后会执行 RunWorkerCompleted 事伯的代码块
bg.RunWorkerAsync();
}
}
}
private void IconViewEx1_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
if (!Soft_Config.OpenByClick) { return; }
RunByListSelected(false);
}
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
var ColumnId = 0;
if (TabList_Type.SelectedItems.Count > 0)
{
ColumnId = TabList_Type.SelectedItems[0].Tag.ToInt();
}
if (ColumnId == 0)
{
Msg.ShowMsg("当前模式下不支持添加软件。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
FrmInCMD frm = new FrmInCMD
{
TopMost = TopMost
};
frm.ShowInCenter(this);
if (frm.ShowDialog(this)==DialogResult.OK)
{
var info = frm.SelectedInfo;
info.SoftType = 1;
RyQuickSQL mySQL = new RyQuickSQL("Softs");
mySQL.AddField("Name", info.Name);
mySQL.AddField("SoftType",1);//0表示运行文件,1表示执行内置命令,2表示执行脚本
mySQL.AddField("Path",frm.SQLConnStr);
if (info.CmdId.Length > 0)
{ info.RunPram = "cmdid=" + info.CmdId; mySQL.AddField("RunPram","cmdid="+ info.CmdId); }
else
{
info.RunPram = "id=" + info.Id;
mySQL.AddField("RunPram","id="+ info.Id);
}
info.IconPath = info.IconPath.Length > 0 ? info.IconPath : info.Path;
mySQL.AddField("StartPath","");//起始路径
mySQL.AddField("IconPath", info.IconPath.Length>0? info.IconPath: info.Path);//图标路径
mySQL.AddField("SetJson","");//设置
mySQL.AddField("Des", info.Des);//备注
mySQL.AddField("Pinyin", ryCommon.PinYin.Convert(info.Name) + "\r\n" + ryCommon.PinYin.ConvertFirstPY(info.Name));
mySQL.AddField("editTime", DateTime.Now);
IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType);
if (db.ConnDb(SQLConnStr) == 1)
{
mySQL.AddField("ClickCount", 0);//点击量
mySQL.AddField("ColumnId", ColumnId);
mySQL.AddField("sortindex", Itrycn_Db.GetSoftCount(db, ColumnId) + 1);
mySQL.AddField("addTime", DateTime.Now);
var ds_c = db.ReadData(mySQL.GetInsertSQL() + ";select last_insert_rowid();", mySQL);
if(ds_c.HaveData())
{
info.Id = ds_c.GetRow(0)[0].ToInt();
}
ds_c?.Dispose();
//LoadDb();
string img_path;
if (info.IconPath.Length == 0)
{
img_path = info.TruePath;
}
else
{
img_path = RyFiles.GetRealPath(info.IconPath);
}
if (dictCacheImg.ContainsKey(img_path))
{
info.Image = dictCacheImg[img_path];
}
else
{
info.Image = API.GetImg(img_path, 128);
dictCacheImg.Add(img_path, info.Image);
}
AddSoft(info);
}
db.Free();
}
frm.Dispose();
}
private void FrmVSoft_ResizeEnd(object sender, EventArgs e)
{
if (Width > 200 && Height > 200)
{
ryCommon.Ini ini = new Ini(VSoft.Config.Soft_Info.UserDataFolder + "\\Win.dat");
ini.WriteIni(VSoft.Config.Soft_Info.Soft_Id, "width", Width);
ini.WriteIni(VSoft.Config.Soft_Info.Soft_Id, "height", Height);
}
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
BtnAddColumn.PerformClick();
}
private void MenuTabType_Opening(object sender, CancelEventArgs e)
{
if(TabList_Type.SelectedItems.Count==0)
{
Menu修改分类.Enabled = false;
Menu删除分类.Enabled = false;
}
else
{
Menu修改分类.Enabled = true;
Menu删除分类.Enabled = true;
}
}
private void MenuTabColumn_Opening(object sender, CancelEventArgs e)
{
if (TabList_Column.SelectedItems.Count == 0)
{
ToolStripMenuItem.Enabled = false;
ToolStripMenuItem.Enabled = false;
}
else
{
ToolStripMenuItem.Enabled = true;
ToolStripMenuItem.Enabled = true;
}
}
private void MenuList_Opening(object sender, CancelEventArgs e)
{
bool isSelected = IconViewEx1.SelectedItems.Count>0;
ToolStripMenuItem.Enabled = isSelected;
ToolStripMenuItem.Enabled = isSelected;
ToolStripMenuItem.Enabled = isSelected;
ToolStripMenuItem.Enabled = isSelected;
ToolStripMenuItem.Enabled = isSelected;
if (isSelected)
{
var info = (SoftInfo)IconViewEx1.SelectedItems[0].Tag;
ToolStripMenuItem.Checked = info.WinStartRun;
}
}
private void IconViewEx1_Resize(object sender, EventArgs e)
{
//LblEmpty.Left = (IconViewEx1.Width - LblEmpty.Width) / 2 + IconViewEx1.Left;
}
private void FrmVSoft_Resize(object sender, EventArgs e)
{
LblEmpty.Left =((panelEx1.Width - LblEmpty.Width) / 2);
}
private void PanelEx1_Resize(object sender, EventArgs e)
{
// LblEmpty.Left = panelEx1.Left + ((panelEx1.Width - LblEmpty.Width) / 2);
}
private void LblSetting_Click(object sender, EventArgs e)
{
ShowSetting(false);
}
private void FrmVSoft_Shown(object sender, EventArgs e)
{
ryCommon.Ini ini = new ryCommon.Ini(Soft_Info.UserDataFolder + "\\Win.dat");
Width = ini.ReadIni(VSoft.Config.Soft_Info.Soft_Id, "width",200,2000, 745);
Height = ini.ReadIni(VSoft.Config.Soft_Info.Soft_Id, "height",200,2000, 543);
//var ColumnId = ini.ReadIni(VSoft.Config.Soft_Info.Soft_Id, "ColumnId", -1);
//var TypeId = ini.ReadIni(VSoft.Config.Soft_Info.Soft_Id, "TypeId", -1);
//for (int i = 0; i < TabList_Column.Items.Count; i++)
//{
// if (TabList_Column.Items[i].Tag.ToInt()==ColumnId)
// {
// TabList_Column.Items[i].Selected = true;
// break;
// }
//}
//for (int i = 0; i < TabList_Type.Items.Count; i++)
//{
// if (TabList_Type.Items[i].Tag.ToInt() == TypeId)
// {
// TabList_Type.Items[i].Selected = true;
// break;
// }
//}
ini.WriteIni(Soft_Info.Soft_Id, "hwnd",Handle.ToInt32());
if (prog_args!=null && prog_args.Length>=1 && prog_args[0]=="q")
{
this.Hide();
}
//IconViewEx1.SetInterval(120, 120);
}
private ListViewItem currentItem = new ListViewItem();
private void IconViewEx1_MouseMove(object sender, MouseEventArgs e)
{
ListViewItem lvi = IconViewEx1.GetItemAt(e.X, e.Y);
if (lvi != null && lvi != currentItem)
{
currentItem = lvi;
Graphics g = IconViewEx1.CreateGraphics();
var size= g.MeasureString(lvi.Text, IconViewEx1.Font);
if (size.Width > IconViewEx1.TileSize.Width-2)
{
lvTp.Show(lvi.Text, IconViewEx1, e.Location);
}
else
{
lvTp.Hide(IconViewEx1);
}
}
else if (lvi == null)
{
lvTp.Hide(IconViewEx1);
}
currentItem = lvi;
}
private void TabList_Type_DragLeave(object sender, EventArgs e)
{
TabList_Type.InsertionMark.Index = -1;
}
private void TabList_Column_DragLeave(object sender, EventArgs e)
{
TabList_Column.InsertionMark.Index = -1;
}
private void IconViewEx1_DragLeave(object sender, EventArgs e)
{
IconViewEx1.InsertionMark.Index = -1;
}
private void BtnLeftColumn_Click(object sender, EventArgs e)
{
if (TabList_Column.Items.Count == 0) { return; }
if (TabList_Column.SelectedItems.Count == 0) { TabList_Column.Items[0].Selected = true; }
else
{
var index = TabList_Column.SelectedItems[0].Index;
if(index>=1)
{
index--;
}
else
{
index = TabList_Column.Items.Count - 1;
}
TabList_Column.Items[index].Selected = true;
TabList_Column.EnsureVisible(index);
}
}
private void BtnRightColumn_Click(object sender, EventArgs e)
{
if (TabList_Column.Items.Count == 0) { return; }
if (TabList_Column.SelectedItems.Count == 0) { TabList_Column.Items[0].Selected = true; }
else
{
var index = TabList_Column.SelectedItems[0].Index;
if (index < TabList_Column.Items.Count-1)
{
index++;
}
else
{
index =0;
}
TabList_Column.Items[index].Selected = true;
TabList_Column.EnsureVisible(index);
//TabList_Column.item = TabList_Column.Items[index];
}
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (IconViewEx1.SelectedItems.Count == 0) { return; }
var info = (SoftInfo)IconViewEx1.SelectedItems[0].Tag;
IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType);
if (db.ConnDb(SQLConnStr) == 1)
{
DataSet ds = db.ReadData("Softs", info.Id);
if (ds.HaveData())
{
DataRow reader = ds.Tables[0].Rows[0];
if (reader["WinStartRun"].ToInt()==1)
{
db.ExecuteNonQuery("update Softs set WinStartRun=0 where id=" + info.Id);
}
else
{
if (System.IO.File.Exists(info.TruePath))
{
if (API.HaveRunFromRegedit(info.TruePath))
{
if (Msg.ShowMsg("该软件已添加到注册表进行开机启动,这样会导致重复启动,是否从注册表中删除。", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
{
API.DelRunFromRegedit(info.TruePath);
}
}
}
db.ExecuteNonQuery("update Softs set WinStartRun=1 where id=" + info.Id);
}
info.WinStartRun= reader["WinStartRun"].ToInt() == 0;
ToolStripMenuItem.Checked= reader["WinStartRun"].ToInt() == 0;
}
}
db.Free();
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
FrmWinStartView frm = new FrmWinStartView
{
Icon = Icon
};
frm.ShowDialog();
foreach (var item in frm.RemovesList)
{
for (int i = 0; i < IconViewEx1.Items.Count; i++)
{
var info= (SoftInfo)IconViewEx1.Items[i].Tag;
if(info.Id==item)
{
info.WinStartRun = false;
}
}
}
frm.Dispose();
}
}
class SelectInfo
{
public int SelectedTypeId { get; set; } = -1;
public int IconVisibleIndex { get; set; } = -1;
public int IconSelectedIndex { get; set; } = -1;
}
}