using System; using System.Collections.Generic; using WMS.Frm.Base; using WMS.Common; using WMS.Model.SystemManage; using System.Windows.Forms; using WMS.Business.Base; using System.Data; using WMS.Model.Base; using WMS.Business.SystemManage; using WMS.Business; using WMS.Frm; namespace WMS.FrmSystems { /// /// 窗体:字典类型 /// public partial class FrmDictionaryType : FormBase { #region 变量 public static FrmDictionaryType frmDictionaryType; private List listDictionaryTypeModel = new List(); private DictionaryTypeModel dictionaryTypeModel = new DictionaryTypeModel(); private int flag = -1;//0:新增;1:修改 #endregion #region 初始化 /// /// 构造函数 /// public FrmDictionaryType() { InitializeComponent(); } public static FrmDictionaryType getInstance() { if (frmDictionaryType == null || frmDictionaryType.IsDisposed) { frmDictionaryType = new FrmDictionaryType(); } return frmDictionaryType; } /// /// 本窗体加载的时候 /// /// /// private void FrmDictionaryType_Load(object sender, EventArgs e) { bindGrid(); FrmSelectModle = new DictionaryTypeModel(); if (frmButtonItem.ContainsKey("Save")) { frmButtonItem["Save"].Enabled = false; } if (frmButtonItem.ContainsKey("Clear")) { frmButtonItem["Clear"].Enabled = false; } } #endregion #region 绑定数据 /// /// 整体绑定数据 /// private void bindGrid() { string errText = string.Empty; //整体绑定数据 string strDataSet = string.Empty; try { listDictionaryTypeModel = IBussFactory.Instance().GetDictonaryTypeDS(); if (listDictionaryTypeModel.Count > 0) { //GridView绑定数据 bsDictionaryType.DataSource = listDictionaryTypeModel; gridViewDictionaryType.RefreshData(); //gridViewDictionaryType.FocusedRowHandle = 0;//选中行变为第一行 gridViewDictionaryType.FocusedRowHandle = listDictionaryTypeModel.FindIndex(p => p.DICTIONARYTYPE == dictionaryTypeModel.DICTIONARYTYPE); //编辑区域绑定数据 if (string.IsNullOrEmpty(dictionaryTypeModel.DICTIONARYIDTITLE)) { dictionaryTypeModel = listDictionaryTypeModel[0]; } bsDictionaryTypeEdit.DataSource = dictionaryTypeModel; if (dictionaryTypeModel.CACHE == "是") { rgCache.SelectedIndex = 0; } else { rgCache.SelectedIndex = 1; } if (dictionaryTypeModel.VCADD == "是") { rgAdd.SelectedIndex = 0; } else { rgAdd.SelectedIndex = 1; } if (dictionaryTypeModel.VCDELETE == "是") { rgDelete.SelectedIndex = 0; } else { rgDelete.SelectedIndex = 1; } if (dictionaryTypeModel.VCMODIFY == "是") { rgModify.SelectedIndex = 0; } else { rgModify.SelectedIndex = 1; } } else { SystemCommon.ShowInfoMessageBox("没有字典分类"); } } catch (Exception) { SystemCommon.ShowInfoMessageBox("未知错误,请检查网络连接!如仍无法解决问题请联系我们!"); } if (frmButtonItem.ContainsKey("Add")) { frmButtonItem["Add"].Enabled = true; } if (frmButtonItem.ContainsKey("Edit")) { frmButtonItem["Edit"].Enabled = true; } if (frmButtonItem.ContainsKey("Del")) { frmButtonItem["Del"].Enabled = true; } if (frmButtonItem.ContainsKey("Save")) { frmButtonItem["Save"].Enabled = false; } if (frmButtonItem.ContainsKey("Clear")) { frmButtonItem["Clear"].Enabled = false; } Confirm(); } /// /// 通用查询 /// /// public override void LoadListData(DataTable table) { listDictionaryTypeModel = ConvertHelper.ConvertToList(table); bsDictionaryType.DataSource = listDictionaryTypeModel; gridViewDictionaryType.RefreshData(); } /// /// GridView选中行改变 /// /// /// private void gridViewDictionaryType_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e) { dictionaryTypeModel = gridViewDictionaryType.GetFocusedRow() as DictionaryTypeModel; bsDictionaryTypeEdit.DataSource = dictionaryTypeModel; if (frmButtonItem.ContainsKey("Add")) { frmButtonItem["Add"].Enabled = true; } if (frmButtonItem.ContainsKey("Edit")) { frmButtonItem["Edit"].Enabled = true; } if (frmButtonItem.ContainsKey("Del")) { frmButtonItem["Del"].Enabled = true; } if (frmButtonItem.ContainsKey("Save")) { frmButtonItem["Save"].Enabled = false; } if (frmButtonItem.ContainsKey("Clear")) { frmButtonItem["Clear"].Enabled = false; } Confirm(); } /// /// 双击GridView 显示属于此字典类型的字典明细 /// /// /// private void gridViewDictionaryType_DoubleClick(object sender, EventArgs e) { string errText = string.Empty; string strDataSet = string.Empty; try { //调用Web服务读取字典明细信息 List listDictionaryTabModel = IBussFactory.Instance().GetDictionaryTab(dictionaryTypeModel.DICTIONARYTYPE); if (listDictionaryTabModel.Count > 0) { FormBase formBase = OpenFrmTable("WMS.FrmSystems", "FrmDictionaryTab");//创建字典明细窗体 if (formBase != null) { FrmDictionaryTab frmDictionaryTab = formBase as FrmDictionaryTab; frmDictionaryTab.DictionaryType = dictionaryTypeModel.DICTIONARYTYPE;//为 刚创建的窗体 的 属性 赋值,用于实现 只显示 属于该分类的 明细信息 //OpenTabAddFrm打开窗体,打开之前检测该窗体是否已经被打开 是则返回false if (!OpenTabAddFrm("0107", "FrmDictionaryTab", "字典明细-" + dictionaryTypeModel.DICTIONARYNAME)) { frmDictionaryTab.FrmDictionaryTab_Load(null, null);//如果已经被打开,执行一下窗体加载方法 } } } else { SystemCommon.ShowInfoMessageBox("该字典分类下没有字典明细"); } } catch (Exception) { SystemCommon.ShowInfoMessageBox("未知错误,请检查网络连接!如仍无法解决问题请联系我们!"); } } #endregion #region 按钮事件 /// /// 清空按钮 /// public override void Clear() { //为bsDictionaryTypeEdit绑定新的Model dictionaryTypeModel = new DictionaryTypeModel(); bsDictionaryTypeEdit.DataSource = dictionaryTypeModel; } /// /// 新增按钮 /// public override void Add() { txtDescription.Enabled = true; txtDictionaryIdTitle.Enabled = true; txtDictionaryName.Enabled = true; txtDictionaryNameTitle.Enabled = true; txtDictionaryType.Enabled = true; txtMNCODE.Enabled = true; txtOperatorID.Enabled = true; rgCache.Enabled = true; rgAdd.Enabled = true; rgDelete.Enabled = true; rgModify.Enabled = true; dictionaryTypeModel = new DictionaryTypeModel(); dictionaryTypeModel.CACHE = "是"; dictionaryTypeModel.VCADD = "是"; dictionaryTypeModel.VCDELETE = "是"; dictionaryTypeModel.VCMODIFY = "是"; bsDictionaryTypeEdit.DataSource = dictionaryTypeModel; if (frmButtonItem.ContainsKey("Add")) { frmButtonItem["Add"].Enabled = false; } if (frmButtonItem.ContainsKey("Edit")) { frmButtonItem["Edit"].Enabled = false; } if (frmButtonItem.ContainsKey("Del")) { frmButtonItem["Del"].Enabled = false; } if (frmButtonItem.ContainsKey("Save")) { frmButtonItem["Save"].Enabled = true; } if (frmButtonItem.ContainsKey("Clear")) { frmButtonItem["Clear"].Enabled = true; } //btnSave.Visible = true; flag = 0; } /// /// 保存按钮 /// public override void Save() { gridControlDictionaryType.Focus(); //非空验证 if (string.IsNullOrEmpty(txtDictionaryType.Text.Trim())) { SystemCommon.ShowInfoMessageBox("字典类型不能为空"); txtDictionaryType.Focus(); return; } if (string.IsNullOrEmpty(txtDictionaryName.Text.Trim())) { SystemCommon.ShowInfoMessageBox("字典名称不能为空"); txtDictionaryName.Focus(); return; } if (string.IsNullOrEmpty(txtDescription.Text.Trim())) { SystemCommon.ShowInfoMessageBox("字典描述不能为空"); txtDescription.Focus(); return; } DictionaryTypeModel model = dictionaryTypeModel; if (rgCache.Text == "是") { model.CACHE = "1"; } else { model.CACHE = "0"; } if (rgAdd.Text == "是") { model.VCADD = "1"; } else { model.VCADD = "0"; } if (rgDelete.Text == "是") { model.VCDELETE = "1"; } else { model.VCDELETE = "0"; } if (rgModify.Text == "是") { model.VCMODIFY = "1"; } else { model.VCMODIFY = "0"; } model.OPERATORID = userData.USER_ID;//操作人 //model.OPERATEDATE = System.DateTime.Now; if (flag == 1)//修改 { try { IBussFactory.Instance().InsertOrUpdateDictionaryType(model, 1); bindGrid(); } catch (Exception) { SystemCommon.ShowInfoMessageBox("未知错误,请检查网络连接!如仍无法解决问题请联系我们!"); flag = -1; } } else if (flag == 0)//新增 { try { IBussFactory.Instance().InsertOrUpdateDictionaryType(model, 0); bindGrid(); } catch (Exception) { SystemCommon.ShowInfoMessageBox("未知错误,请检查网络连接!如仍无法解决问题请联系我们!"); flag = -1; } } else { SystemCommon.ShowInfoMessageBox("未选择新增或修改"); } } /// /// 编辑按钮 /// public override void Edit() { if (!frmButtonItem.ContainsKey("Edit")) { return; } else if (frmButtonItem["Edit"].Enabled == false) { return; } txtDescription.Enabled = true; txtDictionaryIdTitle.Enabled = true; txtDictionaryName.Enabled = true; txtDictionaryNameTitle.Enabled = true; txtDictionaryType.Enabled = true; txtMNCODE.Enabled = true; txtOperatorID.Enabled = true; rgCache.Enabled = true; rgAdd.Enabled = true; rgDelete.Enabled = true; rgModify.Enabled = true; //btnSave.Visible = true; flag = 1; if (frmButtonItem.ContainsKey("Add")) { frmButtonItem["Add"].Enabled = false; } if (frmButtonItem.ContainsKey("Edit")) { frmButtonItem["Edit"].Enabled = false; } if (frmButtonItem.ContainsKey("Del")) { frmButtonItem["Del"].Enabled = false; } if (frmButtonItem.ContainsKey("Save")) { frmButtonItem["Save"].Enabled = true; } if (frmButtonItem.ContainsKey("Clear")) { frmButtonItem["Clear"].Enabled = true; } } /// /// 刷新按钮 /// public override void Refresh() { if (frmButtonItem.ContainsKey("Save") && frmButtonItem["Save"].Enabled == true && DialogResult.OK != SystemCommon.ShowMessageBoxResult("确定放弃正在编辑的数据?")) { return; } bindGrid(); //Clear(); } /// /// 删除按钮 /// public override void Del() { string errText = string.Empty; if (DialogResult.OK == SystemCommon.ShowMessageBoxResult("确定删除")) { string strDictionaryType = txtDictionaryType.Text.Trim(); if (!string.IsNullOrEmpty(strDictionaryType)) { /*检测该分类下是否存在字典明细,若有提示用户是否一并删除*/ string strDataSet = string.Empty; try { List modelList = IBussFactory.Instance().GetDictionaryTab(strDictionaryType); if (modelList.Count > 0) { if (DialogResult.OK == SystemCommon.ShowMessageBoxResult("该分类下存在字典明细,是否删除?(点击是将一并删除,点击否不进行任何操作)")) { errText = string.Empty; try { errText = IBussFactory.Instance().DeleteDictionaryTypeAndTab(strDictionaryType); } catch (Exception) { SystemCommon.ShowInfoMessageBox("未知错误,请检查网络连接!如仍无法解决问题请联系我们!"); } if (string.IsNullOrEmpty(errText)) { bindGrid(); } else { SystemCommon.ShowInfoMessageBox("删除失败:" + errText); return; } } else { return; } } else { /*删除字典分类*/ errText = string.Empty; try { errText = IBussFactory.Instance().DeleteDictionaryType(strDictionaryType); } catch (Exception) { SystemCommon.ShowInfoMessageBox("未知错误,请检查网络连接!如仍无法解决问题请联系我们!"); } if (string.IsNullOrEmpty(errText)) { bindGrid(); } else { SystemCommon.ShowInfoMessageBox("删除失败:" + errText); } } } catch (Exception) { SystemCommon.ShowInfoMessageBox("未知错误,请检查网络连接!如仍无法解决问题请联系我们!"); } } else { SystemCommon.ShowInfoMessageBox("请选择一条记录"); } } } /// /// 查询 /// public override void Search() { FrmSelect frm = new FrmSelect(this.FrmSelectModle); if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK) { this.LoadListData(frm.SelectData); } } /// /// 确定按钮 /// public void Confirm() { txtDescription.Enabled = false; txtDictionaryIdTitle.Enabled = false; txtDictionaryName.Enabled = false; txtDictionaryNameTitle.Enabled = false; txtDictionaryType.Enabled = false; txtMNCODE.Enabled = false; txtOperatorID.Enabled = false; rgCache.Enabled = false; rgAdd.Enabled = false; rgDelete.Enabled = false; rgModify.Enabled = false; //btnSave.Visible = false; } /// /// 保存 /// /// /// private void btnSave_Click(object sender, EventArgs e) { Save(); } #endregion private void gridViewDictionaryType_FocusedColumnChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedColumnChangedEventArgs e) { } } }