using ryCommon;
using ryCommonDb;
using ryControls;
using SysFuns;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using VSoft.Config;
using VSoft.Prams;
namespace VSoft
{
public partial class FrmVSoft : Form
{
string[] prog_args;
string SQLConnStr = Itrycn_Db.SQLConnStr;
MouseHook mouse = new MouseHook();
public FrmVSoft(string[] args)
{
InitializeComponent();
prog_args = args;
//配置软件信息
notifyIcon1.Text = Config.Soft_Info.Soft_Title;
Text = Config.Soft_Info.Soft_Title + " V" + RySoft.VersionStr;
if (!Config.Soft_Info.ShowTray) { notifyIcon1.Visible = false; }
if (!Config.Soft_Info.DonateVisabled) { 捐助ToolStripMenuItem.Text = "关于"; }
if (Config.Soft_Info.Soft_Url.Length == 0) { 打开官网ToolStripMenuItem.PerformClick(); }
notifyIcon1.Icon = Icon;
}
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)
{
if(Math.Abs((dt_lastMouse-DateTime.Now).TotalMilliseconds)<500)
{
clickcount++;
if (clickcount == 2)
{
ShowOrHideUI();
}
clickcount = 1;
}
else
{
clickcount = 1;
}
dt_lastMouse = DateTime.Now;
}
// MessageBox.Show(e.Button.ToString());
// e.Button == MouseButtons.Middle;
}
private bool IsProcUse = false;
private void LoadDb()
{
LoadDb(false);
}
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();
info.Id = row["id"].ToInt();
info.SoftType = row["SoftType"].ToInt();
info.ColumnId = row["ColumnId"].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();
if (info.IconPath.Length == 0)
{
info.Image = API.GetImg(info.TruePath,128);
}
else
{
info.Image = API.GetImg(RyFiles.GetRealPath(row["IconPath"].ToString()),128);
}
IconViewEx1.Items.Add(info.Name).Tag = info ;
}
IconViewEx1.EndUpdate();
db.Free();
if(IconViewEx1.Items.Count==0)
{
LblEmpty.Visible = true;
}
else { LblEmpty.Visible = false; }
}
}
private void LoadColumn()
{
TabList_Column.Items.Clear();
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);
db.ExecuteNonQuery(mySQL.GetInsertSQL(), mySQL);
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)
{
TabList_Column.Items[0].Selected = true;
}
}
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)
{
TabList_Type.Items[0].Selected = true;
}
}
SysFuns.WinHotReg hotkey;
private void FrmVSoft_Load(object sender, EventArgs e)
{
MinimumSize = new Size(400, 200);
LblEmpty.Left =((panelEx1.Width - LblEmpty.Width) / 2);
Config.Soft_Info.UserDataFolder = ryCommon.RyFiles.GetRealPath(Config.Soft_Info.UserDataFolder);
VSoft.Prams.Itrycn_Db.CreateTable();
VSoft.Config.Soft_Config.LoadSetting();
LoadColumn();
//rySearch1.PerformClick();
//if(RySoft.IsAdministrator())
//{
// MessageBox.Show("管理员模式下启动本软件,可能会导致无法拖放图标到本软件。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
//}
hotkey = new SysFuns.WinHotReg(Handle);
HotkeyValue hot = new HotkeyValue(Soft_Config.ShowMainHotKey);
hotkey.RegHotKey(100,hot.Modifiers_Int, hot.KeyCode);
hotkey.OnHotkey += Hotkey_OnHotkey;
ryCommon.RyRegedit.RegRoot = Microsoft.Win32.RegistryHive.CurrentUser;
//如果开机启动没有启动
if(!ryCommon.RyRegedit.IsAutoRun(Soft_Info.Soft_Id, "\"" + Application.ExecutablePath.Replace("/", "\\") + "\" " + Soft_Info.Soft_Pram))
{
switch (MessageBox.Show("您暂未设置开机启动,下次开机后软件将无法自动运行。\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;
}
}
LiveUpdate.RyUpdate update = new LiveUpdate.RyUpdate(Soft_Info.Update_Url);
update.CheckUpdate();
mouse.OnMouseActivity += Mouse_OnMouseActivity;
mouse.Start();
}
private void Hotkey_OnHotkey(int HotKeyID)
{
switch (HotKeyID)
{
case 100:
ShowOrHideUI();
break;
}
}
///
/// 显示或隐藏UI
///
private void ShowOrHideUI()
{
if (this.Visible && RyForm.GetActiveWindow() == Handle)
{
this.Hide();
}
else
{
显示主窗体ToolStripMenuItem.PerformClick();
this.BringToFront();
this.Select();
this.Focus();
RyForm.BringToTop(Handle);
rySearch1.Focus();
}
}
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)
{
MessageBox.Show("请输入内容。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
LoadDb(true);
}
#region 对栏目标签进行操作
///
/// 将栏目列表中的第几个栏目修改
///
///
///
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();
if (frm.ShowDialog() == 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();
frm.IsAdd = 0;
frm.GetInfo(TabList_Column.SelectedItems[0].Tag.ToInt());
if (frm.ShowDialog() == 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 (MessageBox.Show("确定要删除选定项吗?一旦删除将不可恢复。", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.No)
{
return;
}
if (TabList_Column.Items.Count ==1) {
MessageBox.Show("请至少保留一个栏目。", "提示", 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();
MessageBox.Show("当前栏目下还有分类,请先移除再删除栏目。", "提示", 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 对分类标签进行操作
///
///将分类列表中的第几个分类进行修改
///
///
///
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)
{
MessageBox.Show("请先选择一个栏目。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
var id = TabList_Column.SelectedItems[0].Tag.ToInt();
FrmAddType frm = new FrmAddType();
frm.ParentId = id;
if (frm.ShowDialog() == DialogResult.OK)
{
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 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();
}
TabList_Type.EndUpdate();
db.Free();
}
}
frm.Dispose();
}
private void Menu修改分类_Click(object sender, EventArgs e)
{
if (TabList_Column.SelectedItems.Count == 0)
{
MessageBox.Show("请先选择一个栏目。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (TabList_Type.SelectedItems.Count == 0)
{
MessageBox.Show("请先选择一个分类。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
var id = TabList_Type.SelectedItems[0].Tag.ToInt();
if (id == 0) {
MessageBox.Show("默认分类不支持修改", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
FrmAddType frm = new FrmAddType();
frm.IsAdd = 0;
frm.GetInfo(id);
if (frm.ShowDialog() == DialogResult.OK)
{
SetTypeRow(id, TabList_Type.SelectedItems[0].Index);
}
frm.Dispose();
}
private void Menu删除分类_Click(object sender, EventArgs e)
{
if (TabList_Type.SelectedItems.Count == 0) { return; }
if (MessageBox.Show("确定要删除选定项吗?一旦删除将不可恢复。", "提示", 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) {
MessageBox.Show("默认分类不支持删除", "提示", 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();
MessageBox.Show("当前分类下还有软件,请先移除再删除分类。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
db.Free();
return;
}
}
ds.Dispose();
db.DelById("Columns", column_id.ToString());
TabList_Type.SelectedItems[0].Remove();
db.BeginTransaction();
for (int i = 1; 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();
if (info.IconPath.Length == 0)
{
info.Image = API.GetImg(info.TruePath, 128);
}
else
{
info.Image = API.GetImg(RyFiles.GetRealPath(row["IconPath"].ToString()), 128);
}
item.Text = row["Name"].ToString();
}
db.Free();
}
#endregion
}
///
/// 获取当前页面所属的分类或栏目ID
///
///
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)
{
MessageBox.Show("当前模式下不支持添加软件。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
FrmAddSoft frm = new FrmAddSoft();
frm.ColumnId = ColumnId;
if (frm.ShowDialog() == DialogResult.OK)
{
LoadDb();
}
frm.Dispose();
}
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();
frm.SelectId = info.Id;
frm.IsAdd = 0;
frm.GetInfo(info.Id);
if (frm.ShowDialog() == DialogResult.OK)
{
SetSoftRow(info.Id, IconViewEx1.SelectedItems[0].Index);
}
frm.Dispose();
}
private void 从列表删除该软件ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (IconViewEx1.SelectedItems.Count == 0) { return; }
if (MessageBox.Show("确定要删除选定项吗?一旦删除将不可恢复。", "提示", 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("\\UserDb\\SoftLogos", StringComparison.OrdinalIgnoreCase))
{
RyFiles.DeleteFile(RyFiles.GetRealPath(info.IconPath));
}
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
{
MessageBox.Show("没有找到文件。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
private void RunByListSelected(bool RunasAdmin)
{
if (IconViewEx1.SelectedItems.Count == 0) { return; }
var info = (SoftInfo)IconViewEx1.SelectedItems[0].Tag;
var result= VSoft.Prams.Run.Open(info, RunasAdmin);
if (result>36 && VSoft.Config.Soft_Config.HideAfterRun) { this.Hide(); }
}
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)
{
LblDrag.Height = IconViewEx1.TileSize.Height;
LblDrag.Parent = IconViewEx1;
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)
{
LblDrag.Visible = false;
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)
{
ColumnId = TabList_Column.SelectedItems[0].Tag.ToInt();
}
}
if(ColumnId==0)
{
MessageBox.Show("当前模式下不支持添加软件。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
var path = ((string[])filedrop)[0];
FrmAddSoft frm = new FrmAddSoft(path);
frm.ColumnId = ColumnId;
if (frm.ShowDialog() == DialogResult.OK)
{
LoadDb();
}
frm.Dispose();
return;
#endregion
}
Point pt;
pt = ((IconViewEx)(sender)).PointToClient(new Point(e.X, e.Y));
var to_item = IconViewEx1.GetItemAt(pt.X, pt.Y);
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; }
IconViewEx1.BeginUpdate();
IconViewEx1.View = View.List;
IconViewEx1.Items.RemoveAt(lvi.Index);
IconViewEx1.Items.Insert(to_item.Index, lvi);
IconViewEx1.View = View.Tile;
IconViewEx1.EndUpdate();
IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType);
if (db.ConnDb(SQLConnStr) == 1)
{
ReSortSoftByList(db);
}
db.Free();
}
private void IconViewEx1_DragOver(object sender, DragEventArgs e)
{
ListViewItem item = null;
if (sender is IconViewEx)
{
var filedrop = e.Data.GetData(DataFormats.FileDrop);
if (filedrop != null) {
if (LblDrag.Visible) { LblDrag.Visible = false; }
return;
}
var lvi = e.Data.GetData(typeof(ListViewItem));
if(lvi==null)
{
if (LblDrag.Visible) { LblDrag.Visible = false; }
return;
}
else
{
var lvi2 = (ListViewItem)lvi;
if(lvi2.ListView!=IconViewEx1)
{
if (LblDrag.Visible){LblDrag.Visible = false;}
return;
}
}
var list = ((IconViewEx)(sender));
var pt = list.PointToClient(new Point(e.X, e.Y));
item = list.GetItemAt(pt.X, pt.Y);
}
else if (sender is TabList)
{
var list = ((TabList)(sender));
var pt = list.PointToClient(new Point(e.X, e.Y));
item = list.GetItemAt(pt.X, pt.Y);
}
if (item == null)
{
if (LblDrag.Visible)
{
LblDrag.Visible = false;
}
}
else
{
if (!LblDrag.Visible)
{
LblDrag.Visible = true;
}
LblDrag.Location = item.Position;
}
}
#endregion
#region 栏目拖放
private void TabList_Column_DragEnter(object sender, DragEventArgs e)
{
//判定是否现在拖动的数据是LISTVIEW项
ListViewItem lvi = (ListViewItem)e.Data.GetData(typeof(ListViewItem));
if (lvi != null)
{
LblDrag.Height = TabList_Column.TileSize.Height;
LblDrag.Parent = TabList_Column;
e.Effect = DragDropEffects.Move;
}
}
private void TabList_Column_DragDrop(object sender, DragEventArgs e)
{
LblDrag.Visible = false;
Point pt;
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;
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_Column.SelectedItems.Count > 0)
{
if (TabList_Column.SelectedItems[0].Tag.ToInt() != columnid)
{
lvi.Remove();
}
else if (TabList_Type.SelectedItems.Count > 0 && TabList_Type.SelectedItems[0].Tag.ToInt() > 0)
{
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 void TabList_Type_DragEnter(object sender, DragEventArgs e)
{
//判定是否现在拖动的数据是LISTVIEW项
ListViewItem lvi = (ListViewItem)e.Data.GetData(typeof(ListViewItem));
if (lvi != null)
{
LblDrag.Height = TabList_Type.TileSize.Height;
LblDrag.Parent = TabList_Type;
e.Effect = DragDropEffects.Move;
}
}
private void TabList_Type_DragDrop(object sender, DragEventArgs e)
{
LblDrag.Visible = false;
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)
{
if (TabList_Column.SelectedItems.Count>0)
{
columnid = TabList_Column.SelectedItems[0].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;
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 || item.Index==0 || lvi.Index==0) { 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 = 1; 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();
}
}
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; }
LoadDb();
}
private void TabList_Column_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
{
if (IsProcUse) { return; }
if (TabList_Column.SelectedItems.Count > 0)
{
LoadTypeColumn(TabList_Column.SelectedItems[0].Tag.ToInt());
}
else
{
LoadTypeColumn(-1);
}
//LoadDb();
}
///
/// 将当前列表中的软件在数据库中排序
///
///
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;
}
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 (Config.Soft_Info.DonateVisabled)
{
FrmAbout frm = new FrmAbout();
frm.ShowDialog();
frm.Dispose();
}
else
{
MessageBox.Show(Config.Soft_Info.AboutText.Replace("#softname#", Config.Soft_Info.Soft_Title).Replace("#ver#", "V" + RySoft.VersionStr), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
private void 设置ToolStripMenuItem_Click(object sender, EventArgs e)
{
hotkey.Enabled = false;
FrmSetting frm = new FrmSetting();
if(frm.ShowDialog()==DialogResult.OK)
{
VSoft.Config.Soft_Config.LoadSetting();
hotkey.UnHotKey();
HotkeyValue hot = new HotkeyValue(Soft_Config.ShowMainHotKey);
hotkey.RegHotKey(100,hot.Modifiers_Int, hot.KeyCode);
}
frm.Dispose();
hotkey.Enabled = 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;
}
}
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); };//180秒后,3分钟
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)
{
if (TabList_Column.SelectedItems.Count > 0)
{
ColumnId = TabList_Column.SelectedItems[0].Tag.ToInt();
}
}
if (ColumnId == 0)
{
MessageBox.Show("当前模式下不支持添加软件。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
FrmInCMD frm = new FrmInCMD();
if(frm.ShowDialog()==DialogResult.OK)
{
var info = frm.SelectedInfo;
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)
{ mySQL.AddField("RunPram","cmdid="+ info.CmdId); }
else
{
mySQL.AddField("RunPram","id="+ info.Id);
}
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);
db.ExecuteNonQuery(mySQL.GetInsertSQL(), mySQL);
LoadDb();
}
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
{
if (TabList_Type.SelectedItems[0].Index == 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;
}
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)
{
设置ToolStripMenuItem.PerformClick();
}
}
}