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.
474 lines
20 KiB
474 lines
20 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using DBFactory;
|
|
namespace SystemConfig
|
|
{
|
|
public partial class FrmRouteDeviceEdit : Form
|
|
{
|
|
DBOperator dbo = CStaticClass.dbo;
|
|
private static FrmRouteDeviceEdit _formInstance;
|
|
|
|
public static FrmRouteDeviceEdit FormInstance
|
|
{
|
|
get
|
|
{
|
|
if (_formInstance == null)
|
|
{
|
|
_formInstance = new FrmRouteDeviceEdit();
|
|
|
|
}
|
|
return _formInstance;
|
|
}
|
|
set { _formInstance = value; }
|
|
}
|
|
public FrmRouteDeviceEdit()
|
|
{
|
|
InitializeComponent();
|
|
_formInstance = this;
|
|
DataView dv = dbo.ExceSQL("select * from T_Base_Route ").Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
this.comboBox1.ValueMember = "F_RouteID";
|
|
this.comboBox1.DisplayMember = "F_RouteName";
|
|
this.comboBox1.DataSource = dv;
|
|
|
|
}
|
|
}
|
|
|
|
private void button1_Click(object sender, EventArgs e)
|
|
{
|
|
DataView dv = dbo.ExceSQL("SELECT F_StartDevice, F_EndDevice,F_RouteKind FROM T_Base_Route where F_RouteID=" + this.comboBox1.SelectedValue).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
List<List<int>> devs = SearchNextDevices(Convert.ToInt32(dv[0]["F_StartDevice"]), Convert.ToInt32(dv[0]["F_EndDevice"]), dv[0]["F_RouteKind"].ToString());
|
|
if (devs.Count > 0)
|
|
{
|
|
for (int i = 0; i <devs.Count; i++)
|
|
{
|
|
|
|
List<int> devline = devs[i];
|
|
ListViewItem lvi = new ListViewItem(this.comboBox1.SelectedValue.ToString());
|
|
lvi.SubItems.Add(this.comboBox1.Text + "��·��:" + (i + 1).ToString());
|
|
for (int j = (devline.Count - 1); j >= 0; j--)
|
|
{
|
|
if (listView1.Columns.Count <= devline.Count+1)
|
|
{
|
|
for (int kk = 0; kk <= (devline.Count - listView1.Columns.Count+2); kk++)
|
|
{
|
|
listView1.Columns.Add("columnsHeader");
|
|
}
|
|
}
|
|
lvi.SubItems.Add(devline[j].ToString());
|
|
}
|
|
listView1.Items.Add(lvi);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
List< List<int>> SearchNextDevices(int startdev, int enddev, string RouteKind)
|
|
{
|
|
List<List<int>> rets = new List<List<int>>();
|
|
List<List<int>> rets0 = new List<List<int>>();
|
|
List<List<int>> rets1 = new List<List<int>>();
|
|
switch (RouteKind)
|
|
{
|
|
case "1"://���⣬ֻ�������ķ���F_InputNextDevice�����豸
|
|
rets = RecursionDevices(startdev, enddev, "F_InputNextDevice");
|
|
break;
|
|
case "2"://���⣬ֻ�����ķ���F_OutputNextDevice�����豸
|
|
rets = RecursionDevices(startdev, enddev, "F_OutputNextDevice");
|
|
break;
|
|
case "3"://�ƿ⣬�����Ѷ�����RGV��AGV���豸Ҫ����ת���豸����F_InputNextDevice�ͳ���F_OutputNextDevice��������
|
|
case "4"://�ƿ⣬�����Ѷ�����RGV��AGV���豸Ҫ����ת���豸����F_InputNextDevice�ͳ���F_OutputNextDevice��������
|
|
#region �ƿ�
|
|
|
|
if (checkBox1.Checked == true)
|
|
{
|
|
if (comboBox2.Text !=null)
|
|
{
|
|
rets0 = RecursionDevices(startdev, Convert.ToInt32(comboBox2.Text), "F_InputNextDevice");
|
|
if (rets0.Count > 0)
|
|
{
|
|
rets1 = RecursionDevices(Convert.ToInt32(comboBox2.Text), enddev, "F_OutputNextDevice");
|
|
if (rets1.Count > 0)
|
|
{
|
|
for (int i = 0; i < rets1.Count; i++)
|
|
{
|
|
List<int> rets1line = rets1[i];
|
|
for (int j = 0; j < rets0.Count; j++)
|
|
{
|
|
List<int> rets0line = rets0[j];
|
|
for (int k = 0; k < rets0line.Count; k++)
|
|
{
|
|
int rets0element = rets0line[k];
|
|
if (rets1line.Contains(rets0element) == false)
|
|
{
|
|
rets1line.Add(rets0element);
|
|
}
|
|
}
|
|
}
|
|
rets.Add(rets1line);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
rets0 = RecursionDevices(startdev, Convert.ToInt32(comboBox2.Text), "F_OutputNextDevice");
|
|
if (rets0.Count > 0)
|
|
{
|
|
rets1 = RecursionDevices(Convert.ToInt32(comboBox2.Text), enddev, "F_InputNextDevice");
|
|
if (rets1.Count > 0)
|
|
{
|
|
for (int i = 0; i < rets1.Count; i++)
|
|
{
|
|
List<int> rets1line = rets1[i];
|
|
for (int j = 0; j < rets0.Count; j++)
|
|
{
|
|
List<int> rets0line = rets0[j];
|
|
for (int k = 0; k < rets0line.Count; k++)
|
|
{
|
|
int rets0element = rets0line[k];
|
|
if (rets1line.Contains(rets0element) == false)
|
|
{
|
|
rets1line.Add(rets0element);
|
|
}
|
|
}
|
|
}
|
|
rets.Add(rets1line);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
|
|
}
|
|
return rets;
|
|
}
|
|
/// <summary>
|
|
/// �ݹ��γ�List< List<int>>�ĵ������豸�����ϵļ���
|
|
/// </summary>
|
|
/// <param name="startdev"></param>
|
|
/// <param name="enddev"></param>
|
|
/// <param name="IONextDevice"></param>
|
|
/// <returns></returns>
|
|
List< List<int>> RecursionDevices(int startdev, int enddev, string IONextDevice)
|
|
{
|
|
string sql = "";
|
|
DataView dv;
|
|
string nextdev = "";
|
|
string[] spl;
|
|
char[] cc = new char[1] { ';' };
|
|
List<List<int>> routedevs = new List<List<int>>();
|
|
sql = "SELECT " + IONextDevice + " FROM T_Base_Device where F_DeviceIndex=" + startdev;
|
|
dv = dbo.ExceSQL(sql).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
nextdev = dv[0][IONextDevice].ToString();
|
|
|
|
if (nextdev.Length > 0)
|
|
{
|
|
spl = nextdev.Split(cc);
|
|
for (int i = spl.GetLowerBound(0); i <= spl.GetUpperBound(0);i++ )
|
|
{
|
|
|
|
List< List<int>> rs = RecursionSingle(Convert.ToInt32( spl[i]), enddev, IONextDevice);
|
|
if (rs.Count > 0)
|
|
{
|
|
//���ض���·���豸���ϵļ���
|
|
List<int> rss=new List<int>();
|
|
for (int ii = 0; ii < rs.Count; ii++)
|
|
{
|
|
rss = rs[ii];
|
|
if (rss.Contains(Convert.ToInt32(spl[i])) == false)
|
|
{
|
|
rss.Add(Convert.ToInt32(spl[i]));
|
|
}
|
|
|
|
if (rss.Contains(startdev) == false)
|
|
{
|
|
rss.Add(startdev);
|
|
}
|
|
if (routedevs.Contains(rss) == false)
|
|
{
|
|
routedevs.Add(rss);
|
|
}
|
|
}
|
|
//Predicate<List<int>> FindValue = delegate(List<int> obj) { return obj.Contains(Convert.ToInt32(spl[i])); };
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return routedevs;
|
|
//����ֵ
|
|
|
|
}
|
|
|
|
}
|
|
return routedevs;
|
|
//����ֵ
|
|
}
|
|
List< List<int>> RecursionSingle(int startdev, int enddev, string IONextDevice)
|
|
{
|
|
|
|
char[] cc = new char[1] { ';' };
|
|
List<int> routedevs = new List<int>();
|
|
List<List<int>> mutiRoute = new List<List<int>>();
|
|
|
|
#region �ݹ����ö���·����ϸ�豸����
|
|
|
|
if (startdev == enddev)//�ҵ����յ��豸
|
|
{
|
|
|
|
if (routedevs.Contains(enddev) == false)
|
|
{
|
|
routedevs.Add(enddev);
|
|
}
|
|
if (routedevs.Contains(startdev) == false)
|
|
{
|
|
routedevs.Add(startdev);
|
|
}
|
|
mutiRoute.Add(routedevs);
|
|
return mutiRoute;
|
|
}
|
|
else//������
|
|
{
|
|
List< List<int>> mutireturndevs = RecursionDevices(startdev, enddev, IONextDevice);
|
|
if (mutireturndevs.Count > 0)
|
|
{
|
|
for (int k = 0; k < mutireturndevs.Count; k++)
|
|
{
|
|
//List<int> returndevs = mutireturndevs[k];
|
|
//if (returndevs.Count > 0)
|
|
//{
|
|
// for (int j = 0; j < returndevs.Count; j++)
|
|
// {
|
|
|
|
// if (routedevs.Contains(returndevs[j]) == false)
|
|
// {
|
|
// routedevs.Add(returndevs[j]);
|
|
|
|
// }
|
|
|
|
// }
|
|
// if (routedevs.Contains(startdev) == false)
|
|
// {
|
|
// routedevs.Add(startdev);
|
|
|
|
// }
|
|
// mutiRoute.Add(routedevs);
|
|
|
|
//}
|
|
if (mutireturndevs[k].Contains(startdev) == false)
|
|
{
|
|
mutireturndevs[k].Add(startdev);
|
|
|
|
}
|
|
mutiRoute.Add(mutireturndevs[k]);
|
|
}
|
|
}
|
|
return mutiRoute;
|
|
|
|
}
|
|
#endregion
|
|
}
|
|
|
|
private void button2_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
for (int i = 0; i < listView1.Items.Count; i++)
|
|
{
|
|
ListViewItem lvi = listView1.Items[i];
|
|
if (lvi.Checked == true)
|
|
{
|
|
//���Ӷ�F_RouteIDSubֵ���жϣ�
|
|
//�������д���F_RouteID��ôF_RouteIDSub��ȡֵ���Ƕ�Ӧ��F_RouteIDSub+1
|
|
//������F_RouteIDSub��ֵ����F_RouteID+"001"
|
|
int routeIDSub = GetRouteIDSub(Convert.ToInt32( lvi.Text));
|
|
int sn = 0;
|
|
for (int j = 2; j < lvi.SubItems.Count; j++)
|
|
{
|
|
int max = GetMaxRouteDeviceIndex();
|
|
sn = sn + 1;
|
|
string sql = "INSERT INTO T_Base_Route_Device "+
|
|
"(F_RouteDeviceIndex, F_RouteID, F_DeviceIndex, F_SerialNumber,F_RouteIDSub)VALUES " +
|
|
"(" + max + "," + lvi.Text + "," + lvi.SubItems[j].Text + "," + sn + "," + routeIDSub + ")";
|
|
dbo.ExceSQL(sql);
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
int GetMaxRouteDeviceIndex()
|
|
{
|
|
DataView dv = dbo.ExceSQL("SELECT MAX(F_RouteDeviceIndex) AS MaxIndex FROM T_Base_Route_Device").Tables[0].DefaultView; ;
|
|
if (dv.Count > 0)
|
|
{
|
|
if (dv[0]["MaxIndex"].ToString().Length > 0)
|
|
{
|
|
return (Convert.ToInt32(dv[0]["MaxIndex"]) + 1);
|
|
}
|
|
else
|
|
{
|
|
return 1;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
int GetRouteIDSub(int routeID)
|
|
{
|
|
DataView dv = dbo.ExceSQL("SELECT F_RouteIDSub FROM T_Base_Route_Device where F_RouteID=" + routeID + " order by F_RouteIDSub desc").Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
return (Convert.ToInt32(dv[0]["F_RouteIDSub"]) + 1);
|
|
}
|
|
else
|
|
{
|
|
return Convert.ToInt32 (routeID.ToString() + "001");
|
|
}
|
|
}
|
|
|
|
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
if (comboBox1.SelectedValue.ToString().Length <= 0) return;
|
|
comboBox2.Items.Clear();
|
|
DataView dv = dbo.ExceSQL("SELECT F_OutsideAltDevice, F_InsideAltDevice FROM T_Base_Route WHERE (F_RouteID = " + comboBox1.SelectedValue.ToString() + ")").Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
if (dv[0]["F_OutsideAltDevice"].ToString().Length > 0)
|
|
{
|
|
comboBox2.Items.Add(dv[0]["F_OutsideAltDevice"]);
|
|
}
|
|
if (dv[0]["F_InsideAltDevice"].ToString().Length > 0)
|
|
{
|
|
comboBox2.Items.Add(dv[0]["F_InsideAltDevice"]);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void button3_Click(object sender, EventArgs e)
|
|
{
|
|
listView1.Items.Clear();
|
|
}
|
|
|
|
private void button7_Click(object sender, EventArgs e)
|
|
{
|
|
DataView dv = dbo.ExceSQL("SELECT F_routeID,f_routename, F_StartDevice, F_EndDevice,F_RouteKind FROM T_Base_Route order by F_routeID asc").Tables[0].DefaultView;
|
|
for(int k=0;k<dv.Count;k++)
|
|
{
|
|
List<List<int>> devs = SearchNextDevices(Convert.ToInt32(dv[k]["F_StartDevice"]), Convert.ToInt32(dv[k]["F_EndDevice"]), dv[k]["F_RouteKind"].ToString());
|
|
if (devs.Count > 0)
|
|
{
|
|
for (int i = 0; i < devs.Count; i++)
|
|
{
|
|
List<int> devline = devs[i];
|
|
ListViewItem lvi = new ListViewItem(dv[k]["F_routeID"].ToString());
|
|
lvi.SubItems.Add(dv[k]["F_routeID"].ToString() + "��·��:" + (i + 1).ToString());
|
|
for (int j = (devline.Count - 1); j >= 0; j--)
|
|
{
|
|
if (listView1.Columns.Count <= devline.Count + 1)
|
|
{
|
|
for (int kk = 0; kk <= (devline.Count - listView1.Columns.Count + 2); kk++)
|
|
{
|
|
listView1.Columns.Add("columnsHeader");
|
|
}
|
|
}
|
|
lvi.SubItems.Add(devline[j].ToString());
|
|
}
|
|
listView1.Items.Add(lvi);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
private void button5_Click(object sender, EventArgs e)
|
|
{
|
|
for (int i = 0; i < listView1.Items.Count; i++)
|
|
{
|
|
listView1.Items[i].Checked = true;
|
|
}
|
|
}
|
|
|
|
private void button6_Click(object sender, EventArgs e)
|
|
{
|
|
for (int i = 0; i < listView1.Items.Count; i++)
|
|
{
|
|
listView1.Items[i].Checked = false;
|
|
}
|
|
}
|
|
|
|
private void button4_Click(object sender, EventArgs e)
|
|
{
|
|
int startRouteDeviceIndex = 3965;
|
|
//��ѯT_Base_Route ��F_EndDevice�Ƿ�Ϊ �Ǽ����豸
|
|
|
|
string sql = "SELECT F_RouteID, F_RouteName, F_StartDevice, F_EndDevice, F_RouteKind, F_OutsideAltDevice, F_InsideAltDevice, F_Status, F_AutoUpdate FROM T_Base_Route WHERE (F_EndDevice IN (15253, 15247, 15237, 15211, 15205, 14255, 14245, 14235, 14225, 14215, 14205)) AND (F_RouteID > 31)";
|
|
DataTable dt = dbo.ExceSQL(sql).Tables[0];
|
|
|
|
//��ѯ���ϱ���
|
|
if (dt.Rows.Count > 0)
|
|
{
|
|
for (int dtrowcount = 0; dtrowcount < dt.Rows.Count; dtrowcount++)
|
|
{
|
|
string sql1 = "SELECT F_RouteDeviceIndex, F_RouteID, F_RouteIDSub, F_DeviceIndex, F_SerialNumber, F_DeviceOrder, F_UseAwayFork FROM T_Base_Route_Device WHERE (F_RouteID = " + dt.Rows[dtrowcount]["F_RouteID"] + ") ORDER BY F_RouteDeviceIndex";
|
|
DataTable dtRoute = dbo.ExceSQL(sql1).Tables[0];
|
|
if (dtRoute.Rows.Count > 0)
|
|
{
|
|
for (int RouteCount = 0; RouteCount < dtRoute.Rows.Count; RouteCount++)
|
|
{
|
|
if (dtRoute.Rows[RouteCount]["F_DeviceIndex"].ToString() == dt.Rows[dtrowcount]["F_EndDevice"].ToString())
|
|
{
|
|
string sqlss = startRouteDeviceIndex.ToString() +","+ dt.Rows[dtrowcount]["F_RouteID"].ToString()+","+ dtRoute.Rows[RouteCount]["F_RouteIDSub"].ToString() +",17001,"+ (Convert.ToInt32(dtRoute.Rows[RouteCount]["F_SerialNumber"].ToString())+1).ToString();
|
|
string insertsql = "insert into T_Base_Route_Device(F_RouteDeviceIndex,F_RouteID,F_RouteIDSub,F_DeviceIndex,F_SerialNumber,F_DeviceOrder,F_UseAwayFork) values(" + sqlss + ",-1,'-') \r\n";
|
|
startRouteDeviceIndex++;
|
|
textBox1.Text += insertsql;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
//��ѯ����T_Base_Route��F_RouteID�� ��32��ʼ������F_RouteID��ѯT_Base_Route_Device ORder by F_RouteDeviceIndex
|
|
|
|
//���ݳ�����datatable,Ҫ֪�����˼���·������û��ϵ����F_DeviceIndex �Dz��ǵ����Ǽ����豸
|
|
|
|
//�����ǣ����ݿ��в���һ������ 3965 ��ʼ����ǰ��routeid����һ����idsub��17001����һ��+1��-1��-
|
|
//startRouteDeviceIndex++
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|