Пример #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            Cars_and_Clients frmCars = (Cars_and_Clients)Application.OpenForms["Cars_and_Clients"];

            frmCars.loadData();
            frmCars.dataGridView1.Update();
            frmCars.dataGridView1.Refresh();
            this.Close();
        }
Пример #2
0
        private void btnExit_Click(object sender, EventArgs e)
        {
            Cars_and_Clients frmCars = (Cars_and_Clients)Application.OpenForms["Cars_and_Clients"];

            frmCars.loadData();
            frmCars.dgvClients.Update();
            frmCars.dgvClients.Refresh();
            this.Close();
        }
Пример #3
0
 private void btnAddClient_Click(object sender, EventArgs e)
 {
     try
     {
         string             connected;
         DatabaseConnection check = new DatabaseConnection();
         connected = check.checkDatabase();
         if (connected == "true")
         {
             if (txtIDNum.Text != "" & txtName.Text != "")
             {
                 string name     = txtName.Text;
                 string surname  = txtSurname.Text;
                 long   PhoneNum = Convert.ToInt64(txtPhnNum.Text);
                 long   IDNum    = Convert.ToInt64(txtIDNum.Text);
                 string email    = txtEmail.Text;
                 string tech     = Global.Technician.Names + " " + Global.Technician.Surnames;
                 using (SqlConnection conn = new SqlConnection(DatabaseConnection.connectionStr))
                 {
                     conn.Open();
                     string querry = "INSERT INTO Clients(ID,Name,Surname,Email,PhoneNumber,Technician) "
                                     + "Values('" + IDNum + "','" + name + "','" + surname + "','" + email + "','" + PhoneNum + "','" + tech + "')";
                     using (SqlCommand cmd = new SqlCommand(querry, conn))
                     {
                         cmd.ExecuteNonQuery();
                         MessageBox.Show("New Client added!");
                         Cars_and_Clients frmCars = new Cars_and_Clients();
                         txtEmail.Clear();
                         txtIDNum.Clear();
                         txtName.Clear();
                         txtPhnNum.Clear();
                         txtSurname.Clear();
                     }
                     conn.Close();
                 }
             }
             else
             {
                 throw new Exception("Please make sure you have entered all the required information");
                 //MessageBox.Show(error, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 //new LogWriter(error);
             }
         }
         else
         {
             throw new Exception("Not Connected");
             //MessageBox.Show(error);
             //new LogWriter(error);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
         new LogWriter(ex);
     }
 }
Пример #4
0
        private void btnLogIn_Click(object sender, EventArgs e)
        {
            try
            {
                string             connected;
                DatabaseConnection check = new DatabaseConnection();
                connected = check.checkDatabase();
                if (connected == "true")
                {
                    using (SqlConnection conn = new SqlConnection(DatabaseConnection.connectionStr))
                    {
                        DataTable      table   = new DataTable();
                        SqlDataAdapter adapter = new SqlDataAdapter(@"select * from Cars", conn);
                        adapter.Fill(table);

                        if (table.Rows.Count > 0)
                        {
                            Global.Car = new Cars
                            {
                                serialNumber  = table.Rows[0]["SerialNumber"].ToString(),
                                Names         = table.Rows[0]["Names"].ToString(),
                                plateNumber   = table.Rows[0]["NumberPlates"].ToString(),
                                phoneNumber   = table.Rows[0]["PhoneNumber"].ToString(),
                                address       = table.Rows[0]["Address"].ToString(),
                                clientID      = table.Rows[0]["ID"].ToString(),
                                clientAccount = table.Rows[0]["Account"].ToString(),
                                Technician    = table.Rows[0]["Technician"].ToString(),
                                Count         = table.Rows[0]["Count"].ToString(),
                            };
                        }
                        DataTable      table1   = new DataTable();
                        SqlDataAdapter adapter1 = new SqlDataAdapter(@"select * from Technicians where Email = '" + txtEmail.Text + "' and Password = '******'", conn);
                        adapter1.Fill(table1);
                        if (table.Rows.Count > 0)
                        {
                            Global.Technician = new Technicians
                            {
                                ID       = table1.Rows[0]["ID"].ToString(),
                                Email    = table1.Rows[0]["Email"].ToString(),
                                Password = table1.Rows[0]["Password"].ToString(),
                                Role     = table1.Rows[0]["Role"].ToString(),
                                Names    = table1.Rows[0]["Name"].ToString(),
                                Surnames = table1.Rows[0]["Surname"].ToString(),
                                Position = table1.Rows[0]["Position"].ToString(),
                            };
                            if (Global.Technician.Role == "Admin")
                            {
                                Cars_and_Clients frmCar = new Cars_and_Clients();
                                frmCar.Show();
                                this.Hide();
                                new loginLogs(Global.Technician.Surnames + " " + Global.Technician.Names,
                                              Global.Technician.ID, Global.Technician.Email, Global.Technician.Position);
                            }
                            else
                            {
                                MessageBox.Show("Normal user connected!");
                            }
                        }
                        DataTable      table2   = new DataTable();
                        SqlDataAdapter adapter2 = new SqlDataAdapter(@"select * from Clients", conn);
                        adapter2.Fill(table2);

                        if (table2.Rows.Count > 0)
                        {
                            Global.Client = new Clients
                            {
                                Names       = table2.Rows[0]["Name"].ToString(),
                                Surnames    = table2.Rows[0]["Surname"].ToString(),
                                Email       = table2.Rows[0]["Email"].ToString(),
                                ID          = table2.Rows[0]["ID"].ToString(),
                                phoneNumber = table2.Rows[0]["PhoneNumber"].ToString(),
                                Technician  = table.Rows[0]["Technician"].ToString(),
                            };
                        }
                    }
                }
                else
                {
                    throw new Exception("Connection to the database was not established.");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Please provide your correct email and password in order to log in!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                new LogWriter(ex);
            }
        }