예제 #1
0
파일: RgEx.cs 프로젝트: namluu1998/QuizApp
        public static bool isNonCharSpecialAndNonEmpty(string input, string aliases)
        {
            if (isEmpty(input, aliases))
            {
                return(false);

                {
                    MessBox.MessError(string.Format("{0} cannot contain Specia character !!!", aliases));
                }
                if (!isNonCharSpecial(input))
                {
                    return(false);
                }
            }
            return(true);
        }
예제 #2
0
        public void UpdateQuestion()
        {
            if (RgEx.isEmpty(q_title))
            {
                MessBox.MessWarning("Chưa nhập câu hỏi !!"); return;
            }
            string query = string.Format("update questions set q_title = N'{0}',isImage = {1},explain ='{2}' where q_id = {3}",
                                         q_title, isImage, explain, q_id);

            ReturnClass.ExcuteNonQuery(query, ReturnClass.Status.update);
            //for (int i = 0; i < options.Count; ++i)
            foreach (var dt in options)
            {
                dt.id_Qus = dt.id_Qus ?? this.q_id;
                dt.updateOption();
            }
        }
예제 #3
0
        public static void Delete(int exId)
        {
            string query = string.Format("select count(q_id) from questions where q_fk_ex ={0}", exId);

            if (!MessBox.MessWarning(" Confirm deleted " + ReturnClass.scalarReturn(query) + " questions"))
            {
                return;
            }
            //Process Delete Exams
            query = string.Format("select q_id from questions where q_fk_ex ={0}", exId);
            using (SqlDataReader reader = ReturnClass.readerReturn(query))
            {
                while (reader.Read())
                {
                    Questions.DeleteQuestion(reader.GetInt32(0));
                }
            }
        }
예제 #4
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            string user = txtUsername.Text;
            string pass = txtPassword.Text;

            if (user.Equals("Username") || pass.Equals("Password"))
            {
                MessBox.MessError("Username or Password is Empty !!"); return;
            }
            if (!RgEx.isAlphanumericNotSpace(user, "Username"))
            {
                return;
            }
            if (!RgEx.isAlphanumericNotSpace(pass, "Password"))
            {
                return;
            }
            //MessBox.MessInf(isAd);
            string query = string.Format("select isAd from admin_athu where ad_user='******' and ad_password='******'", user, pass);
            string isAd  = ReturnClass.scalarReturn(query);

            //Check invalid User or password
            if (isAd.Equals(""))
            {
                MessBox.MessError("Invalid Input User or Password"); return;
            }
            //Hide old form login and show form Admin or Students
            try
            {
                this.Hide();
                if (isAd.Equals("True"))
                {
                    username = user;
                    formAdmin.ShowDialog();
                }
                else
                {
                    formStudents.ShowDialog();
                }
                this.Show();
            }catch
            {
            }
        }
예제 #5
0
        public bool setQuestions(int numQues, int exId, int timePer)
        {
            string query       = string.Format("select count(q_id) from questions where q_fk_ex ={0}", exId);
            string IdQuestions = ReturnClass.scalarReturn(query);

            if (string.IsNullOrEmpty(IdQuestions) || int.Parse(IdQuestions) < numQues)
            {
                MessBox.Warning("Num Question or Name Exams invalid "); return(false);
            }
            this.numQues = numQues;
            this.exId    = exId;
            this.timePer = timePer;
            optionMix.Clear();
            check.Clear();
            RandomNumberQs();
            InitRandomChoice();
            currentIndex = -1;
            return(true);
        }
예제 #6
0
        public static bool ExcuteNonQuery(string query)
        {
            bool Result = false;

            try
            {
                //Query Execution
                if (sqlConnection.State == ConnectionState.Closed)
                {
                    sqlConnection.Open();
                }
                SqlCommand command = new SqlCommand(query, sqlConnection);
                Result = command.ExecuteNonQuery() == 0 ? false : true;
            }
            catch (Exception ex)
            {
                MessBox.MessError(ex.Message);
            }
            return(Result);
        }
예제 #7
0
        public static string scalarReturn(string q)
        {
            string s = "";

            //Query Execution
            if (sqlConnection.State == ConnectionState.Closed)
            {
                sqlConnection.Open();
            }
            try
            {
                SqlCommand sqlCommand = new SqlCommand(q, sqlConnection);
                object     ob         = sqlCommand.ExecuteScalar();
                if (ob != null)
                {
                    s = ob.ToString();
                }
            }
            catch (Exception ex) {
                MessBox.MessError(ex.Message);
            }
            sqlConnection.Close();
            return(s);
        }