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.BLL;
using SIMDP.Model;
using ProjectBase.Data.BaseDAL;
using ProjectBase.Util;
using ProjectBase.Data.Logs;
namespace SIMDP.View
{
public partial class FormEditLogOperationSetting : DevExpress.XtraEditors.XtraForm
{
///
/// 需要修改的日志操作配置对象
///
public MoLogOperationSetting operationSetting { get; set; }
public FormEditLogOperationSetting()
{
InitializeComponent();
}
private void FormEditLogOperationSetting_Load(object sender, EventArgs e)
{
InitControls();
}
///
/// 初始化控件
///
private void InitControls()
{
//下拉框--数据库表名
List tableList = BLLFactory.Instance.GetTableNames();
this.lookUp_TableName.Properties.DataSource = tableList;
this.lookUp_TableName.Properties.NullText = null;
if (operationSetting == null)
{
this.btn_Save.Enabled = false;
this.lookUp_TableName.Properties.NullText = "请您选择";
this.txt_Creator.Text = SysEnvironment.CurrentLoginName;
this.txt_Editor.Text = SysEnvironment.CurrentLoginName;
return;
}
this.btn_Add.Enabled = false;
this.lookUp_TableName.EditValue = operationSetting.TableName;
this.lookUp_TableName.Enabled = false;
this.check_Insert.Checked = operationSetting.InsertLog;
this.check_Delete.Checked = operationSetting.DeleteLog;
this.check_Update.Checked = operationSetting.UpdateLog;
this.txt_Creator.Text = operationSetting.CreatorName;
this.txt_Editor.Text = SysEnvironment.CurrentLoginName;
this.check_Forbid.Checked = operationSetting.Forbid;
}
private void btn_Cancel_Click(object sender, EventArgs e)
{
this.Close();
}
private void btn_Add_Click(object sender, EventArgs e)
{
try
{
if (lookUp_TableName.Text == "请您选择")
{
DevExpress.XtraEditors.XtraMessageBox.Show("请输入数据库表", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
//检查是否还有其他相同关键字的记录
bool exist = BLLFactory.Instance.IsExistKey("setting_tableName", this.lookUp_TableName.Text);
if (exist)
{
DevExpress.XtraEditors.XtraMessageBox.Show("指定的【数据库表】已经存在,不能重复添加,请修改", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
MoLogOperationSetting mo = new MoLogOperationSetting();
mo.Forbid = this.check_Forbid.Checked;
mo.TableName = this.lookUp_TableName.Text;
mo.InsertLog = this.check_Insert.Checked;
mo.DeleteLog = this.check_Delete.Checked;
mo.UpdateLog = this.check_Update.Checked;
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("插入数据库log_operationSetting出现错误:{0}", ex.ToString()));
}
}
private void btn_Save_Click(object sender, EventArgs e)
{
try
{
MoLogOperationSetting mo = new MoLogOperationSetting();
mo.ID = operationSetting.ID;
mo.Forbid = this.check_Forbid.Checked;
mo.TableName = this.lookUp_TableName.Text;
mo.InsertLog = this.check_Insert.Checked;
mo.DeleteLog = this.check_Delete.Checked;
mo.UpdateLog = this.check_Update.Checked;
mo.CreatorAccount = operationSetting.CreatorAccount;
mo.CreatorName = operationSetting.CreatorName;
mo.CreateTime = operationSetting.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("修改数据库log_operationSetting出现错误:{0}", ex.ToString()));
}
}
}
}