private async void BtnViolation_Clicked(object sender, EventArgs e)
        {
            string         resultmsg       = string.Empty;
            string         existingCheckIn = string.Empty;
            MasterHomePage masterPage      = null;

            BtnViolation.IsVisible = false;
            ShowLoading(true);
            try
            {
                int number;
                if (DeviceInternet.InternetConnected())
                {
                    if (SelectedVehicle != string.Empty)
                    {
                        if (entryRegistrationNumber.Text != null && (!entryRegistrationNumber.Text.Contains(" ") && (entryRegistrationNumber.Text.Length >= 6 && entryRegistrationNumber.Text.Length <= 10)))
                        {
                            string regNumber = entryRegistrationNumber.Text;
                            string regFormat = regNumber.Substring(regNumber.Length - 4);
                            if (int.TryParse(regFormat, out number))
                            {
                                if (pickerBayNumers.SelectedItem != null)
                                {
                                    if ((checkBoxClampVehicle.IsChecked) || (chkWarning.IsChecked))
                                    {
                                        if (pickerVehicleReason.SelectedItem != null)
                                        {
                                            ParkingBay      objselectedbay    = (ParkingBay)pickerBayNumers.SelectedItem;
                                            ViolationReason objselectedreason = (ViolationReason)pickerVehicleReason.SelectedItem;
                                            if (imgCameraByteData != null)
                                            {
                                                if (App.Current.Properties.ContainsKey("LoginUser") && App.Current.Properties.ContainsKey("apitoken"))
                                                {
                                                    await Task.Run(() =>
                                                    {
                                                        existingCheckIn = VerifyVehicleCheckInStatus();
                                                        if (existingCheckIn == string.Empty)
                                                        {
                                                            ViolationAndClamp objViolationAndClamp = new ViolationAndClamp();
                                                            User objloginuser                         = (User)App.Current.Properties["LoginUser"];
                                                            objViolationAndClamp.UserID               = objloginuser.UserID;
                                                            objViolationAndClamp.UserTypeID           = objloginuser.UserTypeID.UserTypeID;
                                                            objViolationAndClamp.LocationID           = objloginuser.LocationParkingLotID.LocationID.LocationID;
                                                            objViolationAndClamp.LocationParkingLotID = objloginuser.LocationParkingLotID.LocationParkingLotID;
                                                            objViolationAndClamp.LocationName         = objloginuser.LocationParkingLotID.LocationID.LocationName;
                                                            objViolationAndClamp.RegistrationNumber   = entryRegistrationNumber.Text;
                                                            objViolationAndClamp.BayNumberID          = objselectedbay.ParkingBayID;
                                                            objViolationAndClamp.BayNumber            = objselectedbay.ParkingBayName;
                                                            objViolationAndClamp.IsClamp              = checkBoxClampVehicle.IsChecked;
                                                            objViolationAndClamp.ReasonID             = objselectedreason.ViolationReasonID;
                                                            objViolationAndClamp.ReasonName           = objselectedreason.Reason;
                                                            objViolationAndClamp.VehicleTypeCode      = SelectedVehicle;
                                                            DateTime openTime                         = DateTime.Parse(objloginuser.LocationParkingLotID.LotOpenTime);
                                                            if (DateTime.Now < openTime)
                                                            {
                                                                objViolationAndClamp.ViolationStartTime = openTime;
                                                                objViolationAndClamp.ViolationTime      = openTime.ToString("MM/dd/yyyy HH:mm tt");
                                                            }
                                                            else
                                                            {
                                                                objViolationAndClamp.ViolationStartTime = violationTime;
                                                                objViolationAndClamp.ViolationTime      = violationTime.ToString("MM/dd/yyyy HH:mm tt");
                                                            }

                                                            objViolationAndClamp.IsWarning             = Convert.ToBoolean(chkWarning.IsChecked);
                                                            objViolationAndClamp.VehicleImageLottitude = Convert.ToDecimal(Latitude);
                                                            objViolationAndClamp.VehicleImageLongitude = Convert.ToDecimal(Longitude);
                                                            if (imgCameraByteData != null)
                                                            {
                                                                objViolationAndClamp.ViolationImage = ByteArrayCompressionUtility.Compress(imgCameraByteData);
                                                            }
                                                            resultmsg = dal_ViolationClamp.SaveViolationAndClamp(Convert.ToString(App.Current.Properties["apitoken"]), objViolationAndClamp);
                                                            if (resultmsg == "Success")
                                                            {
                                                                masterPage = new MasterHomePage();
                                                            }
                                                        }
                                                    });

                                                    if (existingCheckIn == string.Empty)
                                                    {
                                                        if (resultmsg == "Success")
                                                        {
                                                            await Navigation.PushAsync(masterPage);
                                                        }
                                                        else
                                                        {
                                                            await DisplayAlert("Alert", "Violation Check In failed,Please contact Admin.", "Ok");
                                                        }
                                                    }
                                                    else
                                                    {
                                                        await DisplayAlert("Alert", "Vehicle Checked In as Violation at " + existingCheckIn, "Ok");
                                                    }
                                                }
                                                else
                                                {
                                                    await DisplayAlert("Alert", "User details and API token unavailable. Login again", "Ok");
                                                }
                                            }
                                            else
                                            {
                                                await DisplayAlert("Alert", "Please select Vehicle Image.", "Ok");
                                            }
                                        }
                                        else
                                        {
                                            await DisplayAlert("Alert", "Please select Reason.", "Ok");
                                        }
                                    }
                                    else
                                    {
                                        await DisplayAlert("Alert", "Please check Clamp or Warning ", "Ok");
                                    }
                                }
                                else
                                {
                                    await DisplayAlert("Alert", "Please select Bay Number.", "Ok");
                                }
                            }
                            else
                            {
                                await DisplayAlert("Alert", "Please enter valid Registration Number", "Ok");
                            }
                        }
                        else
                        {
                            await DisplayAlert("Alert", "Please enter valid Registration Number.", "Ok");
                        }
                    }
                    else
                    {
                        await DisplayAlert("Alert", "Please select Vehicle type", "Ok");
                    }
                    BtnViolation.IsVisible = true;
                }
                else
                {
                    await DisplayAlert("Alert", "Please check your Internet connection", "Ok");

                    ShowLoading(false);
                    BtnViolation.IsVisible = true;
                }
            }
            catch (Exception ex)
            {
            }
            ShowLoading(false);
            BtnViolation.IsVisible = true;
        }
        private async void btn_UpdateClicked(object sender, EventArgs e)
        {
            IsOnline = VerifyInternet();

            if (IsOnline)
            {
                btnUpdate.IsVisible = false;
                ShowLoading(true);

                try
                {
                    if (txtName.Text == "" || txtName.Text == null)
                    {
                        btnUpdate.IsVisible = true;
                        ShowLoading(false);
                        DisplayAlert("", "Please enter your Name", "Ok");
                        return;
                    }

                    var regexName = new Regex("^[a-z A-Z]*$");
                    if (!regexName.IsMatch(txtName.Text.Trim()))
                    {
                        btnUpdate.IsVisible = true;
                        ShowLoading(false);
                        DisplayAlert("", "Please enter only alphabets for Name", "Ok");
                        return;
                    }

                    if (txtPhoneNumber.Text == "" || txtPhoneNumber.Text == null)
                    {
                        btnUpdate.IsVisible = true;
                        ShowLoading(false);
                        DisplayAlert("", "Please enter your Phone Number", "Ok");
                        return;
                    }

                    if (txtEmail.Text == "" || txtEmail.Text == null)
                    {
                        btnUpdate.IsVisible = true;
                        ShowLoading(false);
                        DisplayAlert("", "Please enter your Email", "Ok");
                        return;
                    }

                    if (txtName.Text.Length >= 3 && txtName.Text.Length <= 20)
                    {
                        if (txtEmail.Text != "" && txtEmail.Text != null)
                        {
                            if (!RegexUtilities.IsEmailValid(txtEmail.Text.Trim()))
                            {
                                btnUpdate.IsVisible = true;
                                ShowLoading(false);
                                DisplayAlert("", "Please enter valid Email", "Ok");
                                return;
                            }
                        }
                        Customer objCustomer = new Customer();
                        objCustomer.CustomerID  = CustomerID;
                        objCustomer.Name        = txtName.Text.Trim();
                        objCustomer.Email       = txtEmail.Text == null || txtEmail.Text == "" ? "" : txtEmail.Text.Trim();
                        objCustomer.PhoneNumber = txtPhoneNumber.Text.Trim();
                        objCustomer.Gender      = Gender_static;

                        if (imgCameraByteData != null)
                        {
                            objCustomer.ProfileImage = ByteArrayCompressionUtility.Compress(imgCameraByteData);
                        }

                        if (App.Current.Properties.ContainsKey("RefreshedToken"))
                        {
                            btnUpdate.IsVisible  = true;
                            objCustomer.DeviceID = Convert.ToString(App.Current.Properties["RefreshedToken"]);
                        }
                        else
                        {
                            btnUpdate.IsVisible  = true;
                            objCustomer.DeviceID = "";
                        }

                        if (txtYearOfBirth.Text != "" && txtYearOfBirth.Text != null)
                        {
                            if (Convert.ToInt32(txtYearOfBirth.Text.Trim()) > 1900)
                            {
                                DateTime dateOfBirth = new DateTime(Convert.ToInt32(txtYearOfBirth.Text.Trim()), DateTime.Now.Month, 1);
                                objCustomer.DateOfBirth = dateOfBirth;
                                objCustomer.Age         = Convert.ToInt32(DateTime.Now.Year) - Convert.ToInt32(txtYearOfBirth.Text.Trim());
                            }
                            else
                            {
                                btnUpdate.IsVisible = true;
                                ShowLoading(false);
                                DisplayAlert("", "Only people born after 1900 please! Enter your Year of Birth", "Ok");
                                return;
                            }
                        }
                        else
                        {
                            objCustomer.DateOfBirth = null;
                            objCustomer.Age         = 0;
                        }

                        if (App.Current.Properties.ContainsKey("apitoken"))
                        {
                            var json    = JsonConvert.SerializeObject(objCustomer);
                            var content = new StringContent(json, Encoding.UTF8, "application/json");
                            dal_Customer = new DALCustomer();
                            OCustomer resultObj = new OCustomer();

                            await Task.Run(() =>
                            {
                                resultObj = dal_Customer.UpdateCustomer(Convert.ToString(App.Current.Properties["apitoken"]), objCustomer);
                            });

                            if (resultObj.CustomerID != 0)
                            {
                                App.Current.Properties["UserName"]     = txtName.Text.Trim();
                                App.Current.Properties["PhoneNumber"]  = txtPhoneNumber.Text.Trim();
                                App.Current.Properties["Email"]        = txtEmail.Text.Trim();
                                App.Current.Properties["CustomerID"]   = resultObj.CustomerID;
                                App.Current.Properties["ProfileImage"] = resultObj.ProfileImage;
                                await Application.Current.SavePropertiesAsync();

                                int CustomerID = resultObj.CustomerID;
                                App.Current.Properties["CustomerID"] = CustomerID;

                                btnUpdate.IsVisible = true;
                                ShowLoading(false);
                                await Navigation.PushAsync(new Home(null, CustomerID));
                            }
                            else
                            {
                                btnUpdate.IsVisible = true;
                                ShowLoading(false);
                                DisplayAlert("Failed - UpdateCustomer", "Update Customer Failed", "Ok");
                            }
                        }
                        else
                        {
                            btnUpdate.IsVisible = true;
                            ShowLoading(false);
                        }
                    }
                    else
                    {
                        btnUpdate.IsVisible = true;
                        ShowLoading(false);
                        DisplayAlert("", "Name must be atleast 3 characters and maximum 20 characters", "Ok");
                    }
                }
                catch (Exception ex)
                {
                    btnUpdate.IsVisible = true;
                    ShowLoading(false);
                    DisplayAlert("Failed - ", "Failed To Update Details", "Ok");
                }
            }
            else
            {
                await DisplayAlert("", "Please check your network connectivity", "Ok");

                return;
            }
        }
Example #3
0
 public void CompressMessages()
 {
     compressedData = ByteArrayCompressionUtility.Compress(uncompressedData.ToArray());
 }