zoukankan      html  css  js  c++  java
  • timer控件、三级联动、帐号激活权限设置

    一、Timer控件

    Timer实际就是一个线程控件。

    属性:Enabled    是否被启用

            Interval     多长时间执行一次控件中的代码

    事件: Tick     事件中放要执行的代码。

    利用Timer控件可以实现即时聊天功能。动态的从数据库查询别人发的信息展示到聊天框中。

    二、三级联动

    实体类

    1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Text;
     5 
     6 namespace WindowsFormsApplication2
     7 {
     8     public class China
     9     {
    10         private string _AreaCode;
    11 
    12         public string AreaCode
    13         {
    14             get { return _AreaCode; }
    15             set { _AreaCode = value; }
    16         }
    17         private string _AreaName;
    18 
    19         public string AreaName
    20         {
    21             get { return _AreaName; }
    22             set { _AreaName = value; }
    23         }
    24         private string _ParentAreaCode;
    25 
    26         public string ParentAreaCode
    27         {
    28             get { return _ParentAreaCode; }
    29             set { _ParentAreaCode = value; }
    30         }
    31 
    32     }
    33 }

    数据操作类:

    1 using System;
     2 using System.Collections.Generic;
     3 using System.Data.SqlClient;
     4 using System.Linq;
     5 using System.Text;
     6 
     7 namespace WindowsFormsApplication2
     8 {
     9     public class ChinaData
    10     {
    11         SqlConnection conn = null;
    12         SqlCommand cmd = null;
    13 
    14         public ChinaData()
    15         {
    16             conn = new SqlConnection("server=.;database=Data0216;user=sa;pwd=123");
    17             cmd = conn.CreateCommand();
    18         }
    19 
    20         //通过一个父级编号,查询该父级编号对应的地区,放到一个集合中去。
    21         public List<China> Select(string pcode)
    22         {
    23             List<China> clist = new List<China>();
    24             cmd.CommandText = "select *from ChinaStates where ParentAreaCode = @a";
    25             cmd.Parameters.Clear();
    26             cmd.Parameters.AddWithValue("@a", pcode);
    27             conn.Open();
    28             SqlDataReader dr = cmd.ExecuteReader();
    29             while (dr.Read())
    30             {
    31                 China c = new China();
    32                 c.AreaCode = dr[0].ToString();
    33                 c.AreaName = dr[1].ToString();
    34                 c.ParentAreaCode = dr[2].ToString();
    35 
    36                 clist.Add(c);
    37             }
    38             conn.Close();
    39             return clist;
    40         }
    41     }
    42 }

    后台代码

    1 using System;
     2 using System.Collections.Generic;
     3 using System.ComponentModel;
     4 using System.Data;
     5 using System.Drawing;
     6 using System.Linq;
     7 using System.Text;
     8 using System.Windows.Forms;
     9 
    10 namespace WindowsFormsApplication2
    11 {
    12     public partial class Form1 : Form
    13     {
    14         public Form1()
    15         {
    16             InitializeComponent();
    17 
    18             //调用方法绑定所有省
    19             Bind("0001", comboBox1);
    20             //绑定所有选中省下面的市,selectvalue是绑定数据源给程序看的value中的选中的内容,和数据库有关。
    21             Bind(comboBox1.SelectedValue.ToString(), comboBox2);
    22             //绑定所有选中市下面的区县
    23             Bind(comboBox2.SelectedValue.ToString(), comboBox3);
    24 
    25         }
    26 
    27         //数据绑定方法(给我一个地区父级编号,绑定到相应的Combox中去),需要一个地区父级编号和一个Combox对象两个参数
    28         public void Bind(string pcode, ComboBox cb)
    29         {
    30             //给一个父级编号,把该父级编号查到的地区放到集合clist中去
    31             List<China> clist = new ChinaData().Select(pcode);
    32             
    33             //绑定Combox的数据源
    34             cb.DataSource = clist;
    35             cb.DisplayMember = "AreaName";
    36             cb.ValueMember = "AreaCode";
    37         }
    38 
    39         //Combox1选中内容改变时,Combox2和Combox3中的数据源相应的改变。
    40         private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
    41         {
    42 
    43             Bind(comboBox1.SelectedValue.ToString(), comboBox2);
    44             if (comboBox2.SelectedValue != null)
    45             {
    46                 Bind(comboBox2.SelectedValue.ToString(), comboBox3);
    47             }
    48         }
    49 
    50         //Combox2中选中内容改变时,Combox3中的数据源响应的改变。
    51         private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
    52         {
    53             Bind(comboBox2.SelectedValue.ToString(), comboBox3);
    54         }
    55     }
    56 }

    三、权限设置

    所谓权限设置就是根据登录用户帐号的不同,该帐号对应显示的操作功能不同

    实现方法:在数据库的用户表中增加字段进行权限的区分,根据从数据库表中查询到的数据进行相应的

  • 相关阅读:
    题解:2018级算法第五次上机 C5-图2
    题解:2018级算法第四次上机 C4-最小乘法
    题解:2018级算法第四次上机 C4-商人卖鱼
    题解:2018级算法第三次上机 C3-Zexal的浩瀚星辰
    C语言算法动态规划板子题汇总
    QT样式表
    3.PCB-禁止布线层
    2.PCB-板切割槽
    1.PCB-板形设置
    变压器
  • 原文地址:https://www.cnblogs.com/snow22546/p/6873698.html
Copyright © 2011-2022 走看看