222 lines
6.9 KiB
C#
222 lines
6.9 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 MES.Entity;
|
||
|
|
using System.Data.Entity.Migrations;
|
||
|
|
using System.Data.Entity;
|
||
|
|
using DevExpress.XtraTreeList.Nodes;
|
||
|
|
|
||
|
|
namespace MES.Form
|
||
|
|
{
|
||
|
|
public partial class FrmsysRole : FrmBaseForm
|
||
|
|
{
|
||
|
|
private Dictionary<string, string> fieldDictionary = new Dictionary<string, string>();
|
||
|
|
public FrmsysRole()
|
||
|
|
{
|
||
|
|
InitializeComponent();
|
||
|
|
}
|
||
|
|
private void FrmsysRole_Load(object sender, EventArgs e)
|
||
|
|
{
|
||
|
|
|
||
|
|
InitFrom(xtraTabControl1,grdList,grdListView,new LayoutControlGroup[]{layoutControlGroup1},new sysRoleInfo());
|
||
|
|
InitSearchDicData();
|
||
|
|
}
|
||
|
|
/// <summary>
|
||
|
|
/// 数据源初始化
|
||
|
|
/// </summary>
|
||
|
|
/// <returns></returns>
|
||
|
|
private void Init()
|
||
|
|
{
|
||
|
|
txtcompanyId.Properties.DataSource = GetDataTableUtils.SqlTable("部门");
|
||
|
|
repositoryItemTreeListtxtcompanyId.DataSource= GetDataTableUtils.SqlTable("部门");
|
||
|
|
txtcreatorId.Properties.DataSource = GetDataTableUtils.SqlTable("用户");
|
||
|
|
repositoryItemtxtcreatorId.DataSource= GetDataTableUtils.SqlTable("用户");
|
||
|
|
txteditorId.Properties.DataSource = GetDataTableUtils.SqlTable("用户");
|
||
|
|
repositoryItemtxteditorId.DataSource= GetDataTableUtils.SqlTable("用户");
|
||
|
|
treeList1.DataSource = GetDataTableUtils.SqlTable("角色功能");
|
||
|
|
|
||
|
|
treeList1.OptionsSelection.MultiSelect = true;
|
||
|
|
treeList1.OptionsSelection.UseIndicatorForSelection = false;
|
||
|
|
treeList1.OptionsView.ShowCheckBoxes = true;
|
||
|
|
treeList1.ExpandAll();
|
||
|
|
}
|
||
|
|
/// <summary>
|
||
|
|
/// 搜索字段
|
||
|
|
/// </summary>
|
||
|
|
/// <returns></returns>
|
||
|
|
private void InitSearchDicData()
|
||
|
|
{
|
||
|
|
fieldDictionary.Add("ID","id");
|
||
|
|
fieldDictionary.Add("公司id","companyId");
|
||
|
|
fieldDictionary.Add("公司名称","companyName");
|
||
|
|
fieldDictionary.Add("角色名称","name");
|
||
|
|
fieldDictionary.Add("创建人","creatorId");
|
||
|
|
fieldDictionary.Add("创建时间","createTime");
|
||
|
|
fieldDictionary.Add("编辑人","editorId");
|
||
|
|
fieldDictionary.Add("编辑时间","editTime");
|
||
|
|
}
|
||
|
|
/// <summary>
|
||
|
|
/// 保存
|
||
|
|
/// </summary>
|
||
|
|
/// <returns></returns>
|
||
|
|
public override bool SaveFunction()
|
||
|
|
{
|
||
|
|
try
|
||
|
|
{
|
||
|
|
sysRoleInfo info= (sysRoleInfo)this.ControlDataToModel(new sysRoleInfo());
|
||
|
|
using (var db = new MESDB())
|
||
|
|
{
|
||
|
|
db.sysRoleInfo.AddOrUpdate(info);
|
||
|
|
db.SaveChanges();
|
||
|
|
}
|
||
|
|
if (treeList1.Nodes.Count > 0)
|
||
|
|
{
|
||
|
|
foreach (TreeListNode node in treeList1.Nodes)//拿所有结点
|
||
|
|
{
|
||
|
|
GetCheckedID(node);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
catch (Exception ex)
|
||
|
|
{
|
||
|
|
ex.Message.ShowError();
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
public override void InitgrdListDataSource()
|
||
|
|
{
|
||
|
|
using (var con=new MESDB())
|
||
|
|
{
|
||
|
|
grdList.DataSource=con.sysRoleInfo.ToList();
|
||
|
|
}
|
||
|
|
Init();
|
||
|
|
}
|
||
|
|
/// <summary>
|
||
|
|
/// 字段为空校验
|
||
|
|
/// </summary>
|
||
|
|
/// <returns></returns>
|
||
|
|
public override bool CheckInput()
|
||
|
|
{
|
||
|
|
if(string.IsNullOrEmpty(txtcompanyId.EditValue.ToString()))
|
||
|
|
{
|
||
|
|
"公司id不能为空".ShowWarning();
|
||
|
|
txtcompanyId.Focus();
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
////if(string.IsNullOrEmpty(txtcompanyName.EditValue.ToString()))
|
||
|
|
////{
|
||
|
|
//// "公司名称不能为空".ShowWarning();
|
||
|
|
//// txtcompanyName.Focus();
|
||
|
|
//// return false;
|
||
|
|
////}
|
||
|
|
if(string.IsNullOrEmpty(txtname.EditValue.ToString()))
|
||
|
|
{
|
||
|
|
"角色名称不能为空".ShowWarning();
|
||
|
|
txtname.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;
|
||
|
|
}
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
/// <summary>
|
||
|
|
/// 删除
|
||
|
|
/// </summary>
|
||
|
|
/// <returns></returns>
|
||
|
|
public override bool DelFunction()
|
||
|
|
{
|
||
|
|
try
|
||
|
|
{
|
||
|
|
sysRoleInfo info = (sysRoleInfo)this.ControlDataToModel(new sysRoleInfo());
|
||
|
|
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.sysRoleInfo.SqlQuery("select * from sysRole").ToList();
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
grdList.DataSource = db.sysRoleInfo.SqlQuery($"select * from sysRole where {sql}").ToList();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
private void btnRefrsh_Click(object sender, EventArgs e)
|
||
|
|
{
|
||
|
|
treeList1.DataSource = GetDataTableUtils.SqlTable("角色功能");
|
||
|
|
treeList1.ExpandAll();
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
List<int> ids = new List<int>();//用来存储ID
|
||
|
|
private void GetCheckedID(TreeListNode parentNode)
|
||
|
|
{
|
||
|
|
|
||
|
|
if (parentNode.Nodes.Count == 0) return;//递归终止
|
||
|
|
foreach (TreeListNode node in parentNode.Nodes)
|
||
|
|
{
|
||
|
|
if (node.CheckState == CheckState.Checked)//判断当前节点选择状态
|
||
|
|
{
|
||
|
|
DataRowView drv = treeList1.GetDataRecordByNode(node) as DataRowView;//强转选中状态的行
|
||
|
|
var str = node.Id;
|
||
|
|
}
|
||
|
|
GetCheckedID(node);//执行递归
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|