Example #1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            SaveQuestion        saveQuestion    = null;
            string              quesModeID      = string.Empty;
            string              questionID      = string.Empty;
            MasterDataFunctions mDataFunc       = null;
            QBQuestions         qbQuestions     = null;
            List <QBQuestions>  qbQuestionsColl = null;
            QBInfo              qbInfo          = null;
            string              qbID            = string.Empty;

            try
            {
                mDataFunc       = new MasterDataFunctions();
                saveQuestion    = new SaveQuestion();
                qbQuestionsColl = new List <QBQuestions>();
                if (cbQB.SelectedItem != null)
                {
                    qbID = ((KeyValuePair <string, string>)cbQB.SelectedItem).Key;
                }

                htQBOrder.Clear();
                for (int i = 0; i < dgvQB.Rows.Count - 1; i++)
                {
                    htQBOrder.Add(dgvQB.Rows[i].Cells[0].Value, dgvQB.Rows[i].Cells[3].Value);
                }

                foreach (QuestionRelation qr in selectedQuestionRelation)
                {
                    qbQuestions = new QBQuestions();
                    qbQuestions.Question_Rel_ID = qr.ID;
                    qbQuestions.Order           = htQBOrder[qr.ID].ToString();
                    qbQuestions.EntityState     = QbQuestionsEntityState;
                    qbQuestionsColl.Add(qbQuestions);
                }

                qbInfo         = new QBInfo();
                qbInfo.ID      = string.IsNullOrWhiteSpace(qbID) ? string.Empty : qbID;
                qbInfo.QBName  = txtQBName.Text;
                qbInfo.Remarks = txtQBRemarks.Text;
                qbInfo.QBQuestionsEntityState = isQBQuestionChanged ? EntityOperationalState.Update : EntityOperationalState.None;
                qbInfo.EntityState            = QbQuestionsEntityState;
                qbInfo.QBQuestions            = qbQuestionsColl;

                isQBQuestionChanged = false;

                mDataFunc.AddQuestionBank(qbInfo);
                MessageBox.Show("Question Bank saved.");
                ResetAll();
                LoadQBCombo();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Example #2
0
        public void AddQuestionBank(oEEntiti Qbinfo)
        {
            DataTable      dtQuestionBank = null;
            DataTable      dtQBQuestions  = null;
            DataRow        drNewQB        = null;
            DataRow        drNewQBRel     = null;
            List <DataRow> drNewQBRelColl = null;
            QBInfo         qbinfo         = null;
            string         qbID           = string.Empty;

            try
            {
                qbinfo = Qbinfo as QBInfo;

                LoadXML();
                dtQuestionBank = oeEntity.Tables[EntityConstents.TBL_QUESTIONSBANK];
                dtQBQuestions  = oeEntity.Tables[EntityConstents.TBL_QUESTIONSBANK_QUES];

                if (qbinfo.EntityState == EntityOperationalState.New)
                {
                    drNewQB = dtQuestionBank.NewRow();
                    drNewQB[EntityConstents.COL_QUESTIONSBANK_ID] = Guid.NewGuid().ToString();
                }
                else
                {
                    drNewQB = dtQuestionBank.AsEnumerable().Where(ans => ans.Field <string>("ID") == qbinfo.ID).SingleOrDefault();
                }

                qbID = drNewQB[EntityConstents.COL_QUESTIONSBANK_ID].ToString();
                drNewQB[EntityConstents.COL_QUESTIONSBANK_EXAMNAME] = qbinfo.QBName;
                drNewQB[EntityConstents.COL_QUESTIONSBANK_REMARKS]  = qbinfo.Remarks;

                if (qbinfo.EntityState == EntityOperationalState.New)
                {
                    dtQuestionBank.Rows.Add(drNewQB);
                }

                if (qbinfo.QBQuestionsEntityState == EntityOperationalState.New || qbinfo.QBQuestionsEntityState == EntityOperationalState.Update)
                {
                    if (qbinfo.QBQuestionsEntityState == EntityOperationalState.Update)
                    {
                        drNewQBRelColl = dtQBQuestions.AsEnumerable().Where(ans => ans.Field <string>("Fk_Question_Bank") == qbID).ToList();
                        if (drNewQBRelColl != null && drNewQBRelColl.Count > 0)
                        {
                            for (int cnt = drNewQBRelColl.Count - 1; cnt >= 0; cnt--)
                            {
                                dtQBQuestions.Rows.Remove(drNewQBRelColl[cnt]);
                            }
                        }
                    }

                    foreach (QBQuestions qbq in qbinfo.QBQuestions)
                    {
                        drNewQBRel = dtQBQuestions.NewRow();
                        drNewQBRel[EntityConstents.COL_QUESTIONSBANK_QUES_ID]      = Guid.NewGuid().ToString();
                        drNewQBRel[EntityConstents.COL_QUESTIONSBANK_QUES_REL_ID]  = qbq.Question_Rel_ID;
                        drNewQBRel[EntityConstents.COL_QUESTIONSBANK_QUES_BANK_ID] = qbID;
                        drNewQBRel[EntityConstents.COL_QUESTIONSBANK_QUES_ORDER]   = qbq.Order;
                        dtQBQuestions.Rows.Add(drNewQBRel);
                    }
                }
                saveXML(oeEntity);
            }
            catch
            {
                throw;
            }
        }