Пример #1
0
        private void Borrow_Click_1(object sender, EventArgs e)
        {
            //Initiating SQL Connection:
            SqlConnection con = new SqlConnection();

            //ConnectionString:
            con.ConnectionString = "data source = DESKTOP-QPUU33H;" +
                                   "database = Library;" +
                                   "integrated security = true";

            //Generating SQL Query
            string sql = "INSERT INTO TransactionReport(UserId,BookId) VALUES(@param1,@param2)";

            using (SqlCommand cmd = new SqlCommand(sql, con))
            {
                //Opening the connection:
                con.Open();

                cmd.Parameters.Add("@param1", SqlDbType.VarChar, 50).Value = viewId.Text.ToString();
                cmd.Parameters.Add("@param2", SqlDbType.Int).Value         = int.Parse(showBookId.Text);


                cmd.CommandType = CommandType.Text;
                cmd.ExecuteNonQuery();
                con.Close();
            }


            if ((int.Parse(showAvailable.Text)) != 0)
            {
                //Initiating SQL Connection:
                SqlConnection con1 = new SqlConnection();


                //ConnectionString:
                con1.ConnectionString = "data source = DESKTOP-QPUU33H;" +
                                        "database = Library;" +
                                        "integrated security = true";

                //Generating SQL Query
                string sql1 = "UPDATE Book SET BookQuantity = " + " '" + (int.Parse(showAvailable.Text) - 1) + "'" + "where BookId=" + int.Parse(showBookId.Text);
                using (SqlCommand cmd = new SqlCommand(sql1, con1))
                {
                    //Opening the connection:
                    con1.Open();

                    cmd.Parameters.Add("BookId", SqlDbType.Int).Value = int.Parse(showBookId.Text);

                    cmd.CommandType = CommandType.Text;
                    cmd.ExecuteNonQuery();

                    //Disconnect
                    con1.Close();


                    BookGridView.Rows.Clear();
                    BookGridView.Refresh();
                }
            }
        }
Пример #2
0
        private void returnbookbtn_Click(object sender, EventArgs e)
        {
            //Initiating SQL Connection:
            SqlConnection con1 = new SqlConnection();


            //ConnectionString:
            con1.ConnectionString = "data source = DESKTOP-QPUU33H;" +
                                    "database = Library;" +
                                    "integrated security = true";

            //Generating SQL Query
            string sql1 = "UPDATE Book SET BookQuantity = " + " '" + (int.Parse(showAvailable.Text) + 1) + "'" + "where BookId=" + int.Parse(showBookId.Text);

            using (SqlCommand cmd = new SqlCommand(sql1, con1))
            {
                //Opening the connection:
                con1.Open();

                cmd.Parameters.Add("BookId", SqlDbType.Int).Value = int.Parse(showBookId.Text);

                cmd.CommandType = CommandType.Text;
                cmd.ExecuteNonQuery();

                //Disconnect
                con1.Close();


                BookGridView.Rows.Clear();
                BookGridView.Refresh();
            }
        }
Пример #3
0
        private void RefreshList()
        {
            int startPeriod = int.TryParse(filterStartPeriod.Text, out startPeriod)
                ? startPeriod
                : int.MinValue;

            int endPeriod = int.TryParse(filterEndPeriod.Text, out endPeriod)
                ? endPeriod
                : int.MaxValue;

            string author = String.IsNullOrWhiteSpace(filterAuthor.Text) ? string.Empty : filterAuthor.Text;

            bookDataSource.DataSource = DataServiceProvider.DataService.Query <Book>(b => b.Year <= endPeriod && b.Year >= startPeriod && b.Author.Contains(author)).Cast <Book>().ToList();
            BookGridView.Refresh();
        }