コード例 #1
0
        private async void btnLogin_Click(object sender, EventArgs e)
        {
            if (txtUsername.Text == "" || txtPassword.Text == "")
            {
                MessageBox.Show("Username and password must not be null", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (lstAdminAccount == null)
            {
                AdminAccountWrapper adminAccountWrapper = new AdminAccountWrapper();
                lstAdminAccount = await adminAccountWrapper.List();
            }

            string username = txtUsername.Text;
            string password = ARSUtilities.Md5Hash(txtPassword.Text);

            AdminAccount adminAccount = lstAdminAccount.Where(aa => aa.Username == username && aa.Password.ToLower() == password.ToLower()).SingleOrDefault();

            if (adminAccount == null)
            {
                MessageBox.Show("Wrong username or password!", "Login failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            fMain.isLoggedIn = isLoggedIn = true;
            Close();
        }
コード例 #2
0
        private async void btnSubmit_Click(object sender, System.EventArgs e)
        {
            // Lay gia tri tren form gan vao account
            profile.UserID       = txtUserID.Text;
            profile.Password     = txtPassword.Text;
            profile.FirstName    = txtFirstName.Text;
            profile.LastName     = txtLastName.Text;
            profile.Address      = txtAddress.Text;
            profile.PhoneNumber  = txtPhoneNumber.Text;
            profile.EmailAddress = txtEmailAddress.Text;
            profile.Age          = Convert.ToInt32(numAge);
            profile.CreditCard   = txtCreditCard.Text;
            profile.SkyMiles     = Convert.ToInt32(numSkyMiles);
            profile.Sex          = rbtnMale.Checked;
            profile.IsActive     = rbtnActive.Checked;

            // Neu dang o che do tao account moi thi phai lay gia tri trong o password gan vao account.
            // Neu dang o che do chinh sua ma gia tri trong o password khac voi gia tri password cua account
            // nghia la nguoi dung da thay doi password, phai cap nhat luon password
            if (mode == FormMode.CREATE || txtPassword.Text != profile.Password)
            {
                profile.Password = ARSUtilities.Md5Hash(txtPassword.Text);
            }

            // Tao mot API
            ProfileWrapper profileWrapper = new ProfileWrapper();
            // Tao bien luu ket qua tra ve
            bool isSuccess;

            // Kiem tra xem dang o che do nao
            if (mode == FormMode.CREATE)
            {
                // Neu dang o che do them moi (CREATE)
                // POST account len server
                isSuccess = await profileWrapper.Post(profile);
            }
            else
            {
                // Neu dang o che do chinh sua (EDIT)
                // PUT account len server
                isSuccess = await profileWrapper.Put(Convert.ToInt32(profile.ID), profile);
            }

            // Kiem tra ket qua tra ve
            if (isSuccess)
            {
                // Neu thanh cong
                MessageBox.Show("Operation completed successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                // Tat form CE
                this.Close();
            }
            else
            {
                // Neu that bai, hien thong bao loi
                MessageBox.Show("An error has occurred:\n" + profileWrapper.GetErrorMessage(), "Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #3
0
        private async void btnSubmit_Click(object sender, EventArgs e)
        {
            // Lay gia tri tren form gan vao account
            adminAccount.Username = txtUsername.Text;
            adminAccount.Name     = txtName.Text;
            adminAccount.Role     = txtRole.Text;
            adminAccount.IsActive = rbtnActive.Checked;

            // Neu dang o che do tao account moi thi phai lay gia tri trong o password gan vao account.
            // Neu dang o che do chinh sua ma gia tri trong o password khac voi gia tri password cua account
            // nghia la nguoi dung da thay doi password, phai cap nhat luon password
            if (mode == FormMode.CREATE || txtPassword.Text != adminAccount.Password)
            {
                adminAccount.Password = ARSUtilities.Md5Hash(txtPassword.Text);
            }

            // Tao mot API
            AdminAccountWrapper adminAccountWrapper = new AdminAccountWrapper();
            // Tao bien luu ket qua tra ve
            bool isSuccess;

            // Kiem tra xem dang o che do nao
            if (mode == FormMode.CREATE)
            {
                // Neu dang o che do them moi (CREATE)
                // POST account len server
                isSuccess = await adminAccountWrapper.Post(adminAccount);
            }
            else
            {
                // Neu dang o che do chinh sua (EDIT)
                // PUT account len server
                isSuccess = await adminAccountWrapper.Put(adminAccount.ID, adminAccount);
            }

            // Kiem tra ket qua tra ve
            if (isSuccess)
            {
                // Neu thanh cong
                MessageBox.Show("Operation completed successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                // Tat form CE
                this.Close();
            }
            else
            {
                // Neu that bai, hien thong bao loi
                MessageBox.Show("An error has occurred:\n" + adminAccountWrapper.GetErrorMessage(), "Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #4
0
        public async Task <T> Get(string id)
        {
            APIWrapper <T>      apiWrapper = new APIWrapper <T>(MODEL_API, id);
            HttpResponseMessage response   = await apiWrapper.GET();

            if (response.IsSuccessStatusCode)
            {
                var responseData = response.Content.ReadAsStringAsync().Result;
                T   lstResult    = ARSUtilities.JsonToObject <T>(responseData.ToString());

                return(lstResult);
            }

            SaveErrorMessage(response);
            return(default(T));
        }
コード例 #5
0
        public async Task <List <FlightSchedule> > List(long ticketID)
        {
            APIWrapper <FlightSchedule> apiWrapper = new APIWrapper <FlightSchedule>(APIWrapper <FlightSchedule> .ARSAPI.TICKET_FLIGHT_SCHEDULE, ticketID.ToString());
            HttpResponseMessage         response   = await apiWrapper.GET();

            if (response.IsSuccessStatusCode)
            {
                var    responseData             = response.Content.ReadAsStringAsync().Result;
                JArray parsed                   = JArray.Parse(responseData.ToString());
                List <FlightSchedule> lstResult = new List <FlightSchedule>();

                foreach (var pair in parsed)
                {
                    FlightSchedule obj = ARSUtilities.JsonToObject <FlightSchedule>(pair.ToString());
                    lstResult.Add(obj);
                }

                return(lstResult);
            }

            return(null);
        }
コード例 #6
0
        public new async Task <List <AirplaneInfo> > Get(string id)
        {
            APIWrapper <AirplaneInfo> apiWrapper = new APIWrapper <AirplaneInfo>(MODEL_API, id);
            HttpResponseMessage       response   = await apiWrapper.GET();

            if (response.IsSuccessStatusCode)
            {
                var    responseData           = response.Content.ReadAsStringAsync().Result;
                JArray parsed                 = JArray.Parse(responseData.ToString());
                List <AirplaneInfo> lstResult = new List <AirplaneInfo>();

                foreach (var pair in parsed)
                {
                    AirplaneInfo obj = ARSUtilities.JsonToObject <AirplaneInfo>(pair.ToString());
                    lstResult.Add(obj);
                }

                return(lstResult);
            }

            return(null);
        }
コード例 #7
0
        public async Task <List <T> > List()
        {
            APIWrapper <T>      apiWrapper = new APIWrapper <T>(MODEL_API);
            HttpResponseMessage response   = await apiWrapper.GET();

            if (response.IsSuccessStatusCode)
            {
                List <T> lstResult    = new List <T>();
                var      responseData = response.Content.ReadAsStringAsync().Result;
                JArray   parsed       = JArray.Parse(responseData.ToString());

                foreach (var pair in parsed)
                {
                    T obj = ARSUtilities.JsonToObject <T>(pair.ToString());
                    lstResult.Add(obj);
                }

                return(lstResult);
            }

            SaveErrorMessage(response);
            return(null);
        }