BaoKai_202508-Wms-Jingwang..../WMS.FrmSystems/FrmDictionaryType.cs
2025-08-24 09:35:55 +08:00

621 lines
20 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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
{
/// <summary>
/// 窗体:字典类型
/// </summary>
public partial class FrmDictionaryType : FormBase
{
#region
public static FrmDictionaryType frmDictionaryType;
private List<DictionaryTypeModel> listDictionaryTypeModel = new List<DictionaryTypeModel>();
private DictionaryTypeModel dictionaryTypeModel = new DictionaryTypeModel();
private int flag = -1;//0:新增;1:修改
#endregion
#region
/// <summary>
/// 构造函数
/// </summary>
public FrmDictionaryType()
{
InitializeComponent();
}
public static FrmDictionaryType getInstance()
{
if (frmDictionaryType == null || frmDictionaryType.IsDisposed)
{
frmDictionaryType = new FrmDictionaryType();
}
return frmDictionaryType;
}
/// <summary>
/// 本窗体加载的时候
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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
/// <summary>
/// 整体绑定数据
/// </summary>
private void bindGrid()
{
string errText = string.Empty;
//整体绑定数据
string strDataSet = string.Empty;
try
{
listDictionaryTypeModel = IBussFactory<BussDictionaryType>.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();
}
/// <summary>
/// 通用查询
/// </summary>
/// <param name="table"></param>
public override void LoadListData(DataTable table)
{
listDictionaryTypeModel = ConvertHelper<DictionaryTypeModel>.ConvertToList(table);
bsDictionaryType.DataSource = listDictionaryTypeModel;
gridViewDictionaryType.RefreshData();
}
/// <summary>
/// GridView选中行改变
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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();
}
/// <summary>
/// 双击GridView 显示属于此字典类型的字典明细
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void gridViewDictionaryType_DoubleClick(object sender, EventArgs e)
{
string errText = string.Empty;
string strDataSet = string.Empty;
try
{
//调用Web服务读取字典明细信息
List<DictionaryTabModel> listDictionaryTabModel = IBussFactory<BussDictionaryTab>.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
/// <summary>
/// 清空按钮
/// </summary>
public override void Clear()
{
//为bsDictionaryTypeEdit绑定新的Model
dictionaryTypeModel = new DictionaryTypeModel();
bsDictionaryTypeEdit.DataSource = dictionaryTypeModel;
}
/// <summary>
/// 新增按钮
/// </summary>
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;
}
/// <summary>
/// 保存按钮
/// </summary>
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<BussDictionaryType>.Instance().InsertOrUpdateDictionaryType(model, 1);
bindGrid();
}
catch (Exception)
{
SystemCommon.ShowInfoMessageBox("未知错误,请检查网络连接!如仍无法解决问题请联系我们!");
flag = -1;
}
}
else if (flag == 0)//新增
{
try
{
IBussFactory<BussDictionaryType>.Instance().InsertOrUpdateDictionaryType(model, 0);
bindGrid();
}
catch (Exception)
{
SystemCommon.ShowInfoMessageBox("未知错误,请检查网络连接!如仍无法解决问题请联系我们!");
flag = -1;
}
}
else
{
SystemCommon.ShowInfoMessageBox("未选择新增或修改");
}
}
/// <summary>
/// 编辑按钮
/// </summary>
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;
}
}
/// <summary>
/// 刷新按钮
/// </summary>
public override void Refresh()
{
if (frmButtonItem.ContainsKey("Save") && frmButtonItem["Save"].Enabled == true && DialogResult.OK != SystemCommon.ShowMessageBoxResult("确定放弃正在编辑的数据?"))
{
return;
}
bindGrid();
//Clear();
}
/// <summary>
/// 删除按钮
/// </summary>
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<DictionaryTabModel> modelList = IBussFactory<BussDictionaryTab>.Instance().GetDictionaryTab(strDictionaryType);
if (modelList.Count > 0)
{
if (DialogResult.OK == SystemCommon.ShowMessageBoxResult("该分类下存在字典明细,是否删除?(点击是将一并删除,点击否不进行任何操作)"))
{
errText = string.Empty;
try
{
errText = IBussFactory<BussDictionaryType>.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<BussDictionaryType>.Instance().DeleteDictionaryType(strDictionaryType);
}
catch (Exception)
{
SystemCommon.ShowInfoMessageBox("未知错误,请检查网络连接!如仍无法解决问题请联系我们!");
}
if (string.IsNullOrEmpty(errText))
{
bindGrid();
}
else
{
SystemCommon.ShowInfoMessageBox("删除失败:" + errText);
}
}
}
catch (Exception)
{
SystemCommon.ShowInfoMessageBox("未知错误,请检查网络连接!如仍无法解决问题请联系我们!");
}
}
else
{
SystemCommon.ShowInfoMessageBox("请选择一条记录");
}
}
}
/// <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>
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;
}
/// <summary>
/// 保存
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnSave_Click(object sender, EventArgs e)
{
Save();
}
#endregion
private void gridViewDictionaryType_FocusedColumnChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedColumnChangedEventArgs e)
{
}
}
}