예제 #1
0
        private void BindNew()
        {
            cNews   oNew        = new cNews();
            DataSet ds          = new DataSet();
            string  strMessage  = string.Empty;
            string  strCriteria = string.Empty;
            string  strActive   = string.Empty;

            strCriteria = strCriteria + "  And  c_active ='Y' And new_status <> 'P'  Order by d_created_date desc";
            try
            {
                if (!oNew.SP_NEW_SHOW_SEL(strCriteria, ref ds, ref strMessage))
                {
                    lblError.Text = strMessage;
                }
                else
                {
                    RpNew.DataSource = ds.Tables[0];
                    RpNew.DataBind();
                }
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message.ToString();
            }
            finally
            {
                oNew.Dispose();
                ds.Dispose();
            }
        }
예제 #2
0
        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            string      strMessage = string.Empty;
            string      strCheck   = string.Empty;
            string      strScript  = string.Empty;
            HiddenField hddnew_id  = (HiddenField)GridView1.Rows[e.RowIndex].FindControl("hddnew_id");
            cNews       oNews      = new cNews();

            try
            {
                if (!oNews.SP_NEW_DEL(hddnew_id.Value.ToString(), ref strMessage))
                {
                    lblError.Text = strMessage;
                }
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message.ToString();
            }
            finally
            {
                oNews.Dispose();
            }
            BindGridView(0);
        }
예제 #3
0
        /// <summary>
        /// Creates a cNews object. It will be saved in permanent storage only
        /// on calling Save()
        /// </summary>
        /// <returns>cNews object</returns>
        public static cNews Create()
        {
            cNews oObj = new cNews();

            SecurityCheck((int)enNews_Action.Create);

            // Create an object in memory, will be saved to storage on calling Save()
            oObj.m_bCreating = true;
            oObj.m_bInvalid  = false;
            return(oObj);
        }
예제 #4
0
        private void BindGridView(int nPageNo)
        {
            cNews   oNews       = new cNews();
            DataSet ds          = new DataSet();
            string  strMessage  = string.Empty;
            string  strCriteria = string.Empty;

            if (!txtCetreria.Equals(""))
            {
                strCriteria = strCriteria + "  And  (new_title like '%" + txtCetreria.Text.Trim() + "%') ";
            }


            try
            {
                if (!oNews.SP_NEW_SEL(strCriteria, ref ds, ref strMessage))
                {
                    lblError.Text = strMessage;
                }
                else
                {
                    try
                    {
                        GridView1.PageIndex           = nPageNo;
                        txthTotalRecord.Value         = ds.Tables[0].Rows.Count.ToString();
                        ds.Tables[0].DefaultView.Sort = ViewState["sort"] + " " + ViewState["direction"];
                        GridView1.DataSource          = ds.Tables[0];
                        GridView1.DataBind();
                    }
                    catch
                    {
                        GridView1.PageIndex           = 0;
                        txthTotalRecord.Value         = ds.Tables[0].Rows.Count.ToString();
                        ds.Tables[0].DefaultView.Sort = ViewState["sort"] + " " + ViewState["direction"];
                        GridView1.DataSource          = ds.Tables[0];
                        GridView1.DataBind();
                    }
                }
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message.ToString();
            }
            finally
            {
                oNews.Dispose();
                ds.Dispose();
                if (GridView1.Rows.Count > 0)
                {
                    GridView1.TopPagerRow.Visible = true;
                }
            }
        }
예제 #5
0
        /// <summary>
        /// Ensures that an object with the specified name exists, while creating other properties are set to their default values
        /// </summary>
        /// <param name="i_sName">Name</param>
        /// <returns>cNews object</returns>
        public static cNews CreateIfRequiredAndGet(string i_sName)
        {
            cNews oObj = cNews.Get_Name(i_sName);

            if (oObj == null)
            {
                oObj       = cNews.Create();
                oObj.sName = i_sName;
                oObj.Save();
            }
            return(oObj);
        }
예제 #6
0
        private void BindData(int nNew_id)
        {
            cNews   oNews       = new cNews();
            DataSet ds          = new DataSet();
            string  strMessage  = string.Empty;
            string  strCriteria = string.Empty;

            strCriteria = strCriteria + "  And  (new_id =" + nNew_id + ") ";
            try
            {
                if (!oNews.SP_NEW_SEL(strCriteria, ref ds, ref strMessage))
                {
                    lblError.Text = strMessage;
                }
                else
                {
                    ltlNew_title.Text = ds.Tables[0].Rows[0]["new_title"].ToString();
                    ltlNew_date.Text  = ds.Tables[0].Rows[0]["d_created_date"].ToString();
                    //N = Normal , P = Pin , Q = Quick
                    if (ds.Tables[0].Rows[0]["new_status"].ToString() == "N")
                    {
                        ltlNew_status.Text = "ข่าวทั่วไป";
                    }
                    else if (ds.Tables[0].Rows[0]["new_status"].ToString() == "Q")
                    {
                        ltlNew_status.Text      = "ข่าวด่วน";
                        ltlNew_status.ForeColor = System.Drawing.Color.Red;
                    }
                    else if (ds.Tables[0].Rows[0]["new_status"].ToString() == "P")
                    {
                        ltlNew_status.Text = "ปักหมุด";
                    }

                    ltlNew_des.Text = ds.Tables[0].Rows[0]["new_des"].ToString();
                    if (ds.Tables[0].Rows[0]["new_des"].ToString() != "")
                    {
                        lblNew_file_name.Text        = ds.Tables[0].Rows[0]["new_file_name"].ToString();
                        lblNew_file_name.NavigateUrl = "";
                    }
                    lblNew_file_name.NavigateUrl = "~/new_attach/" + ds.Tables[0].Rows[0]["new_file_name"].ToString();;
                    ltlNew_by.Text = ds.Tables[0].Rows[0]["c_created_by"].ToString();
                }
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message.ToString();
            }
            finally
            {
                oNews.Dispose();
                ds.Dispose();
            }
        }
예제 #7
0
        /// <summary>
        /// Finds and return cNews objects matching the specified criteria
        /// </summary>
        /// <param name="i_oFilter">Filter criteria (WHERE clause)</param>
        /// <returns>cNews objects</returns>
        public static List <cNews> Find(cFilter i_oFilter)
        {
            DataTable    dt = Find_DataTable(i_oFilter, null);
            List <cNews> l  = new List <cNews>();
            cNews        oObj;

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                oObj                   = new cNews();
                oObj.m_iID             = Convert.ToInt32(dt.Rows[i]["iID"]);
                oObj.m_sName           = dt.Rows[i]["sName"].ToString();
                oObj.m_dtCreatedOn     = Convert.ToDateTime(dt.Rows[i]["dtCreatedOn"]);
                oObj.m_dtLastUpdatedOn = Convert.ToDateTime(dt.Rows[i]["dtLastUpdatedOn"]);

                oObj.m_sHeadLine    = Convert.ToString(dt.Rows[i]["sHeadLine"]);
                oObj.m_sDescription = Convert.ToString(dt.Rows[i]["sDescription"]);
                oObj.m_bIsActive    = Convert.ToBoolean(dt.Rows[i]["bIsActive"]);
                oObj.m_bInvalid     = false;
                l.Add(oObj);
            }
            return(l);
        }
예제 #8
0
        private void BindGridView(int nPageNo)
        {
            cNews   oNews          = new cNews();
            DataSet ds             = new DataSet();
            string  strMessage     = string.Empty;
            string  strCriteria    = string.Empty;
            string  strNews_title  = string.Empty;
            string  strNews_status = string.Empty;
            string  strNews_type   = string.Empty;
            string  strActive      = string.Empty;
            string  strnews_year   = string.Empty;

            strNews_title  = txtNew_title.Text;
            strNews_status = cboNew_status.SelectedValue;
            strNews_type   = cboNew_type.SelectedValue;

            if (!strNews_title.Equals(""))
            {
                strCriteria = strCriteria + "  And  (new_title like '%" + strNews_title + "%') ";
            }
            if (!strNews_type.Equals(""))
            {
                strCriteria = strCriteria + "  And  (new_type like '%" + strNews_type + "%')";
            }
            if (!strNews_status.Equals(""))
            {
                strCriteria = strCriteria + "  And  (new_status = '" + strNews_status + "') ";
            }

            if (RadioActive.Checked)
            {
                strCriteria = strCriteria + "  And  (c_active ='Y') ";
            }
            else if (RadioCancel.Checked)
            {
                strCriteria = strCriteria + "  And  (c_active ='N') ";
            }

            try
            {
                if (!oNews.SP_NEW_SEL(strCriteria, ref ds, ref strMessage))
                {
                    lblError.Text = strMessage;
                }
                else
                {
                    try
                    {
                        GridView1.PageIndex           = nPageNo;
                        txthTotalRecord.Value         = ds.Tables[0].Rows.Count.ToString();
                        ds.Tables[0].DefaultView.Sort = ViewState["sort"] + " " + ViewState["direction"];
                        GridView1.DataSource          = ds.Tables[0];
                        GridView1.DataBind();
                    }
                    catch
                    {
                        GridView1.PageIndex           = 0;
                        txthTotalRecord.Value         = ds.Tables[0].Rows.Count.ToString();
                        ds.Tables[0].DefaultView.Sort = ViewState["sort"] + " " + ViewState["direction"];
                        GridView1.DataSource          = ds.Tables[0];
                        GridView1.DataBind();
                    }
                }
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message.ToString();
            }
            finally
            {
                oNews.Dispose();
                ds.Dispose();
                if (GridView1.Rows.Count > 0)
                {
                    GridView1.TopPagerRow.Visible = true;
                }
            }
        }
예제 #9
0
        private void setData()
        {
            cNews   oNews = new cNews();
            DataSet ds = new DataSet();
            string  strMessage = string.Empty, strCriteria = string.Empty;
            string  strnew_id         = string.Empty,
                    strnews_file_name = string.Empty,
                    strnews_title     = string.Empty,
                    strnews_des       = string.Empty,
                    strnews_type      = string.Empty,
                    strnews_status    = string.Empty,
                    strC_active       = string.Empty,
                    strCreatedBy      = string.Empty,
                    strUpdatedBy      = string.Empty,
                    strCreatedDate    = string.Empty,
                    strUpdatedDate    = string.Empty;

            try
            {
                strCriteria = " and new_id = " + ViewState["new_id"].ToString() + " ";
                if (!oNews.SP_NEW_SEL(strCriteria, ref ds, ref strMessage))
                {
                    lblError.Text = strMessage;
                }
                else
                {
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        #region get Data
                        strnew_id         = ds.Tables[0].Rows[0]["new_id"].ToString();
                        strnews_title     = ds.Tables[0].Rows[0]["new_title"].ToString();
                        strnews_des       = ds.Tables[0].Rows[0]["new_des"].ToString();
                        strnews_type      = ds.Tables[0].Rows[0]["new_type"].ToString();
                        strnews_status    = ds.Tables[0].Rows[0]["new_status"].ToString();
                        strnews_file_name = ds.Tables[0].Rows[0]["new_file_name"].ToString();
                        strC_active       = ds.Tables[0].Rows[0]["c_active"].ToString();
                        strCreatedBy      = ds.Tables[0].Rows[0]["c_created_by"].ToString();
                        strUpdatedBy      = ds.Tables[0].Rows[0]["c_updated_by"].ToString();
                        strCreatedDate    = ds.Tables[0].Rows[0]["d_created_date"].ToString();
                        strUpdatedDate    = ds.Tables[0].Rows[0]["d_updated_date"].ToString();
                        #endregion

                        #region set Control
                        ViewState["new_id"]         = strnew_id;
                        txtnew_title.Text           = strnews_title;
                        txtnew_des.Text             = strnews_title;
                        cboNew_type.SelectedValue   = strnews_type;
                        cboNew_status.SelectedValue = strnews_status;
                        txtnews_file_name.Text      = strnews_file_name;

                        if (strC_active.Equals("Y"))
                        {
                            chkStatus.Checked = true;
                        }
                        else
                        {
                            chkStatus.Checked = false;
                        }
                        #endregion
                    }
                }
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message.ToString();
            }
        }
예제 #10
0
        private bool saveData()
        {
            bool   blnResult          = false;
            bool   blnDup             = false;
            string strMessage         = string.Empty;
            string strActive          = string.Empty,
                   strCreatedBy       = string.Empty,
                   strUpdatedBy       = string.Empty;
            string  strScript         = string.Empty;
            string  strnews_id        = "0";
            string  strnews_file_name = string.Empty;
            cNews   oNews             = new cNews();
            DataSet ds = new DataSet();

            try
            {
                #region set Data
                if (txtnews_file_name.Text.Length > 0)
                {
                    strnews_file_name = txtnews_file_name.Text;
                }

                if (chkStatus.Checked == true)
                {
                    strActive = "Y";
                }
                else
                {
                    strActive = "N";
                }
                strCreatedBy = Session["username"].ToString();
                strUpdatedBy = Session["username"].ToString();
                #endregion
                if (ViewState["mode"].ToString().ToLower().Equals("edit"))
                {
                    #region edit
                    if (!blnDup)
                    {
                        if (oNews.SP_NEW_UPD(ViewState["new_id"].ToString(), txtnew_title.Text, txtnew_des.Text, cboNew_type.SelectedValue, cboNew_status.SelectedValue, strnews_file_name, "", strActive, strUpdatedBy, ref strMessage))
                        {
                            blnResult = true;
                        }
                        else
                        {
                            lblError.Text = strMessage.ToString();
                        }
                    }
                    else
                    {
                        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "frMainPage", strScript, true);
                    }
                    #endregion
                }
                else
                {
                    #region insert
                    if (!blnDup)
                    {
                        if (oNews.SP_NEW_INS(txtnew_title.Text, txtnew_des.Text, cboNew_type.SelectedValue, cboNew_status.SelectedValue, strnews_file_name, "", strActive, strCreatedBy, ref strMessage))
                        {
                            string strGetcode = " and new_title = '" + txtnew_title.Text + "' ";
                            if (!oNews.SP_NEW_SEL(strGetcode, ref ds, ref strMessage))
                            {
                                lblError.Text = strMessage;
                            }
                            if (ds.Tables[0].Rows.Count > 0)
                            {
                                strnews_id = ds.Tables[0].Rows[0]["new_id"].ToString();
                            }
                            ViewState["news_id"] = strnews_id;
                            blnResult            = true;
                        }
                        else
                        {
                            lblError.Text = strMessage.ToString();
                        }
                    }
                    else
                    {
                        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "frMainPage", strScript, true);
                    }
                    #endregion
                }
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message.ToString();
            }
            finally
            {
                oNews.Dispose();
            }
            return(blnResult);
        }
예제 #11
0
using System;
예제 #12
0
        private void button1_Click(object sender, EventArgs e)
        {
            progressBar1.Value = 0;
            List <cNews> news;

            news = new List <cNews>();
            foreach (var elem in ChDriver.FindElements(By.ClassName("wall_post_cont")))
            {
                cNews toBeAddedObject        = new cNews();
                List <IWebElement> postTexts = FindIWIWebElementByClassName(elem, "wall_post_text");
                List <IWebElement> imagLinks = FindIWIWebElementByClassName(elem, "page_post_sized_thumbs");

                toBeAddedObject.Id = elem.GetAttribute("id");

                if (postTexts.Any())
                {
                    toBeAddedObject.Text = postTexts[0].Text;

                    //foreach (IWebElement link in postTexts[0].FindElements(By.TagName("a")))
                    //{
                    //    if (string.IsNullOrEmpty(link.GetAttribute("href")))
                    //        continue;
                    //    toBeAddedObject.link.Add(link.GetAttribute("href"));//linq
                    //}
                    toBeAddedObject.Link.AddRange((from link in postTexts[0].FindElements(By.TagName("a"))
                                                   where !string.IsNullOrEmpty(link.GetAttribute("href"))
                                                   select link.GetAttribute("href")));
                }

                if (imagLinks.Any())
                {
                    foreach (IWebElement iml in imagLinks[0].FindElements(By.TagName("a")))
                    {
                        string temp = iml.GetCssValue("background-image");
                        if (!string.IsNullOrEmpty(temp) && temp.Length > 7)
                        {
                            temp = temp.Substring(5);
                            temp = temp.Remove(temp.Length - 2);
                            toBeAddedObject.ImageLink.Add(temp);
                        }
                    }
                }
                if (toBeAddedObject.ImageLink.Any() || toBeAddedObject.Link.Any() || !string.IsNullOrEmpty(toBeAddedObject.Text))
                {
                    news.Add(toBeAddedObject);
                }
            }
            progressBar1.Value = 5;

            // bool[] fileIsBusy = new bool[3] { false, false, false };
            string[] fileName = new string[3] {
                "JStext.txt", "JSlink.txt", "JSimageLink.txt"
            };
            for (int i = 0; i < 3; i++)
            {
                if (FileOperation.IsOpen(fileName[i]))
                {
                    FileOperation.DeleteLockMarker(fileName[i]);
                }
            }


            // writeToJson(fileName[0], 1, news, ref fileIsBusy[0]);
            FileOperation[] fileOperations = new FileOperation[3] {
                new FileOperation(fileName[0]),
                new FileOperation(fileName[1]),
                new FileOperation(fileName[2]),
            };


            Task[] tasks = new Task[4]
            {
                new Task(() => WriteToJson(fileName[0], 1, news, ref fileOperations[0])),
                new Task(() => WriteToJson(fileName[1], 2, news, ref fileOperations[1])),
                new Task(() => WriteToJson(fileName[2], 3, news, ref fileOperations[2])),
                new Task(() => ReadFromJson(fileName, ref fileOperations)),
            };

            //Task.Factory.StartNew(() => writeToJson("JStext.txt", 1, news,));
            //Task.Factory.StartNew(() => writeToJson("JSlink.txt", 2, news,));
            //Task.Factory.StartNew(() => writeToJson("JSimageLink.txt", 3, news,));

            for (int i = 0; i < 4; i++)
            {
                tasks[i].Start();
            }
            progressBar1.Value += 5;
        }