private void submitButton_Click(object sender, EventArgs e) { if (addNew) { SalesPerson sp = new SalesPerson(nameBox.Text, Int32.Parse(idBox.Text), passwordBox.Text, float.Parse(commissionBox.Text), addressBox.Text); em.addSalesPerson(sp); addNew = false; MessageBox.Show("Successfully added " + sp.getName()); } else { em.getCurrentSalesPerson().setAddress(addressBox.Text); em.getCurrentSalesPerson().setName(nameBox.Text); em.getCurrentSalesPerson().setPassword(passwordBox.Text); em.getCurrentSalesPerson().setEmpId(Int32.Parse(idBox.Text)); em.getCurrentSalesPerson().setCommission(float.Parse(commissionBox.Text)); em.updateSalesPerson(em.getCurrentSalesPerson()); MessageBox.Show("Successfully updated " + em.getCurrentSalesPerson().getName()); } }
public void addSalesPerson(SalesPerson sp) { if (this.connect()) { string query = "INSERT INTO salesperson (name,commission,address) VALUES ('" + sp.getName() + "','" + sp.getCommission() + "','" + sp.getAddress() + "')"; MySqlCommand cmd = new MySqlCommand(query, connection); cmd.ExecuteNonQuery(); query = "SELECT sid FROM salesperson WHERE name = " + sp.getName() + ";"; cmd = new MySqlCommand(query, connection); MySqlDataReader reader = cmd.ExecuteReader(); sp.setSId(reader.GetInt32(0)); query = "INSERT INTO employees (id,password,sid) VALUES ('" + sp.getEmpId() + "','" + sp.getPassword() + "','" + sp.getSId() + "')"; cmd = new MySqlCommand(query, connection); cmd.ExecuteNonQuery(); reader.Close(); } this.stopConnection(); }
public void selectSalesPerson(SalesPerson sp) { employee = sp; }