230 lines
6.3 KiB
C#
230 lines
6.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using WinformGeneralDeveloperFrame;
|
|
using WinformGeneralDeveloperFrame.Commons;
|
|
using DevExpress.XtraLayout;
|
|
using System.Data.Entity.Migrations;
|
|
using System.Data.Entity;
|
|
using MES;
|
|
using MES.Entity;
|
|
|
|
namespace test.Form
|
|
{
|
|
public partial class FrmsysMenu : FrmBaseForm
|
|
{
|
|
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());
|
|
InitSearchDicData();
|
|
}
|
|
/// <summary>
|
|
/// 数据源初始化
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private void Init()
|
|
{
|
|
|
|
|
|
|
|
|
|
repositoryItemtxttoolList.DataSource= GetDataTableUtils.SqlTable("功能按钮");
|
|
txttoolList.Properties.DataSource = GetDataTableUtils.SqlTable("功能按钮");
|
|
|
|
|
|
}
|
|
/// <summary>
|
|
/// 搜索字段
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private void InitSearchDicData()
|
|
{
|
|
fieldDictionary.Add("ID","id");
|
|
fieldDictionary.Add("父id","pid");
|
|
fieldDictionary.Add("菜单名称","name");
|
|
fieldDictionary.Add("图标","icon");
|
|
fieldDictionary.Add("菜单类型","winformType");
|
|
fieldDictionary.Add("排序","sort");
|
|
fieldDictionary.Add("有效","isEnabled");
|
|
fieldDictionary.Add("功能按钮","toolList");
|
|
fieldDictionary.Add("创建人","creatorId");
|
|
fieldDictionary.Add("创建时间","createTime");
|
|
fieldDictionary.Add("编辑人","editorId");
|
|
fieldDictionary.Add("编辑时间","editTime");
|
|
fieldDictionary.Add("是否界面","isForm");
|
|
fieldDictionary.Add("是否功能按钮","isToolBtn");
|
|
}
|
|
/// <summary>
|
|
/// 保存
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public override bool SaveFunction()
|
|
{
|
|
try
|
|
{
|
|
sysMenuInfo info= (sysMenuInfo)this.ControlDataToModel(new sysMenuInfo());
|
|
using (var db = new MESDB())
|
|
{
|
|
db.sysMenuInfo.AddOrUpdate(info);
|
|
db.SaveChanges();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ex.Message.ShowError();
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
public override void InitgrdListDataSource()
|
|
{
|
|
using (var con=new MESDB())///
|
|
{
|
|
grdList.DataSource=con.sysMenuInfo.ToList();
|
|
}
|
|
Init();
|
|
}
|
|
/// <summary>
|
|
/// 字段为空校验
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public override bool CheckInput()
|
|
{
|
|
if(string.IsNullOrEmpty(txtpid.EditValue.ToString()))
|
|
{
|
|
"父id不能为空".ShowWarning();
|
|
txtpid.Focus();
|
|
return false;
|
|
}
|
|
if(string.IsNullOrEmpty(txtname.EditValue.ToString()))
|
|
{
|
|
"菜单名称不能为空".ShowWarning();
|
|
txtname.Focus();
|
|
return false;
|
|
}
|
|
if(string.IsNullOrEmpty(txticon.EditValue.ToString()))
|
|
{
|
|
"图标不能为空".ShowWarning();
|
|
txticon.Focus();
|
|
return false;
|
|
}
|
|
if(string.IsNullOrEmpty(txtwinformType.EditValue.ToString()))
|
|
{
|
|
"菜单类型不能为空".ShowWarning();
|
|
txtwinformType.Focus();
|
|
return false;
|
|
}
|
|
if(string.IsNullOrEmpty(txtsort.EditValue.ToString()))
|
|
{
|
|
"排序不能为空".ShowWarning();
|
|
txtsort.Focus();
|
|
return false;
|
|
}
|
|
if(string.IsNullOrEmpty(txtisEnabled.EditValue.ToString()))
|
|
{
|
|
"有效不能为空".ShowWarning();
|
|
txtisEnabled.Focus();
|
|
return false;
|
|
}
|
|
if(string.IsNullOrEmpty(txttoolList.EditValue.ToString()))
|
|
{
|
|
"功能按钮不能为空".ShowWarning();
|
|
txttoolList.Focus();
|
|
return false;
|
|
}
|
|
if(string.IsNullOrEmpty(txtcreatorId.EditValue.ToString()))
|
|
{
|
|
"创建人不能为空".ShowWarning();
|
|
txtcreatorId.Focus();
|
|
return false;
|
|
}
|
|
if(string.IsNullOrEmpty(txtcreateTime.EditValue.ToString()))
|
|
{
|
|
"创建时间不能为空".ShowWarning();
|
|
txtcreateTime.Focus();
|
|
return false;
|
|
}
|
|
if(string.IsNullOrEmpty(txteditorId.EditValue.ToString()))
|
|
{
|
|
"编辑人不能为空".ShowWarning();
|
|
txteditorId.Focus();
|
|
return false;
|
|
}
|
|
if(string.IsNullOrEmpty(txteditTime.EditValue.ToString()))
|
|
{
|
|
"编辑时间不能为空".ShowWarning();
|
|
txteditTime.Focus();
|
|
return false;
|
|
}
|
|
if(string.IsNullOrEmpty(txtisForm.EditValue.ToString()))
|
|
{
|
|
"是否界面不能为空".ShowWarning();
|
|
txtisForm.Focus();
|
|
return false;
|
|
}
|
|
if(string.IsNullOrEmpty(txtisToolBtn.EditValue.ToString()))
|
|
{
|
|
"是否功能按钮不能为空".ShowWarning();
|
|
txtisToolBtn.Focus();
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
/// <summary>
|
|
/// 删除
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
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;
|
|
}
|
|
/// <summary>
|
|
/// 搜索
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public override void SearchFunction()
|
|
{
|
|
FrmSearch frm = new FrmSearch(fieldDictionary);
|
|
if (frm.ShowDialog()==DialogResult.OK)
|
|
{
|
|
string sql = frm.sql;
|
|
using (var db = new MESDB())
|
|
{
|
|
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();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |