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 CoreFS.CA06;using Pur.Entity;
using Pur.Entity.configureEntity;
using Core.Mes.Client.Comm.Control;
using com.hnshituo.pur.vo;
using Core.Mes.Client.Comm.Tool;
using Pur.Pop_upWindow;
namespace Pur.configure
{
public partial class FrmUoms : FrmPmsBase
{
public FrmUoms()
{
InitializeComponent();
}
public override void ToolBar_Click(object sender, string ToolbarKey)
{
switch (ToolbarKey)
{
case "doQuery":
try
{
this.Cursor = Cursors.WaitCursor;
get_PurUoms();
}
finally
{
this.Cursor = Cursors.Default;
}
break;
case "doAdd":
add_PurUoms();
break;
case "doModify":
upd_PurUoms();
break;
case "doDelete":
del_PurUoms();
break;
case "Close":
this.Close();
break;
}
}
///
/// 查询采购单位
///
///
public void get_PurUoms()
{
PurUomsEntity UomsEntity = new PurUomsEntity();
UomsEntity.WeightUnitCode = txt_WEIGHT_UNIT_CODE_QUERY.Text.Trim();//库存单位编码
UomsEntity.UomCode = txt_UOM_CODE_QUERY.Text.Trim();//采购单位编码
UomsEntity.WeightUnit = txt_WEIGHT_UNIT_QUERY.Text.Trim();//库存单位
UomsEntity.UomName = txt_UOM_NAME_QUERY.Text.Trim();//采购单位名称
UomsEntity.Validflag = "1";
DataTable dt = this.execute("com.hnshituo.pur.configure.service.UomsService", "get_PurUoms", new object[] { UomsEntity });
//按创建时间降序
if (dt.Rows.Count > 0)
{
dt.DefaultView.Sort = "CREATETIME DESC";
dt = dt.DefaultView.ToTable();
}
GridHelper.CopyDataToDatatable(ref dt, ref dataTable1, true);//绑定物料分类表
}
///
/// 增加采购单位
///
///
public void add_PurUoms()
{
PurUomsEntity UomsEntity = new PurUomsEntity();
UomsEntity.UomName = txt_UOM_NAME.Text;//采购单位名称
UomsEntity.WeightUnit = txt_WEIGHT_UNIT.Text;//库存单位
UomsEntity.Validflag = "1";
int num = this.execute("com.hnshituo.pur.configure.service.UomsService", "count", new object[] { UomsEntity });
if (num>0)
{
MessageUtil.ShowTips("添加失败:因为已存在相同的采购单位和库存单位");
return;
}
if (MessageUtil.ShowYesNoAndQuestion("是否确定添加?") == DialogResult.No && ValidInput())
{
return;
}
UomsEntity.UomConefficient = txt_UOM_CONEFFICIENT.Text.Trim() == "" ? 0 : double.Parse(txt_UOM_CONEFFICIENT.Text);//转换系数
UomsEntity.WeightUnitCode = txt_WEIGHT_UNIT_CODE.Text;//库存单位编码
//UomsEntity.UomCode = txt_UOM_CODE.Text;//txt_UOM_CODE.Text;//采购单位编码
UomsEntity.UomCode = this.execute("com.hnshituo.pur.utils.service.UtilsService", "getOddNumber", new object[] { "PUR_Uoms", "Uom_Code", txt_WEIGHT_UNIT_CODE.Text + "-", "2" });
UomsEntity.CreateName = UserInfo.GetUserName();
UomsEntity.CreateUserid = UserInfo.GetUserID();
CoreResult crt = this.execute("com.hnshituo.pur.configure.service.UomsService", "doInsert", new object[] { UomsEntity});
if (crt.Resultcode != 0)
{
MessageUtil.ShowTips("添加失败 " + crt.Resultmsg);
return;
}
MessageUtil.ShowTips("添加成功!");
get_PurUoms();//查询采购单位
ConfigureClassCommon.doActiveSelRow(ultraGrid1, "UomCode", UomsEntity.UomCode);//激活当前行
}
///
/// 修改采购单位
///
///
public void upd_PurUoms()
{
if (MessageUtil.ShowYesNoAndQuestion("是否确定修改?") == DialogResult.No && ValidInput())
{
return;
}
if (ultraGrid1.ActiveRow != null)
{
PurUomsEntity UomsEntity = new PurUomsEntity();
UomsEntity.UomConefficient = txt_UOM_CONEFFICIENT.Text.Trim() == "" ? 0 : double.Parse(txt_UOM_CONEFFICIENT.Text);//转换系数
UomsEntity.WeightUnitCode = txt_WEIGHT_UNIT_CODE.Text;//库存单位编码
UomsEntity.UomCode = ultraGrid1.ActiveRow.Cells["UOMCODE"].Value.ToString();//采购单位编码
UomsEntity.WeightUnit = txt_WEIGHT_UNIT.Text;//库存单位
UomsEntity.UomName = txt_UOM_NAME.Text;//采购单位名称
UomsEntity.UpdateName = UserInfo.GetUserName();
UomsEntity.UpdateUserid = UserInfo.GetUserID();
UomsEntity.Validflag = "1";
CoreResult crt = this.execute("com.hnshituo.pur.configure.service.UomsService", "doUpdate", new object[] { UomsEntity});
if (crt.Resultcode != 0)
{
MessageUtil.ShowTips("修改失败 " + crt.Resultmsg);
return;
}
MessageUtil.ShowTips("修改成功!");
get_PurUoms();//查询采购单位
ConfigureClassCommon.doActiveSelRow(ultraGrid1, "UomCode", UomsEntity.UomCode);//激活当前行
}
else
{
MessageUtil.ShowTips("请选择一条采购单位");
return;
}
}
///
/// 删除采购单位
///
///
public void del_PurUoms()
{
if (MessageUtil.ShowYesNoAndQuestion("是否确定删除?") == DialogResult.No)
{
return;
}
if (ultraGrid1.ActiveRow != null)
{
PurUomsEntity UomsEntity = new PurUomsEntity();
UomsEntity.UomCode = ultraGrid1.ActiveRow.Cells["UOMCODE"].Value.ToString();//采购单位编码
UomsEntity.DeleteTime = System.DateTime.Now;
UomsEntity.DeleteName = UserInfo.GetUserName();
UomsEntity.DeleteUserid = UserInfo.GetUserID();
UomsEntity.Validflag = "0";
CoreResult crt = this.execute("com.hnshituo.pur.configure.service.UomsService", "doUpdate", new object[] { UomsEntity});
if (crt.Resultcode != 0)
{
MessageUtil.ShowTips("删除失败 " + crt.Resultmsg);
return;
}
MessageUtil.ShowTips("删除成功!");
get_PurUoms();//查询采购单位
}
else
{
MessageUtil.ShowTips("请选择一条采购单位");
return;
}
}
///
/// 验证必填项
///
///
private bool ValidInput()
{
if (string.IsNullOrEmpty(txt_UOM_NAME.Text.Trim()))
{
MessageBox.Show("请输入采购单位名称!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return false;
}
//if (string.IsNullOrEmpty(txt_UOM_CODE.Text.Trim()))
//{
// MessageBox.Show("请输入采购单位编号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
// return false;
//}
if (string.IsNullOrEmpty(txt_WEIGHT_UNIT.Text.Trim()))
{
MessageBox.Show("请输入采购单位名称!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return false;
}
if (string.IsNullOrEmpty(txt_WEIGHT_UNIT_CODE.Text.Trim()))
{
MessageBox.Show("请输入采购单位编号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return false;
}
if (string.IsNullOrEmpty(txt_UOM_CONEFFICIENT.Text.Trim()))
{
MessageBox.Show("请输入转换系数!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return false;
}
else if (!StringUtil.IsNumber(txt_UOM_CONEFFICIENT.Text.Trim()))
{
MessageBox.Show("转换系数必须为数字!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return false;
}
return true;
}
///
/// 激活grid列表
///
///
///
private void ultraGrid1_AfterRowActivate(object sender, EventArgs e)
{
txt_UOM_CONEFFICIENT.Text = ultraGrid1.ActiveRow.Cells["UOMCONEFFICIENT"].Value.ToString();
txt_WEIGHT_UNIT_CODE.Text = ultraGrid1.ActiveRow.Cells["WEIGHTUNITCODE"].Value.ToString();
txt_UOM_CODE.Text = ultraGrid1.ActiveRow.Cells["UOMCODE"].Value.ToString();
txt_WEIGHT_UNIT.Text = ultraGrid1.ActiveRow.Cells["WEIGHTUNIT"].Value.ToString();
txt_UOM_NAME.Text = ultraGrid1.ActiveRow.Cells["UOMNAME"].Value.ToString();
}
private void txt_WEIGHT_UNIT_CODE_EditorButtonClick(object sender, Infragistics.Win.UltraWinEditors.EditorButtonEventArgs e)
{
FrmPopItemWeight frm = new FrmPopItemWeight(this.ob);
frm.ShowDialog();
if (!String.IsNullOrEmpty(frm.QstrWeightCode))
{
txt_WEIGHT_UNIT_CODE.Text = frm.QstrWeightCode;
txt_WEIGHT_UNIT.Text = frm.QstrWeightName;
}
}
private void txt_UOM_NAME_EditorButtonClick(object sender, Infragistics.Win.UltraWinEditors.EditorButtonEventArgs e)
{
FrmPopItemWeight frm = new FrmPopItemWeight(this.ob);
frm.ShowDialog();
if (!String.IsNullOrEmpty(frm.QstrWeightCode))
{
txt_UOM_CODE.Text = frm.QstrWeightCode;
txt_UOM_NAME.Text = frm.QstrWeightName;
}
}
}
}