Esempio n. 1
0
 private void Refresh()
 {
     InitHeader();
     try
     {
         QualityTrackingDAC           dac       = new QualityTrackingDAC();
         List <QualityTrackingEntity> lstResult = dac.Query(dtpStart.Value, dtpEnd.Value, batch.Text.Trim(), target.Text.Trim(), type.Text.Trim(), decision.Text.Trim());
         DataTable dt = ControlHelper.ConvertList2DataTable(lstResult);
         dataGridResult.DataSource = dt;
     }
     catch (Exception ex)
     {
         MessageBox.Show("读取数据库出错,请检查网络;\r\n原因:" + ex.Message);
     }
 }
Esempio n. 2
0
        private void btnExport_Click(object sender, EventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.Filter = "Excel文件|*.xls";

            //设置默认文件类型显示顺序
            sfd.FilterIndex      = 1;
            sfd.RestoreDirectory = true;
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                DataTable dt;
                try
                {
                    QualityTrackingDAC           dac       = new QualityTrackingDAC();
                    List <QualityTrackingEntity> lstResult = dac.Query(dtpStart.Value, dtpEnd.Value, batch.Text.Trim(), target.Text.Trim(), type.Text, decision.Text);
                    dt = ControlHelper.ConvertList2ExcelTable(lstResult);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("读取数据库出错,请检查网络;\r\n原因:" + ex.Message);
                    return;
                }

                try
                {
                    NPOIHelper.Export(dt, "", sfd.FileName.ToString());
                }
                catch (Exception ex)
                {
                    MessageBox.Show("导出Excel出错;\r\n原因:" + ex.Message);
                    return;
                }
                MessageBox.Show("导出成功");
            }
        }