private void btn_add_Click(object sender, EventArgs e) { model.MhxyMapRegion m = new model.MhxyMapRegion(); m.x = Convert.ToInt32(txt_left_x.Text.Trim()); m.y = Convert.ToInt32(txt_left_y.Text.Trim()); m.max_x = Convert.ToInt32(txt_right_x.Text.Trim()); m.max_y = Convert.ToInt32(txt_right_y.Text.Trim()); m.name = txt_map_name.Text.Trim(); m.map_id = map_id; if (m.max_x < m.x) { MessageBox.Show("右下X必须大于左上X"); return; } if (m.y < m.max_y) { MessageBox.Show("左上Y须大于右下Y"); return; } m.Save(); loadMap(); MessageBox.Show("保存成功"); }
/// <summary> /// 获取全部数据 /// </summary> /// <returns></returns> public static List <MhxyMapRegion> GetMapAll() { List <MhxyMapRegion> ret = new List <MhxyMapRegion>(); string sql = "select * from mhxy_map_region"; SQLiteConnection conn = SQLiteUtil.GetConn(); conn.Open(); DataSet ds = SQLiteHelper.ExecuteDataSet(conn, sql, null); conn.Close(); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { MhxyMapRegion m = new MhxyMapRegion(); m.id = Convert.ToInt32(ds.Tables[0].Rows[i]["id"].ToString()); m.map_id = Convert.ToInt32(ds.Tables[0].Rows[i]["map_id"].ToString()); m.name = ds.Tables[0].Rows[i]["name"].ToString(); m.x = Convert.ToInt32(ds.Tables[0].Rows[i]["x"].ToString()); m.y = Convert.ToInt32(ds.Tables[0].Rows[i]["y"].ToString()); m.max_x = Convert.ToInt32(ds.Tables[0].Rows[i]["max_x"].ToString()); m.max_y = Convert.ToInt32(ds.Tables[0].Rows[i]["max_y"].ToString()); ret.Add(m); } return(ret); }