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 WMS.Model.SystemManage; using WMS.Frm.Base; using WMS.Common; using WMS.Business.SystemManage; using WMS.Business; namespace WMS.FrmSystems { public partial class FrmRoleDictionary : FormBase { RoleDictionaryModel model = new RoleDictionaryModel(); List rolelist = new List(); int flag = 0; public FrmRoleDictionary() { InitializeComponent(); } private void FrmRoleDictionary_Load(object sender, EventArgs e) { FrmSelectModle = new RoleDictionaryModel(); BindRoleDictionaryData(); this.splitContainerControl1.Panel2.Enabled = false; } #region 按钮事件 // 新增按钮 public void Add() { flag = 0; txtID.Focus(); this.splitContainerControl1.Panel2.Enabled = true; bgsSelect.DataSource = new RoleDictionaryModel(); if (frmButtonItem.ContainsKey("Add")) { frmButtonItem["Add"].Enabled = false; } if (frmButtonItem.ContainsKey("Edit")) { frmButtonItem["Edit"].Enabled = false; } if (frmButtonItem.ContainsKey("Save")) { frmButtonItem["Save"].Enabled = true; } if (frmButtonItem.ContainsKey("Del")) { frmButtonItem["Del"].Enabled = true; } } // 更新编辑修改按钮 public void Edit() { GCustomRoleDictionary_DoubleClick(null, null); } // 删除按钮 public void Del() { List dellist = new List(); int[] selectRows = this.gridViewRoleDictionary.GetSelectedRows(); this.labelControl1.Focus(); foreach (int j in selectRows) { model = new RoleDictionaryModel(); model = this.gridViewRoleDictionary.GetRow(j) as RoleDictionaryModel; dellist.Add(model); } if (dellist.Count == 0) { return; } try { string errText = IBussFactory.Instance().UpdateRoleDictionaryList(dellist); if (errText == "") { SystemCommon.ShowInfoMessageBox("删除成功!"); } else { SystemCommon.ShowInfoMessageBox("删除失败!"); } } catch (Exception ex) { SystemCommon.ShowErrorMessageBox("网络连接错误!请检查当前网络环境是否可用!"); } this.splitContainerControl1.Panel2.Enabled = true; BindRoleDictionaryData(); } /// /// 保存 /// public void Save() { if (dataCheck()) //if (1 == 1) { bgsSelect.EndEdit(); string strRoleDictionary = Newtonsoft.Json.JsonConvert.SerializeObject(bgsSelect.DataSource); string errText = string.Empty; try { //新增 if (flag == 0) { errText = IBussFactory.Instance().AddRoleDictionary(bgsSelect.DataSource as RoleDictionaryModel); } //修改 else if (flag == 1) { errText = IBussFactory.Instance().UpdateRoleDictionary(bgsSelect.DataSource as RoleDictionaryModel); } } catch (Exception ex) { SystemCommon.ShowErrorMessageBox("网络连接错误!请检查当前网络环境是否可用!"); return; } if (string.IsNullOrEmpty(errText)) { SystemCommon.ShowInfoMessageBox("操作成功!"); } else { SystemCommon.ShowInfoMessageBox("操作失败!"); } if (frmButtonItem.ContainsKey("Edit")) { frmButtonItem["Edit"].Enabled = true; } if (frmButtonItem.ContainsKey("Save")) { frmButtonItem["Save"].Enabled = false; } if (frmButtonItem.ContainsKey("Add")) { frmButtonItem["Add"].Enabled = true; } if (frmButtonItem.ContainsKey("Del")) { frmButtonItem["Del"].Enabled = true; } this.txtID.Enabled = true; this.splitContainerControl1.Panel2.Enabled = false; BindRoleDictionaryData(); } } // 刷新按钮 public void Refresh() { // splitContainerControl1.Panel2.Enabled = false; if (frmButtonItem.ContainsKey("Add")) { frmButtonItem["Add"].Enabled = true; } if (frmButtonItem.ContainsKey("Edit")) { frmButtonItem["Edit"].Enabled = true; } if (frmButtonItem.ContainsKey("Save")) { frmButtonItem["Save"].Enabled = false; } if (frmButtonItem.ContainsKey("Del")) { frmButtonItem["Del"].Enabled = true; } BindRoleDictionaryData(); } //数据导出到Excel public void Export() { } //打印 public void Print() { } /// /// 数据导入 /// public void Import() { } public void SaveImport() { } #region 通用查询方法 /// /// 通用查询 方法 /// /// public override void LoadListData(DataTable table) { rolelist = ConvertHelper.ConvertToList(table); GCustomRoleDictionary.DataSource = rolelist; bgsRoleDictionary.DataSource = GCustomRoleDictionary.DataSource; this.gridViewRoleDictionary.RefreshData(); } #endregion #endregion /// /// 绑定角色信息 /// private void BindRoleDictionaryData() { model = new RoleDictionaryModel(); rolelist = IBussFactory.Instance().GetRoleDictionaryListData(model); if (rolelist.Count > 0) { GCustomRoleDictionary.DataSource = rolelist; bgsRoleDictionary.DataSource = GCustomRoleDictionary.DataSource; this.gridViewRoleDictionary.RefreshData(); bgsSelect.DataSource = this.gridViewRoleDictionary.GetRow(0); } } /// /// 验证编号是否存在 /// /// /// private void txtID_Leave(object sender, EventArgs e) { //str_result 0:不存在 1:已存在 string str_result = IBussFactory.Instance().ExistsRoleDictionary(this.txtID.Text.Trim()); if (str_result != "0") { SystemCommon.ShowInfoMessageBox("角色编号已经存在!请重新输入!"); txtID.Focus(); txtID.SelectAll(); return; } } private bool dataCheck() { if (string.IsNullOrEmpty(txtID.Text.Trim())) { SystemCommon.ShowInfoMessageBox("角色编号不能为空!"); txtID.Focus(); return false; } if (string.IsNullOrEmpty(txtName.Text.Trim())) { SystemCommon.ShowInfoMessageBox("角色名称不能为空!"); txtName.Focus(); return false; } if (txtDIsc.Text.Length > 300) { SystemCommon.ShowInfoMessageBox("角色描述信息过长,请重新输入"); txtDIsc.Text = string.Empty; return false; } return true; } //显示数据 private void GCustomRoleDictionary_Click(object sender, EventArgs e) { this.splitContainerControl1.Panel2.Enabled = false; bgsSelect.DataSource = this.gridViewRoleDictionary.GetRow(this.gridViewRoleDictionary.FocusedRowHandle) as RoleDictionaryModel; } //修改数据 private void GCustomRoleDictionary_DoubleClick(object sender, EventArgs e) { flag = 1; this.splitContainerControl1.Panel2.Enabled = true; this.txtID.Enabled = false; if (frmButtonItem.ContainsKey("Edit")) { frmButtonItem["Edit"].Enabled = false; } if (frmButtonItem.ContainsKey("Del")) { frmButtonItem["Del"].Enabled = false; } if (frmButtonItem.ContainsKey("Add")) { frmButtonItem["Add"].Enabled = false; } if (frmButtonItem.ContainsKey("Save")) { frmButtonItem["Save"].Enabled = true; } } } }