438 lines
14 KiB
C#
438 lines
14 KiB
C#
|
|
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.Frm.Base;
|
|||
|
|
using WMS.Model.Base;
|
|||
|
|
using WMS.Common;
|
|||
|
|
using WMS.Base.WebService;
|
|||
|
|
|
|||
|
|
namespace WMS.FrmBaseData
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// 窗体:备注字典
|
|||
|
|
/// </summary>
|
|||
|
|
public partial class FrmRemarkDictionary : FormBase
|
|||
|
|
{
|
|||
|
|
#region 变量
|
|||
|
|
public static FrmRemarkDictionary frmRemarkDictionary;
|
|||
|
|
private BaseRemarkDictionaryModel BaseRemarkDictionaryModel = new BaseRemarkDictionaryModel();
|
|||
|
|
private List<BaseRemarkDictionaryModel> listBaseRemarkDictionaryModel = new List<BaseRemarkDictionaryModel>();
|
|||
|
|
private int flag = -1;//0:新增;1:修改
|
|||
|
|
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region 初始化
|
|||
|
|
/// <summary>
|
|||
|
|
/// 无参构造
|
|||
|
|
/// </summary>
|
|||
|
|
public FrmRemarkDictionary()
|
|||
|
|
{
|
|||
|
|
InitializeComponent();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 本窗体加载的时候
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="sender"></param>
|
|||
|
|
/// <param name="e"></param>
|
|||
|
|
public void FrmRemarkDictionary_Load(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
lueType.LoadData();
|
|||
|
|
|
|||
|
|
bindGrid();
|
|||
|
|
|
|||
|
|
FrmSelectModle = new BaseRemarkDictionaryModel();
|
|||
|
|
if (frmButtonItem.ContainsKey("Save"))
|
|||
|
|
{
|
|||
|
|
frmButtonItem["Save"].Enabled = false;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
public static FrmRemarkDictionary getInstance()
|
|||
|
|
{
|
|||
|
|
if (frmRemarkDictionary == null || frmRemarkDictionary.IsDisposed)
|
|||
|
|
{
|
|||
|
|
frmRemarkDictionary = new FrmRemarkDictionary();
|
|||
|
|
}
|
|||
|
|
return frmRemarkDictionary;
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region 绑定数据
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 整体绑定数据
|
|||
|
|
/// </summary>
|
|||
|
|
private void bindGrid()
|
|||
|
|
{
|
|||
|
|
//绑定备注字典数据
|
|||
|
|
string errText = string.Empty;
|
|||
|
|
|
|||
|
|
BaseRemarkDictionaryModel queryBaseRemarkDictionary = new BaseRemarkDictionaryModel();
|
|||
|
|
string strParameter = Newtonsoft.Json.JsonConvert.SerializeObject(queryBaseRemarkDictionary);
|
|||
|
|
|
|||
|
|
string strResult = string.Empty;
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
strResult = WebLockConfig.Instance.WebBaseRemarkDictionary.GetBaseRemarkDictionaryListStr(strParameter, ref errText);
|
|||
|
|
}
|
|||
|
|
catch (Exception)
|
|||
|
|
{
|
|||
|
|
SystemCommon.ShowInfoMessageBox("未知错误,请检查网络连接!如仍无法解决问题请联系我们!");
|
|||
|
|
}
|
|||
|
|
//如果查询备注字典数据成功
|
|||
|
|
if (errText == string.Empty)
|
|||
|
|
{
|
|||
|
|
listBaseRemarkDictionaryModel = Newtonsoft.Json.JsonConvert.DeserializeObject<List<BaseRemarkDictionaryModel>>(strResult);
|
|||
|
|
|
|||
|
|
//如果有数据
|
|||
|
|
if (listBaseRemarkDictionaryModel.Count > 0) {
|
|||
|
|
|
|||
|
|
//gv绑定数据
|
|||
|
|
bsRemarkDictionary.DataSource = listBaseRemarkDictionaryModel;
|
|||
|
|
GVRemarkDictionary.RefreshData();
|
|||
|
|
//GVRemarkDictionary.FocusedRowHandle = 0;//选中行变为第一行
|
|||
|
|
GVRemarkDictionary.FocusedRowHandle = listBaseRemarkDictionaryModel.FindIndex(p => p.ID == BaseRemarkDictionaryModel.ID);
|
|||
|
|
|
|||
|
|
//编辑区域绑定数据
|
|||
|
|
if (string.IsNullOrEmpty(BaseRemarkDictionaryModel.ID)) {
|
|||
|
|
BaseRemarkDictionaryModel = listBaseRemarkDictionaryModel[0];
|
|||
|
|
}
|
|||
|
|
bsRemarkDictionaryEdit.DataSource = BaseRemarkDictionaryModel;
|
|||
|
|
ColorEdit.Color = System.Drawing.ColorTranslator.FromHtml(BaseRemarkDictionaryModel.COLOR_ID);
|
|||
|
|
}
|
|||
|
|
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>
|
|||
|
|
/// GridView选中行改变
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="sender"></param>
|
|||
|
|
/// <param name="e"></param>
|
|||
|
|
private void GVRemarkDictionary_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
|
|||
|
|
{
|
|||
|
|
//编辑区域数据绑定
|
|||
|
|
BaseRemarkDictionaryModel = new BaseRemarkDictionaryModel();
|
|||
|
|
BaseRemarkDictionaryModel = GVRemarkDictionary.GetFocusedRow() as BaseRemarkDictionaryModel;//当前选中行
|
|||
|
|
bsRemarkDictionaryEdit.DataSource = BaseRemarkDictionaryModel;
|
|||
|
|
ColorEdit.Color = System.Drawing.ColorTranslator.FromHtml(BaseRemarkDictionaryModel.COLOR_ID);
|
|||
|
|
Confirm();//编辑区域不可用
|
|||
|
|
|
|||
|
|
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;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 通用查询
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="table"></param>
|
|||
|
|
public override void LoadListData(DataTable table)
|
|||
|
|
{
|
|||
|
|
listBaseRemarkDictionaryModel = ConvertHelper<BaseRemarkDictionaryModel>.ConvertToList(table);
|
|||
|
|
bsRemarkDictionary.DataSource = listBaseRemarkDictionaryModel;
|
|||
|
|
GVRemarkDictionary.RefreshData();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region 按钮事件
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 清空按钮
|
|||
|
|
/// </summary>
|
|||
|
|
public override void Clear()
|
|||
|
|
{
|
|||
|
|
//为bsRemarkDictionaryEdit绑定新的Model
|
|||
|
|
BaseRemarkDictionaryModel = new BaseRemarkDictionaryModel();
|
|||
|
|
bsRemarkDictionaryEdit.DataSource = BaseRemarkDictionaryModel;
|
|||
|
|
ColorEdit.Color = new Color();
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 新增按钮
|
|||
|
|
/// </summary>
|
|||
|
|
public override void Add()
|
|||
|
|
{
|
|||
|
|
//编辑控件可用
|
|||
|
|
txtContent.Enabled = true;
|
|||
|
|
ColorEdit.Enabled = true;
|
|||
|
|
lueType.Enabled = true;
|
|||
|
|
|
|||
|
|
Clear();
|
|||
|
|
|
|||
|
|
flag = 0;//标识新增
|
|||
|
|
|
|||
|
|
ColorEdit.Color = Color.Black;
|
|||
|
|
|
|||
|
|
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()
|
|||
|
|
{
|
|||
|
|
GCRemarkDictionary.Focus();//改变焦点,确保 正在编辑的控件(如TextBox)的值为编辑后的
|
|||
|
|
|
|||
|
|
if (string.IsNullOrEmpty(lueType.Text.Trim()))
|
|||
|
|
{
|
|||
|
|
SystemCommon.ShowInfoMessageBox("备注类型不能为空");
|
|||
|
|
lueType.Focus();
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
if (string.IsNullOrEmpty(txtContent.Text.Trim()))
|
|||
|
|
{
|
|||
|
|
SystemCommon.ShowInfoMessageBox("备注内容不能为空");
|
|||
|
|
txtContent.Focus();
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
if (ColorEdit.Color.IsEmpty)
|
|||
|
|
{
|
|||
|
|
SystemCommon.ShowInfoMessageBox("请选择备注颜色");
|
|||
|
|
ColorEdit.Focus();
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/*以下将bindingSource绑定的值修改或新增*/
|
|||
|
|
|
|||
|
|
BaseRemarkDictionaryModel model = BaseRemarkDictionaryModel;
|
|||
|
|
model.COLOR_ID = System.Drawing.ColorTranslator.ToHtml(ColorEdit.Color);
|
|||
|
|
model.OPERATORID = userData.USER_ID;//操作人
|
|||
|
|
if (flag == 1)//修改
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
string strBaseRemarkDictionaryModel = Newtonsoft.Json.JsonConvert.SerializeObject(model);//model转字符串
|
|||
|
|
string errText = string.Empty;
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
errText = WebLockConfig.Instance.WebBaseRemarkDictionary.InsOrUpdBaseRemarkDictionary(strBaseRemarkDictionaryModel, 1);//修改
|
|||
|
|
if (string.IsNullOrEmpty(errText))//如果修改成功
|
|||
|
|
{
|
|||
|
|
bindGrid();//重新绑定数据
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
SystemCommon.ShowInfoMessageBox("修改失败" + errText);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
catch (Exception)
|
|||
|
|
{
|
|||
|
|
SystemCommon.ShowInfoMessageBox("未知错误,请检查网络连接!如仍无法解决问题请联系我们!");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
flag = -1;//标识为非新增非修改
|
|||
|
|
}
|
|||
|
|
else if (flag == 0)//新增
|
|||
|
|
{
|
|||
|
|
string strBaseRemarkDictionaryModel = Newtonsoft.Json.JsonConvert.SerializeObject(model);//model转字符串
|
|||
|
|
string errText = string.Empty;
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
errText = WebLockConfig.Instance.WebBaseRemarkDictionary.InsOrUpdBaseRemarkDictionary(strBaseRemarkDictionaryModel, 0);//修改
|
|||
|
|
if (string.IsNullOrEmpty(errText))//如果修改成功
|
|||
|
|
{
|
|||
|
|
bindGrid();//重新绑定数据
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
SystemCommon.ShowInfoMessageBox("新增失败" + errText);
|
|||
|
|
flag = -1;//标识为非新增非修改
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
catch (Exception)
|
|||
|
|
{
|
|||
|
|
SystemCommon.ShowInfoMessageBox("未知错误,请检查网络连接!如仍无法解决问题请联系我们!");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
SystemCommon.ShowInfoMessageBox("未选择新增或修改");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//btnSave.Visible = false;//隐藏保存按钮
|
|||
|
|
|
|||
|
|
//Clear();//保存后clear编辑区域
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 编辑按钮
|
|||
|
|
/// </summary>
|
|||
|
|
public override void Edit()
|
|||
|
|
{
|
|||
|
|
if (!frmButtonItem.ContainsKey("Edit"))
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
else if (frmButtonItem["Edit"].Enabled == false)
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//编辑区域可编辑
|
|||
|
|
txtContent.Enabled = true;
|
|||
|
|
ColorEdit.Enabled = true;
|
|||
|
|
lueType.Enabled = 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;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 刷新按钮
|
|||
|
|
/// </summary>
|
|||
|
|
public override void Refresh()
|
|||
|
|
{
|
|||
|
|
if (frmButtonItem.ContainsKey("Save") && frmButtonItem["Save"].Enabled == true && DialogResult.Yes != SystemCommon.ShowMessageBoxResult("确定放弃正在编辑的数据?"))
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
bindGrid();
|
|||
|
|
//Clear();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 删除按钮
|
|||
|
|
/// </summary>
|
|||
|
|
public override void Del()
|
|||
|
|
{
|
|||
|
|
string errText = string.Empty;
|
|||
|
|
|
|||
|
|
if (DialogResult.Yes == SystemCommon.ShowMessageBoxResult("确定删除"))
|
|||
|
|
{
|
|||
|
|
string str = BaseRemarkDictionaryModel.ID;
|
|||
|
|
if (!string.IsNullOrEmpty(str))
|
|||
|
|
{
|
|||
|
|
//删除备份字典
|
|||
|
|
errText = string.Empty;
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
errText = WebLockConfig.Instance.WebBaseRemarkDictionary.DeleteBaseRemarkDictionary(str);//删除
|
|||
|
|
}
|
|||
|
|
catch (Exception)
|
|||
|
|
{
|
|||
|
|
SystemCommon.ShowInfoMessageBox("未知错误,请检查网络连接!如仍无法解决问题请联系我们!");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (string.IsNullOrEmpty(errText))//如果成功
|
|||
|
|
{
|
|||
|
|
bindGrid();
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
SystemCommon.ShowInfoMessageBox("删除失败" + errText);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
SystemCommon.ShowInfoMessageBox("请选择一条记录");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 确定按钮
|
|||
|
|
/// </summary>
|
|||
|
|
public void Confirm()
|
|||
|
|
{
|
|||
|
|
//编辑区域不可用
|
|||
|
|
txtContent.Enabled = false;
|
|||
|
|
ColorEdit.Enabled = false;
|
|||
|
|
lueType.Enabled = false;
|
|||
|
|
//frmButtonItem["Save"].Enabled = false;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 双击编辑
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="sender"></param>
|
|||
|
|
/// <param name="e"></param>
|
|||
|
|
private void GVRemarkDictionary_DoubleClick(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
Edit();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|