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.

138 lines
4.8 KiB
C#

1 year ago
using ICSharpCode.Core;
using Mesnac.Action.ChemicalWeighing.Entity;
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<Pmt_material> pmt_Materials = new List<Pmt_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()
{
pmt_Materials = Product.PptPlan.PlanHelper.GetAllPmt_material();
cmbMaterial.DataSource = pmt_Materials;
cmbMaterial.DisplayMember = "Material_name";
cmbMaterial.ValueMember = "ID";
}
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;
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.cmbMaterial.Text))
{
MessageBox.Show("请选择物料的名称!", Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
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.MaterialID = (string)this.cmbMaterial.SelectedValue;
_sub.MaterialName = this.cmbMaterial.Text;
_sub.Material_Code = txtMaterialCode.Text;
_sub.SetWeight = 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);
}
}
}
private void btnCancel_Click(object sender, EventArgs e)
{
this.Dispose();
}
private void cmbMaterial_SelectedIndexChanged(object sender, EventArgs e)
{
if (_actionType == ActionType.Add)
{
var name = this.cmbMaterial.Text;
txtMaterialCode.Text = pmt_Materials.SingleOrDefault(d => d.Material_name == name).Material_code;
}
if (_actionType == ActionType.Modify)
{
var name = this.cmbMaterial.Text;
txtMaterialCode.Text = pmt_Materials.FirstOrDefault(d => d.Material_name == name).Material_code;
}
}
}
}