|
|
|
|
using Rs.Controls;
|
|
|
|
|
using Rs.DataAccess;
|
|
|
|
|
using Rs.Framework;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace Rs.MotionPlat
|
|
|
|
|
{
|
|
|
|
|
public partial class SubMenuForm : BaseForm
|
|
|
|
|
{
|
|
|
|
|
string m_category = "";
|
|
|
|
|
SqliteHelper db = new SqliteHelper();
|
|
|
|
|
public SubMenuForm(string category)
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
m_category = category;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SubMenuForm_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
LoadMenu();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void LoadMenu()
|
|
|
|
|
{
|
|
|
|
|
string querySql = $"select * from submenus where enable=1 and category='{m_category}' order by sortindex asc";
|
|
|
|
|
DataTable dt = db.GetDataTable(querySql);
|
|
|
|
|
if(dt!=null&&dt.Rows.Count>0)
|
|
|
|
|
{
|
|
|
|
|
tableLayoutPanel1.ColumnCount= dt.Rows.Count+1;
|
|
|
|
|
tableLayoutPanel1.ColumnStyles.Clear();
|
|
|
|
|
int i = 0;
|
|
|
|
|
foreach(DataRow dr in dt.Rows)
|
|
|
|
|
{
|
|
|
|
|
tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, int.Parse(dr["width"].ToString())));
|
|
|
|
|
ButtonEx button = new ButtonEx();
|
|
|
|
|
button.Tag = dr;
|
|
|
|
|
button.Click += Button_Click;
|
|
|
|
|
button.Cursor = Cursors.Hand;
|
|
|
|
|
button.BackColor = Color.FromArgb(19, 52, 104);
|
|
|
|
|
button.SelectedColor = Color.DarkRed;
|
|
|
|
|
button.FlatStyle = FlatStyle.Flat;
|
|
|
|
|
button.Margin = new Padding(0);
|
|
|
|
|
button.ForeColor = Color.White;
|
|
|
|
|
button.Dock= DockStyle.Fill;
|
|
|
|
|
button.ShowText = dr["showtext"].ToString();
|
|
|
|
|
tableLayoutPanel1.Controls.Add(button,i++,0);
|
|
|
|
|
}
|
|
|
|
|
if(tableLayoutPanel1.Controls.Count>0)
|
|
|
|
|
{
|
|
|
|
|
((ButtonEx)tableLayoutPanel1.Controls[0]).PerformClick();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Button_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
foreach (var btn in tableLayoutPanel1.Controls)
|
|
|
|
|
{
|
|
|
|
|
if(btn is ButtonEx)
|
|
|
|
|
{
|
|
|
|
|
((ButtonEx)btn).Selected = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ButtonEx button=(ButtonEx)sender;
|
|
|
|
|
button.Selected = true;
|
|
|
|
|
DataRow dr = (DataRow)button.Tag;
|
|
|
|
|
if(dr!=null)
|
|
|
|
|
{
|
|
|
|
|
string formname = dr["formname"].ToString();
|
|
|
|
|
Assembly dll = Assembly.LoadFile(Application.StartupPath+ "\\Rs.MotionPlat.exe");
|
|
|
|
|
object obj = null;
|
|
|
|
|
if (dr["key"].ToString()!="")
|
|
|
|
|
{
|
|
|
|
|
obj = dll.CreateInstance(formname, true, BindingFlags.Public | BindingFlags.Instance,null, new object[] { dr["key"].ToString() }, null, null);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
obj = dll.CreateInstance(formname);
|
|
|
|
|
}
|
|
|
|
|
if(obj is Form)
|
|
|
|
|
{
|
|
|
|
|
if (dr["target"].ToString()=="_blank")
|
|
|
|
|
{
|
|
|
|
|
Form subForm = (Form)obj;
|
|
|
|
|
subForm.StartPosition = FormStartPosition.CenterScreen;
|
|
|
|
|
subForm.Show();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
foreach (var item in panelMain.Controls)
|
|
|
|
|
{
|
|
|
|
|
if (item is Form)
|
|
|
|
|
(item as Form).Close();
|
|
|
|
|
}
|
|
|
|
|
panelMain.Controls.Clear();
|
|
|
|
|
Form subForm = (Form)obj;
|
|
|
|
|
subForm.TopLevel = false;
|
|
|
|
|
subForm.Dock = DockStyle.Fill;
|
|
|
|
|
subForm.Visible = true;
|
|
|
|
|
panelMain.Controls.Add(subForm);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnClosed(EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (panelMain != null)
|
|
|
|
|
{
|
|
|
|
|
if(panelMain.Controls.Count>0)
|
|
|
|
|
{
|
|
|
|
|
((Form)panelMain.Controls[0]).Close();
|
|
|
|
|
}
|
|
|
|
|
panelMain.Controls.Clear();
|
|
|
|
|
}
|
|
|
|
|
base.OnClosed(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|