private void btnSearch_Click(object sender, EventArgs e)
        {
            new SearchCustomerTrans().ShowDialog();
            if (Constant.VisitaJayaPerkasaApplication.objGetOtherView != null)
            {
                searchResultCustomerTrans = (VisitaJayaPerkasa.Entities.CustomerTrans)Constant.VisitaJayaPerkasaApplication.objGetOtherView;
                txtCustomer.Text = searchResultCustomerTrans.CustomerName;
                this.customerName = searchResultCustomerTrans.CustomerName;
            }

            Constant.VisitaJayaPerkasaApplication.objGetOtherView = null;
        }
        public CustomerTransEdit(VisitaJayaPerkasa.Entities.CustomerTrans customerTrans)
        {
            InitializeComponent();
            this.customerTrans = customerTrans;
            
            sqlCustomerRepository = new SqlCustomerRepository();
            sqlTypeContRepository = new SqlTypeContRepository();
            sqlCityRepository = new SqlCityRepository();
            sqlPelayaranRepository = new SqlPelayaranRepository();
            sqlConditionRepository = new SqlConditionRepository();
            sqlPriceListRepository = new SqlPriceListRepository();
            sqlWarehouseRepository = new SqlWareHouseRepository();
            sqlRecipientRepository = new SqlRecipientRepository();
            sqlScheduleRepository = new SqlScheduleRepository();
            sqlTruckingRepository = new SqlTruckingRepository();
            sqlJenisBarangRepository = new SqlJenisBarangRepository();

            List<VisitaJayaPerkasa.Entities.Customer> listCustomer = sqlCustomerRepository.ListCustomers();
            List<VisitaJayaPerkasa.Entities.TypeCont> listType = sqlTypeContRepository.GetTypeCont();
            List<VisitaJayaPerkasa.Entities.City> listOrigin = sqlCityRepository.GetCity();
            if (!Constant.VisitaJayaPerkasaApplication.anyConnection)
            {
                MessageBox.Show(this, "Please check your connection", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            List<VisitaJayaPerkasa.Entities.City> listDestination = sqlCityRepository.GetCity();
            List<VisitaJayaPerkasa.Entities.PelayaranDetail> listPelayaran = sqlPelayaranRepository.GetVessels();
            List<VisitaJayaPerkasa.Entities.Schedule> listSchedule = sqlScheduleRepository.ListSchedule();
            List<VisitaJayaPerkasa.Entities.Condition> listCondition = sqlConditionRepository.GetConditions();
            if (!Constant.VisitaJayaPerkasaApplication.anyConnection)
            {
                MessageBox.Show(this, "Please check your connection", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            List<VisitaJayaPerkasa.Entities.WareHouse> listWarehouse;
            List<VisitaJayaPerkasa.Entities.Recipient> listRecipient;
            if (customerTrans != null)
            {
                listWarehouse = (this.customerTrans == null) ? sqlWarehouseRepository.GetWareHouse() : sqlWarehouseRepository.GetWareHouseByCustomer(customerTrans.CustomerID);
                listRecipient = (this.customerTrans == null) ? sqlRecipientRepository.GetRecipient() : sqlRecipientRepository.GetRecipientByCustomer(customerTrans.CustomerID);
            }
            else
            {
                listWarehouse = new List<Entities.WareHouse>();
                listRecipient = new List<Entities.Recipient>();
            }
            List<VisitaJayaPerkasa.Entities.Trucking> listTrucking = new List<Entities.Trucking>();
            List<VisitaJayaPerkasa.Entities.JenisBarang> listJenisBarang = sqlJenisBarangRepository.ListJenisBarang();
            if (!Constant.VisitaJayaPerkasaApplication.anyConnection)
            {
                MessageBox.Show(this, "Please check your connection", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            cboCustomer.DataSource = listCustomer;
            cboCustomer.DisplayMember = "CustomerName";
            cboCustomer.ValueMember = "ID";
            cboCustomer.SelectedIndex = -1;
            cboCustomer.Text = "-- Choose --";
            cboCustomer.Tag = "cboCustomer";
            
            cboType.DataSource = listType;
            cboType.DisplayMember = "TypeName";
            cboType.ValueMember = "ID";
            cboType.SelectedIndex = -1;
            cboType.Text = "-- Choose --";

            cboOrigin.DataSource = listOrigin;
            cboOrigin.DisplayMember = "CityName";
            cboOrigin.ValueMember = "ID";
            cboOrigin.SelectedIndex = -1;
            cboOrigin.Text = "-- Choose --";

            cboDestination.DataSource = listDestination;
            cboDestination.DisplayMember = "CityName";
            cboDestination.ValueMember = "ID";
            cboDestination.SelectedIndex = -1;
            cboDestination.Text = "-- Choose --";

            days = from p in listDestination 
                   select p.Days;

            cboPelayaranDetail.DataSource = listSchedule;
            cboPelayaranDetail.DisplayMember = "namaKapal";
            //cboPelayaranDetail.ValueMember = "ID";
            cboPelayaranDetail.SelectedIndex = -1;
            cboPelayaranDetail.Text = "-- Choose --";

            cboCondition.DataSource = listCondition;
            cboCondition.DisplayMember = "ConditionName";
            cboCondition.ValueMember = "ID";
            cboCondition.SelectedIndex = -1;
            cboCondition.Text = "-- Choose --";

            cboStuffingPlace.DataSource = listWarehouse;
            cboStuffingPlace.DisplayMember = "Address";
            cboStuffingPlace.ValueMember = "Id";
            cboStuffingPlace.SelectedIndex = -1;
            cboStuffingPlace.Text = "-- Choose --";

            cboRecipient.DataSource = listRecipient;
            cboRecipient.DisplayMember = "Name";
            cboRecipient.ValueMember = "ID";
            cboRecipient.SelectedIndex = -1;
            cboRecipient.Text = "-- Choose --";

            cboTrucking.DataSource = listTrucking;
            cboTrucking.DisplayMember = "TruckNo";
            cboTrucking.ValueMember = "ID";
            cboTrucking.SelectedIndex = -1;
            cboTrucking.Text = "-- Choose --";

            cboJenisBarang.DataSource = listJenisBarang;
            cboJenisBarang.DisplayMember = "Nama";
            cboJenisBarang.ValueMember = "Nama";
            cboJenisBarang.SelectedIndex = -1;
            cboJenisBarang.Text = "-- Type or Choose --";

            if (customerTrans == null)
            {
                wantToCreateVessel = true;
                listCustomerTransDetail = new List<Entities.CustomerTransDetail>();
            }
            else
            {
                wantToCreateVessel = false;
                cboCustomer.SelectedValue = customerTrans.CustomerID;
                cboCustomer.Enabled = false;

                SqlCustomerTransRepository sqlCustomerTransRepository = new SqlCustomerTransRepository();
                listCustomerTransDetail = sqlCustomerTransRepository.ListCustomerTransDetail(customerTrans.CustomerTransID);
                ID = customerTrans.CustomerTransID;

                if (!Constant.VisitaJayaPerkasaApplication.anyConnection)
                    MessageBox.Show(this, "Please check your connection", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                else if (listCustomerTransDetail != null)
                    CustomerTransDetailGridView.DataSource = listCustomerTransDetail;
                else
                    listCustomerTransDetail = new List<VisitaJayaPerkasa.Entities.CustomerTransDetail>();

                sqlCustomerTransRepository = null;
            }



            cboCustomer.SelectedIndexChanged += new EventHandler(cboSelected_SelectedIndexChanged);
            cboType.SelectedIndexChanged += new EventHandler(cboSelected_SelectedIndexChanged);
            cboDestination.SelectedIndexChanged += new EventHandler(cboSelected_SelectedIndexChanged);
            cboCondition.SelectedIndexChanged += new EventHandler(cboSelected_SelectedIndexChanged);


            sqlCustomerRepository = null;
            sqlTypeContRepository = null;
            sqlCityRepository = null;
            sqlPelayaranRepository = null;
            sqlConditionRepository = null;

            if (wantToCreateVessel)
            {
                dtpTD.Visible = false;
                dtpETA.Visible = false;
                dtpTA.Visible = false;
                dtpUnloading.Visible = false;
            }
        }