コード例 #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            CrystalReport2 crpt = new CrystalReport2();


            try
            {
                //foreach (CrystalDecisions.CrystalReports.Engine.Table table in crpt.Database.Tables)
                //{
                //    TableLogOnInfo ci = new TableLogOnInfo();
                //    /**
                //     * @notes Ini itterate di masing-masing tabel pada RPT yang dibuat, sehingga koneksi berubah jadi ini
                //     * Database itu dikosongi agar databasenya tetap seperti sebelumnya
                //     * @see https://stackoverflow.com/q/17914605
                //     * @see https://stackoverflow.com/questions/4864169/crystal-report-and-problem-with-connection
                //     */
                //    ci.ConnectionInfo.DatabaseName = "";
                //    ci.ConnectionInfo.ServerName = "10.11.238.40"; //ganti ipnya
                //    ci.ConnectionInfo.UserID = "proyek";
                //    ci.ConnectionInfo.Password = "******";
                //    table.ApplyLogOnInfo(ci);
                //}
            }
            catch (Exception)
            {
                throw;
            }
            crpt.SetDatabaseLogon("proyek", "proyek");
            crystalReportViewer1.ReportSource = crpt;


            crpt.SetParameterValue("Tanggal_Awal", dateTimePicker1.Value);
            crpt.SetParameterValue("Tanggal Akhir", dateTimePicker2.Value);
            crpt.SetParameterValue("idcabang", Form1.Cabang);
        }
コード例 #2
0
ファイル: Report.cs プロジェクト: gracielo2804/ACS2019
 public void LoadData(string jenis)
 {
     conn.Open();
     try
     {
         cry = new CrystalReport2();
         cry.SetParameterValue("ID", "SP");
         cry.SetDatabaseLogon(ID, password);
         TextObject txt;
         TextObject Cabang;
         Cabang = cry.ReportDefinition.ReportObjects["Cabang"] as TextObject;
         txt    = cry.ReportDefinition.ReportObjects["BulanTxt"] as TextObject;
         foreach (CrystalDecisions.CrystalReports.Engine.Table table in cry.Database.Tables)
         {
             TableLogOnInfo ci = new TableLogOnInfo();
             ci.ConnectionInfo.DatabaseName = "";
             ci.ConnectionInfo.ServerName   = IP;
             ci.ConnectionInfo.UserID       = ID;
             ci.ConnectionInfo.Password     = password;
             table.ApplyLogOnInfo(ci);
         }
         if (jenis == "Custom")
         {
             cry.SetParameterValue("Tgl_Awal", TglAwal.Value.ToString("dd/MM/yyyy"));
             cry.SetParameterValue("Tgl_Akhir", TglAkhir.Value.ToString("dd/MM/yyyy"));
             cry.SetParameterValue("Jenis", "Custom");
             txt.Text = TglAwal.Value.ToString("dd/MM/yyyy") + " - " + TglAkhir.Value.ToString("dd/MM/yyyy");
         }
         else if (jenis == "Monthly")
         {
             string a = "1/" + BulanCmb.SelectedItem.ToString() + "/" + TahunCmbBulanan.SelectedItem.ToString().Substring(2, 2);
             cry.SetParameterValue("Tgl_awal", Convert.ToDateTime(a).ToString("dd/MM/yyyy"));
             cmd = new OracleCommand($"Select last_day('{a}') from dual", conn);
             ad  = new OracleDataAdapter(cmd);
             DataSet ds = new DataSet();
             ad.Fill(ds);
             cry.SetParameterValue("Tgl_Akhir", Convert.ToDateTime(ds.Tables[0].Rows[0][0].ToString()));
             cry.SetParameterValue("Jenis", "Bulan");
             txt.Text = BulanCmb.SelectedItem.ToString() + " - " + TahunCmbBulanan.SelectedItem.ToString();
         }
         else if (jenis == "Yearly")
         {
             cry.SetParameterValue("Tgl_Awal", Convert.ToDateTime("01/January/" + TahunCmbTahunan.SelectedItem.ToString()));
             cry.SetParameterValue("Tgl_Akhir", Convert.ToDateTime("31/December/" + TahunCmbTahunan.SelectedItem.ToString()));
             cry.SetParameterValue("Jenis", "Tahun");
             txt.Text = TahunCmbTahunan.SelectedItem.ToString();
         }
         else if (jenis == "Daily")
         {
             cry.SetParameterValue("Tgl_Awal", Date.Value.ToString("dd/MM/yyyy"));
             cry.SetParameterValue("Tgl_Akhir", Date.Value.ToString("dd/MM/yyyy"));
             cry.SetParameterValue("ID", "SP");
             cry.SetParameterValue("Jenis", "Daily");
             txt.Text = Date.Value.ToString("dd/MM/yyyy");
         }
         cry.SetParameterValue("IDCabang", CabangCmb.SelectedValue);
         Cabang.Text       = "Nama Cabang : " + namaCabang();
         Main.ReportSource = cry;
         Main.Visible      = true;
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
     conn.Close();
 }