Exemple #1
0
        private void addServiceUserBtn_Click(object sender, EventArgs e)
        {
            if (Settings.IsTrial && ServiceUserManager.Instance.ServiceUsers.Count >= 5)
            {
                MessageBox.Show("You can only create a maximum of 5 service users while using a trial version of this product.", "Trial", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }


            try
            {
                ServiceUserFrm frm = new ServiceUserFrm()
                {
                    Title   = "Create Service User",
                    Workers = WorkerManager.Instance.ActiveWorkers
                };

                if (frm.ShowDialog() == DialogResult.OK)
                {
                    //add this user to the database
                    ServiceUser new_serviceuser = new ServiceUser()
                    {
                        firstname           = frm.Firstname,
                        surname             = frm.Surname,
                        dob                 = frm.DOB,
                        ServiceBegins       = frm.PeriodStartDate,
                        PeriodWeekCount     = frm.PeriodWeekCount,
                        contactno_primary   = frm.ContactNoPrimary,
                        contactno_secondary = frm.ContactNoSecondary,
                        postcode            = frm.LongLat.pCode,
                        PNumber             = frm.PNumber,
                        idGender            = frm.Gender,
                        LongLatCoords       = frm.LongLat,
                        medicalinfo         = frm.MedicalInfo,
                        notes               = frm.Notes,
                        isNotesImportant    = frm.ImportantNotes,
                        add1                = frm.Add1,
                        add2                = frm.Add2
                    };

                    //clear the service users key workers
                    new_serviceuser.KeyWorkers.Clear();

                    // add the new keyworkers
                    new_serviceuser.KeyWorkers.AddRange(frm.KeyWorkers);

                    //add service user to key workers
                    foreach (Worker worker in frm.KeyWorkers)
                    {
                        worker.KeyServiceUsers.Add(new_serviceuser);

                        //refresh the old key service users here so the change of service user on teh worker isnt
                        //seen as a change
                        worker.OldKeyServiceUsers.Clear();
                        worker.OldKeyServiceUsers.AddRange(worker.KeyServiceUsers);
                    }

                    //attempt to save
                    Cursor = Cursors.WaitCursor;
                    try
                    {
                        new_serviceuser.Save();

                        //add to the ServiceUserManager
                        ServiceUserManager.Instance.ServiceUsers.Add(new_serviceuser);
                    }
                    catch (Exception ex)
                    {
                        Cura.Common.Common.LogError("Error Occured While Trying To Save This New Service User", ex);
                    }

                    if (new_serviceuser.KeyWorkers.Count() > 0)
                    {
                        WorkerManager.Instance.RefreshLists(false, false, false);
                    }
                }

                frm.Dispose();
            }
            catch (Exception ex)
            {
                Cura.Common.Common.LogError("Error Creating New Service User", ex);
            }
            Cursor = Cursors.Default;
        }
Exemple #2
0
        private void editToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (SelectedItem == null || !_allowOpenServiceUser)
            {
                return;
            }

            try
            {
                Cursor = Cursors.WaitCursor;

                ServiceUser serviceuser = SelectedItem;

                ServiceUserFrm frm = new ServiceUserFrm()
                {
                    ID                 = serviceuser.id,
                    PNumber            = serviceuser.PNumber,
                    Firstname          = serviceuser.firstname,
                    Surname            = serviceuser.surname,
                    ContactNoPrimary   = serviceuser.contactno_primary,
                    ContactNoSecondary = serviceuser.contactno_secondary,
                    Title              = "Edit Service User",
                    Gender             = serviceuser.idGender,
                    MedicalInfo        = serviceuser.medicalinfo,
                    Notes              = serviceuser.notes,
                    PeriodStartDate    = serviceuser.ServiceBegins,
                    PeriodWeekCount    = serviceuser.PeriodWeekCount,
                    ImportantNotes     = serviceuser.isNotesImportant,
                    DOB                = serviceuser.dob,
                    Add1               = serviceuser.add1,
                    Add2               = serviceuser.add2,
                };

                frm.CallHistory = serviceuser.CallHistory;

                frm.SetLongLat(serviceuser.LongLatCoords);

                frm.Workers = WorkerManager.Instance.ActiveWorkers;
                frm.KeyWorkers.AddRange(serviceuser.KeyWorkers);

                Cursor = Cursors.Default;

                if (frm.ShowDialog() == DialogResult.OK)
                {
                    //add this user to the database

                    serviceuser.firstname           = frm.Firstname;
                    serviceuser.surname             = frm.Surname;
                    serviceuser.dob                 = frm.DOB;
                    serviceuser.contactno_primary   = frm.ContactNoPrimary;
                    serviceuser.contactno_secondary = frm.ContactNoSecondary;
                    serviceuser.postcode            = frm.LongLat.pCode;
                    serviceuser.add1                = frm.Add1;
                    serviceuser.add2                = frm.Add2;
                    serviceuser.idGender            = frm.Gender;
                    serviceuser.LongLatCoords       = frm.LongLat;
                    serviceuser.medicalinfo         = frm.MedicalInfo;
                    serviceuser.notes               = frm.Notes;
                    serviceuser.ServiceBegins       = frm.PeriodStartDate;
                    serviceuser.PeriodWeekCount     = frm.PeriodWeekCount;
                    serviceuser.isNotesImportant    = frm.ImportantNotes;
                    serviceuser.notes               = frm.Notes;

                    //clear this service user from all its key workers
                    foreach (Worker worker in serviceuser.KeyWorkers)
                    {
                        worker.KeyServiceUsers.Remove(serviceuser);
                    }

                    //clear the service users key workers
                    serviceuser.KeyWorkers.Clear();

                    // add the new keyworkers
                    serviceuser.KeyWorkers.AddRange(frm.KeyWorkers);

                    //add service user to key workers
                    foreach (Worker worker in frm.KeyWorkers)
                    {
                        worker.KeyServiceUsers.Add(serviceuser);

                        //refresh the old key service users here so the change of service user on teh worker isnt
                        //seen as a change
                        worker.OldKeyServiceUsers.Clear();
                        worker.OldKeyServiceUsers.AddRange(worker.KeyServiceUsers);
                    }

                    //attempt to save
                    Cursor = Cursors.WaitCursor;
                    try
                    {
                        serviceuser.MarkForSave = true;
                        serviceuser.Save();
                    }
                    catch (Exception ex)
                    {
                        Cura.Common.Common.LogError("Error Occured While Trying To Save This Service User", ex);
                    }

                    //rebuild the list
                    ServiceUserManager.Instance.RefreshControls(false, false, false);
                    WorkerManager.Instance.RefreshControls(false, false, false);
                }

                frm.Dispose();
            }
            catch (Exception ex)
            {
                Cura.Common.Common.LogError("Error Editing Service User", ex);
            }

            Cursor = Cursors.Default;
        }