You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

217 lines
7.7 KiB
C#

1 year ago
using ICSharpCode.Core;
1 year ago
using Mesnac.Action.ChemicalWeighing.BinManage;
1 year ago
using Mesnac.Action.ChemicalWeighing.Entity;
1 year ago
using Mesnac.Action.ChemicalWeighing.Entity.material;
1 year ago
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
{
1 year ago
private List<xl_material> xl_Materials = new List<xl_material>(); //所有物料集合
1 year ago
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()
{
1 year ago
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";//仓库编码
}
1 year ago
}
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;
1 year ago
this.txtSetWeight.Text = _sub.SetWeight.ToString();
1 year ago
this.Text = "修改物料";
}
1 year ago
1 year ago
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)
{
1 year ago
if (String.IsNullOrEmpty(this.txtPlanId.Text))
{
MessageBox.Show("请输入计划编码!", Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
this.txtPlanId.Focus();
return;
}
1 year ago
if (String.IsNullOrEmpty(this.cmbMaterial.Text))
{
MessageBox.Show("请选择物料的名称!", Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
1 year ago
this.cmbMaterial.Focus();
1 year ago
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;
}
1 year ago
_sub.PId = this.txtPlanId.Text;
_sub.MaterialID = txtMaterialCode.Text; //(string)this.cmbMaterial.SelectedValue;
1 year ago
_sub.MaterialName = this.cmbMaterial.Text;
_sub.Material_Code = txtMaterialCode.Text;
1 year ago
_sub.SetWeight =Convert.ToDouble(this.txtSetWeight.Text);
1 year ago
this.DialogResult = System.Windows.Forms.DialogResult.OK;
}
public void SetComboBoxSelected(ComboBox comboBox, Pmt_material key)
{
1 year ago
//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)
1 year ago
{
1 year ago
//以下向下拉列表框中插入“请选择”
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;
1 year ago
}
}
private void btnCancel_Click(object sender, EventArgs e)
{
this.Dispose();
}
1 year ago
private void cmbMaterial_SelectedIndexChanged_1(object sender, EventArgs e)
1 year ago
{
if (_actionType == ActionType.Add)
{
1 year ago
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;
1 year ago
}
if (_actionType == ActionType.Modify)
{
1 year ago
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;
1 year ago
}
}
}
}