Пример #1
0
        public static bool EditableWorkflow(int workflowId)
        {
            List <Project> projects = ProjectUtil.GetWorkflowProjects(workflowId);

            if (projects.Count == 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #2
0
        public static List <Form> GetProjectForms(int projectId)
        {
            List <Form> formList = new List <Form>();
            Project     p        = ProjectUtil.GetProject(projectId);
            List <WorkflowComponent> workflowComponents = WorkflowComponentUtil.GetWorkflowComponents(p.WorkflowId);

            foreach (WorkflowComponent wc in workflowComponents)
            {
                if (wc.FormID != -1)
                {
                    formList.Add(GetProjectFormByTemplate(wc.FormID, projectId));
                }
            }
            return(formList);
        }
Пример #3
0
        public static Form SubmitForm(int formId, string formName, string formData)
        {
            string defaultApproved = "0";
            string defaultDenied   = "0";
            Form   f  = GetForm(formId);
            Form   ft = GetFormTemplate(f.FormTemplateId);

            string[] approvalIDs = new string[0];
            if (ft.ApproverIDs.Length > 0)
            {
                approvalIDs = ft.ApproverIDs.Split(',');
            }

            if (approvalIDs.Length > 0)
            {
                int i = 0;
                foreach (string roleID in approvalIDs)
                {
                    if (i != 0)
                    {
                        defaultApproved += ",0";
                        defaultDenied   += ",0";
                    }
                    i++;
                }
            }

            f.FormName = formName;
            f.FormData = formData;
            MySqlCommand cmd = new MySqlCommand("UPDATE Forms SET FormName=@formName, FormData=@formData, Submission=1, Approved=@approved, Denied=@denied, DenialReason=\"\" WHERE FormID=@formId");

            cmd.Parameters.AddWithValue("@formName", formName);
            cmd.Parameters.AddWithValue("@formData", formData);
            cmd.Parameters.AddWithValue("@formId", formId);
            cmd.Parameters.AddWithValue("@denied", defaultDenied);
            cmd.Parameters.AddWithValue("@approved", defaultApproved);
            DBConn conn = new DBConn();

            conn.ExecuteInsertCommand(cmd);
            conn.CloseConnection();
            Project p = ProjectUtil.GetProject(f.ProjectId);

            FeedUtil.CreateProjectFormFeedItem(p.Name + " has form " + formName + " ready for your approval", p.CoachId, p.ProjectId, formId);
            return(f);
        }
Пример #4
0
        public static List <WorkflowModel> GetCompanyWorkflows(int companyId)
        {
            List <Project>       projects     = ProjectUtil.GetCompanyProjects(companyId);
            List <WorkflowModel> workflowList = new List <WorkflowModel>();

            foreach (Project proj in projects)
            {
                string query = "SELECT WorkflowID, WorkflowName from Workflows WHERE WorkflowID = @workflowId";

                MySqlCommand cmd = new MySqlCommand(query);
                cmd.Parameters.AddWithValue("@workflowId", proj.WorkflowId);
                DBConn          conn = new DBConn();
                MySqlDataReader dr   = conn.ExecuteSelectCommand(cmd);
                while (dr.Read())
                {
                    WorkflowModel w = new WorkflowModel((int)dr["WorkflowID"], (string)dr["WorkflowName"]);
                    workflowList.Add(w);
                }
                conn.CloseConnection();
            }
            workflowList = workflowList.GroupBy(p => p.WorkflowId).Select(g => g.First()).ToList();
            return(workflowList);
        }
Пример #5
0
        public static bool DeleteWorkflow(int workflowId)
        {
            List <Project> projects = ProjectUtil.GetWorkflowProjects(workflowId);

            if (projects.Count == 0)
            {
                List <WorkflowComponent> comps = WorkflowComponentUtil.GetWorkflowComponents(workflowId);
                foreach (WorkflowComponent item in comps)
                {
                    WorkflowComponentUtil.DeleteWorkflowComponent(item.WFComponentID);
                }
                string       query = "DELETE FROM Workflows WHERE WorkflowID=@workflowId";
                MySqlCommand cmd   = new MySqlCommand(query);
                cmd.Parameters.AddWithValue("@workflowId", workflowId);
                DBConn conn = new DBConn();
                conn.ExecuteInsertCommand(cmd);
                conn.CloseConnection();
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #6
0
        public static List <Form> GetCoachForms(int coachId)
        {
            List <Project> projects = ProjectUtil.GetCoachProjects(coachId);
            List <Form>    formList = new List <Form>();

            foreach (Project p in projects)
            {
                MySqlCommand cmd = new MySqlCommand("SELECT FormID, FormTemplateID, FormName, FormData, ProjectID, ApprovalRequiredID, ApprovalStatusID, Submission, Approved, Denied, DenialReason FROM Forms WHERE ProjectId = @projId");
                cmd.Parameters.AddWithValue("@projId", p.ProjectId);
                DBConn          conn = new DBConn();
                MySqlDataReader dr   = conn.ExecuteSelectCommand(cmd);
                try
                {
                    while (dr.Read())
                    {
                        Form f = new Form((int)dr["FormID"], (string)dr["FormName"], (string)dr["FormData"], p.ProjectId, (int)dr["Submission"], (string)dr["Approved"], (string)dr["Denied"], (string)dr["DenialReason"], (int)dr["FormTemplateID"]);
                        formList.Add(f);
                    }
                }
                catch (Exception e) { }
                conn.CloseConnection();
            }
            return(formList);
        }
Пример #7
0
        public static Form DenyForm(int formId, string denialReason, int roleId)
        {
            Form f            = GetForm(formId);
            Form ft           = GetFormTemplate(f.FormTemplateId);
            int  denialItemCt = -1;

            string[] approvalIDs = new string[0];
            if (ft.ApproverIDs.Length > 0)
            {
                approvalIDs = ft.ApproverIDs.Split(',');
            }

            if (approvalIDs.Length > 0)
            {
                int i = 0;
                foreach (string roleID in approvalIDs)
                {
                    int userRoleID = int.Parse(roleID);

                    //if they are one of the users who needs to approve the form
                    if (userRoleID == roleId)
                    {
                        denialItemCt = i;
                    }
                    i++;
                }
            }

            if (denialItemCt != -1)
            {
                string   newDenial     = "";
                string[] currentDenial = f.Denied.Split(',');
                if (currentDenial.Length > denialItemCt)
                {
                    int i = 0;
                    foreach (string approval in currentDenial)
                    {
                        if (i == denialItemCt)
                        {
                            newDenial += "1";
                        }
                        else
                        {
                            newDenial += currentDenial[i];
                        }

                        i++;

                        if (i != currentDenial.Length)
                        {
                            newDenial += ",";
                        }
                    }
                }

                MySqlCommand cmd = new MySqlCommand("UPDATE Forms SET Denied=@denied, DenialReason=@denialReason, Submission=0 WHERE FormID=@formId");
                cmd.Parameters.AddWithValue("@denialReason", denialReason);
                cmd.Parameters.AddWithValue("@formId", formId);
                cmd.Parameters.AddWithValue("@denied", newDenial);
                DBConn conn = new DBConn();
                conn.ExecuteInsertCommand(cmd);
                conn.CloseConnection();
                Project p = ProjectUtil.GetProject(f.ProjectId);

                //notify all clients of the approval
                List <User> clients = UserUtil.GetClients(p.CompanyId);
                foreach (User client in clients)
                {
                    FeedUtil.CreateProjectFormFeedItem(f.FormName + " was denied by " + UserUtil.GetCoachName(p.CoachId) + " for " + denialReason, client.UserId, p.ProjectId, formId);
                }
            }

            return(f);
        }