using System; using System.Collections.Generic; using WMS.Frm.Base; using WMS.Common; using System.Windows.Forms; using WMS.Model.SystemManage; using System.Data; using WMS.Model.Base; using WMS.Business; using WMS.Business.SystemManage; using WMS.Frm; namespace WMS.FrmSystems { /// /// 窗体:字典明细 /// public partial class FrmDictionaryTab : FormBase { #region 变量 public static FrmDictionaryTab frmDictionaryTab; private DictionaryTabModel dictionaryTabModel = new DictionaryTabModel(); private List listDictionaryTabModel = new List(); private int flag = -1;//0:新增;1:修改 private string dictionaryType = string.Empty;//用于查询绑定GridView的dictionaryType private string addType = string.Empty; public string DictionaryType { get { return dictionaryType; } set { dictionaryType = value; } } #endregion #region 初始化 /// /// 无参构造 /// public FrmDictionaryTab() { InitializeComponent(); lookUpEditDicType.LoadData(); } ///// ///// 带参构造 根据dictionarytab查询 ///// ///// //public FrmDictionaryTab(string dictionarytab) //{ // InitializeComponent(); // dictionaryTab = dictionarytab; //} public static FrmDictionaryTab getInstance() { if (frmDictionaryTab == null || frmDictionaryTab.IsDisposed) { frmDictionaryTab = new FrmDictionaryTab(); } return frmDictionaryTab; } /// /// 本窗体加载的时候 /// /// /// public void FrmDictionaryTab_Load(object sender, EventArgs e) { bindGrid(dictionaryType); FrmSelectModle = new DictionaryTabModel(); if (frmButtonItem.ContainsKey("Save")) { frmButtonItem["Save"].Enabled = false; } //AcceptButton = frmButtonItem["保存"]; } #endregion #region 绑定数据 /// /// 整体绑定数据 /// private void bindGrid(string dictionaryType) { string errText = string.Empty; //整体绑定数据 string strDataSet = string.Empty; try { listDictionaryTabModel = IBussFactory.Instance().GetDictionaryTab(dictionaryType);//调用Web服务读取字典明细信息 } catch (Exception) { SystemCommon.ShowInfoMessageBox("未知错误,请检查网络连接!如仍无法解决问题请联系我们!"); } if (errText == string.Empty) { if (listDictionaryTabModel.Count > 0) { //GridView绑定数据 bsDictionaryTab.DataSource = listDictionaryTabModel; gridViewDictionaryTab.RefreshData(); //gridViewDictionaryTab.FocusedRowHandle = 0;//选中行变为第一行 gridViewDictionaryTab.FocusedRowHandle = listDictionaryTabModel.FindIndex(p => p.VC_DICTIONARY_ID == dictionaryTabModel.VC_DICTIONARY_ID); //编辑区域绑定数据 if (string.IsNullOrEmpty(dictionaryTabModel.VC_DICTIONARY_ID)) { dictionaryTabModel = listDictionaryTabModel[0]; } bsDictionaryTabEdit.DataSource = dictionaryTabModel; if(dictionaryTabModel.C_FLAG == "使用"){ rgFlag.SelectedIndex = 0; }else{ rgFlag.SelectedIndex = 1; } } else { SystemCommon.ShowInfoMessageBox("该字典分类下没有字典明细"); } } else { SystemCommon.ShowInfoMessageBox(errText); } 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; } Confirm(); } /// /// 通用查询 /// /// public override void LoadListData(DataTable table) { listDictionaryTabModel = ConvertHelper.ConvertToList(table); bsDictionaryTab.DataSource = listDictionaryTabModel; gridViewDictionaryTab.RefreshData(); } /// /// GridView选中行改变 /// /// /// private void gridViewDictionaryTab_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e) { //编辑区域数据绑定 dictionaryTabModel = new DictionaryTabModel(); dictionaryTabModel = gridViewDictionaryTab.GetFocusedRow() as DictionaryTabModel; if (dictionaryTabModel == null) { SystemCommon.ShowInfoMessageBox("选择记录"); return; } bsDictionaryTabEdit.DataSource = dictionaryTabModel; 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; } Confirm(); } #endregion #region 按钮事件 /// /// 清空按钮 /// public override void Clear() { //为bsDictionaryTabEdit绑定新的Model dictionaryTabModel = new DictionaryTabModel(); //dictionaryTabModel.C_FLAG = "使用"; bsDictionaryTabEdit.DataSource = dictionaryTabModel; } /// /// 新增按钮 /// public override void Add() { lookUpEditDicType.Enabled = true; txtDescription.Enabled = true; txtPinYinCode.Enabled = true; txtCharValue.Enabled = true; txtDictionaryName.Enabled = true; txtSort.Enabled = true; rgFlag.Enabled = true; dictionaryTabModel = new DictionaryTabModel(); dictionaryTabModel.C_FLAG = "使用"; dictionaryTabModel.VC_DICTIONARY_TYPE = addType; bsDictionaryTabEdit.DataSource = dictionaryTabModel; //btnSave.Visible = true; flag = 0; 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; } } /// /// 保存按钮 /// public override void Save() { gridControlDictionaryTab.Focus(); //非空验证 if (string.IsNullOrEmpty(lookUpEditDicType.Text.Trim())) { SystemCommon.ShowInfoMessageBox("请选择所属字典类型"); lookUpEditDicType.Focus(); return; } if (string.IsNullOrEmpty(txtCharValue.Text.Trim())) { SystemCommon.ShowInfoMessageBox("字符值不能为空"); txtCharValue.Focus(); return; } if (string.IsNullOrEmpty(txtDictionaryName.Text.Trim())) { SystemCommon.ShowInfoMessageBox("字典类型值不能为空"); txtDictionaryName.Focus(); return; } #region 检查字符值是否已存在 string errText = string.Empty; string strDataSet = string.Empty; try { List listTemp = IBussFactory .Instance().GetDictionaryTab(dictionaryTabModel.VC_DICTIONARY_TYPE);//调用Web服务读取字典明细信息 if (listTemp.Count > 0) { if (listTemp.Exists(p => p.VC_CHAR_VALUE == dictionaryTabModel.VC_CHAR_VALUE && p.VC_DICTIONARY_ID != dictionaryTabModel.VC_DICTIONARY_ID)) { SystemCommon.ShowInfoMessageBox("该字符值已存在,请修改字符值"); txtCharValue.Focus(); return; } } } catch (Exception) { SystemCommon.ShowInfoMessageBox("未知错误,请检查网络连接!如仍无法解决问题请联系我们!"); } #endregion DictionaryTabModel model = dictionaryTabModel; if (rgFlag.Text == "使用") { model.C_FLAG = "1"; } else { model.C_FLAG = "0"; } model.OPERATORID = userData.USER_ID;//操作人 if (flag == 1)//修改 { model.VC_DICTIONARY_ID = dictionaryTabModel.VC_DICTIONARY_ID; errText = string.Empty; try { errText = IBussFactory.Instance().UpdateDictionaryTab(model); } catch (Exception) { SystemCommon.ShowInfoMessageBox("未知错误,请检查网络连接!如仍无法解决问题请联系我们!"); } if (string.IsNullOrEmpty(errText)) { bindGrid(dictionaryType); } else { SystemCommon.ShowInfoMessageBox("修改失败" + errText); } } else if (flag == 0)//新增 { errText = string.Empty; try { errText = IBussFactory.Instance().InsertDictionTab(model); } catch (Exception) { SystemCommon.ShowInfoMessageBox("未知错误,请检查网络连接!如仍无法解决问题请联系我们!"); } if (string.IsNullOrEmpty(errText)) { addType = model.VC_DICTIONARY_TYPE; bindGrid(dictionaryType); } else { SystemCommon.ShowInfoMessageBox("新增失败" + errText); } } } /// /// 编辑按钮 /// public override void Edit() { if (!frmButtonItem.ContainsKey("Edit")) { return; } else if (frmButtonItem["Edit"].Enabled == false) { return; } string errText = string.Empty; //判断是否可编辑 bool can = false; try { can = IBussFactory.Instance().GetBoolByDictonaryType(dictionaryTabModel.VC_DICTIONARY_TYPE, "VCMODIFY"); } catch (Exception) { SystemCommon.ShowInfoMessageBox("未知错误,请检查网络连接!如仍无法解决问题请联系我们!"); } if (errText == string.Empty) { if (can) { lookUpEditDicType.Enabled = true; txtDescription.Enabled = true; txtPinYinCode.Enabled = true; txtCharValue.Enabled = true; txtDictionaryName.Enabled = true; txtSort.Enabled = true; rgFlag.Enabled = true; //btnSave.Visible = true; flag = 1; } else { SystemCommon.ShowInfoMessageBox("该字典分类不可被编辑"); } } else { SystemCommon.ShowInfoMessageBox(errText); } 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; } } /// /// 刷新按钮 /// public override void Refresh() { if (frmButtonItem.ContainsKey("Save") && frmButtonItem["Save"].Enabled == true && DialogResult.OK!= SystemCommon.ShowMessageBoxResult("确定放弃正在编辑的数据?")) { return; } bindGrid(dictionaryType); } /// /// 删除按钮 /// public override void Del() { string errText = string.Empty; //判断是否可编辑 bool can = false; try { can = IBussFactory.Instance().GetBoolByDictonaryType(dictionaryTabModel.VC_DICTIONARY_TYPE, "VCDELETE"); } catch (Exception) { SystemCommon.ShowInfoMessageBox("未知错误,请检查网络连接!如仍无法解决问题请联系我们!"); } if (errText == string.Empty) { if (can) { if (DialogResult.OK== SystemCommon.ShowMessageBoxResult("确定删除")) { string str = dictionaryTabModel.VC_DICTIONARY_ID; if (!string.IsNullOrEmpty(str)) { errText = string.Empty; try { errText = IBussFactory.Instance().DeleteDictionaryTab(str); } catch (Exception) { SystemCommon.ShowInfoMessageBox("未知错误,请检查网络连接!如仍无法解决问题请联系我们!"); } if (string.IsNullOrEmpty(errText)) { bindGrid(dictionaryType); } else { SystemCommon.ShowInfoMessageBox("删除失败" + errText); } } else { SystemCommon.ShowInfoMessageBox("请选择一条记录"); } } } else { SystemCommon.ShowInfoMessageBox("该字典分类不可被删除"); } } else { SystemCommon.ShowInfoMessageBox(errText); } } /// /// 确定按钮 /// public void Confirm() { lookUpEditDicType.Enabled = false; txtDescription.Enabled = false; txtPinYinCode.Enabled = false; txtCharValue.Enabled = false; txtDictionaryName.Enabled = false; txtSort.Enabled = false; rgFlag.Enabled = false; //btnSave.Visible = false; } /// /// 保存 /// /// /// private void btnSave_Click(object sender, EventArgs e) { Save(); } /// /// 查询 /// public override void Search() { FrmSelect frm = new FrmSelect(this.FrmSelectModle); if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK) { this.LoadListData(frm.SelectData); } } /// /// 双击编辑 /// /// /// private void gridViewDictionaryTab_DoubleClick(object sender, EventArgs e) { Edit(); } #endregion } }