Exemplo n.º 1
0
 private void btnClients_Click(object sender, EventArgs e)
 {
     frmViewClients frm = new frmViewClients();
     this.Hide();
     frm.ListClientsOrFilter(false);
     if (frm.ShowDialog(this) == DialogResult.OK)
     {
         this.Show();
     }
 }
Exemplo n.º 2
0
        public ClientHandler(ClientInfo client, frmViewClients.SaveOrUpdateOrDelete saveOrUpdateDelete, out bool success)
        {
            if (saveOrUpdateDelete == frmViewClients.SaveOrUpdateOrDelete.Save)
            {
                qry = "INSERT INTO clients (FirstName,LastName,Street,City,Province,Zip,E_Mail,Books_purchased,Books_hired) " +
                    "VALUES (@FirstName,@LastName,@Street,@City,@Province,@Zip,@E_Mail,@Books_purchased,@Books_hired)";
            }
            else if (saveOrUpdateDelete == frmViewClients.SaveOrUpdateOrDelete.Update)
            {
                qry = "UPDATE clients SET FirstName = @FirstName,LastName = @LastName,Street = @Street,City = @City,Province = @Province," +
                "Zip = @Zip,E_Mail = @E_Mail,Books_purchased = @Books_purchased,Books_hired = Books_hired WHERE FirstName = @FirstName";
            }
            else
            {
                qry = "DELETE FROM clients WHERE FirstName = @FirstName";
            }

            using (MySqlConnection Connection = new MySqlConnection(MyConString))
            {
                success = false;

                try
                {
                    MySqlCommand cmd = new MySqlCommand(qry, Connection);
                    cmd.Parameters.Add(new MySqlParameter("@FirstName", (object)client.FirstName));
                    cmd.Parameters.Add(new MySqlParameter("@LastName", (object)client.LastName));
                    cmd.Parameters.Add(new MySqlParameter("@Street", (object)client.Street));
                    cmd.Parameters.Add(new MySqlParameter("@City", (object)client.City));
                    cmd.Parameters.Add(new MySqlParameter("@Province", (object)client.Province));
                    cmd.Parameters.Add(new MySqlParameter("@Zip", (object)client.Zip));
                    cmd.Parameters.Add(new MySqlParameter("@E_Mail", (object)client.E_Mail));
                    cmd.Parameters.Add(new MySqlParameter("@Books_purchased", (object)client.Books_purchased));
                    cmd.Parameters.Add(new MySqlParameter("@Books_hired", (object)client.Books_hired));

                    Connection.Open();
                    cmd.ExecuteNonQuery();
                    success = true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Database Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    Connection.Close();
                }
            }
        }