420 lines
13 KiB
C#
420 lines
13 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.Base.WebService;
|
|||
|
|
using WMS.Model.Base;
|
|||
|
|
using WMS.Common;
|
|||
|
|
using System.Text.RegularExpressions;
|
|||
|
|
using WMS.Ctrl;
|
|||
|
|
|
|||
|
|
namespace WMS.FrmBaseData
|
|||
|
|
{
|
|||
|
|
public partial class FrmAddressArea : FormBase
|
|||
|
|
{
|
|||
|
|
#region 变量声明
|
|||
|
|
/// <summary>
|
|||
|
|
///
|
|||
|
|
/// </summary>
|
|||
|
|
public List<AddressAreaModel> list;
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 实体
|
|||
|
|
/// </summary>
|
|||
|
|
public AddressAreaModel model;
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 操作标志 0 新增 ,1 修改
|
|||
|
|
/// </summary>
|
|||
|
|
public int flg = 0;
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 所选择节点
|
|||
|
|
/// </summary>
|
|||
|
|
public DevExpress.XtraTreeList.Nodes.TreeListNode tr = null;
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
public FrmAddressArea()
|
|||
|
|
{
|
|||
|
|
InitializeComponent();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#region 窗体加载
|
|||
|
|
/// <summary>
|
|||
|
|
/// 窗体加载
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="sender"></param>
|
|||
|
|
/// <param name="e"></param>
|
|||
|
|
private void FrmAddressArea_Load(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
FrmSelectModle = new AddressAreaModel();
|
|||
|
|
//绑定数据
|
|||
|
|
BindData();
|
|||
|
|
LockControl(true);
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region 通用查询
|
|||
|
|
/// <summary>
|
|||
|
|
/// 通用查询
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="table"></param>
|
|||
|
|
public override void LoadListData(DataTable table)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
LoadForm load = new LoadForm();
|
|||
|
|
DevExpress.XtraSplashScreen.SplashScreenManager.ShowForm(load, load.GetType(), false, true, false, 30);
|
|||
|
|
DevExpress.XtraSplashScreen.SplashScreenManager.Default.SetWaitFormDescription("数据查询中,请等待...");
|
|||
|
|
DevExpress.XtraSplashScreen.SplashScreenManager.CloseForm();
|
|||
|
|
|
|||
|
|
list = ConvertHelper<AddressAreaModel>.ConvertToList(table);
|
|||
|
|
BSAddressArea.DataSource = list;
|
|||
|
|
this.BSAddressArea.DataSource = list;
|
|||
|
|
tr_AddressArea.DataSource = list;
|
|||
|
|
tr_AddressArea.ExpandAll();
|
|||
|
|
tr_AddressArea.RefreshDataSource();
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region 绑定数据
|
|||
|
|
/// <summary>
|
|||
|
|
/// 绑定数据
|
|||
|
|
/// </summary>
|
|||
|
|
public void BindData()
|
|||
|
|
{
|
|||
|
|
model = new AddressAreaModel();
|
|||
|
|
string str = Newtonsoft.Json.JsonConvert.SerializeObject(model);
|
|||
|
|
string strResult = WebLockConfig.Instance.WebAddressArea.GetAddressArea(str);
|
|||
|
|
list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<AddressAreaModel>>(strResult);
|
|||
|
|
tr_AddressArea.DataSource = list;
|
|||
|
|
this.tr_AddressArea.Nodes[1].Expanded = false;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region 焦点变化
|
|||
|
|
/// <summary>
|
|||
|
|
/// treelist焦点变化
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="sender"></param>
|
|||
|
|
/// <param name="e"></param>
|
|||
|
|
private void tr_AddressArea_FocusedNodeChanged(object sender, DevExpress.XtraTreeList.FocusedNodeChangedEventArgs e)
|
|||
|
|
{
|
|||
|
|
if (e.Node != null)
|
|||
|
|
{
|
|||
|
|
model = new AddressAreaModel();
|
|||
|
|
model.Add_id = e.Node.GetValue("Add_id").ToString();//获得当前选中主键以此获得实体
|
|||
|
|
string strlist = WebLockConfig.Instance.WebAddressArea.GetAddressArea(Newtonsoft.Json.JsonConvert.SerializeObject(model));
|
|||
|
|
list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<AddressAreaModel>>(strlist);
|
|||
|
|
model = list[0];
|
|||
|
|
Mod();
|
|||
|
|
LockControl(true);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region model 传值
|
|||
|
|
/// <summary>
|
|||
|
|
/// 当前所选节点的实体赋给textbox
|
|||
|
|
/// </summary>
|
|||
|
|
public void Mod()
|
|||
|
|
{
|
|||
|
|
txt_addID.Text = model.Add_id;
|
|||
|
|
txt_addName.Text = model.Add_name;
|
|||
|
|
txt_remark.Text = model.Remark;
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region 锁定控件可操作
|
|||
|
|
/// <summary>
|
|||
|
|
/// 锁定控件可操作 true 锁定 false 解锁
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="bol"></param>
|
|||
|
|
public void LockControl(bool bol)
|
|||
|
|
{
|
|||
|
|
txt_addID.Enabled = !bol;
|
|||
|
|
txt_addName.Enabled = !bol;
|
|||
|
|
txt_remark.Enabled = !bol;
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region 按钮事件
|
|||
|
|
|
|||
|
|
#region 添加按钮
|
|||
|
|
/// <summary>
|
|||
|
|
/// 添加按钮
|
|||
|
|
/// </summary>
|
|||
|
|
public void Add()
|
|||
|
|
{
|
|||
|
|
flg = 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("Confirm"))
|
|||
|
|
{
|
|||
|
|
frmButtonItem["Confirm"].Enabled = true;
|
|||
|
|
}
|
|||
|
|
LockControl(false);
|
|||
|
|
txt_addID.Text = "";
|
|||
|
|
txt_addName.Text = "";
|
|||
|
|
txt_remark.Text = "";
|
|||
|
|
txt_addID.Focus();
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region 删除
|
|||
|
|
/// <summary>
|
|||
|
|
/// 删除
|
|||
|
|
/// </summary>
|
|||
|
|
public void Del()
|
|||
|
|
{
|
|||
|
|
string delid = tr_AddressArea.FocusedNode.GetValue("Add_id").ToString();
|
|||
|
|
if (delid == "")
|
|||
|
|
{
|
|||
|
|
SystemCommon.ShowErrorMessageBox("请选择要删除的节点!");
|
|||
|
|
}
|
|||
|
|
if (SystemCommon.ShowMessageBoxResult("确定删除此信息") == DialogResult.Yes)
|
|||
|
|
{
|
|||
|
|
model = new AddressAreaModel();
|
|||
|
|
model.Add_pid = delid;
|
|||
|
|
string strmodel = Newtonsoft.Json.JsonConvert.SerializeObject(model);
|
|||
|
|
string strlist = WebLockConfig.Instance.WebAddressArea.GetAddressArea(strmodel);
|
|||
|
|
list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<AddressAreaModel>>(strlist);
|
|||
|
|
if (list.Count > 0)
|
|||
|
|
{
|
|||
|
|
SystemCommon.ShowErrorMessageBox("此节点还有下级节点无法删除!");
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
int count = WebLockConfig.Instance.WebAddressArea.execAddressAreaDel(delid);
|
|||
|
|
if (count > 0)
|
|||
|
|
{
|
|||
|
|
SystemCommon.ShowInfoMessageBox("操作成功!");
|
|||
|
|
BindData();
|
|||
|
|
LockControl(true);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
SystemCommon.ShowInfoMessageBox("操作失败!");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region 刷新按钮
|
|||
|
|
/// <summary>
|
|||
|
|
/// 刷新按钮
|
|||
|
|
/// </summary>
|
|||
|
|
public void Refresh()
|
|||
|
|
{
|
|||
|
|
BindData();
|
|||
|
|
|
|||
|
|
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("Confirm"))
|
|||
|
|
{
|
|||
|
|
frmButtonItem["Confirm"].Enabled = false;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region 编辑按钮
|
|||
|
|
/// <summary>
|
|||
|
|
/// 编辑按钮
|
|||
|
|
/// </summary>
|
|||
|
|
public void Edit()
|
|||
|
|
{
|
|||
|
|
tr = tr_AddressArea.FocusedNode;
|
|||
|
|
|
|||
|
|
flg = 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("Confirm"))
|
|||
|
|
{
|
|||
|
|
frmButtonItem["Confirm"].Enabled = true;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
LockControl(false);
|
|||
|
|
Mod();
|
|||
|
|
txt_addID.Enabled = false;
|
|||
|
|
txt_addID.Properties.ReadOnly = true;
|
|||
|
|
txt_addName.SelectAll();
|
|||
|
|
txt_addName.Focus();
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region 确认按钮
|
|||
|
|
/// <summary>
|
|||
|
|
/// 确认按钮
|
|||
|
|
/// </summary>
|
|||
|
|
public void Confirm()
|
|||
|
|
{
|
|||
|
|
if (txt_addName.Enabled == false)
|
|||
|
|
{
|
|||
|
|
SystemCommon.ShowErrorMessageBox("请选择新增或编辑操作!");
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
if (txt_addID.Text.Trim() == "")
|
|||
|
|
{
|
|||
|
|
SystemCommon.ShowErrorMessageBox("编号不能为空!");
|
|||
|
|
txt_addID.Focus();
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
if (txt_addName.Text.Trim() == "")
|
|||
|
|
{
|
|||
|
|
SystemCommon.ShowErrorMessageBox("名称不能为空!");
|
|||
|
|
txt_addName.Focus();
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
Regex reg = new Regex(@"^([a-z]|[A-Z]|[0-9])+$");
|
|||
|
|
if (!reg.IsMatch(this.txt_addID.Text.Trim()))
|
|||
|
|
{
|
|||
|
|
SystemCommon.ShowInfoMessageBox("编号只能输入字母或数字!");
|
|||
|
|
this.txt_addID.Focus();
|
|||
|
|
this.txt_addID.SelectAll();
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
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("Confirm"))
|
|||
|
|
{
|
|||
|
|
frmButtonItem["Confirm"].Enabled = false;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (flg == 0)//新增判断所输入编号数据库是否存在
|
|||
|
|
{
|
|||
|
|
AddressAreaModel _mo = new AddressAreaModel();
|
|||
|
|
|
|||
|
|
_mo.Add_id = txt_addID.Text.Trim();
|
|||
|
|
|
|||
|
|
List<AddressAreaModel> _list = new List<AddressAreaModel>();
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
string str_model = Newtonsoft.Json.JsonConvert.SerializeObject(_mo);
|
|||
|
|
string str_list_model = WebLockConfig.Instance.WebAddressArea.GetAddressArea(str_model);
|
|||
|
|
_list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<AddressAreaModel>>(str_list_model); ;
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
SystemCommon.ShowErrorMessageBox("网络连接错误!");
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
if (_list.Count > 0)
|
|||
|
|
{
|
|||
|
|
SystemCommon.ShowErrorMessageBox("该编号已经存在!请重新输入");
|
|||
|
|
txt_addID.SelectAll();
|
|||
|
|
txt_addID.Focus();
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
model.Add_id = txt_addID.Text.Trim();
|
|||
|
|
model.Add_name = txt_addName.Text.Trim();
|
|||
|
|
model.Remark = txt_remark.Text.Trim();
|
|||
|
|
|
|||
|
|
string strmodel = Newtonsoft.Json.JsonConvert.SerializeObject(model);
|
|||
|
|
int count = WebLockConfig.Instance.WebAddressArea.execAddressAreaAddUpdate(strmodel, flg);
|
|||
|
|
if (count > 0)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
SystemCommon.ShowInfoMessageBox("操作成功!");
|
|||
|
|
LockControl(true);
|
|||
|
|
BindData();
|
|||
|
|
|
|||
|
|
if (tr != null)
|
|||
|
|
{
|
|||
|
|
tr_AddressArea.FocusedNode = tr;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
SystemCommon.ShowInfoMessageBox("操作失败!");
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region 导入
|
|||
|
|
/// <summary>
|
|||
|
|
/// 导入
|
|||
|
|
/// </summary>
|
|||
|
|
public void Import()
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region 导出
|
|||
|
|
/// <summary>
|
|||
|
|
/// 导出
|
|||
|
|
/// </summary>
|
|||
|
|
public void Export()
|
|||
|
|
{
|
|||
|
|
SaveFileDialog fileDialog = new SaveFileDialog();
|
|||
|
|
fileDialog.Title = "导出Excel";
|
|||
|
|
fileDialog.Filter = "Excel文件(*.xls)|*.xls";
|
|||
|
|
DialogResult dialogResult = fileDialog.ShowDialog(this);
|
|||
|
|
if (dialogResult == DialogResult.OK)
|
|||
|
|
{
|
|||
|
|
DevExpress.XtraPrinting.XlsExportOptions options = new DevExpress.XtraPrinting.XlsExportOptions();
|
|||
|
|
this.tr_AddressArea.ExportToXls(fileDialog.FileName);
|
|||
|
|
DevExpress.XtraEditors.XtraMessageBox.Show("保存成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region 保存导入
|
|||
|
|
/// <summary>
|
|||
|
|
/// 保存导入
|
|||
|
|
/// </summary>
|
|||
|
|
public void SaveImport()
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#endregion
|
|||
|
|
}
|
|||
|
|
}
|