예제 #1
0
        // Create new athlete record
        private void btnCustNew_Click(object sender, EventArgs e)
        {
            try
            {
                //Fill Combo boxes with data from database
                this.Hide();
                AthleteForm newAthlete = new AthleteForm();

                con.Open();
                cmd.Connection  = con;
                cmd.CommandText = "sp_distinctCitysZipCountry";

                cmd.CommandType = CommandType.StoredProcedure;
                MySqlDataReader dr = cmd.ExecuteReader();

                while (dr.Read())
                {
                    newAthlete.cbZip.Items.Add(dr["Zip"].ToString());
                }

                con.Close();

                //Change labels on new customer form
                newAthlete.gbCustomer.Text        = "New Athlete";
                newAthlete.lblCustID.Text         = "0".ToString();
                newAthlete.lblLastupdate.Visible  = false;
                newAthlete.lblLastUpdated.Visible = false;
                AthleteForm.AddressID             = 0;
                newAthlete.tbAdd.Enabled          = true;
                newAthlete.tbPhone.Enabled        = true;
                newAthlete.cbZip.Enabled          = true;
                newAthlete.btnEditAddress.Visible = false;
                newAthlete.btnNewAddress.Visible  = false;
                newAthlete.ShowDialog();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);// print error message
            }
            finally
            {
                if (dr != null)
                {
                    dr.Close();
                }
                if (con.State == ConnectionState.Open)
                {
                    con.Close();
                }
            }
        }
예제 #2
0
        // View/Edit athlete record
        private void btnAthleteViewEdit_Click(object sender, EventArgs e)
        {
            try
            {
                if (indexOfSelectedAthlete >= 0)
                {
                    int currentAthleteID = (int)dgvAthlete.Rows[indexOfSelectedAthlete].Cells[0].Value;
                    this.Hide();
                    AthleteForm viewAthlete = new AthleteForm();
                    if (currentAthleteID > 0)
                    {
                        con.Open();

                        MySqlCommand cmd4 = new MySqlCommand("sp_distinctZip");
                        cmd4.Connection = con;
                        MySqlDataReader dr = cmd4.ExecuteReader();

                        while (dr.Read())
                        {
                            viewAthlete.cbZip.Items.Add(dr["postalCode"].ToString());
                        }
                        dr.Close();

                        cmd.Connection  = con;
                        cmd.CommandText = SetSp_AthleteID(IsCorner());// sp_AthleteByID;

                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.Clear();
                        cmd.Parameters.AddWithValue("@AthlID", currentAthleteID);
                        dr = cmd.ExecuteReader();

                        if (dr.Read())
                        {
                            viewAthlete.lblCustID.Text = dr["athleteId"].ToString();
                            viewAthlete.tbName.Text    = dr["athleteName"].ToString();

                            //viewAthlete.cbPosition.Items.Add(dr["athletePosition"].ToString());
                            viewAthlete.cbPosition.Text = dr["athletePosition"].ToString();
                            //viewAthlete.cbDiscipline.Items.Add(dr["athleteDiscipline"].ToString());
                            viewAthlete.cbDiscipline.Text = dr[athleteDiscipline].ToString();
                            //viewAthlete.cbDiscipline.Text = dr["athleteDiscipline"].ToString();
                            viewAthlete.tbPhone.Text        = dr["phone"].ToString();
                            viewAthlete.tbAdd.Text          = dr["address"].ToString();
                            viewAthlete.tbCity.Text         = dr["city"].ToString();
                            viewAthlete.tbCountry.Text      = dr["country"].ToString();
                            viewAthlete.cbZip.Text          = dr["postalCode"].ToString();
                            AthleteForm.AddressID           = Convert.ToInt32(dr["addressId"]);
                            viewAthlete.lblLastUpdated.Text = Schedule.GetCorrectedDate(Convert.ToDateTime(dr["lastUpdate"])).ToString();
                        }
                        con.Close();
                    }
                    viewAthlete.gbCustomer.Text = "Edit Athlete";
                    viewAthlete.ShowDialog();
                }
                else
                {
                    MessageBox.Show("Please select and Appointment to Edit the Athlete!");
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);// print error message
            }
            finally
            {
                if (dr != null)
                {
                    dr.Close();
                }
                if (con.State == ConnectionState.Open)
                {
                    con.Close();
                }
            }
        }