private void Form1_Load(object sender, EventArgs e) { this.comboBox1.DataSource = ClsProductPhoto.ProductLoad(); //using (SqlConnection conn = new SqlConnection(Settings.Default.ADW)) //{ // using (SqlCommand comm = new SqlCommand // ("select distinct YEAR(ModifiedDate) AS Year from Production.ProductPhoto", conn)) // { // this.comboBox1.Items.Clear(); // this.comboBox1.Items.Add("All Years"); // conn.Open(); // SqlDataReader dataReader = comm.ExecuteReader(); // while(dataReader.Read()) // { // this.comboBox1.Items.Add(dataReader["Year"]); // } // this.comboBox1.SelectedIndex = 0; // } //} }
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { flowLayoutPanel1.Controls.Clear(); List <UserControl1> Newcon = new List <UserControl1>(); if (comboBox1.Text == "All Years") { Newcon = ClsProductPhoto.panelshow(); } else { Newcon = ClsProductPhoto.panelshow(comboBox1.Text); } for (int i = 0; i <= Newcon.Count - 1; i++) { flowLayoutPanel1.Controls.Add(Newcon[i]); } //using (SqlConnection conn = new SqlConnection(Settings.Default.ADW)) // if (comboBox1.Text == "All Years") // { // flowLayoutPanel1.Controls.Clear(); // this.comboBox1.DataSource = ClsProductPhoto.ProductLoad(); // flowLayoutPanel1.Controls.Clear(); // using (SqlCommand comm = new SqlCommand("select LargePhoto,LargePhotoFileName from Production.ProductPhoto", conn)) // { // conn.Open(); // SqlDataReader dataReader = comm.ExecuteReader(); // while (dataReader.Read()) // { // byte[] by = (byte[])dataReader["LargePhoto"];//datareader讀到的資料放到byte之中 // using (MemoryStream ms = new MemoryStream(by)) // { // UserControl1 us = new UserControl1(); // us.BtnName = dataReader["LargePhotoFileName"].ToString(); // us.Btnpicture = Image.FromStream(ms); // flowLayoutPanel1.Controls.Add(us); // } // } // } // } // else // { // flowLayoutPanel1.Controls.Clear(); // using (SqlCommand comm = new SqlCommand ("select LargePhoto,LargePhotoFileName from Production.ProductPhoto where YEAR(ModifiedDate) =" + this.comboBox1.Text, conn)) // { // conn.Open(); // SqlDataReader dataReader = comm.ExecuteReader(); // while (dataReader.Read()) // { // byte[] by = (byte[])dataReader["LargePhoto"];//datareader讀到的資料放到byte之中 // using (MemoryStream ms = new MemoryStream(by)) // { // UserControl1 us = new UserControl1(); // us.BtnName = dataReader["LargePhotoFileName"].ToString(); // us.Btnpicture = Image.FromStream(ms); // flowLayoutPanel1.Controls.Add(us); // } // } // } // } }