protected void uiButtonCancel_Click(object sender, EventArgs e)
 {
     uiPanelEdit.Visible = false;
     uiPanelViewNews.Visible = true;
     Clearfields();
     CurrentArNews = null;
 }
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         Master.PageTitle = "الأخبار";
         if (Request.QueryString["NID"] != null && !string.IsNullOrEmpty(Request.QueryString["NID"]))
         {
             uiPanelAllNews.Visible = false;
             uiPanelViewNews.Visible = true;
             int id = Convert.ToInt32(Request.QueryString["NID"].ToString());
             News currentnews = new News();
             currentnews.LoadByPrimaryKey(id);
             uiLabelDate.Text = string.Format("{0:yyyy-MMM-dd}", currentnews.PostedDate);
             uiLabelDate.Text += " " + string.Format("{0:hh:mm}", currentnews.PostedDate);
             uiLabelTitle.Text = currentnews.ArTitle;
             if (!string.IsNullOrEmpty(currentnews.MainImagePath))
                 uiImageNews.ImageUrl = "images.aspx?Inner=news&Image="+currentnews.MainImagePath;
             else
                 uiImageNews.ImageUrl = "images.aspx?Inner=news&Image=" + "arabic/images/logo_Big_watermark.jpg";
             uiLiteralContent.Text = Server.HtmlDecode(currentnews.ArContent);
         }
         else
         {
             uiPanelAllNews.Visible = true;
             uiPanelViewNews.Visible = false;
             BindData();
         }
     }
 }
        private void BindData()
        {
            PagedDataSource dt = new PagedDataSource();
            News currentnews = new News();
            currentnews.LoadAll();
            currentnews.DefaultView.Sort = "PostedDate desc";
            dt.DataSource = currentnews.DefaultView;
            dt.AllowPaging = true;
            dt.PageSize = 10;
            dt.CurrentPageIndex = PageIndex;
            uiRepeaterCurrentNews.DataSource = dt;
            uiRepeaterCurrentNews.DataBind();

            uiLinkButtonPrev.Enabled = !dt.IsFirstPage;
            uiLinkButtonNext.Enabled = !dt.IsLastPage;
            uiLabelPages.Text = "صفحة " + (PageIndex + 1).ToString() + " من " + dt.PageCount.ToString() + " صفحات";
        }
        protected void uiGridViewNews_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "EditNews")
            {
                News objData = new News();
                objData.LoadByPrimaryKey(Convert.ToInt32(e.CommandArgument.ToString()));
                CurrentArNews = objData;
                uiTextBoxArTitle.Text = objData.ArTitle;
                uiTextBoxBrief.Text = objData.Description;
                uiTextBoxDate.Text = objData.PostedDate.ToString("dd/MM/yyyy");
                uiDropDownListHours.SelectedValue = objData.PostedDate.Hour.ToString("00");
                uiDropDownListMins.SelectedValue = objData.PostedDate.Minute.ToString("00");
                uiRadEditorPageContent.Content = Server.HtmlDecode(objData.ArContent);
                uiPanelViewNews.Visible = false;
                uiPanelEdit.Visible = true;

            }
            else if (e.CommandName == "DeleteNews")
            {
                News objData = new News();
                objData.LoadByPrimaryKey(Convert.ToInt32(e.CommandArgument.ToString()));
                objData.MarkAsDeleted();
                objData.Save();
                CurrentArNews = null;
                BindData();

            }
        }
        protected void uiButtonUpdate_Click(object sender, EventArgs e)
        {
            if (CurrentArNews != null)
            {
                UpdateRecord();
            }
            else
            {
                AddNewRecord();
            }

            uiPanelEdit.Visible = false;
            uiPanelViewNews.Visible = true;
            Clearfields();
            BindData();
            CurrentArNews = null;
        }
 private void UpdateRecord()
 {
     News objData = new News();
     objData = CurrentArNews;
     objData.ArTitle = uiTextBoxArTitle.Text;
     objData.ArContent = Server.HtmlEncode(uiRadEditorPageContent.Content);
     objData.Description = uiTextBoxBrief.Text;
     if (uiFileUploadMainPicturePath.HasFile)
     {
         uiFileUploadMainPicturePath.SaveAs(Server.MapPath("~/UploadedFiles/News/" + uiFileUploadMainPicturePath.FileName));
         objData.MainImagePath = "/UploadedFiles/News/" + uiFileUploadMainPicturePath.FileName;
     }
     objData.PostedDate = DateTime.ParseExact(uiTextBoxDate.Text, "dd/MM/yyyy", null);
     objData.PostedDate = objData.PostedDate.AddHours(double.Parse(uiDropDownListHours.SelectedValue));
     objData.PostedDate = objData.PostedDate.AddMinutes(double.Parse(uiDropDownListMins.SelectedValue));
     objData.Save();
 }
        private void BindData()
        {
            News objData = new News();

            objData.LoadAll();
            objData.DefaultView.Sort = "PostedDate Desc";
            uiGridViewNews.DataSource = objData.DefaultView;
            uiGridViewNews.DataBind();
        }