private void button2_Click(object sender, EventArgs e) { try { dataGridView1.DataSource = null; dataGridView1.Columns.Clear(); string tablename = "NBShouLiao"; SqlConnection mConn = new SqlConnection(Conlist.ConStr); SqlCommand cmd = new SqlCommand(); cmd.Connection = mConn; // MessageBox.Show(dateTimePicker1.Value.Date.ToShortDateString()); cmd.CommandText = "select NBSerial,NewNBSerial, Model ,ShipDate,Status from " + tablename + " where ShipDate between '" + dateTimePicker1.Value.Date + "' and '" + dateTimePicker2.Value.Date + "'"; // cmd.CommandText = "select NBSerial,NewNBSerial, Model ,ShipDate,Status from " + tablename + " where ShipDate = '" + dateTimePicker1.Value.Date +"'"; cmd.CommandType = CommandType.Text; SqlDataAdapter sda = new SqlDataAdapter(); sda.SelectCommand = cmd; DataSet ds = new DataSet(); sda.Fill(ds, tablename); dataGridView1.DataSource = ds.Tables[0]; dataGridView1.RowHeadersVisible = false; string[] hTxt = { "原机序号", "新机器序号", "型号", "出货日期", "状态" }; for (int i = 0; i < hTxt.Length; i++) { dataGridView1.Columns[i].HeaderText = hTxt[i]; // dataGridView1.Columns[i].Name = hTxt[i]; } EXCELIO excel = new EXCELIO(); string filename = dateTimePicker1.Value.Date.ToShortDateString().Replace("/", "-") + "到" + dateTimePicker2.Value.Date.ToShortDateString().Replace("/", "-") + "出货明细" + ".xlsx"; bool ok = excel.ExportExcel(dateTimePicker1.Value.Date.ToShortDateString() + "到" + dateTimePicker2.Value.Date.ToShortDateString() + "出货明细", ds.Tables[0], @"D:\出货\" + filename); if (ok == true) { MessageBox.Show("导出OK!!"); } else { MessageBox.Show("导出 Fail !!"); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private void button3_Click(object sender, EventArgs e) { try { dataGridView1.DataSource = null; dataGridView1.Columns.Clear(); string tablename = "ChuKu"; SqlConnection mConn = new SqlConnection(Conlist.ConStr); SqlCommand cmd = new SqlCommand(); cmd.Connection = mConn; cmd.CommandText = "select * from " + tablename + " where chukudate = '" + System.DateTime.Today.ToShortDateString() + "'"; cmd.CommandType = CommandType.Text; SqlDataAdapter sda = new SqlDataAdapter(); sda.SelectCommand = cmd; DataSet ds = new DataSet(); sda.Fill(ds, tablename); dataGridView1.DataSource = ds.Tables[0]; dataGridView1.RowHeadersVisible = false; //dataGridView1.ColumnHeadersVisible = false; EXCELIO excel = new EXCELIO(); string path = @"D:\出库材料"; CodeSoft.MakePath(path); string filename = @"D:\出库材料\" + System.DateTime.Today.ToShortDateString().Replace("/", "-") + "的材料出库" + ".xlsx"; bool ok = excel.ExportExcel(System.DateTime.Today.ToShortDateString().Replace("/", "-") + "材料出库明细", ds.Tables[0], filename); if (ok == true) { MessageBox.Show("导出OK!!"); } else { MessageBox.Show("导出 Fail !!"); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private void button2_Click(object sender, EventArgs e) { try { dataGridView1.DataSource = null; dataGridView1.Columns.Clear(); SqlConnection mConn = new SqlConnection(Conlist.ConStr); SqlCommand cmd = new SqlCommand(); cmd.Connection = mConn; // MessageBox.Show(dateTimePicker1.Value.Date.ToShortDateString()); cmd.CommandText = "select * from " + tableName + " where rukudate between '" + dateTimePicker1.Value.Date + "' and '" + dateTimePicker2.Value.Date + "'"; // cmd.CommandText = "select NBSerial,NewNBSerial, Model ,ShipDate,Status from " + tablename + " where ShipDate = '" + dateTimePicker1.Value.Date +"'"; cmd.CommandType = CommandType.Text; SqlDataAdapter sda = new SqlDataAdapter(); sda.SelectCommand = cmd; DataSet ds = new DataSet(); sda.Fill(ds, tableName); dataGridView1.DataSource = ds.Tables[0]; dataGridView1.RowHeadersVisible = false; EXCELIO excel = new EXCELIO(); string path = @"D:\入库材料"; CodeSoft.MakePath(path); string filename = dateTimePicker1.Value.Date.ToShortDateString().Replace("/", "-") + "到" + dateTimePicker2.Value.Date.ToShortDateString().Replace("/", "-") + "入库明细" + ".xlsx"; bool ok = excel.ExportExcel(dateTimePicker1.Value.Date.ToShortDateString() + "到" + dateTimePicker2.Value.Date.ToShortDateString() + "入库明细", ds.Tables[0], @"D:\入库材料\" + filename); if (ok == true) { MessageBox.Show("导出OK!!"); } else { MessageBox.Show("导出 Fail !!"); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }