Ejemplo n.º 1
0
        private async void CreateAccount_Clicked(object sender, EventArgs e)
        {
            try
            {
                var userid     = txtuname.Text.Trim();
                var password   = txtpass.Text.Trim();
                var InviteCode = txtinvitecode.Text.Trim();
                var BackgroundLocationUpdate = "";

                if ((string.IsNullOrEmpty(txtuname.Text)) || (string.IsNullOrEmpty(txtpass.Text)) || (string.IsNullOrEmpty(txtinvitecode.Text)))
                {
                    lblmsg2.Text         = "All fields are required for registration.";
                    lblmsg2.IsVisible    = true;
                    errorframe.IsVisible = true;
                    return;
                }
                if ((SecurityCheck.isTampered((Convert.ToString(txtpass.Text) == null ? "" : txtpass.Text))) || (Convert.ToString(txtpass.Text).Length < 7))
                {
                    lblmsg2.Text         = "Password did not pass our security criteria. Hint: Needs to be minimum 6 chars long, No Spaces, certain special characters are not allowed.";
                    lblmsg2.IsVisible    = true;
                    errorframe.IsVisible = true;
                    return;
                }



                var rsds = App.SOAP_Request.NewRegistration(userid.Trim(), TripleDES.Encrypt(password.Trim()), InviteCode.Trim(), BackgroundLocationUpdate);



                if (!rsds.Contains("\"CompanyID\":"))
                {
                    lblmsg2.Text         = rsds;
                    lblmsg2.IsVisible    = true;
                    errorframe.IsVisible = true;
                    return;
                }
                Re_Type response = null;
                try
                {
                    response = JsonConvert.DeserializeObject <Re_Type>(rsds);
                    BackgroundLocationUpdate = response.BackgroundLocationUpdate;
                }
                catch (Exception f)
                {
                    lblmsg2.Text         = f.Message;
                    lblmsg2.IsVisible    = true;
                    errorframe.IsVisible = true;
                    return;
                }

                if (response.Valid.ToString().ToLower() == "y")
                {
                    Customer custom = new Customer();
                    custom.UserId                     = userid;
                    custom.Password                   = password;
                    custom.XCode                      = InviteCode;
                    custom.Type                       = response.Type != null ? response.Type : "";
                    custom.CompanyID                  = response.Type != null ? response.CompanyID : "";
                    custom.TransactURL                = response.Type != null ? response.URL : "";
                    custom.ActiveShipmentNo           = "";
                    custom.ActiveShipmentStatus       = "";
                    custom.LocationUpdate             = BackgroundLocationUpdate;
                    custom.IsBackgroundLocationUpdate = "";
                    App.SqlLiteCon().CreateTable <Customer>();

                    App.SqlLiteCon().Insert(custom);

                    if (App.SqlLiteCon().Table <Customer>().Count() == 0)
                    {
                        lblmsg2.Text         = "Invite Code Not Stored.";
                        lblmsg2.IsVisible    = true;
                        errorframe.IsVisible = true;
                        return;
                    }

                    await DisplayAlert("", "Registered Successfully.", "OK");

                    await Navigation.PushAsync(new MainPage());
                }
                else
                {
                    lblmsg2.Text         = "User's registration is not accepted, please contact admin.";
                    lblmsg2.IsVisible    = true;
                    errorframe.IsVisible = true;
                    return;
                }
            }
            catch (Exception ex)
            {
                lblmsg2.Text         = ex.Message.ToString();
                lblmsg2.IsVisible    = true;
                errorframe.IsVisible = true;
            }
        }