示例#1
0
        ///////////////////////////////////////////////////////////////////////////////////////////

        private async void btnUploadCard_ClickAsync(object sender, EventArgs e)
        {
            string[] lines = File.ReadAllLines(@"D:\SGCP1.csv");

            for (int i = 0; i < lines.Length; i++)
            {
                string[] splitted   = lines[i].Split(',');
                string   cardNumber = splitted[1];
                string   cardID     = splitted[2];
                string   status     = splitted[3];

                ParkingCard card = new ParkingCard(cardID, cardNumber, status);


                FormUrlEncodedContent content = new FormUrlEncodedContent(card.ToDictionary());
                HttpClient            client  = new HttpClient();
                var result = await client.PostAsync(Program.host + "api/parkingCard/add", content);

                var responseString = await result.Content.ReadAsStringAsync();

                LoginHistory response = JsonConvert.DeserializeObject <LoginHistory>(responseString);

                if (response.Error != null && response.Error != "")
                {
                    PrintError(response.Error + ": " + cardNumber);
                    return;
                }
                else if (response.Success != null && response.Success != "")
                {
                    PrintSuccess(response.Success + ": " + cardNumber);
                }
            }
        }
示例#2
0
        ///////////////////////////////////////////////////////////////////////////////////////////

        public async void SetTextAsync(string cardID)
        {
            lblMessage.Text = "";
            if (!Program.validToken)
            {
                MessageBox.Show("Chưa đăng nhập");
                return;
            }
            cardID = cardID.ToLower();
            var c = m_lstCards.FirstOrDefault(cc => cc.CardID == cardID);

            string      cardNumber = Interaction.InputBox("Nhập số in trên thẻ", "Nhập số thẻ");
            ParkingCard card       = new ParkingCard(cardID, cardNumber);



            FormUrlEncodedContent content = new FormUrlEncodedContent(card.ToDictionary());

            HttpClient client = new HttpClient();
            var        result = await client.PostAsync(Program.host + "api/parkingCard/add", content);

            var responseString = await result.Content.ReadAsStringAsync();

            LoginHistory response = JsonConvert.DeserializeObject <LoginHistory>(responseString);

            if (response.Error != null && response.Error != "")
            {
                PrintError(response.Error + ": " + cardNumber);
                return;
            }
            else if (response.Success != null && response.Success != "")
            {
                PrintSuccess(response.Success + ": " + cardNumber);
            }


            if (c == null)
            {
                if (m_lstCards.Count == 0)
                {
                    m_lstCards.Add(new DataCards()
                    {
                        CardID      = cardID,
                        CardNumber  = cardNumber,
                        CratedDate  = DateTime.Now,
                        VehicleType = ""
                    });
                }
                else
                {
                    m_lstCards.Insert(0, new DataCards()
                    {
                        CardID      = cardID,
                        CardNumber  = cardNumber,
                        CratedDate  = DateTime.Now,
                        VehicleType = ""
                    });
                }

                grdData.DataSource = null;
                grdData.DataSource = m_lstCards;
            }
            else
            {
                grdData.DataSource = null;
                grdData.DataSource = m_lstCards;
            }
        }