Example #1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            CheckBox        chkSelected            = new CheckBox();
            PotentialLesson LL                     = new PotentialLesson();
            bool            panel1controlsAreValid = true;
            bool            panel2controlsAreValid = true;
            bool            subjectMatterValid     = false;
            bool            stagesValid            = false;

            LL.CurrentUser = LoginName;
            LL.StatusId    = 1;  //This is to be in 'submitted' mode.
            LL.UserName    = LoginName;

            try
            {
                if (txtFirstName.Text.ToString() != "")
                {
                    LL.FirstName = txtFirstName.Text.ToString();
                }
                else
                {
                    ValidationSummary1.AddErrorMessage("Please enter First Name .");
                    panel1controlsAreValid = false;
                }

                if (txtLastName.Text.ToString() != "")
                {
                    LL.LastName = txtLastName.Text.ToString();
                }
                else
                {
                    ValidationSummary1.AddErrorMessage("Please enter Last Name .");
                    panel1controlsAreValid = false;
                }

                if (txtPhone.Text.ToString() != "")
                {
                    LL.Phone = txtPhone.Text.ToString();
                }
                else
                {
                    ValidationSummary1.AddErrorMessage("Please enter Phone # .");
                    panel1controlsAreValid = false;
                }

                if (txtLocation.Text.ToString() != "" && txtLocation.Text.Length < 50)
                {
                    LL.Location = txtLocation.Text.ToString();
                }
                else
                {
                    if (txtLocation.Text.Length > 50)
                    {
                        ValidationSummary1.AddErrorMessage("Location must be less then 50 characters.");
                        panel1controlsAreValid = false;
                    }
                }


                if (ddlSBU.SelectedIndex != 0)
                {
                    try
                    {
                        LL.SBUId = decimal.Parse(ddlSBU.SelectedItem.Value.ToString());
                    }
                    catch (SystemException ex)
                    {
                        throw new Backend.LLException("SBU ID is not numeric.", ex);
                    }
                }
                else
                {
                    ValidationSummary1.AddErrorMessage("Please choose a SBU. ");
                    panel1controlsAreValid = false;
                }

                if (ddlBU.SelectedIndex != -1 && ddlBU.SelectedIndex != 0)
                {
                    try
                    {
                        LL.BUId = decimal.Parse(ddlBU.SelectedItem.Value.ToString());
                    }
                    catch (SystemException ex)
                    {
                        throw new Backend.LLException("BU ID is not numeric.", ex);
                    }
                }
                else
                {
                    ValidationSummary1.AddErrorMessage("Please choose a Business Unit. ");
                    panel1controlsAreValid = false;
                }

                if ((ddlProject.SelectedIndex != -1 && ddlProject.SelectedIndex != 0) || txtOther.Text.ToString() != "")
                {
                    if (txtOther.Text.ToString() != "")
                    {
                        if (txtOther.Text.Length < 81)
                        {
                            LL.ProjectOther = txtOther.Text.ToString();
                        }
                        else
                        {
                            ValidationSummary1.AddErrorMessage("Project Other must be 80 Characters or less. ");
                            panel1controlsAreValid = false;
                        }
                    }

                    if (ddlProject.SelectedIndex != -1 && ddlProject.SelectedIndex != 0)
                    {
                        try
                        {
                            LL.ProjectId = decimal.Parse(ddlProject.SelectedItem.Value.ToString());
                        }
                        catch (SystemException ex)
                        {
                            throw new Backend.LLException("Project ID is not numeric.", ex);
                        }
                    }
                }
                else
                {
                    ValidationSummary1.AddErrorMessage("Please choose a Project Name or if not there, enter a value in the 'other' box. ");
                    panel1controlsAreValid = false;
                }

                if (txtTitle.Text.ToString() != "")
                {
                    LL.Title = txtTitle.Text.ToString();
                }
                else
                {
                    ValidationSummary1.AddErrorMessage("Please enter a Title less then 100 characters. ");
                    panel1controlsAreValid = false;
                }

                if (txtStatement.Text.ToString() != "")
                {
                    LL.Statement = txtStatement.Text.ToString();
                }
                else
                {
                    ValidationSummary1.AddErrorMessage("Please enter a Statement less then 300 characters. ");
                    panel1controlsAreValid = false;
                }

                if (txtRecommendations.Text.ToString() != "")
                {
                    LL.Background = txtBackground.Text.ToString();
                }

                if (ddlFinancialImpact.SelectedIndex > 0)
                {
                    try
                    {
                        LL.FinancialImpactId = decimal.Parse(ddlFinancialImpact.SelectedItem.Value.ToString());
                    }
                    catch (SystemException ex)
                    {
                        throw new Backend.LLException("Financial Impact ID is not numeric.", ex);
                    }
                }

                if (ddlType.SelectedIndex != 0 || txtTypeOther.Text.ToString() != "")
                {
                    if (txtTypeOther.Text.ToString() != "")
                    {
                        if (txtTypeOther.Text.Length < 51)
                        {
                            LL.TypeOther = txtTypeOther.Text.ToString();
                        }
                        else
                        {
                            ValidationSummary1.AddErrorMessage("Type Other must be 50 Characters or less. ");
                            panel1controlsAreValid = false;
                        }
                    }
                    if (ddlType.SelectedIndex != 0)
                    {
                        try
                        {
                            LL.TypeId = decimal.Parse(ddlType.SelectedItem.Value.ToString());
                        }
                        catch (SystemException ex)
                        {
                            throw new Backend.LLException("Type ID is not numeric.", ex);
                        }
                    }
                }
                else
                {
                    //Christian asked to make these fields NOT mandatory, Oct 10, 2008
                    //ValidationSummary1.AddErrorMessage("Please choose a Type or if not there, enter a value in the 'other' box.");
                    //panel1controlsAreValid = false;
                }

                if (ddlImpact.SelectedIndex != 0)
                {
                    try
                    {
                        LL.ImpactId = decimal.Parse(ddlImpact.SelectedItem.Value.ToString());
                    }
                    catch (SystemException ex)
                    {
                        throw new Backend.LLException("Impact ID is not numeric.", ex);
                    }
                }
                else
                {
                    //Christian asked to make these fields NOT mandatory, Oct 10, 2008
                    //ValidationSummary1.AddErrorMessage("Please choose a Impact. ");
                    //panel1controlsAreValid = false;
                }

                if (ddlFrequency.SelectedIndex != 0)
                {
                    try
                    {
                        LL.FrequencyId = decimal.Parse(ddlFrequency.SelectedItem.Value.ToString());
                    }
                    catch (SystemException ex)
                    {
                        throw new Backend.LLException("Frequency Id is not numeric.", ex);
                    }
                }
                else
                {
                    //Christian asked to make these fields NOT mandatory, Oct 10, 2008
                    // ValidationSummary1.AddErrorMessage("Please choose a Frequency. ");
                    // panel1controlsAreValid = false;
                }

                if (txtRecommendations.Text.ToString() != "")
                {
                    LL.Response = txtRecommendations.Text.ToString();
                }
                else
                {
                    ValidationSummary1.AddErrorMessage("Please enter a Recommendations less then 500 characters. ");
                    panel1controlsAreValid = false;
                }

                if (txtReference.Text.ToString() != "")
                {
                    LL.Reference = txtReference.Text.ToString();
                }

                LL.Comments = "";

                // check to see if they picked at least one Subject Matter
                foreach (DataGridItem dgItem in dgSubjectMatter.Items)
                {
                    chkSelected = (CheckBox)dgItem.FindControl("chkSelection");
                    if (chkSelected.Checked)
                    {
                        subjectMatterValid = true;
                    }
                }
                if (!subjectMatterValid)
                {
                    ValidationSummary1.AddErrorMessage("Must pick at least one Process. ");
                    panel2controlsAreValid = false;
                }

                foreach (DataGridItem dgItem in dgStages.Items)
                {
                    chkSelected = (CheckBox)dgItem.FindControl("chkSelection");
                    if (chkSelected.Checked)
                    {
                        stagesValid = true;
                    }
                }

                if (!stagesValid)
                {
                    ValidationSummary1.AddErrorMessage("Must pick at least one Project Phase. ");
                    panel2controlsAreValid = false;
                }


                if (panel1controlsAreValid)
                {
                    if (panel2controlsAreValid)
                    {
                        try
                        {
                            //This is a screen import not a Excel Import
                            LL.ImportfromExcel = "N";
                            LL.Save();
                        }
                        catch (SystemException ex)
                        {
                            throw new Backend.LLException("Failed to save document.", ex);
                        }

                        // Get the LL_ID to save any of the checkboxes picked to the xref table.
                        LL_ID = LL.LLId;

                        foreach (DataGridItem dgItem in dgSubjectMatter.Items)
                        {
                            chkSelected = (CheckBox)dgItem.FindControl("chkSelection");
                            if (chkSelected.Checked)
                            {
                                LL.SubjectMatterId = decimal.Parse(dgItem.Cells[0].Text.ToString());
                                try
                                {
                                    //Make sure some data was returned if not throw an exception
                                    LL.SaveSubjectMatterInfo();
                                }
                                catch (ApplicationException)
                                {
                                    throw new ApplicationException(string.Format("Subject Matter information Save error: ", LL_ID));
                                }
                            }
                        }

                        foreach (DataGridItem dgItem in dgCategory.Items)
                        {
                            chkSelected = (CheckBox)dgItem.FindControl("chkSelection");
                            if (chkSelected.Checked)
                            {
                                LL.CategoryId = decimal.Parse(dgItem.Cells[0].Text.ToString());
                                try
                                {
                                    //Make sure some data was returned if not throw an exception
                                    LL.SaveCategoryInfo();
                                }
                                catch (ApplicationException)
                                {
                                    throw new ApplicationException(string.Format("Discipline information Save error: ", LL_ID));
                                }
                            }
                        }

                        foreach (DataGridItem dgItem in dgStages.Items)
                        {
                            chkSelected = (CheckBox)dgItem.FindControl("chkSelection");
                            if (chkSelected.Checked)
                            {
                                LL.StageId = decimal.Parse(dgItem.Cells[0].Text.ToString());
                                try
                                {
                                    //Make sure some data was returned if not throw an exception
                                    LL.SaveStageInfo();
                                }
                                catch (ApplicationException)
                                {
                                    throw new ApplicationException(string.Format("Project Stage information Save error: ", LL_ID));
                                }
                            }
                        }
                        //Session[Global.Parameters.AmendViewEdit].ToString()
                        //if (Session[Global.Parameters.File3].ToString() != "")
                        if (txtFile1.Text.ToString() != "")
                        {
                            FileUpload3 = (FileUpload)Session[Global.Parameters.File3];
                            Session.Remove(Global.Parameters.File3);

                            if (FileUpload3.HasFile)
                            {
                                String fileName = (String)Session[Global.Parameters.tempFile3];
                                UploadtoDocumentum("Save From the WEB", fileName, FileUpload3.FileName, LL_ID.ToString());
                                Session.Remove(Global.Parameters.tempFile3);
                            }
                        }


                        //if (Session[Global.Parameters.File4].ToString() != "")
                        if (txtFile2.Text.ToString() != "")
                        {
                            FileUpload4 = (FileUpload)Session[Global.Parameters.File4];
                            Session.Remove(Global.Parameters.File4);

                            if (FileUpload4.HasFile)
                            {
                                String fileName = (String)Session[Global.Parameters.tempFile4];
                                UploadtoDocumentum("Save From the WEB", fileName, FileUpload4.FileName, LL_ID.ToString());
                                Session.Remove(Global.Parameters.tempFile4);
                            }
                        }


                        //using the Error msg to confirm the Save.
                        ValidationSummary1.AddErrorMessage("Thank you, your info has been successfully submitted to the Lesson Learned Coordinator. ");
                        //Cleare all fields and return to first page.
                        this.panel1.Visible  = true;
                        this.btnNext.Enabled = true;
                        this.btnBack.Enabled = false;
                        this.btnSave.Enabled = false;

                        this.panel2.Visible = false;
                        ClearAllControls(this);
                        PopulateName();

                        String sPathReport;
                        String sScript;

                        //call report window with their data.
                        Session.Add(Global.Parameters.SubmittedFinal, "SUBMITTED");
                        sPathReport = "window.open('" + Global.ProcessingPage.ToString() + "?" + Global.Parameters.LL_ID + "=" + LL_ID.ToString() + "');";
                        sScript     = "<script> " + sPathReport + "</script>";
                        this.ClientScript.RegisterStartupScript(this.GetType(), "START", sScript);

                        //this.RegisterStartupScript("START", sScript);
                    }
                    else
                    {
                        this.panel1.Visible = false;
                        this.panel2.Visible = true;
                    }
                }
                else
                {
                    this.panel1.Visible  = true;
                    this.btnNext.Enabled = true;
                    this.btnBack.Enabled = false;
                    this.btnSave.Enabled = false;
                    this.panel2.Visible  = false;
                }
            }
            catch (System.Exception ex)
            {
                throw new Backend.LLException("Failed to save document.", ex);
            }
        }
        protected void btnInput_Click(object sender, EventArgs e)
        {
            String documentumFilename = "";

            if (counter == "N")
            {
                if (ExcelFile.HasFile)
                {
                    try
                    {
                        //copy file to webserver

                        String ExceltempFile = System.IO.Path.GetDirectoryName(System.IO.Path.GetTempFileName().ToString());
                        // String ExceltempFile2 = "\\webstore1\\tier1_web2_dev$\\ll\\Reports'";
                        ExceltempFile = ExceltempFile + "\\" + ExcelFile.FileName.ToString();
                        ExcelFile.SaveAs(ExceltempFile);

                        string          connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + ExceltempFile.ToString() + ";Extended Properties=\"Excel 8.0;HDR=YES\"";
                        OleDbConnection dbConn           = new OleDbConnection(connectionString);

                        dbConn.Open();
                        //String sql = "Select * FROM " + ConfigurationManager.AppSettings["Upload"];
                        String           sql = "Select * FROM [Upload$] ";
                        OleDbCommand     cmd = new OleDbCommand(sql, dbConn);
                        DataSet          ds  = new DataSet();
                        OleDbDataAdapter da  = new OleDbDataAdapter(cmd);

                        da.Fill(ds);
                        dbConn.Close();
                        String  Final_ll    = "";
                        decimal row_counter = 0;
                        foreach (DataRow dr in ds.Tables[0].Rows)
                        {
                            DataRow         x  = dr;
                            PotentialLesson ll = new PotentialLesson();
                            ll.CurrentUser = LoginName;
                            ll.StatusId    = 2; //This is to be in 'pending' mode.
                            ll.UserName    = LoginName;

                            if ((dr["Lesson Learned Title"].ToString() != "") && (dr["LESSON LEARNED STATEMENT"].ToString() != ""))
                            {
                                try
                                {
                                    ll.Title      = dr["LESSON LEARNED TITLE"].ToString();
                                    ll.Statement  = dr["LESSON LEARNED STATEMENT"].ToString();
                                    ll.Background = dr["ADDITIONAL BACKGROUND"].ToString();
                                    ll.Response   = dr["RECOMMENDATIONS"].ToString();
                                    ll.Reference  = dr["REFERENCES"].ToString();
                                    ll.TypeId     = 1;
                                    if (dr["CATEGORY"].ToString() != "")
                                    {
                                        ll.CategoryId = System.Decimal.Parse(dr["CATEGORY"].ToString());
                                    }
                                    if (dr["PRIORITY"].ToString() != "")
                                    {
                                        ll.ImpactId = System.Decimal.Parse(dr["PRIORITY"].ToString());
                                    } // Priority on the Input Screen }
                                    if (dr["IMPACT"].ToString() != "")
                                    {
                                        ll.FinancialImpactId = System.Decimal.Parse(dr["IMPACT"].ToString());
                                    }//Impact on the Input Screen }
                                    if (dr["FREQUENCY"].ToString() != "")
                                    {
                                        ll.FrequencyId = System.Decimal.Parse(dr["FREQUENCY"].ToString());
                                    }
                                    if (dr["SBU"].ToString() != "")
                                    {
                                        ll.SBUId = System.Decimal.Parse(dr["SBU"].ToString());
                                    }
                                    if (dr["BU"].ToString() != "")
                                    {
                                        ll.BUId = System.Decimal.Parse(dr["BU"].ToString());
                                    }
                                    if (dr["Project"].ToString() != "")
                                    {
                                        ll.ProjectId = System.Decimal.Parse(dr["Project"].ToString());
                                    }

                                    //RPP April 8, 2009
                                    //Making this Y will imput the data to table LL_POTENTIAL_INPUT,
                                    //While setting it to N will input the data to table LL_POTENTIAL
                                    ll.ImportfromExcel = "N";

                                    ll.Save();
                                    Final_ll = ll.LLId.ToString();
                                    char[] separator = new char[] { ',' };

                                    if (dr["Phases"].ToString() != "")
                                    {
                                        String   phases  = dr["Phases"].ToString().TrimEnd(',');
                                        string[] aPhases = phases.Split(separator);

                                        foreach (string s in aPhases)
                                        {
                                            ll.StageId = System.Decimal.Parse(s.ToString());
                                            ll.SaveStageInfo();
                                        }
                                    }

                                    if (dr["Processes"].ToString() != "")
                                    {
                                        String   processes  = dr["Processes"].ToString().TrimEnd(',');
                                        String[] aProcesses = processes.Split(separator);

                                        foreach (string s in aProcesses)
                                        {
                                            ll.SubjectMatterId = decimal.Parse(s.ToString());
                                            ll.SaveSubjectMatterInfo();
                                        }
                                    }
                                    row_counter += 1;
                                }

                                catch (SystemException ex)
                                {
                                    throw new Backend.LLException("Failed to save document.", ex);
                                }
                            }
                        }

                        if (row_counter > 0)
                        {
                            //save document to the database
                            //RPP Oct 15, 2009 commented out due to Documentum being de-commissioned
                            //UploadtoDocumentum("Excel Input file", ExceltempFile.ToString(), ExcelFile.FileName.ToString(), Final_ll.ToString());
                            documentumFilename = ConfigurationManager.AppSettings["DocumentumCabinet"] + "/" + Final_ll.ToString() + "/" + ExcelFile.FileName.ToString();
                            //documentumFilename = ExceltempFile.ToString(); //rpp

                            //RPP Oct 15, 2009 commented out due to Documentum being de-commissioned
                            //this.lblMsg.Text = "You have successfully imported the Excel file. You have imported " + row_counter.ToString() + " rows. Your file has been saved in Documentum in the folder " + documentumFilename.ToString() + ".";
                            this.lblMsg.Text = "You have successfully imported the Excel file. You have imported " + row_counter.ToString() + " rows.";

                            if (this.cbGrid.Checked)
                            {
                                dgExcel.DataSource = ds;
                                dgExcel.DataBind();
                                dgExcel.Visible = true;
                                Page.DataBind();
                            }
                        }
                        else
                        {
                            this.lblMsg.Text = "There was a problem with your upload, 0 rows were imported into the database. Please ensure the template has not been modified.";
                        }
                        counter = "Y";
                    }
                    catch (SystemException ex)
                    {
                        throw new Backend.LLException("Failed to save document.", ex);
                    }
                }
            }
        }