/// <summary> /// 生产物料清单 /// </summary> private void btnPrint_Click(object sender, EventArgs e) { string slipNumbers = ""; foreach (DataGridViewRow dr in dgvData.Rows) { if (CConvert.ToBoolean(dr.Cells["CHK"].Value)) { slipNumbers += "'" + CConvert.ToString(dr.Cells["SLIP_NUMBER"].Value) + "',"; } } if (slipNumbers.Length > 0) { slipNumbers = slipNumbers.Substring(0, slipNumbers.Length - 1); } else { MessageBox.Show("请先选择订单。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } SaveFileDialog sf = new SaveFileDialog(); sf.FileName = "HD_BOM_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls"; sf.Filter = "(文件)|*.xls;*.xlsx"; if (sf.ShowDialog(this) == DialogResult.OK) { DataTable dt = bProduce.GetBomList(slipNumbers).Tables[0]; int i = 1; _bomDt.Rows.Clear(); DataRow dr = null; foreach (DataRow row in dt.Rows) { dr = _bomDt.NewRow(); dr["序号"] = i++; dr["规格/参数"] = row["CODE"]; dr["名称"] = row["NAME"]; dr["数量"] = CConvert.ToDecimal(row["QUANTITY"]); dr["备注"] = ""; _bomDt.Rows.Add(dr); } CExport.DataTableToExcel_BOM(sf.FileName, _bomDt); MessageBox.Show("导出完成。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } }