• 日期与地区的三级联动


    地区的三级联动:

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

    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;
    }
    }

  • 相关阅读:
    cookie加密
    【雅思】【绿宝书错词本】List1~12
    【日语】【标日初下单词】45~48课
    【日语】【标日初下单词】41~44课
    【日语】【标日初下单词】37~40课
    【日语】【标日初下单词】33~36课
    jQuery火箭图标返回顶部代码
    jQuery火箭图标返回顶部代码
    jQuery火箭图标返回顶部代码
    jQuery火箭图标返回顶部代码
  • 原文地址:https://www.cnblogs.com/m110/p/7889882.html
Copyright © 2020-2023  润新知