|
|
|
|
using ICSharpCode.Core;
|
|
|
|
|
using Mesnac.Action.ChemicalWeighing.BinManage;
|
|
|
|
|
using Mesnac.Action.ChemicalWeighing.Entity;
|
|
|
|
|
using Mesnac.Action.ChemicalWeighing.Entity.material;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace Mesnac.Action.ChemicalWeighing.Warehouse
|
|
|
|
|
{
|
|
|
|
|
public partial class FrmNewMaterial : Form
|
|
|
|
|
{
|
|
|
|
|
private List<xl_material> xl_Materials = new List<xl_material>(); //所有物料集合
|
|
|
|
|
public ActionType _actionType;
|
|
|
|
|
public Hw_WareHouse_Sub _sub = null;
|
|
|
|
|
|
|
|
|
|
public FrmNewMaterial()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
_sub = new Hw_WareHouse_Sub();
|
|
|
|
|
}
|
|
|
|
|
public FrmNewMaterial(ActionType type, int ID)
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
_sub = new Hw_WareHouse_Sub();
|
|
|
|
|
_sub.MainId = ID;
|
|
|
|
|
}
|
|
|
|
|
public FrmNewMaterial(ActionType type, Hw_WareHouse_Sub sub)
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
_actionType = type;
|
|
|
|
|
_sub = sub;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取物料
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void InitCombox()
|
|
|
|
|
{
|
|
|
|
|
xl_Materials = Product.XlPlan.PlanHelper.GetAllMaterial();
|
|
|
|
|
//cmbMaterial.DataSource = pmt_Materials;
|
|
|
|
|
//cmbMaterial.DisplayMember = "Material_name";
|
|
|
|
|
//cmbMaterial.ValueMember = "ID";
|
|
|
|
|
var table = BinHelper.GetBinMaterial();
|
|
|
|
|
if (table != null)
|
|
|
|
|
{
|
|
|
|
|
//以下向下拉列表框中插入“请选择”
|
|
|
|
|
|
|
|
|
|
DataRow dr = table.NewRow();
|
|
|
|
|
dr[0] = "0";
|
|
|
|
|
dr[1] = "请选择";
|
|
|
|
|
dr[2] = "请选择";
|
|
|
|
|
table.Rows.InsertAt(dr, 0);
|
|
|
|
|
|
|
|
|
|
this.cmbMaterial.DataSource = table;
|
|
|
|
|
cmbMaterial.DisplayMember = "MaterialName";
|
|
|
|
|
cmbMaterial.ValueMember = "MaterialID";//仓库编码
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FrmNewMaterial_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
this.InitCombox();
|
|
|
|
|
this.InitUI();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void InitUI()
|
|
|
|
|
{
|
|
|
|
|
if (this._actionType == ActionType.Add)
|
|
|
|
|
{
|
|
|
|
|
this.Text = "添加新物料";
|
|
|
|
|
}
|
|
|
|
|
else if (this._actionType == ActionType.Modify)
|
|
|
|
|
{
|
|
|
|
|
Pmt_material item = Product.PptPlan.PlanHelper.GetPmt_material(_sub.MaterialID);
|
|
|
|
|
SetComboBoxSelected(this.cmbMaterial, item);
|
|
|
|
|
this.txtMaterialCode.Text = _sub.Material_Code;
|
|
|
|
|
this.txtSetWeight.Text = _sub.SetWeight.ToString();
|
|
|
|
|
this.Text = "修改物料";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.btnOk.Text = StringParser.Parse(ResourceService.GetString("Mesnac_Dialog_btnOK"));
|
|
|
|
|
this.btnCancel.Text = StringParser.Parse(ResourceService.GetString("Mesnac_Dialog_btnCancel"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnOk_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (String.IsNullOrEmpty(this.txtPlanId.Text))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("请输入计划编码!", Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
|
|
|
this.txtPlanId.Focus();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (String.IsNullOrEmpty(this.cmbMaterial.Text))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("请选择物料的名称!", Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
|
|
|
this.cmbMaterial.Focus();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (_actionType == ActionType.Add && WarehouseHelper.IsExistsName((string)this.cmbMaterial.SelectedValue, this.cmbMaterial.Text, _sub.MainId))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("选择物料重复!", Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (_actionType == ActionType.Modify && WarehouseHelper.IsExistsUpdateName((string)this.cmbMaterial.SelectedValue, this.cmbMaterial.Text, _sub.MainId, _sub.ID))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("选择物料重复!", Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
_sub.PId = this.txtPlanId.Text;
|
|
|
|
|
_sub.MaterialID = txtMaterialCode.Text; //(string)this.cmbMaterial.SelectedValue;
|
|
|
|
|
_sub.MaterialName = this.cmbMaterial.Text;
|
|
|
|
|
_sub.Material_Code = txtMaterialCode.Text;
|
|
|
|
|
_sub.SetWeight =Convert.ToDouble(this.txtSetWeight.Text);
|
|
|
|
|
|
|
|
|
|
this.DialogResult = System.Windows.Forms.DialogResult.OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void SetComboBoxSelected(ComboBox comboBox, Pmt_material key)
|
|
|
|
|
{
|
|
|
|
|
//for (int i = 0; i < comboBox.Items.Count; i++)
|
|
|
|
|
//{
|
|
|
|
|
// dynamic obj = comboBox.Items[i];
|
|
|
|
|
// if (obj.ID.ToString() == key.ID)
|
|
|
|
|
// {
|
|
|
|
|
// string text = obj.Material_name.ToString();
|
|
|
|
|
// comboBox.SelectedIndex = comboBox.FindString(text);
|
|
|
|
|
// }
|
|
|
|
|
//}
|
|
|
|
|
var table = BinHelper.GetBinMaterial();
|
|
|
|
|
if (table != null)
|
|
|
|
|
{
|
|
|
|
|
//以下向下拉列表框中插入“请选择”
|
|
|
|
|
|
|
|
|
|
DataRow dr = table.NewRow();
|
|
|
|
|
dr[0] = "0";
|
|
|
|
|
dr[1] = "请选择";
|
|
|
|
|
dr[2] = "请选择";
|
|
|
|
|
dr[3] = "请选择";
|
|
|
|
|
dr[4] = "请选择";
|
|
|
|
|
dr[5] = "0";
|
|
|
|
|
table.Rows.InsertAt(dr, 0);
|
|
|
|
|
|
|
|
|
|
this.cmbMaterial.DataSource = table;
|
|
|
|
|
cmbMaterial.DisplayMember = "MaterialName";
|
|
|
|
|
cmbMaterial.ValueMember = "MaterialID";//仓库编码
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_actionType == ActionType.Modify)
|
|
|
|
|
{
|
|
|
|
|
cmbMaterial.SelectedValue = key.ID;
|
|
|
|
|
}
|
|
|
|
|
if (_actionType == ActionType.Add)
|
|
|
|
|
{
|
|
|
|
|
cmbMaterial.SelectedValue = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnCancel_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
this.Dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void cmbMaterial_SelectedIndexChanged_1(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (_actionType == ActionType.Add)
|
|
|
|
|
{
|
|
|
|
|
string name = this.cmbMaterial.Text.ToString();
|
|
|
|
|
if (string.IsNullOrEmpty(name))
|
|
|
|
|
{
|
|
|
|
|
txtMaterialCode.Text = "";
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
string id = this.cmbMaterial.SelectedValue.ToString();
|
|
|
|
|
if (string.IsNullOrEmpty(id))
|
|
|
|
|
{
|
|
|
|
|
txtMaterialCode.Text = "";
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var obj = xl_Materials.SingleOrDefault(d => d.ID.Equals(id));
|
|
|
|
|
if (obj == null) return;
|
|
|
|
|
txtMaterialCode.Text = obj.Material_code;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_actionType == ActionType.Modify)
|
|
|
|
|
{
|
|
|
|
|
string name = this.cmbMaterial.Text.ToString();
|
|
|
|
|
if (string.IsNullOrEmpty(name))
|
|
|
|
|
{
|
|
|
|
|
txtMaterialCode.Text = "";
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
string id = this.cmbMaterial.SelectedValue.ToString();
|
|
|
|
|
if (string.IsNullOrEmpty(id))
|
|
|
|
|
{
|
|
|
|
|
txtMaterialCode.Text = "";
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var obj = xl_Materials.SingleOrDefault(d => d.ID.Equals(id));
|
|
|
|
|
if (obj == null) return;
|
|
|
|
|
txtMaterialCode.Text = obj.Material_code;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|