private void TeacherAddToAGroup_Load(object sender, EventArgs e)
        {
            string           getSchedules        = "SELECT Schedule FROM Groups";
            SqlConnection    connection          = CommonFormActions.CreateConnection("LanguageSchool");
            SqlCommand       getcShedulesCommand = CommonFormActions.CreateCommand(connection, getSchedules);
            HashSet <string> schedules           = new HashSet <string>();

            try
            {
                using (connection)
                {
                    connection.Open();
                    SqlDataReader reader = getcShedulesCommand.ExecuteReader();
                    while (reader.Read())
                    {
                        string currentShedule = reader.GetString(1);
                        schedules.Add(currentShedule);
                    }
                    connection.Close();
                }
            }
            catch (SqlException ol)
            {
                MessageBox.Show(ol.Message.ToString());
                connection.Close();
            }

            foreach (string item in schedules)
            {
                schedule.Items.Add(item);
            }
            startDate.Format       = DateTimePickerFormat.Custom;
            startDate.CustomFormat = "yyyy-MM-dd";
        }
Example #2
0
        private void removeStudent_Click(object sender, EventArgs e)
        {
            SqlConnection connection = CommonFormActions.CreateConnection("LanguageSchool");

            if (allStudentsTable.CurrentRow.Index > -1)
            {
                string       query     = "DELETE FROM Students WHERE [Id Student] = @IdStudent";
                SqlParameter idStudent = new SqlParameter("@IdStudent", SqlDbType.Int);
                idStudent.Value = allStudentsTable.CurrentRow.Cells[0].Value;
                SqlParameter[] parameters = new SqlParameter[1] {
                    idStudent
                };
                SqlCommand command = CommonFormActions.CreateCommand(connection, query, parameters);
                try
                {
                    using (connection)
                    {
                        SqlDataReader reader = command.ExecuteReader();
                        reader.Close();
                    }
                    CommonFormActions.ShowMessage("Success", "Student removed successfully");
                    CommonFormActions.UpdateDataGrid(connection, "Students", allStudentsTable);
                }
                catch (SqlException ol)
                {
                    MessageBox.Show(ol.Message.ToString());
                    connection.Close();
                }
            }
        }
Example #3
0
        private void All_Students_Load(object sender, EventArgs e)
        {
            SqlConnection connection = CommonFormActions.CreateConnection("LanguageSchool");

            using (connection)
            {
                SqlCommand command = new SqlCommand("SELECT * FROM Students;", connection);
                try
                {
                    connection.Open();
                    SqlDataReader reader = command.ExecuteReader();
                    if (reader.HasRows)
                    {
                        DataTable dt = new DataTable();
                        dt.Load(reader);
                        allStudentsTable.DataSource = dt;
                    }
                    else
                    {
                        CommonFormActions.ShowMessage("No Results", "No results to show");
                    }
                    reader.Close();
                }
                catch (SqlException ol)
                {
                    MessageBox.Show(ol.Message.ToString());
                }
            }
        }
Example #4
0
        private void findStudent_Click(object sender, EventArgs e)
        {
            SqlConnection connection = CommonFormActions.CreateConnection("LanguageSchool");

            try
            {
                string findStudentQuery = "SELECT * FROM Students WHERE Name=@Name OR [Family Name]=@FName OR Address=@Address";

                SqlParameter name = new SqlParameter("@Name", SqlDbType.NVarChar);
                name.Value = studentName.Text;

                SqlParameter fName = new SqlParameter("@FName", SqlDbType.NVarChar);
                fName.Value = studentFName.Text;

                SqlParameter address = new SqlParameter("@Address", SqlDbType.NVarChar);
                address.Value = studentAddress.Text;

                SqlParameter[] parameters = new SqlParameter[3] {
                    name, fName, address
                };

                SqlCommand findStudentCommand = CommonFormActions.CreateCommand(connection, findStudentQuery, parameters);
                student.DataSource = CommonFormActions.GetDataTable(connection, findStudentCommand);
            }
            catch (SqlException ol)
            {
                MessageBox.Show(ol.Message.ToString());
                connection.Close();
            }
        }
        private void findTeacher_Click(object sender, EventArgs e)
        {
            SqlConnection connection = CommonFormActions.CreateConnection("LanguageSchool");

            try
            {
                string findATeacherQuery = "SELECT * FROM Teachers WHERE PIN = @PIN OR Name = @Name OR [Family Name] = @FName OR Address = @Address";
                //Parameters
                SqlParameter PIN = new SqlParameter("@PIN", SqlDbType.NVarChar);
                PIN.Value = teacherPIN.Text;

                SqlParameter name = new SqlParameter("@Name", SqlDbType.NVarChar);
                name.Value = teacherName.Text;

                SqlParameter fName = new SqlParameter("@FName", SqlDbType.NVarChar);
                fName.Value = teacherFName.Text;

                SqlParameter address = new SqlParameter("@Address", SqlDbType.NVarChar);
                address.Value = teacherAddress.Text;

                SqlParameter[] parameters = new SqlParameter[4] {
                    PIN, name, fName, address
                };
                SqlCommand findTeacherCommand = CommonFormActions.CreateCommand(connection, findATeacherQuery, parameters);
                DataTable  teacherDataTable   = CommonFormActions.GetDataTable(connection, findTeacherCommand);
                teacher.DataSource = teacherDataTable;
            }
            catch (SqlException ol)
            {
                MessageBox.Show(ol.Message.ToString());
                connection.Close();
            }
        }
Example #6
0
        private string GetCode(string name)
        {
            string       getCode   = "SELECT Code FROM EducationFields WHERE Name = @Name";
            SqlParameter nameParam = new SqlParameter("@Name", SqlDbType.NVarChar);

            nameParam.Value = name;
            SqlParameter[] parameters = new SqlParameter[1] {
                nameParam
            };
            //string getCode = "SELECT Code FROM EducationFields";
            SqlConnection connection     = CommonFormActions.CreateConnection("LanguageSchool");
            SqlCommand    getCodeCommand = CommonFormActions.CreateCommand(connection, getCode, parameters);

            using (connection)
            {
                connection.Open();
                SqlDataReader reader = getCodeCommand.ExecuteReader();
                if (reader.Read())
                {
                    string code = reader.GetString(0);
                    return(code);
                }
                else
                {
                    return("");
                }
            }
        }
Example #7
0
        private void TeachersAddEducation_Load(object sender, EventArgs e)
        {
            string           getFields         = "SELECT Name FROM EducationFields";
            SqlConnection    connection        = CommonFormActions.CreateConnection("LanguageSchool");
            SqlCommand       getcFieldsCommand = CommonFormActions.CreateCommand(connection, getFields);
            HashSet <string> schedules         = new HashSet <string>();

            try
            {
                using (connection)
                {
                    connection.Open();
                    SqlDataReader reader = getcFieldsCommand.ExecuteReader();
                    while (reader.Read())
                    {
                        string currentShedule = reader.GetString(0);
                        schedules.Add(currentShedule);
                    }
                    connection.Close();
                }
            }
            catch (SqlException ol)
            {
                MessageBox.Show(ol.Message.ToString());
                connection.Close();
            }

            foreach (string item in schedules)
            {
                educationFields.Items.Add(item);
            }
        }
Example #8
0
        private void remTeacher_Click(object sender, EventArgs e)
        {
            SqlConnection connection = CommonFormActions.CreateConnection("LanguageSchool");

            if (allTeachersTable.CurrentRow.Index > -1)
            {
                string       query = "DELETE FROM Teachers WHERE PIN = @PIN";
                SqlParameter PIN   = new SqlParameter("@PIN", SqlDbType.NVarChar);
                PIN.Value = allTeachersTable.CurrentRow.Cells[0].Value;
                SqlParameter[] parameters = new SqlParameter[1] {
                    PIN
                };
                SqlCommand command = CommonFormActions.CreateCommand(connection, query, parameters);
                try
                {
                    using (connection)
                    {
                        SqlDataReader reader = command.ExecuteReader();
                        reader.Close();
                    }
                    CommonFormActions.ShowMessage("Success", "Teacher removed successfully");
                    CommonFormActions.UpdateDataGrid(connection, "Teachers", allTeachersTable);
                }
                catch (SqlException ol)
                {
                    MessageBox.Show(ol.Message.ToString());
                    connection.Close();
                }
            }
        }
Example #9
0
        private void teachersDataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            int    rowIndex          = teachersDataGridView.CurrentRow.Index;
            string currentTeacherPIN = teachersDataGridView.Rows[rowIndex].Cells[0].Value.ToString();

            if (currentTeacherPIN != "")
            {
                SqlConnection connectionForTeacher = CommonFormActions.CreateConnection("LanguageSchool");
                string        selectTeacher        = "SELECT * FROM Teachers WHERE PIN = @PIN";
                SqlParameter  selectTeacherPIN     = new SqlParameter("@PIN", SqlDbType.NVarChar);
                selectTeacherPIN.Value = currentTeacherPIN;
                SqlParameter[] selectTeacherParameters = new SqlParameter[1] {
                    selectTeacherPIN
                };
                SqlCommand selectStudentCommand     = CommonFormActions.CreateCommand(connectionForTeacher, selectTeacher, selectTeacherParameters);
                DataTable  selectedTeacherDataTable = CommonFormActions.GetDataTable(connectionForTeacher, selectStudentCommand);
                teachersDataGridView.DataSource = selectedTeacherDataTable;

                SqlConnection connectionForEducation = CommonFormActions.CreateConnection("LanguageSchool");
                string        selectEducation        = "SELECT PIN, Code, Certificate FROM [Teachers-EducationFields] WHERE PIN = @PIN";
                SqlParameter  selectEducationPIN     = new SqlParameter("@PIN", SqlDbType.NVarChar);
                selectEducationPIN.Value = currentTeacherPIN;
                SqlParameter[] selectEducationParameters = new SqlParameter[1] {
                    selectEducationPIN
                };
                SqlCommand selectEducationCommand     = CommonFormActions.CreateCommand(connectionForEducation, selectEducation, selectEducationParameters);
                DataTable  selectedEducationDataTable = CommonFormActions.GetDataTable(connectionForEducation, selectEducationCommand);
                teachers_EducationFieldsDataGridView.DataSource = selectedEducationDataTable;
            }
        }
        private void findGroup_Click(object sender, EventArgs e)
        {
            string findGroupQuery = "SELECT * FROM Groups WHERE [Start Date] >= @StartDate AND " +
                                    "Schedule = @Shedule AND [Start Time] >= @StartTime AND PIN IS NULL";

            //Parameters
            SqlParameter date = new SqlParameter("@StartDate", SqlDbType.Date);

            date.Value = startDate.Value.ToShortDateString();

            SqlParameter weekSchedule = new SqlParameter("@Shedule", SqlDbType.NVarChar);

            weekSchedule.Value = schedule.Text;

            SqlParameter time = new SqlParameter("@StartTime", SqlDbType.Time);

            time.Value = startTime.Value.TimeOfDay;

            SqlParameter[] parameters = new SqlParameter[3] {
                date, weekSchedule, time
            };

            SqlConnection connection      = CommonFormActions.CreateConnection("LanguageSchool");
            SqlCommand    findGroupCommad = CommonFormActions.CreateCommand(connection, findGroupQuery, parameters);
            DataTable     groups          = CommonFormActions.GetDataTable(connection, findGroupCommad);

            group.DataSource = groups;
        }
Example #11
0
        private void searchTerm_KeyUp(object sender, KeyEventArgs e)
        {
            SqlConnection connectionTeachersSearch = CommonFormActions.CreateConnection("LanguageSchool");

            try
            {
                string       selectTeachers = "SELECT * FROM Teachers WHERE PIN LIKE '%' + @Term + '%' or Name LIKE '%' + @Term + '%' or [Family Name] LIKE '%' + @Term + '%' or Address LIKE '%' + @Term + '%'";
                SqlParameter teachersTerm   = new SqlParameter("@Term", SqlDbType.NVarChar);
                teachersTerm.Value = searchTerm.Text;
                SqlParameter[] parameters = new SqlParameter[1] {
                    teachersTerm
                };
                DataTable  personalDataTable = new DataTable();
                SqlCommand command           = CommonFormActions.CreateCommand(connectionTeachersSearch, selectTeachers, parameters);
                using (connectionTeachersSearch)
                {
                    connectionTeachersSearch.Open();
                    command.ExecuteNonQuery();
                    personalDataTable = CommonFormActions.GetDataTable(connectionTeachersSearch, command);
                    connectionTeachersSearch.Close();
                }
                teachersDataGridView.DataSource = personalDataTable;
                string    selectTeachersEducation = "";
                DataTable educationDataTable      = new DataTable();
                for (int row = 0; row < teachersDataGridView.Rows.Count - 1; row++)
                {
                    SqlConnection connectionEducationSearch = CommonFormActions.CreateConnection("LanguageSchool");
                    string        currentPIN = teachersDataGridView.Rows[row].Cells[0].Value.ToString();
                    selectTeachersEducation = "SELECT tef.PIN, tef.Code, tef.Certificate FROM [Teachers-EducationFields] as tef WHERE tef.PIN = @PIN";
                    SqlParameter teachersEducParam = new SqlParameter("@PIN", SqlDbType.NVarChar);
                    teachersEducParam.Value = currentPIN;
                    SqlParameter[] parametersEducation = new SqlParameter[1] {
                        teachersEducParam
                    };
                    SqlCommand commandEduc = CommonFormActions.CreateCommand(connectionEducationSearch, selectTeachersEducation, parametersEducation);
                    using (connectionEducationSearch)
                    {
                        DataTable currentResults = CommonFormActions.GetDataTable(connectionEducationSearch, commandEduc);
                        educationDataTable.Merge(currentResults, true);
                    }
                }
                teachers_EducationFieldsDataGridView.DataSource = educationDataTable;
            }
            catch (SqlException ol)
            {
                MessageBox.Show(ol.Message.ToString());
                connectionTeachersSearch.Close();
            }
        }
Example #12
0
        private void TeacherShowEducation(SqlConnection connection, string PIN, DataGridView table)
        {
            string showEducationQuery = "SELECT ef.Name, tef.Certificate FROM " +
                                        "EducationFields as ef INNER JOIN [Teachers-EducationFields] as tef ON " +
                                        "ef.Code = tef.Code WHERE tef.PIN = @PIN";
            SqlParameter PINParam = new SqlParameter("@PIN", SqlDbType.NVarChar);

            PINParam.Value = PIN;
            SqlParameter[] parameters = new SqlParameter[1] {
                PINParam
            };
            SqlCommand showEducationCommand   = CommonFormActions.CreateCommand(connection, showEducationQuery, parameters);
            DataTable  showEducationDataTable = CommonFormActions.GetDataTable(connection, showEducationCommand);

            table.DataSource = showEducationDataTable;
        }
        private void assingn_Click(object sender, EventArgs e)
        {
            if (group.Rows.Count > 1 && teacher.Rows.Count > 1)
            {
                if (teacher.Rows.Count > 2)
                {
                    CommonFormActions.ShowMessage("Notice", "PLease selcet only one teacher!");
                    return;
                }

                if (group.Rows.Count > 2)
                {
                    CommonFormActions.ShowMessage("Notice", "Please select only one group!");
                    return;
                }

                string assignGroupQuery = "UPDATE Groups SET PIN = @PIN WHERE [Id Group] = @IdGroup";


                //Parameters
                SqlParameter idGroup = new SqlParameter("@IdGroup", SqlDbType.Int);
                idGroup.Value = group.Rows[0].Cells[0].Value;

                SqlParameter PIN = new SqlParameter("@PIN", SqlDbType.NVarChar);
                PIN.Value = teacher.Rows[0].Cells[0].Value;

                SqlParameter[] parameters = new SqlParameter[2] {
                    idGroup, PIN
                };

                SqlConnection connection         = CommonFormActions.CreateConnection("LanguageSchool");
                SqlCommand    assignGroupCommand = CommonFormActions.CreateCommand(connection, assignGroupQuery, parameters);
                using (connection)
                {
                    connection.Open();
                    SqlDataReader reader = assignGroupCommand.ExecuteReader();
                    reader.Close();
                    connection.Close();
                }
                CommonFormActions.ShowMessage("Success", "Group assigned successfully.");
            }
            else
            {
                CommonFormActions.ShowMessage("Notice", "Please select teacher and group!");
            }
        }
Example #14
0
        private void findTeacher_Click(object sender, EventArgs e)
        {
            SqlConnection connection = CommonFormActions.CreateConnection("LanguageSchool");

            try
            {
                string findATeacherQuery = "SELECT * FROM Teachers WHERE PIN = @PIN OR Name = @Name OR [Family Name] = @FName OR Address = @Address";
                //Parameters
                SqlParameter PIN = new SqlParameter("@PIN", SqlDbType.NVarChar);
                PIN.Value = teacherPIN.Text;

                SqlParameter name = new SqlParameter("@Name", SqlDbType.NVarChar);
                name.Value = teacherName.Text;

                SqlParameter fName = new SqlParameter("@FName", SqlDbType.NVarChar);
                fName.Value = teacherFName.Text;

                SqlParameter address = new SqlParameter("@Address", SqlDbType.NVarChar);
                address.Value = teacherAddress.Text;

                SqlParameter[] parameters = new SqlParameter[4] {
                    PIN, name, fName, address
                };
                SqlCommand findTeacherCommand = CommonFormActions.CreateCommand(connection, findATeacherQuery, parameters);
                DataTable  teacherDataTable   = CommonFormActions.GetDataTable(connection, findTeacherCommand);
                teacher.DataSource = teacherDataTable;
                if (teacher.Rows.Count == 2)
                {
                    SqlConnection connectionShowEducation = CommonFormActions.CreateConnection("LanguageSchool");
                    string        currentPIN = teacher.Rows[0].Cells[0].Value.ToString();
                    TeacherShowEducation(connectionShowEducation, currentPIN, teacherEducation);
                }
                else
                {
                    CommonFormActions.ShowMessage("Notice", "Please select a teacher to show education!");
                    teacherEducation.DataSource = null;
                }
            }
            catch (SqlException ol)
            {
                MessageBox.Show(ol.Message.ToString());
                connection.Close();
            }
        }
Example #15
0
        private void enroll_Click(object sender, EventArgs e)
        {
            if (group.Rows.Count > 1 && student.Rows.Count > 1)
            {
                if (student.Rows.Count > 2)
                {
                    CommonFormActions.ShowMessage("Notice", "PLease selcet only one student!");
                    return;
                }

                if (group.Rows.Count > 2)
                {
                    CommonFormActions.ShowMessage("Notice", "Please select only one group!");
                    return;
                }

                string enrolStudentQuery = "INSERT INTO [Students-Groups] ([Id Student], [Id Group]) VALUES(@IdStudent, @IdGroup)";

                //Parameters
                SqlParameter idStudent = new SqlParameter("@IdStudent", SqlDbType.Int);
                idStudent.Value = student.Rows[0].Cells[0].Value;

                SqlParameter idGroup = new SqlParameter("@IdGroup", SqlDbType.Int);
                idGroup.Value = group.Rows[0].Cells[0].Value;

                SqlParameter[] parameters = new SqlParameter[2] {
                    idStudent, idGroup
                };

                SqlConnection connection           = CommonFormActions.CreateConnection("LanguageSchool");
                SqlCommand    enrollStudentCommand = CommonFormActions.CreateCommand(connection, enrolStudentQuery, parameters);
                using (connection)
                {
                    SqlDataReader reader = enrollStudentCommand.ExecuteReader();
                    reader.Close();
                }
                CommonFormActions.ShowMessage("Success", "Student enrolled successfully");
            }
            else
            {
                CommonFormActions.ShowMessage("Notice", "Please select student and group!");
            }
        }
        private void teacher_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            SqlConnection connection        = CommonFormActions.CreateConnection("LanguageSchool");
            int           rowIndex          = teacher.CurrentRow.Index;
            string        currentTeacherPIN = teacher.Rows[rowIndex].Cells[0].Value.ToString();

            if (currentTeacherPIN != "")
            {
                string selectStudentQuery = "SELECT * FROM Teachers WHERE [PIN]=@PIN";

                SqlParameter PIN = new SqlParameter("@PIN", SqlDbType.NVarChar);
                PIN.Value = currentTeacherPIN;
                SqlParameter[] parameters = new SqlParameter[1] {
                    PIN
                };
                SqlCommand selectTeacherCommand = CommonFormActions.CreateCommand(connection, selectStudentQuery, parameters);
                DataTable  selectedStudent      = CommonFormActions.GetDataTable(connection, selectTeacherCommand);
                teacher.DataSource = selectedStudent;
            }
        }
        private void group_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            SqlConnection connection     = CommonFormActions.CreateConnection("LanguageSchool");
            int           rowIndex       = group.CurrentRow.Index;
            int           currentGroupId = 0;
            bool          isId           = int.TryParse(group.Rows[rowIndex].Cells[0].Value.ToString(), out currentGroupId);

            if (isId)
            {
                string       selectGroupQuery = "SELECT * FROM Groups WHERE [Id Group]=@IdGroup";
                SqlParameter groupId          = new SqlParameter("@IdGroup", SqlDbType.Int);
                groupId.Value = currentGroupId;
                SqlParameter[] parameters = new SqlParameter[1] {
                    groupId
                };
                SqlCommand selectGroupCommand = CommonFormActions.CreateCommand(connection, selectGroupQuery, parameters);
                DataTable  selectedGroup      = CommonFormActions.GetDataTable(connection, selectGroupCommand);
                group.DataSource = selectedGroup;
            }
        }
Example #18
0
        private void updStudent_Click(object sender, EventArgs e)
        {
            SqlConnection connection = CommonFormActions.CreateConnection("LanguageSchool");

            if (allStudentsTable.CurrentRow.Index > -1)
            {
                string       query     = "UPDATE Students SET Name = @Name, [Family Name] = @FName, Address = @Address WHERE [Id Student] = @IdStudent";
                SqlParameter studentId = new SqlParameter("@IdStudent", SqlDbType.Int);
                studentId.Value = allStudentsTable.CurrentRow.Cells[0].Value;

                SqlParameter studentName = new SqlParameter("@Name", SqlDbType.NVarChar);
                studentName.Value = allStudentsTable.CurrentRow.Cells[1].Value;

                SqlParameter studentFamilyName = new SqlParameter("@FName", SqlDbType.NVarChar);
                studentFamilyName.Value = allStudentsTable.CurrentRow.Cells[2].Value;

                SqlParameter studentAddress = new SqlParameter("@Address", SqlDbType.NVarChar);
                studentAddress.Value = allStudentsTable.CurrentRow.Cells[3].Value;

                SqlParameter[] parameters = new SqlParameter[4] {
                    studentId, studentName, studentFamilyName, studentAddress
                };
                SqlCommand command = CommonFormActions.CreateCommand(connection, query, parameters);
                try
                {
                    using (connection)
                    {
                        SqlDataReader reader = command.ExecuteReader();
                        reader.Close();
                    }
                    CommonFormActions.ShowMessage("Success", "Student updated successfully.");
                    CommonFormActions.UpdateDataGrid(connection, "Students", allStudentsTable);
                }
                catch (SqlException ol)
                {
                    MessageBox.Show(ol.Message.ToString());
                    connection.Close();
                }
            }
        }
Example #19
0
        private void addTeacher_Click(object sender, EventArgs e)
        {
            if (allTeachersTable.CurrentRow.Index > -1)
            {
                string query = "INSERT INTO Teachers (PIN, Name, [Family Name], Address) VALUES(@PIN, @Name, @FName, @Address)";

                SqlParameter PIN = new SqlParameter("@PIN", SqlDbType.NVarChar);
                PIN.Value = allTeachersTable.CurrentRow.Cells[0].Value;

                SqlParameter teacherName = new SqlParameter("@Name", SqlDbType.NVarChar);
                teacherName.Value = allTeachersTable.CurrentRow.Cells[1].Value;

                SqlParameter teacherFamilyName = new SqlParameter("@FName", SqlDbType.NVarChar);
                teacherFamilyName.Value = allTeachersTable.CurrentRow.Cells[2].Value;

                SqlParameter teacherAddress = new SqlParameter("@Address", SqlDbType.NVarChar);
                teacherAddress.Value = allTeachersTable.CurrentRow.Cells[3].Value;

                SqlParameter[] parameters = new SqlParameter[4] {
                    PIN, teacherName, teacherFamilyName, teacherAddress
                };
                SqlCommand command = CommonFormActions.CreateCommand(connection, query, parameters);
                try
                {
                    using (connection)
                    {
                        SqlDataReader reader = command.ExecuteReader();
                        reader.Close();
                    }
                    CommonFormActions.ShowMessage("Success", "New teacher added successfully.");
                    CommonFormActions.UpdateDataGrid(connection, "Teachers", allTeachersTable);
                }
                catch (SqlException ol)
                {
                    MessageBox.Show(ol.Message.ToString());
                    connection.Close();
                }
            }
        }
Example #20
0
        private void student_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            SqlConnection connection       = CommonFormActions.CreateConnection("LanguageSchool");
            int           rowIndex         = student.CurrentRow.Index;
            string        currentStudentId = student.Rows[rowIndex].Cells[0].Value.ToString();

            if (currentStudentId != "")
            {
                string       selectStudentQuery = "SELECT * FROM Students WHERE [Id Student]=@IdStudent";
                SqlParameter studentId          = new SqlParameter("@IdStudent", SqlDbType.NVarChar);
                studentId.Value = currentStudentId;
                SqlParameter[] parameters = new SqlParameter[1] {
                    studentId
                };
                SqlCommand selectStudentCommand = CommonFormActions.CreateCommand(connection, selectStudentQuery, parameters);
                using (connection)
                {
                    DataTable selectedStudent = CommonFormActions.GetDataTable(connection, selectStudentCommand);
                    student.DataSource = selectedStudent;
                }
            }
        }
Example #21
0
        private void addStudent_Click(object sender, EventArgs e)
        {
            SqlConnection connection = CommonFormActions.CreateConnection("LanguageSchool");

            if (allStudentsTable.CurrentRow.Index > -1)
            {
                string query = "INSERT INTO Students (Name, [Family Name], Address) VALUES(@Name, @FName, @Address)";

                SqlParameter studentName = new SqlParameter("@Name", SqlDbType.NVarChar);
                studentName.Value = allStudentsTable.CurrentRow.Cells[1].Value;

                SqlParameter studentFamilyName = new SqlParameter("@FName", SqlDbType.NVarChar);
                studentFamilyName.Value = allStudentsTable.CurrentRow.Cells[2].Value;

                SqlParameter studentAddress = new SqlParameter("@Address", SqlDbType.NVarChar);
                studentAddress.Value = allStudentsTable.CurrentRow.Cells[3].Value;

                SqlParameter[] parameters = new SqlParameter[3] {
                    studentName, studentFamilyName, studentAddress
                };
                SqlCommand command = CommonFormActions.CreateCommand(connection, query, parameters);
                try
                {
                    using (connection)
                    {
                        SqlDataReader reader = command.ExecuteReader();
                        reader.Close();
                    }
                    CommonFormActions.ShowMessage("Success", "New student added successfully.");
                    CommonFormActions.UpdateDataGrid(connection, "Students", allStudentsTable);
                }
                catch (SqlException ol)
                {
                    MessageBox.Show(ol.Message.ToString());
                    connection.Close();
                }
            }
        }
Example #22
0
        private void addEducation_Click(object sender, EventArgs e)
        {
            if (teacher.Rows.Count > 2)
            {
                CommonFormActions.ShowMessage("Notice", "Please select only one teacher before add education!");
            }
            SqlConnection connection   = CommonFormActions.CreateConnection("LanguageSchool");
            string        addEducation = "INSERT INTO [Teachers-EducationFields] (PIN, Code, Certificate) VALUES (@PIN, @Code, @Certificate)";
            SqlParameter  PIN          = new SqlParameter("@PIN", SqlDbType.NVarChar);

            PIN.Value = teacher.Rows[0].Cells[0].Value.ToString();
            SqlParameter code           = new SqlParameter("@Code", SqlDbType.NVarChar);
            string       educationField = educationFields.Text;

            if (educationField != "")
            {
                string codeStr = GetCode(educationField);
                if (codeStr != "")
                {
                    code.Value = codeStr;
                }
                else
                {
                    CommonFormActions.ShowMessage("Notice", "Please select corect education field!");
                    return;
                }
            }
            else
            {
                CommonFormActions.ShowMessage("Notice", "Please select education field first!");
                return;
            }
            SqlParameter certificate = new SqlParameter("@Certificate", SqlDbType.NVarChar);

            if (certificate.Value != null)
            {
                certificate.Value = certificate.Value;
            }
            else
            {
                certificate.Value = "";
            }
            SqlParameter[] parameters = new SqlParameter[3] {
                PIN, code, certificate
            };
            SqlCommand addEducationCommand = CommonFormActions.CreateCommand(connection, addEducation, parameters);

            try
            {
                using (connection)
                {
                    connection.Open();
                    SqlDataReader reader = addEducationCommand.ExecuteReader();
                    reader.Close();
                    connection.Close();
                    SqlConnection connectionShowEducation = CommonFormActions.CreateConnection("LanguageSchool");
                    string        currentPIN = teacher.Rows[0].Cells[0].Value.ToString();
                    TeacherShowEducation(connectionShowEducation, currentPIN, teacherEducation);
                    CommonFormActions.ShowMessage("Success", "Education information added successfully.");
                }
            }
            catch (SqlException ol)
            {
                if (ol.Number == 2627)
                {
                    CommonFormActions.ShowMessage("Notice", "Cannot finish because of duplicate information.");
                    return;
                }
                MessageBox.Show(ol.Number.ToString());
                connection.Close();
            }
        }