zoukankan      html  css  js  c++  java
  • 用户登录系统(三)

    下面就是对主窗体的操作了:

    首先将test.DAL 和test.BLL引入

    然后编辑代码如下:

      1     public partial class Form1 : Form
      2     {
      3         #region 窗体登录
      4         public Form1()
      5         {
      6             InitializeComponent();
      7             dataGridView1.DataSource = test_BLL.User_info.UserinfoManager.getUserTable();
      8         }
      9         #endregion
     10 
     11         #region 刷新datagridview数据
     12         public void refresh()
     13         {
     14             dataGridView1.DataSource = test_BLL.User_info.UserinfoManager.getUserTable();
     15         }
     16         #endregion
     17 
     18         #region 清除testbox
     19         public void clear()
     20         {
     21             this.textBox1.Clear();
     22             this.textBox2.Clear();
     23             this.textBox3.Clear();
     24         }
     25         #endregion
     26 
     27         #region 用户新增
     28         private void toolStripButton1_Click_1(object sender, EventArgs e)
     29         {
     30             this.clear();
     31             this.textBox1.Focus();
     32         }
     33         #endregion
     34 
     35         #region 用户修改
     36         private void toolStripButton2_Click(object sender, EventArgs e)
     37         {
     38             this.textBox1.Focus();
     39             int index = dataGridView1.CurrentRow.Index;
     40             if (index != -1)
     41             {
     42                 object str = dataGridView1.SelectedRows[0].Cells[1].Value;
     43                 object str1 = dataGridView1.SelectedRows[0].Cells[2].Value;
     44                 object str2 = dataGridView1.SelectedRows[0].Cells[3].Value;
     45                 SqlDataReader sdr = test_BLL.User_info.UserinfoManager.selectUser(str.ToString());
     46                 if (sdr.HasRows && sdr.Read())
     47                 {
     48                     textBox1.Text = sdr.GetValue(1).ToString();
     49                     textBox2.Text = sdr.GetValue(2).ToString();
     50                     textBox3.Text = sdr.GetValue(3).ToString();
     51                 }
     52                 sdr.Close();
     53             }
     54             else
     55             {
     56                 MessageBox.Show("请选择右侧数据");
     57             }
     58         }
     59         #endregion
     60 
     61         #region 用户删除
     62         private void toolStripButton3_Click(object sender, EventArgs e)
     63         {
     64             DialogResult dr = MessageBox.Show("确定删除?");
     65             if (dr == DialogResult.OK)
     66             {
     67                 int index = dataGridView1.CurrentRow.Index;
     68                 if (index != -1)
     69                 {
     70                     //也可以不用一下的判断
     71                     SqlDataReader sdr =tset.DAL.Common.SqlHelper.GetReader(this.dataGridView1.SelectedRows[0].Cells[1].Value.ToString());
     72                     if (sdr.HasRows)
     73                     {
     74                         test_BLL.User_info.UserinfoManager.DeleteUser(this.dataGridView1.SelectedRows[0].Cells[1].Value.ToString());
     75 
     76                         MessageBox.Show("删除成功");
     77                     }
     78                     else
     79                     {
     80                         MessageBox.Show("删除失败");
     81                     }
     82                 }
     83             }
     84             this.refresh();
     85             this.clear();
     86         }
     87         #endregion
     88 
     89         #region 用户登录
     90         private void toolStripButton4_Click(object sender, EventArgs e)
     91         {
     92             if (this.textBox1.Text == "" || this.textBox2.Text == "" || this.textBox3.Text == "")
     93             {
     94                 MessageBox.Show("请填写登录信息");
     95                 this.label4.Text = "登录失败";
     96             }
     97             else
     98             {
     99                 SqlDataReader sdr;
    100                 sdr = test_BLL.User_info.UserinfoManager.userLogin(this.textBox1.Text, this.textBox2.Text, this.textBox3.Text);
    101                 if (sdr.HasRows)
    102                 {
    103                     this.label4.Text = this.textBox2.Text + "登录成功!";
    104                 }
    105                 else
    106                 {
    107                     MessageBox.Show("请重新填写登录信息");
    108                     this.textBox1.Focus();
    109                     this.label4.Text = this.textBox1.Text + "用户名或密码错误!";
    110                 }
    111                 this.refresh();
    112                 this.clear();
    113             }
    114         }
    115         #endregion
    116 
    117         #region 重置
    118         private void button1_Click(object sender, EventArgs e)
    119         {
    120             this.refresh();
    121             this.clear();
    122         }
    123         #endregion
    124 
    125         #region 保存
    126         private void button2_Click(object sender, EventArgs e)
    127         {
    128             if (this.textBox1.Text == "" || this.textBox2.Text == "" || this.textBox3.Text == "")
    129             {
    130                 MessageBox.Show("您填写的信息有误!");
    131             }
    132             else
    133             {
    134                 SqlDataReader sdr = test_BLL.User_info.UserinfoManager.selectUser(this.textBox1.Text); ;
    135                 if (sdr.HasRows)
    136                 {
    137                     test_BLL.User_info.UserinfoManager.UpdateUser(this.textBox1.Text, this.textBox2.Text, this.textBox3.Text);
    138                     MessageBox.Show("修改成功");
    139                 }
    140                 else
    141                 {
    142                     test_BLL.User_info.UserinfoManager.InsertUser(this.textBox1.Text, this.textBox2.Text, this.textBox3.Text);
    143                     MessageBox.Show("新增成功");
    144                 }
    145                 sdr.Close();
    146                 this.refresh();
    147                 this.clear();
    148             }
    149         }
    150         #endregion
    151 
    152         #region 查找
    153         private void button3_Click(object sender, EventArgs e)
    154         {
    155             string textbox_search = "";
    156             textbox_search = this.textBox4.Text;
    157             if (textbox_search != "")
    158             {
    159                 DataTable dt = test_BLL.User_info.UserinfoManager.getConditionUserTable(textbox_search, textbox_search, textbox_search);
    160             }
    161             else
    162             {
    163                 refresh();
    164             }
    165         }
    166         #endregion
    167     }

    这样一个简单的操作用户增删改查的小程序就完成啦!

  • 相关阅读:
    JQuery Ajax 在asp.net中使用小结
    加班对你的提升有多大?
    .net学习笔记---HttpResponse类
    .net学习笔记----HttpRequest类
    MVC学习笔记---MVC生命周期
    MVC学习笔记---MVC生命周期及管道
    .net学习笔记---HttpHandle与HttpModule
    C#学习笔记---修饰符,this关键字和static关键字
    C#学习笔记---如何提高代码逼格
    Linq学习笔记---Linq to Sql之where
  • 原文地址:https://www.cnblogs.com/xiaolong617/p/2751512.html
Copyright © 2011-2022 走看看