BaoKai_202508_Wms_Jingwang_.../WMS.FrmBaseData/FrmPalletHandle.cs
2025-08-24 21:52:42 +08:00

290 lines
8.9 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 System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WMS.Frm.Base;
using WMS.Common;
using WMS.Model.Base;
using WMS.Model.SystemManage;
using System.Text.RegularExpressions;
using WMS.Business;
using WMS.Business.Base;
namespace WMS.FrmBaseData
{
public partial class FrmPalletHandle : FormBase
{
#region
//获得前一界面 双击或点击修改的 行数据
public PalletModel SourceModel;
int workflag;
#endregion
#region
//构造函数传参 0新增 1修改
public FrmPalletHandle(int flag, PalletModel model)
{
SourceModel = model;
workflag = flag;
InitializeComponent();
FormValue();
}
//窗体加载
private void FrmPalletHandle_Load(object sender, EventArgs e)
{
//绑定实体数据
bgsData.DataSource = SourceModel;
//加载类型下拉列表 Model Pallet_Type (ID)
lkpPalletType.LoadData();
}
#endregion
#region
#region
private void btnAccept_Click(object sender, EventArgs e)
{
//数据验证
if (!Grid_ValidatRow())
{
return;
}
//当为新增时 进行验证是否存在相同编号
if (workflag == 0)
{
if (!ExistPalletID())
{
return;
}
}
//确定事件方法
btnSave();
}
#endregion
#region
private void btnClose_Click(object sender, EventArgs e)
{
DialogResult dr = MessageBox.Show("是否要关闭此窗体", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
if (dr == DialogResult.Yes)
this.Close();
}
#endregion
#region leave
private void txtPalletLong_Leave(object sender, EventArgs e)
{
//绑定体积
CheckConst();
}
private void txtPalletWidth_Leave(object sender, EventArgs e)
{
CheckConst();
}
private void txtPalletHeight_Leave(object sender, EventArgs e)
{
CheckConst();
}
#endregion
#region decimal类型文本框 click事件
private void txtPalletLong_Click(object sender, EventArgs e)
{
//设置光标起始位置
this.txtPalletLong.SelectionStart = 0;
this.txtPalletLong.SelectAll();
}
private void txtPalletWidth_Click(object sender, EventArgs e)
{
this.txtPalletWidth.SelectionStart = 0;
this.txtPalletWidth.SelectAll();
}
private void txtPalletHeight_Click(object sender, EventArgs e)
{
this.txtPalletHeight.SelectionStart = 0;
this.txtPalletHeight.SelectAll();
}
private void txtVolume_Click(object sender, EventArgs e)
{
this.txtPalletLong.SelectionStart = 0;
}
private void txtBearWeight_Click(object sender, EventArgs e)
{
this.txtBearWeight.SelectionStart = 0;
this.txtBearWeight.SelectAll();
}
#endregion
#endregion
#region
#region
//窗体传值判断0新增 1修改 方法
private void FormValue()
{
//当为新增时 将版本号带出
if (workflag == 0)
{
SourceModel.VERSION = "version1.0";
}
//当为修改时 将编号设置为不可更改
if (workflag == 1)
{
this.txtPalletID.Properties.ReadOnly = true;
}
}
#endregion
#region
//数据验证
public bool Grid_ValidatRow()
{
#region
//托盘编号验证
if ((this.txtPalletID.Text.Trim() == "") || (txtPalletID.Text.Trim() == null))
{
SystemCommon.ShowInfoMessageBox("请输入托盘编号");
txtPalletID.Focus();
return false;
}
if (!string.IsNullOrEmpty(this.txtPalletID.Text.Trim()))
{
Regex reg = new Regex(@"^([a-z]|[A-Z]|[0-9])+$");
if (!reg.IsMatch(this.txtPalletID.Text.Trim()))
{
SystemCommon.ShowInfoMessageBox("托盘编号只能输入字母或数字!");
txtPalletID.Focus();
return false;
}
}
#endregion
//拼音简称验证
if (!string.IsNullOrEmpty(this.txtPYName.Text.Trim()))
{
Regex reg = new Regex(@"^([a-z]|[A-Z]|[0-9])+$");
if (!reg.IsMatch(this.txtPYName.Text.Trim()))
{
SystemCommon.ShowInfoMessageBox("拼音简称只能输入字母或数字!");
txtPYName.Focus();
return false;
}
}
//托盘名称验证
if ((this.txtPalletName.Text.Trim() == "") || (this.txtPalletName.Text.Trim() == null))
{
SystemCommon.ShowInfoMessageBox("请输入托盘名称!");
txtPalletName.Focus();
return false;
}
//托盘类型验证
if (string.IsNullOrEmpty(this.lkpPalletType.EditValue.ToString()))
{
SystemCommon.ShowInfoMessageBox("请选择托盘类型!");
this.lkpPalletType.Focus();
return false;
}
//宽度不能长于长度验证
if (!string.IsNullOrEmpty(this.txtPalletLong.Text.Trim()) && !string.IsNullOrEmpty(this.txtPalletWidth.Text.Trim()))
{
if (Convert.ToDecimal(this.txtPalletLong.Text.Trim()) < Convert.ToDecimal(this.txtPalletWidth.Text.Trim()))
{
SystemCommon.ShowInfoMessageBox("宽度不能大于长度,请重新输入!");
this.txtPalletWidth.Focus();
return false;
}
}
return true;
}
#endregion
#region
//验证是否存在相同编号
private bool ExistPalletID()
{
PalletModel strmodel = Newtonsoft.Json.JsonConvert.DeserializeObject<PalletModel>(this.txtPalletID.Text.Trim());
List<PalletModel> list = IBussFactory<BussPallet>.Instance().GetPalletList(strmodel);
foreach (PalletModel model in list)
{
if (model.PALLET_ID == this.txtPalletID.Text.Trim())
{
SystemCommon.ShowInfoMessageBox("已存在相同编号,请重新输入");
this.txtPalletID.Text = string.Empty;
this.txtPalletID.Focus();
return false;
}
}
return true;
}
#endregion
#region
// 确认按钮方法 0新增 1修改
private void btnSave()
{
if (workflag == 0 || workflag == 1)
{
List <BaseCtlGoodsModel> ass = (List<BaseCtlGoodsModel>)bgsData.DataSource;
string errtex= IBussFactory<BussBaseCtlGoods>.Instance().Operator(ass, workflag);
if (!string.IsNullOrEmpty(errtex))
{
SystemCommon.ShowInfoMessageBox("操作失败!");
}
else
{
SystemCommon.ShowInfoMessageBox("操作成功!");
this.Close();
}
}
}
#endregion
#region
//计算体积
decimal volum, volumRound;
public void CheckConst()
{
string Plong = this.txtPalletLong.Text;
string Pwidth = this.txtPalletWidth.Text;
string Pheigth = this.txtPalletHeight.Text;
if (!string.IsNullOrEmpty(Plong) && !string.IsNullOrEmpty(Pwidth) && !string.IsNullOrEmpty(Pheigth))
{
volum = Convert.ToDecimal(Plong) * Convert.ToDecimal(Pwidth) * Convert.ToDecimal(Pheigth);
volumRound = Math.Round(volum, 2);
}
this.txtVolume.Text = volumRound.ToString();
//bingdingSource 绑定体积 (勿忘)
SourceModel.VOLUME = Convert.ToDecimal(this.txtVolume.Text);
}
#endregion
#endregion
}
}