Exemplo n.º 1
0
 private void PreviewReport()
 {
     try
     {
         oRpt = new ReportDocument();
         if (Directory.Exists("..\\..\\..\\" + s_dirreport) == false)
         {
             s_dirreport = "report";
         }
         oRpt.Load("..\\..\\..\\" + s_dirreport + "\\" + ReportFile, OpenReportMethod.OpenReportByTempCopy);
         oRpt.SetDataSource(dt);
         s_fomular = "soyte";
         oRpt.DataDefinition.FormulaFields["soyte"].Text    = "'" + d.Syte.Replace("'", "''") + "'"; s_fomular = "benhvien";
         oRpt.DataDefinition.FormulaFields["benhvien"].Text = "'" + d.Tenbv.Replace("'", "''") + "'"; s_fomular = "c1";
         oRpt.DataDefinition.FormulaFields["c1"].Text       = "'" + c1.Replace("'", "''") + "'"; s_fomular = "c2";
         oRpt.DataDefinition.FormulaFields["c2"].Text       = "'" + c2.Replace("'", "''") + "'"; s_fomular = "c3";
         oRpt.DataDefinition.FormulaFields["c3"].Text       = "'" + c3.Replace("'", "''") + "'"; s_fomular = "c4";
         oRpt.DataDefinition.FormulaFields["c4"].Text       = "'" + c4.Replace("'", "''") + "'"; s_fomular = "c5";
         oRpt.DataDefinition.FormulaFields["c5"].Text       = "'" + c5.Replace("'", "''") + "'"; s_fomular = "c6";
         oRpt.DataDefinition.FormulaFields["c6"].Text       = "'" + c6.Replace("'", "''") + "'"; s_fomular = "c7";
         oRpt.DataDefinition.FormulaFields["c7"].Text       = "'" + c7.Replace("'", "''") + "'"; s_fomular = "c8";
         oRpt.DataDefinition.FormulaFields["c8"].Text       = "'" + c8.Replace("'", "''") + "'"; s_fomular = "c9";
         oRpt.DataDefinition.FormulaFields["c9"].Text       = "'" + c9.Replace("'", "''") + "'"; s_fomular = "c10";
         oRpt.DataDefinition.FormulaFields["c10"].Text      = "'" + c10.Replace("'", "''") + "'"; s_fomular = "";
         if (ReportFile == "d_bhyt.rpt" || ReportFile == "d_treem.rpt")
         {
             s_fomular = "giamdoc";
             oRpt.DataDefinition.FormulaFields["giamdoc"].Text = "'" + c11.Replace("'", "''") + "'";
         }
         else if (ReportFile == "d_phieunhap_nhom.rpt")
         {
             s_fomular = "diachi";
             oRpt.DataDefinition.FormulaFields["diachi"].Text = "'" + c11.Replace("'", "''") + "'";
         }
         else
         {
             s_fomular = "giamdoc";
             oRpt.DataDefinition.FormulaFields["giamdoc"].Text = "'" + d.Giamdoc(i_nhom).Replace("'", "''") + "'";
         }
         s_fomular = "phutrach";
         oRpt.DataDefinition.FormulaFields["phutrach"].Text = "'" + d.Phutrach(i_nhom).Replace("'", "''") + "'";
         if (ReportFile == "d_bhyt.rpt")
         {
             s_fomular = "thongke";
             oRpt.DataDefinition.FormulaFields["thongke"].Text = "'" + c12.Replace("'", "''") + "'";
         }
         else if (ReportFile == "d_phieunhap_nhom.rpt")
         {
             s_fomular = "masothue";
             oRpt.DataDefinition.FormulaFields["masothue"].Text = "'" + c12.Replace("'", "''") + "'";
         }
         else
         {
             s_fomular = "thongke";
             oRpt.DataDefinition.FormulaFields["thongke"].Text = "'" + d.Thongke(i_nhom).Replace("'", "''") + "'";
         }
         s_fomular = "ketoan";
         oRpt.DataDefinition.FormulaFields["ketoan"].Text = "'" + d.Ketoan(i_nhom).Replace("'", "''") + "'"; s_fomular = "thukho";
         oRpt.DataDefinition.FormulaFields["thukho"].Text = "'" + d.Thukho(i_nhom).Replace("'", "''") + "'"; s_fomular = "";
         //
         //binh
         if (ReportFile != "d_ctduoc.rpt")
         {
             s_fomular = "l_soluong";
             oRpt.DataDefinition.FormulaFields["l_soluong"].Text   = i_soluong_le.ToString(); s_fomular = "l_dongia";
             oRpt.DataDefinition.FormulaFields["l_dongia"].Text    = i_dongia_le.ToString(); s_fomular = "l_thanhtien";
             oRpt.DataDefinition.FormulaFields["l_thanhtien"].Text = i_thanhtien_le.ToString(); s_fomular = "";
         }
         //
         Report.ReportSource = oRpt;
     }
     catch (Exception e)
     {
         if (s_fomular != "")
         {
             MessageBox.Show("Thiếu formula " + s_fomular + "\nĐề nghị mở report ra bổ sung thêm formula: " + s_fomular);
         }
         else
         {
             MessageBox.Show("The following error was discovered: '" + e.ToString() + "'. It was occured in '" + e.StackTrace + "'", "Report Viewer", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }