SHARE
TWEET

Untitled

a guest Nov 29th, 2014 262 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. private void Dashboard_Load(object sender, EventArgs e)
  3.         {
  4.  
  5.             urlH = new UrlHelper();
  6.                        
  7.            
  8.             checkExisting_data();
  9.             addComboList();
  10.            
  11.            
  12.  
  13.         }
  14.  
  15.        
  16.         void checkExisting_data()
  17.         {
  18.             var result = urlH.getDataFromUrl("http://localhost/samplesites/index.php", "task=get_hours");
  19.             MessageBox.Show(result.ToString());
  20.             var obj = JsonModel.DeserializeJSon<List>(result);
  21.             int i = 1;
  22.             foreach (Person p in obj){
  23.                 //Console.WriteLine("Forename: {0} - Surname: {1}", p.t_start, p.t_end);
  24.                 this.dataGridView1.Rows.Add(i++, p.project_name, p.t_start, p.t_end);
  25.             }
  26.            
  27.  
  28.  
  29.         }
  30.  
  31.  
  32.  
  33. void addComboList()
  34.         {
  35.             var result2 = urlH.getDataFromUrl("http://localhost/samplesites/index.php", "task=get_projects");
  36.             MessageBox.Show(result2.ToString()+"result2");
  37.             var proj = JsonModel.DeserializeJSon<List>(result2);
  38.             foreach (DataProjects pr in proj){
  39.                 this.comboBox1.Items.Add(new ComboItem(Convert.ToInt32(pr.proj_id), pr.project_name));
  40.             }
  41.             //comboBox1.Items.Add(new ComboItem(1, "one"));
  42.             //comboBox1.Items.Add(new ComboItem(5, "Five"));
  43.             comboBox1.SelectedIndexChanged += comboBox1_SelectedIndexChanged;
  44.            
  45.         }
  46.  
  47.        
  48.  
  49.  
  50. //UrlHelper Class
  51.  
  52. using System;
  53. using System.Collections.Generic;
  54. using System.IO;
  55. using System.Linq;
  56. using System.Net;
  57. using System.Text;
  58. using System.Threading.Tasks;
  59.  
  60. namespace TimeTracker
  61. {
  62.     public class UrlHelper
  63.     {
  64.         public string getDataFromUrl(string url, string dataPost){
  65.             //
  66.             var httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
  67.             //httpWebRequest.ContentType = "text/json";
  68.  
  69.             httpWebRequest.Method = "POST";
  70.             httpWebRequest.ContentType = "application/x-www-form-urlencoded";
  71.             string postData = dataPost;
  72.             byte[] byteArray = Encoding.UTF8.GetBytes(postData);
  73.             httpWebRequest.ContentLength = byteArray.Length;
  74.             Stream dataStreamRequest = httpWebRequest.GetRequestStream();
  75.             dataStreamRequest.Write(byteArray, 0, byteArray.Length);
  76.             dataStreamRequest.Close();
  77.            
  78.  
  79.  
  80.             var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
  81.             Stream dataStreamResponse = httpResponse.GetResponseStream();
  82.             StreamReader reader = new StreamReader(dataStreamResponse);
  83.             var result = reader.ReadToEnd();
  84.          
  85.             reader.Close();
  86.             dataStreamResponse.Close();
  87.             httpResponse.Close();
  88.  
  89.             return result;
  90.         }
  91.  
  92.     }
  93. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top