Пример #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                tbBookNum.Enabled = false;
                tbCopyNum.Enabled = false;
                tbSequence.Enabled = false;

                tbCopyNum.Text = (CopyBL.GetCopyNumberMax() + 1).ToString();

                string s = (string)Session["bookNumber"];
                Book b = new Book();
                b = BookBL.SelectByID(s);
                tbBookNum.Text = b.BookNumber.ToString();

                int Seq;
                try
                {
                    Seq = CopyBL.getSequenceMax(tbBookNum.Text) + 1;
                }
                catch (Exception)
                {
                    Seq = 1;
                }
                tbSequence.Text = Seq.ToString();
            }
        }
Пример #2
0
 protected void btSave_Click(object sender, EventArgs e)
 {
     if (tbTitle.Text != "")
     {
         Book b = new Book(int.Parse(tbBookNum.Text), tbTitle.Text, tbAuthor.Text, tbPulisher.Text);
         BookBL.Insert(b);
         Response.Redirect("~/GUI/BookUI.aspx");
     }
     else
     {
         lbTitle.Visible = true;
     }
 }
Пример #3
0
        //public static void DeleteAllCopy(Book b) {
        //    try {
        //        SqlConnection cn = new SqlConnection("Data Source=TRUNGND\\SQL;Initial Catalog=Library;Integrated Security=True");
        //        SqlCommand cmd=new SqlCommand("Delete Copy where bookNumber = @bookNumber",cn);
        //        cmd.Parameters.AddWithValue("@bookNumber",b.BookNumber);
        //        cn.Open();
        //        cmd.ExecuteNonQuery();
        //        cn.Close();
        //    } catch(Exception ex) {
        //        MessageBox.Show(ex.Message);
        //    }
        //}
        public static bool DeleteAllCopy(Book b)
        {
            try
            {
                string conn = ConfigurationManager.ConnectionStrings["LibraryConnectionString"].ConnectionString;
                SqlConnection cn = new SqlConnection(conn);
                SqlCommand cmd = new SqlCommand("Delete Copy where bookNumber = @bookNumber", cn);
                cmd.Parameters.AddWithValue("@bookNumber", b.BookNumber);

                cn.Open();
                cmd.ExecuteNonQuery();
                cn.Close();

                return true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return false;
            }
        }
Пример #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack && Session["bookNumber"] != null)
            {
                tbBookNum.Enabled = false;

                string s = (string)Session["bookNumber"];
                Book b = new Book();
                b = BookBL.SelectByID(s);
                tbBookNum.Text = b.BookNumber.ToString();

                tbAuthor.Text = b.Authors;
                tbPulisher.Text = b.Publisher;
                tbTitle.Text = b.Title;

                //GridViewRow row = (GridViewRow)Session["book"];
                //tbBookNum.Text = row.Cells[1].Text;
                //tbTitle.Text = row.Cells[2].Text;
                //tbAuthor.Text = row.Cells[3].Text;
                //tbPulisher.Text = row.Cells[4].Text;
            }
        }
Пример #5
0
        private void FillCopyBook()
        {
            if (Session["bookNumber"] != null)
            {
                tbBookNum.Enabled = false;
                tbTittle.Enabled = false;

                string s = (string)Session["bookNumber"];
                Book b = new Book();
                b = BookBL.SelectByID(s);
                tbBookNum.Text = b.BookNumber.ToString();
                tbTittle.Text = b.Title;

                string filter = "bookNumber =" + s;
                DataSet ds = new DataSet();
                ds = CopyBL.SelectDS();
                DataView dv = new DataView(ds.Tables[0]);
                dv.RowFilter = filter;
                string sortDirection = "", sortExpression = "";
                if (ViewState["SortDirection"] != null)
                    sortDirection = ViewState["SortDirection"].ToString();
                if (ViewState["SortExpression"] != null)
                {
                    sortExpression = ViewState["SortExpression"].ToString();
                    dv.Sort = sortExpression + " " + sortDirection;
                }
                gvCopyBook.DataSource = dv;
                gvCopyBook.DataBind();
                lbNum.Text = gvCopyBook.Rows.Count.ToString();
            }
        }
Пример #6
0
 protected void gvBook_RowDeleting(object sender, GridViewDeleteEventArgs e)
 {
     GridViewRow row = gvBook.SelectedRow;
     if (row != null)
     {
         {
             string s = gvBook.Rows[e.RowIndex].Cells[1].Text;
             Book b = new Book();
             b.BookNumber = int.Parse(s);
             BookBL.DeleteAllCopy(b);
             BookBL.Delete(b);
             FillBook();
         }
     }
     else
     {
         ClientScript.RegisterClientScriptBlock(this.GetType(), "wtf", "alert('Please select a book!');", true);
     }
 }
Пример #7
0
 public static bool Update(Book b)
 {
     return BookDA.Update(b);
 }
Пример #8
0
 public static bool Insert(Book b)
 {
     return BookDA.Insert(b);
 }
Пример #9
0
 public static bool DeleteAllCopy(Book b)
 {
     return BookDA.DeleteAllCopy(b);
 }
Пример #10
0
 public static bool Delete(Book b)
 {
     return BookDA.Delete(b);
 }
Пример #11
0
        public static bool Update(Book b)
        {
            try
            {
                string conn = ConfigurationManager.ConnectionStrings["LibraryConnectionString"].ConnectionString;
                SqlConnection cn = new SqlConnection(conn);
                SqlCommand cmd = new SqlCommand("Update Book set title = @title, "
                + "authors = @authors, publisher = @publisher where bookNumber = @bookNumber", cn);
                cmd.Parameters.AddWithValue("@bookNumber", b.BookNumber);
                cmd.Parameters.AddWithValue("@title", b.Title);
                cmd.Parameters.AddWithValue("@authors", b.Authors);
                cmd.Parameters.AddWithValue("@publisher", b.Publisher);

                cn.Open();
                cmd.ExecuteNonQuery();
                cn.Close();

                return true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return false;
            }
        }
Пример #12
0
 public static Book SelectByID(string s)
 {
     try
     {
         string conn = ConfigurationManager.ConnectionStrings["LibraryConnectionString"].ConnectionString;
         string sql = "SELECT * FROM Book where bookNumber = " + s;
         SqlDataAdapter da = new SqlDataAdapter(sql, conn);
         DataSet ds = new DataSet();
         da.Fill(ds);
         Book b = new Book();
         b.BookNumber = int.Parse(ds.Tables[0].Rows[0][0].ToString());
         b.Title = ds.Tables[0].Rows[0][1].ToString();
         b.Authors = ds.Tables[0].Rows[0][2].ToString();
         b.Publisher = ds.Tables[0].Rows[0][3].ToString();
         return b;
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
         return new Book();
     }
 }
Пример #13
0
        public static bool Insert(Book b)
        {
            try
            {
                string conn = ConfigurationManager.ConnectionStrings["LibraryConnectionString"].ConnectionString;
                SqlConnection cn = new SqlConnection(conn);
                SqlCommand cmd = new SqlCommand("Insert into Book(bookNumber, title, authors, publisher) " +
                "values(@bookNumber, @title, @authors, @publisher)", cn);
                cmd.Parameters.AddWithValue("@bookNumber", b.BookNumber);
                cmd.Parameters.AddWithValue("@title", b.Title);
                cmd.Parameters.AddWithValue("@authors", b.Authors);
                cmd.Parameters.AddWithValue("@publisher", b.Publisher);

                cn.Open();
                cmd.ExecuteNonQuery();
                cn.Close();

                return true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return false;
            }
        }