private async Task <DialogTurnResult> SaveOrContinueStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationtoken)
        {
            var answer = stepContext.Result.ToString();

            if (answer == "yes")
            {
                return(await stepContext.ReplaceDialogAsync(nameof(MerakiDeviceBoMDialog)));
            }
            else
            {
                //save all state
                var Basket = await _botaccessors.QuoteBasket.GetAsync(stepContext.Context, () => new QuoteBasketModel(), cancellationtoken);

                await stepContext.Context.SendActivityAsync(MessageFactory.Text($"company is id {Basket.customer.COMPANY_ID} customername is {Basket.customer.NAME}"));

                var customercompany = CompanyUtil.GetCompanyById(Basket.customer.COMPANY_ID);

                //var dealid=DealsUtil.CreateDeal($"testdeal-{customercompany.NAME}", Basket.customer.COMPANY_ID, Basket.customer.COMPANY_ID, DEALENDPOINT);
                //await stepContext.Context.SendActivityAsync(MessageFactory.Text("the deal is " + dealid));
                //var quoteexpirationdate = DateTime.Today.AddDays(7);
                //var quoteid = DealsUtil.CreateQuote(Basket.customer.NAME, Basket.customer.LAST_NAME, customercompany.NAME,dealid,Basket.customer.EMAIL[0].VALUE,quoteexpirationdate.ToString(),TERMS,QUOTEENDPOINT);
                //Basket.clearProducts();
                //await stepContext.Context.SendActivityAsync($"Check your emails for the quote {quoteid} ");
                return(await stepContext.ReplaceDialogAsync(nameof(IntroDialog)));
            }
        }
Example #2
0
        //client submitting form
        protected void SubmitFormBtn_Click(object sender, EventArgs e)
        {
            SaveForm();
            FormResult.Visible = false;
            string formJson = formViewerData.Value.ToString();

            if (formJson.Length > 0 && formJson != "undefined")
            {
                //updating a form not, creating it
                if (Request.QueryString["pfid"] != null)
                {
                    int  formId = int.Parse(Request.QueryString["pfid"]);
                    Form f      = FormUtil.GetForm(formId);
                    FormUtil.SubmitForm(formId, f.FormName, formJson);
                    User user = (User)Session["User"];
                    Log.Info(user.Identity + " submitted " + CompanyUtil.GetCompanyName(user.CompanyId) + "'s form " + f.FormName + " with " + formJson);
                    FormResult.CssClass = "success";
                    FormResult.Text     = "Submitted form " + f.FormName;
                    Response.Redirect("Forms.aspx?pfid=" + formId);
                }
            }
            else
            {
                FormResult.CssClass = "error";
                FormResult.Text     = "Please fill out the form";
            }
            FormResult.Visible = true;
        }
Example #3
0
        protected void DenyFormBtn_Click(object sender, EventArgs e)
        {
            FormResult.Visible = false;
            //updating a form not, creating it
            if (Request.QueryString["pfid"] != null)
            {
                string  denyText = DenyReason.Text;
                int     formId   = int.Parse(Request.QueryString["pfid"]);
                Form    f        = FormUtil.GetForm(formId);
                Project p        = ProjectUtil.GetProject(f.ProjectId);

                User user = (User)Session["User"];
                FormUtil.DenyForm(formId, denyText, user.RoleId);
                FormResult.CssClass = "success";
                FormResult.Text     = "Denied form " + f.FormName;
                if (denyText.Length > 0)
                {
                    FormResult.Text += ": " + denyText;
                }
                else
                {
                    denyText = "None specified";
                }
                Log.Info(user.Identity + " denied " + CompanyUtil.GetCompanyName(p.CompanyId) + "'s form " + f.FormName + " - " + p.Name + " with reason: " + denyText);
                Response.Redirect("Forms.aspx?pfid=" + formId);
                FormResult.Visible = true;
            }
        }
Example #4
0
        private async Task <DialogTurnResult> JumpTopDeviceOptionsStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationtoken)
        {
            var customerdata = (CustomerModel)stepContext.Values[customerInfo];
            var company_name = "";

            if (stepContext.Result.ToString() != null)

            {
                company_name = stepContext.Result.ToString();
            }


            var companyID = CompanyUtil.SaveCompanyDetails(company_name);

            customerdata.COMPANY_ID = companyID;
            var customerID = CustomerUtil.saveCustomerInformation(customerdata.NAME, customerdata.LAST_NAME, customerdata.COMPANY_ID, customerdata.EMAIL[0].VALUE, customerdata.PHONE[0].VALUE);
            await stepContext.Context.SendActivityAsync(MessageFactory.Text($"The company id is {companyID} "));


            var cacheCustomerInfo = await _botaccessors.UserProfile.GetAsync(stepContext.Context, () => new CustomerModel());

            customerdata.ID = customerID;

            cacheCustomerInfo = customerdata;

            await _botaccessors.UserProfile.SetAsync(stepContext.Context, cacheCustomerInfo, cancellationtoken);

            await stepContext.Context.SendActivityAsync(MessageFactory.Text(customerdata.ToString()));


            return(await stepContext.ReplaceDialogAsync(nameof(MerakiDeviceBoMDialog), cacheCustomerInfo));
        }
Example #5
0
        private void SetupAdminPage()
        {
            RoleSelect.DataSource     = RoleUtil.GetRoles();
            RoleSelect.DataTextField  = "roleName";
            RoleSelect.DataValueField = "roleId";
            RoleSelect.DataBind();
            RoleSelect.SelectedIndex = 0;

            UserRole.DataSource     = RoleUtil.GetRoles();
            UserRole.DataTextField  = "roleName";
            UserRole.DataValueField = "roleId";
            UserRole.DataBind();

            CompanySelect.DataSource     = CompanyUtil.GetCompanies();
            CompanySelect.DataTextField  = "companyName";
            CompanySelect.DataValueField = "companyId";
            CompanySelect.DataBind();
            CompanySelect.SelectedIndex = 0;

            LockedAccountSelect.DataSource     = UserUtil.GetLockedUsers();
            LockedAccountSelect.DataTextField  = "Identity";
            LockedAccountSelect.DataValueField = "UserId";
            LockedAccountSelect.DataBind();
            LockedAccountSelect.SelectedIndex = 0;

            MakeUserTable();
            MakeCompanyTable();
        }
Example #6
0
        private async Task <DialogTurnResult> JumpTopDeviceOptionsStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationtoken)
        {
            var customerdata = (CustomerModel)stepContext.Values["customerinfo"];
            var company_name = "";

            if (stepContext.Result.ToString() != null)

            {
                company_name = stepContext.Result.ToString();
            }


            var companyID = CompanyUtil.SaveCompanyDetails(company_name);

            customerdata.COMPANY_ID = companyID;
            var customerID = CustomerUtil.saveCustomerInformation(customerdata.NAME, customerdata.LAST_NAME, customerdata.COMPANY_ID, customerdata.EMAIL[0].VALUE, customerdata.PHONE[0].VALUE);


            var Basket = await _botAccessors.QuoteBasket.GetAsync(stepContext.Context, () => new QuoteBasketModel());

            customerdata.ID = customerID;

            Basket.customer = customerdata;

            await _botAccessors.QuoteBasket.SetAsync(stepContext.Context, Basket, cancellationtoken);

            await stepContext.Context.SendActivityAsync(MessageFactory.Text(customerdata.ToString()));


            return(await stepContext.ReplaceDialogAsync("DeviceBOMDialog"));
        }
 public CompanySettingController()
 {
     CompanyId   = SessionUtil.GetCompanyID();
     result      = new Result();
     companyUtil = new CompanyUtil();
     stateUtil   = new StateUtil();
     countryUtil = new CountryUtil();
     packageUtil = new PackageUtil();
 }
Example #8
0
        protected void CoachDownloadBtn_Click(object sender, EventArgs e)
        {
            if (Request.QueryString["pfid"] != null)
            {
                int     formId = int.Parse(Request.QueryString["pfid"]);
                Form    f      = FormUtil.GetForm(formId);
                Project p      = ProjectUtil.GetProject(f.ProjectId);
                FormResult.CssClass = "success";
                FormResult.Text     = "Denied form " + f.FormName;

                User user = (User)Session["User"];
                Log.Info(user.Identity + " downloaded files from " + CompanyUtil.GetCompanyName(p.CompanyId) + "'s form " + f.FormName + " - " + p.Name);
                SendFile(f.FilePath);
                FormResult.Visible = true;
            }
        }
Example #9
0
        protected void MakeCompanyTable()
        {
            List <Company> companies = CompanyUtil.GetCompanies();

            CompanyTable.InnerHtml = "";
            var companyTable = "";

            companyTable += "<table class=\"ui orange table\"><thead><tr><th>Company Name</th></tr></thead>";
            companyTable += "<tbody>";
            foreach (Company company in companies)
            {
                if (company.CompanyId != -1 && company.CompanyId != -2)
                {
                    companyTable += "<tr><td>" + company.CompanyName + "</td></tr>";
                }
            }
            companyTable           += "</tbody></table>";
            CompanyTable.InnerHtml += companyTable;
        }
Example #10
0
        protected void ProjectView(Project p)
        {
            Company     c     = CompanyUtil.GetCompany(p.CompanyId);
            List <User> users = UserUtil.GetUsersByCompany(c.CompanyId);

            projectNode += "<h2><a href='Projects.aspx'>Projects</a> > " + p.Name + "</h2><div id=\"project-top-div\"><div class=\"project-info\"><div id=\"project-top\"><div class=\"project-item\">";
            projectNode += "<i class=\"huge circular building icon\"></i><h3>" + c.CompanyName + "</h3></div><div class=\"project-item\">";
            projectNode += "<i class=\"huge circular user icon\"></i><h3>" + UserUtil.GetCoach(p.CoachId).FullName + "</h3></div>";
            projectNode += "<div class=\"project-item\"><i class=\"huge circular money icon\"></i>";
            projectNode += "<h3>Funding Source</h3></div></div></div>";


            projectNode += "<div id=\"more-project-info\"><div class=\"ui accordion\"><div class=\"title\"><i class=\"dropdown icon\"></i>Company Contact";
            projectNode += "</div><div class=\"content\">";

            foreach (User i in users)
            {
                projectNode += "<p>" + i.FullName + " | " + i.Email + "</p><br>";
            }

            projectNode += "</div></div><div class=\"ui accordion\"><div class=\"title\"><i class=\"dropdown icon\"></i>Project Notes</div>";
            projectNode += "<div class=\"content\"><p class=\"transition hidden\">" + p.Notes + "</p></div></div></div></div></div>";
            projectNode += "<script>$('.ui.accordion').accordion();</script>";

            projectNode += "<div class=\"wrapper\"><ol class=\"ProgressBar\">";
            try
            {
                foreach (WorkflowComponent com in WorkflowComponentUtil.GetWorkflowComponents(p.WorkflowId))
                {
                    Form form = FormUtil.GetProjectFormByTemplate(com.FormID, p.ProjectId);
                    projectNode += "<li class=\"ProgressBar-step\" id=\"li" + com.WFComponentID + "\">";
                    projectNode += "<svg class=\"ProgressBar-icon\"></svg><a href='Forms.aspx?pfid=" + form.FormId + "'><span class=\"ProgressBar-stepLabel\">" + com.ComponentTitle + "</a></span>";
                    projectNode += "<div class=\"li-dropdown\" id=\"li-drop" + com.WFComponentID + "\">";
                    projectNode += "<div class=\"workflow-form\"><i class=\"big inbox icon\"></i><h3>" + form.FormName + "</h3></div></div></li>";
                }
            }
            catch (Exception e) { }
            projectNode += "</ol></div>";

            projectViewer.InnerHtml += projectNode;
        }
Example #11
0
        protected void MakeUserTable()
        {
            List <User> users = UserUtil.GetUsers();

            UserTable.InnerHtml = "";
            var userTable = "";

            userTable += "<table class=\"ui orange table\"><thead><tr><th>Name</th><th>Email</th><th>Company</th><th>Role</th></tr></thead>";
            userTable += "<tbody>";
            foreach (User user in users)
            {
                if (user.UserId != -1 && user.UserId != -2)
                {
                    Company company = CompanyUtil.GetCompany(user.CompanyId);
                    Role    role    = RoleUtil.GetRole(user.RoleId);
                    userTable += "<tr onclick=\"EditUser('" + user.FirstName + "','" + user.LastName + "','" + role.RoleName + "'," + role.RoleId + "," + user.UserId + ")\">" +
                                 "<td>" + user.FullName + "</td><td>" + user.Email + "</td><td>" + company.CompanyName + "</td><td>" + role.RoleName + "</td></tr>";
                }
            }
            userTable           += "</tbody></table>";
            UserTable.InnerHtml += userTable;
        }
Example #12
0
        private async Task <DialogTurnResult> SaveOrContinueStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationtoken)
        {
            var answer = stepContext.Result.ToString().ToLowerInvariant();

            if (answer == "yes")
            {
                return(await stepContext.ReplaceDialogAsync("DeviceBOMDialog"));
            }
            else if (answer == "no")
            {
                //save all state
                var Basket = await _botAccessors.QuoteBasket.GetAsync(stepContext.Context, () => new QuoteBasketModel(), cancellationtoken);


                var customercompany = CompanyUtil.GetCompanyById(Basket.customer.COMPANY_ID);

                var dealid = DealsUtil.CreateDeal($"Botdeal-{Basket.customer.NAME}", Basket.customer.COMPANY_ID, Basket.customer.COMPANY_ID, DEALENDPOINT);

                var quoteexpirationdate = DateTime.Today.AddDays(7);
                var quoteid             = DealsUtil.CreateQuote(Basket.customer.NAME, Basket.customer.LAST_NAME, customercompany, dealid, Basket.customer.EMAIL[0].VALUE, quoteexpirationdate.ToString(), TERMS + Basket.currentRate, QUOTEENDPOINT);
                var result = DealsUtil.AddProductsToQuote(quoteid, Basket.products, ADDPRODUCTSENDPOINT);
                if (result == "True")
                {
                    await stepContext.Context.SendActivityAsync(MessageFactory.Text("Your quote has been send"));
                }
                else
                {
                    await stepContext.Context.SendActivityAsync(MessageFactory.Text("Sorry, we could not process your request at the moment"));
                }

                Basket.clearProducts();

                return(await stepContext.ReplaceDialogAsync("IntroDialog"));
            }
            else
            {
                return(await stepContext.EndDialogAsync(cancellationtoken));
            }
        }
Example #13
0
        protected void CompanyBtn_Click(object sender, EventArgs e)
        {
            CompanyResult.Visible = false;
            CompanyError.Visible  = false;

            string companyName = Company.Text;

            Company.Text = "";

            //Validate that the logged in user has permissions to do this

            if (companyName.Length > 0)
            {
                Company company = CompanyUtil.CreateCompany(companyName);
                if (company != null)
                {
                    User user = (User)Session["User"];
                    if (user != null)
                    {
                        Log.Info(user.Identity + " created a new company " + companyName);
                    }
                    else
                    {
                        Log.Info("System created a new company " + companyName);
                    }
                    //display user created msg
                    CompanyResult.Visible = true;
                    CompanyResult.Text    = "Created company " + companyName;
                }
            }
            else
            {
                CompanyError.Visible = true;
                CompanyError.Text    = "Please enter a company name";
            }

            ClearFields();
        }
Example #14
0
        private void SaveForm()
        {
            FormResult.Visible = false;
            string formJson = formViewerData.Value.ToString();

            if (formJson.Length > 0 && formJson != "undefined")
            {
                //updating a form not, creating it
                if (Request.QueryString["pfid"] != null)
                {
                    int     formId = int.Parse(Request.QueryString["pfid"]);
                    Form    f      = FormUtil.GetForm(formId);
                    Project p      = ProjectUtil.GetProject(f.ProjectId);
                    FormUtil.UpdateForm(formId, f.FormName, formJson);
                    User user = (User)Session["User"];
                    Log.Info(user.Identity + " edited " + CompanyUtil.GetCompanyName(user.CompanyId) + " a form" + f.FormName + " from project " + p.Name + " with " + formJson);

                    if (fileInputName.Value.ToString().Length > 0)
                    {
                        string localName = fileUploadName.Value.ToString();
                        string fileType  = localName.Split('.')[1];
                        string path      = CompanyUtil.GetCompanyName(user.CompanyId) + "-" + p.Name + "-" + f.FormName + "." + fileType;
                        SaveFiles(path);
                        f = FormUtil.UpdateFormFile(f, path, localName);
                        Log.Info(user.Identity + " edited " + CompanyUtil.GetCompanyName(user.CompanyId) + " a form" + f.FormName + " from project " + p.Name + " added a file " + f.FilePath);
                    }
                    FormResult.CssClass = "success";
                    FormResult.Text     = "Updated form " + f.FormName;
                }
            }
            else
            {
                FormResult.CssClass = "error";
                FormResult.Text     = "Please fill out the form";
            }
            FormResult.Visible = true;
        }
Example #15
0
        protected void ProjectFileDownloader_Click(object sender, EventArgs e)
        {
            if (Request.QueryString["pid"] != null)
            {
                int                      projId             = int.Parse(Request.QueryString["pid"]);
                Project                  p                  = ProjectUtil.GetProject(projId);
                Company                  c                  = CompanyUtil.GetCompany(p.CompanyId);
                WorkflowModel            w                  = WorkflowUtil.GetWorkflow(p.WorkflowId);
                List <WorkflowComponent> workflowComponents = WorkflowComponentUtil.GetWorkflowComponents(w.WorkflowId);
                string                   zipPath            = String.Format("{0} - {1} - {2}.zip", w.WorkflowName, p.Name, CompanyUtil.GetCompanyName(p.CompanyId));
                //delete the zip if it exists
                if (File.Exists(zipPath))
                {
                    File.Delete(zipPath);
                }

                using (ZipArchive zip = ZipFile.Open(zipPath, ZipArchiveMode.Create))
                {
                    //for each form get the file
                    foreach (WorkflowComponent wc in workflowComponents)
                    {
                        Form f = FormUtil.GetProjectFormByTemplate(wc.FormID, projId);
                        if (f.FilePath.Length > 0)
                        {
                            string fileType = f.FilePath.Split('.')[1];
                            string fileName = string.Format("{0} {1} Attachment.{2}", CompanyUtil.GetCompanyName(p.CompanyId), f.FormName, fileType);
                            zip.CreateEntryFromFile(f.FilePath, fileName);
                        }
                        string pdfName = string.Format("{0} - {1} - {2}.pdf", w.WorkflowName, f.FormName, c.CompanyName);
                        string pdfPath = string.Format("./PDFGen/{0}", pdfName);
                        zip.CreateEntryFromFile(pdfPath, pdfName);
                    }
                }

                SendFile(zipPath);
            }
        }
Example #16
0
        //Register a new user in the system
        protected void RegisterBtn_Click(object sender, EventArgs e)
        {
            UserCreateResult.Visible = false;
            EmailError.Visible       = false;
            NameError.Visible        = false;
            PasswordError.Visible    = false;
            RoleCompanyError.Visible = false;

            string email             = Email.Text;
            string firstName         = FirstName.Text;
            string lastName          = LastName.Text;
            string pass              = Password.Text;
            string pass2             = PasswordRepeat.Text;
            int    roleId            = int.Parse(SelectedRole.Value);
            int    companyId         = int.Parse(SelectedCompany.Value);
            string displayName       = "";
            bool   verificationEmail = true;

            //Validate that the logged in user has permissions to do this
            //Validate the new user's information
            //Create the new user account
            //Send an email to the new user

            //checks that a role was selected for the user

            if (!UserUtil.DoesUserExist(email))
            {
                if (firstName.Length > 0 && lastName.Length > 0)
                {
                    if (roleId != -1)
                    {
                        if (companyId != -1)
                        {
                            if (pass.Equals(pass2))
                            {
                                if (pass.Length > 7)
                                {
                                    int validPass = ValidatePasswordSecurity(pass);
                                    if (validPass == 0)
                                    {
                                        //creates the user in firebase
                                        Firebase.Auth.User fbUser = FirebaseUtil.CreateNewUser(email, pass, displayName, verificationEmail);

                                        //if the user already exists in firebase, try to log them in
                                        if (fbUser == null)
                                        {
                                            fbUser = FirebaseUtil.LoginUser(email, pass);
                                        }

                                        if (fbUser != null)
                                        {
                                            User u    = UserUtil.CreateUser(roleId, companyId, email, firstName, lastName);
                                            User user = (User)Session["User"];
                                            if (user != null)
                                            {
                                                Log.Info(user.Identity + " created a new " + RoleUtil.GetRole(roleId).RoleName + " account under " + CompanyUtil.GetCompanyName(companyId) + " assigned to " + firstName + " " + lastName + " - " + email);
                                            }
                                            else
                                            {
                                                Log.Info("System created a new " + RoleUtil.GetRole(roleId).RoleName + " account under " + CompanyUtil.GetCompanyName(companyId) + " assigned to " + firstName + " " + lastName + " - " + email);
                                            }
                                            u.FirebaseUser = fbUser;
                                            //display user created msg
                                            UserCreateResult.Visible = true;
                                            UserCreateResult.Text    = "Successfully created user " + u.Identity;
                                        }
                                        else
                                        {
                                            UserCreateResult.CssClass = "error";
                                            UserCreateResult.Visible  = true;
                                            UserCreateResult.Text     = "Error creating user in Firebase";
                                        }
                                    }
                                    else
                                    {
                                        PasswordError.Visible = true;
                                        if (validPass == 1)
                                        {
                                            PasswordError.Text = "Password must contain at least 1 uppercase";
                                        }
                                        else if (validPass == 2)
                                        {
                                            PasswordError.Text = "Password must contain at least 1 lowercase";
                                        }
                                        else if (validPass == 3)
                                        {
                                            PasswordError.Text = "Password must contain at least 1 number";
                                        }
                                        else
                                        {
                                            PasswordError.Text = "Unknown password error";
                                        }
                                    }
                                }
                                else
                                {
                                    //display user failed to be created msg
                                    PasswordError.Visible = true;
                                    PasswordError.Text    = "Password must be at least 8 chars";
                                }
                            }
                            else
                            {
                                //throw error, passwords don't match
                                PasswordError.Visible = true;
                                PasswordError.Text    = "Passwords don't match";
                            }
                        }
                        else
                        {
                            //throw error, please select company for user
                            RoleCompanyError.Visible = true;
                            RoleCompanyError.Text    = "Please select a company";
                        }
                    }
                    else
                    {
                        //throw error, please select role for new user
                        RoleCompanyError.Visible = true;
                        RoleCompanyError.Text    = "Please select a role";
                    }
                }
                else
                {
                    NameError.Visible = true;
                    NameError.Text    = "Please enter a first and last name";
                }
            }
            else
            {
                EmailError.Visible = true;
                EmailError.Text    = "Email already in use";
            }

            ClearFields();
        }
Example #17
0
        protected void CreateProjectBtn_Click(object sender, EventArgs e)
        {
            int    companyId    = int.Parse(SelectedCompany.Value);
            int    workflowId   = int.Parse(SelectedWorkflow.Value);
            int    coachId      = int.Parse(SelectedCoach.Value);
            string projectName  = ProjectName.Text;
            string projectNotes = ProjectNotes.Text;

            if (projectName.Length > 0)
            {
                if (companyId != -1)
                {
                    if (workflowId != -1)
                    {
                        if (coachId != -1)
                        {
                            if (Request.QueryString["pid"] != null)
                            {
                                int     projId = int.Parse(Request.QueryString["pid"]);
                                Project p      = ProjectUtil.UpdateProject(projId, projectName, companyId, coachId, projectNotes);
                                User    user   = (User)Session["User"];
                                Log.Info(user.Identity + " updated project " + projectName + " with a Workflow of " + WorkflowUtil.GetWorklowName(workflowId) + " assigned to " + CompanyUtil.GetCompanyName(companyId) + " under Coach " + UserUtil.GetCoachName(coachId) + " with notes: " + projectNotes);
                                Response.Redirect("Projects.aspx?pid=" + p.ProjectId);
                            }
                            else
                            {
                                Project p    = ProjectUtil.CreateProject(projectName, workflowId, companyId, coachId, projectNotes);
                                User    user = (User)Session["User"];
                                Log.Info(user.Identity + " created project " + projectName + " with a Workflow of " + WorkflowUtil.GetWorklowName(workflowId) + " assigned to " + CompanyUtil.GetCompanyName(companyId) + " under Coach " + UserUtil.GetCoachName(coachId) + " with notes: " + projectNotes);
                                Response.Redirect("Projects.aspx?pid=" + p.ProjectId);
                            }
                        }
                    }
                }
            }
            else
            {
                //enter valid name
            }
        }
Example #18
0
        protected void ApproveFormBtn_Click(object sender, EventArgs e)
        {
            FormResult.Visible = false;
            //updating a form not, creating it
            if (Request.QueryString["pfid"] != null)
            {
                int           formId = int.Parse(Request.QueryString["pfid"]);
                Form          f      = FormUtil.GetForm(formId);
                Project       p      = ProjectUtil.GetProject(f.ProjectId);
                WorkflowModel w      = WorkflowUtil.GetWorkflow(p.WorkflowId);

                User user = (User)Session["User"];
                FormUtil.ApproveForm(formId, user.RoleId);
                Log.Info(user.Identity + " approved " + CompanyUtil.GetCompanyName(p.CompanyId) + "'s form " + f.FormName + " - " + p.Name);
                FormResult.CssClass = "success";
                FormResult.Text     = "Approved form " + f.FormName;
                FormResult.Visible  = true;

                //prep html for pdf generation
                HtmlDocument doc     = new HtmlDocument();
                string       pdfName = string.Format("{0} - {1} - {2}", w.WorkflowName, f.FormName, CompanyUtil.GetCompanyName(p.CompanyId));
                string       html    = formViewerData.Value;
                if (html.Contains("user-data"))
                {
                    html = html.Replace("user-data", "value");
                }
                if (html.Contains("\""))
                {
                    html = html.Replace("\"", "'");
                }
                doc.LoadHtml(html);
                doc.Save("PDFGen/" + CompanyUtil.GetCompanyName(p.CompanyId) + "_" + f.FormName + "_" + p.Name + ".html");

                //radiobtns
                foreach (HtmlNode link in doc.DocumentNode.SelectNodes("//input[@type]"))
                {
                    HtmlAttribute type = link.Attributes["type"];
                    if (type.Value.Equals("radio"))
                    {
                        if (link.Attributes.Contains("checked"))
                        {
                        }
                        else
                        {
                            if (link.Attributes.Contains("id"))
                            {
                                string toDelId = link.Attributes["id"].Value;

                                foreach (HtmlNode label in doc.DocumentNode.SelectNodes("//label[@for]"))
                                {
                                    string forId = label.Attributes["for"].Value;
                                    if (forId.Equals(toDelId))
                                    {
                                        label.Remove();
                                    }
                                }
                            }
                        }
                        link.Attributes.Remove("value");
                    }
                }

                //text fields, dates, + similar
                foreach (HtmlNode link in doc.DocumentNode.SelectNodes("//input[@value]"))
                {
                    HtmlAttribute value = link.Attributes["value"];
                    if (link.Attributes.Contains("placeholder"))
                    {
                        link.Attributes.Remove("placeholder");
                    }
                    string val = value.Value;
                    link.InnerHtml = val;
                    link.Attributes.Remove("value");
                }

                //text areas
                foreach (HtmlNode link in doc.DocumentNode.SelectNodes("//textarea[@value]"))
                {
                    HtmlAttribute value = link.Attributes["value"];
                    if (link.Attributes.Contains("placeholder"))
                    {
                        link.Attributes.Remove("placeholder");
                    }
                    string val = value.Value;
                    link.InnerHtml = val;
                    link.Attributes.Remove("value");
                }

                //attached files
                if (f.FilePath.Length > 0)
                {
                    foreach (HtmlNode link in doc.DocumentNode.SelectNodes("//input[@type]"))
                    {
                        HtmlAttribute type = link.Attributes["type"];
                        if (type.Value.Equals("file"))
                        {
                            string fileType = f.FilePath.Split('.')[1];
                            string fileName = string.Format("{0} {1} Attachment.{2}", CompanyUtil.GetCompanyName(p.CompanyId), f.FormName, fileType);
                            link.InnerHtml = "See " + fileName;
                        }
                    }
                }
                doc.Save("PDFGen/" + CompanyUtil.GetCompanyName(p.CompanyId) + "_" + f.FormName + "_" + p.Name + ".html");
                doc.Load("PDFGen/" + CompanyUtil.GetCompanyName(p.CompanyId) + "_" + f.FormName + "_" + p.Name + ".html");
                html = doc.Text;

                //pdf gen
                PDFGen.CreateHTMLPDF(html, pdfName);
                Response.Redirect("Forms.aspx?pfid=" + formId);
            }
        }
Example #19
0
 public CompanyController()
 {
     result      = new Result();
     companyUtil = new CompanyUtil();
     countryUtil = new CountryUtil();
 }