예제 #1
0
        private void editToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (SelectedItem == null || !_allowOpenWorker)
            {
                return;
            }

            try
            {
                Cursor = Cursors.WaitCursor;

                Worker worker = SelectedItem;

                WorkerFrm frm = new WorkerFrm()
                {
                    ID                 = worker.id,
                    Firstname          = worker.firstname,
                    Surname            = worker.surname,
                    ContactNoPrimary   = worker.contactno_primary,
                    ContactNoSecondary = worker.contactno_secondary,
                    Add1               = worker.add1,
                    Add2               = worker.add2,
                    IsDriver           = worker.isDriver,
                    Title              = "Edit Care Worker",
                    ENumber            = worker.ENumber,

                    Notes = worker.notes
                };

                frm.CallHistory = worker.CallHistory;

                frm.SetWorkingHours(worker.WorkingHours);
                frm.SetDaysOff(worker.WorkingHours.daysOff);

                frm.SetLongLat(worker.LongLatCoords);

                frm.ServiceUsers = ServiceUserManager.Instance.ServiceUsers;
                frm.KeyServiceUsers.AddRange(worker.KeyServiceUsers);

                frm.Workers = WorkerManager.Instance.Workers.Where(w => w != worker).ToList();

                Cursor = Cursors.Default;

                if (frm.ShowDialog() == DialogResult.OK)
                {
                    //add this user to the database
                    worker.firstname           = frm.Firstname;
                    worker.surname             = frm.Surname;
                    worker.postcode            = frm.LongLat.pCode;
                    worker.add1                = frm.Add1;
                    worker.add2                = frm.Add2;
                    worker.contactno_primary   = frm.ContactNoPrimary;
                    worker.contactno_secondary = frm.ContactNoSecondary;
                    worker.isDriver            = frm.IsDriver;
                    worker.LongLatCoords       = frm.LongLat;

                    worker.WorkingHours.Clear();
                    worker.WorkingHours.AddRange(frm.Availabilities);

                    worker.WorkingHours.daysOff.Clear();
                    worker.WorkingHours.daysOff.AddRange(frm.Availabilities.daysOff);

                    worker.notes = frm.Notes;

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

                    ////clear the service users key workers
                    worker.KeyServiceUsers.Clear();

                    //// add the new keyworkers
                    worker.KeyServiceUsers.AddRange(frm.KeyServiceUsers);

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

                        serviceuser.OldKeyWorkers.Clear();
                        serviceuser.OldKeyWorkers.AddRange(serviceuser.KeyWorkers);
                    }

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

                    WorkerManager.Instance.RefreshControls(false, false, false);
                }

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

            Cursor = Cursors.Default;
        }
예제 #2
0
        /// <summary>
        /// create a new worker!
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void newworkerbtn_Click_1(object sender, EventArgs e)
        {
            if (Settings.IsTrial && WorkerManager.Instance.Workers.Count >= 5)
            {
                MessageBox.Show("You can only create a maximum of 5 workers while using a trial version of this product.", "Trial", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            try
            {
                WorkerFrm frm = new WorkerFrm()
                {
                    Title = "Create Care Worker"
                };

                frm.Workers      = WorkerManager.Instance.Workers;
                frm.ServiceUsers = ServiceUserManager.Instance.ServiceUsers;

                if (frm.ShowDialog() == DialogResult.OK)
                {
                    //add this user to the database
                    Worker new_worker = new Worker()
                    {
                        firstname           = frm.Firstname,
                        surname             = frm.Surname,
                        add1                = frm.Add1,
                        add2                = frm.Add2,
                        contactno_primary   = frm.ContactNoPrimary,
                        contactno_secondary = frm.ContactNoSecondary,
                        isDriver            = frm.IsDriver,
                        ENumber             = frm.ENumber,
                        notes               = frm.Notes
                    };



                    new_worker.LongLatCoords = frm.LongLat;
                    new_worker.postcode      = frm.LongLat.pCode;

                    new_worker.WorkingHours.Clear();
                    new_worker.WorkingHours.AddRange(frm.Availabilities);

                    new_worker.WorkingHours.daysOff.Clear();
                    new_worker.WorkingHours.daysOff.AddRange(frm.Availabilities.daysOff);

                    ////clear the service users key workers
                    new_worker.KeyServiceUsers.Clear();

                    //// add the new keyworkers
                    new_worker.KeyServiceUsers.AddRange(frm.KeyServiceUsers);

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

                        serviceuser.OldKeyWorkers.Clear();
                        serviceuser.OldKeyWorkers.AddRange(serviceuser.KeyWorkers);
                    }


                    //attempt to save
                    Cursor = Cursors.WaitCursor;
                    try
                    {
                        //save the worker
                        new_worker.Save();

                        //add to the worker manager if it saved successfully
                        WorkerManager.Instance.Workers.Add(new_worker);
                    }
                    catch (Exception ex)
                    {
                        Cura.Common.Common.LogError("Error Occured While Trying To Save This New Worker", ex);
                    }
                    Cursor = Cursors.Default;
                }

                frm.Dispose();
            }
            catch (Exception ex)
            {
                Cura.Common.Common.LogError("Error Creating New Worker", ex);
            }

            Cursor = Cursors.Default;
        }