コード例 #1
0
ファイル: BooksDetails_DAL.cs プロジェクト: Rigo85/prueba2
        public Int32 UpdateBookRecord(BooksDetails_BEL objBEL)
        {
            int result = 0;

            using (TransactionScope scope = new TransactionScope())
            {
                using (SqlConnection conn = new SqlConnection(conStr))
                {
                    try
                    {
                        conn.Open();
                        using (SqlCommand cmd = new SqlCommand("UpdateBookRecord_SP", conn))
                        {
                            cmd.CommandType = CommandType.StoredProcedure;
                            cmd.Parameters.AddWithValue("BookId", objBEL.BookId);
                            cmd.Parameters.AddWithValue("BookName", objBEL.BookName);
                            cmd.Parameters.AddWithValue("Author", objBEL.Author);
                            cmd.Parameters.AddWithValue("Price", objBEL.Price);

                            result = cmd.ExecuteNonQuery();
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                }

                scope.Complete();
            }

            return(result > 0 ? result : 0);
        }
コード例 #2
0
 protected void btnSubmit_Click(object sender, EventArgs e)
 {
     objBookDetailsBEL.BookName  = txtBookName.Text.Trim();
     objBookDetailsBEL.Author    = txtAuthor.Text.Trim();
     objBookDetailsBEL.Publisher = txtPublisher.Text.Trim();
     objBookDetailsBEL.Price     = Convert.ToDecimal(txtPrice.Text);
     try
     {
         int retVal = objBookDetailsBLL.SaveBookDetails(objBookDetailsBEL);
         if (retVal > 0)
         {
             lblStatus.Text      = "Book detail saved successfully";
             lblStatus.ForeColor = System.Drawing.Color.Green;
             ClearControls();
             BindBookRecordsGridView();
         }
         else
         {
             lblStatus.Text      = "Book details couldn't be saved";
             lblStatus.ForeColor = System.Drawing.Color.Red;
         }
     }
     catch (Exception ex)
     {
         Response.Write("Oops! error occured:" + ex.Message.ToString());
     }
     finally
     {
         objBookDetailsBEL = null;
         objBookDetailsBLL = null;
     }
 }
コード例 #3
0
ファイル: BooksDetails_DAL.cs プロジェクト: Rigo85/prueba2
        public Int32 SaveBookDetails(BooksDetails_BEL objBEL)
        {
            int BookDetailsID = 0;

            using (TransactionScope scope = new TransactionScope())
            {
                using (SqlConnection conn = new SqlConnection(conStr))
                {
                    try
                    {
                        conn.Open();

                        using (SqlCommand cmd = new SqlCommand("InsertBookDetails_SP", conn))
                        {
                            cmd.CommandType = CommandType.StoredProcedure;
                            cmd.Parameters.AddWithValue("BookName", objBEL.BookName);
                            cmd.Parameters.AddWithValue("Author", objBEL.Author);
                            cmd.Parameters.AddWithValue("Price", objBEL.Price);

                            BookDetailsID = Convert.ToInt32(cmd.ExecuteScalar());
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                }

                scope.Complete();
            }

            return(BookDetailsID);
        }
コード例 #4
0
        private void BindBookRecordsGridView()
        {
            DataSet ds = new DataSet();

            try
            {
                ds = objBookDetailsBLL.GetBookRecords();
                if (ds.Tables[0].Rows.Count > 0)
                {
                    grdBookDetails.DataSource = ds;
                    grdBookDetails.DataBind();
                }
                else
                {
                    grdBookDetails.DataSource = null;
                    grdBookDetails.DataBind();
                }
            }
            catch (Exception ex)
            {
                Response.Write("Oops! error occured:" + ex.Message.ToString());
            }
            finally
            {
                objBookDetailsBEL = null;
                objBookDetailsBLL = null;
            }
        }
コード例 #5
0
 protected void grdBookDetails_RowUpdating(object sender, GridViewUpdateEventArgs e)
 {
     objBookDetailsBEL.BookId    = Convert.ToInt32(grdBookDetails.DataKeys[e.RowIndex].Value);
     objBookDetailsBEL.BookName  = ((TextBox)(grdBookDetails.Rows[e.RowIndex].FindControl("txtBookNameEdit"))).Text.Trim();
     objBookDetailsBEL.Author    = ((TextBox)(grdBookDetails.Rows[e.RowIndex].FindControl("txtAuthorEdit"))).Text.Trim();
     objBookDetailsBEL.Publisher = ((TextBox)(grdBookDetails.Rows[e.RowIndex].FindControl("txtPublisherEdit"))).Text.Trim();
     objBookDetailsBEL.Price     = Convert.ToDecimal(((TextBox)(grdBookDetails.Rows[e.RowIndex].FindControl("txtPriceEdit"))).Text.Trim());
     try
     {
         int retVal = objBookDetailsBLL.UpdateBookRecord(objBookDetailsBEL);
         if (retVal > 0)
         {
             lblStatus.Text      = "Book detail updated successfully";
             lblStatus.ForeColor = System.Drawing.Color.Green;
             ClearControls();
             grdBookDetails.EditIndex = -1;
             BindBookRecordsGridView();
         }
         else
         {
             lblStatus.Text      = "Book details couldn't be updated";
             lblStatus.ForeColor = System.Drawing.Color.Red;
         }
     }
     catch (Exception ex)
     {
         Response.Write("Oops! error occured:" + ex.Message.ToString());
     }
     finally
     {
         objBookDetailsBEL = null;
         objBookDetailsBLL = null;
     }
 }
コード例 #6
0
        protected void grdBookDetails_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            int Book_Id = Convert.ToInt32(grdBookDetails.DataKeys[e.RowIndex].Value);

            objBookDetailsBEL.BookId = Book_Id;
            try
            {
                int retVal = objBookDetailsBLL.DeleteBookRecord(objBookDetailsBEL);

                if (retVal > 0)
                {
                    lblStatus.Text      = "Book detail deleted successfully";
                    lblStatus.ForeColor = System.Drawing.Color.Green;
                    ClearControls();
                    BindBookRecordsGridView();
                }
                else
                {
                    lblStatus.Text      = "Book details couldn't be deleted";
                    lblStatus.ForeColor = System.Drawing.Color.Red;
                }
            }
            catch (Exception ex)
            {
                Response.Write("Oops! error occured:" + ex.Message.ToString());
            }
            finally
            {
                objBookDetailsBEL = null;
                objBookDetailsBLL = null;
            }
        }
コード例 #7
0
        public Int32 UpdateBookRecord(BooksDetails_BEL objBel)
        {
            BooksDetails_DAL1 objDal = new BooksDetails_DAL1();

            try
            {
                return(objDal.UpdateBookRecord(objBel));
            }
            catch (Exception ex)
            {
                throw new ArgumentException(ex.Message);
            }
            finally
            {
                objDal = null;
            }
        }
コード例 #8
0
        public Int32 UpdateBookRecord(BooksDetails_BEL objBel)
        {
            BooksDetails_DAL objDal = new BooksDetails_DAL();

            try
            {
                return(objDal.UpdateBookRecord(objBel));
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                objDal = null;
            }
        }
コード例 #9
0
        public Int32 SaveBookDetails(BooksDetails_BEL objBel)
        {
            BooksDetails_DAL objDal = new BooksDetails_DAL();

            try
            {
                return(objDal.SaveBookDetails(objBel));
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                objDal = null;
            }
        }
コード例 #10
0
        public ActionResult Save(BooksDetails_BEL Book)
        {
            if (ModelState.IsValid)
            {
                if (Book.BookId > 0)
                {
                    BookDetails_BLL.UpdateBookRecord(Book);
                }
                else
                {
                    BookDetails_BLL.SaveBookDetails(Book);
                }

                return(RedirectToAction("Index"));
            }
            else
            {
                return(View(Book));
            }
        }
コード例 #11
0
ファイル: BooksDetails_DAL.cs プロジェクト: Rigo85/prueba2
        public IEnumerable <BooksDetails_BEL> GetBookRecords()
        {
            List <BooksDetails_BEL> books = new List <BooksDetails_BEL>();

            using (TransactionScope scope = new TransactionScope())
            {
                using (SqlConnection conn = new SqlConnection(conStr))
                {
                    try
                    {
                        conn.Open();
                        using (SqlCommand cmd = new SqlCommand("FetchBookRecords_Sp", conn))
                        {
                            cmd.CommandType = CommandType.StoredProcedure;
                            using (SqlDataReader reader = cmd.ExecuteReader())
                            {
                                //todo probar linq
                                while (reader.Read())
                                {
                                    BooksDetails_BEL book = new BooksDetails_BEL(
                                        reader["BookName"].ToString(),
                                        reader["Author"].ToString(),
                                        decimal.Parse(reader["Price"].ToString()));
                                    book.BookId = Convert.ToInt32(reader["BookId"]);
                                    book.Active = Convert.ToBoolean(reader["Active"]);

                                    books.Add(book);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                }

                scope.Complete();
            }

            return(books);
        }
コード例 #12
0
        public Int32 UpdateBookRecord(BooksDetails_BEL objBEL)
        {
            int result;

            try
            {
                SqlCommand cmd = new SqlCommand("UpdateBookRecord_SP", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@BookId", objBEL.BookId);
                cmd.Parameters.AddWithValue("@BookName", objBEL.BookName);
                cmd.Parameters.AddWithValue("@Author", objBEL.Author);
                cmd.Parameters.AddWithValue("@Publisher", objBEL.Publisher);
                cmd.Parameters.AddWithValue("@Price", objBEL.Price);
                if (con.State == ConnectionState.Closed)
                {
                    con.Open();
                }
                result = cmd.ExecuteNonQuery();
                cmd.Dispose();
                if (result > 0)
                {
                    return(result);
                }
                else
                {
                    return(0);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (con.State != ConnectionState.Closed)
                {
                    con.Close();
                }
            }
        }
コード例 #13
0
        public Int32 DeleteBookRecord(BooksDetails_BEL objBEL)
        {
            int result;

            try
            {
                SqlCommand cmd = new SqlCommand("DeleteBookRecords_Sp", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@BookId", objBEL.BookId);
                if (con.State == ConnectionState.Closed)
                {
                    con.Open();
                }
                result = cmd.ExecuteNonQuery();
                cmd.Dispose();
                if (result > 0)
                {
                    return(result);
                }
                else
                {
                    return(0);
                }
            }
            catch (Exception ex)
            {
                throw new ArgumentException(ex.Message);
            }
            finally
            {
                if (con.State != ConnectionState.Closed)
                {
                    con.Close();
                }
            }
        }
コード例 #14
0
        public ActionResult Remove(BooksDetails_BEL Book)
        {
            int result = BookDetails_BLL.DeleteBookRecord(Book.BookId);

            return(View("Index", BookDetails_BLL.GetBookRecords()));
        }
コード例 #15
0
 public ActionResult Create(BooksDetails_BEL Book)
 {
     return(View(Book));
 }