public List<Surat> ListSurat(EnumSurat type)
        {
            List<Surat> listSurat = null;

            try
            {
                using (SqlConnection con = new SqlConnection(VisitaJayaPerkasa.Constant.VisitaJayaPerkasaApplication.connectionString))
                {
                    Constant.VisitaJayaPerkasaApplication.anyConnection = false;
                    con.Open();
                    Constant.VisitaJayaPerkasaApplication.anyConnection = true;

                    String strType = "";
                    if (type == EnumSurat.LeadTime)
                        strType = "LT";
                    else if (type == EnumSurat.PenawaranHarga)
                        strType = "PH";
                    else if (type == EnumSurat.RO)
                        strType = "RO";
                    else
                        strType = "SI";

                    using (SqlCommand command = new SqlCommand(
                        "Select No_Surat, Tgl, [Surat].Customer_id, [Surat].Supplier_id, customer_name From [Surat] left join [Supplier] " + 
                        "on [surat].supplier_id = [supplier].supplier_id Left Join [Customer] " + 
                        "on [Customer].customer_id = [Surat].customer_id Where No_Surat like '%" + strType + "%'", con))
                    {
                        SqlDataReader reader = command.ExecuteReader();
                        while (reader.Read())
                        {
                            Surat surat = new Surat();
                            surat.NoSurat = reader.GetString(0);
                            surat.Tgl = reader.GetDateTime(1);

                            if (!Utility.Utility.IsDBNull(reader.GetValue(2)))
                                surat.CustomerID = Utility.Utility.ConvertToUUID(reader.GetValue(2).ToString());
                            if (!Utility.Utility.IsDBNull(reader.GetValue(3)))
                                surat.SupplierID = Utility.Utility.ConvertToUUID(reader.GetValue(3).ToString());
                            if (!Utility.Utility.IsDBNull(reader.GetValue(4)))
                                surat.CustomerName = reader.GetString(4);

                            if (listSurat == null)
                                listSurat = new List<Surat>();

                            listSurat.Add(surat);
                            surat = null;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Logging.Error("SqlSuratRepository.cs - ListSurat() " + e.Message);
            }

            return listSurat;
        }
        public newLeadTime(Surat objSurat, rptLeadTimeControl objParent)
        {
            InitializeComponent();
            this.objParent = objParent;


            sqlCustomerRepository = new SqlCustomerRepository();
            List<Customer> listCustomer = sqlCustomerRepository.listCustomerForPriceList();
            cboCustomer.DataSource = listCustomer;
            cboCustomer.DisplayMember = "CustomerName";
            cboCustomer.ValueMember = "ID";



            if (objSurat == null)
            {
                surat = new Surat();
                sqlSuratRepository = new SqlSuratRepository();
                isCreateNew = true;

                Surat tempSurat = sqlSuratRepository.GetlastNoSurat(EnumSurat.LeadTime);
                String strTempNoSurat = (tempSurat == null) ? "0" : tempSurat.NoSurat.Substring(0, 4);
                etNoSurat.Text = surat.GenerateNoSurat(Int32.Parse(strTempNoSurat), EnumSurat.LeadTime);



                listCustomer = null;
                tempSurat = null;
                strTempNoSurat = null;
                sqlSuratRepository = null;
            }
            else 
            {
                isCreateNew = false;
                surat = objSurat;
                etNoSurat.Text = objSurat.NoSurat;
                radDateTimePicker1.Value = objSurat.Tgl;
                cboCustomer.SelectedValue = objSurat.CustomerID;
            }

            
            sqlCustomerRepository = null;
        }
        public Surat GetlastNoSurat(EnumSurat type)
        {
            Surat surat = null;

            try
            {
                using (SqlConnection con = new SqlConnection(VisitaJayaPerkasa.Constant.VisitaJayaPerkasaApplication.connectionString))
                {
                    Constant.VisitaJayaPerkasaApplication.anyConnection = false;
                    con.Open();
                    Constant.VisitaJayaPerkasaApplication.anyConnection = true;
                    String strType = "";

                    switch (type)
                    { 
                        case EnumSurat.LeadTime:
                            strType = "LT";
                            break;
                        case EnumSurat.PenawaranHarga:
                            strType = "PH";
                            break;
                        case EnumSurat.RO:
                            strType = "RO";
                            break;
                        case EnumSurat.ShippingInstruction:
                            strType = "SI";
                            break;
                    }

                    using (SqlCommand command = new SqlCommand(
                        "Select Top 1 No_Surat, Tgl, Customer_id, Supplier_id From [Surat] Where No_Surat Like '%" + strType + "%' Order by No_Surat desc", con))
                    {
                        SqlDataReader reader = command.ExecuteReader();
                        if (reader.Read())
                        {
                            surat = new Surat();
                            surat.NoSurat = reader.GetString(0);
                            surat.Tgl = reader.GetDateTime(1);

                            if (!Utility.Utility.IsDBNull(reader.GetValue(2)))
                                surat.CustomerID = Utility.Utility.ConvertToUUID(reader.GetValue(2).ToString());
                            if (!Utility.Utility.IsDBNull(reader.GetValue(3)))
                                surat.SupplierID = Utility.Utility.ConvertToUUID(reader.GetValue(3).ToString());
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Logging.Error("SqlSuratRepository.cs - GetlastNoSurat() " + e.Message);
            }

            return surat;
        }
        public PrintLeadTime(Surat objSurat)
        {
            InitializeComponent();
            this.objSurat = objSurat;
            sqlCustomerTransRepository = new SqlCustomerTransRepository();
            reportDocument = new ReportDocument();
            paramFields = new ParameterFields();
            crtLeadTime = new CrtLeadTime();


            //Execute Query
            String strQry = "Select [CUSTOMER_TRANS_DETAIL].no_container as Column1, " + 
                "(Select Top 1 address From WareHouse Where stuffing_place_id = stuffing_place) as Column2, " + 
                "[CUSTOMER_TRANS_DETAIL].terima_toko as Column3 From [CUSTOMER_TRANS_DETAIL] " + 
                "Join [Customer_Trans] On " + 
                "[Customer_Trans].tgl_transaksi = cast('" + Utility.Utility.ConvertDateToString(objSurat.Tgl) + "' as date) And " + 
                "[Customer_Trans].Customer_id = '" + objSurat.CustomerID + "' And " + 
                "([Customer_Trans].deleted is not null Or [Customer_Trans].deleted = 0) " +
                "And [Customer_Trans].id = [Customer_Trans_Detail].customer_trans_id";

            int columnNo = 1;
            paramField = new ParameterField();
            paramField.Name = "col" + columnNo.ToString();
            paramDiscreteValue = new ParameterDiscreteValue();
            paramDiscreteValue.Value = "Container";
            paramField.CurrentValues.Add(paramDiscreteValue);
            paramFields.Add(paramField);
            columnNo++;

            paramField = new ParameterField();
            paramField.Name = "col" + columnNo.ToString();
            paramDiscreteValue = new ParameterDiscreteValue();
            paramDiscreteValue.Value = "Tgl penerimaan Container";
            paramField.CurrentValues.Add(paramDiscreteValue);
            paramFields.Add(paramField);
            columnNo++;

            paramField = new ParameterField();
            paramField.Name = "col" + columnNo.ToString();
            paramDiscreteValue = new ParameterDiscreteValue();
            paramDiscreteValue.Value = "Gudang";
            paramField.CurrentValues.Add(paramDiscreteValue);
            paramFields.Add(paramField);

            paramField = new ParameterField();
            paramField.Name = "noSurat";
            paramDiscreteValue = new ParameterDiscreteValue();
            paramDiscreteValue.Value = objSurat.NoSurat;
            paramField.CurrentValues.Add(paramDiscreteValue);
            paramFields.Add(paramField);

            paramField = new ParameterField();
            paramField.Name = "parameterReceive";
            paramDiscreteValue = new ParameterDiscreteValue();
            paramDiscreteValue.Value = objSurat.CustomerName;
            paramField.CurrentValues.Add(paramDiscreteValue);
            paramFields.Add(paramField);
            crystalReportViewer1.ParameterFieldInfo = paramFields;


            SqlConnection con = new SqlConnection(VisitaJayaPerkasa.Constant.VisitaJayaPerkasaApplication.connectionString);
            SqlDataAdapter da = new SqlDataAdapter(strQry, VisitaJayaPerkasa.Constant.VisitaJayaPerkasaApplication.connectionString);
            ShippingMainDataSet ds = new ShippingMainDataSet();
            da.Fill(ds, "Surat_Lead_Time");

            crtLeadTime.SetDataSource(ds);
            crystalReportViewer1.ReportSource = crtLeadTime;
        }