/** * 从数据库里面查出所有的数据,展示。 * */ private void showAllLandStation() { List <Dictionary <string, object> > result = ProfileHelper.Instance.Select("SELECT * FROM LandStation"); landStationList.Clear(); foreach (Dictionary <string, object> dictionary in result) { String mainLandStation = ConfigHelper.Instance.GetConfig("land_station_main_name"); int id = Convert.ToInt32(dictionary["ID"]); String name = Convert.ToString(dictionary["Name"]); String ip = Convert.ToString(dictionary["IP"]); double lat = Convert.ToDouble(dictionary["Lat"]); double lang = Convert.ToDouble(dictionary["Lng"]); double length = Convert.ToDouble(dictionary["Length"]); int num = Convert.ToInt16(dictionary["Num"]); Boolean cb_check = false; if (!string.IsNullOrEmpty(mainLandStation) && mainLandStation.Equals(name)) { cb_check = true; } Land_Station land_Station = new Land_Station(cb_check, id, name, ip, lat, lang, length, num); landStationList.Add(land_Station); } this.dataGridView1.DataSource = null; if (null != landStationList && landStationList.Count() > 0) { this.dataGridView1.DataSource = this.landStationList; } //showMainLandStaion(); }
private void skinButton1_Click(object sender, EventArgs e) { String name = skinTextBox2.Text; if (null == name || name.Length == 0) { MessageBox.Show("请输入名称!"); return; } if (null == skinTextBox1.Text || skinTextBox1.Text.Length == 0) { MessageBox.Show("请输入IP!"); return; } if (null == skinTextBox3.Text || skinTextBox3.Text.Length == 0) { MessageBox.Show("请输入经纬度!"); return; } if (null == skinTextBox4.Text || skinTextBox4.Text.Length == 0) { MessageBox.Show("请输入经纬度!"); return; } if (null == skinTextBox5.Text || skinTextBox5.Text.Length == 0) { MessageBox.Show("请输入环数!"); return; } if (null == skinTextBox6.Text || skinTextBox6.Text.Length == 0) { MessageBox.Show("请输入环距离!"); return; } Land_Station land_Station = new Land_Station( false, 0, name, Convert.ToString(skinTextBox1.Text), Convert.ToDouble(skinTextBox3.Text), Convert.ToDouble(skinTextBox4.Text), Convert.ToDouble(skinTextBox6.Text), Convert.ToInt16(skinTextBox5.Text)); if (skinLabel6.Text.Equals("ID")) { // 插入数据库 ProfileHelper.Instance.Update( "INSERT INTO LandStation (ID, Name, IP, Lat, Lng, Num, Length) VALUES ( NULL, '" + land_Station.Name + "', '" + land_Station.IP + "', " + land_Station.Lat + ", " + land_Station.Lng + ", " + land_Station.Num + ", " + land_Station.Length + ")"); } else if (!string.IsNullOrWhiteSpace(skinLabel6.Text)) { // 更新数据库 ProfileHelper.Instance.Update( "UPDATE LandStation set " + " Name = '" + land_Station.Name + "', " + " IP = '" + land_Station.IP + "', " + " Lat = " + land_Station.Lat + ", " + " Lng = " + land_Station.Lng + ", " + " Num = " + land_Station.Num + ", " + " Length = " + land_Station.Length + " where ID = '" + skinLabel6.Text + "'"); // 更新后初始化组件 skinTextBox1.Text = ""; skinTextBox2.Text = ""; skinTextBox3.Text = ""; skinTextBox4.Text = ""; skinTextBox5.Text = ""; skinTextBox6.Text = ""; skinButton1.Text = "新增"; } showAllLandStation(); landStation_event(true, 2); }