Exemplo n.º 1
0
        void GetTickets()
        {
            soldTickets.Clear();

            Vasarlas vasarlas = new Vasarlas();

            vasarlas.want    = "vasarlasok";
            vasarlas.request = QueryList.query;

            string cmd            = "data=" + JsonConvert.SerializeObject(vasarlas);
            var    httpWebRequest = (HttpWebRequest)WebRequest.Create("http://localhost/rftapi/api/api.php");

            httpWebRequest.ContentType = "application/x-www-form-urlencoded";
            httpWebRequest.Method      = "POST";

            using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
            {
                streamWriter.Write(cmd);
                streamWriter.Flush();
                streamWriter.Close();
            }

            var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();

            string[] responses;
            string   result;

            using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
            {
                result    = streamReader.ReadToEnd();
                responses = result.Split('{');
            }

            string[] success = responses[1].Split(',');
            if (success[1] == "\"successful\":\"true\"")
            {
                for (int i = 2; i < responses.Length; i++)
                {
                    responses[i] = responses[i].Replace("\"", String.Empty);
                    responses[i] = responses[i].Replace(":", ",");

                    string[] singleEntry = responses[i].Split(',');

                    Vasarlas newVasarlas = new Vasarlas();
                    newVasarlas.id     = int.Parse(singleEntry[1]);
                    newVasarlas.filmid = int.Parse(singleEntry[3]);
                    newVasarlas.vevoid = int.Parse(singleEntry[5]);
                    string dateTimeTemp = singleEntry[7] + ":" + singleEntry[8] + ":" + singleEntry[9];
                    dateTimeTemp = dateTimeTemp.Replace("}", "");
                    dateTimeTemp = dateTimeTemp.Replace("]", "");
                    newVasarlas.vasarlasIdeje = Convert.ToDateTime(dateTimeTemp);

                    soldTickets.Add(newVasarlas);
                }
                UpdateTicketsDataGrid();
            }
        }
Exemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            int  db;
            bool result = int.TryParse(tb_Darab.Text, out db);

            if (result)
            {
                Vasarlas vasarlas = new Vasarlas();
                vasarlas.want    = "buying";
                vasarlas.request = QueryList.insert;

                vasarlas.vevoid = 1;
                vasarlas.filmid = int.Parse(tb_EloadasId.Text);

                string cmd = "data=" + JsonConvert.SerializeObject(vasarlas);



                string[] responses;
                string   responseFromApi = "";
                for (int i = 0; i < db; i++)
                {
                    var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://localhost/rftapi/api/api.php");
                    httpWebRequest.ContentType = "application/x-www-form-urlencoded";
                    httpWebRequest.Method      = "POST";
                    using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
                    {
                        streamWriter.Write(cmd);
                        streamWriter.Flush();
                        streamWriter.Close();
                    }

                    var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();

                    using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                    {
                        responseFromApi = streamReader.ReadToEnd();
                    }
                }
                responses = responseFromApi.Split('{');
                string[] success = responses[1].Split(',');
                if (success[1] == "\"successful\":\"true\"}")
                {
                    MessageBox.Show("Jegy(ek) eladva!");
                }
                else
                {
                    MessageBox.Show(responseFromApi);
                }
            }
            else
            {
                MessageBox.Show("A hosszhoz számot kell írni!");
            }
        }