private void enter_Click(object sender, RoutedEventArgs e)
        {
            string pwd1 = getPassWord(this.pb1);
            string pwd2 = getPassWord(this.pb2);

            if (pwd1 == "" || pwd2 == "")
            {
                MessageBox.Show("不能为空!");
            }
            else if (pwd1 != pwd2)
            {
                MessageBox.Show("两次输入密码不同!");
                pb1.Password = "";
                pb2.Password = "";
            }
            else if (pwd1.Length < 8)
            {
                MessageBox.Show("输入密码过短!");
                pb1.Password = "";
                pb2.Password = "";
            }
            else if (JudgeEasility(pwd1))
            {
                MessageBox.Show("密码太简单!");
                pb1.Password = "";
                pb2.Password = "";
            }
            else
            {
                MySqlConnection con     = Connect.Connection();
                MySqlCommand    command = new MySqlCommand();
                command.Connection  = con;
                command.CommandText = "update login set PassWord = '******' where UserId = '" + Connect.GetUser() + "';";
                con.Open();
                command.ExecuteNonQuery();
                con.Close();
                MessageBox.Show("更改成功!");
                this.Close();
            }
        }
        //点击事件区域
        //===================================================================================================================
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var button = sender as Button;

            if (button.Background == System.Windows.Media.Brushes.Red)
            {
                MessageBox.Show("该座位已被预约!");
                return;
            }
            if (!CanBook())
            {
                MessageBox.Show("你已预约另一位置,不能再次预约!");
                return;
            }
            string name = button.Name;

            string[]        array  = name.Split('_');
            string          row    = array[1];
            string          column = array[2];
            MySqlConnection con    = Connect.Connection();
            MySqlDataReader reader;
            MySqlCommand    command;

            try
            {
                con.Open();
                string cmd = "insert into seatbook values('" + row + "','" + column + "','" + Connect.GetUser() + "');";

                command = new MySqlCommand(cmd, con);
                command.ExecuteNonQuery();

                cmd     = "select * from seatbook where x = '" + row + "' and y = '" + column + "'and UserId = '" + Connect.GetUser() + "';";
                command = new MySqlCommand(cmd, con);
                reader  = command.ExecuteReader();
                if (reader.HasRows)
                {
                    MessageBox.Show("预约成功!");
                }
                reader.Close();
            }catch (MySqlException ex)
            {
                MessageBox.Show(ex.Message);
            }
            con.Close();

            ButtonBrush();
        }
        private void Cancel(object sender, MouseButtonEventArgs e)//右键点击取消
        {
            var button = sender as Button;

            if (button.Background == System.Windows.Media.Brushes.Green)
            {
                return;
            }
            if (CanBook())
            {
                MessageBox.Show("你无权取消该位置的预约!");
                return;
            }
            string name = button.Name;

            string[] array  = name.Split('_');
            string   row    = array[1];
            string   column = array[2];

            bool            mark = false;
            MySqlConnection con  = Connect.Connection();
            MySqlDataReader reader;
            MySqlCommand    command;

            try
            {
                con.Open();
                string cmd = "select * from seatbook where x = '" + row + "' and y = '" + column + "'and UserId = '" + Connect.GetUser() + "';";
                command = new MySqlCommand(cmd, con);
                reader  = command.ExecuteReader();
                if (reader.HasRows)
                {
                    mark = true;
                }
                else
                {
                    MessageBox.Show("你无权取消该位置的预约!");
                }
                reader.Close();
                if (mark)
                {
                    cmd     = "delete from seatbook where UserId = '" + Connect.GetUser() + "';";
                    command = new MySqlCommand(cmd, con);
                    command.ExecuteNonQuery();
                    MessageBox.Show("取消预约成功!");
                }
            }
            catch (MySqlException ex)
            {
                MessageBox.Show(ex.Message);
            }
            con.Close();
            ButtonBrush();
        }
Beispiel #4
0
        private void borrow_Click(object sender, RoutedEventArgs e)
        {
            if (!IsHaveQual(num))
            {
                MessageBox.Show("可借阅数目超过最大上限!");
                return;
            }
            if (num == 0)
            {
                return;
            }


            string[] gather = new string[num];
            for (int i = 0; i < num; i++)
            {
                gather[i] = this.list1.Items[i + 1].ToString();
            }
            for (int i = 0; i < num; i++)
            {
                string[] array = gather[i].Split('|');
                array[0] = array[0].Trim();
                array[1] = array[1].Trim();

                MySqlConnection con = Connect.Connection();
                try
                {
                    con.Open();
                    string       cmd     = "insert into borrow values ('" + array[0] + "','" + array[1] + "','" + Connect.GetUser() + "');";
                    MySqlCommand command = new MySqlCommand(cmd, con);
                    command.ExecuteNonQuery();
                    MessageBox.Show("借阅成功!");
                    //string check = "select * from borrow where BookName = '" + array[0] + "' and Writer = '" + array[1] + "' and UserId = '" + Connect.GetUser() + "';";
                    //command = new MySqlCommand(check, con);
                    //MySqlDataReader reader = command.ExecuteReader();
                    //if (reader.HasRows)
                    //{
                    //    MessageBox.Show("借阅成功!");
                    //}
                    //else
                    //{
                    //    MessageBox.Show("借阅失败!");
                    //    return;
                    //}
                    //reader.Close();
                    con.Close();
                }
                catch (MySqlException ex)
                {
                    MessageBox.Show(ex.Message);
                    return;
                }
            }
            list1.Items.Clear();
            List1AddHead();
            num = 0;
        }
Beispiel #5
0
        private bool IsHaveQual(int num)
        {
            MySqlConnection con    = Connect.Connection();
            bool            result = false;
            string          cmd    = "select count(UserId) as 'cnt' from borrow where UserId = '" + Connect.GetUser() + "';";

            try
            {
                con.Open();
                MySqlCommand    command = new MySqlCommand(cmd, con);
                MySqlDataReader reader  = command.ExecuteReader();
                int             i       = 0;
                if (reader.Read())
                {
                    i = Convert.ToInt32(reader["cnt"].ToString());
                }

                if (i + num <= 3)
                {
                    result = true;
                }

                con.Close();
                reader.Close();
            }
            catch (MySqlException ex)
            {
                MessageBox.Show(ex.Message);
            }
            return(result);
        }
Beispiel #6
0
        }//向list1中加入图书数据

        private void inquery_Click(object sender, RoutedEventArgs e)
        {
            string          bookname = this.Bookname.Text.ToString().Trim();
            string          writer   = this.Writer.Text.ToString().Trim();
            string          cmd      = "";
            MySqlConnection con      = Connect.Connection();

            if (bookname == "" && writer == "")
            {
                MessageBox.Show("请输入内容!");
                return;
            }
            else if (bookname == "" && writer != "")
            {
                cmd = "select * from book where Writer like '%" + writer + "%";
            }
            else if (writer == "" && bookname != "")
            {
                cmd = "select * from book where BookName like '%" + bookname + "%";
            }
            else
            {
                cmd = "select * from book where BookName like '%" + bookname + "%' and Writer like '%" + writer + "%";
            }
            cmd = cmd + "';";
            try
            {
                con.Open();
                MySqlCommand    command = new MySqlCommand(cmd, con);
                MySqlDataReader reader  = command.ExecuteReader();
                list.Items.Clear();
                AddHead();
                string[] str = new string[5];
                while (reader.Read())
                {
                    str[0] = reader["BookName"].ToString();

                    str[1] = reader["Writer"].ToString();

                    str[2] = reader["Page"].ToString();

                    str[3] = reader["Public"].ToString();

                    str[4] = reader["DefaultPrice"].ToString();


                    string sep1 = Formatting(str[0], 20);
                    string sep2 = Formatting(str[1], 20);
                    string sep3 = Formatting(str[2], 20);
                    string sep4 = Formatting(str[3], 20);
                    string sep5 = Formatting(str[4], 20);

                    string strsub = sep1 + sep2 + sep3 + sep4 + sep5;

                    this.list.Items.Add(strsub);
                }
                reader.Close();
            }
            catch (MySqlException ex)
            {
                MessageBox.Show(ex.Message);
            }
            con.Close();
        }
Beispiel #7
0
        //点击事件
        //==============================================================================================================================

        private void SelectPic_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openFile = new OpenFileDialog();//用来打开图片选择窗口

            openFile.Filter      = "JPEG|*.jpg";
            openFile.DefaultExt  = "jpg";
            openFile.Multiselect = false;//不能多选


            Image image = new Image();//将原本image的source储存起来;

            image.Source        = this.Picture.Source;
            this.Picture.Source = null;//设置image的源文件为空;

            if (openFile.ShowDialog() == true)
            {
                Computer computer = new Computer(); //computer类,先引入microsoft.visualBasic,再using device;
                string   path     = "d:/libraryresource/Userpicture/";
                bool     ishave   = false;          //用来标记用户之前是否设置过图片;

                //获取原图片文件
                MySqlConnection con     = Connect.Connection();
                string          cmd     = "select * from usermessage where UserId = '" + Connect.GetUser() + "';";
                MySqlCommand    command = new MySqlCommand(cmd, con);
                MySqlDataReader reader;


                con.Open();
                reader = command.ExecuteReader();
                reader.Read();
                if (reader["Picture"].ToString() != null && reader["Picture"].ToString().Trim() != "")
                {
                    string pic = reader["Picture"].ToString().Trim();
                    computer.FileSystem.RenameFile(path + pic, "midpic.jpg");//把原文件名设置为   midpic.jpg
                    ishave = true;
                }
                con.Close();
                reader.Close();



                string type    = System.IO.Path.GetExtension(openFile.FileName);
                string newname = Connect.GetUser() + type;//设置图片新的名字,以用户名命名

                System.IO.File.Copy(openFile.FileName, System.IO.Path.Combine(@path, System.IO.Path.GetFileName(openFile.FileName)));
                string oldname = System.IO.Path.GetFileName(openFile.FileName);

                ////string oldpath = path + openFile.FileName;
                ////File.Move(oldpath, path + name);
                string oldnamepath = path + oldname;

                if (oldname != newname)
                {
                    computer.FileSystem.RenameFile(oldnamepath, newname);
                }
                if (ishave == true)//如果之前有记录,不需要更新,图片的名字不变;如果没有,则向数据库插入对应的信息。
                {
                    computer.FileSystem.DeleteFile(path + "midpic.jpg");
                }
                else
                {
                    con.Open();
                    command.CommandText = "update usermessage set Picture = '" + newname + "' where UserId = '" + Connect.GetUser() + "';";
                    command.ExecuteNonQuery();
                    con.Close();
                }

                //pack://SiteOfOrigin:,,,/

                setImageSource("d:/libraryresource/Userpicture/" + newname);
                return;
            }
            else
            {
                this.Picture.Source = image.Source;
                return;
            }
        }
Beispiel #8
0
        }//检查是否有有关该用户的信息记录

        private void SetValues()
        {
            DeleteTextChange();
            string          picturePath = "d:/LibraryResource/UserPicture/";//pack://SiteOfOrigin:,,,/
            MySqlConnection con         = Connect.Connection();
            string          cmd         = string.Format("select * from usermessage where UserId = '{0}';", Connect.GetUser().ToString());

            MySqlDataReader reader;

            try
            {
                con.Open();
                MySqlCommand command = new MySqlCommand(cmd, con);
                reader = command.ExecuteReader();


                reader.Read();
                this.NickName.Text  = reader["NickName"].ToString();
                this.Age.Text       = reader["Age"].ToString();
                this.College.Text   = reader["College"].ToString();
                this.Address.Text   = reader["Address"].ToString();
                this.Motto.Text     = reader["Motto"].ToString();
                this.Introduce.Text = reader["Introduce"].ToString();

                string pictureName = reader["Picture"].ToString().Trim();//图片设置
                if (pictureName != "" && pictureName != null)
                {
                    picturePath += pictureName;
                    //this.Picture.Source = new BitmapImage(new Uri(picturePath, UriKind.Absolute));
                    setImageSource(picturePath);
                }
                else
                {
                    this.Picture.Source = new BitmapImage(new Uri("pack://SiteOfOrigin:,,,/d:/libraryresource/Userpicture/defaultpic.jpg", UriKind.Absolute));
                }

                reader.Close();
            } catch (MySqlException ex)
            {
                MessageBox.Show(ex.Message + "setvalues");
            }
            con.Close();
            AddTextChange();
            return;
        }//设置所有文本框中的信息
Beispiel #9
0
        //功能函数
        //=======================================================================================================================================
        private void Init()
        {
            MySqlConnection con     = Connect.Connection();
            string          cmd     = "select * from UserMessage where UserId = '" + Connect.GetUser() + "';";
            MySqlCommand    command = new MySqlCommand(cmd, con);
            MySqlDataReader reader;
            bool            isHave = true;

            try
            {
                con.Open();
                reader = command.ExecuteReader();
                reader.Read();
                if (reader.HasRows)
                {
                    isHave = false;
                }

                reader.Close();

                if (isHave)
                {
                    command.CommandText = "insert into UserMessage (UserId) values('" + Connect.GetUser() + "');";
                    command.ExecuteNonQuery();
                }
            }
            catch (MySqlException ex)
            {
                MessageBox.Show(ex.Message + "Init");
            }
            con.Close();
            return;
        }//检查是否有有关该用户的信息记录
Beispiel #10
0
        private void Submit_Click(object sender, RoutedEventArgs e)
        {
            SetEnabledFalse();
            MySqlConnection con = Connect.Connection();
            MySqlCommand    command;
            TextBox         textBox;
            string          mark = "";

            while (true)
            {
                if (ChangeNum == 0)
                {
                    MessageBox.Show("更新完成!");
                    break;
                }
                con.Open();
                for (int i = 0; i < 6; i++)
                {
                    if (Havechanged[i] != null && Havechanged[i] != "")
                    {
                        mark           = Havechanged[i];
                        Havechanged[i] = null;
                        break;
                    }
                }
                textBox = this.FindName(mark) as TextBox;
                string cmd = "update usermessage set " + textBox.Name.Trim() + " = '" + textBox.Text.ToString().Trim() + "' where UserId = '" + Connect.GetUser() + "';";
                command = new MySqlCommand(cmd, con);
                command.ExecuteNonQuery();
                con.Close();
                ChangeNum--;
            }
            this.Change.IsEnabled = true;
            Havechanged           = new string[6];
            ChangeNum             = 0;
            SetValues();
        }