2021-04-13 17:46:18 +08:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Data.Entity;
|
|
|
|
|
using System.Data.Entity.Migrations;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using WinformGeneralDeveloperFrame;
|
|
|
|
|
using WinformGeneralDeveloperFrame.Commons;
|
|
|
|
|
using DevExpress.XtraLayout;
|
|
|
|
|
using MES.Entity;
|
|
|
|
|
|
|
|
|
|
namespace MES.Form
|
|
|
|
|
{
|
2021-04-17 15:40:26 +08:00
|
|
|
|
|
|
|
|
public partial class FrmsysMenu : FrmBaseForm
|
2021-04-13 17:46:18 +08:00
|
|
|
{
|
|
|
|
|
private Dictionary<string, string> fieldDictionary = new Dictionary<string, string>();
|
|
|
|
|
public FrmsysMenu()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
private void FrmsysMenu_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
InitFrom(xtraTabControl1,grdList,grdListView,new LayoutControlGroup[]{layoutControlGroup1},new sysMenuInfo());
|
2021-04-17 15:40:26 +08:00
|
|
|
InitSearchDicData();
|
2021-04-13 17:46:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void InitgrdListDataSource()
|
|
|
|
|
{
|
|
|
|
|
using (var con = new MESDB())///
|
|
|
|
|
{
|
|
|
|
|
grdList.DataSource = con.sysMenuInfo.ToList();
|
|
|
|
|
}
|
|
|
|
|
Init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Init()
|
|
|
|
|
{
|
|
|
|
|
txtpid.Properties.DataSource = GetDataTableUtils.SqlTable("菜单tree");
|
|
|
|
|
repositoryItemTreeListtxtpid.DataSource= GetDataTableUtils.SqlTable("菜单tree");
|
2021-05-25 18:09:07 +08:00
|
|
|
//txttoolList.Properties.DataSource = GetDataTableUtils.SqlTable("功能按钮");
|
2021-04-25 18:49:28 +08:00
|
|
|
repositoryItemCheckedComboBoxEdit1.DataSource= GetDataTableUtils.SqlTable("功能按钮");
|
|
|
|
|
txtcreatorId.Properties.DataSource = GetDataTableUtils.SqlTable("用户");
|
2021-04-13 17:46:18 +08:00
|
|
|
repositoryItemtxtcreatorId.DataSource= GetDataTableUtils.SqlTable("用户");
|
|
|
|
|
txteditorId.Properties.DataSource = GetDataTableUtils.SqlTable("用户");
|
|
|
|
|
repositoryItemtxteditorId.DataSource = GetDataTableUtils.SqlTable("用户");
|
2021-04-17 15:40:26 +08:00
|
|
|
}
|
|
|
|
|
private void InitSearchDicData()
|
|
|
|
|
{
|
|
|
|
|
fieldDictionary.Add("菜单名称", "name");
|
2021-05-26 17:17:51 +08:00
|
|
|
//fieldDictionary.Add("创建时间", "createTime");
|
2021-04-13 17:46:18 +08:00
|
|
|
}
|
|
|
|
|
private void simpleButton1_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
string file = GetIconPath();
|
|
|
|
|
if (!string.IsNullOrEmpty(file))
|
|
|
|
|
{
|
|
|
|
|
this.txticon.Text = file;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private string GetIconPath()
|
|
|
|
|
{
|
|
|
|
|
string file = FileDialogHelper.Open("选择图标文件", FileDialogHelper.ImageFilter, "", Application.StartupPath+"\\Images");
|
|
|
|
|
string result = "";
|
|
|
|
|
if (!string.IsNullOrEmpty(file))
|
|
|
|
|
{
|
|
|
|
|
result = file.Replace(Application.StartupPath, "").Trim('\\');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool SaveFunction()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
sysMenuInfo info= (sysMenuInfo)this.ControlDataToModel(new sysMenuInfo());
|
|
|
|
|
using (var db = new MESDB())
|
|
|
|
|
{
|
|
|
|
|
db.Database.Log = Console.WriteLine;
|
|
|
|
|
db.sysMenuInfo.AddOrUpdate(info);
|
|
|
|
|
db.SaveChanges();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
ex.Message.ShowError();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool DelFunction()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
sysMenuInfo info = (sysMenuInfo)this.ControlDataToModel(new sysMenuInfo());
|
|
|
|
|
using (var db = new MESDB())
|
|
|
|
|
{
|
2021-05-15 13:57:34 +08:00
|
|
|
using (var tran = db.Database.BeginTransaction())
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
db.Entry(info).State = EntityState.Deleted;
|
|
|
|
|
db.SaveChanges();
|
|
|
|
|
db.Database.ExecuteSqlCommand($"delete from sysRoleFunction where roleId={info.id}");
|
|
|
|
|
db.Database.ExecuteSqlCommand($"delete from sysUserRole where roleId={info.id}");
|
|
|
|
|
tran.Commit();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
tran.Rollback();
|
|
|
|
|
ex.Message.ShowError();
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
tran.Dispose();
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-04-13 17:46:18 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
ex.Message.ShowError();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void SearchFunction()
|
|
|
|
|
{
|
|
|
|
|
FrmSearch frm = new FrmSearch(fieldDictionary);
|
|
|
|
|
if (frm.ShowDialog()==DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
string sql = frm.sql;
|
|
|
|
|
using (var db = new MESDB())
|
|
|
|
|
{
|
2021-04-17 15:40:26 +08:00
|
|
|
if (string.IsNullOrEmpty(sql))
|
|
|
|
|
{
|
|
|
|
|
grdList.DataSource = db.sysMenuInfo.SqlQuery("select * from sysMenu").ToList();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
grdList.DataSource = db.sysMenuInfo.SqlQuery($"select * from sysMenu where {sql}").ToList();
|
|
|
|
|
}
|
2021-04-13 17:46:18 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|