Esempio n. 1
0
        private void 店铺注册_button_Click(object sender, EventArgs e)
        {
            String          username = this.store_register_box1.Text;
            String          password = this.store_register_box2.Text;
            Database2       db2      = new Database2();
            MySqlConnection conn     = db2.getConn();

            if (username.Equals("") || password.Equals(""))
            {
                MessageBox.Show("账号密码为空");
            }
            else
            {
                try
                {
                    conn.Open();
                    String       sql1  = String.Format("select * from `c#_store`.user_store where username= '******'", username);
                    MySqlCommand comm1 = new MySqlCommand(sql1, conn);
                    String       sql2  = String.Format("insert into `c#_store`.user_store (username,password) values ('{0}','{1}')", username, password);
                    MySqlCommand comm2 = new MySqlCommand(sql2, conn);
                    if (Convert.ToInt32(comm1.ExecuteScalar()) > 0)
                    {
                        MessageBox.Show("账号已经注册,请登录");
                        Form1.form1.登录ToolStripMenuItem_Click(null, null);
                    }
                    else
                    {
                        comm2.ExecuteNonQuery();
                        db2.insert("注册成功");
                        MessageBox.Show("注册成功");
                        Form1.form1.登录ToolStripMenuItem_Click(null, null);
                    }
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception);
                }
                finally
                {
                    conn.Close();
                }
            }
        }
Esempio n. 2
0
        private void store_button_Click(object sender, EventArgs e)
        {
            String          username = this.store_login1.Text;
            String          password = this.store_login2.Text;
            Database2       db       = new Database2();
            MySqlConnection conn     = db.getConn();

            if (username.Equals("") || password.Equals(""))
            {
                MessageBox.Show("账号或密码为空");
            }
            else
            {
                try
                {
                    conn.Open();
                    String       sql1  = String.Format("select * from `c#_store`.user_store where username= '******' ", username);
                    MySqlCommand comm2 = new MySqlCommand(sql1, conn);
                    if (Convert.ToInt32(comm2.ExecuteScalar()) > 0)
                    {
                        String sql = String.Format("select username,password from `c#_store`.user_store   where username = '******' limit 1",
                                                   username);
                        MySqlCommand    comm1  = new MySqlCommand(sql, conn);
                        MySqlDataReader reader = comm1.ExecuteReader();
                        while (reader.Read())
                        {
                            String username1 = reader[0].ToString();
                            String password1 = reader[1].ToString();
                            if (username1 != null && password.Equals(password1))
                            {
                                Form1 form1 = new Form1();
                                form1.username = username;
                                db.insert("登录成功");
                                MessageBox.Show("登录成功");
                                this.Close();
                            }
                            else
                            {
                                db.insert("密码错误,重新输入");
                                MessageBox.Show("密码错误,请重新输入");
                            }
                        }
                        reader.Close();
                    }
                    else
                    {
                        MessageBox.Show("账户不存在,请注册");
                        Form1.form1.注册ToolStripMenuItem_Click(null, null);
                    }
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception);
                    MessageBox.Show(exception.Message.ToString());
                }
                finally
                {
                    conn.Close();
                }
            }
        }