652 lines
21 KiB
C#
652 lines
21 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.Model.SystemManage;
|
|
using WMS.Common;
|
|
using DevExpress.XtraEditors;
|
|
using System.Collections;
|
|
using System.Threading;
|
|
using WMS.Business;
|
|
using WMS.Business.SystemManage;
|
|
using WMS.Business.Base;
|
|
using WMS.Frm;
|
|
|
|
namespace WMS.FrmBaseData
|
|
{
|
|
/// <summary>
|
|
/// 窗体:商品分类
|
|
/// </summary>
|
|
public partial class FrmGoodsType : FormBase
|
|
{
|
|
#region 变量
|
|
//字典表实体集合
|
|
List<DictionaryTabModel> listDictionaryTabModel = null;
|
|
|
|
//商品分类实体集合
|
|
List<GoodsTypeModel> listGoodsType = null;
|
|
|
|
//商品分类编号
|
|
static string strGoodsTypeID = string.Empty;
|
|
|
|
//操作标志 0新增 1修改 2删除
|
|
static int iFlag;
|
|
private bool importing = false;
|
|
|
|
private int tempID;
|
|
#endregion
|
|
|
|
#region 构造方法
|
|
/// <summary>
|
|
/// 构造方法
|
|
/// </summary>
|
|
public FrmGoodsType()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
#endregion
|
|
|
|
#region 窗体初始化
|
|
/// <summary>
|
|
/// 窗体初始化
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void FrmGoodsType_Load(object sender, EventArgs e)
|
|
{
|
|
FrmSelectModle = new GoodsTypeModel();//用于查询按钮
|
|
//frmButtonItem["删除"].Enabled = false;
|
|
//数据绑定
|
|
DataBind();
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region 数据绑定
|
|
/// <summary>
|
|
/// 数据绑定
|
|
/// </summary>
|
|
private void DataBind()
|
|
{
|
|
if (!importing)
|
|
{
|
|
//错误信息
|
|
string strErrorText = "";
|
|
//从字典表获取商品分类状态
|
|
|
|
new Thread(delegate()
|
|
{
|
|
try
|
|
{
|
|
listDictionaryTabModel = IBussFactory<BussDictionaryTab>.Instance().GetDictionaryTab("good_type_status");
|
|
}
|
|
catch (Exception)
|
|
{
|
|
SystemCommon.ShowInfoMessageBox("未知错误,请检查网络连接!如仍无法解决问题请联系我们!");
|
|
}
|
|
|
|
this.Invoke(new MethodInvoker(delegate()
|
|
{
|
|
dictionaryTabModelBindingSource.DataSource = listDictionaryTabModel;
|
|
|
|
GoodsTypeModel model = new GoodsTypeModel();
|
|
listGoodsType = IBussFactory<BussGoodsType>.Instance().GetGoodsTypeList(model);
|
|
|
|
goodsTypeModelBindingSource.DataSource = listGoodsType;
|
|
treeListCustom1.ExpandAll();
|
|
|
|
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("SaveImport")) { frmButtonItem["SaveImport"].Enabled = false; }
|
|
}));
|
|
|
|
}).Start();
|
|
|
|
}
|
|
else {
|
|
goodsTypeModelBindingSource.DataSource = listGoodsType;
|
|
treeListCustom1.ExpandAll();
|
|
if (frmButtonItem.ContainsKey("Edit"))
|
|
{
|
|
frmButtonItem["Edit"].Enabled = true;
|
|
}
|
|
if (frmButtonItem.ContainsKey("Del"))
|
|
{
|
|
frmButtonItem["Del"].Enabled = true;
|
|
}
|
|
if (frmButtonItem.ContainsKey("Save"))
|
|
{
|
|
frmButtonItem["Save"].Enabled = false;
|
|
}
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region 按钮方法
|
|
/// <summary>
|
|
/// 清空
|
|
/// </summary>
|
|
public override void Clear()
|
|
{
|
|
//分类编号
|
|
strGoodsTypeID = "";
|
|
//分类名称
|
|
txtGoodsTypeName.Text = "";
|
|
//分类简称
|
|
txtGoodsTypeShort.Text = "";
|
|
//助记码
|
|
txtPINYIN.Text = "";
|
|
//备注
|
|
txtRemark.Text = "";
|
|
//排序
|
|
txtSort.Text = "";
|
|
//上级分类
|
|
tlueGoodsType.EditValue = null;
|
|
//状态
|
|
lueSTATUS.EditValue = null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 保存方法
|
|
/// </summary>
|
|
public override void Save()
|
|
{
|
|
if (Validation()) {
|
|
GoodsTypeModel model = GetGoodsTypeModel();
|
|
string errText=string.Empty;
|
|
|
|
string strGoodsTypeModel = Newtonsoft.Json.JsonConvert.SerializeObject(model);
|
|
if (importing)
|
|
{
|
|
foreach (GoodsTypeModel goodsType in listGoodsType)
|
|
{
|
|
if(goodsType.TEMPID == tempID){
|
|
goodsType.GOODS_TYPE_NAME = txtGoodsTypeName.Text;
|
|
goodsType.GOODS_TYPE_SHORT_NAME = txtGoodsTypeShort.Text;
|
|
goodsType.PY_NAME = txtPINYIN.Text;
|
|
if (!string.IsNullOrEmpty(txtSort.Text))
|
|
{
|
|
goodsType.SORT = decimal.Parse(txtSort.Text);
|
|
}
|
|
goodsType.STATUS = lueSTATUS.EditValue.ToString();
|
|
goodsType.REMARK = txtRemark.Text;
|
|
if (tlueGoodsType.EditValue != null)
|
|
{
|
|
goodsType.PARENT_ID = tlueGoodsType.EditValue.ToString();
|
|
}
|
|
}
|
|
}
|
|
|
|
DataBind();
|
|
}
|
|
else if (iFlag == 0)
|
|
{
|
|
if (IBussFactory<BussGoodsType>.Instance().AddGoodsTypeInfo(model))
|
|
{
|
|
SystemCommon.ShowInfoMessageBox("操作成功!");
|
|
DataBind();
|
|
}
|
|
else
|
|
{
|
|
SystemCommon.ShowErrorMessageBox(errText);
|
|
}
|
|
}
|
|
else if (iFlag == 1)
|
|
{
|
|
if (IBussFactory<BussGoodsType>.Instance().UpdateGoodsTypeInfo(model))
|
|
{
|
|
SystemCommon.ShowInfoMessageBox("操作成功!");
|
|
DataBind();
|
|
}
|
|
else
|
|
{
|
|
SystemCommon.ShowErrorMessageBox(errText);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 增加
|
|
/// </summary>
|
|
public override void Add()
|
|
{
|
|
iFlag = 0;
|
|
Clear();
|
|
lueSTATUS.EditValue = "1";
|
|
tlueGoodsType.EditValue = treeListCustom1.FocusedNode.GetValue("PARENT_ID").ToString();
|
|
//tlueGoodsType.EditValue = "-1";
|
|
//lueSTATUS.Properties.KeyValue = "1";
|
|
//lueSTATUS.Text = "可用";
|
|
//lueSTATUS.ClosePopup();
|
|
|
|
foreach (Control item in panelControl1.Controls)
|
|
{
|
|
item.Enabled = true;
|
|
}
|
|
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 Del()
|
|
{
|
|
iFlag = 2;
|
|
string errText = string.Empty;
|
|
|
|
if (strGoodsTypeID == "-1" || strGoodsTypeID == "SPFL1101" || strGoodsTypeID == "SPFL1102" || strGoodsTypeID == "SPFL1103"
|
|
|| strGoodsTypeID == "SPFL1104" || strGoodsTypeID == "SPFL1105" || strGoodsTypeID == "SPFL1106" || strGoodsTypeID == "SPFL1107" || strGoodsTypeID == "SPFL1108")
|
|
{
|
|
SystemCommon.ShowInfoMessageBox("该分类为系统内置分类不能删除!");
|
|
return;
|
|
}
|
|
|
|
//查询该分类下有无子分类,若有,禁止删除
|
|
GoodsTypeModel queryModel = new GoodsTypeModel();
|
|
queryModel.PARENT_ID = strGoodsTypeID;
|
|
List<GoodsTypeModel> queryList = IBussFactory<BussGoodsType>.Instance().GetGoodsTypeList(queryModel);
|
|
if (queryList.Count > 0) {
|
|
SystemCommon.ShowInfoMessageBox("该分类下有子分类,请先删除其自分类!");
|
|
return;
|
|
}
|
|
|
|
if (XtraMessageBox.Show("是否确定删除此商品分类?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
|
|
{
|
|
if (!importing)
|
|
{
|
|
if (IBussFactory<BussGoodsType>.Instance().DeleteGoodsTypeInfo(strGoodsTypeID))
|
|
{
|
|
SystemCommon.ShowInfoMessageBox("操作成功!");
|
|
DataBind();
|
|
}
|
|
else
|
|
{
|
|
SystemCommon.ShowErrorMessageBox(errText);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
listGoodsType.RemoveAll(p => p.GOODS_TYPE_ID == strGoodsTypeID && p.GOODS_TYPE_NAME == txtGoodsTypeName.Text);
|
|
DataBind();
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 刷新
|
|
/// </summary>
|
|
public override void Refresh()
|
|
{
|
|
if (frmButtonItem.ContainsKey("Save") && frmButtonItem["Save"].Enabled == true && DialogResult.Yes != SystemCommon.ShowMessageBoxResult("确定放弃正在编辑的数据?"))
|
|
{
|
|
return;
|
|
}
|
|
importing = false;
|
|
DataBind();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 修改
|
|
/// </summary>
|
|
public override void Edit()
|
|
{
|
|
if (!frmButtonItem.ContainsKey("Edit"))
|
|
{
|
|
return;
|
|
}
|
|
else if (frmButtonItem["Edit"].Enabled == false)
|
|
{
|
|
return;
|
|
}
|
|
|
|
iFlag = 1;
|
|
foreach (Control item in panelControl1.Controls)
|
|
{
|
|
item.Enabled = true;
|
|
}
|
|
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;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 验证
|
|
/// <summary>
|
|
/// 验证
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private bool Validation()
|
|
{
|
|
//商品分类名称
|
|
if (txtGoodsTypeName.Text == "")
|
|
{
|
|
SystemCommon.ShowErrorMessageBox("请输入商品分类名称!");
|
|
txtGoodsTypeName.Focus();
|
|
return false;
|
|
}
|
|
////商品分类简称
|
|
//if (txtGoodsTypeShort.Text == "")
|
|
//{
|
|
// SystemCommon.ShowErrorMessageBox("请输入商品分类简称!");
|
|
// txtGoodsTypeShort.Focus();
|
|
// return false;
|
|
//}
|
|
|
|
return true;
|
|
}
|
|
#endregion
|
|
|
|
#region GoodsTypeModel 赋值
|
|
/// <summary>
|
|
/// GoodsTypeModel 赋值
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private GoodsTypeModel GetGoodsTypeModel()
|
|
{
|
|
GoodsTypeModel model = new GoodsTypeModel();
|
|
if (iFlag == 1)
|
|
{
|
|
model.GOODS_TYPE_ID = strGoodsTypeID;
|
|
}
|
|
else
|
|
{
|
|
strGoodsTypeID = "";
|
|
}
|
|
model.GOODS_TYPE_NAME = txtGoodsTypeName.Text;
|
|
model.GOODS_TYPE_SHORT_NAME = txtGoodsTypeShort.Text;
|
|
model.PY_NAME = txtPINYIN.Text;
|
|
if (!string.IsNullOrEmpty(txtSort.Text)) {
|
|
model.SORT = decimal.Parse(txtSort.Text);
|
|
}
|
|
model.STATUS = lueSTATUS.EditValue.ToString();
|
|
model.REMARK = txtRemark.Text;
|
|
if (tlueGoodsType.EditValue != null) {
|
|
model.PARENT_ID = tlueGoodsType.EditValue.ToString();
|
|
}
|
|
return model;
|
|
}
|
|
#endregion
|
|
|
|
#region 选择树节点事件
|
|
/// <summary>
|
|
/// 选择树节点事件
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void treeListCustom1_FocusedNodeChanged(object sender, DevExpress.XtraTreeList.FocusedNodeChangedEventArgs e)
|
|
{
|
|
if (e.Node == null)
|
|
return;
|
|
|
|
if (e.Node["GOODS_TYPE_ID"] != null)
|
|
{
|
|
strGoodsTypeID = e.Node["GOODS_TYPE_ID"].ToString();
|
|
}
|
|
|
|
if (e.Node["TEMPID"] != null)
|
|
{
|
|
tempID = (int)e.Node["TEMPID"];
|
|
}
|
|
|
|
if (e.Node["GOODS_TYPE_NAME"] != null)
|
|
{
|
|
txtGoodsTypeName.Text = e.Node["GOODS_TYPE_NAME"].ToString();
|
|
}
|
|
|
|
if (e.Node["GOODS_TYPE_SHORT_NAME"] != null)
|
|
{
|
|
txtGoodsTypeShort.Text = e.Node["GOODS_TYPE_SHORT_NAME"].ToString();
|
|
}
|
|
|
|
if (e.Node["PARENT_ID"] != null)
|
|
{
|
|
tlueGoodsType.EditValue = e.Node["PARENT_ID"].ToString();
|
|
}
|
|
|
|
if (e.Node["PY_NAME"] != null)
|
|
{
|
|
txtPINYIN.Text = e.Node["PY_NAME"].ToString();
|
|
}
|
|
|
|
if (e.Node["REMARK"] != null)
|
|
{
|
|
txtRemark.Text = e.Node["REMARK"].ToString();
|
|
}
|
|
|
|
if (e.Node["SORT"] != null && e.Node["SORT"].ToString() != "")
|
|
{
|
|
txtSort.Text = e.Node["SORT"].ToString().Split('.')[0];
|
|
}
|
|
|
|
if (e.Node["STATUS"] != null)
|
|
{
|
|
lueSTATUS.EditValue = e.Node["STATUS"].ToString();
|
|
}
|
|
|
|
foreach (Control item in panelControl1.Controls)
|
|
{
|
|
item.Enabled = false;
|
|
}
|
|
|
|
if (!importing)
|
|
{
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// 导入
|
|
/// </summary>
|
|
public void Import()
|
|
{
|
|
|
|
OpenFileDialog fileDialog = new OpenFileDialog();
|
|
fileDialog.Title = "导入商品资料";
|
|
fileDialog.Filter = "Excel文件(*.xls;*.xlsx)|*.xls;*.xlsx";
|
|
DialogResult dialogResult = fileDialog.ShowDialog(this);
|
|
if (dialogResult == DialogResult.OK)
|
|
{
|
|
|
|
Hashtable ht = new Hashtable();
|
|
|
|
//ht.Add("GOODS_TYPE_ID", "商品代码");
|
|
//ht.Add("GOODS_TYPE_NAME", "商品名称");
|
|
|
|
List<GoodsTypeModel> tempList = NPOIHelper<GoodsTypeModel>.Import(fileDialog, ht);
|
|
for (int i = 0; i < tempList.Count; i++)
|
|
{
|
|
tempList[i].TEMPID = i;
|
|
if (string.IsNullOrEmpty(tempList[i].STATUS)) {
|
|
tempList[i].STATUS = "1";
|
|
}
|
|
if (string.IsNullOrEmpty(tempList[i].STATUS))
|
|
{
|
|
|
|
tempList[i].STATUS = "1";
|
|
tempList[i].GOODS_TYPE_ID = "-1";
|
|
}
|
|
}
|
|
|
|
if (tempList == null)
|
|
{
|
|
DataBind();
|
|
return;
|
|
}
|
|
|
|
if (importing)
|
|
{
|
|
listGoodsType.AddRange(tempList);
|
|
}
|
|
else
|
|
{
|
|
listGoodsType = tempList;
|
|
}
|
|
|
|
//if (listGoodsType == null)
|
|
//{
|
|
// DataBind();
|
|
// return;
|
|
//}
|
|
|
|
if (frmButtonItem.ContainsKey("Add")) { frmButtonItem["Add"].Enabled = false; }
|
|
if (frmButtonItem.ContainsKey("SaveImport")) { frmButtonItem["SaveImport"].Enabled = true; }
|
|
importing = true;
|
|
|
|
DataBind();
|
|
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 保存
|
|
/// </summary>
|
|
public void SaveImport()
|
|
{
|
|
//将list存入数据库
|
|
if (listGoodsType != null && listGoodsType.Count > 0)
|
|
{
|
|
|
|
string errText = string.Empty;
|
|
List<int> errorIndex = new List<int>();
|
|
int hadNum = 0;
|
|
int lengthNum = 0;
|
|
string error = string.Empty;
|
|
|
|
try
|
|
{
|
|
errorIndex = IBussFactory<BussGoodsType>.Instance().AddGoodsTypeList(listGoodsType, ref hadNum, ref lengthNum, ref error);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
SystemCommon.ShowErrorMessageBox("未知错误,请检查网络连接!如仍无法解决问题请联系我们!");
|
|
}
|
|
|
|
if (errorIndex.Count == 0)
|
|
{
|
|
SystemCommon.ShowInfoMessageBox("所有记录已保存成功");
|
|
Refresh();
|
|
}
|
|
else
|
|
{
|
|
List<GoodsTypeModel> tempList = new List<GoodsTypeModel>();
|
|
for (int i = errorIndex.Count - 1; i >= 0; i--)
|
|
{
|
|
tempList.Add(listGoodsType[i]);
|
|
}
|
|
listGoodsType = tempList;
|
|
DataBind();
|
|
|
|
string fileName = @"D:\WMS\保存导入商品分类错误日志" + System.DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt";
|
|
SystemCommon.WriteFile(fileName, error);///写文件
|
|
|
|
/*错误提示*/
|
|
string info = string.Empty;
|
|
if (errorIndex.Count > (hadNum + lengthNum))
|
|
{
|
|
info += ((errorIndex.Count - hadNum - lengthNum) + "个商品分类导入时遇到未知错误,");
|
|
}
|
|
if (hadNum > 0)
|
|
{
|
|
info += (hadNum + "个商品分类编号已存在,");
|
|
}
|
|
if (lengthNum > 0)
|
|
{
|
|
info += (lengthNum + "条商品分类记录数据长度过长,");
|
|
}
|
|
info += "日志已写入" + fileName + ",未出错记录已写入数据库并从窗体中移除。";
|
|
SystemCommon.ShowErrorMessageBox(info);
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 导出
|
|
/// </summary>
|
|
public void Export()
|
|
{
|
|
treeListCustom1.ShowExportDialog();
|
|
SystemCommon.ShowErrorMessageBox("导出完成");
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查询
|
|
/// </summary>
|
|
public override void Search()
|
|
{
|
|
FrmSelect frm = new FrmSelect(this.FrmSelectModle);
|
|
if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
|
|
{
|
|
this.LoadListData(frm.SelectData);
|
|
}
|
|
}
|
|
}
|
|
}
|