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 { public partial class FrmsysMenu : FrmBaseForm { private Dictionary fieldDictionary = new Dictionary(); public FrmsysMenu() { InitializeComponent(); } private void FrmsysMenu_Load(object sender, EventArgs e) { InitFrom(xtraTabControl1,grdList,grdListView,new LayoutControlGroup[]{layoutControlGroup1},new sysMenuInfo()); } 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"); txttoolList.Properties.DataSource = GetDataTableUtils.SqlTable("功能按钮"); txtcreatorId.Properties.DataSource = GetDataTableUtils.SqlTable("用户"); repositoryItemtxtcreatorId.DataSource= GetDataTableUtils.SqlTable("用户"); txteditorId.Properties.DataSource = GetDataTableUtils.SqlTable("用户"); repositoryItemtxteditorId.DataSource = GetDataTableUtils.SqlTable("用户"); fieldDictionary.Add("菜单名称","name"); fieldDictionary.Add("创建时间", "createTime"); } 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()) { db.Entry(info).State=EntityState.Deleted; db.SaveChanges(); } } 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()) { grdList.DataSource=db.sysMenuInfo.SqlQuery($"select * from sysMenu where {sql}").ToList(); } } } } }