Exemplo n.º 1
0
        ///
        /// przycisk połączenia
        ///

        private void connButton_Click(object sender, EventArgs e)
        {
            string connetionString, sql = "";

            login    = loginTextBox1.Text;
            password = loginTextBox2.Text;
            SqlConnection DBconnect;

            connetionString = @"Data Source=mssql-2017.labs.wmi.amu.edu.pl;Initial Catalog=s434903_inzopr2019z;User ID=s444513;Password=Gxrbqfvw7L";
            DBconnect       = new SqlConnection(connetionString);
            DBconnect.Open();
            sql = "SELECT * FROM Studenci WHERE Imie LIKE '" + login + "' AND Nazwisko LIKE '" + password + "';";
            SqlCommand    command = new SqlCommand(sql, DBconnect);
            SqlDataReader reader  = command.ExecuteReader();

            if (reader.HasRows)
            {
                reader.Read();
                string semester;
                semester = reader.GetValue(3).ToString();
                if (semester.CompareTo("0") != 0)
                {
                    StudentWin next = new StudentWin(login, password, semester);
                    next.Show();
                    this.Hide();
                }
                else
                {
                    AdmWin next = new AdmWin(login, password);
                    next.Show();
                    this.Hide();
                }
            }
            else
            {
                MessageBox.Show("Nie znaleźono rekordu.");
            }
            reader.Close();
            DBconnect.Close();
        }
Exemplo n.º 2
0
        ///
        /// metoda odpowiedzialna za akcje przycisków w tabeli
        ///


        private void tabela1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            string        connetionString, sql = "";
            SqlConnection DBconnect;

            connetionString = @"Data Source=mssql-2017.labs.wmi.amu.edu.pl;Initial Catalog=s434903_inzopr2019z;User ID=s444513;Password=Gxrbqfvw7L";
            var senderGrid = (DataGridView)sender;

            if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn && e.ColumnIndex == 4)
            {
                var      wartośćKonkretnejKomórki = senderGrid.Rows[e.RowIndex].Cells[0].Value;
                String[] name = wartośćKonkretnejKomórki.ToString().Split(' ');
                DBconnect = new SqlConnection(connetionString);
                DBconnect.Open();
                sql = "select Id from Studenci where Imie ='" + name[0] + "' and Nazwisko ='" + name[1] + "'";
                SqlCommand    command6 = new SqlCommand(sql, DBconnect);
                SqlDataReader reader6  = command6.ExecuteReader();
                if (reader6.HasRows)
                {
                    reader6.Read();
                    string id;
                    id = reader6.GetValue(0).ToString();

                    PreviewShedule shedule = new PreviewShedule(id, name[0], name[1]);
                    shedule.Show();
                }
                reader6.Close();
                DBconnect.Close();
            }

            if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn && e.ColumnIndex == 2)
            {
                var      wartośćKonkretnejKomórki = senderGrid.Rows[e.RowIndex].Cells[0].Value;
                String[] name = wartośćKonkretnejKomórki.ToString().Split(' ');
                DBconnect = new SqlConnection(connetionString);
                DBconnect.Open();
                sql = "select Id from Studenci where Imie ='" + name[0] + "' and Nazwisko ='" + name[1] + "'";
                SqlCommand    command3 = new SqlCommand(sql, DBconnect);
                SqlDataReader reader3  = command3.ExecuteReader();
                if (reader3.HasRows)
                {
                    reader3.Read();
                    string id;
                    id        = reader3.GetValue(0).ToString();
                    DBconnect = new SqlConnection(connetionString);
                    DBconnect.Open();
                    sql = "update Plan_Zajec set status = 'zatwierdzony' where Studenci_Id =" + id;
                    SqlCommand    command4 = new SqlCommand(sql, DBconnect);
                    SqlDataReader reader4  = command4.ExecuteReader();

                    DBconnect = new SqlConnection(connetionString);
                    DBconnect.Open();
                    sql = "select Zajecia_Id from Plan_Zajec where Studenci_Id=" + id;;
                    SqlCommand    command5 = new SqlCommand(sql, DBconnect);
                    SqlDataReader reader5  = command5.ExecuteReader();
                    if (reader5.HasRows)
                    {
                        for (int i = 0; i <= 3; i++)
                        {
                            reader5.Read();
                            string zajecia_id;
                            zajecia_id = reader5.GetValue(0).ToString();
                            DBconnect  = new SqlConnection(connetionString);
                            DBconnect.Open();
                            sql = "select Ilosc_Miejsc from Zajecia where Id=" + zajecia_id;
                            SqlCommand    command6 = new SqlCommand(sql, DBconnect);
                            SqlDataReader reader6  = command6.ExecuteReader();
                            if (reader6.HasRows)
                            {
                                int    ilo_miejsc;
                                string ilosc_miejsc;
                                reader6.Read();
                                ilosc_miejsc = reader6.GetValue(0).ToString();
                                ilo_miejsc   = Convert.ToInt32(ilosc_miejsc);
                                DBconnect    = new SqlConnection(connetionString);
                                DBconnect.Open();
                                sql = "update Zajecia set Ilosc_Miejsc =" + (ilo_miejsc - 1) + " where Id=" + zajecia_id;
                                SqlCommand    command7 = new SqlCommand(sql, DBconnect);
                                SqlDataReader reader7  = command7.ExecuteReader();
                                reader7.Close();
                                DBconnect.Close();
                            }
                            reader6.Close();
                            DBconnect.Close();
                        }
                    }
                    reader4.Close();
                    DBconnect.Close();
                    reader5.Close();
                    DBconnect.Close();

                    MessageBox.Show("Zaakceptowano pomyślnie");
                    AdmWin next = new AdmWin("Admin", "Admin");
                    next.Show();
                    this.Hide();
                }
                reader3.Close();
                DBconnect.Close();
            }

            if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn && e.ColumnIndex == 3)
            {
                var      wartośćKonkretnejKomórki = senderGrid.Rows[e.RowIndex].Cells[0].Value;
                String[] name = wartośćKonkretnejKomórki.ToString().Split(' ');
                DBconnect = new SqlConnection(connetionString);
                DBconnect.Open();
                sql = "select Id from Studenci where Imie ='" + name[0] + "' and Nazwisko ='" + name[1] + "'";
                SqlCommand    command5 = new SqlCommand(sql, DBconnect);
                SqlDataReader reader5  = command5.ExecuteReader();
                if (reader5.HasRows)
                {
                    reader5.Read();
                    string id;
                    id        = reader5.GetValue(0).ToString();
                    DBconnect = new SqlConnection(connetionString);
                    DBconnect.Open();
                    sql = "delete Plan_Zajec where Studenci_Id =" + id;
                    SqlCommand    command6 = new SqlCommand(sql, DBconnect);
                    SqlDataReader reader6  = command6.ExecuteReader();
                    MessageBox.Show("Odrzucono pomyślnie");
                    AdmWin next = new AdmWin("Admin", "Admin");
                    next.Show();
                    this.Hide();
                    reader6.Close();
                    DBconnect.Close();
                }
                reader5.Close();
                DBconnect.Close();
            }
        }