예제 #1
0
 public CAUHOI(CAUHOI CH)
 {
     this.IDCH    = CH.IDCH;
     this.NoiDung = CH.NoiDung;
     this.CauA    = CH.CauA;
     this.CauB    = CH.CauB;
     this.CauC    = CH.CauC;
     this.CauD    = CH.CauD;
     this.IDLoai  = CH.IDLoai;
 }
예제 #2
0
        private void GetCauHoi()
        {
            if (dem == 10)
            {
                timer1.Stop();
                progressBar1.Value = 0;
                MessageBox.Show("Wow You are win!");
                return;
            }
            string         url            = Program.url + "cauhoi/ran";
            HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);

            httpWebRequest.ContentType = "application/json; charset=utf-8";
            httpWebRequest.Method      = "POST";

            StreamWriter streamWriter = new StreamWriter(httpWebRequest.GetRequestStream());


            string json = "{ \"IDUser\": \""; //IDUser để biết rằng chính user đó yêu cầu lấy câu hỏi mới

            json += Program.IDUser;
            json += "\",\"IDLoai\": \"";
            json += Program.IDLoaiCH;
            json += "\"  }";


            streamWriter.Write(json);
            streamWriter.Flush();
            streamWriter.Close();


            HttpWebResponse response = (HttpWebResponse)httpWebRequest.GetResponse();

            if (response.StatusCode == HttpStatusCode.OK)
            {
                StreamReader reader = new StreamReader(response.GetResponseStream());
                string       result = reader.ReadToEnd();

                CAUHOI cauhoi = JsonConvert.DeserializeObject <CAUHOI>(result); // Chuyển json về dạng CauHoi

                arrayId[dem] = cauhoi.getIDCH();                                //add id câu hỏi vào mảng

                lblCauHoi.Text = "Question " + ++dem + ": " + cauhoi.getNoiDung(); dem--;
                btnCauA.Text   = "A. " + cauhoi.getCauA();
                btnCauB.Text   = "B. " + cauhoi.getCauB();
                btnCauC.Text   = "C. " + cauhoi.getCauC();
                btnCauD.Text   = "D. " + cauhoi.getCauD();
            }
        }