1
0
Fork 0
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.

163 lines
6.0 KiB
C#

using HighWayIot.Repository.service;
using HighWayIot.Winform.UserControlPages.SysConfigPages;
using Models;
using System;
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;
using System.Windows.Forms.VisualStyles;
namespace HighWayIot.Winform.UserControlPages
{
public partial class MaterialConfigPage : UserControl
{
/// <summary>
/// 物料子类型服务类实例
/// </summary>
ZxMaterialChildTypeService zxMaterialChildTypeService = ZxMaterialChildTypeService.Instance;
/// <summary>
/// 物料子类型数组
/// </summary>
string[] MaterialChildTypeArray;
/// <summary>
/// 物料类型服务类实例
/// </summary>
ZxMaterialTypeService zxMaterialTypeService = ZxMaterialTypeService.Instance;
/// <summary>
/// 物料类型数组
/// </summary>
string[] MaterialTypeArray;
/// <summary>
/// 物料信息服务类实例
/// </summary>
ZxMaterialService zxMaterialService = ZxMaterialService.Instance;
/// <summary>
/// 物料信息列表
/// </summary>
List<ZxMaterialEntity> Lists;
public MaterialConfigPage()
{
InitializeComponent();
Init();
}
private void Init()
{
MaterialDataGridView.AutoGenerateColumns = false;
//绑定物料类型
MaterialTypeArray = zxMaterialTypeService.GetMaterialTypeInfos().Select(x => x.MaterialTypeName).ToArray();
Array.Resize(ref MaterialTypeArray, MaterialTypeArray.Length + 1);
Array.Copy(MaterialTypeArray, 0, MaterialTypeArray, 1, MaterialTypeArray.Length - 1);
MaterialTypeArray[0] = string.Empty;
MaterialTypeComboBox.DataSource = MaterialTypeArray;
Lists = zxMaterialService.GetMaterialInfos();
MaterialDataGridView.DataSource = null;
MaterialDataGridView.DataSource = Lists;
}
/// <summary>
/// 添加物料
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void AddMaterial_Click(object sender, EventArgs e)
{
MaterialAddForm form = new MaterialAddForm();
form.ShowDialog();
Lists = zxMaterialService.GetMaterialInfos();
MaterialDataGridView.DataSource = null;
MaterialDataGridView.DataSource = Lists;
}
/// <summary>
/// 更新物料
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void UpdateMaterial_Click(object sender, EventArgs e)
{
ZxMaterialEntity entity = new ZxMaterialEntity();
int a = MaterialDataGridView.CurrentRow.Index;
entity.MaterialCode = MaterialDataGridView.Rows[a].Cells["MaterialCode"].Value.ToString();
entity.MaterialName = MaterialDataGridView.Rows[a].Cells["MaterialName"].Value.ToString();
entity.MaterialType = MaterialDataGridView.Rows[a].Cells["MaterialType"].Value.ToString();
entity.ChildType = MaterialDataGridView.Rows[a].Cells["ChildType"].Value.ToString();
bool.TryParse(MaterialDataGridView.Rows[a].Cells["IsUse"].Value.ToString(), out bool b);
entity.IsUse = b;
entity.IsDeleted = false;
MaterialUpdateForm form = new MaterialUpdateForm(entity);
form.ShowDialog();
Lists = zxMaterialService.GetMaterialInfos();
MaterialDataGridView.DataSource = null;
MaterialDataGridView.DataSource = Lists;
}
/// <summary>
/// 删除物料
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void DeleteMaterial_Click(object sender, EventArgs e)
{
int a = MaterialDataGridView.CurrentRow.Index;
string s = MaterialDataGridView.Rows[a].Cells["MaterialCode"].Value.ToString();
if(MessageBox.Show($"是否要删除编号为{s}的物料?", "确认", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
{
return;
}
if (!zxMaterialService.DeleteMaterialInfoByMaterialCode(s))
{
MessageBox.Show($"编号为{s}的物料删除失败" ,"提示");
}
Lists = zxMaterialService.GetMaterialInfos();
MaterialDataGridView.DataSource = null;
MaterialDataGridView.DataSource = Lists;
}
/// <summary>
/// 查询物料
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void SelectMaterial_Click(object sender, EventArgs e)
{
Lists = zxMaterialService.GetMaterialInfos(MaterialNameTextbox.Text.Trim(), MaterialTypeComboBox.Text.Trim(), ChildComboBox.Text.Trim(), IsAvailableUseCheckBox.Checked, IsUseCheckBox.Checked);
MaterialDataGridView.DataSource = null;
MaterialDataGridView.DataSource = Lists;
}
/// <summary>
/// 物料类型更改事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MaterialTypeComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
MaterialChildTypeArray = zxMaterialChildTypeService.GetMaterialChildTypeInfos(x => x.MaterialTypeName == MaterialTypeComboBox.Text).Select(x => x.MaterialChlidTypeName).ToArray();
Array.Resize(ref MaterialChildTypeArray, MaterialChildTypeArray.Length + 1);
Array.Copy(MaterialChildTypeArray, 0, MaterialChildTypeArray, 1, MaterialChildTypeArray.Length - 1);
MaterialChildTypeArray[0] = string.Empty;
ChildComboBox.DataSource = MaterialChildTypeArray;
}
}
}