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

393 lines
13 KiB

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Windows.Forms;
using MESClassLibrary.BLL.BasicInfo;
using MESClassLibrary.BLL.Log;
using MESClassLibrary.BLL.PunchAndWeld;
using MESClassLibrary.Model;
namespace PunchAndWeld
{
public partial class FrmPlan : Form
{
public FrmPlan()
{
InitializeComponent();
}
public int Flag = 0;
private void FrmPlan_Load(object sender, EventArgs e)
{
InitDevice();
InitPart();
InitButton();
this.listView1.Columns.Clear();
this.listView1.Columns.Add("ID", 0, HorizontalAlignment.Center);
this.listView1.Columns.Add("设备名称", 300, HorizontalAlignment.Center);
this.listView1.Columns.Add("零件号", 200, HorizontalAlignment.Center);
this.listView1.Columns.Add("零件名称", 400, HorizontalAlignment.Center);
this.listView1.Columns.Add("数量", 150, HorizontalAlignment.Center);
this.listView1.Columns.Add("完成数", 0, HorizontalAlignment.Center);
InitList();
}
private void InitButton()
{
btAdd.Enabled = true;
btEdit.Enabled = true;
btDel.Enabled = true;
panel1.Visible = false;
comboBox1.SelectedIndex = -1;
comboBox2.SelectedIndex = -1;
textBox1.Text = "";
comboBox1.Enabled = true;
comboBox2.Enabled = true;
}
private void InitDevice()
{
try
{
PunchDeviceBLL bll=new PunchDeviceBLL();
comboBox1.Items.Clear();
DataTable dt = bll.SearchInfo();
if (dt != null && dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
comboBox1.Items.Add(dt.Rows[i]["DeviceName"].ToString());
}
}
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
}
}
private void InitPart()
{
try
{
PunchPartBLL bll = new PunchPartBLL();
PunchDeviceBLL pbll = new PunchDeviceBLL();
comboBox2.Items.Clear();
DataTable dt1 = pbll.SearchInfo();
if (dt1 != null && dt1.Rows.Count > 0)
{
for (int i = 0; i < dt1.Rows.Count; i++)
{
DataTable dt = bll.SearchPunchPart(dt1.Rows[i]["DeviceNo"].ToString());
if (dt != null && dt.Rows.Count > 0)
{
for (int j = 0; j < dt.Rows.Count; j++)
{
comboBox2.Items.Add(dt.Rows[j]["ProductName"].ToString());
}
}
}
}
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
}
}
private void InitList()
{
try
{
PunchPlanBLL bll=new PunchPlanBLL();
this.listView1.Items.Clear();
DataTable dt = bll.SearchAllPlan();
if (dt != null && dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
ListViewItem lvi = new ListViewItem(dt.Rows[i]["ID"].ToString());
lvi.SubItems.Add(dt.Rows[i]["DeviceName"].ToString()); //后面添加的Item都为SubItems ,即为子项
lvi.SubItems.Add(dt.Rows[i]["PartNo"].ToString()); //后面添加的Item都为SubItems ,即为子项
lvi.SubItems.Add(dt.Rows[i]["ProductName"].ToString());
lvi.SubItems.Add(dt.Rows[i]["PlanCount"].ToString());
lvi.SubItems.Add(dt.Rows[i]["CompleteCount"].ToString());
listView1.Items.Add(lvi);
}
}
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
}
}
private void btAdd_Click(object sender, EventArgs e)
{
btAdd.Enabled = false;
btEdit.Enabled = false;
btDel.Enabled = false;
panel1.Visible = true;
Flag = 1;
}
private void btSave_Click(object sender, EventArgs e)
{
try
{
ProductBLL pbll=new ProductBLL();
PunchDeviceBLL dbll=new PunchDeviceBLL();
PunchPlanBLL planbll=new PunchPlanBLL();
PunchPlanModel md=new PunchPlanModel();
string ProductID = "", deviceNo = "";
bool IsFlag = false;
#region 验证数据有效性
if (comboBox1.Text == "")
{
MessageBox.Show("设备名称不能为空!", "提示", MessageBoxButtons.OK);
return;
}
if (comboBox2.Text == "")
{
MessageBox.Show("零件名称不能为空!", "提示", MessageBoxButtons.OK);
return;
}
if (IsNumeric(textBox1.Text.Trim()) == false)
{
MessageBox.Show("数量必须为整数!", "提示", MessageBoxButtons.OK);
textBox1.Focus();
return;
}
#endregion
#region 获取信息
DataTable dt1 = pbll.SearchInfoByProductName(comboBox2.Text.Trim());
if (dt1 != null && dt1.Rows.Count > 0)
{
ProductID = dt1.Rows[0]["ProductID"].ToString();
}
else
{
ProductID = "";
}
DataTable dt2 = dbll.SearchDeviceNo(comboBox1.Text.Trim());
if (dt2 != null && dt2.Rows.Count > 0)
{
deviceNo = dt2.Rows[0]["DeviceNo"].ToString();
}
else
{
deviceNo = "";
}
#endregion
#region 添加保存
if (Flag == 1)
{
md.ID = Guid.NewGuid().ToString();
md.DeviceNo = deviceNo;
md.ProductID = ProductID;
md.PlanCount = Convert.ToInt32(textBox1.Text.Trim());
if (planbll.AddInfo(md) == true)
{
MessageBox.Show("添加成功!", "提示", MessageBoxButtons.OK);
}
else
{
MessageBox.Show("添加失败!", "提示", MessageBoxButtons.OK);
return;
}
}
#endregion
#region 编辑保存
if (Flag == 2)
{
if (Convert.ToInt32(textBox1.Text.Trim()) <
Convert.ToInt32(listView1.SelectedItems[0].SubItems[5].Text))
{
MessageBox.Show("编辑失败,计划数不能小于生产数!", "提示", MessageBoxButtons.OK);
textBox1.Focus();
return;
}
md.ID = listView1.SelectedItems[0].Text;
md.PlanCount = Convert.ToInt32(textBox1.Text.Trim());
if (planbll.UpdateInfo(md) == true)
{
MessageBox.Show("编辑成功!", "提示", MessageBoxButtons.OK);
}
else
{
MessageBox.Show("编辑失败!", "提示", MessageBoxButtons.OK);
return;
}
}
#endregion
InitList();
InitButton();
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
}
}
private bool IsNumeric(string str)
{
System.Text.RegularExpressions.Regex reg1 = new System.Text.RegularExpressions.Regex(@"^[0-9]\d*$");
return reg1.IsMatch(str);
}
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
if (listView1.SelectedItems.Count != 0)
{
btAdd.Enabled = true;
btEdit.Enabled = true;
btDel.Enabled = true;
comboBox1.Text= listView1.SelectedItems[0].SubItems[1].Text;
comboBox2.Text = listView1.SelectedItems[0].SubItems[3].Text;
textBox1.Text = listView1.SelectedItems[0].SubItems[4].Text;
}
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
}
}
private void btEdit_Click(object sender, EventArgs e)
{
try
{
if (listView1.SelectedItems.Count == 0)
{
MessageBox.Show("请选择要编辑的行!", "提示", MessageBoxButtons.OK);
return;
}
Flag = 2;
panel1.Visible = true;
btAdd.Enabled = false;
btEdit.Enabled = false;
btDel.Enabled = false;
comboBox1.Enabled = false;
comboBox2.Enabled = false;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
}
}
private void btCal_Click(object sender, EventArgs e)
{
InitList();
InitButton();
}
private void btDel_Click(object sender, EventArgs e)
{
try
{
PunchPlanBLL bll=new PunchPlanBLL();
PunchPlanModel md=new PunchPlanModel();
if (listView1.SelectedItems.Count == 0)
{
MessageBox.Show("请选择要删除的行!", "提示", MessageBoxButtons.OK);
return;
}
DialogResult result=MessageBox.Show("确定要删除该计划?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
if (result == DialogResult.OK)
{
if (Convert.ToInt32(listView1.SelectedItems[0].SubItems[5].Text) != 0)
{
MessageBox.Show("该计划已开始生产,无法删除!", "提示", MessageBoxButtons.OK);
return;
}
else
{
md.ID = listView1.SelectedItems[0].Text;
bll.DelInfo(md);
}
InitList();
InitButton();
}
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
PunchPartBLL bll = new PunchPartBLL();
PunchDeviceBLL pbll = new PunchDeviceBLL();
comboBox2.Items.Clear();
DataTable dt1 = pbll.SearchDeviceNo(comboBox1.Text.Trim());
if (dt1 != null && dt1.Rows.Count > 0)
{
for (int i = 0; i < dt1.Rows.Count; i++)
{
DataTable dt = bll.SearchPunchPart(dt1.Rows[i]["DeviceNo"].ToString());
if (dt != null && dt.Rows.Count > 0)
{
for (int j = 0; j < dt.Rows.Count; j++)
{
comboBox2.Items.Add(dt.Rows[j]["ProductName"].ToString());
}
}
}
}
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
}
}
}
}