private void AlterGroup() { AlteringGroup = elementBase.SelectRoleWhere(this.GroupId); this.NameT.Text = AlteringGroup.Name; this.DescriptionT.Text = AlteringGroup.Description; this.rolesSelector.SelectedValue = AlteringGroup.id_role; }
//================================================= //запросы по группам public GlobalClass.GroupsCreateMapper SelectRoleWhere(int id) { string query = @"select a.ID, b.Name, b.Description, a.ID_info, a.ID_role FROM usergroup as a JOIN group_info as b ON b.ID = a.ID_info where a.ID = " + id.ToString() + " limit 1"; GlobalClass.GroupsCreateMapper tempGroup = new GlobalClass.GroupsCreateMapper(); if (this.openConnection() == true) { MySqlCommand cmd = new MySqlCommand(query, dbConnect); MySqlDataReader dataReader = cmd.ExecuteReader(); //Read the data and store them in the list while (dataReader.Read()) { int II = (int)((long)dataReader["ID_info"]); int IR = (int)((long)dataReader["ID_role"]); int I = (int)((long)dataReader["ID"]); string N = (string)dataReader["Name"]; string D = (string)dataReader["Description"]; tempGroup = new GlobalClass.GroupsCreateMapper(I, N, D, II, IR); } //close Data Reader dataReader.Close(); //close Connection this.CloseConnection(); //return list to be displayed return(tempGroup); } else { return(tempGroup); } }
public void UpdateGroup(GlobalClass.GroupsCreateMapper AlteringGroup) { //Open connection if (this.openConnection() == true) { MySqlCommand cmd = new MySqlCommand(); cmd.Connection = dbConnect; string query = @"UPDATE user_info SET Name='" + AlteringGroup.Name + @"', Description='" + AlteringGroup.Description + @"' WHERE ID=" + AlteringGroup.id_info; cmd.CommandText = query; cmd.ExecuteNonQuery(); query = @"UPDATE usergroup SET ID_role=" + AlteringGroup.id_role + @" WHERE ID=" + AlteringGroup.ID; cmd.CommandText = query; cmd.ExecuteNonQuery(); //close connection this.CloseConnection(); } }
public void InsertGroup(GlobalClass.GroupsCreateMapper InsertingGroup) { if (this.openConnection() == true) { MySqlCommand cmd = new MySqlCommand(); cmd.Connection = dbConnect; string query = @"INSERT INTO user_info (`Name`,`Description`) VALUES ('" + InsertingGroup.Name + "','" + InsertingGroup.Description + "')"; cmd.CommandText = query; cmd.ExecuteNonQuery(); long inserted_id = -1; inserted_id = cmd.LastInsertedId; if (inserted_id > -1) { query = @"INSERT INTO aquser (`ID_info`,`ID_role`) VALUES ('" + inserted_id + "','" + InsertingGroup.id_role + "')"; cmd.CommandText = query; cmd.ExecuteNonQuery(); } //close connection this.CloseConnection(); } }