public rptSIControl()
        {
            InitializeComponent();
            sqlScheduleRepository = new SqlScheduleRepository();
            sqlCityRepository = new SqlCityRepository();
            List<VisitaJayaPerkasa.Entities.Supplier> listSupplier;
            SqlSupplierRepository sqlSupplierRepository = new SqlSupplierRepository();
            listSupplier = sqlSupplierRepository.ListSuppliers();
            if (!Constant.VisitaJayaPerkasaApplication.anyConnection)
                MessageBox.Show(this, "Please check your connection", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            cboSupplier.DataSource = listSupplier;
            cboSupplier.DisplayMember = "SupplierName";
            cboSupplier.SelectedIndex = -1;
            cboSupplier.ValueMember = "Id";
            cboSupplier.Text = "-- Choose --";

            List<VisitaJayaPerkasa.Entities.Schedule> listSchedule = sqlScheduleRepository.ListSchedule();
            cboKapal.DataSource = listSchedule;
            cboKapal.DisplayMember = "namaKapal";
            cboKapal.SelectedIndex = -1;
            cboKapal.Text = "-- Choose --";

            List<VisitaJayaPerkasa.Entities.City> listDestination = sqlCityRepository.GetCity();
            cboCity.DataSource = listDestination;
            cboCity.DisplayMember = "CityName";
            cboCity.ValueMember = "ID";
            cboCity.SelectedIndex = -1;
            cboCity.Text = "-- Choose --";
        }
        private void radButtonElement1_Click(object sender, EventArgs e)
        {
            if(cboTujuan.Text.Equals(Constant.VisitaJayaPerkasaApplication.cboDefaultText))
                MessageBox.Show(this, "Please select tujuan", "Information");
            else if (cboKapal.Text.Equals(Constant.VisitaJayaPerkasaApplication.cboDefaultText))
                MessageBox.Show(this, "Please select kapal", "Information");
            else if(etVOY.Text.Trim().Length == 0)
                MessageBox.Show(this, "Please fill voy", "Information");
            else if(pickerETD.Value.Date <= DateTime.Today.Date && wantToCreateVessel)
                MessageBox.Show(this, "Please correct etd", "Information");
            else if(pickerTglClosing.Value.Date > pickerETD.Value.Date)
                MessageBox.Show(this, "date of tgl closing must be lower than etd", "Information");
            else
            {
                try
                {
                    if (etRObegin20.Text.Trim().Length == 0 && etRObegin40.Text.Trim().Length == 0) {
                        MessageBox.Show(this, "Please fill ro begin", "Information");
                        return;
                    }

                    if (etRObegin20.Text.Trim().Length > 0)
                        Int32.Parse(etRObegin20.Text.Trim());
                    if (etRObegin40.Text.Trim().Length > 0)
                        Int32.Parse(etRObegin40.Text.Trim());
                }
                catch (Exception ex) {
                    Utility.Log.Logging.Information("try parse int for validate " + ex.Message);
                    MessageBox.Show(this, "Please correct Ro value", "Information");
                    return;
                }

                sqlScheduleRepository = new SqlScheduleRepository();

                if (wantToCreateVessel) {
                    SqlParameter[] sqlParam = SqlUtility.SetSqlParameter(
                            new string[]{"schedule_id", "tujuan", "pelayaran_detail_id", "tgl_closing", 
                                "voy", "deleted", "keterangan", "vessel_code", "ro_begin_20",
                                "ro_begin_40", "ro_end_20", "ro_end_40", "etd", "td", "eta", "ta", 
                                "unloading"
                            },
                            new object[]{Guid.NewGuid(), 
                                Utility.Utility.ConvertToUUID(cboTujuan.SelectedValue.ToString()),
                                Utility.Utility.ConvertToUUID(cboKapal.SelectedValue.ToString().Substring(0, 36)),
                                pickerTglClosing.Value.Date,
                                etVOY.Text.Trim(),
                                0,
                                etKet.Text.Trim(),
                                cboKapal.SelectedValue.ToString().Substring(36),
                                Utility.Utility.IsStringNullorEmpty(etRObegin20.Text.Trim()) ? 0 : Int32.Parse(etRObegin20.Text.Trim()) ,
                                Utility.Utility.IsStringNullorEmpty(etRObegin40.Text.Trim()) ? 0 : Int32.Parse(etRObegin40.Text.Trim()),
                                0,
                                0,
                                pickerETD.Value.Date,
                                DBNull.Value,
                                DBNull.Value,
                                DBNull.Value,
                                DBNull.Value
                            });

                    if (sqlScheduleRepository.CreateNewSchedule(sqlParam))
                    {
                        MessageBox.Show(this, "Success Create schedule", "Information");
                        radButtonElement2.PerformClick();
                    }
                    else if (!Constant.VisitaJayaPerkasaApplication.anyConnection)
                        MessageBox.Show(this, "Please check your connection", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    else {
                        MessageBox.Show(this, "Cannot Create schedule", "Information");
                    }
                }
                else {
                    if (wantToEditTdETC)
                    {
                        if (pickerETA.Value.Date < pickerTD.Value.Date)
                        {
                            MessageBox.Show(this, "Eta must be greather than TD ", "Information");
                            return;
                        }
                        else if (pickerTD.Value.Date < pickerETD.Value.Date)
                        {
                            MessageBox.Show(this, "TD must be greather than ETD", "Information");
                            return;
                        }
                        else if (pickerTA.Value.Date < pickerETA.Value.Date)
                        {
                            MessageBox.Show(this, "TA must be greather than ETA", "Information");
                            return;
                        }
                        else if (schedule.ro_end_20 > Int32.Parse(etRObegin20.Text.Trim()))
                        {
                            MessageBox.Show(this, "Please correct ro begin 20. \n Ro end 20 greater than ro begin 20", "Information");
                            return;
                        }
                        else if (schedule.ro_end_40 > Int32.Parse(etRObegin40.Text.Trim()))
                        {
                            MessageBox.Show(this, "Please correct ro begin 40. \n Ro end 40 greater than ro begin 40", "Information");
                            return;
                        }
                    }
                    else { 
                        if (schedule.ro_end_20 > Int32.Parse(etRObegin20.Text.Trim()))
                        {
                            MessageBox.Show(this, "Please correct ro begin 20. \n Ro end 20 greater than ro begin 20", "Information");
                            return;
                        }
                        else if (schedule.ro_end_40 > Int32.Parse(etRObegin40.Text.Trim()))
                        {
                            MessageBox.Show(this, "Please correct ro begin 40. \n Ro end 40 greater than ro begin 40", "Information");
                            return;
                        }
                    }


                    SqlParameter[] sqlParam = SqlUtility.SetSqlParameter(
                        new string[]{"schedule_id", "tujuan", "pelayaran_detail_id", "tgl_closing", 
                                                "voy", "deleted", "keterangan", "vessel_code", "ro_begin_20",
                                                "ro_begin_40", "ro_end_20", "ro_end_40", "etd", "td", "eta", "ta", 
                                                "unloading"
                                            },
                        new object[]{schedule.ID, 
                                                Utility.Utility.ConvertToUUID(cboTujuan.SelectedValue.ToString()),
                                                Utility.Utility.ConvertToUUID(cboKapal.SelectedValue.ToString().Substring(0, 36)),
                                                pickerTglClosing.Value.Date,
                                                etVOY.Text.Trim(),
                                                0,
                                                etKet.Text.Trim(),
                                                cboKapal.SelectedValue.ToString().Substring(36),
                                                Utility.Utility.IsStringNullorEmpty(etRObegin20.Text.Trim()) ? 0 : Int32.Parse(etRObegin20.Text.Trim()) ,
                                                Utility.Utility.IsStringNullorEmpty(etRObegin40.Text.Trim()) ? 0 : Int32.Parse(etRObegin40.Text.Trim()),
                                                schedule.ro_end_20,
                                                schedule.ro_end_40,
                                                pickerETD.Value.Date,
                                                (wantToEditTdETC) ? pickerTD.Value.Date : schedule.td,
                                                (wantToEditTdETC) ? pickerETA.Value.Date : schedule.eta,
                                                (wantToEditTdETC) ? pickerTA.Value.Date : schedule.ta,
                                                pickerUnLoading.Value.Date
                            });


                    if (sqlScheduleRepository.EditSchedule(sqlParam))
                    {
                        MessageBox.Show(this, "Success edit schedule", "Information");
                        radButtonElement2.PerformClick();
                    }
                    else if (!Constant.VisitaJayaPerkasaApplication.anyConnection)
                        MessageBox.Show(this, "Please check your connection", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    else
                    {
                        MessageBox.Show(this, "Cannot edit schedule", "Information");
                    }
                }


                sqlScheduleRepository = null;
            }
        }
        private void LoadDataInBackground()
        {
            sqlScheduleRepository = new SqlScheduleRepository();
            schedules = null;


            if (cboKeySearch.Text.Equals("Destination"))
            {
                schedules = sqlScheduleRepository.ListSchedule((isFirstMenuLoad) ? "01/01/1990" : actionBarDateBegin.Text,
                    (isFirstMenuLoad) ? "01/01/2100" : actionBarDateEnd.Text, cboValueSearch.SelectedValue.ToString(), "", "", (cbFinish.ToggleState == Telerik.WinControls.Enumerations.ToggleState.On) ? true : false
                    );
                if (!Constant.VisitaJayaPerkasaApplication.anyConnection)
                    MessageBox.Show(this, "Please check your connection", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (cboKeySearch.Text.Equals("Vessel"))
            {
                schedules = sqlScheduleRepository.ListSchedule((isFirstMenuLoad) ? "01/01/1990" : actionBarDateBegin.Text,
                    (isFirstMenuLoad) ? "01/01/2100" : actionBarDateEnd.Text, "", cboValueSearch.SelectedValue.ToString(), "", (cbFinish.ToggleState == Telerik.WinControls.Enumerations.ToggleState.On) ? true : false
                    );
                if (!Constant.VisitaJayaPerkasaApplication.anyConnection)
                    MessageBox.Show(this, "Please check your connection", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (cboKeySearch.Text.Equals("VOY"))
            {
                schedules = sqlScheduleRepository.ListSchedule((isFirstMenuLoad) ? "01/01/1990" : actionBarDateBegin.Text,
                    (isFirstMenuLoad) ? "01/01/2100" : actionBarDateEnd.Text, "", "", txtRoSearch.Text.Trim(), (cbFinish.ToggleState == Telerik.WinControls.Enumerations.ToggleState.On) ? true : false
                    );
                if (!Constant.VisitaJayaPerkasaApplication.anyConnection)
                    MessageBox.Show(this, "Please check your connection", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                schedules = sqlScheduleRepository.ListSchedule((isFirstMenuLoad) ? "01/01/1990" : actionBarDateBegin.Text,
                    (isFirstMenuLoad) ? "01/01/2100" : actionBarDateEnd.Text, "", "", "", (cbFinish.ToggleState == Telerik.WinControls.Enumerations.ToggleState.On) ? true : false
                    );
                if (!Constant.VisitaJayaPerkasaApplication.anyConnection)
                    MessageBox.Show(this, "Please check your connection", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }


            if (schedules != null)
            {
                showShedule = schedules;
            }
            else
                showShedule = null;

            if (showShedule != null)
            {
                totalPage = Convert.ToInt32(Math.Ceiling(Convert.ToDecimal(showShedule.Count() / Convert.ToDecimal(pageSize))));
                currentPage = 1;
            }
            else
                totalPage = 0;

            isFirstMenuLoad = false;
        }
        private void radButtonElementRemove_Click(object sender, EventArgs e)
        {
            if (showShedule != null)
            {
                sqlScheduleRepository = new SqlScheduleRepository();
                DialogResult dResult = MessageBox.Show(this, "Are you sure want delete this data ? ", "Confirmation", MessageBoxButtons.YesNo);
                if (dResult == DialogResult.Yes)
                {
                    GridViewRowInfo gridInfo = ScheduleGridView.SelectedRows.First();
                    string id = gridInfo.Cells[0].Value.ToString();
                    SqlParameter[] sqlParam = SqlUtility.SetSqlParameter(new string[] { "schedule_id" }, new object[] { id });

                    if (sqlScheduleRepository.DeleteSchedule(sqlParam))
                    {
                        MessageBox.Show("Data Deleted !");
                        LoadData();
                    }
                    if (!Constant.VisitaJayaPerkasaApplication.anyConnection)
                        MessageBox.Show(this, "Please check your connection", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    else
                        MessageBox.Show("Cannot Delete Data !");

                    sqlParam = null;
                    gridInfo = 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;
            }
        }