• timer控件、三级联动


    timer控件:

    实现时间日期自增长:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    
    namespace timer控件
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
    
                label1.Text = DateTime.Now.ToString("yyyy年MM月dd日hh时mm分ss秒");
            }
            //计时器
            private void timer1_Tick(object sender, EventArgs e)
            {
                label1.Text = DateTime.Now.ToString("yyyy年MM月dd日hh时mm分ss秒");
            }
        }
    }

    抽奖设置,点击开始开始抽奖,开始按钮变为结束,点击结束,抽奖结束,结束按钮变为开始:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    
    namespace timer控件
    {
        public partial class Form2 : Form
        {
            List<long> nu = new List<long>();
            Random r = new Random();
    
            public Form2()
            {
                InitializeComponent();
                nu.Add(13969374807);
                nu.Add(13864311111);
                nu.Add(13864322222);
                nu.Add(13864333333);
                nu.Add(13864344444);
    
            }
            //抽奖
            bool s = false;
            private void button1_Click(object sender, EventArgs e)
            {
                if (s)//结束抽奖
                {
                    button1.Text = "开始";
                    s = false;
                    timer1.Enabled = false;
                }
                else//开始抽奖
                {
                    button1.Text = "停止";
                    s = true;
                    timer1.Enabled = true;            
                }
            }
    
            private void timer1_Tick(object sender, EventArgs e)
            {
                label2.Text= nu[r.Next(0,nu.Count)].ToString();
            }
        }
    }

    作弊:
    在if结束抽奖中加一句代码:

    label2.text="13969374807";

    三级联动:

    创建实体类:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace 三级联动.App_Code
    {
        public class china
        {
            public string areacode { get; set; }
            public string areaname { get; set; }
            public string parentareacode { get; set; }
    
        }
    }

    创建数据访问类:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Data.SqlClient;
    
    namespace 三级联动.App_Code
    {
        public class chinadata
        {
            SqlConnection conn = null;
            SqlCommand cmd = null;
    
            public chinadata()
            {
                conn = new SqlConnection("server=.;database=mydb;user=sa;pwd=123");
                cmd = conn.CreateCommand();       
            }
    
            public List<china> select(string pcode)
            {
                List<china> clist = new List<china>();
                cmd.CommandText = "select*from ChinaStates where ParentAreaCode=@a";
                cmd.Parameters.Clear();
                cmd.Parameters.Add("@a",pcode);
                conn.Open();
                SqlDataReader dr = cmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        china c = new china();
                        c.areacode = dr[0].ToString();
                        c.areaname = dr[1].ToString();
                        c.parentareacode = dr[2].ToString();
                        clist.Add(c);
                    }            
                }
                conn.Close();
                return clist;
            }
    
    
    
        }
    }

    form1:使用selectedindexchanged事件,引用命名空间

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using 三级联动.App_Code;
    
    namespace 三级联动
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
    
    
                //绑定省
                comboBox1.DataSource = new chinadata().select("0001");
                comboBox1.DisplayMember = "areaname";
                comboBox1.ValueMember = "areacode";
    
                //绑定市
                comboBox2.DataSource = new chinadata().select(comboBox1.SelectedValue.ToString());
                comboBox2.DisplayMember = "areaname";
                comboBox2.ValueMember = "areacode";
    
                //绑定区
                comboBox3.DataSource = new chinadata().select(comboBox2.SelectedValue.ToString());
                comboBox3.DisplayMember = "areaname";
                comboBox3.ValueMember = "areacode";
    
    
            }
    
            private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
            {
           //绑定市跟随省移动 comboBox2.DataSource
    = new chinadata().select(comboBox1.SelectedValue.ToString()); comboBox2.DisplayMember = "areaname"; comboBox2.ValueMember = "areacode"; } private void comboBox2_SelectedIndexChanged(object sender, EventArgs e) {
           //绑定区跟随市移动 comboBox3.DataSource
    = new chinadata().select(comboBox2.SelectedValue.ToString()); comboBox3.DisplayMember = "areaname"; comboBox3.ValueMember = "areacode"; } } }

  • 相关阅读:
    困扰程序员的30种软件开发问题,你是否时曾相识?
    一位阿里架构师给每个程序员的小建议
    一位阿里架构师给每个程序员的小建议
    一位阿里架构师给每个程序员的小建议
    MongoDB常用语句
    MongoDB常用语句
    ACM2055_ctype.h_cctype
    Serverless 每周小报-20190610
    linux-深度学习环境配置-Centos
    2018 ACM 国际大学生程序设计竞赛上海大都会赛
  • 原文地址:https://www.cnblogs.com/wy1992/p/6165847.html
Copyright © 2020-2023  润新知