Example #1
0
        public List <TNF> getAllTNFByUserID(string userID)
        {
            SqlConnection conn     = new SqlConnection();
            List <TNF>    toReturn = new List <TNF>();

            try
            {
                conn = new SqlConnection();
                string connstr = ConfigurationManager.ConnectionStrings["DBConnectionString"].ToString();
                conn.ConnectionString = connstr;
                conn.Open();
                SqlCommand comm = new SqlCommand();
                comm.Connection  = conn;
                comm.CommandText = "select * from [TNF] where userID=@userID";
                comm.Parameters.AddWithValue("@userID", userID);
                SqlDataReader dr = comm.ExecuteReader();
                while (dr.Read())
                {
                    TNF            t       = new TNF();
                    UserDAO        userDAO = new UserDAO();
                    WorkflowDAO    wfDAO   = new WorkflowDAO();
                    WorkflowSubDAO wfsDAO  = new WorkflowSubDAO();
                    User           user    = userDAO.getUserByID((string)dr["userID"]);
                    t.setUser(user);
                    t.setTNFID((int)dr["tnfid"]);
                    t.setType((string)dr["type"]);
                    t.setStatus((string)(dr["status"]));
                    t.setWFStatus((int)dr["wf_status"]);
                    t.setWorkflow(wfDAO.getWorkflowByID((int)dr["wfid"]));
                    if (!dr.IsDBNull(6))
                    {
                        t.setWorkflowSub(wfsDAO.getWorkflowSubByID((int)dr["wf_sub_id"]));
                    }
                    t.setApplicationDate(dr.GetDateTime(7));

                    toReturn.Add(t);
                }
                dr.Close();
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            finally
            {
                conn.Close();
            }
            return(toReturn);
        }
        protected void submitBtn_Click(object sender, EventArgs e)
        {
            //To do validations here
            if (courseInput.SelectedIndex == 0)
            {
                lblErrorMsgTest.Visible = true;
                lblErrorMsgTest.Text    = "Got error";
            }

            //Assume all fields entered correctly
            //declaration of variables
            WorkflowDAO wfDAO                             = new WorkflowDAO();
            TNFDAO      tnfDAO                            = new TNFDAO();
            User        currentUser                       = (User)Session["currentUser"];
            int         courseID                          = Convert.ToInt32(courseInput.SelectedValue);
            int         lessonID                          = Convert.ToInt32(Request.Form["rbnLessonID"]);
            string      prepareForNewJobRole              = null;
            string      prepareForNewJobRoleText          = null;
            DateTime?   prepareForNewJobRoleCompletedDate = null;
            string      shareKnowledge                    = null;
            string      shareKnowledgeText                = null;
            DateTime?   shareKnowledgeCompletedDate       = null;
            string      otherObjectives                   = null;
            string      otherObjectivesText               = null;
            DateTime?   otherObjectivesCompletedDate      = null;
            DateTime    applicationDate                   = DateTime.Now.Date;


            if (objectiveInput1.Checked)
            {
                prepareForNewJobRole              = "y";
                prepareForNewJobRoleText          = objectiveElaborate1.Text;
                prepareForNewJobRoleCompletedDate = DateTime.ParseExact(completeDateInput1.Text, "MM/dd/yyyy", CultureInfo.InvariantCulture);
            }
            else
            {
                prepareForNewJobRole = "n";
            }
            if (objectiveInput2.Checked)
            {
                shareKnowledge              = "y";
                shareKnowledgeText          = objectiveElaborate2.Text;
                shareKnowledgeCompletedDate = DateTime.ParseExact(completeDateInput2.Text, "MM/dd/yyyy", CultureInfo.InvariantCulture);
            }
            else
            {
                shareKnowledge = "n";
            }
            if (objectiveInput3.Checked)
            {
                otherObjectives              = "y";
                otherObjectivesText          = objectiveElaborate3.Text;
                otherObjectivesCompletedDate = DateTime.ParseExact(completeDateInput3.Text, "MM/dd/yyyy", CultureInfo.InvariantCulture);
            }
            else
            {
                otherObjectives = "n";
            }


            //creation of TNF object
            Workflow currentWF = wfDAO.getCurrentActiveWorkflow("individual");
            TNF      newTNF    = new TNF(currentUser, "individual", "pending", 0, currentWF, applicationDate);
            int      tnfid     = tnfDAO.createTNF(newTNF);

            newTNF.setTNFID(tnfid);
            tnfDAO.createTNF_Data(tnfid, courseID, prepareForNewJobRole, prepareForNewJobRoleText, prepareForNewJobRoleCompletedDate, shareKnowledge, shareKnowledgeText, shareKnowledgeCompletedDate, otherObjectives, otherObjectivesText, otherObjectivesCompletedDate, lessonID);

            //start routing

            Boolean successOrNot = Workflow_Route.routeForApproval(newTNF);

            if (successOrNot)
            {
                //to create lesson info
                Response.Redirect("submitTRF.aspx");
            }
            else
            {
                //do something
            }
        }