Example #1
0
 public Frm_Rating(int numStar, DTO_Exercise ex, int timeLeft, int PositionKey) : this(numStar)
 {
     btnRemake.Show();
     canSave          = true;
     this.ex          = ex;
     this.numStar     = numStar;
     this.timeLeft    = timeLeft;
     this.PositionKey = PositionKey;
 }
Example #2
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            Form form = (Form)(((Control)sender).TopLevelControl); //Tìm form ngoài cùng của sender
            int  time = 0;
            //Frm_Typing exercise = new Frm_Typing(BUS_Exercise.FindContent(lbxExerciseList.SelectedItem, ref time), time);
            DTO_Exercise ob       = lbxExerciseList.SelectedItem as DTO_Exercise;
            Frm_Typing   exercise = new Frm_Typing(lbxExerciseList.SelectedItem as DTO_Exercise, true);

            exercise.ShowDialog(form);
        }
Example #3
0
        static public bool SaveDataPause(Object o, int timeleft, int position, int star) //Tìm nội dung bài tập trong
        {
            bool         result = false;
            DTO_Exercise ob     = new DTO_Exercise();

            ob          = o as DTO_Exercise;
            ob.Position = position;
            ob.Timeleft = timeleft;
            ob.Star     = star;
            return(BUS_Exercise.UpdateExercise(ob));
        }
Example #4
0
        static public void AddExercise(string title, int time, string[] lines)
        {
            List <string> text = new List <string>();

            foreach (string s in lines)
            {
                text.Add(s);
            }
            DTO_Exercise exercise = new DTO_Exercise("Paragraph", time, title, text, getFileName(), time, 0, 0);

            DAO_Exercise.AddExercise(exercise);
        }
Example #5
0
        static public void AddExercise(DTO_Exercise exercise)
        {
            XmlDocument xd    = new XmlDocument();
            FileStream  lfile = new FileStream(exerciseXmlFilePath, FileMode.Open);

            xd.Load(lfile);

            XmlElement exerciseNode = xd.CreateElement("Exercise");

            XmlElement titleNode = xd.CreateElement("Title");
            XmlText    titleText = xd.CreateTextNode(exercise.Title);

            XmlElement timeNode = xd.CreateElement("Time");
            XmlText    timeText = xd.CreateTextNode(exercise.Time.ToString());

            XmlElement TimeleftNode = xd.CreateElement("Timeleft");
            XmlText    TimeleftText = xd.CreateTextNode(exercise.Timeleft.ToString());
            XmlElement StarNode     = xd.CreateElement("Star");
            XmlText    StarText     = xd.CreateTextNode(exercise.Star.ToString());
            XmlElement PositionNode = xd.CreateElement("Position");
            XmlText    PositionText = xd.CreateTextNode(exercise.Position.ToString());


            XmlElement fileNameNode = xd.CreateElement("FileName");
            //string fileName = Guid.NewGuid().ToString() + ".txt";
            XmlText fileNameText = xd.CreateTextNode(exercise.FileName);

            titleNode.AppendChild(titleText);
            fileNameNode.AppendChild(fileNameText);
            timeNode.AppendChild(timeText);

            TimeleftNode.AppendChild(TimeleftText);
            StarNode.AppendChild(StarText);
            PositionNode.AppendChild(PositionText);

            exerciseNode.AppendChild(titleNode);
            exerciseNode.AppendChild(timeNode);
            exerciseNode.AppendChild(fileNameNode);

            exerciseNode.AppendChild(TimeleftNode);
            exerciseNode.AppendChild(StarNode);
            exerciseNode.AppendChild(PositionNode);

            xd.DocumentElement.AppendChild(exerciseNode);

            lfile.Close();
            xd.Save(exerciseXmlFilePath);

            //Tạo file chứa nội dung bài tập
            CreateTxtFile(exercise.FileName, exercise.ExerciseText.ToArray());
        }
Example #6
0
        static public DTO_Exercise CreateExercise(DTO_LessonSection section)
        {
            DTO_Exercise exercise = new DTO_Exercise();

            exercise.Title        = section.Name;
            exercise.Time         = section.Time;
            exercise.ExerciseType = section.Type;
            exercise.Timeleft     = section.Time;
            exercise.IsLesson     = true;

            exercise.ExerciseText = DAO_LessonSection.ReadExerciseDetailFromSection(section);

            return(exercise);
        }
Example #7
0
        public Frm_FingerExercise(DTO_Exercise ob)
        {
            InitializeComponent();
            exerciseText = ob.ExerciseText;
            time         = ob.Time;
            timeLeft     = time;
            lbTimer.Text = TimeSpan.FromSeconds(timeLeft).ToString(@"mm\:ss");

            //Đếm số câu trong bài, dùng cho ProgressBar
            numSentence = exerciseText.Count;

            //Cập nhật ProgressBar
            progressBar1.Maximum = numSentence;
            lbStatus.Text        = "Progress: 0/" + numSentence + " sentence.";
        }
Example #8
0
        public static void ShowTypingForm(object sender, EventArgs e)
        {
            DTO_Exercise exerciseText = BUS_UserControls.SearchTypingInfo(sender);

            Form form = (Form)(((Control)sender).TopLevelControl); //Tìm form ngoài cùng của sender

            if (exerciseText.ExerciseType == "Key")
            {
                Frm_FingerExercise exercise = new Frm_FingerExercise(exerciseText);
                exercise.ShowDialog(form);
            }
            else
            {
                Frm_Typing exercise = new Frm_Typing(exerciseText);
                exercise.ShowDialog(form);
            }
        }
Example #9
0
        static public List <DTO_Exercise> FindAllExercise(ref List <string> warningTitles) //Tìm tất cả bài tập trong file Exercise.xml
        {
            XmlDocument xd    = new XmlDocument();
            FileStream  rfile = new FileStream(exerciseXmlFilePath, FileMode.Open);

            xd.Load(rfile);

            List <DTO_Exercise> exercises        = new List <DTO_Exercise>();
            XmlNodeList         exerciseNodeList = xd.GetElementsByTagName("Exercise"); // Tìm danh sách các bài tập

            string        title;
            int           time;
            List <string> text;

            foreach (XmlElement exerciseNode in exerciseNodeList)
            {
                title = exerciseNode.GetElementsByTagName("Title")[0].InnerText;
                time  = int.Parse(exerciseNode.GetElementsByTagName("Time")[0].InnerText);

                string fileName = exerciseNode.GetElementsByTagName("FileName")[0].InnerText;

                string Timeleft = exerciseNode.GetElementsByTagName("Timeleft")[0].InnerText;
                string Star     = exerciseNode.GetElementsByTagName("Star")[0].InnerText;
                string Position = exerciseNode.GetElementsByTagName("Position")[0].InnerText;
                if (FileTxtExist(fileName)) //Nếu file chứa nội dung có tồn tại thì thêm vào danh sách, còn nếu không thì thêm thông tin title của bài tập vào danh sách warningTitles
                {
                    text = ReadTextFromTxt(fileName);
                    DTO_Exercise exercise = new DTO_Exercise("Paragraph", time, title, text, fileName, int.Parse(Timeleft), int.Parse(Position), int.Parse(Star));
                    exercises.Add(exercise);
                }
                else
                {
                    warningTitles.Add(title);
                }
            }

            rfile.Close();

            return(exercises);
        }
Example #10
0
        static public bool UpdateExercise(DTO_Exercise exercise)
        {
            bool result = false;

            try
            {
                XmlDocument xd    = new XmlDocument();
                FileStream  rfile = new FileStream(exerciseXmlFilePath, FileMode.Open);
                xd.Load(rfile);

                List <DTO_Exercise> exercises        = new List <DTO_Exercise>();
                XmlNodeList         exerciseNodeList = xd.GetElementsByTagName("Exercise"); // Tìm danh sách các bài tập

                string        title;
                int           time;
                List <string> text;

                foreach (XmlElement exerciseNode in exerciseNodeList)
                {
                    if (exerciseNode.GetElementsByTagName("FileName")[0].InnerText == exercise.FileName)
                    {
                        exerciseNode.GetElementsByTagName("Title")[0].InnerText    = exercise.Title;
                        exerciseNode.GetElementsByTagName("Time")[0].InnerText     = exercise.Time.ToString();
                        exerciseNode.GetElementsByTagName("Timeleft")[0].InnerText = exercise.Timeleft.ToString();
                        exerciseNode.GetElementsByTagName("Star")[0].InnerText     = exercise.Star.ToString();
                        exerciseNode.GetElementsByTagName("Position")[0].InnerText = exercise.Position.ToString();
                    }
                }

                rfile.Close();
                xd.Save(exerciseXmlFilePath);
                result = true;
            }
            catch (Exception ex)
            {
                result = true;
            }

            return(result);
        }
Example #11
0
 static public bool UpdateExercise(DTO_Exercise ob)
 {
     return(DAO_Exercise.UpdateExercise(ob));
 }
Example #12
0
        //public Frm_Typing(List<string> text, int t)
        //{
        //    //TODO: Thay đổi kích thước font chữ trong RTB_String theo từng loại

        //    InitializeComponent();
        //    time = t;
        //    timeLeft = t;
        //    exerciseText = text;
        //    if (time < 3600)
        //    {
        //        lbTimer.Text = TimeSpan.FromSeconds(timeLeft).ToString(@"mm\:ss");
        //    }
        //    else
        //    {
        //        lbTimer.Text = TimeSpan.FromSeconds(timeLeft).ToString(@"hh\:mm\:ss");
        //    }
        //    RTB_String.Lines = exerciseText.ToArray();

        //    //Tìm index ký tự cuối cùng được hiển thị để scroll
        //    location = RTB_String.GetCharIndexFromPosition(new Point(RTB_String.ClientSize.Width, RTB_String.ClientSize.Height));
        //}
        public Frm_Typing(DTO_Exercise ob)
        {
            InitializeComponent();
            objectmodel = ob;
            time        = objectmodel.Timeleft;
            Title       = objectmodel.Title;
            NameFile    = objectmodel.FileName;
            PositionKey = objectmodel.Position;
            //exerciseText = objectmodel.ExerciseText;
            //BUS.BUS_Typing.FindContent(ob, ref time, ref Title, ref NameFile,ref exerciseText);
            this.type = objectmodel.ExerciseType;

            //Thay đổi kích thước font chữ trong RTB_String theo từng loại
            switch (type)
            {
            case "Word":
                RTB_String.Font = new System.Drawing.Font("Microsoft Sans Serif", 36F);
                break;

            case "Sentence":
                RTB_String.Font = new System.Drawing.Font("Microsoft Sans Serif", 27.5F);
                break;

            case "Paragraph":
                RTB_String.Font = new System.Drawing.Font("Microsoft Sans Serif", 14F);
                break;
            }

            //Xoá các ký tự trằng đầu và cuối đoạn văn, thêm ký hiệu "↵" vào cuối đoạn.
            foreach (string line in objectmodel.ExerciseText)
            {
                if (line.Trim() != "")
                {
                    exerciseText.Add(line.Trim() + "↵");
                }
            }

            timeLeft = time;
            if (time < 3600)
            {
                lbTimer.Text = TimeSpan.FromSeconds(timeLeft).ToString(@"mm\:ss");
            }
            else
            {
                lbTimer.Text = TimeSpan.FromSeconds(timeLeft).ToString(@"hh\:mm\:ss");
            }
            RTB_String.Lines = exerciseText.ToArray();

            //Đếm số câu trong bài, dùng cho ProgressBar
            for (int i = 0; i < RTB_String.Text.Length; i++)
            {
                if (RTB_String.Text[i] == '.' || RTB_String.Text[i] == '?' || RTB_String.Text[i] == '↵')
                {
                    numSentence++;
                }

                if (i > 0 && RTB_String.Text[i] == '↵' && (RTB_String.Text[i - 1] == '.' || RTB_String.Text[i - 1] == '?'))
                {
                    numSentence--;
                }

                if (i < PositionKey)
                {
                    curSentence = numSentence;
                }
            }

            if (ob.Star > 0) //Đã hoàn thành
            {
                finished    = true;
                curSentence = numSentence;
            }

            //Cập nhật ProgressBar
            progressBar1.Maximum = numSentence;
            lbStatus.Text        = "Progress: " + curSentence + "/" + numSentence + " sentence.";

            //Nếu form dùng hiển thị bài học thì ẩn nút save
            if (objectmodel.IsLesson == true)
            {
                btn_save.Hide();
            }

            //Tìm index ký tự cuối cùng được hiển thị để scroll
            location = RTB_String.GetCharIndexFromPosition(new Point(RTB_String.ClientSize.Width, RTB_String.ClientSize.Height));
            LoadKeyPressed();
            ScrollText();
        }
Example #13
0
 public Frm_Typing(DTO_Exercise ob, bool canRemake) : this(ob)
 {
     this.canRemake = canRemake;
 }
Example #14
0
        public static DTO_Exercise SearchTypingInfo(object sender)
        {
            DTO_Exercise exercise = (DTO_Exercise)(((Control)sender).Tag); //Lấy đối tượng DTO_Exercise đc lưu trong tag của label đã nhấn vào

            return(exercise);
        }