public void AddMember(Member member) { if (this.bll.AddMember(member)) { this.view.ShowMessage("Successfully added member."); } else { this.view.ShowMessage("Error adding member."); } }
public bool AddMember(Member member) { try { return this.dll.CreateMember(member); } catch (Exception ex) { Console.WriteLine(ex.Message); return false; } }
private void btnAdd_Click(object sender, EventArgs e) { Member member = new Member(); member.firstname = this.txtFirstName.Text; member.lastname = this.txtLastName.Text; member.middleInitial= this.txtMiddleInt.Text; member.address = this.txtAddress.Text; member.city = this.txtCity.Text; member.state = this.txtState.Text; member.zip = this.txtZip.Text; this.controller.AddMember(member); }
public bool CreateMember(Member member) { using (OleDbConnection con = new OleDbConnection(this.connectionString)) { con.Open(); using (OleDbCommand cmd = new OleDbCommand("INSERT INTO Members (lastname, firstname, middleInitial, suffix, address, city, state, zip) VALUES "+ "(@lastname, @firstname, @middleInitial, @suffix, @address, @city, @state, @zip)", con)) { OleDbParameter lastName = new OleDbParameter("@lastname", OleDbType.VarChar); lastName.Value = member.lastname; cmd.Parameters.Add(lastName); OleDbParameter firstName = new OleDbParameter("@firstname", OleDbType.VarChar); firstName.Value = member.firstname; cmd.Parameters.Add(firstName); OleDbParameter midInit = new OleDbParameter("@middleInitial", OleDbType.VarChar); midInit.Value = member.middleInitial; cmd.Parameters.Add(midInit); OleDbParameter suffix = new OleDbParameter("@suffix", OleDbType.VarChar); suffix.Value = member.suffix; cmd.Parameters.Add(suffix); OleDbParameter address = new OleDbParameter("@address", OleDbType.VarChar); address.Value = member.address; cmd.Parameters.Add(address); OleDbParameter city = new OleDbParameter("@city", OleDbType.VarChar); city.Value = member.city; cmd.Parameters.Add(city); OleDbParameter state = new OleDbParameter("@state", OleDbType.VarChar); state.Value = member.state; cmd.Parameters.Add(state); OleDbParameter zip = new OleDbParameter("@zip", OleDbType.VarChar); zip.Value = member.zip; cmd.Parameters.Add(zip); int numRows = cmd.ExecuteNonQuery(); return numRows != 0; } } }
public List<Member> ReadAllMembers() { List<Member> members = new List<Member>(); using (OleDbConnection con = new OleDbConnection(this.connectionString)) { con.Open(); using (OleDbCommand cmd = new OleDbCommand("SELECT id, lastname, firstname, middleInitial, suffix, address, city, state, zip FROM Members", con)) { var reader = cmd.ExecuteReader(); while (reader.Read()) { Member member = new Member(); member.id = (int)reader.GetValue(0); member.lastname = (string)reader.GetValue(1); member.firstname = (string)reader.GetValue(2); member.middleInitial = (string)reader.GetValue(3); member.address = (string)reader.GetValue(4); member.city = (string)reader.GetValue(5); member.state = (string)reader.GetValue(6); member.zip = (string)reader.GetValue(7); members.Add(member); } } } return members; }