Пример #1
0
        private async void btnLogin_Click(object sender, EventArgs e)
        {
            if (!ValidateFormControls.CheckTextboxes(groupBox1, errorProvider1))
            {
                return;
            }

            Cursor = Cursors.WaitCursor;

            using (var HC = new HttpClient())
            {
                var response = await HC.GetAsync(Constants.baseUrl + $"Staff/{txtStaffId.Text}/{txtPassword.Text}");

                if (response.IsSuccessStatusCode)
                {
                    var rtn = JsonConvert.DeserializeObject <ApiReturnObject <Useracct> >(await response.Content.ReadAsStringAsync());

                    MessageBox.Show(rtn.Message);

                    if (rtn.Status)
                    {
                        LoggedInUser = rtn.Object;
                        groupBox1.Hide();
                        groupBox2.Show();
                    }
                }
                else
                {
                    MessageBox.Show("An error occured while connecting to API.");
                }
            }


            Cursor = Cursors.Default;
        }
Пример #2
0
        private async void btnSearch_Click(object sender, EventArgs e)
        {
            if (!ValidateFormControls.CheckTextboxes(this, errorProvider1))
            {
                return;
            }

            Cursor = Cursors.WaitCursor;

            using (var HC = new HttpClient())
            {
                var response = await HC.GetAsync(Constants.baseUrl + $"Staff/{txtStaffId.Text}");

                if (response.IsSuccessStatusCode)
                {
                    var rtn = JsonConvert.DeserializeObject <ApiReturnObject <List <Stafftab> > >(await response.Content.ReadAsStringAsync());

                    Staffs = rtn.Object;

                    dgridUsers.DataSource = Staffs;
                    dgridUsers.Refresh();

                    if (!rtn.Status)
                    {
                        MessageBox.Show(rtn.Message);
                    }
                }
            }


            Cursor = Cursors.Default;
        }