Пример #1
0
        ///<summary>Inserts one QuestionDef into the database.  Provides option to use the existing priKey.</summary>
        internal static long Insert(QuestionDef questionDef, bool useExistingPK)
        {
            if (!useExistingPK && PrefC.RandomKeys)
            {
                questionDef.QuestionDefNum = ReplicationServers.GetKey("questiondef", "QuestionDefNum");
            }
            string command = "INSERT INTO questiondef (";

            if (useExistingPK || PrefC.RandomKeys)
            {
                command += "QuestionDefNum,";
            }
            command += "Description,ItemOrder,QuestType) VALUES(";
            if (useExistingPK || PrefC.RandomKeys)
            {
                command += POut.Long(questionDef.QuestionDefNum) + ",";
            }
            command +=
                "'" + POut.String(questionDef.Description) + "',"
                + POut.Int(questionDef.ItemOrder) + ","
                + POut.Int((int)questionDef.QuestType) + ")";
            if (useExistingPK || PrefC.RandomKeys)
            {
                Db.NonQ(command);
            }
            else
            {
                questionDef.QuestionDefNum = Db.NonQ(command, true);
            }
            return(questionDef.QuestionDefNum);
        }
Пример #2
0
 ///<summary>Inserts one QuestionDef into the database.  Returns the new priKey.</summary>
 internal static long Insert(QuestionDef questionDef)
 {
     if(DataConnection.DBtype==DatabaseType.Oracle) {
         questionDef.QuestionDefNum=DbHelper.GetNextOracleKey("questiondef","QuestionDefNum");
         int loopcount=0;
         while(loopcount<100){
             try {
                 return Insert(questionDef,true);
             }
             catch(Oracle.DataAccess.Client.OracleException ex){
                 if(ex.Number==1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated")){
                     questionDef.QuestionDefNum++;
                     loopcount++;
                 }
                 else{
                     throw ex;
                 }
             }
         }
         throw new ApplicationException("Insert failed.  Could not generate primary key.");
     }
     else {
         return Insert(questionDef,false);
     }
 }
Пример #3
0
        ///<summary>Used by MoveUp and MoveDown.</summary>
        private static void SetOrder(int mySelNum, int myItemOrder, QuestionDef[] List)
        {
            QuestionDef temp = List[mySelNum];

            temp.ItemOrder = myItemOrder;
            QuestionDefs.Update(temp);
        }
Пример #4
0
 ///<summary>Inserts one QuestionDef into the database.  Provides option to use the existing priKey.</summary>
 internal static long Insert(QuestionDef questionDef,bool useExistingPK)
 {
     if(!useExistingPK && PrefC.RandomKeys) {
         questionDef.QuestionDefNum=ReplicationServers.GetKey("questiondef","QuestionDefNum");
     }
     string command="INSERT INTO questiondef (";
     if(useExistingPK || PrefC.RandomKeys) {
         command+="QuestionDefNum,";
     }
     command+="Description,ItemOrder,QuestType) VALUES(";
     if(useExistingPK || PrefC.RandomKeys) {
         command+=POut.Long(questionDef.QuestionDefNum)+",";
     }
     command+=
          "'"+POut.String(questionDef.Description)+"',"
         +    POut.Int   (questionDef.ItemOrder)+","
         +    POut.Int   ((int)questionDef.QuestType)+")";
     if(useExistingPK || PrefC.RandomKeys) {
         Db.NonQ(command);
     }
     else {
         questionDef.QuestionDefNum=Db.NonQ(command,true);
     }
     return questionDef.QuestionDefNum;
 }
Пример #5
0
 public async Task<IActionResult> Create( [FromBody] QuestionDef Question ) {
     if( Question == null ) {
         return BadRequest();
     }
     await _questionRepo.Add( Question );
     return CreatedAtRoute( "GetQuestion", new { Controller = "Questions", id = Question.QuestionId }, Question );
 }
Пример #6
0
 ///<summary>Inserts one QuestionDef into the database.  Returns the new priKey.</summary>
 internal static long Insert(QuestionDef questionDef)
 {
     if (DataConnection.DBtype == DatabaseType.Oracle)
     {
         questionDef.QuestionDefNum = DbHelper.GetNextOracleKey("questiondef", "QuestionDefNum");
         int loopcount = 0;
         while (loopcount < 100)
         {
             try {
                 return(Insert(questionDef, true));
             }
             catch (Oracle.DataAccess.Client.OracleException ex) {
                 if (ex.Number == 1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated"))
                 {
                     questionDef.QuestionDefNum++;
                     loopcount++;
                 }
                 else
                 {
                     throw ex;
                 }
             }
         }
         throw new ApplicationException("Insert failed.  Could not generate primary key.");
     }
     else
     {
         return(Insert(questionDef, false));
     }
 }
Пример #7
0
 public async Task<IActionResult> Put( int id, [FromBody] QuestionDef Question ) {
     if( Question == null ) {
         return NotFound();
     }
     Question.QuestionId = id;
     await _questionRepo.Update( Question );
     return RedirectToRoute( "GetQuestion", new { Controller = "Questions", id = Question.QuestionId } );
 }
Пример #8
0
 // Update An Existing Question
 public async Task Update(QuestionDef question)
 {
     if (question != null)
     {
         _quizContext.Questions.Update(question);
         await _quizContext.SaveChangesAsync();
     }
 }
Пример #9
0
 ///<summary></summary>
 public FormQuestionDefEdit(QuestionDef questionDefCur)
 {
     //
     // Required for Windows Form Designer support
     //
     InitializeComponent();
     Lan.F(this);
     QuestionDefCur = questionDefCur;
 }
Пример #10
0
        // Add A New Question
        public async Task Add(QuestionDef question)
        {
            if (question != null)
            {
                await _quizContext.Questions.AddAsync(question);

                await _quizContext.SaveChangesAsync();
            }
        }
Пример #11
0
        ///<summary></summary>
        public static void Insert(QuestionDef def)
        {
            string command = "INSERT INTO questiondef (Description,ItemOrder,QuestType) VALUES("
                             + "'" + POut.PString(def.Description) + "', "
                             + "'" + POut.PInt(def.ItemOrder) + "', "
                             + "'" + POut.PInt((int)def.QuestType) + "')";

            def.QuestionDefNum = General.NonQ(command, true);
        }
Пример #12
0
        ///<summary>Updates one QuestionDef in the database.</summary>
        internal static void Update(QuestionDef questionDef)
        {
            string command = "UPDATE questiondef SET "
                             + "Description   = '" + POut.String(questionDef.Description) + "', "
                             + "ItemOrder     =  " + POut.Int(questionDef.ItemOrder) + ", "
                             + "QuestType     =  " + POut.Int((int)questionDef.QuestType) + " "
                             + "WHERE QuestionDefNum = " + POut.Long(questionDef.QuestionDefNum);

            Db.NonQ(command);
        }
Пример #13
0
        private void butAdd_Click(object sender, System.EventArgs e)
        {
            QuestionDef def = new QuestionDef();

            def.ItemOrder = QuestionList.Length;
            FormQuestionDefEdit FormQ = new FormQuestionDefEdit(def);

            FormQ.IsNew = true;
            FormQ.ShowDialog();
            FillGrid();
        }
Пример #14
0
        ///<summary></summary>
        public static void Update(QuestionDef def)
        {
            string command = "UPDATE questiondef SET "
                             + "QuestionDefNum = '" + POut.PInt(def.QuestionDefNum) + "'"
                             + ",Description = '" + POut.PString(def.Description) + "'"
                             + ",ItemOrder = '" + POut.PInt(def.ItemOrder) + "'"
                             + ",QuestType = '" + POut.PInt((int)def.QuestType) + "'"
                             + " WHERE QuestionDefNum  ='" + POut.PInt(def.QuestionDefNum) + "'";

            General.NonQ(command);
        }
Пример #15
0
		///<summary>Converts a DataTable to a list of objects.</summary>
		public static List<QuestionDef> TableToList(DataTable table){
			List<QuestionDef> retVal=new List<QuestionDef>();
			QuestionDef questionDef;
			for(int i=0;i<table.Rows.Count;i++) {
				questionDef=new QuestionDef();
				questionDef.QuestionDefNum= PIn.Long  (table.Rows[i]["QuestionDefNum"].ToString());
				questionDef.Description   = PIn.String(table.Rows[i]["Description"].ToString());
				questionDef.ItemOrder     = PIn.Int   (table.Rows[i]["ItemOrder"].ToString());
				questionDef.QuestType     = (QuestionType)PIn.Int(table.Rows[i]["QuestType"].ToString());
				retVal.Add(questionDef);
			}
			return retVal;
		}
Пример #16
0
 ///<summary>Inserts one QuestionDef into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(QuestionDef questionDef)
 {
     if (DataConnection.DBtype == DatabaseType.MySql)
     {
         return(InsertNoCache(questionDef, false));
     }
     else
     {
         if (DataConnection.DBtype == DatabaseType.Oracle)
         {
             questionDef.QuestionDefNum = DbHelper.GetNextOracleKey("questiondef", "QuestionDefNum");                  //Cacheless method
         }
         return(InsertNoCache(questionDef, true));
     }
 }
Пример #17
0
 ///<summary>Returns true if Update(QuestionDef,QuestionDef) would make changes to the database.
 ///Does not make any changes to the database and can be called before remoting role is checked.</summary>
 public static bool UpdateComparison(QuestionDef questionDef, QuestionDef oldQuestionDef)
 {
     if (questionDef.Description != oldQuestionDef.Description)
     {
         return(true);
     }
     if (questionDef.ItemOrder != oldQuestionDef.ItemOrder)
     {
         return(true);
     }
     if (questionDef.QuestType != oldQuestionDef.QuestType)
     {
         return(true);
     }
     return(false);
 }
Пример #18
0
        private static Selection getSelection(String choiceValue, QuestionDef q)
        {
            Selection s;

            if (q == null || q.getDynamicChoices() != null)
            {
                s = new Selection(choiceValue);
            }
            else
            {
                SelectChoice choice = q.getChoiceForValue(choiceValue);
                s = (choice != null ? choice.selection() : null);
            }

            return(s);
        }
Пример #19
0
        ///<summary>Updates one QuestionDef in the database.</summary>
        public static void Update(QuestionDef questionDef)
        {
            string command = "UPDATE questiondef SET "
                             + "Description   =  " + DbHelper.ParamChar + "paramDescription, "
                             + "ItemOrder     =  " + POut.Int(questionDef.ItemOrder) + ", "
                             + "QuestType     =  " + POut.Int((int)questionDef.QuestType) + " "
                             + "WHERE QuestionDefNum = " + POut.Long(questionDef.QuestionDefNum);

            if (questionDef.Description == null)
            {
                questionDef.Description = "";
            }
            OdSqlParameter paramDescription = new OdSqlParameter("paramDescription", OdDbType.Text, POut.StringParam(questionDef.Description));

            Db.NonQ(command, paramDescription);
        }
Пример #20
0
        ///<summary>Converts a DataTable to a list of objects.</summary>
        public static List <QuestionDef> TableToList(DataTable table)
        {
            List <QuestionDef> retVal = new List <QuestionDef>();
            QuestionDef        questionDef;

            foreach (DataRow row in table.Rows)
            {
                questionDef = new QuestionDef();
                questionDef.QuestionDefNum = PIn.Long(row["QuestionDefNum"].ToString());
                questionDef.Description    = PIn.String(row["Description"].ToString());
                questionDef.ItemOrder      = PIn.Int(row["ItemOrder"].ToString());
                questionDef.QuestType      = (OpenDentBusiness.QuestionType)PIn.Int(row["QuestType"].ToString());
                retVal.Add(questionDef);
            }
            return(retVal);
        }
Пример #21
0
        ///<summary>Converts a DataTable to a list of objects.</summary>
        internal static List <QuestionDef> TableToList(DataTable table)
        {
            List <QuestionDef> retVal = new List <QuestionDef>();
            QuestionDef        questionDef;

            for (int i = 0; i < table.Rows.Count; i++)
            {
                questionDef = new QuestionDef();
                questionDef.QuestionDefNum = PIn.Long(table.Rows[i]["QuestionDefNum"].ToString());
                questionDef.Description    = PIn.String(table.Rows[i]["Description"].ToString());
                questionDef.ItemOrder      = PIn.Int(table.Rows[i]["ItemOrder"].ToString());
                questionDef.QuestType      = (QuestionType)PIn.Int(table.Rows[i]["QuestType"].ToString());
                retVal.Add(questionDef);
            }
            return(retVal);
        }
Пример #22
0
        ///<summary>Gets a list of all QuestionDefs.</summary>
        public static QuestionDef[] Refresh()
        {
            string    command = "SELECT * FROM questiondef ORDER BY ItemOrder";
            DataTable table   = General.GetTable(command);

            QuestionDef[] List = new QuestionDef[table.Rows.Count];
            for (int i = 0; i < table.Rows.Count; i++)
            {
                List[i] = new QuestionDef();
                List[i].QuestionDefNum = PIn.PInt(table.Rows[i][0].ToString());
                List[i].Description    = PIn.PString(table.Rows[i][1].ToString());
                List[i].ItemOrder      = PIn.PInt(table.Rows[i][2].ToString());
                List[i].QuestType      = (QuestionType)PIn.PInt(table.Rows[i][3].ToString());
            }
            return(List);
        }
Пример #23
0
        private static ArrayList getSelections(String text, QuestionDef q)
        {
            ArrayList v = new ArrayList();

            List <String> choices = DateUtils.split(text, XFormAnswerDataSerializer.DELIMITER, true);

            for (int i = 0; i < choices.Count; i++)
            {
                Selection s = getSelection((String)choices[i], q);
                if (s != null)
                {
                    v.Add(s);
                }
            }

            return(v);
        }
Пример #24
0
        /**
         * Attempts to save the answer at the specified FormIndex into the
         * datamodel.
         *
         * @param index
         * @param data
         * @return OK if save was successful, error if a constraint was violated.
         */
        public int answerQuestion(FormIndex index, IAnswerData data)
        {
            QuestionDef q = model.getQuestionPrompt(index).getQuestion();

            if (model.getEvent(index) != FormEntryController.EVENT_QUESTION)
            {
                throw new SystemException("Non-Question object at the form index.");
            }
            TreeElement element         = model.getTreeElement(index);
            Boolean     complexQuestion = q.isComplex();

            Boolean hasConstraints = false;

            if (element.required && data == null)
            {
                return(ANSWER_REQUIRED_BUT_EMPTY);
            }
            else if (!complexQuestion && !model.getForm().evaluateConstraint(index.getReference(), data))
            {
                return(ANSWER_CONSTRAINT_VIOLATED);
            }
            else if (!complexQuestion)
            {
                commitAnswer(element, index, data);
                return(ANSWER_OK);
            }
            else if (complexQuestion && hasConstraints)
            {
                //TODO: itemsets: don't currently evaluate constraints for itemset/copy -- haven't figured out how handle it yet
                throw new SystemException("Itemsets do not currently evaluate constraints. Your constraint will not work, please remove it before proceeding.");
            }
            else
            {
                try
                {
                    model.getForm().copyItemsetAnswer(q, element, data);
                }
                catch (InvalidReferenceException ire)
                {
                    Console.WriteLine(ire.StackTrace);
                    throw new SystemException("Invalid reference while copying itemset answer: " + ire.Message);
                }
                return(ANSWER_OK);
            }
        }
Пример #25
0
        ///<summary>Updates one QuestionDef in the database.  Uses an old object to compare to, and only alters changed fields.  This prevents collisions and concurrency problems in heavily used tables.  Returns true if an update occurred.</summary>
        public static bool Update(QuestionDef questionDef, QuestionDef oldQuestionDef)
        {
            string command = "";

            if (questionDef.Description != oldQuestionDef.Description)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "Description = " + DbHelper.ParamChar + "paramDescription";
            }
            if (questionDef.ItemOrder != oldQuestionDef.ItemOrder)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ItemOrder = " + POut.Int(questionDef.ItemOrder) + "";
            }
            if (questionDef.QuestType != oldQuestionDef.QuestType)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "QuestType = " + POut.Int((int)questionDef.QuestType) + "";
            }
            if (command == "")
            {
                return(false);
            }
            if (questionDef.Description == null)
            {
                questionDef.Description = "";
            }
            OdSqlParameter paramDescription = new OdSqlParameter("paramDescription", OdDbType.Text, POut.StringParam(questionDef.Description));

            command = "UPDATE questiondef SET " + command
                      + " WHERE QuestionDefNum = " + POut.Long(questionDef.QuestionDefNum);
            Db.NonQ(command, paramDescription);
            return(true);
        }
Пример #26
0
        public List <SelectChoice> getSelectChoices()
        {
            QuestionDef q = getQuestion();

            ItemsetBinding itemset = q.getDynamicChoices();

            if (itemset != null)
            {
                if (!dynamicChoicesPopulated)
                {
                    form.populateDynamicChoices(itemset, mTreeElement.getRef());
                    dynamicChoicesPopulated = true;
                }
                return(itemset.getChoices());
            }
            else
            { //static choices
                return(q.getChoices());
            }
        }
Пример #27
0
        ///<summary>Inserts one QuestionDef into the database.  Provides option to use the existing priKey.  Doesn't use the cache.</summary>
        public static long InsertNoCache(QuestionDef questionDef, bool useExistingPK)
        {
            bool   isRandomKeys = Prefs.GetBoolNoCache(PrefName.RandomPrimaryKeys);
            string command      = "INSERT INTO questiondef (";

            if (!useExistingPK && isRandomKeys)
            {
                questionDef.QuestionDefNum = ReplicationServers.GetKeyNoCache("questiondef", "QuestionDefNum");
            }
            if (isRandomKeys || useExistingPK)
            {
                command += "QuestionDefNum,";
            }
            command += "Description,ItemOrder,QuestType) VALUES(";
            if (isRandomKeys || useExistingPK)
            {
                command += POut.Long(questionDef.QuestionDefNum) + ",";
            }
            command +=
                DbHelper.ParamChar + "paramDescription,"
                + POut.Int(questionDef.ItemOrder) + ","
                + POut.Int((int)questionDef.QuestType) + ")";
            if (questionDef.Description == null)
            {
                questionDef.Description = "";
            }
            OdSqlParameter paramDescription = new OdSqlParameter("paramDescription", OdDbType.Text, POut.StringParam(questionDef.Description));

            if (useExistingPK || isRandomKeys)
            {
                Db.NonQ(command, paramDescription);
            }
            else
            {
                questionDef.QuestionDefNum = Db.NonQ(command, true, "QuestionDefNum", "questionDef", paramDescription);
            }
            return(questionDef.QuestionDefNum);
        }
Пример #28
0
        ///<summary>Updates one QuestionDef in the database.  Uses an old object to compare to, and only alters changed fields.  This prevents collisions and concurrency problems in heavily used tables.</summary>
        internal static void Update(QuestionDef questionDef, QuestionDef oldQuestionDef)
        {
            string command = "";

            if (questionDef.Description != oldQuestionDef.Description)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "Description = '" + POut.String(questionDef.Description) + "'";
            }
            if (questionDef.ItemOrder != oldQuestionDef.ItemOrder)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ItemOrder = " + POut.Int(questionDef.ItemOrder) + "";
            }
            if (questionDef.QuestType != oldQuestionDef.QuestType)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "QuestType = " + POut.Int((int)questionDef.QuestType) + "";
            }
            if (command == "")
            {
                return;
            }
            command = "UPDATE questiondef SET " + command
                      + " WHERE QuestionDefNum = " + POut.Long(questionDef.QuestionDefNum);
            Db.NonQ(command);
        }
Пример #29
0
        public static IAnswerData getAnswerData(String text, int dataType, QuestionDef q)
        {
            String trimmedText = text.Trim();

            if (trimmedText.Length == 0)
            {
                trimmedText = null;
            }

            switch (dataType)
            {
            case Constants.DATATYPE_NULL:
            case Constants.DATATYPE_UNSUPPORTED:
            case Constants.DATATYPE_TEXT:
            case Constants.DATATYPE_BARCODE:
            case Constants.DATATYPE_BINARY:

                return(new StringData(text));

            case Constants.DATATYPE_INTEGER:

                try
                {
                    return(trimmedText == null ? null : new IntegerData(int.Parse(trimmedText)));
                }
                catch (FormatException nfe)
                {
                    return(null);
                }

            case Constants.DATATYPE_LONG:

                try
                {
                    return(trimmedText == null ? null : new LongData(long.Parse(trimmedText)));
                }
                catch (FormatException nfe)
                {
                    return(null);
                }

            case Constants.DATATYPE_DECIMAL:

                try
                {
                    return(trimmedText == null ? null : new DecimalData(Double.Parse(trimmedText)));
                }
                catch (FormatException nfe)
                {
                    return(null);
                }

            case Constants.DATATYPE_CHOICE:

                ArrayList selections = getSelections(text, q);
                return(selections.Count == 0 ? null : new SelectOneData((Selection)selections[0]));

            case Constants.DATATYPE_CHOICE_LIST:

                return(new SelectMultiData(getSelections(text, q)));

            case Constants.DATATYPE_DATE_TIME:

                DateTime dt = (trimmedText == null ? DateTime.Now : DateUtils.parseDateTime(trimmedText));
                return(dt == null ? null : new DateTimeData(ref dt));

            case Constants.DATATYPE_DATE:

                DateTime d = (trimmedText == null ? DateTime.Now : DateUtils.parseDate(trimmedText));
                return(d == null ? null : new DateData(ref d));

            case Constants.DATATYPE_TIME:

                DateTime t = (trimmedText == null ? DateTime.Now : DateUtils.parseTime(trimmedText));
                return(t == null ? null : new TimeData(ref t));

            case Constants.DATATYPE_BOOLEAN:

                if (trimmedText == null)
                {
                    return(null);
                }
                else
                {
                    if (trimmedText.Equals("1"))
                    {
                        return(new BooleanData(true));
                    }
                    if (trimmedText.Equals("0"))
                    {
                        return(new BooleanData(false));
                    }
                    return(trimmedText.Equals("t") ? new BooleanData(true) : new BooleanData(false));
                }

            case Constants.DATATYPE_GEOPOINT:

                try
                {
                    List <String> gpv = (trimmedText == null ? null : DateUtils.split(trimmedText, " ", false));

                    int      len = gpv.Count;
                    double[] gp  = new double[len];
                    for (int i = 0; i < len; i++)
                    {
                        gp[i] = Double.Parse(((String)gpv[i]));
                    }
                    return(new GeoPointData(gp));
                }
                catch (FormatException nfe)
                {
                    return(null);
                }

            default:
                return(new UncastData(trimmedText));
            }
        }
Пример #30
0
        ///<summary>Ok to delete whenever, because no patients are tied to this table by any dependencies.</summary>
        public static void Delete(QuestionDef def)
        {
            string command = "DELETE FROM questiondef WHERE QuestionDefNum =" + POut.PInt(def.QuestionDefNum);

            General.NonQ(command);
        }
Пример #31
0
        public static void Initialize(MIQuizContext context)
        {
            context.Database.EnsureCreated();

            var demoUser = "******";
            var demoQuiz = "LaneBoyQuiz";

            // Check if records exist... if so then no need to run seed methods.
            //if(context.Users.Any() && context.Quizes.Any() && context.Questions.Any() && context.Answers.Any() ) {
            //    return;
            //}

            // Seeds of proserity
            var users = new User[] {
                new User {
                    IsActive = true, FirstName = "Demo", LastName = "User", UserName = demoUser, Role = 0
                }
            };

            foreach (User u in users)
            {
                context.Users.Add(u);
            }
            context.SaveChanges();
            var demoUserId = users.Single(u => u.UserName.Equals(demoUser)).UserId;

            var quizDefs = new QuizDef[] {
                new QuizDef {
                    Name        = demoQuiz,
                    Description = "This is a test... it is only a test.", Instructions = "Do the thing.", GradingCriteria = "Largely based on feels, you know like college.", IsActive = true, UserId = demoUserId
                }
            };

            foreach (QuizDef qd in quizDefs)
            {
                context.Quizes.Add(qd);
            }
            context.SaveChanges();
            var demoQuizId = quizDefs.Single(q => q.Name.Equals(demoQuiz)).QuizId;


            var questionDefs = new QuestionDef[] {
                new QuestionDef {
                    IsActive = true, Type = "MC", Text = "Multiple Choice Question With Single Correct Answer?"
                },
                new QuestionDef {
                    IsActive = true, Type = "MC", Text = "Multiple Choice Question With Several Correct Answers?"
                },
                new QuestionDef {
                    IsActive = true, Type = "MC", Text = "Textual Question With Single Correct Answer... How many correct answers are there to this question?"
                },
                new QuestionDef {
                    IsActive = true, Type = "MC", Text = "Textual Question With Several Correct Answers... Can this question have more than one correct answer?"
                },
                new QuestionDef {
                    IsActive = true, Type = "MC", Text = "True/False Type Question With Traditional Answers?"
                },
                new QuestionDef {
                    IsActive = true, Type = "MC", Text = "True/False Type Question With Different Text For Answers?"
                }
            };

            foreach (QuestionDef qd in questionDefs)
            {
                context.Questions.Add(qd);
            }
            context.SaveChanges();

            var answerDefs = new AnswerDef[] {
                new AnswerDef {
                    IsActive = true, Text = "This is a multiple choice type question with one correct answer."
                },
                new AnswerDef {
                    IsActive = true, Text = "This is not a multiple choice type question."
                },
                new AnswerDef {
                    IsActive = true, Text = "Pigs can fly every bit as well as an web application developer."
                },
                new AnswerDef {
                    IsActive = true, Text = "This is not the API you are looking for..."
                },
                new AnswerDef {
                    IsActive = true, Text = "This is a multiple choice type question with several correct answers."
                },
                new AnswerDef {
                    IsActive = true, Text = "This is not a multiple choice type question."
                },
                new AnswerDef {
                    IsActive = true, Text = "This answer could be correct as well."
                },
                new AnswerDef {
                    IsActive = true, Text = "This is not the API you are looking for..."
                },
                new AnswerDef {
                    IsActive = true, Text = "one"
                },
                new AnswerDef {
                    IsActive = true, Text = "1"
                },
                new AnswerDef {
                    IsActive = true, Text = "yes"
                },
                new AnswerDef {
                    IsActive = true, Text = "yup"
                },
                new AnswerDef {
                    IsActive = true, Text = "absolutely"
                },
                new AnswerDef {
                    IsActive = true, Text = "for sursies"
                },
                new AnswerDef {
                    IsActive = true, Text = "True"
                },
                new AnswerDef {
                    IsActive = true, Text = "False"
                },
                new AnswerDef {
                    IsActive = true, Text = "Whaaaaaaattttt..."
                },
                new AnswerDef {
                    IsActive = true, Text = "Oh for sure it is!"
                },
            };

            foreach (AnswerDef ad in answerDefs)
            {
                context.Answers.Add(ad);
            }
            context.SaveChanges();

            var quizToQuestion = new JoinQuizQuestion[] {
                new JoinQuizQuestion {
                    QuizId = demoQuizId, Question = questionDefs[0]
                },                                                                   //Multiple Choice Question With Single Correct Answer?
                new JoinQuizQuestion {
                    QuizId = demoQuizId, Question = questionDefs[1]
                },                                                                   //Multiple Choice Question With Several Correct Answers?
                new JoinQuizQuestion {
                    QuizId = demoQuizId, Question = questionDefs[2]
                },                                                                   //Textual Question With Single Correct Answer... How many correct answers are there to this question?
                new JoinQuizQuestion {
                    QuizId = demoQuizId, Question = questionDefs[3]
                },                                                                   //Textual Question With Several Correct Answers... Can this question have more than one correct answer?
                new JoinQuizQuestion {
                    QuizId = demoQuizId, Question = questionDefs[4]
                },                                                                   //True/False Type Question With Traditional Answers?
                new JoinQuizQuestion {
                    QuizId = demoQuizId, Question = questionDefs[5]
                }                                                                    //True/False Type Question With Different Text For Answers?
            };

            // Add stuff to set up JoinQuizQuestion (QuizQuestionTbl)
            context.AddRange(quizToQuestion);
            context.SaveChanges();

            var questionToAnswer = new JoinQuestionAnswer[] {
                //Multiple Choice Question With Single Correct Answer?
                new JoinQuestionAnswer {
                    Question = questionDefs[0], Answer = answerDefs[0], IsCorrectAnswer = true
                },                                                                                                 //This is a multiple choice type question with one correct answer.
                new JoinQuestionAnswer {
                    Question = questionDefs[0], Answer = answerDefs[1], IsCorrectAnswer = false
                },                                                                                                 //This is not a multiple choice type question.
                new JoinQuestionAnswer {
                    Question = questionDefs[0], Answer = answerDefs[2], IsCorrectAnswer = false
                },                                                                                                 //Pigs can fly every bit as well as an web application developer.
                new JoinQuestionAnswer {
                    Question = questionDefs[0], Answer = answerDefs[3], IsCorrectAnswer = false
                },                                                                                                 //This is not the API you are looking for...
                //Multiple Choice Question With Several Correct Answers?
                new JoinQuestionAnswer {
                    Question = questionDefs[1], Answer = answerDefs[4], IsCorrectAnswer = true
                },                                                                                                 //This is a multiple choice type question with several correct answers.
                new JoinQuestionAnswer {
                    Question = questionDefs[1], Answer = answerDefs[5], IsCorrectAnswer = false
                },                                                                                                 //This is not a multiple choice type question.
                new JoinQuestionAnswer {
                    Question = questionDefs[1], Answer = answerDefs[6], IsCorrectAnswer = true
                },                                                                                                 //This answer could be correct as well.
                new JoinQuestionAnswer {
                    Question = questionDefs[1], Answer = answerDefs[7], IsCorrectAnswer = false
                },                                                                                                 //This is not the API you are looking for...
                //Textual Question With Single Correct Answer... How many correct answers are there to this question?
                new JoinQuestionAnswer {
                    Question = questionDefs[2], Answer = answerDefs[8], IsCorrectAnswer = true
                },                                                                                                //one
                new JoinQuestionAnswer {
                    Question = questionDefs[2], Answer = answerDefs[9], IsCorrectAnswer = true
                },                                                                                                //1
                //Textual Question With Several Correct Answers... Can this question have more than one correct answer?
                new JoinQuestionAnswer {
                    Question = questionDefs[3], Answer = answerDefs[10], IsCorrectAnswer = true
                },                                                                                                 //yes
                new JoinQuestionAnswer {
                    Question = questionDefs[3], Answer = answerDefs[11], IsCorrectAnswer = true
                },                                                                                                 //yup
                new JoinQuestionAnswer {
                    Question = questionDefs[3], Answer = answerDefs[12], IsCorrectAnswer = true
                },                                                                                                 //absolutely
                new JoinQuestionAnswer {
                    Question = questionDefs[3], Answer = answerDefs[13], IsCorrectAnswer = true
                },                                                                                                 //for sursies
                //True/False Type Question With Traditional Answers?
                new JoinQuestionAnswer {
                    Question = questionDefs[4], Answer = answerDefs[14], IsCorrectAnswer = true
                },                                                                                                 //True
                new JoinQuestionAnswer {
                    Question = questionDefs[4], Answer = answerDefs[15], IsCorrectAnswer = true
                },                                                                                                 //False
                //True/False Type Question With Different Text For Answers?
                new JoinQuestionAnswer {
                    Question = questionDefs[5], Answer = answerDefs[16], IsCorrectAnswer = true
                },                                                                                                 //Whaaaaaaattttt...
                new JoinQuestionAnswer {
                    Question = questionDefs[5], Answer = answerDefs[17], IsCorrectAnswer = true
                }                                                                                                  //Oh for sure it is!
            };

            context.AddRange(questionToAnswer);
            context.SaveChanges();
        }
Пример #32
0
 ///<summary>Inserts one QuestionDef into the database.  Returns the new priKey.</summary>
 public static long Insert(QuestionDef questionDef)
 {
     return(Insert(questionDef, false));
 }
Пример #33
0
		///<summary>Updates one QuestionDef in the database.  Uses an old object to compare to, and only alters changed fields.  This prevents collisions and concurrency problems in heavily used tables.</summary>
		public static void Update(QuestionDef questionDef,QuestionDef oldQuestionDef){
			string command="";
			if(questionDef.Description != oldQuestionDef.Description) {
				if(command!=""){ command+=",";}
				command+="Description = '"+POut.String(questionDef.Description)+"'";
			}
			if(questionDef.ItemOrder != oldQuestionDef.ItemOrder) {
				if(command!=""){ command+=",";}
				command+="ItemOrder = "+POut.Int(questionDef.ItemOrder)+"";
			}
			if(questionDef.QuestType != oldQuestionDef.QuestType) {
				if(command!=""){ command+=",";}
				command+="QuestType = "+POut.Int   ((int)questionDef.QuestType)+"";
			}
			if(command==""){
				return;
			}
			command="UPDATE questiondef SET "+command
				+" WHERE QuestionDefNum = "+POut.Long(questionDef.QuestionDefNum);
			Db.NonQ(command);
		}
Пример #34
0
		///<summary>Updates one QuestionDef in the database.</summary>
		public static void Update(QuestionDef questionDef){
			string command="UPDATE questiondef SET "
				+"Description   = '"+POut.String(questionDef.Description)+"', "
				+"ItemOrder     =  "+POut.Int   (questionDef.ItemOrder)+", "
				+"QuestType     =  "+POut.Int   ((int)questionDef.QuestType)+" "
				+"WHERE QuestionDefNum = "+POut.Long(questionDef.QuestionDefNum);
			Db.NonQ(command);
		}
Пример #35
0
        //note: code overlap with FormDef.copyItemsetAnswer
        public IAnswerData getAnswerValue()
        {
            QuestionDef q = getQuestion();

            ItemsetBinding itemset = q.getDynamicChoices();

            if (itemset != null)
            {
                if (itemset.valueRef != null)
                {
                    List <SelectChoice> choices           = getSelectChoices();
                    List <String>       preselectedValues = new List <String>();

                    //determine which selections are already present in the answer
                    if (itemset.copyMode)
                    {
                        TreeReference        destRef  = itemset.getDestRef().contextualize(mTreeElement.getRef());
                        List <TreeReference> subNodes = form.Instance.expandReference(destRef);
                        for (int i = 0; i < subNodes.Count; i++)
                        {
                            TreeElement node  = form.Instance.resolveReference(subNodes[i]);
                            String      value = itemset.getRelativeValue().evalReadable(form.Instance, new EvaluationContext(form.exprEvalContext, node.getRef()));
                            preselectedValues.Add(value);
                        }
                    }
                    else
                    {
                        List <Selection> sels = new List <Selection>();
                        IAnswerData      data = mTreeElement.getValue();
                        if (data is SelectMultiData)
                        {
                            sels = (List <Selection>)data.Value;
                        }
                        else if (data is SelectOneData)
                        {
                            sels = new List <Selection>();
                            sels.Add((Selection)data.Value);
                        }
                        for (int i = 0; i < sels.Count; i++)
                        {
                            preselectedValues.Add(sels[i].xmlValue);
                        }
                    }

                    //populate 'selection' with the corresponding choices (matching 'value') from the dynamic choiceset
                    List <Selection> selection = new List <Selection>();
                    for (int i = 0; i < preselectedValues.Count; i++)
                    {
                        String       value  = preselectedValues[i];
                        SelectChoice choice = null;
                        for (int j = 0; j < choices.Count; j++)
                        {
                            SelectChoice ch = choices[j];
                            if (value.Equals(ch.Value))
                            {
                                choice = ch;
                                break;
                            }
                        }

                        selection.Add(choice.selection());
                    }

                    //convert to IAnswerData
                    if (selection.Count == 0)
                    {
                        return(null);
                    }
                    else if (q.ControlType == Constants.CONTROL_SELECT_MULTI)
                    {
                        return(new SelectMultiData(selection));
                    }
                    else if (q.ControlType == Constants.CONTROL_SELECT_ONE)
                    {
                        return(new SelectOneData(selection[0])); //do something if more than one selected?
                    }
                    else
                    {
                        throw new SystemException("can't happen");
                    }
                }
                else
                {
                    return(null); //cannot map up selections without <value>
                }
            }
            else
            { //static choices
                return(mTreeElement.getValue());
            }
        }