Ejemplo n.º 1
0
        public bool mdl_user_Them(DataTable dsuser)
        {
            DbAccess db = new DbAccess();

            db.BeginTransaction();
            try
            {
                for (int i = 0; i < dsuser.Rows.Count; i++)
                {
                    id           = Int64.Parse(dsuser.Rows[i]["id"].ToString());
                    auth         = (dsuser.Rows[i]["auth"].ToString());
                    confirmed    = bool.Parse(dsuser.Rows[i]["confirmed"].ToString());
                    policyagreed = bool.Parse(dsuser.Rows[i]["policyagreed"].ToString());
                    deleted      = bool.Parse(dsuser.Rows[i]["deleted"].ToString());
                    suspended    = bool.Parse(dsuser.Rows[i]["suspended"].ToString());
                    mnethostid   = Int64.Parse(dsuser.Rows[i]["mnethostid"].ToString());
                    username     = dsuser.Rows[i]["username"].ToString();
                    password     = dsuser.Rows[i]["password"].ToString();
                    idnumber     = dsuser.Rows[i]["idnumber"].ToString();
                    firstname    = dsuser.Rows[i]["firstname"].ToString();
                    lastname     = dsuser.Rows[i]["lastname"].ToString();
                    email        = dsuser.Rows[i]["email"].ToString();
                    emailstop    = bool.Parse(dsuser.Rows[i]["emailstop"].ToString());
                    icq          = dsuser.Rows[i]["icq"].ToString();
                    skype        = dsuser.Rows[i]["skype"].ToString();
                    yahoo        = dsuser.Rows[i]["yahoo"].ToString();
                    aim          = dsuser.Rows[i]["aim"].ToString();
                    msn          = dsuser.Rows[i]["msn"].ToString();
                    phone1       = dsuser.Rows[i]["phone1"].ToString();
                    phone2       = dsuser.Rows[i]["phone2"].ToString();
                    institution  = dsuser.Rows[i]["institution"].ToString();
                    department   = dsuser.Rows[i]["department"].ToString();
                    address      = dsuser.Rows[i]["address"].ToString();
                    city         = dsuser.Rows[i]["city"].ToString();
                    country      = dsuser.Rows[i]["country"].ToString();
                    lang         = dsuser.Rows[i]["lang"].ToString();
                    calendartype = dsuser.Rows[i]["calendartype"].ToString();
                    theme        = dsuser.Rows[i]["theme"].ToString();
                    timezone     = dsuser.Rows[i]["timezone"].ToString();
                    firstaccess  = Int64.Parse(dsuser.Rows[i]["firstaccess"].ToString());
                    lastaccess   = Int64.Parse(dsuser.Rows[i]["lastaccess"].ToString());
                    lastlogin    = Int64.Parse(dsuser.Rows[i]["lastlogin"].ToString());
                    currentlogin = Int64.Parse(dsuser.Rows[i]["currentlogin"].ToString());
                    lastip       = dsuser.Rows[i]["lastip"].ToString();
                    secret       = dsuser.Rows[i]["secret"].ToString();
                    picture      = dsuser.Rows[i]["picture"].ToString();
                    url          = dsuser.Rows[i]["url"].ToString();
                    description  = dsuser.Rows[i]["description"].ToString();
                    if (dsuser.Rows[i]["descriptionformat"].ToString() != "")
                    {
                        descriptionformat = int.Parse(dsuser.Rows[i]["descriptionformat"].ToString());
                    }
                    else
                    {
                        descriptionformat = 0;
                    }
                    if (dsuser.Rows[i]["mailformat"].ToString() != "")
                    {
                        mailformat = bool.Parse(dsuser.Rows[i]["mailformat"].ToString());
                    }
                    else
                    {
                        mailformat = false;
                    }
                    if (dsuser.Rows[i]["maildigest"].ToString() != "")
                    {
                        maildigest = bool.Parse(dsuser.Rows[i]["maildigest"].ToString());
                    }
                    else
                    {
                        maildigest = false;
                    }
                    if (dsuser.Rows[i]["maildisplay"].ToString() != "")
                    {
                        maildisplay = int.Parse(dsuser.Rows[i]["maildisplay"].ToString());
                    }
                    else
                    {
                        maildisplay = 0;
                    }
                    if (dsuser.Rows[i]["autosubscribe"].ToString() != "")
                    {
                        autosubscribe = bool.Parse(dsuser.Rows[i]["autosubscribe"].ToString());
                    }
                    else
                    {
                        autosubscribe = false;
                    }
                    if (dsuser.Rows[i]["trackforums"].ToString() != "")
                    {
                        trackforums = bool.Parse(dsuser.Rows[i]["trackforums"].ToString());
                    }
                    else
                    {
                        trackforums = false;
                    }
                    timecreated       = dsuser.Rows[i]["timecreated"].ToString();
                    timemodified      = dsuser.Rows[i]["timemodified"].ToString();
                    trustbitmask      = dsuser.Rows[i]["trustbitmask"].ToString();
                    imagealt          = dsuser.Rows[i]["imagealt"].ToString();
                    lastnamephonetic  = dsuser.Rows[i]["lastnamephonetic"].ToString();
                    firstnamephonetic = dsuser.Rows[i]["firstnamephonetic"].ToString();
                    middlename        = dsuser.Rows[i]["middlename"].ToString();
                    alternatename     = dsuser.Rows[i]["alternatename"].ToString();

                    db.CreateNewSqlCommand();
                    db.AddParameter("@id", id);
                    db.AddParameter("@auth", auth);
                    db.AddParameter("@confirmed", confirmed);
                    db.AddParameter("@policyagreed", policyagreed);
                    db.AddParameter("@deleted", deleted);
                    db.AddParameter("@suspended", suspended);
                    db.AddParameter("@mnethostid", mnethostid);
                    db.AddParameter("@username", username);
                    db.AddParameter("@password", password);
                    db.AddParameter("@idnumber", idnumber);
                    db.AddParameter("@firstname", firstname);
                    db.AddParameter("@lastname", lastname);
                    db.AddParameter("@email", email);
                    db.AddParameter("@emailstop", emailstop);
                    db.AddParameter("@icq", icq);
                    db.AddParameter("@skype", skype);
                    db.AddParameter("@yahoo", yahoo);
                    db.AddParameter("@aim", aim);
                    db.AddParameter("@msn", msn);
                    db.AddParameter("@phone1", phone1);
                    db.AddParameter("@phone2", phone2);
                    db.AddParameter("@institution", institution);
                    db.AddParameter("@department", department);
                    db.AddParameter("@address", address);
                    db.AddParameter("@city", city);
                    db.AddParameter("@country", country);
                    db.AddParameter("@lang", lang);
                    db.AddParameter("@calendartype", calendartype);
                    db.AddParameter("@theme", theme);
                    db.AddParameter("@timezone", timezone);
                    db.AddParameter("@firstaccess", firstaccess);
                    db.AddParameter("@lastaccess", lastaccess);
                    db.AddParameter("@lastlogin", lastlogin);
                    db.AddParameter("@currentlogin", currentlogin);
                    db.AddParameter("@lastip", lastip);
                    db.AddParameter("@secret", secret);
                    db.AddParameter("@picture", picture);
                    db.AddParameter("@url", url);
                    db.AddParameter("@description", description);
                    db.AddParameter("@descriptionformat", descriptionformat);
                    db.AddParameter("@mailformat", mailformat);
                    db.AddParameter("@maildigest", maildigest);
                    db.AddParameter("@maildisplay", maildisplay);
                    db.AddParameter("@autosubscribe", autosubscribe);
                    db.AddParameter("@trackforums", trackforums);
                    db.AddParameter("@timecreated", timecreated);
                    db.AddParameter("@timemodified", timemodified);
                    db.AddParameter("@trustbitmask", trustbitmask);
                    db.AddParameter("@imagealt", imagealt);
                    db.AddParameter("@lastnamephonetic", lastnamephonetic);
                    db.AddParameter("@firstnamephonetic", firstnamephonetic);
                    db.AddParameter("@middlename", middlename);
                    db.AddParameter("@alternatename", alternatename);
                    db.ExecuteNonQueryWithTransaction("mdl_user_Them");
                }
                db.CommitTransaction();
                return(true);
            }
            catch
            {
                db.RollbackTransaction();
                return(false);
            }
        }
        public bool mdl_quiz_them(DataTable dsquiz)
        {
            DbAccess db = new DbAccess();

            db.BeginTransaction();
            try
            {
                for (int i = 0; i < dsquiz.Rows.Count; i++)
                {
                    db.CreateNewSqlCommand();
                    id                          = float.Parse(dsquiz.Rows[i]["id"].ToString());
                    course                      = float.Parse(dsquiz.Rows[i]["course"].ToString());
                    name                        = dsquiz.Rows[i]["name"].ToString();
                    intro                       = dsquiz.Rows[i]["intro"].ToString();
                    introformat                 = float.Parse(dsquiz.Rows[i]["introformat"].ToString());
                    timeopen                    = float.Parse(dsquiz.Rows[i]["timeopen"].ToString());
                    timeclose                   = float.Parse(dsquiz.Rows[i]["timeclose"].ToString());
                    timelimit                   = float.Parse(dsquiz.Rows[i]["timelimit"].ToString());
                    overduehandling             = dsquiz.Rows[i]["overduehandling"].ToString();
                    graceperiod                 = float.Parse(dsquiz.Rows[i]["graceperiod"].ToString());
                    preferredbehaviour          = dsquiz.Rows[i]["preferredbehaviour"].ToString();
                    canredoquestions            = float.Parse(dsquiz.Rows[i]["canredoquestions"].ToString());
                    attempts                    = int.Parse(dsquiz.Rows[i]["attempts"].ToString());
                    attemptonlast               = float.Parse(dsquiz.Rows[i]["attemptonlast"].ToString());
                    grademethod                 = float.Parse(dsquiz.Rows[i]["grademethod"].ToString());
                    decimalpoints               = float.Parse(dsquiz.Rows[i]["decimalpoints"].ToString());
                    questiondecimalpoints       = float.Parse(dsquiz.Rows[i]["questiondecimalpoints"].ToString());
                    reviewattempt               = int.Parse(dsquiz.Rows[i]["reviewattempt"].ToString());
                    reviewcorrectness           = int.Parse(dsquiz.Rows[i]["reviewcorrectness"].ToString());
                    reviewmarks                 = int.Parse(dsquiz.Rows[i]["reviewmarks"].ToString());
                    reviewspecificfeedback      = int.Parse(dsquiz.Rows[i]["reviewspecificfeedback"].ToString());
                    reviewgeneralfeedback       = int.Parse(dsquiz.Rows[i]["reviewgeneralfeedback"].ToString());
                    reviewrightanswer           = int.Parse(dsquiz.Rows[i]["reviewrightanswer"].ToString());
                    reviewoverallfeedback       = int.Parse(dsquiz.Rows[i]["reviewoverallfeedback"].ToString());
                    questionsperpage            = float.Parse(dsquiz.Rows[i]["questionsperpage"].ToString());
                    navmethod                   = dsquiz.Rows[i]["navmethod"].ToString();
                    shuffleanswers              = dsquiz.Rows[i]["shuffleanswers"].ToString();
                    sumgrades                   = float.Parse(dsquiz.Rows[i]["sumgrades"].ToString());
                    grade                       = float.Parse(dsquiz.Rows[i]["grade"].ToString());
                    timecreated                 = float.Parse(dsquiz.Rows[i]["timecreated"].ToString());
                    timemodified                = float.Parse(dsquiz.Rows[i]["timemodified"].ToString());
                    password                    = dsquiz.Rows[i]["password"].ToString();
                    subnet                      = dsquiz.Rows[i]["subnet"].ToString();
                    browsersecurity             = dsquiz.Rows[i]["browsersecurity"].ToString();
                    delay1                      = float.Parse(dsquiz.Rows[i]["delay1"].ToString());
                    delay2                      = float.Parse(dsquiz.Rows[i]["delay2"].ToString());
                    showuserpicture             = float.Parse(dsquiz.Rows[i]["showuserpicture"].ToString());
                    showblocks                  = float.Parse(dsquiz.Rows[i]["showblocks"].ToString());
                    completionattemptsexhausted = bool.Parse(dsquiz.Rows[i]["completionattemptsexhausted"].ToString());
                    completionpass              = bool.Parse(dsquiz.Rows[i]["completionpass"].ToString());
                    allowofflineattempts        = bool.Parse(dsquiz.Rows[i]["allowofflineattempts"].ToString());

                    db.AddParameter("@id", id);
                    db.AddParameter("@course", course);
                    db.AddParameter("@name", name);
                    db.AddParameter("@intro", intro);
                    db.AddParameter("@introformat", introformat);
                    db.AddParameter("@timeopen", timeopen);
                    db.AddParameter("@timeclose", timeclose);
                    db.AddParameter("@timelimit", timelimit);
                    db.AddParameter("@overduehandling", overduehandling);
                    db.AddParameter("@graceperiod", graceperiod);
                    db.AddParameter("@preferredbehaviour", preferredbehaviour);
                    db.AddParameter("@canredoquestions", canredoquestions);
                    db.AddParameter("@attempts", attempts);
                    db.AddParameter("@attemptonlast", attemptonlast);
                    db.AddParameter("@grademethod", grademethod);
                    db.AddParameter("@decimalpoints", decimalpoints);
                    db.AddParameter("@questiondecimalpoints", questiondecimalpoints);
                    db.AddParameter("@reviewattempt", reviewattempt);
                    db.AddParameter("@reviewcorrectness", reviewcorrectness);
                    db.AddParameter("@reviewmarks", reviewmarks);
                    db.AddParameter("@reviewspecificfeedback", reviewspecificfeedback);
                    db.AddParameter("@reviewgeneralfeedback", reviewgeneralfeedback);
                    db.AddParameter("@reviewrightanswer", reviewrightanswer);
                    db.AddParameter("@reviewoverallfeedback", reviewoverallfeedback);
                    db.AddParameter("@questionsperpage", questionsperpage);
                    db.AddParameter("@navmethod", navmethod);
                    db.AddParameter("@shuffleanswers", shuffleanswers);
                    db.AddParameter("@sumgrades", sumgrades);
                    db.AddParameter("@grade", grade);
                    db.AddParameter("@timecreated", timecreated);
                    db.AddParameter("@timemodified", timemodified);
                    db.AddParameter("@password", password);
                    db.AddParameter("@subnet", subnet);
                    db.AddParameter("@browsersecurity", browsersecurity);
                    db.AddParameter("@delay1", delay1);
                    db.AddParameter("@delay2", delay2);
                    db.AddParameter("@showuserpicture", showuserpicture);
                    db.AddParameter("@showblocks", showblocks);
                    db.AddParameter("@completionattemptsexhausted", completionattemptsexhausted);
                    db.AddParameter("@completionpass", completionpass);
                    db.AddParameter("@allowofflineattempts", allowofflineattempts);
                    db.ExecuteNonQueryWithTransaction("mdl_quiz_them");
                }
                db.CommitTransaction();
                return(true);
            }
            catch
            {
                db.RollbackTransaction();
                return(false);
            }
        }
        public bool mdl_question_usages_Them(DataTable ds_mdl_question_attempts, DataTable ds_mdl_quiz_attempts)
        {
            DbAccess db = new DbAccess();

            db.BeginTransaction();
            try
            {
                db.CreateNewSqlCommand();
                db.AddParameter("@contextid", contextid);
                db.AddParameter("@component", component);
                db.AddParameter("@preferredbehaviour", preferredbehaviour);
                int questionusage_id = db.ExecuteScalarWithTransaction("mdl_question_usages_Them");
                //------------------
                ds_questionattempt_id.Clear();
                ds_questionattempt_id.Columns.Clear();
                ds_questionattempt_id.Columns.Add("questionusage_id");
                //------------------
                db.CreateNewSqlCommand();
                db.AddParameter("@quiz", ds_mdl_quiz_attempts.Rows[0][1].ToString());
                db.AddParameter("@userid", ds_mdl_quiz_attempts.Rows[0][2].ToString());
                db.AddParameter("@attempt", ds_mdl_quiz_attempts.Rows[0][3].ToString());
                db.AddParameter("@uniqueid", questionusage_id.ToString());
                db.AddParameter("@layout", ds_mdl_quiz_attempts.Rows[0][5].ToString());
                db.AddParameter("@currentpage", ds_mdl_quiz_attempts.Rows[0][6].ToString());
                db.AddParameter("@preview", ds_mdl_quiz_attempts.Rows[0][7].ToString());
                db.AddParameter("@state", ds_mdl_quiz_attempts.Rows[0][8].ToString());
                db.AddParameter("@timestart", ds_mdl_quiz_attempts.Rows[0][9].ToString());
                db.AddParameter("@timefinish", ds_mdl_quiz_attempts.Rows[0][10].ToString());
                db.AddParameter("@timemodified", ds_mdl_quiz_attempts.Rows[0][11].ToString());
                db.AddParameter("@timemodifiedoffline", ds_mdl_quiz_attempts.Rows[0][12].ToString());
                db.AddParameter("@timecheckstate", ds_mdl_quiz_attempts.Rows[0][13].ToString());
                db.AddParameter("@sumgrades", ds_mdl_quiz_attempts.Rows[0][14].ToString());
                db.ExecuteNonQueryWithTransaction("mdl_quiz_attempts_Them");

                //---------
                for (int i = 0; i < ds_mdl_question_attempts.Rows.Count; i++)
                {
                    db.CreateNewSqlCommand();
                    db.AddParameter("@questionusageid", questionusage_id);
                    db.AddParameter("@slot", ds_mdl_question_attempts.Rows[i][2].ToString());
                    db.AddParameter("@behaviour", ds_mdl_question_attempts.Rows[i][3].ToString());
                    db.AddParameter("@questionid", ds_mdl_question_attempts.Rows[i][4].ToString());
                    db.AddParameter("@variant", ds_mdl_question_attempts.Rows[i][5].ToString());
                    db.AddParameter("@maxmark", ds_mdl_question_attempts.Rows[i][6].ToString());
                    db.AddParameter("@minfraction", ds_mdl_question_attempts.Rows[i][7].ToString());
                    db.AddParameter("@maxfraction", ds_mdl_question_attempts.Rows[i][8].ToString());
                    db.AddParameter("@flagged", bool.Parse(ds_mdl_question_attempts.Rows[i][9].ToString()));
                    db.AddParameter("@questionsummary", ds_mdl_question_attempts.Rows[i][10].ToString());
                    db.AddParameter("@rightanswer", ds_mdl_question_attempts.Rows[i][11].ToString());
                    db.AddParameter("@responsesummary", ds_mdl_question_attempts.Rows[i][12].ToString());
                    db.AddParameter("@timemodified", ds_mdl_question_attempts.Rows[i][13].ToString());
                    questionattempt_id = db.ExecuteScalarWithTransaction("mdl_question_attempts_Them");

                    //--------------todo
                    ds_mdl_question_attempt_steps = mdl_question_attempt_steps_DS(ds_mdl_question_attempts.Rows[i][0].ToString(), 0.ToString());
                    db.CreateNewSqlCommand();
                    db.AddParameter("@questionattemptid", questionattempt_id.ToString());
                    ds_questionattempt_id.Rows.Add(questionattempt_id.ToString());
                    db.AddParameter("@sequencenumber", ds_mdl_question_attempt_steps.Rows[0][2].ToString());
                    db.AddParameter("@state", ds_mdl_question_attempt_steps.Rows[0][3].ToString());
                    if ((ds_mdl_question_attempt_steps.Rows[0][4].ToString()) == "")
                    {
                        db.AddParameter("@fraction", DBNull.Value);
                    }
                    else
                    {
                        db.AddParameter("@fraction", (ds_mdl_question_attempt_steps.Rows[0][4].ToString()));
                    }
                    db.AddParameter("@timecreated", ds_mdl_question_attempt_steps.Rows[0][5].ToString());
                    db.AddParameter("@userid", ds_mdl_question_attempt_steps.Rows[0][6].ToString());
                    attemptstep_id = db.ExecuteScalarWithTransaction("mdl_question_attempt_steps_Them");
                    ds_mdl_question_attempt_step_data = mdl_question_attempt_step_data_DS(ds_mdl_question_attempt_steps.Rows[0][0].ToString());//_order
                    db.CreateNewSqlCommand();
                    db.AddParameter("@attemptstepid", attemptstep_id.ToString());
                    db.AddParameter("@name", ds_mdl_question_attempt_step_data.Rows[0][2].ToString());
                    db.AddParameter("@value", ds_mdl_question_attempt_step_data.Rows[0][3].ToString());
                    db.ExecuteNonQueryWithTransaction("mdl_question_attempt_step_data_Them");
                }
                for (int i = 0; i < ds_mdl_question_attempts.Rows.Count; i++)
                {
                    //--------------complete
                    ds_mdl_question_attempt_steps = mdl_question_attempt_steps_DS(ds_mdl_question_attempts.Rows[i][0].ToString(), 1.ToString());//complete
                    db.CreateNewSqlCommand();
                    db.AddParameter("@questionattemptid", ds_questionattempt_id.Rows[i][0].ToString());
                    db.AddParameter("@sequencenumber", ds_mdl_question_attempt_steps.Rows[0][2].ToString());
                    db.AddParameter("@state", ds_mdl_question_attempt_steps.Rows[0][3].ToString());
                    if ((ds_mdl_question_attempt_steps.Rows[0][4].ToString()) == "")
                    {
                        db.AddParameter("@fraction", DBNull.Value);
                    }
                    else
                    {
                        db.AddParameter("@fraction", (ds_mdl_question_attempt_steps.Rows[0][4].ToString()));
                    }
                    db.AddParameter("@timecreated", ds_mdl_question_attempt_steps.Rows[0][5].ToString());
                    db.AddParameter("@userid", ds_mdl_question_attempt_steps.Rows[0][6].ToString());
                    attemptstep_id = db.ExecuteScalarWithTransaction("mdl_question_attempt_steps_Them");
                    ds_mdl_question_attempt_step_data = mdl_question_attempt_step_data_DS(ds_mdl_question_attempt_steps.Rows[0][0].ToString());//_order
                    db.CreateNewSqlCommand();
                    db.AddParameter("@attemptstepid", attemptstep_id.ToString());
                    db.AddParameter("@name", ds_mdl_question_attempt_step_data.Rows[0][2].ToString());
                    db.AddParameter("@value", ds_mdl_question_attempt_step_data.Rows[0][3].ToString());
                    db.ExecuteNonQueryWithTransaction("mdl_question_attempt_step_data_Them");
                }
                for (int i = 0; i < ds_mdl_question_attempts.Rows.Count; i++)
                {
                    //--------------grade
                    ds_mdl_question_attempt_steps = mdl_question_attempt_steps_DS(ds_mdl_question_attempts.Rows[i][0].ToString(), 2.ToString());
                    if (ds_mdl_question_attempt_steps.Rows.Count > 0)
                    {
                        db.CreateNewSqlCommand();
                        db.AddParameter("@questionattemptid", ds_questionattempt_id.Rows[i][0].ToString());
                        db.AddParameter("@sequencenumber", ds_mdl_question_attempt_steps.Rows[0][2].ToString());
                        db.AddParameter("@state", ds_mdl_question_attempt_steps.Rows[0][3].ToString());
                        if ((ds_mdl_question_attempt_steps.Rows[0][4].ToString()) == "")
                        {
                            db.AddParameter("@fraction", DBNull.Value);
                        }
                        else
                        {
                            db.AddParameter("@fraction", (ds_mdl_question_attempt_steps.Rows[0][4].ToString()));
                        }
                        db.AddParameter("@timecreated", ds_mdl_question_attempt_steps.Rows[0][5].ToString());
                        db.AddParameter("@userid", ds_mdl_question_attempt_steps.Rows[0][6].ToString());
                        attemptstep_id = db.ExecuteScalarWithTransaction("mdl_question_attempt_steps_Them");
                        ds_mdl_question_attempt_step_data = mdl_question_attempt_step_data_DS(ds_mdl_question_attempt_steps.Rows[0][0].ToString());//_order
                        db.CreateNewSqlCommand();
                        db.AddParameter("@attemptstepid", attemptstep_id.ToString());
                        db.AddParameter("@name", ds_mdl_question_attempt_step_data.Rows[0][2].ToString());
                        db.AddParameter("@value", ds_mdl_question_attempt_step_data.Rows[0][3].ToString());
                        db.ExecuteNonQueryWithTransaction("mdl_question_attempt_step_data_Them");
                    }
                }
                db.CommitTransaction();
                return(true);
            }
            catch
            {
                db.RollbackTransaction();
                return(false);
            }
        }