BaoKai_202508-Wms-Jingwang..../WMS.FrmSystems/FrmDictionaryTab.cs

572 lines
18 KiB
C#
Raw Permalink Normal View History

2025-08-24 09:35:55 +08:00
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
{
/// <summary>
/// 窗体:字典明细
/// </summary>
public partial class FrmDictionaryTab : FormBase
{
#region
public static FrmDictionaryTab frmDictionaryTab;
private DictionaryTabModel dictionaryTabModel = new DictionaryTabModel();
private List<DictionaryTabModel> listDictionaryTabModel = new List<DictionaryTabModel>();
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
/// <summary>
/// 无参构造
/// </summary>
public FrmDictionaryTab()
{
InitializeComponent();
lookUpEditDicType.LoadData();
}
///// <summary>
///// 带参构造 根据dictionarytab查询
///// </summary>
///// <param name="dictionarytab"></param>
//public FrmDictionaryTab(string dictionarytab)
//{
// InitializeComponent();
// dictionaryTab = dictionarytab;
//}
public static FrmDictionaryTab getInstance()
{
if (frmDictionaryTab == null || frmDictionaryTab.IsDisposed)
{
frmDictionaryTab = new FrmDictionaryTab();
}
return frmDictionaryTab;
}
/// <summary>
/// 本窗体加载的时候
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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
/// <summary>
/// 整体绑定数据
/// </summary>
private void bindGrid(string dictionaryType)
{
string errText = string.Empty;
//整体绑定数据
string strDataSet = string.Empty;
try
{
listDictionaryTabModel = IBussFactory<BussDictionaryTab>.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();
}
/// <summary>
/// 通用查询
/// </summary>
/// <param name="table"></param>
public override void LoadListData(DataTable table)
{
listDictionaryTabModel = ConvertHelper<DictionaryTabModel>.ConvertToList(table);
bsDictionaryTab.DataSource = listDictionaryTabModel;
gridViewDictionaryTab.RefreshData();
}
/// <summary>
/// GridView选中行改变
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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
/// <summary>
/// 清空按钮
/// </summary>
public override void Clear()
{
//为bsDictionaryTabEdit绑定新的Model
dictionaryTabModel = new DictionaryTabModel();
//dictionaryTabModel.C_FLAG = "使用";
bsDictionaryTabEdit.DataSource = dictionaryTabModel;
}
/// <summary>
/// 新增按钮
/// </summary>
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;
}
}
/// <summary>
/// 保存按钮
/// </summary>
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<DictionaryTabModel> listTemp = IBussFactory<BussDictionaryTab> .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<BussDictionaryTab>.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<BussDictionaryTab>.Instance().InsertDictionTab(model);
}
catch (Exception)
{
SystemCommon.ShowInfoMessageBox("未知错误,请检查网络连接!如仍无法解决问题请联系我们!");
}
if (string.IsNullOrEmpty(errText))
{
addType = model.VC_DICTIONARY_TYPE;
bindGrid(dictionaryType);
}
else
{
SystemCommon.ShowInfoMessageBox("新增失败" + errText);
}
}
}
/// <summary>
/// 编辑按钮
/// </summary>
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<BussDictionaryType>.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;
}
}
/// <summary>
/// 刷新按钮
/// </summary>
public override void Refresh()
{
if (frmButtonItem.ContainsKey("Save") && frmButtonItem["Save"].Enabled == true && DialogResult.OK!= SystemCommon.ShowMessageBoxResult("确定放弃正在编辑的数据?"))
{
return;
}
bindGrid(dictionaryType);
}
/// <summary>
/// 删除按钮
/// </summary>
public override void Del()
{
string errText = string.Empty;
//判断是否可编辑
bool can = false;
try
{
can = IBussFactory<BussDictionaryType>.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<BussDictionaryTab>.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);
}
}
/// <summary>
/// 确定按钮
/// </summary>
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;
}
/// <summary>
/// 保存
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnSave_Click(object sender, EventArgs e)
{
Save();
}
/// <summary>
/// 查询
/// </summary>
public override void Search()
{
FrmSelect frm = new FrmSelect(this.FrmSelectModle);
if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
this.LoadListData(frm.SelectData);
}
}
/// <summary>
/// 双击编辑
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void gridViewDictionaryTab_DoubleClick(object sender, EventArgs e)
{
Edit();
}
#endregion
}
}