protected void uiButtonSearch_Click(object sender, EventArgs e)
 {
     ArNews objData = new ArNews();
     objData.SearchArNews(uiTextBoxSearch.Text, !string.IsNullOrEmpty(uiTextBoxFromDate.Text) ? DateTime.Parse(uiTextBoxFromDate.Text) : DateTime.ParseExact("01/01/1900", "dd/MM/yyyy", null)
                                              , !string.IsNullOrEmpty(uiTextBoxToDate.Text) ? DateTime.Parse(uiTextBoxToDate.Text) : DateTime.MaxValue);
     uiGridViewNews.DataSource = objData.DefaultView;
     uiGridViewNews.DataBind();
 }
 private void UpdateRecord()
 {
     ArNews objData = new ArNews();
     objData = CurrentArNews;
     objData.EnTitle = uiTextBoxEnTitle.Text;
     objData.ArTitle = uiTextBoxArTitle.Text;
     objData.EnBody = Server.HtmlEncode(uiFCKeditorEnBody.Value);
     objData.ArBody = Server.HtmlEncode(uiFCKeditorArBody.Value);
     //objData.CategoryID = Convert.ToInt32(uiDropDownListCategory.SelectedValue);
     objData.EnBrief = uiTextBoxEnBreif.Text;
     objData.ArBrief = uiTextBoxArBrief.Text;
     if (uiFileUploadMainPicturePath.HasFile)
     {
         uiFileUploadMainPicturePath.SaveAs(Server.MapPath("~/FileUploads/News/" + uiFileUploadMainPicturePath.FileName));
         objData.MainPicturePath = "/FileUploads/News/" + uiFileUploadMainPicturePath.FileName;
     }
     objData.CreatedDate = DateTime.Now.AddHours(6);
     objData.Save();
 }
        protected void uiLinkButtonExport_Click(object sender, EventArgs e)
        {
            string filter = "";
            //DataTable dt = new DataTable ();
            ArNews news = new ArNews();
            foreach (GridViewRow row in uiGridViewExport.Rows)
            {

                System.Web.UI.WebControls.CheckBox cb = (System.Web.UI.WebControls.CheckBox)row.FindControl("uiCheckBoxExport");
                if (cb.Checked)
                {
                    if(!string.IsNullOrEmpty(filter))
                        filter += ",";
                    HiddenField hf = (HiddenField)row.FindControl("uiHiddenFieldID");
                    filter += hf.Value;
                }
            }
            news.LoadAll();
            news.Filter = "NewsID in (" + filter + ")";

            if (news.RowCount > 0)
            {
                StringBuilder sbDocBody = new StringBuilder();

                /*object oMissing = System.Reflection.Missing.Value;

                Application oWordApp = new Application();
                Document document = oWordApp.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);
                document.Activate();*/

                int i = 0;
                sbDocBody.Append("<html><body>");
                foreach (DataRowView item in news.DefaultView)
                {

                   /* oWordApp.Selection.TypeText(item["ArTitle"].ToString());
                    oWordApp.Selection.TypeParagraph();
                    oWordApp.Selection.TypeParagraph();

                    oWordApp.Selection.InlineShapes.AddPicture("http://www.globallogistics.mtg-eg.com/" + item["MainPicturePath"].ToString());
                    oWordApp.Selection.TypeParagraph();

                    oWordApp.Selection.TypeText(StripTagsCharArray(Server.HtmlDecode(item["ArBody"].ToString())));
                    oWordApp.Selection.InsertNewPage();*/
                    sbDocBody.Append(item["ArTitle"].ToString());
                    sbDocBody.Append("<br />");
                    sbDocBody.Append("<img src=\'http://www.globallogistics.mtg-eg.com/" + item["MainPicturePath"].ToString() + "\'");
                    sbDocBody.Append("<br />");
                    sbDocBody.Append(Server.HtmlDecode(item["ArBody"].ToString()));
                    sbDocBody.Append("<br />");
                    sbDocBody.Append("<br />");
                    sbDocBody.Append("<hr />");
                    i++;

                }
                sbDocBody.Append("</body></html>");
                /*document.SaveAs(Server.MapPath("~/fileuploads/News.docx"), oMissing, oMissing, oMissing, oMissing, oMissing, oMissing,
                        oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing);
                document.Close();*/
                HttpContext.Current.Response.Clear();
                HttpContext.Current.Response.Buffer = true;
                HttpContext.Current.Response.Charset = "utf-8";

                HttpContext.Current.Response.ContentType = "application/msword";
                HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=\"news.doc\"");
                /*HttpContext.Current.Response.TransmitFile("/fileuploads/News.docx");

                HttpContext.Current.Response.Flush();*/
                HttpContext.Current.Response.Write(sbDocBody.ToString());
                HttpContext.Current.Response.End();
               // oWordApp.Application.Quit(ref oMissing, ref oMissing, ref oMissing);
            }
            else
            {

            }
        }
 private void BindExportData()
 {
     ArNews objData = new ArNews();
     objData.LoadAll();
     uiGridViewExport.DataSource = objData.DefaultView;
     uiGridViewExport.DataBind();
 }
        protected void uiGridViewNews_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "EditNews")
            {
                ArNews objData = new ArNews();
                objData.LoadByPrimaryKey(Convert.ToInt32(e.CommandArgument.ToString()));
                CurrentArNews = objData;
                uiTextBoxArTitle.Text = objData.ArTitle;
                uiTextBoxEnTitle.Text = objData.EnTitle;
                uiFCKeditorArBody.Value = Server.HtmlDecode(objData.ArBody);
                uiFCKeditorEnBody.Value = Server.HtmlDecode(objData.EnBody);
                //uiDropDownListCategory.SelectedValue = objData.CategoryID.ToString();
                uiTextBoxEnBreif.Text = objData.EnBrief;
                uiTextBoxArBrief.Text = objData.ArBrief;
                //uiTextBoxDate.Text = ds.Tables[0].Rows[0]["CreatedDate"].ToString();
                uiPanelViewNews.Visible = false;
                uiPanelEdit.Visible = true;

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

            }
        }