public ModifyCustomerForm(Customer c) //initialize the inputs for textboxes using existing data { InitializeComponent(); lblCustomerIDMod.Text = c.CustomerID.ToString(); tbCustomerFNameMod.Text = c.Forename; tbCustomerLNameMod.Text = c.Surname; tbCustomerAddressMod.Text = c.Address; tbCustomerPostalMod.Text = c.Postal; tbCustomerPostOfficeMod.Text = PostUtils.GetPostOffice(c.Postal); tbCustomerEmailMod.Text = c.Email; tbCustomerPhoneMod.Text = c.Phone; }
private void btnAdd_Click(object sender, EventArgs e) //add a new customer to the database { PostUtils.CheckPostal(tbCustomerPostalAdd.Text, tbCustomerPostOfficeAdd.Text); ConnectionUtils.OpenConnection(); string query3 = "START TRANSACTION; " + "INSERT INTO asiakas(asiakas_id,postinro,etunimi,sukunimi,lahiosoite,email,puhelinnro) " + "VALUES(default,'" + TextBoxUtils.ModifyInput(tbCustomerPostalAdd.Text, tbCustomerPostalAdd.MaxLength) + "','" + TextBoxUtils.ModifyInput(tbCustomerFNameAdd.Text, tbCustomerFNameAdd.MaxLength) + "','" + TextBoxUtils.ModifyInput(tbCustomerLNameAdd.Text, tbCustomerLNameAdd.MaxLength) + "','" + TextBoxUtils.ModifyInput(tbCustomerAddressAdd.Text, tbCustomerAddressAdd.MaxLength) + "','" + TextBoxUtils.ModifyInput(tbCustomerEmailAdd.Text, tbCustomerEmailAdd.MaxLength) + "','" + TextBoxUtils.ModifyInput(tbCustomerPhoneAdd.Text, tbCustomerPhoneAdd.MaxLength) + "'); " + "COMMIT;"; MySqlCommand command3 = new MySqlCommand(query3, ConnectionUtils.connection); command3.ExecuteNonQuery(); ConnectionUtils.CloseConnection(); this.Close(); }
private void Fill_customer_values() // Fill customer data function { if (tbBookCustomerEmail.Text == "") { tbBookCustomerEmail.Text = TextBoxUtils.ModifyInput(dt.Rows[currentcustomer].Field <string>("email").ToString(), tbBookCustomerEmail.MaxLength); } else if (tbBookCustomerPhone.Text == "") { tbBookCustomerPhone.Text = TextBoxUtils.ModifyInput(dt.Rows[currentcustomer].Field <string>("puhelinnro"), tbBookCustomerPhone.MaxLength); } tbBookCustomerName.Text = TextBoxUtils.ModifyInput(dt.Rows[currentcustomer].Field <string>("etunimi").ToString(), tbBookCustomerName.MaxLength); tbBookCustomerLastname.Text = TextBoxUtils.ModifyInput(dt.Rows[currentcustomer].Field <string>("sukunimi").ToString(), tbBookCustomerLastname.MaxLength); tbBookCustomerAddress.Text = TextBoxUtils.ModifyInput(dt.Rows[currentcustomer].Field <string>("lahiosoite").ToString(), tbBookCustomerAddress.MaxLength); tbBookCustomerPostnumber.Text = TextBoxUtils.ModifyInput(dt.Rows[currentcustomer].Field <string>("postinro").ToString(), tbBookCustomerPostnumber.MaxLength); tbBookCustomerPostOffice.Text = TextBoxUtils.ModifyInput(PostUtils.GetPostOffice(dt.Rows[currentcustomer].Field <string>("postinro").ToString()), tbBookCustomerPostOffice.MaxLength); customerid = dt.Rows[currentcustomer].Field <int>("asiakas_id"); lblBookCustomerID.Visible = true; lblBookCustomerID.Text = "Asiakas ID: " + customerid.ToString(); }
private void btnModify_Click(object sender, EventArgs e) //modifies the customer's data according to the textbox inputs { DialogResult res = MessageBox.Show("Haluatko varmasti muuttaa valitun asiakkaan tietoja?", "Muuta asiakkaan tietoja", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (res == DialogResult.Yes) { PostUtils.CheckPostal(tbCustomerPostalMod.Text, tbCustomerPostOfficeMod.Text); string query = "START TRANSACTION; " + "UPDATE asiakas " + "SET postinro='" + TextBoxUtils.ModifyInput(tbCustomerPostalMod.Text, tbCustomerPostalMod.MaxLength) + "',etunimi='" + TextBoxUtils.ModifyInput(tbCustomerFNameMod.Text, tbCustomerFNameMod.MaxLength) + "',sukunimi='" + TextBoxUtils.ModifyInput(tbCustomerLNameMod.Text, tbCustomerLNameMod.MaxLength) + "',lahiosoite='" + TextBoxUtils.ModifyInput(tbCustomerAddressMod.Text, tbCustomerAddressMod.MaxLength) + "'," + "email='" + TextBoxUtils.ModifyInput(tbCustomerEmailMod.Text, tbCustomerEmailMod.MaxLength) + "',puhelinnro='" + TextBoxUtils.ModifyInput(tbCustomerPhoneMod.Text, tbCustomerPhoneMod.MaxLength) + "' " + "WHERE asiakas_id=" + lblCustomerIDMod.Text + "; " + "COMMIT;"; ConnectionUtils.OpenConnection(); MySqlCommand command = new MySqlCommand(query, ConnectionUtils.connection); command.ExecuteNonQuery(); ConnectionUtils.CloseConnection(); this.Close(); } }
private void btnBookAddResirvation_Click(object sender, EventArgs e) // new book adding { if (tbBookCustomerEmail.Text == "" || tbBookCustomerPhone.Text == "" || tbBookCustomerName.Text == "" || tbBookCustomerLastname.Text == "" || tbBookCustomerPostnumber.Text == "" || tbBookCustomerPostOffice.Text == "" || tbBookCustomerAddress.Text == "") { MessageBox.Show("Kaikki asiakastiedot pitäisi olla täyetty.", "Tiedot puuttuu", MessageBoxButtons.OK, MessageBoxIcon.Error); return; // If some customer data not specified, cancel action } string queryCustomer, services = "\n\nLisäpalvelut:\n"; if (customerid != 0) //If customer finded, update it { PostUtils.CheckPostal(tbBookCustomerPostnumber.Text, tbBookCustomerPostOffice.Text); ConnectionUtils.OpenConnection(); MySqlCommand command = new MySqlCommand("SELECT toimipaikka FROM posti WHERE postinro='" + tbBookCustomerPostnumber.Text + "'", ConnectionUtils.connection); tbBookCustomerPostOffice.Text = command.ExecuteScalar().ToString(); ConnectionUtils.CloseConnection(); queryCustomer = "START TRANSACTION; " + "UPDATE asiakas SET etunimi='" + tbBookCustomerName.Text + "', sukunimi='" + tbBookCustomerLastname.Text + "', " + "lahiosoite='" + tbBookCustomerAddress.Text + "', postinro='" + tbBookCustomerPostnumber.Text + "', " + "email='" + tbBookCustomerEmail.Text + "', puhelinnro='" + tbBookCustomerPhone.Text + "' " + "WHERE asiakas_id='" + customerid + "'; " + "COMMIT;"; } else // if customer not finded, add new { PostUtils.CheckPostal(tbBookCustomerPostnumber.Text, tbBookCustomerPostOffice.Text); queryCustomer = "START TRANSACTION; " + "INSERT INTO asiakas(asiakas_id,postinro,etunimi,sukunimi,lahiosoite,email,puhelinnro) " + "VALUES(default,'" + tbBookCustomerPostnumber.Text + "','" + tbBookCustomerName.Text + "','" + tbBookCustomerLastname.Text + "','" + tbBookCustomerAddress.Text + "','" + tbBookCustomerEmail.Text + "','" + tbBookCustomerPhone.Text + "'); " + "COMMIT;"; } foreach (DataGridViewRow row in dgvBookServices.Rows) // Get services { if (Convert.ToInt32(row.Cells["kpl"].Value) != 0) { services += row.Cells["nimi"].Value.ToString() + " - " + row.Cells["kpl"].Value.ToString() + "kpl\n"; } } if (services == "\n\nLisäpalvelut:\n") // If all services are 0, erase services { services = ""; } // Book/order overview window DialogResult res = MessageBox.Show("\t\tYhteenveto \n\nMökki tiedot:" + "\nAlue: \t\t" + lblBookAlue.Text + "\nMökki ID: \t" + lblBookCottageId.Text + "\nMajoitusaika: \t" + lblBookBookingDateFrom.Text + " - " + lblBookBookingDateTo.Text + " " + lblBookDays.Text + "\nOsoite: \t\t" + lblBookCottageAddress.Text + "\n\nAsiakas tiedot: " + "\nNimi: \t\t" + tbBookCustomerName.Text + " " + tbBookCustomerLastname.Text + "\nOsoite: \t\t" + tbBookCustomerAddress.Text + ", " + tbBookCustomerPostnumber.Text + ", " + tbBookCustomerPostOffice.Text + "\nSähköposti: \t" + tbBookCustomerEmail.Text + "\nPuhelinnumero: \t" + tbBookCustomerPhone.Text + services + "\n\nSumma yhteensä: " + lblBookPriceFull.Text, "Yhteenveto", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); if (res == DialogResult.OK) { try { ConnectionUtils.OpenConnection(); MySqlCommand command1 = new MySqlCommand(queryCustomer, ConnectionUtils.connection); command1.ExecuteNonQuery(); // 1. add/update customer string queryBook = MakeQueryBook(); ConnectionUtils.OpenConnection(); MySqlCommand command2 = new MySqlCommand(queryBook, ConnectionUtils.connection); command2.ExecuteNonQuery(); // 2. get added/updated customer ID and make book ConnectionUtils.CloseConnection(); ConnectionUtils.OpenConnection(); MySqlCommand command = new MySqlCommand("SELECT varaus_id FROM varaus WHERE asiakas_id LIKE '" + customerid + "' AND mokki_mokki_id LIKE '" + lblBookCottageId.Text + "' AND varattu_alkupvm LIKE '" + lblBookBookingDateFrom.Text + "%' AND varattu_loppupvm LIKE '" + lblBookBookingDateTo.Text + "%' ", ConnectionUtils.connection); varausid = Convert.ToInt32(command.ExecuteScalar()); // get just added order ID ConnectionUtils.CloseConnection(); if (services != "") // if services exists { string queryServices = MakeQueryServices(); ConnectionUtils.OpenConnection(); MySqlCommand command3 = new MySqlCommand(queryServices, ConnectionUtils.connection); command3.ExecuteNonQuery(); // 3. get added order ID and add services to data table ConnectionUtils.CloseConnection(); this.Close(); } BillingUtils.CreateInvoice(varausid); // Make new billing DialogResult result = MessageBox.Show("Varaus lisätty. Uusi lasku lisätty järjestelmään. Varaus id: " + varausid + " \nSiirrytäänkö laskuun?", "Prosessi onnistui", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { BillingUtils.GoToCreatedInvoice(varausid); } this.Close(); } catch (Exception ex) { MessageBox.Show("Tapahtunut virhe, yritä uudelleen. Virhe: \n\n\n" + ex, "Virhe", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else if (res == DialogResult.Cancel) { } }