Esempio n. 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (LoggedInUser.GetUser() != null)
            {
                Response.Redirect("Index");
            }

            if (IsPostBack)
            {
                return;
            }

            var stringID = Request.Params["ID"];

            if (string.IsNullOrEmpty(stringID))
            {
                Response.Redirect("Login");
            }

            var lists = new UserManager().GetUsers(null, null, $"{nameof(TechnicalServiceSystem.Entities.Users.User.UserName)} ASC");

            userList.DataSource = lists;
            userList.DataBind();

            userList.SelectItem(stringID);
        }
Esempio n. 2
0
        protected void Setup_UserContent()
        {
            User user = null;

            if (LoggedInUser.IsUserLoggedIn)
            {
                user = LoggedInUser.GetUser();
            }

            //setup user related stuff!
            if (user != null)
            {
                lblUserName.Text = "< " + user.UserName + " >";
                var path = user.Photo?.FileName;
                if (string.IsNullOrWhiteSpace(path))
                {
                    path = "./system/DefaultUser.jpg";
                }
                userImage.ImageUrl     = path;
                LoginMenu.Text         = "Logout";
                ProfileMenu.Visible    = true;
                LoginSeperator.Visible = true;
            }
            else
            {
                //set up the default stuff
                lblUserName.Text       = string.Empty;
                userImage.ImageUrl     = "./system/DefaultUser.jpg";
                LoginMenu.Text         = "Login";
                ProfileMenu.Visible    = false;
                LoginSeperator.Visible = false;
            }
        }
Esempio n. 3
0
        protected void LoadTask()
        {
            var TaskID = 0;

            if (int.TryParse(Request.Params["TaskID"], out TaskID) && TaskID > 0)
            {
                var taskMngr = new TaskManager();
                OriginalTask = taskMngr.GetTasks(Settings.GetCompanyName(), TaskID);
                Task         = OriginalTask.Clone();
            }
            else
            {
                TaskID = 0;
                Task   = null;
            }

            //if the task is null or 0, we are making a new task
            if (Task == null || TaskID == 0)
            {
                User user = null;
                if (LoggedInUser.IsUserLoggedIn)
                {
                    user = LoggedInUser.GetUser();
                }

                OriginalTask = new Task(0)
                {
                    Description    = "",
                    IsUrguent      = false,
                    TypeID         = 0,
                    ReporterUser   = null,
                    Reporter       = "",
                    Location       = null,
                    CreationDate   = DateTime.Now,
                    LastModifiedOn = DateTime.Now
                };
                Task = OriginalTask.Clone();
                var department = user != null
                    ? SystemLists.General.Departments.Where(d => d.ID == user.Department.ID).First()
                    : SystemLists.General.Departments.First();

                new GeneralManager().GetDepartment(department);
                Task.Location = department.Locations.OrderBy(l => l.Description).First();
                Task.Reporter = user != null ? user.UserName : "";
                TaskID        = 0;
            }
        }
Esempio n. 4
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");
        }
Esempio n. 5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Settings.RequireLogin() && LoggedInUser.IsUserLoggedIn == false)
            {
                Response.Redirect("Login.aspx");
            }

            if (LoggedInUser.IsUserLoggedIn == false || RoleManager.UserHasPermission(LoggedInUser.GetUser(), RolesPermissions.ManageUsers) == false)
            {
                Response.Redirect("Index.aspx");
            }

            if (IsPostBack)
            {
                return;
            }

            Page_LoadUser();
            Page_Setup();
            Page_Fill();
        }
Esempio n. 6
0
        protected void SetupPage()
        {
            //setup the page in general
            if (Task.ID > 0)
            {
                //editting a task!
                txtReporter.Disabled = true;

                var userHash = LoggedInUser.GetUserHash();
                var taskMngr = new TaskManager();

                //check if its editable at all. if not, disable and grey out a few shits
                if (!taskMngr.TaskEditable(Task.ID, userHash) || !taskMngr.SetTaskOpened(Task.ID, userHash))
                {
                    ReadOnly                   = true;
                    machineRow.Visible         = false;
                    selectTechnicians.Disabled = true;
                    selectTechnicians.Style.Add("background-color", "#EBEBE4");
                    selectDepartments.Disabled = true;
                    selectDepartments.Style.Add("background-color", "#EBEBE4");
                    selectLocations.Disabled = true;
                    selectLocations.Style.Add("background-color", "#EBEBE4");
                    txtDescription.Disabled = true;
                    NoteBox.Disabled        = true;
                    selectMachines.Disabled = true;
                    selectMachines.Style.Add("background-color", "#EBEBE4");
                    selectTaskState.Disabled = true;
                    selectTaskState.Style.Add("background-color", "#EBEBE4");
                    chkUrguent.Enabled      = false;
                    imagesList.Disabled     = true;
                    AddPhotoBtn.Disabled    = true;
                    AddPhotoInput.Disabled  = true;
                    AddNotesButton.Disabled = true;

                    /* Add a warning/alert to the page saying we can't open the task */
                    JavascriptAlert.Show(ReadOnlyMsg);
                    return;
                }
            }

            ReadOnly = false;

            //check user permissions
            if (LoggedInUser.IsUserLoggedIn)
            {
                txtReporter.Disabled = true;

                var roles = RoleManager.GetUserPermissions(LoggedInUser.GetUser());

                if (!roles.Any(x => x == RolesPermissions.ManageMachines) &&
                    !roles.Any(x => x == RolesPermissions.Technician))
                {
                    machineRow.Visible = false;
                }

                if (!roles.Any(x => x == RolesPermissions.ManageTasks) &&
                    !roles.Any(x => x == RolesPermissions.Technician))
                {
                    selectTaskState.Disabled = true;
                    selectTaskState.Style.Add("background-color", "#EBEBE4");
                }
            }
            else
            {
                selectTechnicians.Disabled = true;
                selectTechnicians.Style.Add("background-color", "#EBEBE4");
                machineRow.Visible       = false;
                selectTaskState.Disabled = true;
                selectTaskState.Style.Add("background-color", "#EBEBE4");
            }

            //fill the images in the ul
            foreach (var item in Task.Photos)
            {
                var li = new HtmlGenericControl("li");
                li.Attributes.Add("style", "display:inline;max-height:inherit;");

                var ancor = new HtmlGenericControl("a");
                ancor.Attributes.Add("href", item.FileName);
                ancor.Attributes.Add("data-lightbox", "TaskImages");
                ancor.Attributes.Add("style",
                                     "height:inherit;max-height:inherit;min-height:inherit;width:auto;margin-bottom:0;padding-right:5px;");

                var image = new HtmlGenericControl("img");
                image.Attributes.Add("src", item.FileName);
                image.Attributes.Add("style",
                                     "height:inherit;max-height:inherit;min-height:inherit;width:auto;margin-bottom:0;");

                ancor.Controls.Add(image);
                li.Controls.Add(ancor);
                imagesList.Controls.Add(li);
            }
        }
Esempio n. 7
0
        protected void Setup_Tabs()
        {
            //OK, HOW THIS WORKS.
            //We loop trough all roles. per function of the system the user has access to we add a number that is a bitwise new number ( 0,1,2,4,8,16,32,64,128,...)
            //after we've looped trough the roles, we do a bitwise or so we can easily tell if the user has access to a part of the system

            User user = null;

            if (LoggedInUser.IsUserLoggedIn)
            {
                user = LoggedInUser.GetUser();
            }

            var roles = RoleManager.GetUserPermissions(user);

            //handle the tasks tab
            if (!roles.Any(x => x == RolesPermissions.Tasks))
            {
                TasksTab.Visible = false;
                Tasks.Visible    = false;
            }
            else
            {
                //link the departments drop down
                var list = SystemLists.General.Departments;

                var DepartmentsList = new ObservableCollection <Department>();
                DepartmentsList.Add(new Department(0)
                {
                    Description = LanguageFiles.GetLocalTranslation("AllDepartments", "All")
                });
                foreach (var item in SystemLists.General.Departments)
                {
                    DepartmentsList.Add(item);
                }

                DropDownSorting.DataSource = DepartmentsList;
                DropDownSorting.DataBind();

                if (LoggedInUser.IsUserLoggedIn && (!roles.Any(x => x == RolesPermissions.Technician)))
                {
                    DropDownSorting.SelectedIndex =
                        DepartmentsList.ToList().FindIndex(x => x.ID == LoggedInUser.GetUser().Department.ID);
                }
                else
                {
                    DropDownSorting.SelectedIndex = 0;
                }


                //set the parameters for the datasource
                string departmentID = Request.QueryString["depID"];
                var    searchText   = Request.QueryString["Search"];

                var departmentField = TaskSource.SelectParameters["DepartmentID"];
                var searchField     = TaskSource.SelectParameters["SearchText"];
                if (LoggedInUser.IsUserLoggedIn)
                {
                    if (
                        !RoleManager.UserHasPermission(LoggedInUser.GetUser(), RolesPermissions.ManageTasks) &&
                        (
                            (String.IsNullOrWhiteSpace(departmentID) && String.IsNullOrWhiteSpace(searchText)) ||
                            (LoggedInUser.GetUser().Department.ID.ToString() == departmentID)
                        ))
                    {
                        // logged in + either nothing was given or the user's department was chosen -> show department + user's tasks
                        departmentField.DefaultValue = LoggedInUser.GetUser().Department.ID.ToString();
                        searchText = LoggedInUser.GetUser().UserName;
                    }
                    else if (!String.IsNullOrWhiteSpace(departmentID))
                    {
                        //department was set.
                        departmentField.DefaultValue = departmentID;
                    }

                    if (!String.IsNullOrWhiteSpace(searchText))
                    {
                        //search text was given.
                        searchField.DefaultValue = searchText;
                    }
                }
                else
                {
                    if (!String.IsNullOrWhiteSpace(departmentID))
                    {
                        departmentField.DefaultValue = departmentID;
                    }

                    if (!String.IsNullOrWhiteSpace(searchText))
                    {
                        searchField.DefaultValue = searchText;
                    }
                }

                //set the department parameter
                TaskSource.SelectParameters["DepartmentID"] = departmentField;
                TaskSource.SelectParameters["SearchText"]   = searchField;

                //set datasource and bind/retrieve data (databind also executes all inline code to bind to them)
                TaskSource.DataBind();
                TaskGrid.DataSourceID = nameof(TaskSource);
                TaskGrid.DataBind();
            }

            //handle machines tab
            //if (!roles.Any(x => x == RolesPermissions.ManageMachines))
            {
                //no permissions!
                MachinesTab.Visible = false;
                //Machines.Visible = false;
            }

            /*else
             * {
             *  MachinesTab.Visible = true;
             *  //Machines.Visible = true;
             * }*/

            //permissions to the Suppliers tab!

            /*if (!roles.Any(x => x == RolesPermissions.ManageSuppliers) &&
             *  !roles.Any(x => x == RolesPermissions.ViewSuppliers))*/
            {
                SuppliersTab.Visible = false;
                //Suppliers.Visible = false;
            }

            /*else
             * {
             *  SuppliersTab.Visible = true;
             *  Suppliers.Visible = true;
             * }*/


            //permissions for the Users tab!
            if (!roles.Any(x => x == RolesPermissions.ManageUsers))
            {
                UsersTab.Visible = false;
                Users.Visible    = false;
            }
            else
            {
                UsersTab.Visible = true;
                Users.Visible    = true;

                var RolesList = new ObservableCollection <RoleModel>();
                var roleList  = LanguageFiles.LoadLanguageFile("Roles");

                for (int i = 0; i < roleList.Length; i++)
                {
                    RolesList.Add(RoleModel.CreateModel((Role)i, roleList[i]));
                }

                //bind User dropdown of roles
                selectUserType.DataSource = RolesList;
                selectUserType.DataBind();

                //set the parameters for the datasource
                string role       = Request.QueryString["UserRole"];
                var    searchText = Request.QueryString["SearchUser"];

                if (!String.IsNullOrWhiteSpace(role) && role != nameof(Role.AllRoles))
                {
                    var RoleField = UserSource.SelectParameters["role"];
                    RoleField.DefaultValue = role;
                    UserSource.SelectParameters["role"] = RoleField;
                }

                if (!String.IsNullOrWhiteSpace(searchText))
                {
                    var searchField = UserSource.SelectParameters["contains"];
                    searchField.DefaultValue = searchText;
                    UserSource.SelectParameters["contains"] = searchField;
                }

                UserSource.DataBind();
                UserGrid.DataSourceID = nameof(UserSource);
                UserGrid.DataBind();
            }

            //set the last known open tab
            if (!String.IsNullOrWhiteSpace(ActiveTab))
            {
                hidTABControl.Value = ActiveTab;
            }
        }