Exemplo n.º 1
0
        public static DataTable InsertANews(News newId)
        {
            SqlCommand sqlCmd;
            var sqlAdapter = new SqlDataAdapter();
            SqlConnection sqlConnect = Blog.Common.SqlProvider.SelectGetConnection();
            DataTable dt = new DataTable { Locale = CultureInfo.CurrentCulture };
            try
            {
                sqlConnect.Open();
                sqlCmd = new SqlCommand("sp_InsertANews", sqlConnect);
                sqlCmd.Parameters.Add("Title", SqlDbType.NVarChar).Value = newId.Title;
                sqlCmd.Parameters.Add("CategoryID", SqlDbType.Int).Value = newId.CategoryId;
                sqlCmd.Parameters.Add("Author", SqlDbType.VarChar).Value = newId.Author;
                sqlCmd.Parameters.Add("Content", SqlDbType.NVarChar).Value = newId.Content;

                sqlCmd.CommandType = CommandType.StoredProcedure;

                sqlAdapter.SelectCommand = sqlCmd;
                sqlAdapter.Fill(dt);
                return dt;
            }
            catch (SqlException)
            {
                sqlConnect.Close();
                return null;
            }
            finally
            {
                sqlConnect.Close();
            }
        }
Exemplo n.º 2
0
        public static bool DeleteNews(News news)
        {
            SqlCommand sqlcmd;
            SqlConnection sqlconnecnt = Common.SqlProvider.SelectGetConnection();

            try
            {
                sqlconnecnt.Open();
                sqlcmd = new SqlCommand("sp_DeleteANews", sqlconnecnt);
                sqlcmd.Parameters.Add("id", SqlDbType.Int).Value = news.NewsId;
                sqlcmd.CommandType = CommandType.StoredProcedure;
                sqlcmd.ExecuteNonQuery();

                return true;
            }
            catch (SqlException)
            {
                sqlconnecnt.Close();
                return false;
            }
            finally
            {
                sqlconnecnt.Close();
            }
        }
        public void SelectNewsById(News newId)
        {
            DataTable dt;
            dt = NewsBU.SelectNewDetailById((newId));
            NewId = newId.NewsId;

            labelTitle.Text = dt.Rows[0]["Title"].ToString();
            labelAuthors.Text = dt.Rows[0]["author"].ToString();
            labelContentNew.Text = dt.Rows[0]["contentnew"].ToString();
            labelCreateTime.Text = dt.Rows[0]["createtime"].ToString();
            labelViewNumber.Text = dt.Rows[0]["numberviews"].ToString();

            DataTable objdt;

            objdt = NewsBU.SelectCommentById((newId));
            LvViewComments.DataSource = objdt;
            LvViewComments.DataBind();
        }
Exemplo n.º 4
0
        public static News FillDataById(int newId)
        {
            SqlCommand sqlcmd;
            SqlConnection sqlconnecnt = Common.SqlProvider.SelectGetConnection();

            News news = new News();
            try
            {
                sqlconnecnt.Open();
                sqlcmd = new SqlCommand("sp_GetNewsByID", sqlconnecnt);
                sqlcmd.Parameters.Add("id", SqlDbType.Int).Value = newId;

                sqlcmd.CommandType = CommandType.StoredProcedure;
                sqlcmd.ExecuteNonQuery();

                SqlDataReader dr = sqlcmd.ExecuteReader();
                if (dr != null)
                    if (dr.Read())
                    {

                        news.Title = (string)dr["Title"];
                        news.Author = (string)dr["Author"];
                        news.Content = (string)dr["Contentnew"];
                        news.Views = (int)dr["numberviews"];
                        news.Comments = (int)dr["numbercomment"];

                    }

                return news;
            }
            catch (SqlException)
            {
                sqlconnecnt.Close();
                return news;
            }
            finally
            {
                sqlconnecnt.Close();
            }
        }
        protected void DeleteCommand1(object sender, CommandEventArgs e)
        {
            News news = new News();

            string id = e.CommandArgument.ToString();
            news.NewsId = (Convert.ToInt32(id, CultureInfo.CurrentCulture));
            NewsBU.DeleteNews(news);
            panelInsertNews.Visible = false;
            panelUpdateNew.Visible = false;
            panelShowAllData.Visible = true;
        }
        protected void ButtonUpdateSummitClick(object sender, EventArgs e)
        {
            if (CheckInputUpdateNews())
            {

                News news = new News();
                news.NewsId = Int32.Parse(txtUpdateNewsId.Text, CultureInfo.CurrentCulture);
                news.Title = txtUpdateTitle.Text;
                news.CategoryId = Int32.Parse(dropUpdateCategoryName.SelectedValue,CultureInfo.CurrentCulture);
                news.Author = txtUpdateAuthor.Text;
                news.Content = txtUpdateContent.Text;
                news.Views = Convert.ToInt32(txtUpdateViews.Text,CultureInfo.CurrentCulture);
                news.Comments = Convert.ToInt32(txtUpdateComment.Text, CultureInfo.CurrentCulture);

                NewsBU.UpdateNews(news);

                panelInsertNews.Visible = false;
                panelUpdateNew.Visible = false;
                panelShowAllData.Visible = true;
                Display();
            }
        }
        protected void ButtonInsertSummitClick(object sender, EventArgs e)
        {
            if (CheckInputInsert())
            {

                var news = new News();

                news.Author = txtInsertAuthor.Text;
                news.Content = txtInsertContent.Text;
                news.Title = txtInsertTitle.Text;
                news.CategoryId = Convert.ToInt32(dropInsertCategory.SelectedValue, CultureInfo.CurrentCulture);
                NewsBU.InsertANews(news);

                panelInsertNews.Visible = false;
                panelUpdateNew.Visible = false;
                panelShowAllData.Visible = true;
                Display();
            }
        }
Exemplo n.º 8
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if ( Session["Username"] == "")
            {

                ControlLogOn controlLogOn = (ControlLogOn)Page.LoadControl("~/UserControls/ControlLogOn.ascx");

                placeLogOn.Controls.Add(controlLogOn);

            }
            else
            {
                placeLogOn.Controls.Clear();
                ControlLogOnUser controlLogOnUser = (ControlLogOnUser)Page.LoadControl("~/UserControls/ControlLogOnUser.ascx");
                placeLogOn.Controls.Add(controlLogOnUser);

            }

            if (Request.QueryString["wuc"] != null)
            {
                switch (Request.QueryString["wuc"])
                {
                    case "pd":
                        if (Request.QueryString["chitiet"] != null)
                        {
                            News ns = new News();
                            ns.NewsId = Convert.ToInt32(Request.QueryString["chitiet"], CultureInfo.CurrentCulture);

                            ControlDetailNews controlDetailNews = (ControlDetailNews)Page.LoadControl("~/UserControls/ControlDetailNews.ascx");
                            controlDetailNews.SelectNewsById(ns);
                            placeCenter.Controls.Add(controlDetailNews);
                            Session["URLReferrer"] = Request.Url;
                        }
                        break;

                    case "menu":
                        if (Request.QueryString["item"] != null)
                        {
                            ControlNews controlNews = (ControlNews)Page.LoadControl("~/UserControls/ControlNews.ascx");
                            placeCenter.Controls.Add(controlNews);
                            Session["URLReferrer"] = Request.Url;
                        }
                        break;

                    case "mn":
                        if (Request.QueryString["link"] == "MNews")
                        {

                            if ( Session["Username"] == "")
                            {

                            }
                            else
                            {
                                ControlManagementNews controlManagementNews = (ControlManagementNews)Page.LoadControl("~/UserControls/ControlManagementNews.ascx");
                                placeCenter.Controls.Add(controlManagementNews);
                                Session["URLReferrer"] = Request.Url;
                            }

                        }

                        if (Request.QueryString["link"] == "MCategory")
                        {

                            if (Session["Username"] == "")
                            {

                            }
                            else
                            {

                                ControlManagementCategories controlManagementCategories = (ControlManagementCategories)Page.LoadControl("~/UserControls/ControlManagementCategories.ascx");
                                placeCenter.Controls.Add(controlManagementCategories);
                                Session["URLReferrer"] = Request.Url;
                            }

                        }
                        if (Request.QueryString["link"] == "MUsers")
                        {

                            if (Session["Username"] == "")
                            {

                            }
                            else
                            {

                                ControlManagementUser controlManagementUser = (ControlManagementUser)Page.LoadControl("~/UserControls/ControlManagementUser.ascx");
                                placeCenter.Controls.Add(controlManagementUser);
                                Session["URLReferrer"] = Request.Url;
                            }

                        }

                        break;

                }
            }
            else
            {
                ControlNews controlNews = (ControlNews)Page.LoadControl("~/UserControls/ControlNews.ascx");
                placeCenter.Controls.Add(controlNews);
                Session["URLReferrer"] = Request.Url;
            }
        }
Exemplo n.º 9
0
 public static bool UpdateNews(News news)
 {
     return NewsDao.UpdateNews(news);
 }
Exemplo n.º 10
0
 public static DataTable SelectNewDetailById(News newId)
 {
     return NewsDao.SelectDetailNewById((newId));
 }
Exemplo n.º 11
0
 public static DataTable SelectCommentById(News newId)
 {
     return NewsDao.SelectCommentById((newId));
 }
Exemplo n.º 12
0
 public static DataTable InsertANews(News newId)
 {
     return NewsDao.InsertANews(newId);
 }
Exemplo n.º 13
0
 public static bool DeleteNews(News news)
 {
     return NewsDao.DeleteNews(news);
 }
Exemplo n.º 14
0
        public static bool UpdateNews(News news)
        {
            SqlCommand sqlcmd;
            SqlConnection sqlconnecnt = Common.SqlProvider.SelectGetConnection();

            try
            {
                sqlconnecnt.Open();
                sqlcmd = new SqlCommand("sp_updateANews", sqlconnecnt);
                sqlcmd.Parameters.Add("ID", SqlDbType.Int).Value = news.NewsId;
                sqlcmd.Parameters.Add("Title", SqlDbType.NVarChar).Value = news.Title;
                sqlcmd.Parameters.Add("CategoryID", SqlDbType.Int).Value = news.CategoryId;
                sqlcmd.Parameters.Add("Author", SqlDbType.NVarChar).Value = news.Author;
                sqlcmd.Parameters.Add("Content", SqlDbType.NVarChar).Value = news.Content;
                sqlcmd.Parameters.Add("views", SqlDbType.Int).Value = news.Views;
                sqlcmd.Parameters.Add("comment", SqlDbType.Int).Value = news.Comments;
                sqlcmd.CommandType = CommandType.StoredProcedure;
                sqlcmd.ExecuteNonQuery();

                return true;
            }
            catch (SqlException)
            {
                sqlconnecnt.Close();
                return false;
            }
            finally
            {
                sqlconnecnt.Close();
            }
        }
Exemplo n.º 15
0
        // ve nha lam tiep pham bu cho news
        public static DataTable SelectDetailNewById(News newId)
        {
            SqlCommand sqlCmd;
            var sqlAdapter = new SqlDataAdapter();
            SqlConnection sqlConnect = Blog.Common.SqlProvider.SelectGetConnection();
            DataTable dt = new DataTable { Locale = CultureInfo.CurrentCulture };
            try
            {
                sqlConnect.Open();
                sqlCmd = new SqlCommand("sp_getDetailNew", sqlConnect);
                sqlCmd.Parameters.Add("newid", SqlDbType.Int).Value = newId.NewsId;

                sqlCmd.CommandType = CommandType.StoredProcedure;

                sqlAdapter.SelectCommand = sqlCmd;
                sqlAdapter.Fill(dt);
                return dt;
            }
            catch (SqlException)
            {
                sqlConnect.Close();
                return null;
            }
            finally
            {
                sqlConnect.Close();
            }
        }