public static void Update(GradeField gradeField)
 {
     SqlHelper.ExecuteNonQuery(@"Update T_Grade set
         CompletedDate=@CompletedDate,
         Pagragraph=@Pagragraph,
         Speed=@Speed,
         BackSpace=@BackSpace,
         HitKey=@HitKey,
         KeyLong=@KeyLong,
         WrongWords=@WrongWords,
         WordsCount=@WordsCount,
         KeyCount=@KeyCount,
         CostTime=@CostTime",
         new OleDbParameter("@CompletedDate", gradeField.CompletedDate.ToString("G")),
         new OleDbParameter("@Pagragraph", gradeField.Paragraph),
         new OleDbParameter("@Speed", gradeField.Speed),
         new OleDbParameter("@BackSpace", gradeField.BackSpace),
         new OleDbParameter("@HitKey", gradeField.HitKey),
         new OleDbParameter("@KeyLong", gradeField.KeyLong),
         new OleDbParameter("@WrongWords", gradeField.WrongWords),
         new OleDbParameter("@WordsCount", gradeField.WordsCount),
         new OleDbParameter("@KeyCount", gradeField.KeyCount),
         new OleDbParameter("@CostTime", gradeField.CostTime)
         );
 }
        public static List<GradeField> GetAll()
        {
            DataTable dt = SqlHelper.ExecuteDataTable("Select * from T_Grade");
            List<GradeField> gradeFields = new List<GradeField>();

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                DataRow row = dt.Rows[i];
                GradeField gradeField = new GradeField();
                gradeField = ToDataField(row);
                gradeFields.Add(gradeField);
            }

            return gradeFields;
        }
 public static void Insert(GradeField gradeField)
 {
     SqlHelper.ExecuteNonQuery(@"Insert into T_Grade(
         CompletedDate, Paragraph, Speed, BackSpace, HitKey, KeyLong, WrongWords, WordsCount, KeyCount, CostTime)
         values(@CompletedDate, @Paragraph, @Speed, @BackSpace, @HitKey, @KeyLong, @WrongWords, @WordsCount, @KeyCount, @CostTime)",
         new OleDbParameter("@CompletedDate", gradeField.CompletedDate.ToString("G")),
         new OleDbParameter("@Paragraph", gradeField.Paragraph),
         new OleDbParameter("@Speed", gradeField.Speed),
         new OleDbParameter("@BackSpace", gradeField.BackSpace),
         new OleDbParameter("@HitKey", gradeField.HitKey),
         new OleDbParameter("@KeyLong", gradeField.KeyLong),
         new OleDbParameter("@WrongWords", gradeField.WrongWords),
         new OleDbParameter("@WordsCount", gradeField.WordsCount),
         new OleDbParameter("@KeyCount", gradeField.KeyCount),
         new OleDbParameter("@CostTime", gradeField.CostTime)
         );
 }
        public void InsertTest()
        {
            GradeField gradeField = new GradeField();
            gradeField.CompletedDate = DateTime.Now;
            gradeField.Paragraph = "第N段";
            gradeField.Speed = 14.1234556;
            gradeField.BackSpace = 9;
            gradeField.HitKey = 5.123456;
            gradeField.KeyLong = 2.123456;
            gradeField.WrongWords = 3;
            gradeField.WordsCount = 98;
            gradeField.KeyCount = 123;
            gradeField.CostTime = "0:21.88";

            DataOperationDAL.Insert(gradeField);
            dataCount++;
            Assert.IsNotNull(gradeField);
        }
Ejemplo n.º 5
0
        private void textBoxInput_TextChanged(object sender, EventArgs e)
        {
            try
            {
                if (this.Vabs(this.textBoxInput.Text.Length - preLen) > 100)
                {
                    this.Reset();
                }
                else
                {
                    if (!_flagSpeed)
                    {
                        timerSpeed.Start();
                    }
                    int num3;
                    this.MyTrimEnd(this.textBoxInput.Text);
                    if (this.textBoxInput.Text.Length >= wordsCount)
                    {
                        this.textBoxInput.Text = this.textBoxInput.Text.Substring(0, wordsCount);
                    }
                    this.labelLeave.Text = "余" + ((wordsCount - this.textBoxInput.TextLength)).ToString() + "字";
                    double num2 = ((double)(this.textBoxInput.Text.Length * 100)) / ((double)wordsCount);
                    //this.lableRate.Text = string.Format("{0:0.00}", num2) + "%";
                    this.progressBar1.Value = (this.textBoxInput.Text.Length * this.progressBar1.Maximum) / wordsCount;
                    for (num3 = preLen - 1; num3 >= this.textBoxInput.Text.Length; num3--)
                    {
                        this.richTextBoxGot.Select(num3, 1);
                        this.richTextBoxGot.SelectionBackColor = Color.White;
                    }
                    num3 = this.textBoxInput.TextLength - 30;
                    if (num3 < 0)
                    {
                        num3 = 0;
                    }
                    while (num3 < this.textBoxInput.Text.Length)
                    {
                        if (this.textBoxInput.Text[num3] == this.richTextBoxGot.Text[num3])
                        {
                            this.richTextBoxGot.Select(num3, 1);
                            this.richTextBoxGot.SelectionBackColor = Color.DarkGray;
                            isRight[num3] = true;
                        }
                        else
                        {
                            this.richTextBoxGot.Select(num3, 1);
                            this.richTextBoxGot.SelectionBackColor = Color.Red;
                            isRight[num3] = false;
                        }
                        num3++;
                    }
                    int selectionStart = this.richTextBoxGot.SelectionStart;
                    int lineFromCharIndex = this.richTextBoxGot.GetLineFromCharIndex(selectionStart);
                    if (lineFromCharIndex != preLine)
                    {
                        int num6 = this.richTextBoxGot.GetLineFromCharIndex(this.richTextBoxGot.TextLength - 1);
                        int start = this.richTextBoxGot.GetFirstCharIndexOfCurrentLine() - 1;
                        if (start < 0)
                        {
                            start = 0;
                        }
                        if (lineFromCharIndex < num6)
                        {
                            this.richTextBoxGot.Select(start, 1);
                            this.richTextBoxGot.ScrollToCaret();
                        }
                        preLine = lineFromCharIndex;
                    }
                    preLen = this.textBoxInput.Text.Length;
                    if (this.textBoxInput.Text.Length == wordsCount && textBoxInput.Text[wordsCount - 1] == richTextBoxGot.Text[wordsCount - 1])
                    {
                        // MessageBox.Show( richTextBoxGot.Text[actLen - 1].ToString (),textBoxInput.Text[actLen-1].ToString ());
                        double keyLong;
                        this.timerCount.Stop();
                        string str = "";
                        string str2 = "";
                        wrongWords = 0;
                        rightWord = 0;
                        for (num3 = 0; num3 < wordsCount; num3++)
                        {
                            if (this.richTextBoxGot.Text[num3] != this.textBoxInput.Text[num3])
                            {
                                wrongWords++;
                                str = str + this.richTextBoxGot.Text[num3];
                                str2 = str2 + this.textBoxInput.Text[num3];
                            }
                            else
                            {
                                rightWord++;
                            }
                        }
                        this.textBoxInput.ReadOnly = true;
                        this.textBoxInput.Select(this.textBoxInput.Text.Length, 0);
                        if (this.textBoxInput.Text.Length != 0)
                        {
                            keyLong = ((double)keyCount) / ((double)this.textBoxInput.Text.Length);
                        }
                        else
                        {
                            keyLong = 0.0;
                        }
                        endTime = DateTime.Now.TimeOfDay.TotalSeconds;
                        FollowTyperc.countCost += endTime - startTime;
                        avgTime += FollowTyperc.countCost;
                        avgBack += backSpace;
                        avgPress += keyCount;
                        avgWords += wordsCount;
                        avgWrongWords += wrongWords;

                        double num9 = (((rightWord + wrongWords) - (5 * wrongWords)) * 60.0) / FollowTyperc.countCost;
                        double hitKey = ((double)keyCount) / FollowTyperc.countCost;
                        this.dataGridViewResult.Rows.Add(new object[] { page, string.Format("{0:0.00}", num9), string.Format("{0:0.00}", hitKey), string.Format("{0:0.00}", keyLong), backSpace.ToString(), string.Format("{0:0000}", num) });
                        this.dataGridViewResult.Sort(this.dataGridViewResult.Columns[this.dataGridViewResult.Columns.Count - 1], ListSortDirection.Descending);
                        string s = "";// this.lablePara.Text + " 速度";
                        double dsped = num9;
                        string speed = "";
                        int num12;
                        if (!english_Show)
                        {
                            s = this.lablePara.Text + " 速度";

                            //if (wrongWord > 0)
                            //{
                            //    spd = string.Format("{0:0.00}", num9) + "/";
                            //    s = s + string.Format("{0:0.00}", num9) + "/";
                            //    num9 = (rightWord * 60.0) / FollowTyperc.countCost;
                            //    s = s + string.Format("{0:0.00}", num9);
                            //    spd += string.Format("{0:0.00}", num9);
                            //}
                            //else
                            //{
                            s = s + string.Format("{0:0.00}", num9);
                            speed += string.Format("{0:0.00}", num9);
                            //}
                            timerSpeed.Stop();
                            _flagSpeed = false;
                            lableSpeed.Text = speed;
                            if (str == "")
                            {
                                str = " 错字:无";
                            }
                            else
                            {
                                str = " 正[" + str + "] 误[" + str2 + "]";
                            }
                            object obj2 = s;
                            s = string.Concat(new object[] { obj2, " 回改", backSpace, " 击键", string.Format("{0:0.00}", hitKey), " 码长", string.Format("{0:0.00}", keyLong) });
                            double countCosts = FollowTyperc.countCost;

                            num12 = (int)(countCosts / 60.0);
                            countCosts -= num12 * 60;

                            if (bolA[0])// (bwrongWord)
                            {
                                s += " 错字" + wrongWords;
                            }

                            if (bolA[1])//  (bcountWord)
                            {
                                s += " 字数" + wordsCount;
                            }

                            if (bolA[2])
                            {
                                s += " 键数" + keyCount;
                            }
                            string UseTime = " 用时" + num12 + ":" + string.Format("{0:0.00}", countCosts);
                            if (bolA[3])// (bTime )
                            {
                                s += UseTime;
                            }

                            if (bolA[4])// (bwroRight  )
                            {
                                s += str;
                            }

                            _todayWordsCount += wordsCount;
                            _ToatlWordsCount += wordsCount;
                            s += SignSet();
                            SendToQQ(s);
                            // labelInfo.Text = "成绩格式:中文";
                            labWords.Text = "今日:" + _todayWordsCount + " 总数:" + _ToatlWordsCount;
                        }
                        else
                        {
                            s = "Paragraph:" + page + " Speed:";

                            if (wrongWords > 0)
                            {
                                speed = string.Format("{0:0.00}", num9) + "/";
                                s = s + string.Format("{0:0.00}", num9) + "/";
                                num9 = (rightWord * 60.0) / FollowTyperc.countCost;
                                s = s + string.Format("{0:0.00}", num9);
                                speed += string.Format("{0:0.00}", num9);
                            }
                            else
                            {
                                s = s + string.Format("{0:0.00}", num9);
                                speed += string.Format("{0:0.00}", num9);
                            }
                            timerSpeed.Stop();
                            _flagSpeed = false;
                            lableSpeed.Text = speed;
                            if (str == "")
                            {
                                str = " WrongWords:None";
                            }
                            else
                            {
                                str = " Ture[" + str + "] False[" + str2 + "]";
                            }
                            object obj2 = s;
                            s = string.Concat(new object[] { obj2, " BackSpace:", backSpace, " Hits:", string.Format("{0:0.00}", hitKey), " WordLength:", string.Format("{0:0.00}", keyLong) });
                            double countCosts = FollowTyperc.countCost;

                            num12 = (int)(countCosts / 60.0);
                            countCosts -= num12 * 60;

                            if (bolA[0])// (bwrongWord)
                            {
                                s += " WrongWordCounts:" + wrongWords;
                            }

                            if (bolA[1])//  (bcountWord)
                            {
                                s += " WordsCounts:" + wordsCount;
                            }

                            if (bolA[2])
                            {
                                s += " KeyCounts:" + keyCount;
                            }
                            string UseTime = " Time:" + num12 + ":" + string.Format("{0:0.00}", countCosts);
                            if (bolA[3])// (bTime )
                            {
                                s += UseTime;
                            }

                            if (bolA[4])// (bwroRight  )
                            {
                                s += str;
                            }

                            _todayWordsCount += wordsCount;
                            _ToatlWordsCount += wordsCount;
                            s += SignSetEnglish();
                            SendToQQ(s);
                            // labelInfo.Text = "成绩格式:英文" ;
                            labWords.Text = "Today:" + _todayWordsCount + " Total:" + _ToatlWordsCount;
                        }
                        System.Threading.ThreadPool.QueueUserWorkItem(o =>
                        {
                            if (dsped > 4 && IsHandleCreated)
                            {
                                Invoke(new Action(() =>
                                {
                                    GradeField gradeField = new GradeField();
                                    gradeField.CompletedDate = DateTime.Now;
                                    gradeField.Paragraph = lablePara.Text;
                                    gradeField.Speed = double.Parse(speed);
                                    gradeField.BackSpace = backSpace;
                                    gradeField.HitKey = double.Parse(string.Format("{0:0.00}", hitKey));
                                    gradeField.KeyLong = double.Parse(string.Format("{0:0.00}", keyLong));
                                    gradeField.WrongWords = wrongWords;
                                    gradeField.WordsCount = wordsCount;
                                    gradeField.KeyCount = keyCount;
                                    gradeField.CostTime = num12 + ":" + string.Format("{0:0.00}", countCost);

                                    DataOperationDAL.Insert(gradeField);
                                }));
                            }
                        });

                        System.Threading.ThreadPool.QueueUserWorkItem(o =>
                        {
                            if (sendafterType)
                            {
                                Invoke(new Action(() =>
                                {
                                    SendText();
                                }));
                            }
                        });

                        grade = new StringBuilder(s);
                        averageGrade(num9, hitKey);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        //把公共的代码,封装到一个方法中,提高代码的利用性
        private static GradeField ToDataField(DataRow row)
        {
            GradeField gradeField = new GradeField();
            gradeField.CompletedDate = (DateTime)row["CompletedDate"];
            gradeField.Paragraph = (string)row["Paragraph"];
            gradeField.Speed = (double)row["Speed"];
            gradeField.BackSpace = (int)row["BackSpace"];
            gradeField.HitKey = (double)row["HitKey"];
            gradeField.KeyLong = (double)row["KeyLong"];
            gradeField.WrongWords = (int)row["WrongWords"];
            gradeField.WordsCount = (int)row["WordsCount"];
            gradeField.KeyCount = (int)row["KeyCount"];
            gradeField.CostTime = (string)row["CostTime"];

            return gradeField;
        }