Beispiel #1
0
        private void BackButton_Click(object sender, EventArgs e)
        {
            string  searchAll     = textBox1.Text;
            string  searchAny     = textBox2.Text;
            string  searchExclude = textBox3.Text;
            string  start         = dateTimePicker1.Value.ToString("yyyy-MM-dd");
            string  end           = dateTimePicker2.Value.ToString("yyyy-MM-dd");
            string  lang          = comboBox1.Text;
            decimal maxResult     = numericUpDown1.Value;
            long    maxid         = -1;
            long    minid         = -1;

            if (re != null && re.Results != null && re.Results.Count > 0)
            {
                maxid = re.Results.Max(x => x.NewsId);
                re    = ResultViewMethods.Post(searchAll, searchAny, searchExclude, start, end, maxResult, minid, maxid, lang);

                if (re.Results.Count == 1)
                {
                    MessageBox.Show("there isn't new news");
                }
                else
                {
                    dataGridView1.DataSource = re.Results;
                }
            }
        }
Beispiel #2
0
        private void SearchButton_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrWhiteSpace(textBox1.Text))
            {
                MessageBox.Show(this, "Enter topic please.");
                return;
            }
            else if (numericUpDown1.Value == 0)
            {
                MessageBox.Show(this, "Enter MaxResult please.");
                return;
            }
            else if (dateTimePicker1.Value.Date == dateTimePicker2.Value.Date)
            {
                MessageBox.Show(this, "Change start time or end time, please.");
                return;
            }
            string  searchAll     = textBox1.Text;
            string  searchAny     = textBox2.Text;
            string  searchExclude = textBox3.Text;
            string  start         = dateTimePicker1.Value.ToString("yyyy-MM-dd");
            string  end           = dateTimePicker2.Value.ToString("yyyy-MM-dd");
            string  lang          = comboBox1.Text;
            decimal maxResult     = numericUpDown1.Value;
            long    maxid         = -1;
            long    minid         = -1;

            re = ResultViewMethods.Post(searchAll, searchAny, searchExclude, start, end, maxResult, maxid, minid, lang);
            dataGridView1.DataSource = re.Results;
        }
Beispiel #3
0
        public Form1()
        {
            re = new ResultView();


            InitializeComponent();
        }
Beispiel #4
0
 public void insertByEfx(ResultView resultView)
 {
     using (var db = new NewsEntities4())
     {
         foreach (var item in resultView.Results)
         {
             db.News.Add(item);
         }
         db.SaveChanges();
     }
 }
Beispiel #5
0
        public bool InsertNews(ResultView resultView)
        {
            try
            {
                using (SqlConnection con = Connection._Connection)
                {
                    con.Open();

                    foreach (var item in resultView.Results)
                    {
                        string saveResult = @"INSERT into News(Country,DomainName,GroupId,ImageUrl,IsPopularWebsite,Lang,NewsId,OnHomePage,PublishDate,RetweetCount,Spot,Title,Topics,Url)
                         VALUES (@Country,@DomainName,@GroupId,@ImageUrl,@IsPopularWebsite,@Lang,@NewsId,@OnHomePage,@PublishDate,@RetweetCount,@Spot,@Title,@Topics,@Url)";


                        SqlCommand cmd = new SqlCommand();
                        cmd.Connection = con;

                        cmd.Parameters.Add("@Country", SqlDbType.NVarChar).Value     = item.Country;
                        cmd.Parameters.Add("@DomainName", SqlDbType.NVarChar).Value  = item.DomainName;
                        cmd.Parameters.Add("@GroupId", SqlDbType.NVarChar).Value     = item.GroupId;
                        cmd.Parameters.Add("@ImageUrl", SqlDbType.NVarChar).Value    = item.ImageUrl;
                        cmd.Parameters.Add("@IsPopularWebsite", SqlDbType.Bit).Value = item.IsPopularWebsite;
                        cmd.Parameters.Add("@Lang", SqlDbType.NVarChar).Value        = item.Lang;
                        cmd.Parameters.Add("@NewsId", SqlDbType.NVarChar).Value      = item.NewsId;
                        cmd.Parameters.Add("@OnHomePage", SqlDbType.Bit).Value       = item.OnHomePage;
                        cmd.Parameters.Add("@PublishDate", SqlDbType.VarChar).Value  = item.PublishDate;
                        cmd.Parameters.Add("@RetweetCount", SqlDbType.Int).Value     = item.RetweetCount;
                        cmd.Parameters.Add("@Spot", SqlDbType.NVarChar).Value        = item.Spot;
                        cmd.Parameters.Add("@Title", SqlDbType.NVarChar).Value       = item.Title;
                        cmd.Parameters.Add("@Topics", SqlDbType.NVarChar).Value      = item.Topics;
                        cmd.Parameters.Add("@Url", SqlDbType.NVarChar).Value         = item.Url;
                        cmd.CommandText = saveResult;

                        int rowCount = cmd.ExecuteNonQuery();
                    }

                    con.Close();
                }
            }
            catch (SqlException ex)
            {
                throw ex;
            }

            return(false);
        }
Beispiel #6
0
        public static ResultView Post(string searchAll, string searchAny, string searchExclude, string start, string end, decimal maxResult, long MaxId, long MinId, string lang)
        {
            try
            {
                String url = String.Format("https://api.newsmeter.com/api/news?searchAll={0}&searchAny={1}%&searchExclude={2}%&startDate={3}&endDate={4}&maxResult={5}&maxNewsId={6}&minNewsId={7}&lang={8}", searchAll, searchAny, searchExclude, start, end, maxResult, MaxId, MinId, lang);

                //string url = "https://api.newsmeter.com/api/news?1=1";

                //StringBuilder sb = new StringBuilder(url);
                //if (!String.IsNullOrWhiteSpace(searchAll))
                //{
                //    sb.Append("&searchAll=" + searchAll);
                //}

                //if (MaxId > 0)
                //{
                //    sb.Append("&maxNewsId=" + MaxId);
                //}
                //url = sb.ToString();

                ResultView res = new ResultView();
                WebRequest req = WebRequest.Create(url);
                req.Method = "GET";
                req.Headers.Add("token", "445271f4-b117-4e2a-a3a3-7effdd2c475e");
                req.ContentType = "application/json; charset=utf-8";
                WebResponse  resp   = req.GetResponse();
                Stream       stream = resp.GetResponseStream();
                StreamReader re     = new StreamReader(stream);
                string       json   = re.ReadToEnd();
                res = Newtonsoft.Json.JsonConvert.DeserializeObject <ResultView>(json);
                //var dd= Newtonsoft.Json.JsonConvert.SerializeObject(list);//yukardaki işlemin tam tersi
                return(res);
            }
            catch (WebException e)
            {
                throw e;
            }
        }