示例#1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            ClientScript.GetPostBackEventReference(this, string.Empty);
            //validates that the user is logged in
            if (Session["User"] != null)
            {
                User user = (User)Session["User"];
                userLbl.Text = user.FullName;

                if (user.RoleId == 1)
                {
                    CreateClientFormList(user.CompanyId);
                    CreateNewFormBtn.Visible = false;
                }
                else if (user.RoleId == 2)
                {
                    CreateFormList(user.UserId);
                    CreateNewFormBtn.Visible = false;
                }
                else if (user.RoleId == 4)
                {
                    AdminBtn.Visible = true;
                }
                if (user.RoleId > 2)
                {
                    tabMenu.Visible     = true;
                    FormTab.Visible     = true;
                    TemplateTab.Visible = true;

                    //creates the template list and the full list of forms
                    if (Request.QueryString["templates"] != null)
                    {
                        CreateAdminFormList();
                        FormTab.CssClass     = "item";
                        TemplateTab.CssClass = "item active";
                    }
                    else
                    {
                        CreateFullFormList();
                        FormTab.CssClass     = "item active";
                        TemplateTab.CssClass = "item";
                    }
                }

                //loads the selected form if there is one
                if (Request.QueryString["fid"] != null)
                {
                    int  formId = int.Parse(Request.QueryString["fid"]);
                    Form f      = FormUtil.GetFormTemplate(formId);
                    FormNameLbl.Text = " <a href='Forms.aspx?templates=1'>Forms</a> > " + f.FormName;

                    //admin and trying to del
                    if (Request.QueryString["del"] != null && user.RoleId > 1)
                    {
                        if (FormUtil.DeleteForm(f.FormId))
                        {
                            Log.Info(user.Identity + " deleted a form template " + f.FormName);
                            ReloadSection();
                        }
                        else
                        {
                            FormError.Visible = true;
                            FormError.Text    = "Unable to delete Form " + f.FormName;
                        }
                    }
                    else
                    {
                        //if they are trying to edit and they are admin, show form builder
                        if (Request.QueryString["edit"] != null && user.RoleId > 1)
                        {
                            ShowFormBuilder(f, user.RoleId);
                        }
                        //otherwise just show the form viewer
                        else
                        {
                            //disable the save/submit buttons for form templates
                            SubmitFormBtn.Visible = false;
                            SaveFormBtn.Visible   = false;
                            ShowFormViewer(f, user.RoleId);
                        }
                    }
                }
                //if theyre a client trying to fill out a form
                else if (Request.QueryString["pfid"] != null)
                {
                    int     formId = int.Parse(Request.QueryString["pfid"]);
                    Form    f      = FormUtil.GetForm(formId);
                    Project p      = ProjectUtil.GetProject(f.ProjectId);
                    FormNameLbl.Text = "<a href='Forms.aspx'>Forms</a> > <a href='Projects.aspx?pid=" + f.ProjectId + "'>" + p.Name + "</a> > " + f.FormName;
                    ShowFormViewer(f, user.RoleId);
                }
                //if theyre an admin and trying to make a new form
                else if (Request.QueryString["edit"] != null && Request.QueryString["fid"] == null && user.RoleId > 1)
                {
                    formListing.Visible = false;
                    formBuilder.Visible = true;
                }
            }
            else
            {
                Response.Redirect("Login.aspx");
            }
        }