Пример #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            int      bookId = Convert.ToInt32(Request["bookId"]);
            BooksBll BBll   = new BooksBll();

            model = BBll.GetModel(bookId);
            CategoriesBll CBll = new CategoriesBll();

            list   = CBll.GetModelList("");
            listPB = PBll.GetModelList("");
        }
        public bool Insert(CategoriesBll c)
        {
            //Creating A Boolean VAriable and set its default value to false
            bool isSucces = false;

            //Connecting to Database


            try
            {
                //Writing Query to Add New Category
                string sql = "INSERT INTO tbl_categories (title, description, added_date, added_by) VALUES (@title, @description, @added_date, @added_by)";

                //Creating SQL Command to pass values in our query
                SqlCommand cmd = new SqlCommand(sql, conn);
                //Passing Values through parameter
                cmd.Parameters.AddWithValue("@title", c.Title);
                cmd.Parameters.AddWithValue("@description", c.Description);
                cmd.Parameters.AddWithValue("@added_date", c.AddedDate);
                cmd.Parameters.AddWithValue("@added_by", c.AddedBy);

                //Open Database Connection
                conn.Open();

                //Creating the int variable to execute query
                int rows = cmd.ExecuteNonQuery();

                //If the query is executed successfully then its value will be greater than 0 else it will be less than 0

                if (rows > 0)
                {
                    //Query Executed Succesfully
                    isSucces = true;
                }
                else
                {
                    //Failed to Execute Query
                    isSucces = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                //Closing Database Connection
                conn.Close();
            }

            return(isSucces);
        }
        public bool Update(CategoriesBll c)
        {
            //Creating Boolean variable and set its default value to false
            bool isSuccess = false;

            //Creating SQL Connection


            try
            {
                //Query to Update Category
                string sql = "UPDATE tbl_categories SET title=@title, description=@description, added_date=@added_date, added_by=@added_by WHERE id=@id";

                //SQl Command to Pass the Value on Sql Query
                SqlCommand cmd = new SqlCommand(sql, conn);

                //Passing Value using cmd
                cmd.Parameters.AddWithValue("@title", c.Title);
                cmd.Parameters.AddWithValue("@description", c.Description);
                cmd.Parameters.AddWithValue("@added_date", c.AddedDate);
                cmd.Parameters.AddWithValue("@added_by", c.AddedBy);
                cmd.Parameters.AddWithValue("@id", c.Id);

                //Open DAtabase Connection
                conn.Open();

                //Create Int Variable to execute query
                int rows = cmd.ExecuteNonQuery();

                //if the query is successfully executed then the value will be grater than zero
                if (rows > 0)
                {
                    //Query Executed Successfully
                    isSuccess = true;
                }
                else
                {
                    //Failed to Execute Query
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                conn.Close();
            }

            return(isSuccess);
        }
Пример #4
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string        typeName = context.Request["typeName"];
            CategoriesBll Bll      = new CategoriesBll();
            Categories    ca       = new Categories();

            ca.Name = typeName;
            int caa = Bll.Add(ca);

            if (caa > 0)
            {
                context.Response.Write("ok");
            }
        }
Пример #5
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string        typeName = context.Request["typeName"];
            int           typeid   = Convert.ToInt32(context.Request["typeid"]);
            CategoriesBll Bll      = new CategoriesBll();
            Categories    ca       = new Categories();

            ca.Id   = typeid;
            ca.Name = typeName;
            bool falg = Bll.Update(typeName, typeid);

            if (falg)
            {
                context.Response.Write("ok");
            }
        }
        public bool Delete(CategoriesBll c)
        {
            //Create a Boolean variable and set its value to false
            bool isSuccess = false;



            try
            {
                //SQL Query to Delete from Database
                string sql = "DELETE FROM tbl_categories WHERE id=@id";

                SqlCommand cmd = new SqlCommand(sql, conn);
                //Passing the value using cmd
                cmd.Parameters.AddWithValue("@id", c.Id);

                //Open SqlConnection
                conn.Open();

                int rows = cmd.ExecuteNonQuery();

                //If the query is executd successfully then the value of rows will be greater than zero else it will be less than 0
                if (rows > 0)
                {
                    //Query Executed Successfully
                    isSuccess = true;
                }
                else
                {
                    //Faied to Execute Query
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                conn.Close();
            }

            return(isSuccess);
        }
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            //获取用户要删除的BookID
            int          typeid = Convert.ToInt32(context.Request["typeid"]);
            BooksBll     Bll    = new BooksBll();
            List <Books> books  = Bll.GetModelList("CategoryId=" + typeid);

            if (books.Count > 0)
            {
                context.Response.Write("no");
            }
            else
            {
                CategoriesBll cBll = new CategoriesBll();
                bool          falg = cBll.Delete(typeid);
                if (falg)
                {
                    context.Response.Write("ok");
                }
            }
        }
Пример #8
0
        protected void Page_Load(object sender, EventArgs e)
        {
            CategoriesBll cb = new CategoriesBll();

            string index = Request["index"];

            if (string.IsNullOrEmpty(index))
            {
                pageIndex = 1;
            }
            else
            {
                pageIndex = Convert.ToInt32(index);
            }
            //总页数
            int total = cb.GetRecordCount("");

            pageCount = Convert.ToInt32(Math.Ceiling((double)total / pageSize));
            //集合
            DataSet ds = cb.GetListByPage("", "", (pageIndex - 1) * pageSize + 1, pageIndex * pageSize);

            typeList = cb.DataTableToList(ds.Tables[0]);
        }
 public string EditCategory(string newCategoryName, int id)
 {
     return(CategoriesBll.Update(newCategoryName, id));
 }
 public ActionResult DeleteCategory(int id)
 {
     CategoriesBll.Delete(CategoriesBll.GetCategoryWithId(id));
     return(RedirectToAction("Categories"));
 }
        public string AddNewCategory(string catName)
        {
            var id = CategoriesBll.Add(catName);

            return(id);
        }
 // GET: Admin/Shop
 public ActionResult Categories()
 {
     return(View(CategoriesBll.Get()));
 }