public static bool DeleteSysMsg(SysMsg msg)
        {
            MySqlConnection mConnect = null;
            MySqlCommand    mCommand = null;

            List <SysMsg> list = new List <SysMsg>();

            try
            {
                mConnect            = new MySqlConnection("server=localhost;user id=root;Password=;database=classroomad");
                mCommand            = new MySqlCommand();
                mCommand.Connection = mConnect;
                mConnect.Open();
            }
            catch
            {
                Console.WriteLine("FAILED to link MySQL in DeleteSysMsg(" + msg.Info + ")");
                return(false);
            }

            mCommand.CommandText  = "DELETE FROM SysMsg WHERE ";
            mCommand.CommandText += "sendId=" + msg.SendId
                                    + " and recvId=" + msg.RecvId
                                    + " and time = '" + msg.Time.ToString("yyyy-MM-dd") + "'"
                                    + " and info = '" + msg.Info + "';";

            mCommand.Prepare();
            int i = mCommand.ExecuteNonQuery();

            mConnect.Close();

            return(i > 0);
        }
        public static bool SendSysMsg(SysMsg msg)
        {
            MySqlConnection mConnect = null;
            MySqlCommand    mCommand = null;

            List <SysMsg> list = new List <SysMsg>();

            try
            {
                mConnect            = new MySqlConnection("server=localhost;user id=root;Password=;database=classroomad");
                mCommand            = new MySqlCommand();
                mCommand.Connection = mConnect;
                mConnect.Open();
            }
            catch
            {
                Console.WriteLine("FAILED to link MySQL in SendSysMsg(" + msg.Info + ")");
                return(false);
            }

            mCommand.CommandText  = "INSERT INTO SysMsg VALUES";
            mCommand.CommandText += " ("
                                    + msg.SendId + ", "
                                    + msg.RecvId + ", '"
                                    + msg.Time.ToString("yyyy-MM-dd") + "', "
                                    + "'" + msg.Info
                                    + "');";

            mCommand.Prepare();
            int i = mCommand.ExecuteNonQuery();

            mConnect.Close();

            return(i > 0);
        }
        private void TBDecline_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (DatabaseLinker.DeleteRent(rent))
            {
                rent.GetApproved();

                SysMsg msg = new SysMsg(0, rent.pId, DateTime.Now, "对不起, 您申请的课程 " + rent.rId + ", " + rent.Info + " 没有通过审核, 已被管理员删除.");
                DatabaseLinker.SendSysMsg(msg);

                MessageBox.Show("已删除课程.");
                this.Close();
            }
        }
        private void TBOK_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (DatabaseLinker.ApproveRent(rent))
            {
                rent.GetApproved();

                SysMsg msg = new SysMsg(0, rent.pId, DateTime.Now, "您申请的课程 " + rent.rId + ", " + rent.Info + " 已经通过审核.");
                DatabaseLinker.SendSysMsg(msg);

                MessageBox.Show("审核已通过.");
                this.Close();
            }
        }
        // 系统消息初始化
        private void TextBlockMessageInitialize(TextBlock tb, SysMsg msg)
        {
            string sendName = DatabaseLinker.GetName(msg.SendId);

            tb.FontSize = 24;
            tb.Padding  = new Thickness(16);
            tb.Inlines.Add(new Bold(new Run(sendName + ": (" + msg.Time.ToString("yyyy/MM/dd") + ")\r\n")));
            tb.Inlines.Add(new Run("  " + msg.Info));
            tb.TextWrapping = TextWrapping.Wrap;

            //  tb.MouseEnter += tbRent_MouseEnter;
            //  tb.MouseLeave += tbRent_MouseLeave;

            tb.Tag = msg;
        }
        private void GridMessage_Loaded(object sender, RoutedEventArgs e)
        {
            listSysMsg = DatabaseLinker.GetPersonSysMsgList(person.pId);

            for (int i = listSysMsg.Count - 1; i >= 0; --i)
            {
                SysMsg    msg = listSysMsg[i];
                TextBlock tb  = new TextBlock();
                TextBlockMessageInitialize(tb, msg);
                stackPanelMessage.Children.Add(tb);
            }

            if (person.pId == 0)
            {
                List <Rent> listRent = DatabaseLinker.GetUnapprovedRentTable();

                foreach (Rent r in listRent)
                {
                    TextBlock tb = new TextBlock();
                    TextBlockUnapprovedRentInitialize(tb, r);
                    stackPanelMessage.Children.Add(tb);
                }
            }
        }
        private void TBOK_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (DatabaseLinker.ApproveRent(rent))
            {
                rent.GetApproved();

                SysMsg msg = new SysMsg(0, rent.pId, DateTime.Now, "您申请的课程 " + rent.rId + ", " + rent.Info + " 已经通过审核.");
                DatabaseLinker.SendSysMsg(msg);

                MessageBox.Show("审核已通过.");
                this.Close();
            }
        }
        private void TBDecline_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (DatabaseLinker.DeleteRent(rent))
            {
                rent.GetApproved();

                SysMsg msg = new SysMsg(0, rent.pId, DateTime.Now, "对不起, 您申请的课程 " + rent.rId + ", " + rent.Info + " 没有通过审核, 已被管理员删除.");
                DatabaseLinker.SendSysMsg(msg);

                MessageBox.Show("已删除课程.");
                this.Close();
            }
        }
        // 系统消息初始化
        private void TextBlockMessageInitialize(TextBlock tb, SysMsg msg)
        {
            string sendName = DatabaseLinker.GetName(msg.SendId);

            tb.FontSize = 24;
            tb.Padding = new Thickness(16);
            tb.Inlines.Add(new Bold(new Run(sendName + ": ("+msg.Time.ToString("yyyy/MM/dd")+")\r\n")));
            tb.Inlines.Add(new Run("  " + msg.Info));
            tb.TextWrapping = TextWrapping.Wrap;

              //  tb.MouseEnter += tbRent_MouseEnter;
              //  tb.MouseLeave += tbRent_MouseLeave;

            tb.Tag = msg;
        }
        public static bool SendSysMsg(SysMsg msg)
        {
            MySqlConnection mConnect = null;
            MySqlCommand mCommand = null;

            List<SysMsg> list = new List<SysMsg>();

            try
            {
                mConnect = new MySqlConnection("server=localhost;user id=root;Password=;database=classroomad");
                mCommand = new MySqlCommand();
                mCommand.Connection = mConnect;
                mConnect.Open();
            }
            catch
            {
                Console.WriteLine("FAILED to link MySQL in SendSysMsg(" + msg.Info + ")");
                return false;
            }

            mCommand.CommandText = "INSERT INTO SysMsg VALUES";
            mCommand.CommandText += " ("
                                + msg.SendId + ", "
                                + msg.RecvId + ", '"
                                + msg.Time.ToString("yyyy-MM-dd") + "', "
                                + "'" + msg.Info
                                + "');";

            mCommand.Prepare();
            int i = mCommand.ExecuteNonQuery();

            mConnect.Close();

            return i > 0;
        }
        public static bool DeleteSysMsg(SysMsg msg)
        {
            MySqlConnection mConnect = null;
            MySqlCommand mCommand = null;

            List<SysMsg> list = new List<SysMsg>();

            try
            {
                mConnect = new MySqlConnection("server=localhost;user id=root;Password=;database=classroomad");
                mCommand = new MySqlCommand();
                mCommand.Connection = mConnect;
                mConnect.Open();
            }
            catch
            {
                Console.WriteLine("FAILED to link MySQL in DeleteSysMsg(" + msg.Info + ")");
                return false;
            }

            mCommand.CommandText = "DELETE FROM SysMsg WHERE ";
            mCommand.CommandText += "sendId=" + msg.SendId
                                + " and recvId=" + msg.RecvId
                                + " and time = '" + msg.Time.ToString("yyyy-MM-dd") + "'"
                                + " and info = '" + msg.Info + "';";

            mCommand.Prepare();
            int i = mCommand.ExecuteNonQuery();

            mConnect.Close();

            return i > 0;
        }