private void btProcess_Click(object sender, EventArgs e) { try { if (rbMBPHT08.Checked) { string sql = "", err = ""; DataTable dtReport = new DataTable(); string from_dt = dpFromDate.Text; string to_dt = dpToDate.Text; #region SQL_PHT08 sql += " select h.branch_code,h.branch_name,nvl(sum(h.SoLuongThe),0) SoLuongThe "; sql += " from ( "; sql += " Select trim(cp.branch_receive_card ) branch_code "; sql += " ,(select b.code ||'- '|| b.name from " + Businessbp.executedb.owner + "branch b "; sql += " where trim(b.code)=trim(cp.branch_receive_card) and b.amnd_state='A' "; sql += " ) branch_name "; sql += " ,count(c.contract_number) as SoLuongThe "; sql += " from " + Businessbp.executedb.owner + "acnt_contract c"; sql += " ,nab_cp_card_prepaid cp,"; sql += " nab_product sp "; sql += " where c.add_info_01 = cp.source_application_no "; sql += " and c.amnd_state = 'A'"; sql += " and c.con_cat = 'C' "; sql += " and c.contr_status = '267'"; sql += " and trunc(c.date_open) >= trunc(to_date('" + from_dt + "','dd/mm/yyyy')) "; sql += " and trunc(c.date_open) <= trunc(to_date('" + to_dt + "','dd/mm/yyyy')) "; sql += " and sp.product_code <> '333' "; sql += " and c.product = sp.product_code "; sql += " and sp.type in ('D','P') "; if (cb_branch.SelectedValue.ToString().Trim() != "888") sql += " and trim(cp.branch_receive_card) ='" + cb_branch.SelectedValue.ToString().Trim() + "' "; sql += " group by cp.branch_receive_card "; sql += " union all "; sql += " Select trim(cd.branch_receive_card) branch_code, "; sql += " (select b.code ||'- '|| b.name from " + Businessbp.executedb.owner + "branch b "; sql += " where trim(b.code)=trim(cd.branch_receive_card) and b.amnd_state='A') branch_name "; sql += " ,count(c.contracT_number) as SoLuongThe "; sql += " from " + Businessbp.executedb.owner + "acnt_contract c,nab_cp_card cd, nab_product sp2"; sql += " where c.add_info_01 = cd.source_application_no "; sql += " and c.amnd_state = 'A'"; sql += " and c.con_cat = 'C' "; sql += " and c.contr_status = '267'"; sql += " and trunc(c.date_open) >= trunc(to_date('" + from_dt + "','dd/mm/yyyy')) "; sql += " and trunc(c.date_open) <= trunc(to_date('" + to_dt + "','dd/mm/yyyy')) "; sql += " and sp2.product_code <> '333' "; sql += " and c.product = sp2.product_code "; sql += " and sp2.type in ('C') "; if (cb_branch.SelectedValue.ToString().Trim() != "888") sql += " and trim(cd.branch_receive_card) ='" + cb_branch.SelectedValue.ToString().Trim() + "' "; sql += " group by cd.branch_receive_card "; sql += " )h "; sql += " group by h.branch_code,h.branch_name "; #endregion SQL_PHT08 this.Cursor = Cursors.WaitCursor; string type = "MB_PHT08"; if (sql != "") { dtReport = Businessbp.executedb.getTable(sql, ref err); if (err != "") { MessageBox.Show(err); this.Cursor = Cursors.Default; return; } else { string folderOut = tbFilePath.Text.Trim() + "" + type + "\\"; ; //Tao thu muc if (!Directory.Exists(folderOut)) { Directory.CreateDirectory(folderOut); } //Export pdf #region Export try { if (dtReport.Rows.Count > 0) { for (int i = 0; i < dtReport.Rows.Count; i++) { string branch = dtReport.Rows[i]["branch_code"].ToString().Trim(); string Branch_name = dtReport.Rows[i]["branch_name"].ToString().Trim(); string file_path = folderOut.Trim() + branch.Trim() + "_" + type + "_" + dpFromDate.Text.Trim().Replace("/", "") + "_" + dpToDate.Text.Trim().Replace("/", "") + ".doc"; ConvertNumToStr objConvert = new ConvertNumToStr(); string SoLuongThe_Chu = ""; string SoLuongThe_Nbr = dtReport.Rows[i]["SoLuongThe"].ToString().Trim(); SoLuongThe_Chu = objConvert.converNumToString(objConvert.slipArray(SoLuongThe_Nbr)); string Date_Send = " ngày " + DateTime.Now.Day + " tháng " + DateTime.Now.Month + " năm " + DateTime.Now.Year; string From_To_Date = dpFromDate.Text + " - " + dpToDate.Text; Rpt_MH_PHT08_GiaoNhanThePin cry = new Rpt_MH_PHT08_GiaoNhanThePin(); // cry.SetDataSource(dtReport); // string title = ""; cry.SetParameterValue("Branch", Branch_name); cry.SetParameterValue("Date_Send", Date_Send); cry.SetParameterValue("SoLuongThe_Nbr", SoLuongThe_Nbr); cry.SetParameterValue("SoLuongThe_Chu", SoLuongThe_Chu + " Thẻ"); cry.SetParameterValue("SoLuongPin_Nbr", SoLuongThe_Nbr); cry.SetParameterValue("SoLuongPin_Chu", SoLuongThe_Chu + " PIN"); cry.SetParameterValue("From_To_Date", From_To_Date); ExportOptions CrExportOptions; DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions(); PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions(); CrDiskFileDestinationOptions.DiskFileName = file_path;// tbFilePath.Text.Trim() + "\\" + card_number.Trim() + ".pdf";//"c:\\csharp.net-informations.pdf"; CrExportOptions = cry.ExportOptions; { CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile; //CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat; CrExportOptions.ExportFormatType = ExportFormatType.WordForWindows; CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions; CrExportOptions.FormatOptions = CrFormatTypeOptions; } cry.Export(); //--Fix for Load Report failse if (cry != null) { cry.Close(); cry.Dispose(); } } } else { // MessageBox.Show("");//+ card_number.Trim()); } } catch (Exception ex) { MessageBox.Show(ex.Message); this.Cursor = Cursors.Default; } #endregion Export } }//End for branch this.Cursor = Cursors.Default; tbStatus.Text += "-- Success:" + dtReport.Rows.Count; } else //MB-PHT06 { this.Cursor = Cursors.WaitCursor; string branch_code = cb_branch.SelectedValue.ToString().Trim(); try { process_MB_PHT06(cb_branch.SelectedValue.ToString().Trim()); tbStatus.Text = "DONE!!!"; } catch (Exception ex) { MessageBox.Show("Err btn_Process_Click: " + ex.ToString()); } this.Cursor = Cursors.Default; } } catch { } }
public virtual CrystalDecisions.CrystalReports.Engine.ReportDocument CreateReport() { Rpt_MH_PHT08_GiaoNhanThePin rpt = new Rpt_MH_PHT08_GiaoNhanThePin(); rpt.Site = this.Site; return rpt; }