/* Add Methods */ public String addCustomer(Customer add, String password) { // TODO: change to bool string checkIfExsites = "Select * FROM users WHERE person_id = '" + add.getIdNumber() + "' ;"; MySqlCommand cmdCheck = new MySqlCommand(checkIfExsites, this.connection); MySqlDataReader dataReader = cmdCheck.ExecuteReader(); int count = 0; while (dataReader.Read()) { count++; } dataReader.Close(); if (count > 0) { return "ID allready in use"; } string query = "INSERT INTO cilent (F_Name, L_Name, ClientIDNum, phone_number, Address, DateJoind, Md_LastDate, eMail, program, person_id, password, Premission) VALUES('" + add.getNameFirst() + "', '" + add.getNameLast() + "' , '" + add.getIdNumber() + "', '" + add.getPhoneNumber() + "','" + add.getHomeAddress() + "','" + add.getDateJoined() + "','" + add.getMedicalClearanceExpiration() + "','" + add.getEmailAddress() + "', '1','" + add.getIdNumber() + "', md5('" + password + "'), 0);"; MySqlCommand cmd = new MySqlCommand(query, this.connection); try { cmd.ExecuteNonQuery(); } catch (MySqlException ex) { if (ex.Message.Contains("Duplicate")) { if (ex.Message.Contains("PhoneNumber")) { return "Phone Number"; } else if (ex.Message.Contains("eMail")) { return "Email"; } } else System.Windows.Forms.MessageBox.Show("Unknow error"); } long customerDbId = cmd.LastInsertedId; string query2 = "INSERT INTO users (person_id, password, type) VALUES('" + add.getIdNumber() + "', md5('" + password + "'), 'customer');"; MySqlCommand cmd2 = new MySqlCommand(query2, this.connection); cmd2.ExecuteNonQuery(); string query3 = "INSERT INTO client_program (program_id, client_id) VALUES('1', '" + customerDbId + "');"; MySqlCommand cmd3 = new MySqlCommand(query3, this.connection); cmd3.ExecuteNonQuery(); return "OK"; }
private void buttonAddFind_Click(object sender, EventArgs e) { // Validate ID Input if (!validateID()) { return; } if (this.requetsType == "Add") {// Current Form Request is Add if (validateData()) {// Detiles are OK String result = current.getCutomerManagement().addCustomer(textBoxNameFirst.Text, textBoxNameLast.Text, textBoxAddress.Text, textBoxPhoneNumber.Text, textBoxEmail.Text, Convert.ToInt64(textBoxID.Text), PermissiomLevels.CUSTOMER, DateTime.Now.ToString("dd/mm/yyyy"), dateTimePickerMDClerExp.Value.ToString("dd/MM/yyyy"), textBoxPassword.Text); switch (result) {// Varify Addition case "ID": labelID.ForeColor = Color.Red; MessageBox.Show("This ID Number is listed for another customer!"); return; case "Phone Number": labelPhone.ForeColor = Color.Red; MessageBox.Show("This Phone Number is listed for another customer!"); return; case "Email": labelEmail.ForeColor = Color.Red; MessageBox.Show("This Email is listed for another customer!"); return; case "Customer Allready existes": MessageBox.Show("Customer Allready existes!"); resetLabelColors(); refresher(); return; case "OK": MessageBox.Show("Customer Added Successfully!"); refresher(); return; } // Switch } // if (validateData()) return; } // if (this.requetsType == "Add") // Current Form Request is Edit (Button Text is Find) customerObject = dbConnector.Instance.getCusomerById(Convert.ToInt32(textBoxID.Text)); // in this place we need to read data from MYSQL database and fill in our text boxes if (customerObject == null) { // Customer Not Found MessageBox.Show("There is no Customer with this id"); return; } // Fill Data textBoxNameFirst.Text = customerObject.getNameFirst(); textBoxNameLast.Text = customerObject.getNameLast(); textBoxPhoneNumber.Text = customerObject.getPhoneNumber(); dateTimePickerMDClerExp.Value = Convert.ToDateTime(customerObject.getMedicalClearanceExpiration()); textBoxEmail.Text = customerObject.getEmailAddress(); textBoxAddress.Text = customerObject.getHomeAddress(); buttonSave.Enabled = true; panelData.Visible = true; }
public String EditCustomer(Customer add) { string query = "UPDATE cilent SET F_Name='" + add.getNameFirst() + "', L_Name='" + add.getNameLast() + "', Md_LastDate = '"+add.getMedicalClearanceExpiration() +"' ,phone_number='" + add.getPhoneNumber() + "', person_id='" + add.getIdNumber() + "', address='" + add.getHomeAddress() + "', email='" + add.getEmailAddress() + "' WHERE idCilent='" + add.getDBid() + "';"; MySqlCommand cmd = new MySqlCommand(query, this.connection); try { cmd.ExecuteNonQuery(); } catch (MySqlException ex) { if (ex.Message.Contains("Duplicate")) { if (ex.Message.Contains("ClientIDNum")) { return "ID"; } else if (ex.Message.Contains("PhoneNumber")) { return "Phone Number"; } else if (ex.Message.Contains("eMail")) { return "Email"; } } else System.Windows.Forms.MessageBox.Show("Unknow error"); } return "O.K"; }