예제 #1
0
        protected override void OnPostCreate(Bundle savedInstanceState)
        {
            base.OnPostCreate(savedInstanceState);

            //Bind Event Handlers
            btnSave.Click       += BtnSave_Click;
            btnCancel.Click     += btnCancel_Click;
            btnUpload.Click     += btnUpload_Click;
            btnEditSketch.Click += BtnEditSketch_Click;
            btnDelete.Click     += btnDelete_Click;

            ModeSwitch.CheckedChange += ModeSwitch_CheckedChange;

            btnRefresh.Click += delegate(object sender, EventArgs args)
            {
                ctlSurveySheetRoom.LoadData(LoggedInUser, mguidFormUID);
                ctlSurveySheetRoom.OnDataLoaded();
            };

            btnNew.Click += delegate(object sender, EventArgs args)
            {
                Save(true);

                if (mobjForm == null)
                {
                    mobjForm     = new BusinessLogic.SurveySheet();
                    mguidFormUID = mobjForm.SheetUID;
                }

                NavigatingToChild = true;

                ctlSurveySheetRoom.OpenAssessment(true, 0, mguidFormUID);
            };

            //Set IsDirty
            txtSheetName.AfterTextChanged         += MarkAsDirty;
            txtJobNumber.AfterTextChanged         += txtJobNumber_AfterTextChanged;
            txtJobNumber.FocusChange              += txtJobNumber_FocusChanged;
            txtDate.AfterTextChanged              += MarkAsDirty;
            txtAddress.AfterTextChanged           += MarkAsDirty;
            txtClient.AfterTextChanged            += MarkAsDirty;
            txtSurveyor.AfterTextChanged          += MarkAsDirty;
            txtReasonForSurvey.AfterTextChanged   += MarkAsDirty;
            txtTotalSamplesTaken.AfterTextChanged += MarkAsDirty;
            txtWater.AfterTextChanged             += MarkAsDirty;
            txtPower.AfterTextChanged             += MarkAsDirty;
            txtParking.AfterTextChanged           += MarkAsDirty;
            txtGeneralComments.AfterTextChanged   += MarkAsDirty;
        }
예제 #2
0
        private void txtJobNumber_AfterTextChanged(object sender, EventArgs e)
        {
            try
            {
                JobCodeFound = false;

                //using the local database even when connected as it is currently updated everytime a connection is available and the RiskAssessment activity is opened.
                BusinessLogic.LocalDatabase db = new BusinessLogic.LocalDatabase();

                var objResult = from j in db.database.Table <WcfService.JobListResponse>()
                                where j.Code.ToLower() == txtJobNumber.Text.ToLower()
                                select j;

                if (objResult.Count() > 0)
                {
                    if (mobjForm == null)
                    {
                        mobjForm     = new BusinessLogic.SurveySheet();
                        mguidFormUID = mobjForm.SheetUID;
                    }
                    mobjForm.JobNumber = txtJobNumber.Text;
                    txtAddress.Text    = objResult.FirstOrDefault().Address;
                    mobjForm.Address   = objResult.FirstOrDefault().Address;
                    txtClient.Text     = objResult.FirstOrDefault().PolicyHolder;
                    mobjForm.Client    = objResult.FirstOrDefault().PolicyHolder;
                    JobCodeFound       = true;
                }

                IsDirty = true;
            }
            catch (Exception ex)
            {
                new AlertDialog.Builder(this)
                .SetTitle("Error finding Address.")
                .SetMessage($"An unexpected error occurred when trying to find a job matching the given job code.")
                .SetIcon(Resource.Drawable.Icon)
                .SetNeutralButton("Ok", (sender2, args) => { })
                .Show();
            }
        }
예제 #3
0
        private void Save(bool blnSavingWithoutMessage)
        {
            string invalidMessage = string.Empty;

            Lock();

            if (mobjForm != null)
            {
                if (CurrentMode == Mode.Create && mobjForm.SheetUID == null)
                {
                    mobjForm = new BusinessLogic.SurveySheet();
                    if (mguidFormUID != Guid.Empty)
                    {
                        mobjForm.SheetUID = mguidFormUID;
                    }
                }
            }
            else
            {
                if (CurrentMode == Mode.Create)
                {
                    mobjForm = new BusinessLogic.SurveySheet();
                    if (mguidFormUID != Guid.Empty)
                    {
                        mobjForm.SheetUID = mguidFormUID;
                    }
                }
            }

            mobjForm.SheetName = txtSheetName.Text;
            mobjForm.JobNumber = txtJobNumber.Text;

            if (!string.IsNullOrWhiteSpace(txtDate.Text))
            {
                try
                {
                    mobjForm.Date = DateTime.Parse(txtDate.Text);
                }
                catch (Exception ex)
                {
                    new AlertDialog.Builder(this)
                    .SetIcon(Resource.Drawable.Icon)
                    .SetTitle("Invalid Date")
                    .SetMessage("The date entered is not valid, please check the value and try again.")
                    .SetNeutralButton("OK.", (sender, args) => { })
                    .Show();
                }
            }

            mobjForm.Address  = txtAddress.Text;
            mobjForm.Client   = txtClient.Text;
            mobjForm.Surveyor = txtSurveyor.Text;

            if (!string.IsNullOrWhiteSpace(txtTotalSamplesTaken.Text))
            {
                mobjForm.TotalSamplesTaken = Convert.ToInt32(txtTotalSamplesTaken.Text);
            }

            mobjForm.ReasonForSurvey = txtReasonForSurvey.Text;
            mobjForm.Water           = txtWater.Text;
            mobjForm.Power           = txtPower.Text;
            mobjForm.Parking         = txtParking.Text;
            mobjForm.GeneralComments = txtGeneralComments.Text;

            try
            {
                mobjForm.SketchPath = Sketch.UriPath;
            }
            catch (Exception ex)
            {
                mobjForm.SketchPath = null;
            }

            mobjForm.CreatedByUserID = LoggedInUser.ID;
            mobjForm.SaveToDevice();

            IsDirty = false;

            Unlock();

            if (!blnSavingWithoutMessage)
            {
                new AlertDialog.Builder(this)
                .SetIcon(Resource.Drawable.Icon)
                .SetTitle("Save Complete.")
                .SetMessage("Survey Sheet saved successfully.")
                .SetNeutralButton("OK.", (sender, args) => { })
                .Show();
            }
        }
예제 #4
0
        private void LoadAndPopulate()
        {
            CurrentMode = (Mode)Intent.GetIntExtra("Mode", (int)Mode.Create);
            string uid = Intent.GetStringExtra("FormUID");

            mguidFormUID = Guid.Parse(uid);

            if (Sketch == null)
            {
                Sketch = new WcfService.SerialisablePhotoThumbnail()
                {
                };
            }

            try
            {
                ctlSurveySheetRoom.mFormUID = mguidFormUID;
                ctlSurveySheetRoom.LoadData(LoggedInUser, mguidFormUID);
                ctlSurveySheetRoom.OnDataLoaded();
            }
            catch (Exception ex)
            {
                new AlertDialog.Builder(this)
                .SetIcon(Resource.Drawable.Icon)
                .SetTitle("Item list could not be loaded.")
                .SetMessage("An unexpected error occurred and the list of items on the form could not be loaded")
                .SetNeutralButton("OK.", (sender, args) => { })
                .Show();
            }

            btnUpload.Enabled = false;
            Android.Net.ConnectivityManager mngrCheckConnectivity = (Android.Net.ConnectivityManager)GetSystemService(Context.ConnectivityService);
            Android.Net.NetworkInfo         CheckActiveConnection = mngrCheckConnectivity.ActiveNetworkInfo;
            if (CheckActiveConnection != null)
            {
                btnUpload.Enabled = true;
            }

            //load and populate here for edit and view modes
            if (CurrentMode != Mode.Create)
            {
                ModeSwitch.Visibility = ViewStates.Visible;
                btnDelete.Visibility  = ViewStates.Visible;

                mobjForm = new BusinessLogic.SurveySheet();
                mobjForm.Load(mguidFormUID);

                txtSheetName.Text         = mobjForm.SheetName;
                txtDate.Text              = mobjForm.Date != DateTime.MinValue ? mobjForm.Date.ToShortDateString() : string.Empty;
                txtJobNumber.Text         = mobjForm.JobNumber;
                txtAddress.Text           = mobjForm.Address;
                txtClient.Text            = mobjForm.Client;
                txtSurveyor.Text          = mobjForm.Surveyor;
                txtTotalSamplesTaken.Text = mobjForm.TotalSamplesTaken.ToString();
                txtReasonForSurvey.Text   = mobjForm.ReasonForSurvey;
                txtWater.Text             = mobjForm.Water;
                txtPower.Text             = mobjForm.Power;
                txtParking.Text           = mobjForm.Parking;
                txtGeneralComments.Text   = mobjForm.GeneralComments;

                if (mobjForm.SketchPath != null || !string.IsNullOrWhiteSpace(mobjForm.SketchPath))
                {
                    Sketch.UriPath = mobjForm.SketchPath;
                    var uriImage = Code.URI.FromPath(Sketch.UriPath);
                    imgSketch.SetImageAutoScale(uriImage.GetImage(this));
                }

                switchMode(CurrentMode);
            }
            else
            {
                txtSheetName.Text = "Survey Sheet - " + LoggedInUser.Name;
                txtDate.Text      = DateTime.Now.ToShortDateString();
            }
        }