protected void AddQuestionBtn_Click(object sender, EventArgs e)
        {
            try
            {
                int rowIndex = 0;
                ArrayList listofQuestionsData = new ArrayList();

                if (ViewState["AddTable"] != null)
                {

                    DataTable dtCurrentTable = (DataTable)ViewState["AddTable"];

                    if (dtCurrentTable.Rows.Count > 0)
                    {

                        for (int i = 1; i <= dtCurrentTable.Rows.Count; i++)
                        {
                            //extract the TextBox values & Checkbox value
                            string box1 = (string)AddQuestionGrid.Rows[rowIndex].Cells[0].Text;
                            TextBox box2 = (TextBox)AddQuestionGrid.Rows[rowIndex].Cells[1].FindControl("QuestionTbx");
                            TextBox box3 = (TextBox)AddQuestionGrid.Rows[rowIndex].Cells[2].FindControl("RateOneTbx");
                            TextBox box4 = (TextBox)AddQuestionGrid.Rows[rowIndex].Cells[3].FindControl("RateSevenTbx");
                            CheckBox chk2 = (CheckBox)AddQuestionGrid.Rows[rowIndex].Cells[4].FindControl("QnInclude");

                            if (box2.Text.Trim() != "" && box3.Text.Trim() != "" && box4.Text.Trim() != "")
                            {
                                bool valid = dbmanager.GetAppraisalQuestionValid(box2.Text.Trim());
                                if (valid == false)
                                {
                                    Question qn = new Question(Convert.ToInt32(box1), box2.Text.Trim(), chk2.Checked, box3.Text.Trim(), box4.Text.Trim());
                                    listofQuestionsData.Add(qn);
                                }
                            }
                            rowIndex++;

                        }
                        int returnupdate = dbmanager.InsertAllAppraisalQuestions(listofQuestionsData);
                        if (returnupdate > 0)
                        {
                            MessageBoxShow(returnupdate + " record(s) added.");
                        }
                        else
                        {
                            MessageBoxShow("No record is added.");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBoxShow(ex.Message);
            }
        }
Esempio n. 2
0
        public static ArrayList GetAllQuestionListWithIDs()
        {
            SqlConnection myconn = null;
            ArrayList listofquestion = new ArrayList();
            Question q1 = null;
            //List<Question> questionList = new List<Question>();
            try
            {
                myconn = new SqlConnection();
                SqlCommand comm = new SqlCommand();
                myconn.ConnectionString = connectionString;
                myconn.Open();
                comm.Connection = myconn;
                comm.CommandText = "select QuestionID, Question from Question order by QuestionID asc";

                SqlDataReader dr = comm.ExecuteReader();
                while (dr.Read())
                {
                    int qID = Convert.ToInt32(dr["QuestionID"].ToString());
                    string question = dr["Question"].ToString();
                    bool include = false;
                    Question q2 = new Question(qID, question, include);
                    listofquestion.Add(q2);
                }
                dr.Close();
            }

            catch (SqlException)
            {
                return listofquestion;
            }

            finally
            {
                myconn.Close();
            }
            return listofquestion;
        }
        protected void Save_Click(object sender, EventArgs e)
        {
            try
            {
                int rowIndex = 0;
                ArrayList listofQuestionsData = new ArrayList();
                ArrayList listofQuestionOnlyUpdateInclude = new ArrayList();

                if (ViewState["CurrentTable"] != null)
                {

                    DataTable dtCurrentTable = (DataTable)ViewState["CurrentTable"];

                    if (dtCurrentTable.Rows.Count > 0)
                    {
                        int count = 0;
                        for (int i = 1; i <= dtCurrentTable.Rows.Count; i++)
                        {
                            //extract the TextBox values & Checkbox value

                            Label lbl1 = (Label)AppraisalQuestionGrid.Rows[rowIndex].Cells[0].FindControl("QuestionIdLbl");
                            TextBox box2 = (TextBox)AppraisalQuestionGrid.Rows[rowIndex].Cells[1].FindControl("QuestionsTbx");

                            TextBox rate1 = (TextBox)AppraisalQuestionGrid.Rows[rowIndex].Cells[2].FindControl("RateOneTbx");
                            TextBox rate2 = (TextBox)AppraisalQuestionGrid.Rows[rowIndex].Cells[3].FindControl("RateSevenTbx");
                            CheckBox chk2 = (CheckBox)AppraisalQuestionGrid.Rows[rowIndex].Cells[4].FindControl("QnInclude");
                            if (box2.Text.Trim() != "")
                            {
                                ArrayList listofquestion = dbmanager.GetAllQuestionListInOrder();

                                Question qn = new Question(Convert.ToInt32(listofquestion[count].ToString()), box2.Text, chk2.Checked, rate1.Text, rate2.Text);
                                //bool checkqninAppraisal = dbmanager.CheckQuestionIdExistInAppraisal(qn.QuestionID);

                                //if (checkqninAppraisal == false)
                                //{
                                //    listofQuestionsData.Add(qn);
                                //}
                                //if (checkqninAppraisal == true)
                                //{
                                    listofQuestionOnlyUpdateInclude.Add(qn);
                                //}
                            }
                            rowIndex++;
                            count++;
                        }
                        //int returnupdate = dbmanager.UpdateAllAppraisalQuestion(listofQuestionsData);
                        int returnupdate = dbmanager.UpdateAllAppraisalQuestion(listofQuestionOnlyUpdateInclude);
                        //int returnupdateInclude = dbmanager.UpdateAllAppraisalQuestionOnlyInclude(listofQuestionOnlyUpdateInclude);
                        //int totalupdate = returnupdate + returnupdateInclude;
                        //if (totalupdate != 0 && totalupdate == listofQuestionsData.Count + listofQuestionOnlyUpdateInclude.Count)
                        if (returnupdate != 0)
                        {
                            MessageBoxShow(returnupdate + " record(s) updated successfully.");
                        }
                        else
                        {
                            MessageBoxShow("No record is updated, might have data relationship with other tables.");
                        }
                    }

                }
            }
            catch (Exception ex)
            {
                MessageBoxShow(ex.Message);
            }
        }
Esempio n. 4
0
        public static ArrayList GetAllQuestionForAppraisal()
        {
            SqlConnection myconn = null;
            ArrayList listofquestion = new ArrayList();
            Question quest = null;
            try
            {
                myconn = new SqlConnection();
                SqlCommand comm = new SqlCommand();
                myconn.ConnectionString = connectionString;
                myconn.Open();
                comm.Connection = myconn;
                comm.CommandText = "select * from Question where QuestionInclude!='N' order by QuestionInclude, QuestionId asc";

                SqlDataReader dr = comm.ExecuteReader();
                while (dr.Read())
                {
                    bool qninclude = false;
                    string include = dr["QuestionInclude"].ToString();
                    if (include == "Y")
                    {
                        qninclude = true;
                    }
                    int id = Convert.ToInt32(dr["QuestionID"]);
                    string question = dr["Question"].ToString();
                    string one = dr["OneRate"].ToString();
                    string seven = dr["SevenRate"].ToString();

                    quest = new Question(id, question, qninclude, one, seven);
                    listofquestion.Add(quest);
                }
                dr.Close();
            }

            catch (SqlException)
            {
                return listofquestion;
            }

            finally
            {
                myconn.Close();
            }
            return listofquestion;
        }