Exemplo n.º 1
0
        private void RemoveBtn_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string BookName      = BookNameTxtBx.Text;
                string Category      = CategoryTxtBx.Text;
                string Available     = AvailableTxtBx.Text;
                string Edition       = EditionTxtBx.Text;
                string PublishedYear = PublishYearTxtBx.Text;
                string AuthorName    = AuthorTxtBx.Text;
                string ISBN          = ISBNTxtBx.Text;
                string Language      = LanguageTxtBx.Text;

                if (string.IsNullOrEmpty(BookName) && string.IsNullOrEmpty(Category) && string.IsNullOrEmpty(Available) && string.IsNullOrEmpty(Edition) && string.IsNullOrEmpty(PublishedYear) && string.IsNullOrEmpty(AuthorName) && string.IsNullOrEmpty(ISBN) && string.IsNullOrEmpty(Language))
                {
                    MessageBox.Show(
                        messageBoxText: "Please enter valid Values.",
                        caption: "Error",
                        button: MessageBoxButton.OK,
                        MessageBoxImage.Error);

                    BookNameTxtBx.Focus();
                    CategoryTxtBx.Focus();
                    AvailableTxtBx.Focus();
                    EditionTxtBx.Focus();
                    PublishYearTxtBx.Focus();
                    AuthorTxtBx.Focus();
                    ISBNTxtBx.Focus();
                    LanguageTxtBx.Focus();
                }
                else
                {
                    con.Open();

                    cmd = new SqlCommand("Delete From Books Where BookName=@BookName and CategoryTitle=@CategoryTitle and Available=@Available and PublishedYear=@PublishedYear and Edition=@Edition and AuthorName=@AuthorName and ISBN=@ISBN and Language=@Language ", con);

                    cmd.Parameters.AddWithValue("@BookName", BookNameTxtBx.Text);
                    cmd.Parameters.AddWithValue("@CategoryTitle", CategoryTxtBx.Text);
                    cmd.Parameters.AddWithValue("@Available", AvailableTxtBx.Text);
                    cmd.Parameters.AddWithValue("@PublishedYear", PublishYearTxtBx.Text);
                    cmd.Parameters.AddWithValue("@Edition", EditionTxtBx.Text);
                    cmd.Parameters.AddWithValue("@AuthorName", AuthorTxtBx.Text);
                    cmd.Parameters.AddWithValue("@ISBN", ISBNTxtBx.Text);
                    cmd.Parameters.AddWithValue("@Language", LanguageTxtBx.Text);

                    int deleted = cmd.ExecuteNonQuery();
                    MessageBox.Show(
                        messageBoxText: $"Book «{BookNameTxtBx.Text}» successfully Removed",
                        caption: "Successful Remove",
                        button: MessageBoxButton.OK,
                        icon: MessageBoxImage.Information);
                    new SearchEditBookInformation().Show();
                    Close();
                }
            }
            catch (Exception b)
            {
                MessageBox.Show(
                    messageBoxText: "Exception occur :" + b.Message + "\t" + b.GetType(),
                    caption: "Exception",
                    button: MessageBoxButton.OK,
                    icon: MessageBoxImage.Error);
            }
        }
Exemplo n.º 2
0
        private void SaveBtn_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string BookName      = BookNameTxtBx.Text;
                string Category      = CategoryTxtBx.Text;
                string Available     = AvailableTxtBx.Text;
                string Edition       = EditionTxtBx.Text;
                string PublishedYear = PublishYearTxtBx.Text;
                string AuthorName    = AuthorTxtBx.Text;
                string ISBN          = ISBNTxtBx.Text;
                string Language      = LanguageTxtBx.Text;

                if (string.IsNullOrEmpty(BookName) && string.IsNullOrEmpty(Category) && string.IsNullOrEmpty(Available) && string.IsNullOrEmpty(Edition) && string.IsNullOrEmpty(PublishedYear) && string.IsNullOrEmpty(AuthorName) && string.IsNullOrEmpty(ISBN) && string.IsNullOrEmpty(Language))
                {
                    MessageBox.Show(
                        messageBoxText: "Please enter valid Values.",
                        caption: "Error",
                        button: MessageBoxButton.OK,
                        MessageBoxImage.Error);

                    BookNameTxtBx.Focus();
                    CategoryTxtBx.Focus();
                    AvailableTxtBx.Focus();
                    EditionTxtBx.Focus();
                    PublishYearTxtBx.Focus();
                    AuthorTxtBx.Focus();
                    ISBNTxtBx.Focus();
                    LanguageTxtBx.Focus();
                }
                else
                {
                    con = new SqlConnection(@"Data Source =.; Initial Catalog = Library; Integrated Security = True");
                    con.Open();
                    cmd = new SqlCommand("Update Books Set BookName=@BookName , CategoryTitle=@CategoryTitle, Available=@Available , PublishedYear=@PublishedYear , Edition=@Edition , AuthorName=@AuthorName , ISBN=@ISBN , Language=@Language where Id = '" + SearchEditBookInformation.SetValueForBookId + "'", con);
                    cmd.Parameters.Add("@BookName", BookNameTxtBx.Text);
                    cmd.Parameters.Add("@CategoryTitle", CategoryTxtBx.Text);
                    cmd.Parameters.Add("@Available", AvailableTxtBx.Text);
                    cmd.Parameters.Add("@PublishedYear", PublishYearTxtBx.Text);
                    cmd.Parameters.Add("@Edition", EditionTxtBx.Text);
                    cmd.Parameters.Add("@AuthorName", AuthorTxtBx.Text);
                    cmd.Parameters.Add("@ISBN", ISBNTxtBx.Text);
                    cmd.Parameters.Add("@Language", LanguageTxtBx.Text);
                    cmd.ExecuteNonQuery();
                    MessageBox.Show(
                        messageBoxText: $"Information of the Book «{BookNameTxtBx.Text}» Successfully Updated",
                        caption: "Successful Update",
                        button: MessageBoxButton.OK,
                        icon: MessageBoxImage.Information);
                    con.Close();
                    new SearchEditBookInformation().Show();
                    Close();
                }
            }
            catch (Exception b)
            {
                MessageBox.Show(
                    messageBoxText: "Exception occur :" + b.Message + "\t" + b.GetType(),
                    caption: "Exception",
                    button: MessageBoxButton.OK,
                    icon: MessageBoxImage.Error);
            }
        }
Exemplo n.º 3
0
        private void SaveBtn_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string BookName      = BookNameTxtBx.Text;
                string Category      = CategoryTxtBx.Text;
                string Available     = AvailableTxtBx.Text;
                string Edition       = EditionTxtBx.Text;
                string PublishedYear = PublishYearTxtBx.Text;
                string AuthorName    = AuthorTxtBx.Text;
                string ISBN          = ISBNTxtBx.Text;
                string Language      = LanguageTxtBx.Text;

                if (string.IsNullOrEmpty(BookName) && string.IsNullOrEmpty(Category) && string.IsNullOrEmpty(Available) && string.IsNullOrEmpty(Edition) && string.IsNullOrEmpty(PublishedYear) && string.IsNullOrEmpty(AuthorName) && string.IsNullOrEmpty(ISBN) && string.IsNullOrEmpty(Language))
                {
                    MessageBox.Show(
                        messageBoxText: "Please enter valid Values.",
                        caption: "Error",
                        button: MessageBoxButton.OK,
                        MessageBoxImage.Error);

                    BookNameTxtBx.Focus();
                    CategoryTxtBx.Focus();
                    AvailableTxtBx.Focus();
                    EditionTxtBx.Focus();
                    PublishYearTxtBx.Focus();
                    AuthorTxtBx.Focus();
                    ISBNTxtBx.Focus();
                    LanguageTxtBx.Focus();
                }
                else
                {
                    con.Open();
                    cmd = new SqlCommand("INSERT INTO Books (BookName,CategoryTitle,Available,PublishedYear,Edition,AuthorName,ISBN,Language) VALUES (@BookName,@CategoryTitle,@Available,@PublishedYear,@Edition,@AuthorName,@ISBN,@Language)", con);
                    cmd.Parameters.Add("@BookName", BookNameTxtBx.Text);
                    cmd.Parameters.Add("@CategoryTitle", CategoryTxtBx.Text);
                    cmd.Parameters.Add("@Available", AvailableTxtBx.Text);
                    cmd.Parameters.Add("@PublishedYear", PublishYearTxtBx.Text);
                    cmd.Parameters.Add("@Edition", EditionTxtBx.Text);
                    cmd.Parameters.Add("@AuthorName", AuthorTxtBx.Text);
                    cmd.Parameters.Add("@ISBN", ISBNTxtBx.Text);
                    cmd.Parameters.Add("@Language", LanguageTxtBx.Text);
                    cmd.ExecuteNonQuery();
                    MessageBox.Show(
                        messageBoxText: $"Book «{BookNameTxtBx.Text}» successfully Added",
                        caption: "Successful Adding",
                        button: MessageBoxButton.OK,
                        icon: MessageBoxImage.Information);
                    con.Close();
                    BookNameTxtBx.Text    = "";
                    CategoryTxtBx.Text    = "";
                    AvailableTxtBx.Text   = "";
                    EditionTxtBx.Text     = "";
                    PublishYearTxtBx.Text = "";
                    AuthorTxtBx.Text      = "";
                    ISBNTxtBx.Text        = "";
                    LanguageTxtBx.Text    = "";
                }
            }
            catch (Exception b)
            {
                MessageBox.Show(
                    messageBoxText: "Exception occur :" + b.Message + "\t" + b.GetType(),
                    caption: "Exception",
                    button: MessageBoxButton.OK,
                    icon: MessageBoxImage.Error);
            }
        }