private void btnExcel_Click(object sender, EventArgs e) { //PrintExcel pe = new PrintExcel(); //pe.OutputAsExcelFile(dgvAppDetail); SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "PDF文件(*.pdf)|*.pdf"; // Show save file dialog box DialogResult result = saveFileDialog.ShowDialog(); if (result == DialogResult.OK) { try { string strRandom = getRandomString(12); string tempFilePath = System.IO.Directory.GetCurrentDirectory() + @"\tempPDF\" + strRandom + ".xls"; PrintExcel pe = new PrintExcel(); pe.WriteToExcelReport(pe.exporeDataToTable(dgvAppDetail), tempFilePath, "Sheet1"); string localFilePath = saveFileDialog.FileName.ToString(); PrintPDF pp = new PrintPDF(); pp.XLSConvertToPDF(tempFilePath, localFilePath); MessageBox.Show("保存成功", "消息", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show("保存失败", "消息", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
private void btnPrintPDF_Click(object sender, EventArgs e) { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "PDF文件(*.pdf)|*.pdf"; // Show save file dialog box DialogResult result = saveFileDialog.ShowDialog(); //点了保存按钮进入 if (result == DialogResult.OK) { DataTable tempDetailDT = ApplicationDetailTable.Clone(); foreach (DataRow dr in ApplicationDetailTable.Rows) { if (dr["IsSuccess"].ToString() == "1") { tempDetailDT.Rows.Add(dr.ItemArray); } } //获得文件路径 string localFilePath = saveFileDialog.FileName.ToString(); PrintPDF pp = new PrintPDF(); try { DataTable appDT = applicationInfo.SelectApplicationByTransNo(applicationInfo.TransNo); pp.CreatePDF(appDT, tempDetailDT, localFilePath, "员工内购购买明细"); MessageBox.Show("保存成功", "消息", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch { MessageBox.Show("保存失败", "消息", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
private void btnOutFinish_Click(object sender, EventArgs e) { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "Excel文件(*.xls)|*.xls"; DialogResult result = saveFileDialog.ShowDialog(); if (result == DialogResult.OK) { try { string strBeginDate = dtWuliuBegin.Value.ToShortDateString().ToString(); string strEndDate = dtWuliuEnd.Value.AddDays(1).ToShortDateString().ToString(); string localFilePath = saveFileDialog.FileName.ToString(); //string tempFilePath = System.IO.Directory.GetCurrentDirectory() + @"\tempPDF\" + strRandom + ".xls"; PrintExcel pe = new PrintExcel(); pe.WriteToExcel(applicationInfo.SelectApplication(" and a.WuliuDate>=#" + strBeginDate + "# and a.WuliuDate<#" + strEndDate + "# "), localFilePath, "Sheet1"); PrintPDF pp = new PrintPDF(); //pp.XLSConvertToPDF(tempFilePath, localFilePath); MessageBox.Show("保存成功", "消息", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show("保存失败", "消息", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
private void btnExport_Click(object sender, EventArgs e) { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "Excel文件(*.xls)|*.xls"; DialogResult result = saveFileDialog.ShowDialog(); if (result == DialogResult.OK) { try { string localFilePath = saveFileDialog.FileName.ToString(); //string tempFilePath = System.IO.Directory.GetCurrentDirectory() + @"\tempPDF\" + strRandom + ".xls"; PrintExcel pe = new PrintExcel(); pe.WriteToExcel(applicationInfo.SelectUNApplication(""), localFilePath, "Sheet1"); PrintPDF pp = new PrintPDF(); //pp.XLSConvertToPDF(tempFilePath, localFilePath); MessageBox.Show("保存成功", "消息", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show("保存失败", "消息", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
private void btnPrint_Click(object sender, EventArgs e) { bool isSuccess = false; Business.PrintPDF printPDF = new PrintPDF(); SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "PDF文件(*.pdf)|*.pdf"; // Show save file dialog box DialogResult result = saveFileDialog.ShowDialog(); applicationInfo.applicationDT = applicationInfo.SelectApplicationByTransNo(applicationInfo.TransNo); //点了保存按钮进入 if (result == DialogResult.OK) { if (applicationInfo.AppState < 2) { MessageBox.Show("商品部未批准,无法打印", "消息", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { if (applicationInfo.applicationDT.Rows.Count > 0) { try { //获得文件路径 string localFilePath = saveFileDialog.FileName.ToString(); PrintPDF pp = new PrintPDF(); if (applicationInfo.applicationDT.Rows[0]["MoneyUnit"].ToString() == "1" && Convert.ToInt32(ApplicationDetailTable.Rows[0].ItemArray[6]) == 1) { isSuccess = printPDF.CreatePDF(applicationInfo.applicationDT, ApplicationDetailTable, localFilePath, "Staff Purchase Requisition Form 订购申请表"); } else { isSuccess = printPDF.CreateEnPDF(applicationInfo.applicationDT, ApplicationDetailTable, localFilePath); } if (isSuccess) { MessageBox.Show("保存成功", "消息", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("保存失败", "消息", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch { MessageBox.Show("保存失败", "消息", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } } }
private void btnExpotDetailtoExcel_Click(object sender, EventArgs e) { PrintPDF pe = new PrintPDF(); DataTable dtInfo = pe.exporeDataToTable(dgvApplyInfo); string strSQL = "select top 1 * from ApplicationDetail"; AccessHelper ah = new AccessHelper(); DataTable dtDetail; string strTransNoList = ""; if (dtInfo.Rows.Count > 0) { for (int i = 0; i < dtInfo.Rows.Count; i++) { string strTransNo = dtInfo.Rows[i]["交易号"].ToString(); if (strTransNo != null && strTransNo.Length > 0) { if (i != dtInfo.Rows.Count - 1) { strTransNoList += "'" + strTransNo + "',"; } else { strTransNoList += "'" + strTransNo + "'"; } } } strSQL = "select * from ApplicationDetail where IsDelete = 0 and TransNo in (" + strTransNoList + ") "; dtDetail = ah.SelectToDataTable(strSQL); ah.Close(); SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "EXCEL文件(*.xls)|*.xls"; // Show save file dialog box DialogResult result = saveFileDialog.ShowDialog(); if (result == DialogResult.OK) { try { string localFilePath = saveFileDialog.FileName.ToString(); pe = new PrintPDF(); pe.WriteToExcel_hisDetail(dtDetail, localFilePath, "Sheet1"); MessageBox.Show("保存成功", "消息", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show("保存失败", "消息", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } }