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.
lj_plc/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjPlanning/FrmPlanning.cs

179 lines
5.3 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using Mesnac.Action.ChemicalWeighing.LjMaterial;
using Mesnac.Action.ChemicalWeighing.LjMetageFormula;
using Mesnac.Action.ChemicalWeighing.LjMixFormula;
using Mesnac.Action.ChemicalWeighing.LjProdcutLine;
namespace Mesnac.Action.ChemicalWeighing.LjPlanning
{
public partial class FrmPlanning : Form
{
public FrmPlanning()
{
InitializeComponent();
FillController();
}
private int _id;
private LjPlanningView view = new LjPlanningView();
public FrmPlanning(int id) : this()
{
_id=id;
var ljPlanningView = LjPlanningDb.GetById(id);
if (ljPlanningView != null)
{
txtCarNumber.Text = ljPlanningView.NumCar.ToString();
//根据更新去获取数据
Checked(DrpMetageA, ljPlanningView.MetageAId);
Checked(DrpMetageB1,ljPlanningView.MetageB1Id);
Checked(DrpMetageB2, ljPlanningView.MetageB2Id);
Checked(DrpMixA,ljPlanningView.MixAId);
Checked(DrpMixB,ljPlanningView.MixBId);
Checked(DrpMixC,ljPlanningView.MixCId);
}
}
private void Checked(ComboBox alBox,string checkId)
{
foreach (MyNameValueStr combo in alBox.Items)
{
if (combo.Id == checkId)
{
alBox.SelectedItem = combo;
break;
}
}
}
private List<ProductLineView> productLineViews;
// private List<MyNameValueStr> lsList;
private List<MyNameValueStr> lsAMixList;
private List<MyNameValueStr> lsBMixList;
private List<MyNameValueStr> lsCMixList;
private void FillController()
{
productLineViews = ProductLineDb.GetList();
DrpProductLine.DataSource=productLineViews;
FillComboBox(DrpProductLine);
//var selectedIndex = DrpProductLine.SelectedIndex;
//var productLineView = productLineViews[selectedIndex];
//this.label1.Text=productLineView.DryName;
IEnumerable<MyNameValueStr> ien = MetageFormulaDb.GetMetageNmaValue();
var drpA = ien.ToList();
var drpB = ien.ToList();
var drpC = ien.ToList();
FillComboBox(DrpMetageA);
DrpMetageA.DataSource = drpA;
FillComboBox(DrpMetageB1);
DrpMetageB1.DataSource = drpB;
FillComboBox(DrpMetageB2);
DrpMetageB2.DataSource = drpC;
lsAMixList = MixDb.GetMyNameValueStrs(2);
DrpMixA.DataSource = lsAMixList;
FillComboBox(DrpMixA);
lsBMixList= MixDb.GetMyNameValueStrs(1);
DrpMixB.DataSource = lsBMixList;
FillComboBox(DrpMixB);
lsCMixList = MixDb.GetMyNameValueStrs(3);
DrpMixC.DataSource = lsCMixList;
FillComboBox(DrpMixC);
}
private void FillComboBox(ComboBox combo)
{
combo.ValueMember = "Id";
combo.DisplayMember = "Name";
}
private void DrpProductLine_SelectedIndexChanged(object sender, System.EventArgs e)
{
var selectedIndex = DrpProductLine.SelectedIndex;
var productLineView = productLineViews[selectedIndex];
this.label1.Text = productLineView.DryName;
}
private void btnCancel_Click(object sender, System.EventArgs e)
{
this.Close();
}
private void btnOK_Click(object sender, System.EventArgs e)
{
string carNumber = txtCarNumber.Text.Trim();
if (string.IsNullOrEmpty(carNumber))
{
MessageBox.Show(@"请输入车次");
return;
}
if (!int.TryParse(carNumber, out var carNo))
{
MessageBox.Show(@"请输入正确的车次");
return;
}
view.UpdateTime = DateTime.Now;
view.NumCar = carNo;
view.MetageAId = DrpMetageA.SelectedValue.ToString();
view.MetageAName = DrpMetageA.Text;
view.MixAId = DrpMixA.SelectedValue.ToString();
view.MixAName = DrpMixA.Text;
view.MetageB1Id = DrpMetageB1.SelectedValue.ToString();
view.MetageB1Name= DrpMetageB1.Text;
view.MetageB2Id = DrpMetageB2.SelectedValue.ToString();
view.MetageB2Name= DrpMetageB2.Text;
view.MixBId= DrpMixB.SelectedValue.ToString();
view.MixBName=DrpMixB.Text;
view.MixCId =DrpMixC.SelectedValue.ToString();
view.MixCName=DrpMixC.Text;
//需要设计状态 0 未开始 -1 异常退出 1 完成
if (_id == 0)
{
view.CreateTime = DateTime.Now;
view.Status = "0";
LjPlanningDb.Add(view);
}
else
{
view.UpdateTime= DateTime.Now;
view.Status = "0";
view.Id = _id;
LjPlanningDb.Update(view);
}
}
}
}