Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void Dashboard_Load(object sender, EventArgs e)
- {
- urlH = new UrlHelper();
- checkExisting_data();
- addComboList();
- }
- void checkExisting_data()
- {
- var result = urlH.getDataFromUrl("http://localhost/samplesites/index.php", "task=get_hours");
- MessageBox.Show(result.ToString());
- var obj = JsonModel.DeserializeJSon<List>(result);
- int i = 1;
- foreach (Person p in obj){
- //Console.WriteLine("Forename: {0} - Surname: {1}", p.t_start, p.t_end);
- this.dataGridView1.Rows.Add(i++, p.project_name, p.t_start, p.t_end);
- }
- }
- void addComboList()
- {
- var result2 = urlH.getDataFromUrl("http://localhost/samplesites/index.php", "task=get_projects");
- MessageBox.Show(result2.ToString()+"result2");
- var proj = JsonModel.DeserializeJSon<List>(result2);
- foreach (DataProjects pr in proj){
- this.comboBox1.Items.Add(new ComboItem(Convert.ToInt32(pr.proj_id), pr.project_name));
- }
- //comboBox1.Items.Add(new ComboItem(1, "one"));
- //comboBox1.Items.Add(new ComboItem(5, "Five"));
- comboBox1.SelectedIndexChanged += comboBox1_SelectedIndexChanged;
- }
- //UrlHelper Class
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Net;
- using System.Text;
- using System.Threading.Tasks;
- namespace TimeTracker
- {
- public class UrlHelper
- {
- public string getDataFromUrl(string url, string dataPost){
- //
- var httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
- //httpWebRequest.ContentType = "text/json";
- httpWebRequest.Method = "POST";
- httpWebRequest.ContentType = "application/x-www-form-urlencoded";
- string postData = dataPost;
- byte[] byteArray = Encoding.UTF8.GetBytes(postData);
- httpWebRequest.ContentLength = byteArray.Length;
- Stream dataStreamRequest = httpWebRequest.GetRequestStream();
- dataStreamRequest.Write(byteArray, 0, byteArray.Length);
- dataStreamRequest.Close();
- var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
- Stream dataStreamResponse = httpResponse.GetResponseStream();
- StreamReader reader = new StreamReader(dataStreamResponse);
- var result = reader.ReadToEnd();
- reader.Close();
- dataStreamResponse.Close();
- httpResponse.Close();
- return result;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement