예제 #1
0
 /// <summary>
 /// Handles the 1 event of the Back_Btn_Click control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
 private void Back_Btn_Click_1(object sender, RoutedEventArgs e)
 {
     SecretaryGui SG = new SecretaryGui();
     SG.Show();
     Login.close = 1;
     this.Close();
 }
예제 #2
0
        //כפתור כניסה
        /// <summary>
        /// Handles the Click event of the button1 control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (client.Equals(true)) // if this is a remote computer.
                {
                    serverip = this.Host_textBox.Text;
                    Connectionstring = "Server=" + serverip + "; Database=project; UId=root;Password=1234;";
                   // MessageBox.Show("" + Connectionstring +"");
                }
                else if (client.Equals(false)) // // if this is the host computer (the one with the SQL DataBase on it).
                {
                    Connectionstring = "Server=localhost;Database=project; UId=root;Password=1234;";
                }
               // string Connectionstring = " Server=localhost;Database=project; UId=root;Password=1234;";
                MySqlConnection objc = new MySqlConnection(Connectionstring);
                try
                {
                   // MessageBox.Show("ניסיון התחברות");
                    objc.Open();
                   // MessageBox.Show("התחברות הצליחה");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                CheckSingleQuotationMark CSQ = new CheckSingleQuotationMark();
                string pass = this.textBox2.Password;
                Console.WriteLine(pass);
                pass = CSQ.checkForSingleQuotationMark(pass);
                Console.WriteLine("לאחר בדיקת ציטוט בסיסמה");
                Console.WriteLine(pass);
                string Query = "select * from project.users where empid='" + CSQ.checkForSingleQuotationMark(this.textBox1.Text) + "'and password='******'";
                Console.WriteLine("השאילתה הנשלחת בכניסה:");
                Console.WriteLine(Query);
                MySqlCommand crcommand = new MySqlCommand(Query, objc);
                crcommand.ExecuteNonQuery();
                MySqlDataReader dr = crcommand.ExecuteReader();
                int count = 0;
                while (dr.Read())
                {
                    count++;
                    user_role = dr.GetString(2);
                }
                if (count == 1)
                {
                  //  string Connectionstring1 = " Server=localhost;Database=project; UId=root;Password=1234;";
                 //   MySqlConnection objc1 = new MySqlConnection(Connectionstring1);
                    MySqlConnection objc1 = new MySqlConnection(Connectionstring);
                    try
                    {
                        //MessageBox.Show(" 1 ניסיון התחברות");
                        objc1.Open();
                       // MessageBox.Show("התחברות הצליחה 1");
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                    string Query1 = "SELECT  employees.emp_firstname, employees.emp_lastname, users.connected, users.email FROM project.users, project.employees WHERE users.empid=employees.empid and users.empid='" + this.textBox1.Text + "'and users.password='******'";
                    //MySqlCommand crcommand1 = new MySqlCommand(Query1, objc);
                    MySqlCommand crcommand1 = new MySqlCommand(Query1, objc1);
                    crcommand1.ExecuteNonQuery();
                    MySqlDataReader dr1 = crcommand1.ExecuteReader();
                    int count1 = 0;
                    while (dr1.Read())
                    {
                        count1++;
                        first_name = dr1.GetString(0);
                        first_name1 = first_name;
                        first_name = CSQ.checkForSingleQuotationMark(first_name);
                        last_name = dr1.GetString(1);
                        last_name1 = last_name;
                        last_name = CSQ.checkForSingleQuotationMark(last_name);
                        connected = dr1.GetString(2);
                        useremail = dr1.GetString(3);
                    }
                    //MessageBox.Show(""+connected+"");
                    if (count1 == 1)
                    {
                        if (connected != "מחובר" && connected != "לא מחובר")
                        {
                            MessageBox.Show("קיימת בעיה במצב החיבור שלך, יש לפנות למנהל המערכת  ", " שגיאה", MessageBoxButton.OK,MessageBoxImage.Error);
                        }

                        if (connected.Equals("מחובר"))
                        {
                            MessageBox.Show("אתה כבר מחובר למערכת  ", " שגיאה", MessageBoxButton.OK,MessageBoxImage.Error);
                        }

                        if (connected.Equals("לא מחובר"))
                        {
                            MessageBox.Show("      ברוכ/ה הבא/ה " + Login.last_name1 + " " + Login.first_name1 + "", "!ההתחברות למערכת בוצעה בהצלחה", MessageBoxButton.OK,MessageBoxImage.Information);
                            empid = this.textBox1.Text;
                            string user_connected = "מחובר";
                            //string user_connected = "לא מחובר";

                            if (user_role.Equals("מנהל"))
                            {
                                DBConnection conn = new DBConnection();
                                Console.WriteLine(my_host_name);
                                string query2 = "UPDATE users SET connected='" + user_connected + "',last_log_in_date='" + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + "'  ,last_location='" + my_host_name + "' WHERE empid= '" + this.textBox1.Text + "' and password ='******' ";
                                conn.LogIn(query2, Connectionstring);
                                //conn.LogIn(query2);
                                ManagerGui MG = new ManagerGui();
                                MG.Show();
                            }

                            if (user_role.Equals("מזכירה"))
                            {
                                DBConnection conn = new DBConnection();
                                string query2 = "UPDATE users SET connected='" + user_connected + "',last_log_in_date='" + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + "' ,last_location='" + my_host_name + "' WHERE empid= '" + this.textBox1.Text + "' and password ='******'";
                                //conn.LogIn(query2);
                                conn.LogIn(query2, Connectionstring);
                                SecretaryGui SG = new SecretaryGui();
                                SG.Show();
                            }

                            if (user_role.Equals("איכות"))
                            {
                                DBConnection conn = new DBConnection();
                                string query2 = "UPDATE users SET connected='" + user_connected + "',last_log_in_date='" + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + "' ,last_location='" + my_host_name + "' WHERE empid= '" + this.textBox1.Text + "' and password ='******'";
                               // conn.LogIn(query2);
                                conn.LogIn(query2, Connectionstring);
                                QualityGui QG = new QualityGui();
                                QG.Show();
                            }

                              this.Close();
                          //    MGui.ShowDialog();
                           // this.Close();
                        }

                   //     else
                   //     {
                  //          MessageBox.Show("קיימת בעיה במצב החיבור שלך, יש לפנות למנהל המערכת  ", " שגיאה", MessageBoxButton.OK);
                   //     }
                    }
                    else
                    {
                        MessageBox.Show("!אינך משתמש פעיל במערכת, אנא פנה למנהל", "!ההתחברות למערכת נכשלה", MessageBoxButton.OK,MessageBoxImage.Error);
                        textBox1.Clear();
                        textBox2.Clear();
                    }
                    objc1.Close();
                }
                if (count < 1)
                {
                    MessageBox.Show("שם משתמש ו/או סיסמא שגויים! אנא נסה שנית", "!ההתחברות למערכת נכשלה", MessageBoxButton.OK,MessageBoxImage.Error);
                  //  textBox1.Clear();
                  //  textBox2.Clear();
                }
                objc.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }