Esempio n. 1
0
        /// <summary>
        /// 刷新问题状态,具体做法同初始化
        /// </summary>
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Before = null;
            string n           = MainWindow.UserCode;
            string UserNameTea = n.ToString();

            infoList.Clear();
            TeaAnsQues    Stu = new TeaAnsQues();
            SqlConnection myConnection;
            string        connStr = "Server ='" + IPAddress.ip + "'; database =测试数据库; uid =sa; pwd=1738010002";

            //string connStr = @"Server =   LAPTOP-25MJ4H0M\SQLEXPRESS; database =教学系统; Trusted_Connection=SSPI";
            myConnection = new SqlConnection(connStr);
            try
            {
                myConnection.Open();
            }
            catch (Exception)
            {
                MessageBox.Show("连接失败");
            }
            SqlCommand    cmd2 = new SqlCommand("select 管理班级 from jsb where 职工号 = '" + UserNameTea + "'", myConnection);
            SqlDataReader sdr2 = cmd2.ExecuteReader();

            sdr2.Read();
            string TeaClass = sdr2[0].ToString();

            sdr2.Close();
            SqlCommand    cmd = new SqlCommand("select 问题,答案,状态,姓名,学号,时间 from wtb where 班级 = '" + TeaClass + "'", myConnection);
            SqlDataReader sdr = cmd.ExecuteReader();

            while (sdr.Read())
            {
                Stu.TeaStatus   = sdr[2].ToString();
                Stu.TeaQuestion = sdr[0].ToString();
                Stu.TeaAnswer   = sdr[1].ToString();
                Stu.TeaName     = sdr[3].ToString();
                Stu.TeaUser     = sdr[4].ToString();
                Stu.Time        = DateTime.Parse(sdr[5].ToString().Trim());

                infoList.Add(Stu);
            }
            infoList.Sort(delegate(TeaAnsQues x, TeaAnsQues y)
            {
                return(y.Time.CompareTo(x.Time));
            });
            DG4.AutoGenerateColumns = false;
            DG4.ItemsSource         = null;
            DG4.ItemsSource         = infoList;
        }
Esempio n. 2
0
        public QuesAns()
        {
            InitializeComponent();
            Before = null;
            WindowStartupLocation = WindowStartupLocation.CenterScreen;
            //建立定时器,时间间隔为1s,并启动定时器
            timer.Tick    += new EventHandler(timer_Tick);
            timer.Interval = new TimeSpan(0, 0, 1);
            timer.Start();

            //UserNameTea为教师的账户名
            string     n           = MainWindow.UserCode;
            string     UserNameTea = n.ToString();
            TeaAnsQues Stu         = new TeaAnsQues();
            //数据库连接
            SqlConnection myConnection;
            string        connStr = "Server ='" + IPAddress.ip + "'; database =测试数据库; uid =sa; pwd=1738010002";

            //string connStr = @"Server =   LAPTOP-25MJ4H0M\SQLEXPRESS; database =教学系统; Trusted_Connection=SSPI";
            myConnection = new SqlConnection(connStr);
            try
            {
                myConnection.Open();
            }
            catch (Exception)
            {
                MessageBox.Show("连接失败");
            }
            //查询该教师管理的班级
            SqlCommand    cmd2 = new SqlCommand("select 管理班级 from jsb where 职工号 = '" + UserNameTea + "'", myConnection);
            SqlDataReader sdr2 = cmd2.ExecuteReader();

            sdr2.Read();
            //TeaClass为管理的班级
            string TeaClass = sdr2[0].ToString();

            sdr2.Close();
            //查询该班级所有的问题
            SqlCommand    cmd = new SqlCommand("select 问题,答案,状态,姓名,学号,时间 from wtb where 班级 = '" + TeaClass + "'", myConnection);
            SqlDataReader sdr = cmd.ExecuteReader();

            //循环读取问题
            while (sdr.Read())
            {
                Stu.TeaStatus   = sdr[2].ToString();
                Stu.TeaQuestion = sdr[0].ToString();
                Stu.TeaAnswer   = sdr[1].ToString();
                Stu.TeaName     = sdr[3].ToString();
                Stu.TeaUser     = sdr[4].ToString();
                Stu.Time        = DateTime.Parse(sdr[5].ToString().Trim());

                infoList.Add(Stu);
            }
            //将问题列表按时间排序
            infoList.Sort(delegate(TeaAnsQues x, TeaAnsQues y)
            {
                return(y.Time.CompareTo(x.Time));
            });
            //绑定数据源
            DG4.AutoGenerateColumns = false;
            DG4.ItemsSource         = infoList;
        }
Esempio n. 3
0
 //定时刷新
 void timer_Tick(object sender, EventArgs e)
 {
     #region 数据库连接
     SqlConnection myConnection;
     string        connStr = "Server ='" + IPAddress.ip + "'; database =测试数据库; uid =sa; pwd=1738010002";
     //string connStr = @"Server =   LAPTOP-25MJ4H0M\SQLEXPRESS; database =教学系统; Trusted_Connection=SSPI";
     myConnection = new SqlConnection(connStr);
     try
     {
         myConnection.Open();
     }
     catch (Exception)
     {
         MessageBox.Show("连接失败");
     }
     #endregion
     //循环读取是否被选中
     for (int i = 0; i < this.DG4.Items.Count; i++)
     {
         var         cntr   = DG4.ItemContainerGenerator.ContainerFromIndex(i);
         DataGridRow ObjROw = (DataGridRow)cntr;
         if (ObjROw != null)
         {
             FrameworkElement objElement = DG4.Columns[4].GetCellContent(ObjROw);
             if (objElement != null)
             {
                 System.Windows.Controls.CheckBox objChk = (System.Windows.Controls.CheckBox)objElement;
                 if (objChk.IsChecked == true)
                 {
                     if (Before != infoList[i].TeaQuestion)
                     {
                         Before = infoList[i].TeaQuestion;
                         break;
                     }
                 }
             }
         }
     }
     string n           = MainWindow.UserCode;
     string UserNameTea = n.ToString();
     infoList.Clear();
     TeaAnsQues    Stu  = new TeaAnsQues();
     SqlCommand    cmd2 = new SqlCommand("select 管理班级 from jsb where 职工号 = '" + UserNameTea + "'", myConnection);
     SqlDataReader sdr2 = cmd2.ExecuteReader();
     sdr2.Read();
     string TeaClass = sdr2[0].ToString();
     sdr2.Close();
     SqlCommand    cmd = new SqlCommand("select 问题,答案,状态,姓名,学号,时间 from wtb where 班级 = '" + TeaClass + "'", myConnection);
     SqlDataReader sdr = cmd.ExecuteReader();
     while (sdr.Read())
     {
         Stu.TeaStatus   = sdr[2].ToString();
         Stu.TeaQuestion = sdr[0].ToString();
         Stu.TeaAnswer   = sdr[1].ToString();
         Stu.TeaName     = sdr[3].ToString();
         Stu.TeaUser     = sdr[4].ToString();
         if (Before == null)
         {
             Stu.TeaSelectQues = false;
         }
         else if (Stu.TeaQuestion == Before)
         {
             Stu.TeaSelectQues = true;
         }
         else
         {
             Stu.TeaSelectQues = false;
         }
         Stu.Time = DateTime.Parse(sdr[5].ToString().Trim());
         infoList.Add(Stu);
     }
     infoList.Sort(delegate(TeaAnsQues x, TeaAnsQues y)
     {
         return(y.Time.CompareTo(x.Time));
     });
     DG4.AutoGenerateColumns = false;
     DG4.ItemsSource         = null;
     DG4.ItemsSource         = infoList;
 }
Esempio n. 4
0
        /// <summary>
        /// 从数据库查询所有的问题并显示在界面上
        /// </summary>
        public AdminQueAns()
        {
            InitializeComponent();
            WindowStartupLocation = WindowStartupLocation.CenterScreen;
            string n           = MainWindow.UserCode;
            string UserNameTea = n.ToString();
            //Stu为单个问题的信息集合
            TeaAnsQues Stu = new TeaAnsQues();

            #region 数据库连接
            SqlConnection myConnection;
            string        connStr = "Server ='" + IPAddress.ip + "'; database =测试数据库; uid =sa; pwd=1738010002";
            //string connStr = @"Server =   LAPTOP-25MJ4H0M\SQLEXPRESS; database =教学系统; Trusted_Connection=SSPI";
            myConnection = new SqlConnection(connStr);
            try
            {
                myConnection.Open();
            }
            catch (Exception)
            {
                MessageBox.Show("连接失败");
            }
            #endregion
            //查询所有的问题
            SqlCommand    cmd = new SqlCommand("select 问题,答案,状态,姓名,学号,时间,班级 from wtb", myConnection);
            SqlDataReader sdr = cmd.ExecuteReader();
            //count为已解决的问题数量,total为总问题数量,todaytotal为今日问题数量,QueAnsRate为答疑率
            float    count      = 0;
            float    total      = 0;
            int      todaycount = 0;
            float    QueAnsRate;
            DateTime now = DateTime.Now;
            //TimeSpan sub = DateTime.Parse(sdr[5].ToString()).Date - now.Date;
            //System.Data.Entity.DbFunctions.DiffDays(sdr[5].ToString()), DateTime.Now) == 0;
            //遍历读取所有的问题并将其加入到infoList问题列表
            while (sdr.Read())
            {
                //MessageBox.Show(sdr[5].ToString());
                TimeSpan sub = DateTime.Parse(sdr[5].ToString()).Date - now.Date;
                Stu.TeaStatus   = sdr[2].ToString();
                Stu.TeaQuestion = sdr[0].ToString();
                Stu.TeaAnswer   = sdr[1].ToString();
                Stu.TeaName     = sdr[3].ToString();
                Stu.TeaUser     = sdr[4].ToString();
                Stu.ClassName   = sdr[6].ToString();
                Stu.Time        = DateTime.Parse(sdr[5].ToString().Trim());
                //将单个问题添加到问题列表
                if (sdr[2].ToString().Trim().Equals("已解决") == true)
                {
                }
                else
                {
                    infoList.Add(Stu);
                }

                //infoList.Sort(delegate (TeaAnsQues x, TeaAnsQues y)
                //{
                //return y.Time.CompareTo(x.Time);
                // });
                //MessageBox.Show(sdr[2].ToString().Equals("已解决").ToString());
                //如果问题状态为已解决 则count+1
                if (sdr[2].ToString().Trim().Equals("已解决") == true)
                {
                    count += 1;
                }
                //如果问题的创建时间为今天 则todaycount+1
                if (sub.Days == 0)
                {
                    todaycount += 1;
                }
                total++;
            }
            //对所有的问题按时间进行排序
            infoList.Sort(delegate(TeaAnsQues x, TeaAnsQues y)
            {
                return(y.Time.CompareTo(x.Time));
            });
            //计算答疑率
            QueAnsRate = count / total;
            //MessageBox.Show(count.ToString());
            DayQueTotal.Content = todaycount.ToString();
            AnsRate.Content     = (QueAnsRate * 100).ToString() + "%";
            //绑定DG11 的数据源为问题列表
            DG11.AutoGenerateColumns = false;
            DG11.ItemsSource         = infoList;
        }