Пример #1
0
        public async override void OnStart()
        {
            base.OnStart();
            if (ViewModel.Facilities.Count == 0)
            {
                MessageDialog messageDialog = new MessageDialog();
                messageDialog.ShowLoading();
                if (ap.IsOnline(Application.Context))
                {
                    await ViewModel.ExecuteFacilitiesCommand(userId);

                    // await this.SqlLiteManager.SyncFacilitiesFromAPI(ViewModel.Facilities);
                }
                else
                {
                    //await this.SqlLiteManager.GetLocalFacilities(userId);
                }
                if (ViewModel.Facilities.Count == 0)
                {
                    messageDialog.SendMessage("There are no facilities that are assinged to this profile.", "No Facilities Found");
                }
                recyclerView.SetAdapter(adapter = new BrowseFacilitiesAdapter(Activity, ViewModel, userId));
                messageDialog.HideLoading();
            }

            refresher.Refresh += Refresher_Refresh;
            adapter.ItemClick += Adapter_ItemClick;
        }
        private async void SaveFacility()
        {
            if (appPreferences.IsOnline(Application.Context))
            {
                facility.SettlementType = settlementtype.SelectedItem.ToString();
                facility.Zoning         = zoning.SelectedItem.ToString();


                MessageDialog messageDialog = new MessageDialog();
                messageDialog.ShowLoading();
                bool isUpdated = await viewModel.ExecuteUpdateFacilityCommand(facility);

                messageDialog.HideLoading();
                if (isUpdated)
                {
                    messageDialog.SendToast("Facility Information is saved successful.");
                    var            intent   = new Intent(this, typeof(FacilityDetailActivity));
                    Context        mContext = Android.App.Application.Context;
                    AppPreferences ap       = new AppPreferences(mContext);
                    ap.SaveFacilityId(facility.Id.ToString());
                    intent.PutExtra("data", Newtonsoft.Json.JsonConvert.SerializeObject(facility));
                    this.StartActivity(intent);
                    Finish();
                }
                else
                {
                    messageDialog.SendToast("Error occurred: Unable to save Facility Information.");
                }
            }
        }
Пример #3
0
        private async void SignIn_Click(object sender, EventArgs e)
        {
            if (!ValidateForm())
            {
                return;
            }

            MessageDialog messageDialog = new MessageDialog();

            messageDialog.ShowLoading();

            EncryptionHelper encryptionHelper = new EncryptionHelper();

            message.Text = "";
            var user = new User()
            {
                Username = username.Text,
                Password = password.Text,
            };

            if (appPreferences.IsOnline(Application.Context))
            {
                user = await ViewModel.ExecuteLoginCommand(user);

                if (user.RespondMessage != null)
                {
                    message.Text = user.RespondMessage;
                }
                else
                {
                    var newIntent = new Intent(this, typeof(MainActivity));
                    newIntent.AddFlags(ActivityFlags.ClearTop);
                    newIntent.AddFlags(ActivityFlags.SingleTop);
                    appPreferences.SaveUserId(user.Id.ToString());

                    StartActivity(newIntent);

                    Finish();
                }
            }

            messageDialog.HideLoading();
        }
Пример #4
0
        private async void SaveDeedInfor()
        {
            if (appPreferences.IsOnline(Application.Context))
            {
                MessageDialog messageDialog = new MessageDialog();
                messageDialog.ShowLoading();

                if (!ValidateDeedInfo())
                {
                    messageDialog.HideLoading();
                    return;
                }
                DeedsInfo.ErFNumber       = erfNumber.Text;
                DeedsInfo.TitleDeedNumber = titleDeedNumber.Text;
                DeedsInfo.Extent          = extentm2.Text;
                DeedsInfo.OwnerInfomation = ownerInformation.Text;
                DeedsInfo.FacilityId      = Facility.Id;
                DeedsInfo.CreatedUserId   = userId;
                DeedsInfo.ModifiedDate    = DateTime.Now;
                DeedsInfo.ModifiedUserId  = userId;
                DeedsInfo.CreatedDate     = DateTime.Now;
                bool isSuccess = await ViewModel.AddUpdateDeedsInfoAsync(DeedsInfo);

                messageDialog.HideLoading();
                if (isSuccess)
                {
                    messageDialog.SendToast("Deeds information is saved successful.");
                    var intent = new Intent(this, typeof(FacilityDetailActivity));
                    appPreferences.SaveFacilityId(Facility.Id.ToString());
                    Facility.Buildings = new List <Building>();
                    Facility.DeedsInfo = DeedsInfo;
                    intent.PutExtra("data", Newtonsoft.Json.JsonConvert.SerializeObject(Facility));
                    this.StartActivity(intent);
                    Finish();
                }
                else
                {
                    messageDialog.SendToast("Error occurred: Unable to save deed information.");
                }
            }
        }
Пример #5
0
        private async void SaveLocation()
        {
            if (appPreferences.IsOnline(Application.Context))
            {
                MessageDialog messageDialog = new MessageDialog();
                messageDialog.ShowLoading();
                if (!ValidateLocation())
                {
                    messageDialog.HideLoading();
                    return;
                }

                Location.LocalMunicipality = localmunicipality.SelectedItem.ToString();
                Location.Province          = province.SelectedItem.ToString();
                Location.StreetAddress     = streetAddress.Text;
                Location.Suburb            = suburb.Text;
                Location.Region            = region.Text;
                Location.BoundryPolygon    = _BoundryPolygons;
                Location.FacilityId        = Facility.Id;
                bool isSuccess = await ViewModel.AddUpdateLocationAsync(Location);

                messageDialog.HideLoading();
                if (isSuccess)
                {
                    messageDialog.SendToast("Location is saved successful.");
                    var            intent   = new Intent(this, typeof(FacilityDetailActivity));
                    Context        mContext = Android.App.Application.Context;
                    AppPreferences ap       = new AppPreferences(mContext);
                    ap.SaveFacilityId(Facility.Id.ToString());
                    Facility.Buildings = new List <Building>();
                    Facility.Location  = Location;
                    intent.PutExtra("data", Newtonsoft.Json.JsonConvert.SerializeObject(Facility));
                    this.StartActivity(intent);
                    Finish();
                }
                else
                {
                    messageDialog.SendToast("Error occurred: Unable to save location.");
                }
            }
        }
Пример #6
0
        private async void SavePerson()
        {
            if (appPreferences.IsOnline(Application.Context))
            {
                MessageDialog messageDialog = new MessageDialog();
                messageDialog.ShowLoading();

                Person.FullName       = fullname.Text;
                Person.Designation    = designation.Text;
                Person.PhoneNumber    = mobileNumber.Text;
                Person.EmailAddress   = emailaddress.Text;
                Person.FacilityId     = Facility.Id;
                Person.CreatedUserId  = userId;
                Person.ModifiedDate   = DateTime.Now;
                Person.ModifiedUserId = userId;
                Person.CreatedDate    = DateTime.Now;
                bool isSuccess = await ViewModel.AddUpdatePersonAsync(Person);

                messageDialog.HideLoading();
                if (isSuccess)
                {
                    messageDialog.SendToast("Responsible person is saved successful.");
                    var            intent   = new Intent(this, typeof(FacilityDetailActivity));
                    Context        mContext = Android.App.Application.Context;
                    AppPreferences ap       = new AppPreferences(mContext);
                    ap.SaveFacilityId(Facility.Id.ToString());
                    Facility.Buildings        = new List <Building>();
                    Facility.ResposiblePerson = Person;
                    intent.PutExtra("data", Newtonsoft.Json.JsonConvert.SerializeObject(Facility));
                    this.StartActivity(intent);
                    Finish();
                }
                else
                {
                    messageDialog.SendToast("Error occurred: Unable to save responsible person.");
                }
            }
        }
        async void SaveBuilding()
        {
            if (appPreferences.IsOnline(Application.Context))
            {
                MessageDialog messageDialog = new MessageDialog();
                messageDialog.ShowLoading();

                if (!ValidateForm())
                {
                    messageDialog.HideLoading();
                    return;
                }

                int numberOfFloors = 0;
                if (!String.IsNullOrEmpty(nooOfFoors.Text))
                {
                    numberOfFloors = Convert.ToInt32(nooOfFoors.Text);
                }

                if (PhotoIsChanged)
                {
                    FileName = SaveImage(((BitmapDrawable)buildingPhoto.Drawable).Bitmap);
                }

                Building item = new Building
                {
                    Id                      = building.Id,
                    BuildingName            = buildingName.Text,
                    BuildingNumber          = building.Id == 0 ? facilityId + helpers.RandomDigits(10) : building.BuildingNumber,
                    BuildingType            = buildingType.SelectedItem.ToString(),
                    BuildingStandard        = buildingstandard.SelectedItem.ToString(),
                    Status                  = utilisationStatus.Text,
                    NumberOfFloors          = numberOfFloors,
                    FootPrintArea           = Convert.ToDouble(totalFootprintAream2.Text),
                    ImprovedArea            = Convert.ToDouble(totalImprovedaAeam2.Text),
                    Heritage                = heritage.Checked == true ? true : false,
                    OccupationYear          = occupationYear.Text,
                    DisabledAccess          = disabledAccesss.SelectedItem.ToString(),
                    DisabledComment         = disabledComment.Text,
                    ConstructionDescription = constructionDescription.Text,
                    GPSCoordinates          = _GPSCoordinates,
                    Photo                   = PhotoIsChanged == true ? FileName : building.Photo,
                    CreatedDate             = new DateTime(),
                    CreatedUserId           = userId,
                    ModifiedUserId          = userId,
                    Facility                = new Facility
                    {
                        Id = facilityId
                    }
                };
                bool isAdded = false;
                if (!isEdit)
                {
                    isAdded = await ViewModel.AddBuildingAsync(item);
                }
                else
                {
                    isAdded = await ViewModel.UpdateBuildingAsync(item);
                }

                if (isAdded)
                {
                    if (PhotoIsChanged)
                    {
                        PictureViewModel pictureViewModel = new PictureViewModel();
                        Bitmap           _bm = ((BitmapDrawable)buildingPhoto.Drawable).Bitmap;
                        string           bal = "";
                        if (_bm != null)
                        {
                            MemoryStream stream = new MemoryStream();
                            _bm.Compress(Bitmap.CompressFormat.Jpeg, 100, stream);
                            byte[] ba = stream.ToArray();
                            bal = Base64.EncodeToString(ba, Base64.Default);
                        }

                        Models.Picture picture = new Models.Picture()
                        {
                            Name = FileName,
                            File = bal,
                        };
                        List <Models.Picture> pictures = new List <Models.Picture>();
                        pictures.Add(picture);
                        await pictureViewModel.ExecuteSavePictureCommand(pictures);
                    }
                    messageDialog.HideLoading();
                    if (!isEdit)
                    {
                        messageDialog.SendToast("Building is added successful.");
                    }
                    else
                    {
                        messageDialog.SendToast("Building is updated successful.");
                    }
                    Finish();
                }
                else
                {
                    messageDialog.HideLoading();
                    if (!isEdit)
                    {
                        messageDialog.SendToast("Unable to add new building.");
                    }
                    else
                    {
                        messageDialog.SendToast("Unable to update building.");
                    }
                }
            }
        }
        private async void SaveFacility()
        {
            if (appPreferences.IsOnline(Application.Context))
            {
                MessageDialog messageDialog = new MessageDialog();
                messageDialog.ShowLoading();
                if (imageNames.Count() == 0)
                {
                    imageNames = new List <string>();
                }

                if (FirstPhotoIsChanged)
                {
                    string thisFileName = appPreferences.SaveImage(((BitmapDrawable)facilityPhoto.Drawable).Bitmap);
                    if (imageNames.Count() > 0)
                    {
                        imageNames[0] = thisFileName;
                    }
                    else
                    {
                        imageNames.Add(thisFileName);
                    }
                }
                if (SecondPhotoIsChanged)
                {
                    var _fileName = String.Format("facility_{0}", Guid.NewGuid());
                    appPreferences.SaveImage(((BitmapDrawable)secondFacilityPhoto.Drawable).Bitmap, _fileName);
                    if (imageNames.Count() > 1)
                    {
                        imageNames[1] = _fileName;
                    }
                    else
                    {
                        imageNames.Add(_fileName);
                    }
                }
                if (FirstPhotoIsChanged)
                {
                    facility.IDPicture = "";

                    foreach (var name in imageNames)
                    {
                        if (!String.IsNullOrEmpty(name))
                        {
                            if (String.IsNullOrEmpty(facility.IDPicture))
                            {
                                facility.IDPicture = name;
                            }
                            else
                            {
                                facility.IDPicture = facility.IDPicture + "," + name;
                            }
                        }
                    }
                }


                bool isUpdated = await ViewModel.ExecuteUpdateFacilityCommand(facility);

                if (isUpdated)
                {
                    PictureViewModel      pictureViewModel = new PictureViewModel();
                    List <Models.Picture> pictures         = new List <Models.Picture>();
                    if (FirstPhotoIsChanged)
                    {
                        Bitmap _bm  = ((BitmapDrawable)facilityPhoto.Drawable).Bitmap;
                        string file = "";
                        if (_bm != null)
                        {
                            MemoryStream stream = new MemoryStream();
                            _bm.Compress(Bitmap.CompressFormat.Jpeg, 100, stream);
                            byte[] ba = stream.ToArray();
                            file = Base64.EncodeToString(ba, Base64.Default);
                        }

                        Models.Picture picture = new Models.Picture()
                        {
                            Name = imageNames[0],
                            File = file,
                        };
                        pictures.Add(picture);
                    }
                    if (SecondPhotoIsChanged && imageNames.Count() > 1)
                    {
                        Bitmap _bm  = ((BitmapDrawable)secondFacilityPhoto.Drawable).Bitmap;
                        string file = "";
                        if (_bm != null)
                        {
                            MemoryStream stream = new MemoryStream();
                            _bm.Compress(Bitmap.CompressFormat.Jpeg, 100, stream);
                            byte[] ba = stream.ToArray();
                            file = Base64.EncodeToString(ba, Base64.Default);
                        }

                        Models.Picture picture = new Models.Picture()
                        {
                            Name = imageNames[1],
                            File = file,
                        };
                        pictures.Add(picture);
                    }
                    bool isSuccess = await pictureViewModel.ExecuteSavePictureCommand(pictures);

                    messageDialog.HideLoading();
                    messageDialog.SendToast("Pictures are saved successful.");
                    var            intent   = new Intent(this, typeof(FacilityDetailActivity));
                    Context        mContext = Android.App.Application.Context;
                    AppPreferences ap       = new AppPreferences(mContext);
                    ap.SaveFacilityId(facility.Id.ToString());
                    intent.PutExtra("data", Newtonsoft.Json.JsonConvert.SerializeObject(facility));
                    this.StartActivity(intent);
                    Finish();
                }
                else
                {
                    messageDialog.HideLoading();
                    messageDialog.SendToast("Pictures are not saved successful.");
                }
            }
        }