Пример #1
0
        private void lblCauHoi_MouseDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                if (dtpNgay.SelectedDate != null)
                {
                    ng = dtpNgay.SelectedDate.Value.ToString("yyyy-MM-dd");
                }
                reset_clock();
                string sql = "";
                str.TaoThuMuc(Thumuc);
                cls.ClsConnect();
                var dtchk = cls.LoadDataText("select * from KQTHINV  where USERNAME='******' and NGAY='" + ng + "'");
                if (dtchk.Rows.Count == 0)
                {
                    sql = "insert into KQTHINV select LOAI, CAUHOI, A, B, C, D, DAPAN, TT, POS,'" +
                          BienBll.NdTen.Trim() + "'  NG_NHAP,0 VONG,'" + BienBll.Ndma.Trim() +
                          "' USERNAME, TRALOI,CANCU,NGAY from CAUHOI where NGAY='" + ng + "'";
                    cls.LoadDataText(sql);
                }
                dt = cls.LoadDataText("select * from KQTHINV  where USERNAME='******' and NGAY='" + ng + "' and TRALOI is null");
                if (dt.Rows.Count > 0)
                {
                    str.WriteText(dt, filename);
                    StreamReader sr       = new StreamReader(filename);
                    string       readLine = sr.ReadLine();
                    if (readLine != null)
                    {
                        string[] arrStr = readLine.Split('#');
                        txtCauHoi.Text = arrStr[1];
                        txtA.Text      = arrStr[2];
                        txtB.Text      = arrStr[3];
                        txtC.Text      = arrStr[4];
                        txtD.Text      = arrStr[5];
                        dapan          = arrStr[6];
                        TT             = arrStr[7];
                        cancu          = arrStr[13];
                    }

                    StreamReader srl = new StreamReader(filename);
                    while (srl.Peek() >= 0)
                    {
                        lst.Add(srl.ReadLine());
                        Sodong = Sodong + 1;
                    }
                    cls.DongKetNoi();
                    lblCauHoi.IsEnabled = false;
                    star_clock();
                }
                else
                {
                    MessageBox.Show("Bạn đã làm xong bài thi của mình rồi !", "Thông báo", MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error " + ex.Message, "Thông báo", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Пример #2
0
        private void lblCauHoi_MouseDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                reset_clock();
                string sql = "";
                str.TaoThuMuc(Thumuc);
                cls.ClsConnect();

                dtvong = cls.LoadDataText("select max(VONG) VONG,count(*) DEM from KQTHINV where USERNAME='******' and LOAI='" + CboChuDe.SelectionBoxItem.ToString().Trim() + "'");
                if (dtvong.Rows[0]["DEM"].ToString() == "0")
                {
                    vong  = "0";
                    socau = "0";
                }
                else
                {
                    vong = dtvong.Rows[0]["VONG"].ToString();
                    if (CboChuDe.SelectionBoxItem.ToString().Trim() == "AL")
                    {
                        dtsocau = cls.LoadDataText(
                            "select cast(max(VONG) as int) VONG,count(*) DEM from KQTHINV where USERNAME='******' and VONG='" + vong + "' and TRALOI is null ");
                    }
                    else
                    {
                        dtsocau = cls.LoadDataText(
                            "select cast(max(VONG) as int) VONG,count(*) DEM from KQTHINV where USERNAME='******' and VONG='" + vong + "' and TRALOI is null and LOAI='" + CboChuDe.SelectionBoxItem.ToString().Trim() + "'");
                    }

                    if (dtsocau.Rows.Count > 0)
                    {
                        socau = dtsocau.Rows[0]["DEM"].ToString();
                    }
                    txtVong.Text = BienBll.NdTen + " Đang Thi Vòng Số : " + vong + " Số Câu Chưa Trả Lời : " + socau;
                }

                if (vong == "0" & socau == "0")
                {
                    if (CboChuDe.SelectionBoxItem.ToString().Trim() == "AL")
                    {
                        sql = "insert into KQTHINV select 'AL' LOAI, CAUHOI, A, B, C, D, DAPAN, TT, POS,'" +
                              BienBll.NdTen.Trim() +
                              "'  NG_NHAP,1 VONG,'" + BienBll.Ndma.Trim() + "' USERNAME, TRALOI,CANCU from CAUHOI order by TT";
                    }
                    else
                    {
                        sql = "insert into KQTHINV select LOAI, CAUHOI, A, B, C, D, DAPAN, TT, POS,'" +
                              BienBll.NdTen.Trim() +
                              "'  NG_NHAP,1 VONG,'" + BienBll.Ndma.Trim() + "' USERNAME, TRALOI,CANCU from CAUHOI where LOAI='" + CboChuDe.SelectionBoxItem.ToString().Trim() + "' order by TT";
                    }

                    cls.LoadDataText(sql);
                }
                else
                {
                    if (socau == "0")     //lam het cau tao vong moi
                    {
                        int    i = 0;
                        string s = vong;
                        i = int.Parse(s);
                        i = Convert.ToInt32(s) + 1;
                        if (CboChuDe.SelectionBoxItem.ToString().Trim() == "AL")
                        {
                            sql = "insert into KQTHINV select 'AL' LOAI, CAUHOI, A, B, C, D, DAPAN, TT, POS,'" +
                                  BienBll.NdTen.Trim() +
                                  "'  NG_NHAP," + i + " VONG,'" + BienBll.Ndma.Trim() +
                                  "' USERNAME, TRALOI,CANCU from CAUHOI order by TT";
                        }
                        else
                        {
                            sql = "insert into KQTHINV select LOAI, CAUHOI, A, B, C, D, DAPAN, TT, POS,'" +
                                  BienBll.NdTen.Trim() +
                                  "'  NG_NHAP," + i + " VONG,'" + BienBll.Ndma.Trim() + "' USERNAME, TRALOI,CANCU from CAUHOI where LOAI='" + CboChuDe.SelectionBoxItem.ToString().Trim() + "' order by TT";
                        }
                        cls.LoadDataText(sql);
                    }
                }
                //var dtsocau = cls.LoadDataText("select count(*) DEM from KQTHINV where USERNAME='******' and TRALOI is null");
                var dtsl = cls.LoadDataText("select max(VONG) VONG,count(*) DEM from KQTHINV where USERNAME='******' and TRALOI is null and LOAI='" + CboChuDe.SelectionBoxItem.ToString().Trim() + "'");
                if (dtsl.Rows.Count > 0)
                {
                    vong = dtsl.Rows[0]["VONG" +
                                        ""].ToString();
                    socau        = dtsl.Rows[0]["DEM"].ToString();
                    txtVong.Text = BienBll.NdTen + " Đang Thi Vòng Số : " + vong + " Số Câu Chưa Trả Lời : " + socau;
                    var dtsai =
                        cls.LoadDataText("select COUNT(*) dem from KQTHINV where VONG=" + vong + " and USERNAME='******' and DAPAN<>TRALOI and LOAI='" + CboChuDe.SelectionBoxItem.ToString().Trim() + "'");
                    socausai       = (int)dtsai.Rows[0]["DEM"];
                    lblSai.Content = socausai.ToString();
                    lblCon.Content = datraloi.ToString();
                }
                if (CboChuDe.SelectionBoxItem.ToString().Trim() == "AL")
                {
                    dt = cls.LoadDataText("select * from KQTHINV  where USERNAME='******' and TRALOI is null");
                }
                else
                {
                    dt = cls.LoadDataText("select * from KQTHINV  where USERNAME='******' and LOAI='" + CboChuDe.SelectionBoxItem + "' and TRALOI is null");
                }
                str.WriteText(dt, filename);
                StreamReader sr       = new StreamReader(filename);
                string       readLine = sr.ReadLine();
                if (readLine != null)
                {
                    string[] arrStr = readLine.Split('#');
                    txtCauHoi.Text = arrStr[1];
                    txtA.Text      = arrStr[2];
                    txtB.Text      = arrStr[3];
                    txtC.Text      = arrStr[4];
                    txtD.Text      = arrStr[5];
                    dapan          = arrStr[6];
                    TT             = arrStr[7];
                    cancu          = arrStr[13];
                }
                //MessageBox.Show(sql, "Thông báo", MessageBoxButton.OK, MessageBoxImage.Information);
                StreamReader srl = new StreamReader(filename);
                while (srl.Peek() >= 0)
                {
                    lst.Add(srl.ReadLine());
                    Sodong = Sodong + 1;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error " + ex.Message, "Thông báo", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            cls.DongKetNoi();
            lblCauHoi.IsEnabled = false;
            lblOk.IsEnabled     = false;
            Countdown(thoigian, TimeSpan.FromSeconds(1), cur => tb.Text = cur.ToString()); //tutm
            star_clock();
        }