private void saveCatsProdsToPdf_Click(object sender, EventArgs e) { // todo : fix the save file problem (fixed and now works properly) Emad .. Feb 2, 2018 try { lblState.Text = "جاري الحفظ ..."; this.Cursor = Cursors.WaitCursor; Reports.rpt_singleCategoryProducts rpt_singleCatProducts = new Reports.rpt_singleCategoryProducts(); // refresh the report (clear any binded params, if the report was used before and already has a binded param) rpt_singleCatProducts.Refresh(); // bind the category_ID param to the report rpt_singleCatProducts.SetParameterValue("@cat_id", Convert.ToInt32(dataGridView1.CurrentRow.Cells[0].Value.ToString())); //create export report options ExportOptions exprtOpts = new ExportOptions(); DiskFileDestinationOptions dfOptions = new DiskFileDestinationOptions(); PdfFormatOptions pdfFrmtOps = new PdfFormatOptions(); SaveFileDialog sfd = new SaveFileDialog(); sfd.Title = "حفظ قائمة المنتجات"; sfd.Filter = "PDF files (*.pdf)|*.pdf|All files (*.*)|*.*"; sfd.CheckPathExists = true; sfd.ShowDialog(); //MessageBox.Show(sfd.FileName); // bind the result "address of file as a string" to the dfOptions object of (DiskFileDestinationOptions dfOptions = new DiskFileDestinationOptions();) dfOptions.DiskFileName = sfd.FileName; exprtOpts = rpt_singleCatProducts.ExportOptions; exprtOpts.ExportDestinationType = ExportDestinationType.DiskFile; exprtOpts.ExportFormatType = ExportFormatType.PortableDocFormat; exprtOpts.ExportFormatOptions = pdfFrmtOps; exprtOpts.ExportDestinationOptions = dfOptions; rpt_singleCatProducts.Export(); lblState.Text = "تم الحفظ بنجاح"; this.Cursor = Cursors.Default; } catch (UnauthorizedAccessException) { MessageBox.Show("ليس لديك صلاحية لحفظ الملف في هذا المسار. من فضلك اختر مسار مختلف", "خطا بالصلاحية", MessageBoxButtons.OK, MessageBoxIcon.Error); lblState.Text = ".."; } }
private void prtSlctCat_Click(object sender, EventArgs e) { // instanciate on object of the crystal report (report for printing all products stored in db "stored proc called get all products") Reports.rpt_singleCategoryProducts rptSingleCatProducts = new Reports.rpt_singleCategoryProducts(); // obj from the form of reports Views.frm_reports reportsFrm = new Views.frm_reports(); // refresh the sub report new Reports.rpt_all_products().Refresh(); // refresh the report in case if a change has made in the database rptSingleCatProducts.Refresh(); rptSingleCatProducts.SetParameterValue("@cat_id", Convert.ToInt32(dataGridView1.CurrentRow.Cells[0].Value.ToString())); //bind the crystal report to the crystal report viewer on the reports form reportsFrm.crystalReportViewer1.ReportSource = rptSingleCatProducts; reportsFrm.ShowDialog(); }