Files
FG2608061/CODE/20230901/SA17168/AGVSystem Ver2.0/Location_Set.cs
T

127 lines
5.1 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace AGVSystem
{
public partial class Location_Set : Form
{
string strsql = "";
ClsDBConn_sql db = new ClsDBConn_sql();
DataSet ds = new DataSet();
public Location_Set(int id , int x, int y ,int map )
{
InitializeComponent();
txt_zb_x.Text = x.ToString();
txt_zb_y.Text = y.ToString();
cmb_map.SelectedIndex = map;
num_id.Value = id;
}
private void button1_Click(object sender, EventArgs e)
{
string count = "0";
if (Cls.Param.UserName_temp == "")
{
MessageBox.Show("请登录管理员权限!", "AGV调度管理系统", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
strsql = "UPDATE [LandMarkInfo] SET [Flag_Value] = "+num_plcvalue.Value+
",[Loc_X] = "+txt_zb_x.Text+
",[Loc_Y] = "+txt_zb_y.Text+
",[Binding] = "+cmb_bd.SelectedIndex+
",[Area] = "+cmb_map.SelectedIndex+
",[Bank] = "+cmb_zhangaiwu.SelectedIndex+
",[Speed] = "+num_speed.Value+
",[Next_Station1] = "+next_loc1.Value+
",[Drict1] = "+cmb_run1.SelectedIndex+
",[LongTime1] = "+next_longtime1.Value+
",[Next_Station2] = "+next_loc2.Value+
",[Drict2] = "+cmb_run2.SelectedIndex+
",[LongTime2] = "+next_longtime2.Value+
" WHERE [Loc_ID] = "+num_id.Value;
count = db.Command(strsql);
if (count == "1")
{
MessageBox.Show("更新成功!");
this.Close();
}
}
int value = -100;
private void num_id_ValueChanged(object sender, EventArgs e)
{
value = -100;
strsql = "SELECT [Loc_ID] ,[Flag_Value],[Binding],[Area],[Assembly_ID],[Bank],[Speed]"+
",[Next_Station1],[Drict1],[LongTime1] ,[Next_Station2] ,[Drict2] ,[LongTime2]"+
" FROM [LandMarkInfo] where Loc_ID ="+num_id.Value;
ds.Tables.Clear();
ds = db.connDt(strsql);
if (ds.Tables[0].Rows.Count == 1)
{
num_plcvalue.Value = Convert.ToDecimal( ds.Tables[0].Rows[0][0].ToString());
}
else if (ds.Tables[0].Rows.Count > 1)
{
foreach (DataRow dr in ds.Tables[0].Rows)
{
if (value == -100)
{
value = Convert.ToInt16(dr[0].ToString());
}
else
{
if (value != Convert.ToInt16(dr[0].ToString()))
{
MessageBox.Show(num_id.Value.ToString()+"对应的标记值有误!");
button1.Enabled = false;
return;
}
}
}
}
if (ds.Tables[0].Rows.Count >= 1)
{
num_plcvalue.Value = Convert.ToDecimal(ds.Tables[0].Rows[0][1].ToString());
cmb_map.SelectedIndex = Convert.ToInt16(ds.Tables[0].Rows[0][3].ToString());
cmb_bd.SelectedIndex = Convert.ToInt16(ds.Tables[0].Rows[0][2].ToString());
cmb_type.SelectedIndex = ds.Tables[0].Rows[0][4].ToString() == "0" ? 0 : 1;
cmb_zhangaiwu.SelectedIndex = Convert.ToInt16(ds.Tables[0].Rows[0][5].ToString());
num_speed.Value = Convert.ToDecimal(ds.Tables[0].Rows[0][6].ToString());
next_loc1.Value = Convert.ToDecimal(ds.Tables[0].Rows[0][7].ToString());
next_loc2.Value = Convert.ToDecimal(ds.Tables[0].Rows[0][10].ToString());
next_longtime1.Value = Convert.ToDecimal(ds.Tables[0].Rows[0][9].ToString());
next_longtime2.Value = Convert.ToDecimal(ds.Tables[0].Rows[0][12].ToString());
cmb_run1.SelectedIndex = Convert.ToInt16(ds.Tables[0].Rows[0][8].ToString());
cmb_run2.SelectedIndex = Convert.ToInt16(ds.Tables[0].Rows[0][11].ToString());
}
}
private void next_loc1_ValueChanged(object sender, EventArgs e)
{
strsql = "SELECT [Loc_X] ,[Loc_Y] FROM LandMarkInfo WHERE Loc_ID ="+next_loc1.Value;
ds.Tables.Clear();
ds = db.connDt(strsql);
if (ds.Tables[0].Rows.Count == 1)
{
next_longtime1.Value = Math.Abs(Convert.ToInt16(ds.Tables[0].Rows[0][0].ToString()) - Convert.ToInt16(txt_zb_x.Text)) + Math.Abs(Convert.ToInt16(ds.Tables[0].Rows[0][1].ToString()) - Convert.ToInt16(txt_zb_y.Text));
}
}
private void Location_Set_Load(object sender, EventArgs e)
{
this.next_loc1.ValueChanged += new System.EventHandler(this.next_loc1_ValueChanged);
}
}
}