分析那个二进制文件真是复杂啊....费了不少脑筋。
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
namespace WindowsApplication1
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
public partial class Form1 : Form
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
public Form1()
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
InitializeComponent();
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
int x = 0;
int y = 0;
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
//private void button1_Click(object sender, EventArgs e)
//{
// Form2 frm = new Form2();
// frm.Pos = new Point(x, y);
// frm.Show();
//}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
//private void Form1_MouseMove(object sender, MouseEventArgs e)
//{
// x = e.X;
// y = e.Y;
//}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
private void 输入编号ToolStripMenuItem_Click(object sender, EventArgs e)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
Form2 frm = new Form2();
frm.Pos = new Point(x, y);
frm.Show();
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
//private void Form1_MouseDown(object sender, MouseEventArgs e)
//{
// x = e.X;
// y = e.Y;
//}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
x = e.X;
y = e.Y;
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
private void 查看编号ToolStripMenuItem_Click(object sender, EventArgs e)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
Form3 frm = new Form3();
frm.Pos = new Point(x, y);
frm.Show();
}
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
//using System.Data;
using System.Data.SqlClient;
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
namespace WindowsApplication1
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
public partial class Form2 : Form
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
private Point pos;
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
public Point Pos
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{ return pos; }//获得鼠标的xy坐标
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
set
{ pos = value; }
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
public Form2()
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
InitializeComponent();
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
private void Form2_Load(object sender, EventArgs e)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
textBox1.Text = pos.X.ToString();
textBox2.Text = pos.Y.ToString();
textBox1.Enabled = false;
textBox2.Enabled = false;
//MessageBox.Show("单击form1上的Button时鼠标位置为:x="+pos.X.ToString()+";y="+pos.Y.ToString());
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
private void button1_Click(object sender, EventArgs e)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
int xstart = pos.X;//元件x的起始坐标
int ystart = pos.Y;
int xend=0; //元件x的终止坐标
int yend=0;
string lei= comboBox1.Text;
if (textBox3.Text.Length > 0 && lei.Length > 0)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
string leiBie = comboBox1.SelectedItem.ToString();
SqlConnection myConnection = new SqlConnection("server=localhost;database=sdg;uid=sa;pwd=sa");
string strCom = "select * from device where xstart<=" + xstart + " and xend>="+xstart+" and ystart<="+ystart+" and yend>="+ystart+"";
//" + xend + ">" + xstart + "and and" + yend + ">" + ystart + "and"+xend +">"+pos .X +"and"+yend +">"+pos .Y +"
DataSet mydataset = new DataSet();
myConnection.Open();
SqlDataAdapter myCommand = new SqlDataAdapter(strCom, myConnection);
myCommand.Fill(mydataset, "info");
if (mydataset.Tables["info"].Rows.Count == 0)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
//switch (leiBie)
//{
// case "柜门":
//}
if (leiBie == "柜门")
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
xend = xstart + 11;
yend = ystart + 11;
SqlCommand com = new SqlCommand("insert into device values (1," + xstart + "," + xend + "," + ystart + "," + yend + ",'" + textBox3.Text.Trim() + "','" + comboBox1.SelectedItem + "') ", myConnection);
com.ExecuteNonQuery();
}
else if (leiBie == "断路器")
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
xend = xstart + 16;
yend = ystart + 16;
SqlCommand com = new SqlCommand("insert into device values (1," + xstart + "," + xend + "," + ystart + "," + yend + ",'" + textBox3.Text.Trim() + "','" + comboBox1.SelectedItem + "') ", myConnection);
com.ExecuteNonQuery();
}
else if (leiBie == "横刀闸")
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
xend = xstart + 27;
yend = ystart + 7;
SqlCommand com = new SqlCommand("insert into device values (1," + xstart + "," + xend + "," + ystart + "," + yend + ",'" + textBox3.Text.Trim() + "','" + comboBox1.SelectedItem + "') ", myConnection);
com.ExecuteNonQuery();
}
else if (leiBie == "竖刀闸")
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
xend = xstart + 7;
yend = ystart + 27;
SqlCommand com = new SqlCommand("insert into device values (1," + xstart + "," + xend + "," + ystart + "," + yend + ",'" + textBox3.Text.Trim() + "','" + comboBox1.SelectedItem + "') ", myConnection);
com.ExecuteNonQuery();
}
else if (leiBie == "手车")
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
xend = xstart + 15;
yend = ystart + 15;
SqlCommand com = new SqlCommand("insert into device values (1," + xstart + "," + xend + "," + ystart + "," + yend + ",'" + textBox3.Text.Trim() + "','" + comboBox1.SelectedItem + "') ", myConnection);
com.ExecuteNonQuery();
}
}
else
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
//textBox1.Text = mydataset.Tables["xstart"].Rows.ToString ();
//textBox2.Text = mydataset.Tables["ystart"].Rows.ToString ();
//textBox3.Text = mydataset.Tables["num"].Rows.ToString ();
MessageBox.Show("此位置已经有数据,请选择另一个地方", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
myConnection.Close();
}
else if (lei.Length == 0)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
MessageBox.Show("请选择类别编号", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
comboBox1.Focus();
}
else if (textBox3.Text.Trim ().Length == 0)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
MessageBox.Show("请输入编号", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
textBox3.Focus();
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
private void button2_Click(object sender, EventArgs e)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
this.Close();
}
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
namespace WindowsApplication1
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
public partial class Form3 : Form
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
private Point pos;
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
public Point Pos
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{ return pos; }//获得鼠标的xy坐标
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
set
{ pos = value; }
}
public Form3()
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
InitializeComponent();
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
private void Form3_Load(object sender, EventArgs e)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
try
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
int xstart = pos.X;//元件x的起始坐标
int ystart = pos.Y;
SqlConnection myConnection = new SqlConnection("server=localhost;database=sdg;uid=sa;pwd=sa");
string strCom = "select top 1 * from device where xstart<=" + xstart + " and xend>=" + xstart + " and ystart<=" + ystart + " and yend>=" + ystart + "";
// //" + xend + ">" + xstart + "and and" + yend + ">" + ystart + "and"+xend +">"+pos .X +"and"+yend +">"+pos .Y +"
DataSet mydataset = new DataSet();
myConnection.Open();
SqlDataAdapter myCommand = new SqlDataAdapter(strCom, myConnection);
myCommand.Fill(mydataset, "info");
if (mydataset.Tables["info"].Rows.Count == 1)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
//textBox1 .Text =mydataset .Tables ["num"].Rows.ToString ();
}
else
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
MessageBox.Show("不存在", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
catch(Exception ex)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{ MessageBox.Show(ex.ToString ()); }
}
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)