protected void btnUpdateClient(object sender, EventArgs e) { try { Person p = new Person(); p.Code = Convert.ToInt32(txtCode.Text); p.Name = Convert.ToString(txtName.Text); p.Address = Convert.ToString(txtAddress.Text); p.Email = Convert.ToString(txtEmail.Text); PersonDAL d = new PersonDAL(); d.Update(p); lblMessage.Text = "Update was done with success!"; txtCode.Text = string.Empty; txtName.Text = string.Empty; txtAddress.Text = string.Empty; txtEmail.Text = string.Empty; } catch (Exception ex) { lblMessage.Text = ex.Message; } }
public void btnRegister_Click(object sender, EventArgs e) { try { Person p = new Person(); p.Name = txtName.Text; p.Address = txtAddress.Text; p.Email = txtEmail.Text; PersonDAL d = new PersonDAL(); d.Insert(p); // record person lblMessage.Text = p.Name + "'s was registered with Success!!!"; txtName.Text = string.Empty; txtAddress.Text = string.Empty; txtEmail.Text = string.Empty; } catch (Exception ex) { lblMessage.Text = ex.Message; } }
public Person GetPersonCode(int code) { try { OpenConnection(); Cmd = new SqlCommand("select * from Person " + "where Code=@v1", Con); Cmd.Parameters.AddWithValue("@v1", code); Dr = Cmd.ExecuteReader(); Person p = null; if (Dr.Read()) { p = new Person(); p.Code = Convert.ToInt32(Dr["Code"]); p.Name = Convert.ToString(Dr["Name"]); p.Address = Convert.ToString(Dr["Address"]); p.Email = Convert.ToString(Dr["Email"]); } return p; } catch (Exception ex) { throw new Exception("Error when delete the person!" + ex.Message); } finally { CloseConnection(); } }
public bool ChangPW(string pid, string newPw) { Model.Person thePerson = Retrieve(pid); if (thePerson != null) { thePerson.Password = newPw; return(true); } return(false); }
/// <summary> /// 增加 /// </summary> /// <param name="person"></param> /// <returns></returns> public bool Add(Model.Person person) { for (int i = 0; i < persons.Count; i++) { if (person.ID == persons[i].ID) { return(false); } } persons.Add(person); return(true); }
public void Insert(Person p) { try { // Open Connection OpenConnection(); Cmd = new SqlCommand("insert into Person(Name,Address,Email) values (@v1, @v2, @v3)", Con); Cmd.Parameters.AddWithValue("@v1", p.Name); Cmd.Parameters.AddWithValue("@v2", p.Address); Cmd.Parameters.AddWithValue("@v3", p.Email); Cmd.ExecuteNonQuery(); } catch (Exception ex) { throw new Exception("Error when insert the person!" + ex.Message); } }
public void Update(Person p) { try { OpenConnection(); Cmd = new SqlCommand("Update Person set Name=@v1, Address=@v2, Email=@v3 " + "where Code=@v4", Con); Cmd.Parameters.AddWithValue("@v1", p.Name); Cmd.Parameters.AddWithValue("@v2", p.Address); Cmd.Parameters.AddWithValue("@v3", p.Email); Cmd.Parameters.AddWithValue("@v4", p.Code); Cmd.ExecuteNonQuery(); } catch (Exception ex) { throw new Exception("Error when update the person!" + ex.Message); } }
protected void btnDeleteClient(object sender, EventArgs e) { try { int Code = Convert.ToInt32(txtCode.Text); Person p = new Person(); PersonDAL d = new PersonDAL(); d.Delete(Code); lblMessage.Text = "Deleted Client!"; txtCode.Text = string.Empty; txtName.Text = string.Empty; txtAddress.Text = string.Empty; txtEmail.Text = string.Empty; } catch (Exception ex) { lblMessage.Text = ex.Message; } }
public List<Person> List() { try { OpenConnection(); Cmd = new SqlCommand("Select * from Person", Con); Dr = Cmd.ExecuteReader(); List<Person> list = new List<Person>(); // list null while(Dr.Read()) { Person p = new Person(); p.Code = Convert.ToInt32(Dr["Code"]); p.Name = Convert.ToString(Dr["Name"]); p.Address = Convert.ToString(Dr["Address"]); p.Email = Convert.ToString(Dr["Email"]); list.Add(p); } return list; } catch (Exception ex) { throw new Exception("Error when list person!" + ex.Message); } }