Esempio n. 1
0
        public static async Task <ValueData <PostRank> > getAllRank()
        {
            Dictionary <String, String> query = new Dictionary <String, String> {
                { "key", "dirumahaja" }
            };

            HttpContent q = new FormUrlEncodedContent(query);

            HttpClient client = new HttpClient {
                BaseAddress = new Uri(baseURL)
            };

            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            using (HttpResponseMessage responseMessage = await client.PostAsync(baseURL + "getAllPost", q))
            {
                if (responseMessage.IsSuccessStatusCode)
                {
                    String data = await responseMessage.Content.ReadAsStringAsync();

                    JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();

                    ValueData <PostRank> valueData = javaScriptSerializer.Deserialize <ValueData <PostRank> >(data);

                    return(valueData);
                }
                else
                {
                    throw new Exception(responseMessage.ReasonPhrase);
                }
            }
        }
        private async Task tampilDataRank()
        {
            ValueData <PostRank> responseData = await Utility.getAllRank();

            int success = responseData.success;

            if (success == 1)
            {
                dgvPostRank.Rows.Clear();

                for (int i = 0; i < responseData.data.Count; i++)
                {
                    dgvPostRank.Rows.Add();
                    dgvPostRank.Rows[i].Cells[0].Value = responseData.data[i].id;
                    dgvPostRank.Rows[i].Cells[1].Value = responseData.data[i].username;
                    dgvPostRank.Rows[i].Cells[2].Value = responseData.data[i].content;

                    if (responseData.data[i].username.Equals(lblNPM.Text))
                    {
                        lblRank.Text = responseData.data[i].id.ToString();
                    }
                }

                dgvPostRank.SelectionMode      = DataGridViewSelectionMode.FullRowSelect;
                dgvPostRank.AllowUserToAddRows = false;
            }
            else
            {
                MessageBox.Show(responseData.message, "Information!", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }