#region
|
|
using System;
|
using System.Data;
|
using System.Windows.Forms;
|
using CSFrameworkV5.Common;
|
using CSFrameworkV5.Core;
|
using DevExpress.XtraEditors;
|
|
#endregion
|
|
namespace CSFrameworkV5.Library.PermissionForms
|
{
|
/// <summary>
|
/// 点击确定应用数据事件
|
/// </summary>
|
/// <param name="detail">数据表</param>
|
/// <param name="listBox">复选列表框</param>
|
/// <returns></returns>
|
public delegate bool OnUserRoleEditorApply(DataTable detail,
|
CheckedListBoxControl listBox, DateTime expireDate);
|
|
public partial class frmUserRolePicker : frmBase
|
{
|
private string _codeField;
|
private DataTable _detail;
|
private string _displayField;
|
private bool _isOK;
|
private DataTable _list;
|
private OnUserRoleEditorApply _myMethod;
|
private string _nameField;
|
private bool _supportRemoveItem;
|
|
private frmUserRolePicker()
|
{
|
InitializeComponent();
|
}
|
|
private void btnApply_Click(object sender, EventArgs e)
|
{
|
try
|
{
|
frmWaitingEx.ShowMe(this);
|
|
if (_myMethod != null)
|
{
|
_isOK = _myMethod(_detail, chkList, txtExpireDate.DateTime);
|
if (_isOK)
|
{
|
Msg.ShowInformation("操作成功!");
|
btnApply.Tag = "OK";
|
Close();
|
}
|
else
|
{
|
Msg.Warning("处理数据发生错误!");
|
}
|
}
|
else
|
{
|
Msg.Warning("没有提供处理事件:OnDetailItemEditorApply!");
|
}
|
}
|
finally
|
{
|
frmWaitingEx.HideMe(this);
|
}
|
}
|
|
private void btnCancel_Click(object sender, EventArgs e)
|
{
|
btnApply.Tag = null;
|
Close();
|
}
|
|
private void btnSearch_Click(object sender, EventArgs e)
|
{
|
if (txtCodeName.Text != "")
|
{
|
var filter = _codeField + " LIKE '%" + txtCodeName.Text +
|
"%' OR " + _nameField + " LIKE '%" +
|
txtCodeName.Text + "%'";
|
var dt = _list.Copy();
|
dt.DefaultView.RowFilter = filter;
|
dt = dt.DefaultView.ToTable();
|
InitEditor(dt);
|
}
|
else
|
{
|
InitEditor(_list);
|
}
|
}
|
|
/// <summary>
|
/// 通用接口
|
/// </summary>
|
/// <param name="callBack">点确定按钮回调函数</param>
|
/// <param name="detail">本次处理的数据</param>
|
/// <param name="list">参考数据,用于填充ListBox列表组件数据源</param>
|
/// <param name="codeField">取值字段名</param>
|
/// <param name="nameField">标题字段名</param>
|
/// <param name="displayField">显示字段名</param>
|
/// <param name="supportRemoveItem">是否支持删除项目</param>
|
/// <returns></returns>
|
public static bool Execute(OnUserRoleEditorApply callBack,
|
DataTable detail,
|
DataTable list,
|
string codeField, string nameField, string displayField,
|
bool supportRemoveItem)
|
{
|
var form = new frmUserRolePicker();
|
form._myMethod = callBack;
|
form._codeField = codeField;
|
form._detail = detail;
|
form._displayField = displayField;
|
form._list = list;
|
form._nameField = nameField;
|
form._supportRemoveItem = supportRemoveItem;
|
form.InitEditor(list);
|
form.ShowDialog();
|
return form.btnApply.Tag != null;
|
}
|
|
private void frmDetailItemEditor_Load(object sender, EventArgs e)
|
{
|
txtExpireDate.DateTime = DateTime.Today.AddYears(10);
|
}
|
|
private void InitEditor(DataTable listData)
|
{
|
if (_displayField == "") _displayField = _nameField;
|
|
CheckState chk;
|
string code;
|
chkList.Items.Clear();
|
foreach (DataRow R in listData.Rows)
|
{
|
code = ConvertEx.ToString(R[_codeField]);
|
var rs = _detail.Select(_codeField + "='" + code + "'");
|
if (rs.Length > 0)
|
chk = CheckState.Checked;
|
else
|
chk = CheckState.Unchecked;
|
|
if (_supportRemoveItem) //支持删除功能
|
chkList.Items.Add(code, R[_displayField].ToStringEx(), chk,
|
true);
|
else //编辑器不支持删除(去掉勾),要禁止已勾选的项目
|
chkList.Items.Add(code, R[_displayField].ToStringEx(), chk,
|
rs.Length == 0);
|
}
|
}
|
}
|
}
|