Ejemplo n.º 1
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (textBox1.Text == "1" && textBox2.Text == "1")
     {
         ADMIN_PAGE admin_page = new ADMIN_PAGE();
         admin_page.Show();
         this.Close();
     }
     else
     {
         MessageBox.Show("Невірний логін або пароль", "Помилка");
     }
 }
Ejemplo n.º 2
0
        private void button15_Click(object sender, EventArgs e)
        {
            string penalty = "";

            foreach (object item in checkedListBox1.CheckedItems)
            {
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    connection.Open();
                    SqlCommand command = new SqlCommand();
                    command.Connection = connection;

                    string curItemString = ((DataRowView)item)[checkedListBox1.DisplayMember].ToString();

                    command.CommandText = "(SELECT Id_penalty FROM penalties WHERE penalty_name = @penalty_name)";
                    command.Parameters.AddWithValue("@penalty_name", curItemString);

                    SqlDataReader thisReader = command.ExecuteReader();
                    while (thisReader.Read())
                    {
                        penalty += thisReader["Id_penalty"].ToString() + " ";
                    }
                }
            }
            int rent = Convert.ToInt32(label30.Text);

            int[] arr = penalty.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(k => int.Parse(k.Trim())).ToArray();
            if (arr.Length != 0)
            {
                for (int i = 0; i < arr.Length; i++)
                {
                    using (SqlConnection connection = new SqlConnection(connectionString))
                    {
                        connection.Open();
                        SqlCommand command = new SqlCommand();
                        command.Connection = connection;

                        int pen = arr[i];
                        command.CommandText = "insert into rent_penalty (Id_penalty, Id_rent) values(@Id_penalty,@Id_rent)";
                        command.Parameters.AddWithValue("@Id_penalty", pen);
                        command.Parameters.AddWithValue("@Id_rent", rent);

                        command.ExecuteNonQuery();
                        command.Parameters.Clear();
                        double amount = Convert.ToDouble(label16.Text);
                        command.CommandText = "UPDATE rent SET total_amount = @total_amount WHERE Id_rent = @Id_rent;";
                        command.Parameters.AddWithValue("@total_amount", Math.Round(amount));
                        command.Parameters.AddWithValue("@Id_rent", rent);

                        command.ExecuteNonQuery();
                        command.Parameters.Clear();
                    }
                }
            }
            else
            {
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    connection.Open();
                    SqlCommand command = new SqlCommand();
                    command.Connection  = connection;
                    command.CommandText = "insert into rent_penalty ( Id_rent) values(@Id_rent)";
                    command.Parameters.AddWithValue("@Id_rent", rent);

                    command.ExecuteNonQuery();
                }
            }
            dataset.Clear();
            adapter.Fill(dataset);
            MessageBox.Show("Замовлення закрито!");
            ADMIN_PAGE admin = new ADMIN_PAGE();

            this.Close();
            admin.Show();
        }