Exemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            SqlConnection sqlConnection = new SqlConnection(DataSourseString.getString());

            try
            {
                sqlConnection.Open();
                if (textBox2.Text != "" && textBox3.Text != "" && textBox4.Text != "")
                {
                    DateTime date1  = DateTime.Now;
                    DateTime date2  = date1.AddDays(Convert.ToInt32(textBox4.Text));
                    String   date1s = "";
                    String   date2s = "";
                    date1s += date1.Year + "-0" + date1.Month + "-" + date1.Day + "T00:00:00.000";
                    date2s += date2.Year + "-0" + date2.Month + "-0" + date2.Day + "T00:00:00.000";
                    SqlCommand sqlCommand = new SqlCommand("INSERT INTO [Emploer] (Name_emploer, password_emploer, role_emploer, date_in_System,date_out_System,block_,[count]) VALUES ('" + textBox2.Text + "','" + textBox3.Text + "', 0,'" + date1s + "','" + date2s + "',0,0)", sqlConnection);
                    sqlCommand.ExecuteReader();
                    this.Hide();
                    new Form1().Show();
                }
                else
                {
                    MessageBox.Show("Заполните данные");
                }

                sqlConnection.Close();
            }
            catch (SqlException err)
            {
                Console.WriteLine(err.ToString(), "Error");
            }
        }
Exemplo n.º 2
0
 public static DataTable getTable(string sql)
 {
     using (SqlConnection sqlConnection = new SqlConnection(DataSourseString.getString()))
     {
         using (SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sql, sqlConnection))
         {
             DataTable dataTable = new DataTable();
             sqlDataAdapter.Fill(dataTable);
             return(dataTable);
         }
     }
 }
Exemplo n.º 3
0
        private void button1_Click(object sender, EventArgs e)
        {
            SqlConnection sqlConnection = new SqlConnection(DataSourseString.getString());

            sqlConnection.Open();
            if (textBox1.Text != "" && textBox2.Text != "")
            {
                SqlCommand sqlCommand = new SqlCommand("update [Emploer] set [password_emploer]='" + textBox1.Text + "',[LastName_emploer] = '" + textBox2.Text + "'  where ID_Emploer =" + User.ID_user + ";", sqlConnection);
                sqlCommand.ExecuteNonQuery();
                this.Hide();
                new Form1().Show();
            }
            else
            {
                MessageBox.Show("Заполните данные");
            }
        }
Exemplo n.º 4
0
        private void Form3_Load(object sender, EventArgs e)
        {
            SqlConnection sqlConnection = new SqlConnection(DataSourseString.getString());

            sqlConnection.Open();
            SqlCommand    comand = new SqlCommand("select * from [Emploer] where ID_Emploer =" + User.ID_user + ";", sqlConnection);
            SqlDataReader reader;

            reader = comand.ExecuteReader();
            if (reader.Read())
            {
                textBox1.Text = reader["password_emploer"].ToString();
                textBox2.Text = reader["LastName_emploer"].ToString();
            }
            else
            {
                MessageBox.Show("Текущго пользователя не существует");
            }
        }
Exemplo n.º 5
0
        private void button2_Click(object sender, EventArgs e)
        {
            SqlConnection sqlConnection = new SqlConnection(DataSourseString.getString());
            SqlDataReader reader;

            try
            {
                sqlConnection.Open();
                SqlCommand comand = new SqlCommand("select * from [Emploer] where [Name_emploer] = '" + textBox1.Text + "'", sqlConnection);
                reader = comand.ExecuteReader();
                if (textBox1.Text != "")
                {
                    if (reader.Read())
                    {
                        reader.Close();
                        SqlCommand sqlCommand = new SqlCommand("update [Emploer] set [block_]=0, count=0 where [Name_emploer] = '" + textBox1.Text + "'", sqlConnection);
                        sqlCommand.ExecuteReader();
                        this.Hide();
                        new Form1().Show();
                    }
                    else
                    {
                        MessageBox.Show("Такого пользователя не существует");
                    }
                }
                else
                {
                    MessageBox.Show("Заполните данные");
                }

                sqlConnection.Close();
            }
            catch (SqlException err)
            {
                Console.WriteLine(err.ToString(), "Error");
            }
        }
Exemplo n.º 6
0
        private void button1_Click(object sender, EventArgs e)
        {
            SqlConnection sqlConnection = new SqlConnection(DataSourseString.getString());
            SqlDataReader reader;

            try
            {
                sqlConnection.Open();
                SqlCommand comand = new SqlCommand("select * from [Emploer] where [Name_emploer] = '" + textBox1.Text + "';", sqlConnection);
                reader = comand.ExecuteReader();
                if (textBox1.Text != "" && textBox2.Text != "")
                {
                    if (reader.Read())
                    {
                        String pas = reader["password_emploer"].ToString();
                        User.ID_user = Convert.ToInt32(reader["ID_Emploer"].ToString());
                        if (pas == textBox2.Text)
                        {
                            User.role = Convert.ToInt32(reader["role_emploer"]);
                            if (User.role == 1)
                            {
                                this.Hide();
                                new Form2().Show();
                            }
                            else
                            {
                                int block = Convert.ToInt32(reader["block_"].ToString());
                                if (block == 0)
                                {
                                    DateTime dateIn  = Convert.ToDateTime(reader["date_in_System"]);
                                    DateTime dateOut = Convert.ToDateTime(reader["date_out_System"]);
                                    if (DateTime.Now.CompareTo(dateIn) >= 0 && DateTime.Now.CompareTo(dateOut) <= 0)
                                    {
                                        if ((Convert.ToInt32(DateTime.Now.Day) % 2 == 0 && User.ID_user % 2 == 0) || (Convert.ToInt32(DateTime.Now.Day) % 2 == 1 && User.ID_user % 2 == 1))
                                        {
                                            this.Hide();
                                            new Form3().Show();
                                        }
                                        else
                                        {
                                            MessageBox.Show("Error", "Сегодня вы не можете войти");
                                        }
                                    }
                                    else
                                    {
                                        if (DateTime.Now.CompareTo(dateIn) < 0)
                                        {
                                            MessageBox.Show("Error", "Аккаунт еще не доступен");
                                        }
                                        else
                                        {
                                            reader.Close();
                                            SqlCommand sqlCommand = new SqlCommand("update [Emploer] set [block_]=1 where ID_Emploer =" + User.ID_user + ";", sqlConnection);
                                            sqlCommand.ExecuteNonQuery();
                                            MessageBox.Show("Error", "Время действия аккаунта истекло");
                                        }
                                    }
                                }
                                else
                                {
                                    MessageBox.Show("Пользователь заблокирован");
                                }
                            }
                        }
                        else
                        {
                            SqlCommand sqlCommand;
                            int        count = Convert.ToInt32(reader["count"].ToString());
                            if (count == 2)
                            {
                                sqlCommand = new SqlCommand("update [Emploer] set [block_]=1 where ID_Emploer =" + User.ID_user + ";", sqlConnection);
                            }
                            else
                            {
                                count++;
                                sqlCommand = new SqlCommand("update [Emploer] set [count]=" + count + " where ID_Emploer =" + User.ID_user + ";", sqlConnection);
                            }
                            reader.Close();
                            //DataReader.Close();
                            sqlCommand.ExecuteNonQuery();
                            MessageBox.Show("Неверный пароль");
                        }
                    }
                    else
                    {
                        MessageBox.Show("Текущего пользователя не существует");
                    }
                }
                else
                {
                    MessageBox.Show("Заполните данные");
                }

                sqlConnection.Close();
            }
            catch (SqlException err)
            {
                Console.WriteLine(err.ToString(), "Error");
            }
        }