//FORM3
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.Versioning;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using AinB;
using System.Windows.Forms;
namespace AinB
{
public partial class ToB : Form
{
public string FName; //窗口名称
public string MO; //MO
public string ST; //产区
public string ITEM; //
public ToB()
{
InitializeComponent();
}
private void ToB_Load(object sender, EventArgs e)
{
string[] ButName = { "", "提 交", "返 回" };
string[] Items = { "电批", "电烙铁", "热风机" };
int i = 1;
if (FName == "生产区")
{
Meth meth = new Meth();
DataTable dt = meth.MacInfo(ST, MO);
try {
if (meth == null) { MessageBox.Show($"系统无法找到{MO}记录,请确认!"); }
}
catch { }
string[] labName = { FName, "MO:", dt.Rows[0]["MO"].ToString(), "ITEM:", dt.Rows[0]["ITEM"].ToString() };
for (int j = 0; j < 5; j++)
{
Label Toplab = new Label();
Toplab.Text = labName[j];
Toplab.Location = new Point(50 + 100 * j, 15); Toplab.Size = new Size(50, 20);
if (j == 2 || j == 4)
{
Toplab.Location = new Point( 100 * j, 15); Toplab.Size = new Size(150, 20);
}
ToBpanel.Controls.Add(Toplab);
if (j < 2)
{
ComboBox Cbox = new ComboBox();
Cbox.Location = new Point(100 + 250 * j, 50);
Cbox.Size = new Size(200, 50);
if (j == 0)
{
for (int n = 0; n < dt.Rows.Count; n++)
{
Cbox.Items.Add(dt.Rows[n]["APCode"] + dt.Rows[n]["APDesc"].ToString());
Cbox.Text = Cbox.Text.Trim();
}
}
if (j == 1)
{
Cbox.Size = new Size(120, 50);
for (int n = 0; n < dt.Rows.Count; n++)
{
Cbox.Items.Add(dt.Rows[n]["GroupCode"].ToString());
Cbox.Text = Cbox.Text.Trim();
}
}
Cbox.Name = "选择设备";
Cbox.Text = Cbox.Text.Trim();
Cbox.DropDownStyle = ComboBoxStyle.DropDownList;
ToBpanel.Controls.Add(Cbox);
}
}
}
else if (FName == "维修区")
{
Label Toplab = new Label();
Toplab.Text = FName;
Toplab.Location = new Point(280, 15);
Toplab.Size = new Size(50, 15);
ToBpanel.Controls.Add(Toplab);
Label ItemName = new Label();
ItemName.Text = "产品系列:";
ItemName.Location = new Point(60, 50);
ItemName.Size = new Size(60, 25);
ToBpanel.Controls.Add(ItemName);
TextBox Itembox = new TextBox();
Itembox.Location = new Point(120, 45);
Itembox.Size = new Size(150, 25);
ToBpanel.Controls.Add(Itembox);
Label MacName = new Label();
MacName.Text = "被校验设备:";
MacName.Location = new Point(300, 50);
MacName.Size = new Size(80, 25);
ToBpanel.Controls.Add(MacName);
ComboBox Macbobox = new ComboBox();
Macbobox.Name = ("选择设备");
for (int n = 0; n < 3; n++)
{
Macbobox.Items.Add(Items[n]);
}
Macbobox.Text = Macbobox.Text.Trim();
Macbobox.DropDownStyle = ComboBoxStyle.DropDownList;
Macbobox.Location = new Point(380, 45);
Macbobox.Size = new Size(150, 25);
ToBpanel.Controls.Add(Macbobox);
}
Label Maclab = new Label();
Maclab.Name = "L_" + i.ToString();
Maclab.Text = $"设备{i}:";
Maclab.Location = new Point(78, 63 + 50 * i);
Maclab.Size = new Size(50, 15);
ToBpanel.Controls.Add(Maclab);
TextBox Macbox = new TextBox();
Macbox.Name = "T_" + i.ToString();
string Str_1 = Macbox.Text.Trim();
Macbox.Location = new Point(128, 63 + 50 * i);
Macbox.PreviewKeyDown += new PreviewKeyDownEventHandler(PreviewKeyDown);
Macbox.Size = new Size(200, 25);
ToBpanel.Controls.Add(Macbox);
Button Addbut = new Button();
Addbut.Name = $"B{i}";
Addbut.Text = "+";
Addbut.Location = new Point(278 + 50, 63 + 50 * i);
Addbut.Size = new Size(20, 20);
Addbut.Click += new EventHandler(Add_Click);
ToBpanel.Controls.Add(Addbut);
for (; i < 3; i++)
{
Button Bbut = new Button();
Bbut.Text = ButName[i];
Bbut.BackColor = Color.SkyBlue;
Bbut.Location = new Point(100 * (i + 1), 310);
Bbut.Size = new Size(80, 25);
Bbut.Click += new EventHandler(But_Click);
ToBpanel.Controls.Add(Bbut);
}
}
private void But_Click(object sender, EventArgs e)
{
Button button = sender as Button;
try
{
if (button.Text == "提 交")
{
MessageBox.Show("1");
}
if (button.Text == "返 回")
{
MessageBox.Show("2");
}
}
catch { }
}
//动态新增控件
private void Add_Click(object sender, EventArgs e)
{
int m = 1;
if (FName == "维修区") { m--; }
foreach (Control c in this.ToBpanel.Controls)
{
if (c is TextBox)
{
m++;
}
}
Label Maclab = new Label();
Maclab.Name = "L_" + (m).ToString();
Maclab.Text = "设备" + (m).ToString() + ":";
Maclab.Location = new Point(78, 63 + 50 * (m));
Maclab.Size = new Size(50, 15);
ToBpanel.Controls.Add(Maclab);
TextBox Macbox = new TextBox();
Macbox.Name = "T_" + (m).ToString();
Macbox.Location = new Point(78 + 50, 63 + 50 * (m));
Macbox.Size = new Size(200, 25);
Macbox.PreviewKeyDown += new PreviewKeyDownEventHandler(PreviewKeyDown);
ToBpanel.Controls.Add(Macbox);
Button Addbut = new Button();
Addbut.Name = "B_" + (m).ToString();
Addbut.Text = "-";
Addbut.Location = new Point(278 + 50, 63 + 50 * (m));
Addbut.Size = new Size(20, 20);
Addbut.Click += new EventHandler(Movebut_Click);
ToBpanel.Controls.Add(Addbut);
if (m >= 5) { MessageBox.Show("最多4个设备"); return; }
}
//回车事件
private new void PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
TextBox getText = sender as TextBox;
string id = getText.Name.Split('_')[1];
string Str = getText.Text.Trim();
if (e.KeyCode == Keys.Enter)
{
foreach (Control c in ToBpanel.Controls)
{
if (c.Name == getText.Name)
{
try
{
if (Str.Length > 0)
{
Data ToData = new Data();
ToData.FName = FName;
foreach (Control cc in ToBpanel.Controls)
{
if (cc.Name == "选择设备" && cc.Text.Length > 0)
{
string BoxName = cc.Text.Trim();
ToData.MacName = BoxName;
}
}
ToData.MdiParent = AinB.Index.ActiveForm;
ToData.Show();
}
else
{
MessageBox.Show($"设备{id}:不能为空!");
return;
}
}
catch { }
}
}
}
}
//动态移除控件
private void Movebut_Click(object sender, EventArgs e)
{
Button btnAction = sender as Button;
string id = btnAction.Name.Split('_')[1];
foreach (Control c in this.ToBpanel.Controls)
{
if (c.Name == "L_" + id)
{
ToBpanel.Controls.Remove(c);
c.Dispose();
}
}
foreach (Control c in this.ToBpanel.Controls)
{
if (c.Name == "T_" + id)
{
ToBpanel.Controls.Remove(c);
c.Dispose();
}
}
foreach (Control c in this.ToBpanel.Controls)
{
if (c.Name == "B_" + id)
{
ToBpanel.Controls.Remove(c);
c.Dispose();
return;
}
}
}
}
}