using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using SIMDP.Model;
using SIMDP.BLL;
using ProjectBase.Data.BaseDAL;
using ProjectBase.Util;
using ProjectBase.Data.Logs;
namespace SIMDP.View
{
public partial class FormEditBlack : DevExpress.XtraEditors.XtraForm
{
///
/// 需要修改的黑白名单对象
///
public MoWhite white { get; set; }
///
/// 授权类型的字典表
///
private Dictionary Dic_Type
{
get
{
Dictionary type = new Dictionary();
type.Add("1", "白名单");
type.Add("0", "黑名单");
return type;
}
}
public FormEditBlack()
{
InitializeComponent();
}
private void FormEditBlack_Load(object sender, EventArgs e)
{
InitControls();
}
private void InitControls()
{
//下拉框--类型
this.lookUp_Type.Properties.DataSource = Dic_Type;
this.lookUp_Type.Properties.ValueMember = "Key";
this.lookUp_Type.Properties.DisplayMember = "Value";
this.lookUp_Type.Properties.NullText = "请您选择";
//下拉框--所属用户
List userList = BLLFactory.Instance.GetAll();
Dictionary dic = new Dictionary();
foreach (MoAuthoryUser item in userList)
{
dic.Add(item.LoginAccount, item.UserName);
}
this.lookUp_UserName.Properties.DataSource = dic;
this.lookUp_UserName.Properties.ValueMember = "Key";
this.lookUp_UserName.Properties.DisplayMember = "Value";
this.lookUp_UserName.Properties.NullText = "请您选择";
this.txt_Creator.Enabled = false;
this.txt_Editor.Enabled = false;
if (white == null)
{
this.btn_Save.Enabled = false;
this.txt_Creator.Text = SysEnvironment.CurrentLoginName;
this.txt_Editor.Text = SysEnvironment.CurrentLoginName;
return;
}
this.btn_Add.Enabled = false;
this.txt_Name.Text = white.Name;
this.lookUp_UserName.EditValue = white.UserAccount;
this.lookUp_Type.EditValue = white.Type.ToString();
this.txt_IpStart.Text = white.IPStart;
this.txt_IpEnd.Text = white.IPEnd;
this.txt_Note.Text = white.Note;
this.txt_Creator.Text = white.CreatorName;
this.txt_Editor.Text = white.EditorName;
this.check_Forbid.Checked = white.Forbid;
}
private void btn_Cancel_Click(object sender, EventArgs e)
{
this.Close();
}
private void btn_Add_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(txt_Name.Text))
{
DevExpress.XtraEditors.XtraMessageBox.Show("请输入显示名称", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (lookUp_UserName.Text == "请您选择")
{
DevExpress.XtraEditors.XtraMessageBox.Show("请输入所属用户", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (lookUp_Type.Text == "请您选择")
{
DevExpress.XtraEditors.XtraMessageBox.Show("请输入授权类型", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (string.IsNullOrEmpty(txt_IpStart.Text))
{
DevExpress.XtraEditors.XtraMessageBox.Show("请输入IP起始地址", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (string.IsNullOrEmpty(txt_IpEnd.Text))
{
DevExpress.XtraEditors.XtraMessageBox.Show("请输入IP结束地址", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
try
{
MoWhite mo = new MoWhite();
mo.Name = txt_Name.Text;
mo.UserAccount = lookUp_UserName.EditValue.ToString();
mo.UserName = lookUp_UserName.Text;
mo.Type = Convert.ToInt32(lookUp_Type.EditValue);
mo.Forbid = check_Forbid.Checked;
mo.IPStart = txt_IpStart.Text;
mo.IPEnd = txt_IpEnd.Text;
mo.Note = txt_Note.Text;
mo.CreatorAccount = SysEnvironment.CurrentLoginID;
mo.CreatorName = SysEnvironment.CurrentLoginName;
mo.CreateTime = DateTime.Now;
mo.EditorAccount = SysEnvironment.CurrentLoginID;
mo.EditorName = SysEnvironment.CurrentLoginName;
mo.EditTime = DateTime.Now;
bool flag = BLLFactory.Instance.Insert(mo);
if (flag)
{
DevExpress.XtraEditors.XtraMessageBox.Show("添加成功。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.DialogResult = DialogResult.OK;
this.Close();
}
else
{
DevExpress.XtraEditors.XtraMessageBox.Show("添加失败。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
catch (Exception ex)
{
DevExpress.XtraEditors.XtraMessageBox.Show("添加失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
LogHelper.log.Error(string.Format("插入数据库black出现错误:{0}", ex.ToString()));
}
}
private void btn_Save_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(txt_Name.Text))
{
DevExpress.XtraEditors.XtraMessageBox.Show("请输入显示名称", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (lookUp_UserName.Text == "请您选择")
{
DevExpress.XtraEditors.XtraMessageBox.Show("请输入所属用户", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (lookUp_Type.Text == "请您选择")
{
DevExpress.XtraEditors.XtraMessageBox.Show("请输入授权类型", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (string.IsNullOrEmpty(txt_IpStart.Text))
{
DevExpress.XtraEditors.XtraMessageBox.Show("请输入IP起始地址", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (string.IsNullOrEmpty(txt_IpEnd.Text))
{
DevExpress.XtraEditors.XtraMessageBox.Show("请输入IP结束地址", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
try
{
MoWhite mo = new MoWhite();
mo.ID = white.ID;
mo.Name = txt_Name.Text;
mo.UserAccount = lookUp_UserName.EditValue.ToString();
mo.UserName = lookUp_UserName.Text;
mo.Type = Convert.ToInt32(lookUp_Type.EditValue);
mo.Forbid = check_Forbid.Checked;
mo.IPStart = txt_IpStart.Text;
mo.IPEnd = txt_IpEnd.Text;
mo.Note = txt_Note.Text;
mo.CreatorAccount = white.CreatorAccount;
mo.CreatorName = white.CreatorName;
mo.CreateTime = white.CreateTime;
mo.EditorAccount = SysEnvironment.CurrentLoginID;
mo.EditorName = SysEnvironment.CurrentLoginName;
mo.EditTime = DateTime.Now;
bool flag = BLLFactory.Instance.Update(mo,mo.ID);
if (flag)
{
DevExpress.XtraEditors.XtraMessageBox.Show("修改成功。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.DialogResult = DialogResult.OK;
this.Close();
}
else
{
DevExpress.XtraEditors.XtraMessageBox.Show("修改失败。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
catch (Exception ex)
{
DevExpress.XtraEditors.XtraMessageBox.Show("修改失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
LogHelper.log.Error(string.Format("修改数据库black出现错误:{0}", ex.ToString()));
}
}
}
}