private void CalulateLocation(UDPData data, out int x, out int y) { if (string.IsNullOrEmpty(data.Loc[0].ReferNo)) { x = y = -1; return; } else { for (int ii = 0; ii < 3; ii++) { for (int jj = 0; jj < _dictReaderLoc.Count; jj++) { if (data.Loc[ii].ReferNo == _dictReaderLoc.Keys.ElementAt(jj)) { if (_dictTag.ContainsKey(jj)) { _dictTag[jj] = data.Loc[ii].Destance; } else { _dictTag.Add(jj, data.Loc[ii].Destance); } break; } } } Point pt = CaculateLocation.OutputResultLocation(_dictTag); x = pt.X; y = pt.Y; } }
private void ImportSampleData() { int[][] iSamples = new int[][] { new int[] { 45, 18, 29, 28, 16, 17, 16, 0 }, new int[] { 40, 31, 33, 29, 29, 0, 0, 0 }, new int[] { 35, 42, 27, 39, 21, 16, 0, 0 }, new int[] { 33, 0, 45, 20, 26, 0, 27, 0 }, new int[] { 32, 0, 38, 23, 23, 0, 0, 0 }, new int[] { 0, 32, 28, 46, 0, 25, 0, 0 }, new int[] { 37, 0, 30, 0, 32, 0, 25, 0 }, new int[] { 0, 19, 34, 28, 0, 0, 0, 0 }, new int[] { 29, 19, 16, 49, 0, 28, 0, 18 }, new int[] { 0, 0, 40, 0, 36, 0, 35, 21 }, new int[] { 0, 0, 24, 0, 32, 38, 23, 0 }, new int[] { 0, 0, 0, 23, 26, 42, 0, 37 }, new int[] { 0, 0, 26, 0, 0, 29, 33, 28 }, new int[] { 0, 0, 0, 0, 44, 30, 25, 29 }, new int[] { 21, 0, 0, 28, 21, 49, 0, 43 }, new int[] { 0, 0, 32, 0, 39, 37, 35, 32 }, new int[] { 0, 0, 0, 0, 22, 23, 25, 23 }, new int[] { 0, 0, 0, 18, 24, 39, 0, 38 } }; for (int ii = 0; ii < iSamples.Length; ii++) { int x = ii % 3, y = ii / 3; for (int jj = 0; jj < 8; jj++) { CaculateLocation.InputStudyLocation(jj, iSamples[ii][jj], new Point(x, y)); } } }
private void Form1_Load(object sender, EventArgs e) { //初始化地图 _sMapPath = System.IO.Path.GetFullPath(Program.GetAppSettingValue("MapPath", "./Map/Map.jpg")); string sDir = System.IO.Path.GetDirectoryName(_sMapPath); if (!System.IO.Directory.Exists(sDir)) { System.IO.Directory.CreateDirectory(sDir); } if (System.IO.File.Exists(_sMapPath)) { System.IO.FileStream fs = new System.IO.FileStream(_sMapPath, System.IO.FileMode.Open); try { Image img = Image.FromStream(fs); this.panMap.BackgroundImage = img; } catch { MessageBox.Show("加载图片失败!"); return; } finally { fs.Close(); fs.Dispose(); } } //初始化参考点坐标 string msg; var dict = XMLDal.GetXMLDatas("reader", "data", "readerID", out msg); if (dict != null && dict.Count > 0) { foreach (KeyValuePair <string, string> kv in dict) { string[] sLoc = kv.Value.Split('-'); if (sLoc.Length != 2) { continue; } else { AddNewReaderLoc(kv.Key, Color.Red, new Point(Convert.ToInt32(sLoc[0]), Convert.ToInt32(sLoc[1]))); } } } //初始化IP和端口信息 this.tbIP.Text = Program.GetAppSettingValue("DefaultIP", ""); this.tbPort.Text = Program.GetAppSettingValue("DefaultPortNo", ""); //初始化udp监听端口 _portListen = Convert.ToInt32(Program.GetAppSettingValue("ListenPort", "8567")); //初始化表格 dtData = new DataTable(); dtData.Columns.AddRange(new DataColumn[] { new DataColumn("RowNo", typeof(int)), new DataColumn("TagNo", typeof(string)), new DataColumn("ReferNo1", typeof(string)), new DataColumn("Distance1", typeof(int)), new DataColumn("ReferNo2", typeof(string)), new DataColumn("Distance2", typeof(int)), new DataColumn("ReferNo3", typeof(string)), new DataColumn("Distance3", typeof(int)), new DataColumn("ReadDate", typeof(DateTime)) }); this.dgData.AutoGenerateColumns = false; this.dgData.DataSource = dtData; //初始化定位网格大小 CaculateLocation.SetGridSize(3, 6); ImportSampleData(); }