private void button2_Click(object sender, EventArgs e)
 {
     if (radioButton1.Checked)
     {
         if (textBox1.Text != "" && textBox2.Text != "" && textBox3.Text != "" && textBox5.Text != "" && textBox6.Text != "")
         {
             CompanyAccount Company = new CompanyAccount();
             Company.Username     = account.Username;
             Company.Password     = account.Password;
             Company.CompanyName  = textBox1.Text;
             Company.CompanyID    = textBox2.Text;
             Company.EmailAddress = textBox3.Text;
             Company.FAX          = textBox4.Text;
             Company.PhoneNumber  = textBox5.Text;
             Company.Address1     = textBox6.Text;
             Company.Address2     = textBox7.Text;
             this.UseWaitCursor   = true;
             button1.Enabled      = false;
             button2.Enabled      = false;
             button3.Enabled      = false;
             Task T = new Task(() => Da.RegisterCompanyAccount(Company));
             T.Start();
         }
         else
         {
             MessageBox.Show("Some fields are left empty.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         }
     }
     else if (radioButton2.Checked)
     {
         if (textBox1.Text != "" && textBox2.Text != "" && textBox5.Text != "" && textBox4.Text != "")
         {
             SoloAccount Person = new SoloAccount();
             Person.Username     = account.Username;
             Person.Password     = account.Password;
             Person.Name         = textBox1.Text;
             Person.Surname      = textBox2.Text;
             Person.DateOfBirth  = dateTimePicker.Value;
             Person.EmailAddress = textBox4.Text;
             Person.PhoneNumber  = textBox5.Text;
             this.UseWaitCursor  = true;
             button1.Enabled     = false;
             button2.Enabled     = false;
             button3.Enabled     = false;
             Task T = new Task(() => Da.RegisterSoloAccount(Person));
             T.Start();
         }
         else
         {
             MessageBox.Show("Mandatory fields are empty.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         }
     }
 }
Beispiel #2
0
 public void RegisterCompanyAccount(CompanyAccount Company)
 {
     try
     {
         string       query  = "insert into Account (Username, Password, IsAdmin, Company_idClientCompany) values (@Name, @Password, @IsAdmin, @ID)";
         string       query1 = "insert into Company (Name, CompanyID, PhoneNumer, EmailAddress, FAX, Address1, Address2) values (@Name, @ID, @Phone, @Email, @Fax, @Ad1, @Ad2)";
         string       query2 = "select idClientCompany from Company where CompanyID = @ID";
         MySqlCommand comm   = new MySqlCommand(query, connection);
         MySqlCommand comm1  = new MySqlCommand(query1, connection);
         MySqlCommand comm2  = new MySqlCommand(query2, connection);
         comm1.Parameters.AddWithValue("@Name", Company.CompanyName);
         comm1.Parameters.AddWithValue("@ID", Company.CompanyID);
         comm1.Parameters.AddWithValue("@Phone", Company.PhoneNumber);
         comm1.Parameters.AddWithValue("@Email", Company.EmailAddress);
         comm1.Parameters.AddWithValue("@Fax", Company.FAX);
         comm1.Parameters.AddWithValue("@Ad1", Company.Address1);
         comm1.Parameters.AddWithValue("@Ad2", Company.Address2);
         comm2.Parameters.AddWithValue("@ID", Company.CompanyID);
         OpenConnection();
         comm1.ExecuteNonQuery();
         MySqlDataReader reader = comm2.ExecuteReader();
         reader.Read();
         int Id = Convert.ToInt32(reader[0].ToString());
         reader.Close();
         comm.Parameters.AddWithValue("@Name", Company.Username);
         comm.Parameters.AddWithValue("@Password", Company.Password);
         comm.Parameters.AddWithValue("@IsAdmin", 0);
         comm.Parameters.AddWithValue("@ID", Id);
         comm.ExecuteNonQuery();
         CloseConnection();
         MessageBox.Show("Registration successful", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
         RegResponder();
         Application.Run(new LogInForm());
     }
     catch (Exception Ex)
     {
         //Duplicate entry
         MessageBox.Show(Ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
     }
 }