private void LoadBookIssueForm()
 {
     if (_selectedId > 0)
     {
         var selectedbookIsbnNo = "";
         using (var connection = new SqlConnection(@"data source=.\SQLEXPRESS;DATABASE=Library ;Integrated Security=true;")
                )
         {
             var command = new SqlCommand("select Isbn from Book where BookId=@id", connection);
             command.Parameters.AddWithValue("@id", _selectedId);
             connection.Open();
             var reader = command.ExecuteReader();
             reader.Read();
             selectedbookIsbnNo = reader.GetString(0);
         }
         this.Hide();
         var objBookIssueForm = new BookIssueForm(selectedbookIsbnNo);
         objBookIssueForm.Show();
     }
     else
     {
         var objDialogWindow = new DialogWindow("Please select book ISBN or a row to issue book", "Warning Dialog", DialogWindow.DialogBoxIconType.Exclamation);
         objDialogWindow.ShowDialog();
     }
 }
        private void StudentAddButton_Click(object sender, EventArgs e)
        {
            if (StudentIdTextBox.Text == "")
            {
                label8.Show();
            }
            if (StudentIdTextBox.Text != "")
            {
                label8.Hide();
            }


            if (StudentNameTextBox.Text == "")
            {
                label16.Show();
            }
            if (StudentNameTextBox.Text != "")
            {
                label16.Hide();
            }


            if (LibraryCardNoTextBox.Text == "")
            {
                label15.Show();
            }
            if (LibraryCardNoTextBox.Text != "")
            {
                label15.Hide();
            }


            if (DepartmentComboBox.Text == "")
            {
                label5.Show();
            }
            if (DepartmentComboBox.Text != "")
            {
                label5.Hide();
            }

            if (SessionComboBox.Text == "")
            {
                label6.Show();
            }
            if (SessionComboBox.Text != "")
            {
                label6.Hide();
            }

            if (StudentIdTextBox.Text == "" || StudentNameTextBox.Text == "" || LibraryCardNoTextBox.Text == "" || SessionComboBox.Text == "" || DepartmentComboBox.Text == "")
            {
                return;
            }
            if (!CheckIsStudentIdExist())
            {
                try
                {
                    int departmentId;
                    using (
                        var con = new SqlConnection(@"data source=.\SQLEXPRESS;DATABASE=Library ;Integrated Security=true;")
                        )
                    {
                        con.Open();
                        var           command       = new SqlCommand("select DepartmentId from Department where DepartmentShortName='" + DepartmentComboBox.SelectedItem + "'or DepartmentFullName='" + DepartmentComboBox.SelectedItem + "' ", con);
                        SqlDataReader sqlDatRreader = command.ExecuteReader();
                        sqlDatRreader.Read();
                        departmentId = sqlDatRreader.GetInt32(0);
                    }


                    var stream  = new FileStream(_op.FileName, FileMode.Open, FileAccess.Read);
                    var reader  = new StreamReader(stream);
                    var imgData = new Byte[stream.Length - 1];
                    stream.Read(imgData, 0, (int)stream.Length - 1);

                    label7.Hide();
                    var sqlCommand =
                        new SqlCommand(
                            "insert into Student values(@StudentId,@Name,@LibraryCardNo,@DepartmentId,@SessionId,@Image) ",
                            _connection);

                    sqlCommand.Parameters.AddWithValue("@StudentId", StudentIdTextBox.Text);
                    sqlCommand.Parameters.AddWithValue("@DepartmentId", departmentId);
                    sqlCommand.Parameters.AddWithValue("@SessionId", SessionComboBox.SelectedValue);
                    sqlCommand.Parameters.AddWithValue("@Name", StudentNameTextBox.Text);
                    sqlCommand.Parameters.AddWithValue("@LibraryCardNo", LibraryCardNoTextBox.Text);
                    sqlCommand.Parameters.AddWithValue("@Image", imgData);



                    sqlCommand.ExecuteNonQuery();

                    _connection.Close();


                    if (Convert.ToInt32(label12.Text) == 3)
                    {
                        var sqlCommand1 =
                            new SqlCommand(
                                "select max(Id) from Student",
                                _connection);
                        _connection.Open();
                        var reader1 = sqlCommand1.ExecuteReader();
                        reader1.Read();
                        var id = reader1.GetInt32(0);


                        _connection.Close();
                        this.Hide();
                        var bookReservationPage = new BookIssueForm(id);
                        bookReservationPage.Closed += (s, args) => this.Close();
                        bookReservationPage.Show();
                    }
                    else
                    {
                        LoadStudentGridView();
                        MessageBox.Show(@"New student has been inserted successfully ", "", MessageBoxButtons.OK,
                                        MessageBoxIcon.Information);
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show(@"Something is wrong.Please make sure that student image is uploaded and try again.", "",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                label7.Show();
            }
        }