示例#1
0
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            //存储历史记录
            //保存定位器数据
            string sErrorMsg = "";

            foreach (KeyValuePair <string, Point> kv in this._dictReaderLoc)
            {
                string msg;
                if (!XMLDal.SaveDataToXML("reader", "data", "readerID", kv.Key, kv.Value.X + "-" + kv.Value.Y, out msg))
                {
                    sErrorMsg += msg + "\r\n";
                }
            }

            if (!string.IsNullOrEmpty(sErrorMsg))
            {
                MessageBox.Show("保存定位器坐标失败!错误详细:\r\n" + sErrorMsg);
                sErrorMsg = "";
            }
        }
示例#2
0
        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();
        }