private void SaveButton_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection("Data Source=DESKTOP-P024OII\\TARIQULPC;Initial Catalog=Library_Management_System;Integrated Security=True"); try { con.Open(); SqlCommand cmd = con.CreateCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = "insert into BooksInfo values('" + BookNameTextBox.Text + "', '" + AuthorNameTextBox.Text + "', '" + dateTimePicker1.Text + "', " + PriceTextBox.Text + ", " + QuantityTextBox.Text + ", " + QuantityTextBox.Text + ")"; cmd.ExecuteNonQuery(); MessageBox.Show("Book is successfully added"); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { con.Close(); } BookNameTextBox.Clear(); AuthorNameTextBox.Clear(); PriceTextBox.Clear(); QuantityTextBox.Clear(); }
private void AcceptButton_Click(object sender, RoutedEventArgs e) { try { string name = BookNameTextBox.Text; int count = int.Parse(BookCountTextBox.Text); BookNameTextBox.Clear(); BookCountTextBox.Clear(); _books.Create(new Book(name, count)); } catch (Exception exp) { (Owner.Owner as MainWindow).CallExceptionWindow($"Что-то пошло не так :(\n+{exp.Message}"); return; } (Owner.Owner as MainWindow).CallAcceptWindow("Книга добавлена успешно"); }
private void IssueButton_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection("Data Source=DESKTOP-P024OII\\TARIQULPC;Initial Catalog=Library_Management_System;Integrated Security=True"); try { con.Open(); SqlCommand scmd = new SqlCommand("select * from BooksInfo where BookName = '" + BookNameTextBox.Text + "'", con); SqlDataReader sdr = scmd.ExecuteReader(); int AvailableBook = 0; int id = 0; if (sdr.Read()) { AvailableBook = Convert.ToInt32(sdr[6]); id = Convert.ToInt16(sdr[0]); } con.Close(); if (AvailableBook != 0) { con.Open(); SqlCommand sscmd = new SqlCommand("select * from Issue_book where StuID = '" + StuID + "' and BookID = " + id + ";", con); SqlDataReader sReader = sscmd.ExecuteReader(); int count = 0; while (sReader.Read()) { count++; } con.Close(); if (count == 0) { con.Open(); SqlCommand cmd = new SqlCommand("insert into Issue_book(StuID ,StuName, StuDept, StuContact, StuEmail, BookID, BookName, BookIssueDate, RemainDay) values('" + StuID + "', '" + StuNameTextBox.Text + "', '" + StuDeptTextBox.Text + "', '" + StuContTextBox.Text + "', '" + StuEmailTextBox.Text + "', " + id + ", '" + BookNameTextBox.Text + "', '" + IssueDateTimePicker.Value.ToString() + "', '" + Convert.ToInt16(RemainDayTextBox.Text) + "');", con); cmd.ExecuteNonQuery(); con.Close(); MessageBox.Show("Book is successfully issued", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); con.Open(); AvailableBook--; SqlCommand ucmd = new SqlCommand("update BooksInfo set AvailableQnt = " + AvailableBook + " where BookName = '" + BookNameTextBox.Text + "'", con); ucmd.ExecuteNonQuery(); con.Close(); } else if (count > 0) { MessageBox.Show("You have issued this book once but did not return. So return first", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { MessageBox.Show("This book is not available", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { con.Close(); } BookNameTextBox.Clear(); }
private void button1_Click(object sender, EventArgs e) { int check; if (StudentNameTextBox.Text == string.Empty && DepartmentComboBox.SelectedIndex < 0 && RollNoTextBox.Text == string.Empty && CategoryComboBox.SelectedIndex < 0 && BookNameTextBox.Text == string.Empty) { MessageBox.Show("Fill all Fields!"); } else if (StudentNameTextBox.Text == string.Empty) { MessageBox.Show("Please enter student name"); } else if (DepartmentComboBox.SelectedIndex < 0) { MessageBox.Show("Please Select Department"); } else if (RollNoTextBox.Text == string.Empty) { MessageBox.Show("Please Enter Roll Number"); } else if (!int.TryParse(RollNoTextBox.Text, out check)) { MessageBox.Show("Roll No can only be Integar"); RollNoTextBox.Clear(); } else if (CategoryComboBox.SelectedIndex < 0) { MessageBox.Show("Please Select Category"); } else if (BookNameTextBox.Text == string.Empty) { MessageBox.Show("please enter book name"); } else { string Student_Name = StudentNameTextBox.Text; string Department = DepartmentComboBox.SelectedItem.ToString(); string Roll_No = RollNoTextBox.Text; string Category = CategoryComboBox.SelectedItem.ToString(); string Book_Name = BookNameTextBox.Text; DateTime Issuance_Date = IssuanceDateDateTimePicker.Value; DateTime Due_Date = DueDateDateTimePicker.Value; int recieved = dataAccess.InsertIntoBookIssuanceTable(Student_Name, Department, Roll_No, Category, Book_Name, Issuance_Date, Due_Date); if (recieved == 1) { date_time = DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString(); writer = file.AppendText(); writer.WriteLine("New Book is Issued at " + date_time); writer.Close(); MessageBox.Show("Data is stored successfully"); } else { MessageBox.Show("Data is not Stored Successfully"); } StudentNameTextBox.Clear(); DepartmentComboBox.SelectedIndex = -1; RollNoTextBox.Clear(); CategoryComboBox.SelectedIndex = -1; BookNameTextBox.Clear(); IssuanceDateDateTimePicker.ResetText(); DueDateDateTimePicker.ResetText(); } }