Beispiel #1
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;
        }//检查是否有有关该用户的信息记录
        }//绘制Button的背景色

        private bool CanBook()
        {
            MySqlConnection con = Connect.Connection();
            MySqlDataReader reader;
            MySqlCommand    command;
            bool            result = true;

            try
            {
                con.Open();
                string cmd = "select * from seatbook where UserId = '" + Connect.GetUser() + "';";
                command = new MySqlCommand(cmd, con);
                reader  = command.ExecuteReader();
                if (reader.HasRows)
                {
                    result = false;
                }
                reader.Close();
            }
            catch (MySqlException ex)
            {
                MessageBox.Show(ex.Message);
            }
            con.Close();
            return(result);
        }
        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();
        }
        //功能函数
        //========================================================================================================

        private void Init()
        {
            this.no1.Text = "";
            this.no2.Text = "";
            this.no3.Text = "";
            MySqlConnection con = Connect.Connection();
            MySqlDataReader reader;
            MySqlCommand    command;
            string          cmd = "select * from borrow where UserId = '" + Connect.GetUser() + "';";
            int             i   = 0;

            try
            {
                con.Open();
                command = new MySqlCommand(cmd, con);
                reader  = command.ExecuteReader();
                string  bookname, writer;
                TextBox tb;

                while (reader.Read())
                {
                    i++;
                    bookname = reader["BookName"].ToString().Trim();
                    writer   = reader["Writer"].ToString().Trim();
                    string str1 = Formatting(bookname, 15);
                    string str2 = Formatting(writer, 15);
                    str2 = str2.TrimEnd('|').Trim();
                    string str  = str1 + str2;
                    string name = "no" + i;
                    tb      = this.FindName(name) as TextBox;
                    tb.Text = str;
                }
                i++;

                for (; i <= 3; i++)
                {
                    Button btn = this.FindName("btn_no" + i) as Button;
                    btn.IsEnabled = false;
                }
                reader.Close();
                con.Close();
            }catch (MySqlException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Beispiel #5
0
        private void Win_SourceInitialized(object sender, EventArgs e)
        {
            UserLogin login = new UserLogin();

            login.WindowStyle           = WindowStyle.None;
            login.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
            if (login.ShowDialog() == false)
            {
                this.Close();
            }
            else
            {
                Connect.SetUser(login.UserId);
                tip.Content = "当前用户:" + Connect.GetUser();
            }
            //tip.Content = "当前用户:1";
            //Connect.SetUser("1");
        }
        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 enter_Click(object sender, RoutedEventArgs e)
        {
            bool            mark    = false;
            string          pwd     = getPassWord();
            MySqlConnection con     = Connect.Connection();
            MySqlCommand    command = new MySqlCommand();

            command.CommandText = "select * from login where PassWord = '******' and UserId = '" + Connect.GetUser() + "';";
            command.Connection  = con;
            con.Open();
            MySqlDataReader reader = command.ExecuteReader();

            if (reader.HasRows)
            {
                mark = true;
            }
            reader.Close();
            con.Close();
            if (mark)
            {
                ResetPassword reset = new ResetPassword();
                reset.WindowStyle           = WindowStyle.None;
                reset.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
                reset.ShowDialog();
                this.Close();
            }
            else
            {
                MessageBox.Show("密码输入不正确!");
            }
        }
Beispiel #9
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 #10
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 #11
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 #12
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 #13
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();
        }
        //点击事件
        //==========================================================================================================

        private void ReturnBook(object sender, RoutedEventArgs e)
        {
            Button btn  = sender as Button;
            string name = btn.Name;

            string[] array = name.Split('_');
            name = array[1];
            TextBox tb = this.FindName(name) as TextBox;

            array = tb.Text.Split('|');
            string bookname = array[0].Trim();
            string writer   = array[1].Trim();

            MySqlConnection con = Connect.Connection();
            MySqlCommand    command;
            MySqlDataReader reader;
            string          cmd = "delete from borrow where BookName = '" + bookname + "' and Writer = '" + writer + "' and UserId = '" + Connect.GetUser() + "';";

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

                cmd     = "select * from borrow where BookName = '" + bookname + "' and Writer = '" + writer + "' and UserId = '" + Connect.GetUser() + "'; ";
                command = new MySqlCommand(cmd, con);

                reader = command.ExecuteReader();
                if (!reader.HasRows)
                {
                    MessageBox.Show("成功还书!");
                }
                Init();
            }
            catch (MySqlException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }