Exemple #1
0
 private void GetLocations(int departmentID)
 {
     try
     {
         var generalMgr = new GeneralManager();
         Locations = generalMgr.GetLocations(departmentID);
     }
     catch (Exception ex)
     {
         MessageBox.Show("Failed to retrieve Department Locations : " + ex.Message);
     }
 }
Exemple #2
0
        protected void SetupDataBindings()
        {
            //setup all bindings in the page
            var user        = LoggedInUser.GetUser();
            var department  = Task == null ? (LoggedInUser.IsUserLoggedIn ? user.Department.ID : 0) : Task.Department.ID;
            var generalMngr = new GeneralManager();

            //data binding
            selectDepartments.DataSource = SystemLists.General.Departments;
            selectLocations.DataSource   = generalMngr.GetLocations(department, Settings.GetCompanyName());
            selectTechnicians.DataSource =
                SystemLists.User.TranslatedTechnicians((string)GetGlobalResourceObject("NotSet", "0"));
            selectTaskState.DataSource =
                SystemLists.Tasks.GetTranslatedTaskStatuses(LanguageFiles.LoadLanguageFile("TaskStatus"));
            if (selectMachines.Visible)
            {
                var list = new ObservableCollection <Machine>();
                list.Add(new Machine(0)
                {
                    Description = (string)GetGlobalResourceObject("NotSet", "0")
                });
                foreach (var machine in SystemLists.Supplier.Machines)
                {
                    list.Add(machine);
                }
                selectMachines.DataSource = list;
            }

            //call databind on page, and all its controls
            DataBind();



            //selections
            //machine. basically, if a device is set we pass a tostring from the id, if a null was somewhere -> empty string which ends up doing nothing.
            selectMachines.SelectItem(Task.Device?.ID.ToString() ?? "");
            selectDepartments.SelectItem(department.ToString());

            selectLocations.SelectItem((Task.Location?.ID.ToString() ?? ""));
            selectTaskState.SelectItem(Task.StatusID > 0 ? Task.StatusID.ToString() : "");
            selectTechnicians.SelectItem(Task.Technician?.ID.ToString() ?? "0");
        }
Exemple #3
0
        public IHttpActionResult Get(int id)
        {
            if (Settings.RequireLogin() && !LoggedInUser.IsUserLoggedIn)
            {
                return(BadRequest("Invalid authorisation."));
            }

            var list = new List <Location>();

            try
            {
                var generalMngr = new GeneralManager();
                list = generalMngr.GetLocations(id, Settings.GetCompanyName())?.ToList() ?? new List <Location>();
                return(Ok(list.Select(x => new LocationModel(x)).ToList()));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
Exemple #4
0
        public static bool NewPropertyValue(string PropertyName, object value)
        {
            var type     = typeof(Task);
            var property = type.GetProperty(PropertyName);

            //check if the property exists, if we are actuall working on a task and the task is not readonly
            if (property == null || Task == null || ReadOnly)
            {
                return(false);
            }

            var changed = false;

            //see which property we are changing, verify value and set value as changed and found if its all ok
            switch (PropertyName)
            {
            case nameof(Task.Photos):
                var data = value as string;

                if (data == null)
                {
                    break;
                }

                Photo photo;
                if (Task.ID > 0)
                {
                    photo = new Photo(0,
                                      string.Format("Task_{0}_Photo_{1}", Task.ID, DateTime.Now.ToString("yyyyMMdd_HH_mm_ss")));
                }
                else
                {
                    photo = new Photo(0, string.Empty);
                }
                photo.PhotoSource = data;
                Task.Photos.Add(photo);
                changed = true;
                break;

            case nameof(Task.Notes):
                var descr = value as string;

                if (string.IsNullOrWhiteSpace(descr) || Regex.IsMatch(descr, @"^[A-Za-z0-9?!,.:; ]+$") == false)
                {
                    break;
                }

                var note = new Note(descr, DateTime.Now);
                Task.AddNote(note);
                changed = true;
                break;

            case nameof(Task.Location):
                try
                {
                    var locID = int.Parse(value as string);
                    Task.Location = new GeneralManager().GetLocation(locID);
                    changed       = (Task.Location.ID != OriginalTask.Location.ID);
                }
                catch
                {
                    changed = false;
                }

                break;

            case nameof(Task.StatusID):
                try
                {
                    var statusID = int.Parse(value as string);
                    Task.StatusID = statusID;
                    changed       = Task.StatusID != OriginalTask.StatusID;

                    var statusChanged = Task.StatusID != OriginalTask.StatusID;
                }
                catch
                {
                    changed = false;
                }
                break;

            case nameof(Task.Technician):
                try
                {
                    var userID = int.Parse(value as string);
                    Task.Technician = (User)SystemLists.User.Technicians.Where(t => t.ID == userID).FirstOrDefault();
                    changed         = Task.TechnicianID != OriginalTask.TechnicianID;

                    var statusChanged = Task.StatusID != OriginalTask.StatusID;
                }
                catch
                {
                    changed = false;
                }
                break;

            case nameof(Task.Device):
                try
                {
                    var machineID = int.Parse(value as string);
                    Task.Device = new SupplierManager().GetMachine(machineID);
                    changed     = Task.Device?.ID != OriginalTask.Device?.ID;
                }
                catch
                {
                    changed = false;
                }
                break;

            case "DepartmentID":
                var newDep = 0;
                if (int.TryParse(value as string, out newDep))
                {
                    //we have to set the department! so we get the new department, get the list of locations of said department, check the locationID's on which to set,
                    //set the changed flag in the task and then parse the DepartmentID like the rest
                    Location newloc;
                    var      generalMngr = new GeneralManager();
                    var      list        = generalMngr.GetLocations(newDep, Settings.GetCompanyName());

                    if (newDep == OriginalTask.DepartmentID)
                    {
                        newloc = OriginalTask.Location;
                    }
                    else
                    {
                        newloc = list.First();
                    }

                    Task.Location = newloc;

                    var locationChanged = (Task.Location?.ID ?? 0) != (OriginalTask.Location?.ID ?? 0);
                }
                goto case "Generic";

            case "Reporter":
                var text = value as string;

                if (string.IsNullOrWhiteSpace(text) || Regex.IsMatch(text, @"^[A-Za-z0-9 ]+$") == false)
                {
                    break;
                }
                goto case "Generic";

            case "Description":
                var desc = value as string;

                if (string.IsNullOrWhiteSpace(desc) ||
                    Regex.IsMatch(desc, @"^[A-Za-z0-9?!.,:; ]+$") == false)
                {
                    break;
                }
                goto case "Generic";

            case "IsUrguent":
            case "Generic":    //Generic is kinda our "default push change" case :P
                //Generic awesomeness!!
                //basically, we take the value, try and convert it to the needed type, and assign the value. if the conversion fails it means we didn't get the right type anyway, so no change
                try
                {
                    var variableType = property.PropertyType;
                    var valueType    = value.GetType();
                    var newValue     = Convert.ChangeType(value, variableType);
                    if (newValue != property.GetValue(Task, null))
                    {
                        changed = true;
                    }
                    property.SetValue(Task, newValue);
                }
                catch
                {
                    changed = false;
                }

                break;

            default:
                break;
            }

            return(changed);
        }