zoukankan      html  css  js  c++  java
  • 日期与地区的三级联动

    地区的三级联动:

    数据库中有地区名,地区编号,上级编号;

    public Form1()
    {
    InitializeComponent();
    chinastatesdata chi = new chinastatesdata();
    List<chinastates> cl = chi.select(0001);
    comboBox1.DataSource = cl;
    comboBox1.DisplayMember = "areaname";
    comboBox1.ValueMember = "areacode";
    }

    private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
    {
    //chinastatesdata chi = new chinastatesdata();
    //int a = 11;
    //if (comboBox1.Text.Length < 20)
    //{
    // a = chi.se(comboBox1.Text);
    //}
    chinastates c = comboBox1.SelectedItem as chinastates;
    List<chinastates> cl = new chinastatesdata().select(c.areacode);
    comboBox2.DataSource = cl;
    comboBox2.DisplayMember = "areaname";
    comboBox2.ValueMember = "areacode";
    }

    private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
    {
    chinastates c = comboBox2.SelectedItem as chinastates;
    List<chinastates> cl = new chinastatesdata().select(c.areacode);
    comboBox3.DataSource = cl;
    comboBox3.DisplayMember = "areaname";
    comboBox3.ValueMember = "areacode";
    }

    public List<chinastates> select(int a)
    {
    List<chinastates> cl = new List<chinastates>();
    com.CommandText = "select * from chinastates where parentareacode= @a";
    com.Parameters.Clear();
    com.Parameters.AddWithValue("@a", a);
    con.Open();
    SqlDataReader dr = com.ExecuteReader();
    if (dr.HasRows)
    {
    while (dr.Read())
    {
    chinastates c = new chinastates();
    c.areacode = Convert.ToInt32(dr["areacode"]);
    c.areaname = dr["areaname"].ToString();
    cl.Add(c);
    }
    }
    con.Close();
    return cl;
    }

    --------------------------------

    日期的三级联动:

    List<int> i = new List<int>();
    for (int x = DateTime.Now.Year; x > 1950; x--)
    {
    i.Add(x);
    }
    comboBox2.DataSource = i;

    List<int> ii = new List<int>();
    for(int x = 1; x < 13; x++)
    {
    ii.Add(x);
    }
    comboBox3.DataSource = ii;

    List<int> iii = new List<int>();
    iii.Add(1);
    comboBox4.DataSource = iii;

    private void textBox2_Enter(object sender, EventArgs e)
    {
    if (textBox2.ForeColor == Color.Red)
    {
    textBox2.Text = "";
    textBox2.ForeColor = Color.Black;
    }
    }

    private void textBox3_Enter(object sender, EventArgs e)
    {
    if (textBox3.ForeColor == Color.Red)
    {
    textBox3.Text = "";
    textBox3.ForeColor = Color.Black;
    }
    }

    private void comboBox4_Enter(object sender, EventArgs e)
    {
    int n = Convert.ToInt32(comboBox2.Text);
    int y = Convert.ToInt32(comboBox3.Text);
    if (y == 2 && ((n % 4 == 0 && n % 100 != 0) || n % 400 == 0))
    {
    List<int> i = new List<int>();
    for (int x = 1; x <= 29; x++)
    {
    i.Add(x);
    }
    comboBox4.DataSource = i;
    }
    if (y == 2 && (n % 4 != 0 || (n % 100 == 0 && n % 400 != 0)))
    {
    List<int> i = new List<int>();
    for (int x = 1; x <= 28; x++)
    {
    i.Add(x);
    }
    comboBox4.DataSource = i;
    }
    if (y == 1 || y == 3 || y == 5 || y == 7 || y == 8 || y == 10 || y == 12)
    {
    List<int> i = new List<int>();
    for (int x = 1; x <= 31; x++)
    {
    i.Add(x);
    }
    comboBox4.DataSource = i;
    }
    if (y == 4 || y == 6 || y == 9 || y == 11)
    {
    List<int> i = new List<int>();
    for (int x = 1; x <= 30; x++)
    {
    i.Add(x);
    }
    comboBox4.DataSource = i;
    }
    }

  • 相关阅读:
    SystemVerilog搭建测试平台---第一章:验证导论
    二线制I2C CMOS串行EEPROM续
    二线制I2C CMOS串行EEPROM
    Codeforces 777E:Hanoi Factory(贪心)
    2019HPU-ICPC-Training-1
    Codeforces 777B:Game of Credit Cards(贪心)
    Codeforces 777D:Cloud of Hashtags(暴力,水题)
    Codeforces 777C:Alyona and Spreadsheet(预处理)
    Codeforces 888D: Almost Identity Permutations(错排公式,组合数)
    Codeforces 888E:Maximum Subsequence(枚举,二分)
  • 原文地址:https://www.cnblogs.com/m110/p/7889882.html
Copyright © 2011-2022 走看看