Esempio n. 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            string        s   = str;
            SqlConnection con = new SqlConnection(s);

            con.Open();
            manager f1 = (manager)this.Owner;

            f1.Controls["textBox1"].Text = "";
            if (radioButton2.Checked)
            {
                string     sql     = string.Format("select * from manager where id='{0}'", textBox1.Text);
                SqlCommand command = new SqlCommand(sql, con);

                SqlDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    string id        = (String)reader["id"];
                    string name      = (String)reader["name"];
                    string native    = (String)reader["native"];
                    string adress    = (String)reader["adress"];
                    string phone     = (String)reader["phone"];
                    string age       = (String)reader["age"];
                    string sex       = (String)reader["sex"];
                    string salary    = (String)reader["salary"];
                    string date      = (String)reader["date"];
                    string education = (String)reader["education"];
                    f1.Controls["textBox1"].Text += String.Format("编号:{0}\r\n姓名:{1}\r\n性别:{2}\r\n籍贯:{3}\r\n出生日期:{4}\r\n学历:{5}\r\n住址:{6}\r\n电话:{7}\r\n工龄:{8}\r\n基本工资{9}\r\n", id, name, sex, native, date, education, adress, phone, age,
                                                                  salary);
                    f1.Controls["textBox1"].Text += String.Format("**************************************************************************************************\r\n");
                }
            }

            else
            {
                string     sql     = string.Format("select * from manager where name='{0}'", textBox1.Text);
                SqlCommand command = new SqlCommand(sql, con);

                SqlDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    string id        = (String)reader["id"];
                    string name      = (String)reader["name"];
                    string native    = (String)reader["native"];
                    string adress    = (String)reader["adress"];
                    string phone     = (String)reader["phone"];
                    string age       = (String)reader["age"];
                    string sex       = (String)reader["sex"];
                    string salary    = (String)reader["salary"];
                    string date      = (String)reader["date"];
                    string education = (String)reader["education"];
                    f1.Controls["textBox1"].Text += String.Format("编号:{0}\r\n姓名:{1}\r\n性别:{2}\r\n籍贯:{3}\r\n出生日期:{4}\r\n学历:{5}\r\n住址:{6}\r\n电话:{7}\r\n工龄:{8}\r\n基本工资{9}\r\n", id, name, sex, native, date, education, adress, phone, age,
                                                                  salary);
                    f1.Controls["textBox1"].Text += String.Format("**************************************************************************************************\r\n");
                }
            }
        }
Esempio n. 2
0
        private void button2_Click(object sender, EventArgs e)
        {
            string        s   = str;
            SqlConnection con = new SqlConnection(s);

            con.Open();
            manager f1 = (manager)this.Owner;

            f1.Controls["textBox1"].Text = "";

            string     sql     = string.Format("select * from manager ");
            SqlCommand command = new SqlCommand(sql, con);

            SqlDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                string id        = (String)reader["id"];
                string allsalary = (String)reader["allsalary"];
                f1.Controls["textBox1"].Text += String.Format("编号:{0}\t 薪水:{1}\r\n", id, allsalary);
            }
            this.Close();
        }
Esempio n. 3
0
        private void button1_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection();

            con.ConnectionString = str;
            con.Open();

            string userid   = this.textBox1.Text;
            string password = this.textBox2.Text;

            if (radioButton2.Checked)
            {
                if (userid.Equals("") || password.Equals(""))//用户名或密码为空
                {
                    MessageBox.Show("用户名或密码不能为空");
                }
                else//用户名或密码不为空
                {
                    string        connectionString = str;
                    SqlConnection SqlCon           = new SqlConnection(connectionString);                          //数据库连接
                    SqlCon.Open();                                                                                 //打开数据库
                    string     sql = "Select * from admin where aid='" + userid + "' and apwd='" + password + "'"; //查找用户sql语句
                    SqlCommand cmd = new SqlCommand(sql, SqlCon);
                    cmd.CommandType = CommandType.Text;
                    SqlDataReader sdr;
                    sdr = cmd.ExecuteReader();
                    if (sdr.Read())         //从结果中找到
                    {
                        Form admin = new admin();
                        this.Hide();
                        admin.ShowDialog();
                        this.Close();

                        MessageBox.Show("登录成功", "提示");
                    }
                    else
                    {
                        MessageBox.Show("用户名或密码错误", "提示");
                        return;
                    }
                }
            }


            if (radioButton1.Checked)
            {
                if (userid.Equals("") || password.Equals(""))//用户名或密码为空
                {
                    MessageBox.Show("用户名或密码不能为空");
                }
                else//用户名或密码不为空
                {
                    string        connectionString = str;
                    SqlConnection SqlCon           = new SqlConnection(connectionString);                           //数据库连接
                    SqlCon.Open();                                                                                  //打开数据库
                    string     sql = "Select * from [user] where uid='" + userid + "' and upwd='" + password + "'"; //查找用户sql语句
                    SqlCommand cmd = new SqlCommand(sql, SqlCon);
                    cmd.CommandType = CommandType.Text;
                    SqlDataReader sdr;
                    sdr = cmd.ExecuteReader();
                    if (sdr.Read())         //从结果中找到
                    {
                        Form manager = new manager();
                        this.Hide();
                        manager.ShowDialog();
                        this.Close();

                        MessageBox.Show("登录成功", "提示");
                    }
                    else
                    {
                        MessageBox.Show("用户名或密码错误", "提示");
                        return;
                    }
                }
            }
            con.Close();
        }