/** * * 初始化显示数据库已有信息列在UserList显示 * * * * */ private void Load_InfoList() { //Dictionary<String, int> ViewListHash = null; //List<Dictionary<String, String>> dataList = new List<Dictionary<string, string>>(); DataOp dataOp = new DataOp(this.oracleip, this.oracleport, this.database, this.userid, this.password); List <Collection_t> dataList = new List <Collection_t>(); //查询所有电表信息 OleDbDataReader data = dataOp.GetAllRowByTable("COLLECTOR_T"); while (data.Read()) { //Dictionary<String, String> dataListHash = new Dictionary<string,string>(); Collection_t collection_t = new Collection_t(data[0].ToString(), data[1].ToString(), data[2].ToString(), data[3].ToString(), data[4].ToString(), data[5].ToString(), data[6].ToString(), data[7].ToString(), data[8].ToString(), data[9].ToString()); //得到电表所属网关的ip地址 OleDbDataReader data_gateway = dataOp.GetRowByIndex("GATEWAY_T", "GATEWAY_ID", collection_t.Gateway_id); ////根据网关id查ip地址与端口: while (data_gateway.Read()) { collection_t.Address = data_gateway[2].ToString(); collection_t.Port = data_gateway[3].ToString(); collection_t.Active_net = data_gateway[5].ToString(); } dataList.Add(collection_t); } UpdateList(dataList); dataOp.Close(); }
/** * * 查询按钮触发事件 * * * * * */ private void search_Click(object sender, EventArgs e) { //根据选项查询一条完整记录并显示,更新列表 DataOp dataOp = new DataOp(this.oracleip, this.oracleport, this.database, this.userid, this.password); //得到大楼号 string building_name = building.Text; string building_id = dataOp.GetOneStrTypeByName("BUILDING_ID", "BUILDING_T", "BUILDING_NAME", building_name); //得到房间号 string room_name = room.Text; string room_id = dataOp.GetOneStrTypeByName("ROOM_ID", "ROOM_T", "ROOM_NAME", room_name); //得到选择查询的电表状态 string collect_state = collectState.Text; //根据大楼和房间号查询电表信息 string sql = null; //判断楼号与房间号是否为空,以及电表状态,生成合适的sql语句 if (building_id == null || room_id == null) { if (building_id == null && room_id == null) { if (collect_state == "") { sql = "select * from COLLECTOR_T"; } else { sql = "select * from COLLECTOR_T where STATE = '" + collect_state + "'"; } } else if (building_id != null) { if (collect_state == "") { sql = "select * from COLLECTOR_T where BUILDING_ID = " + building_id; } else { sql = "select * from COLLECTOR_T where BUILDING_ID = " + building_id + " and STATE = '" + collect_state + "'"; } } else { if (collect_state == "") { sql = "select * from COLLECTOR_T where ROOM_ID = " + room_id; } else { sql = "select * from COLLECTOR_T where ROOM_ID = " + room_id + " and STATE = '" + collect_state + "'"; } } } else { if (collect_state == "") { sql = "select * from COLLECTOR_T where BUILDING_ID = " + building_id + " and ROOM_ID = " + room_id; } else { sql = "select * from COLLECTOR_T where BUILDING_ID = " + building_id + " and ROOM_ID = " + room_id + " and STATE = '" + collect_state + "'"; } } //根据sql语句查询电表信息 OleDbDataReader data = dataOp.GetRowsBySql(sql); List <Collection_t> dataList = new List <Collection_t>();//暂存数据库数据 while (data.Read()) { //Dictionary<String, String> dataListHash = new Dictionary<string,string>(); Collection_t collection_t = new Collection_t(data[0].ToString(), data[1].ToString(), data[2].ToString(), data[3].ToString(), data[4].ToString(), data[5].ToString(), data[6].ToString(), data[7].ToString(), data[8].ToString(), data[9].ToString()); //得到电表所属网关的ip地址 OleDbDataReader data_gateway = dataOp.GetRowByIndex("GATEWAY_T", "GATEWAY_ID", collection_t.Gateway_id); ////根据网关id查ip地址与端口: while (data_gateway.Read()) { collection_t.Address = data_gateway[2].ToString(); collection_t.Port = data_gateway[3].ToString(); collection_t.Active_net = data_gateway[5].ToString(); } dataList.Add(collection_t); } UpdateList(dataList);//更新显示界面列表 //更新数据列表 dataOp.Close(); }