public virtual CrystalDecisions.CrystalReports.Engine.ReportDocument CreateReport() {
     RptBeritaAcaraDelivery rpt = new RptBeritaAcaraDelivery();
     rpt.Site = this.Site;
     return rpt;
 }
        private void btnViewBeritaAcara_Click(object sender, EventArgs e)
        {
            //if no customer selected, alert and return
            if (cboCustomer2.SelectedIndex < 0)
            {
                MessageBox.Show("Please select customer.");
                return;
            }

            //if no transaction selected, alert and return
            if (cboTransDate.SelectedIndex < 0)
            {
                MessageBox.Show("Please select transaction.");
                return;
            }

            //if no trans detail selected, alert and return
            if (cboTransDetail.SelectedIndex < 0)
            {
                MessageBox.Show("Please select transaction detail.");
                return;
            }

            //prepare parameter data
            //DateTime date = new DateTime(2011, 12, 24);
            string customerId = cboCustomer2.SelectedValue.ToString();
            string transDetailId = cboTransDetail.SelectedValue.ToString();

            //build query
            string query = "SELECT ct.id, ct.customer_id, ct.tgl_transaksi, " +
                           "       pd.vessel_name, ctd.voy, ctd.td, des.city_name, ctd.no_container, " +
                           "       ctd.no_seal, c.customer_name, r.recipient_name, tc.type_name, " +
                           "       ctd.jenis_barang, cnd.condition_name, " +
                           "       ctd.sj1, sj2, sj3, sj4, sj5, sj6, sj7, sj8, sj9, sj10, " +
                           "       ctd.sj11, sj12, sj13, sj14, sj15, sj16, sj17, sj18, sj19, sj20, " +
                           "       ctd.sj21, sj22, sj23, sj24, sj25, ctd.no_ba " +
                           "FROM   CUSTOMER_TRANS AS ct " +
                           "       INNER JOIN CUSTOMER AS c ON c.customer_id = ct.customer_id " +
                           "       LEFT OUTER JOIN CUSTOMER_TRANS_DETAIL AS ctd ON ctd.customer_trans_id = ct.id " +
                           "       LEFT OUTER JOIN PELAYARAN_DETAIL AS pd ON pd.pelayaran_detail_id = ctd.pelayaran_detail_id " +
                           "       LEFT OUTER JOIN CITY AS des ON des.city_id = ctd.destination " +
                           "       LEFT OUTER JOIN RECIPIENT AS r ON r.recipient_id = ctd.recipient_id " +
                           "       LEFT OUTER JOIN TYPE_CONT AS tc ON tc.type_id = ctd.type_id " +
                           "       LEFT OUTER JOIN CONDITION AS cnd ON cnd.condition_id = ctd.condition_id " +
                           "WHERE ((ctd.deleted is null OR ctd.deleted = '0') AND (ct.deleted is null OR ct.deleted = '0')) " + 
                           "AND ct.customer_id = '" + customerId + "' " +
                           "AND ctd.id = '" + transDetailId + "' ";

            SqlConnection con = new SqlConnection(VisitaJayaPerkasa.Constant.VisitaJayaPerkasaApplication.connectionString);
            try
            {
                con.Open();
                SqlCommand command = new SqlCommand(query, con);
                SqlDataReader reader = command.ExecuteReader();

                ParameterFields pluralParameter = new ParameterFields();
                ParameterField singleParameter;
                ParameterDiscreteValue parameterDiscreteValue;

                int i = 3;
                while (reader.Read())
                {
                    //populate report params
                    string kapal = (Utility.Utility.IsDBNull(reader.GetValue(i))) ? null : reader.GetValue(i).ToString();
                    i++;
                    string voy = (Utility.Utility.IsDBNull(reader.GetValue(i))) ? null : reader.GetValue(i).ToString();
                    i++;
                    singleParameter = new ParameterField();
                    singleParameter.Name = "strKapal";
                    parameterDiscreteValue = new ParameterDiscreteValue();
                    parameterDiscreteValue.Value = kapal + " / " + voy;
                    singleParameter.CurrentValues.Add(parameterDiscreteValue);
                    pluralParameter.Add(singleParameter);
                    
                    singleParameter = new ParameterField();
                    singleParameter.Name = "dtATD";
                    parameterDiscreteValue = new ParameterDiscreteValue();
                    parameterDiscreteValue.Value = reader.GetDateTime(i).Date;
                    singleParameter.CurrentValues.Add(parameterDiscreteValue);
                    pluralParameter.Add(singleParameter);
                    i++;

                    singleParameter = new ParameterField();
                    singleParameter.Name = "strTujuan";
                    parameterDiscreteValue = new ParameterDiscreteValue();
                    parameterDiscreteValue.Value = (Utility.Utility.IsDBNull(reader.GetValue(i))) ? null : reader.GetValue(i).ToString();
                    singleParameter.CurrentValues.Add(parameterDiscreteValue);
                    pluralParameter.Add(singleParameter);
                    i++;

                    singleParameter = new ParameterField();
                    singleParameter.Name = "strContainer";
                    parameterDiscreteValue = new ParameterDiscreteValue();
                    parameterDiscreteValue.Value = (Utility.Utility.IsDBNull(reader.GetValue(i))) ? null : reader.GetValue(i).ToString();
                    singleParameter.CurrentValues.Add(parameterDiscreteValue);
                    pluralParameter.Add(singleParameter);
                    i++;

                    singleParameter = new ParameterField();
                    singleParameter.Name = "strSegel";
                    parameterDiscreteValue = new ParameterDiscreteValue();
                    parameterDiscreteValue.Value = (Utility.Utility.IsDBNull(reader.GetValue(i))) ? null : reader.GetValue(i).ToString();
                    singleParameter.CurrentValues.Add(parameterDiscreteValue);
                    pluralParameter.Add(singleParameter);
                    i++;

                    singleParameter = new ParameterField();
                    singleParameter.Name = "strPengirim";
                    parameterDiscreteValue = new ParameterDiscreteValue();
                    parameterDiscreteValue.Value = (Utility.Utility.IsDBNull(reader.GetValue(i))) ? null : reader.GetValue(i).ToString();
                    singleParameter.CurrentValues.Add(parameterDiscreteValue);
                    pluralParameter.Add(singleParameter);
                    i++;

                    singleParameter = new ParameterField();
                    singleParameter.Name = "strPenerima";
                    parameterDiscreteValue = new ParameterDiscreteValue();
                    parameterDiscreteValue.Value = (Utility.Utility.IsDBNull(reader.GetValue(i))) ? null : reader.GetValue(i).ToString();
                    singleParameter.CurrentValues.Add(parameterDiscreteValue);
                    pluralParameter.Add(singleParameter);
                    i++;

                    singleParameter = new ParameterField();
                    singleParameter.Name = "strTypeCont";
                    parameterDiscreteValue = new ParameterDiscreteValue();
                    parameterDiscreteValue.Value = (Utility.Utility.IsDBNull(reader.GetValue(i))) ? null : reader.GetValue(i).ToString();
                    singleParameter.CurrentValues.Add(parameterDiscreteValue);
                    pluralParameter.Add(singleParameter);
                    i++;

                    singleParameter = new ParameterField();
                    singleParameter.Name = "strJenisBarang";
                    parameterDiscreteValue = new ParameterDiscreteValue();
                    parameterDiscreteValue.Value = (Utility.Utility.IsDBNull(reader.GetValue(i))) ? null : reader.GetValue(i).ToString();
                    singleParameter.CurrentValues.Add(parameterDiscreteValue);
                    pluralParameter.Add(singleParameter);
                    i++;

                    singleParameter = new ParameterField();
                    singleParameter.Name = "strKondisi";
                    parameterDiscreteValue = new ParameterDiscreteValue();
                    parameterDiscreteValue.Value = (Utility.Utility.IsDBNull(reader.GetValue(i))) ? null : reader.GetValue(i).ToString();
                    singleParameter.CurrentValues.Add(parameterDiscreteValue);
                    pluralParameter.Add(singleParameter);
                    i++;

                    for (int j = 1; j <= 25; j++)
                    {
                        string noDo = "strDO" + j.ToString();
                        singleParameter = new ParameterField();
                        singleParameter.Name = noDo;
                        parameterDiscreteValue = new ParameterDiscreteValue();
                        parameterDiscreteValue.Value = (Utility.Utility.IsDBNull(reader.GetValue(i))) ? "0" : reader.GetValue(i).ToString();
                        singleParameter.CurrentValues.Add(parameterDiscreteValue);
                        pluralParameter.Add(singleParameter);
                        i++;
                    }
                    
                    singleParameter = new ParameterField();
                    singleParameter.Name = "strNoBA";
                    parameterDiscreteValue = new ParameterDiscreteValue();
                    parameterDiscreteValue.Value = (Utility.Utility.IsDBNull(reader.GetValue(i))) ? null : reader.GetValue(i).ToString();
                    singleParameter.CurrentValues.Add(parameterDiscreteValue);
                    pluralParameter.Add(singleParameter);
                    i++;

                    break;
                }
                
                /*foreach (ParameterField field in pluralParameter)
                {
                    MessageBox.Show(field.Name + " = " + (field.CurrentValues[0] as ParameterDiscreteValue).Value.ToString());
                }//*/

                rptBeritaAcara = new RptBeritaAcaraDelivery();
                reportViewer.ParameterFieldInfo = pluralParameter;
                reportViewer.ReportSource = rptBeritaAcara;
            }
            catch (SqlException sqlEx)
            {
                MessageBox.Show(sqlEx.Message);
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.Message);
            }
            finally
            {
                con.Close();
            }
        }