Example #1
0
        public void LoadDataInBackground()
        {
            sqlPriceRepository = new SqlPriceListRepository();
            listPrice = sqlPriceRepository.GetPriceListByCriteria(Utility.Utility.ConvertStringToDate("01/01/1990"), Utility.Utility.ConvertStringToDate("01/01/5555"),
                    "", "", "", "", "", 1, "");

            string searchValue = radTextBoxElementSearchWord.Text.ToLower().Trim();
            if (!Constant.VisitaJayaPerkasaApplication.anyConnection)
            {
                MessageBox.Show(this, "Please check your connection", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (listPrice != null)
            {
                if (!string.IsNullOrEmpty(searchValue))
                    showListPrice = listPrice.Where(c => c.Item.ToLower().Contains(searchValue)).ToList<VisitaJayaPerkasa.Entities.PriceList>();
                else
                    showListPrice = listPrice;
            }
            else
                showListPrice = null;

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

            sqlPriceRepository = null;
        }
Example #2
0
        public AtkEdit(Entities.PriceList price)
        {
            InitializeComponent();
            this.price = price;

            sqlPriceListRepository = new SqlPriceListRepository();
            List<Entities.Category> listCategory = sqlPriceListRepository.GetTypeOfSupplier(1);
            if (!Constant.VisitaJayaPerkasaApplication.anyConnection)
            {
                MessageBox.Show(this, "Please check your connection", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            categorySupplier = listCategory != null ? listCategory.FirstOrDefault() : null;

            if (categorySupplier != null)
            {
                listSupplier = sqlPriceListRepository.GetSupplier(categorySupplier.ID);
                if (!Constant.VisitaJayaPerkasaApplication.anyConnection)
                {
                    MessageBox.Show(this, "Please check your connection", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                cbSupplier.Enabled = true;
                cbSupplier.DataSource = listSupplier;
                cbSupplier.DisplayMember = "SupplierName";
                cbSupplier.ValueMember = "Id";
                cbSupplier.SelectedIndex = -1;
                cbSupplier.Text = "-- Choose --";


                if (this.price == null)
                {
                    pickerDate.Value = DateTime.Now;
                    wantToCreateNew = true;
                }
                else
                {
                    cbSupplier.SelectedValue = price.SupplierID;
                    if (cbSupplier.Text.Equals(Constant.VisitaJayaPerkasaApplication.cboDefaultText) || cbSupplier.Text.Equals(""))
                        radButtonElement1.Enabled = false;

                    pickerDate.Value = price.DateFrom;
                    etItem.Text = price.Item;
                    etPrice.Text = price.PriceSupplier.ToString();
                    wantToCreateNew = false;
                }
            }

            listCategory = null;
            sqlPriceListRepository = null;
        }
Example #3
0
        private void radButtonElementRemove_Click(object sender, EventArgs e)
        {
            if (AtkGridView.SelectedRows.Count == 1)
            {
                sqlPriceRepository = new SqlPriceListRepository();
                DialogResult dResult = MessageBox.Show(this, "Are you sure want delete this data ? ", "Confirmation", MessageBoxButtons.YesNo);
                if (dResult == DialogResult.Yes)
                {
                    GridViewRowInfo gridInfo = AtkGridView.SelectedRows.First();
                    string id = gridInfo.Cells[0].Value.ToString();

                    if (sqlPriceRepository.DeletePrice(Utility.Utility.ConvertToUUID(id)))
                    {
                        MessageBox.Show("Data Deleted !");
                        LoadData();
                    }
                    else if (!Constant.VisitaJayaPerkasaApplication.anyConnection)
                        MessageBox.Show(this, "Please check your connection", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    else
                        MessageBox.Show("Cannot Delete Data !");
                }

                sqlPriceRepository = null;
            }
        }
Example #4
0
        private void btnSaveGrid_Click(object sender, EventArgs e)
        {
            if (PriceListGridView.RowCount > 0)
            {
                List<VisitaJayaPerkasa.Entities.PriceList> tempPriceList = new List<VisitaJayaPerkasa.Entities.PriceList>();

                if (cboTypeSupplier.Text.ToLower().Equals("shipping lines"))
                {
                    for (int i = 0; i < PriceListGridView.RowCount; i++)
                    {
                        VisitaJayaPerkasa.Entities.PriceList objPriceList = new VisitaJayaPerkasa.Entities.PriceList();

                        string id = (PriceListGridView.Rows[i].Cells[0].Value.ToString().Equals("")) ? Guid.Empty.ToString() : PriceListGridView.Rows[i].Cells[0].Value.ToString();
                        objPriceList.ID = Utility.Utility.ConvertToUUID(id);

                        id = (PriceListGridView.Rows[i].Cells[1].Value.ToString().Equals("")) ? Utility.Utility.DefaultDateTime().ToString() : PriceListGridView.Rows[i].Cells[1].Value.ToString();
                        objPriceList.DateFrom = Utility.Utility.ConvertStringToDate(id);
                        if (objPriceList.DateFrom.ToString().Equals(Utility.Utility.DefaultDateTime().ToString()))
                        {
                            MessageBox.Show(this, "Please fill date from in line " + i, "Information");
                            return;
                        }

                        id = (PriceListGridView.Rows[i].Cells[2].Value.ToString().Equals("")) ? Utility.Utility.DefaultDateTime().ToString() : PriceListGridView.Rows[i].Cells[2].Value.ToString();
                        objPriceList.DateTo = Utility.Utility.ConvertStringToDate(id);
                        if (objPriceList.DateTo.ToString().Equals(Utility.Utility.DefaultDateTime().ToString()))
                        {
                            MessageBox.Show(this, "Please fill date to in line " + i, "Information");
                            return;
                        }

                        id = (PriceListGridView.Rows[i].Cells[5].Value.ToString().Equals("")) ? Guid.Empty.ToString() : PriceListGridView.Rows[i].Cells[5].Value.ToString();
                        objPriceList.TypeID = Utility.Utility.ConvertToUUID(id);
                        if (objPriceList.TypeID.ToString().Equals(Guid.Empty.ToString()))
                        {
                            MessageBox.Show(this, "Please fill type in line " + i, "Information");
                            return;
                        }

                        id = (PriceListGridView.Rows[i].Cells[6].Value.ToString().Equals("")) ? Guid.Empty.ToString() : PriceListGridView.Rows[i].Cells[6].Value.ToString();
                        objPriceList.ConditionID = Utility.Utility.ConvertToUUID(id);
                        if (objPriceList.ConditionID.ToString().Equals(Guid.Empty))
                        {
                            MessageBox.Show(this, "Please fill condition in line " + i, "Information");
                            return;
                        }

                        id = (PriceListGridView.Rows[i].Cells[9].Value.ToString().Equals("")) ? "-1" : PriceListGridView.Rows[i].Cells[9].Value.ToString();
                        objPriceList.PriceSupplier = Utility.Utility.ConvertStringToDecimal(id);
                        if (objPriceList.PriceSupplier.ToString().Equals("-1"))
                        {
                            MessageBox.Show(this, "Please fill price supplier in line and check your price in line " + i, "Information");
                            return;
                        }


                        if (objPriceList.DateFrom.Date > objPriceList.DateTo.Date) {
                            MessageBox.Show(this, "Please correct datefrom and dateto in line " + i, "Information");
                            return;
                        }

                        tempPriceList.Add(objPriceList);
                        objPriceList = null;
                    }



                    for (int i = 0; i < tempPriceList.Count; i++) {
                        for (int j = i+1; j < tempPriceList.Count; j++) {
                            if (
                                (
                                    tempPriceList.ElementAt(i).TypeID.ToString().Equals(tempPriceList.ElementAt(j).TypeID.ToString()) &&
                                    tempPriceList.ElementAt(i).ConditionID.ToString().Equals(tempPriceList.ElementAt(j).ConditionID.ToString())
                                )
                                &&
                                (
                                    (
                                        tempPriceList.ElementAt(i).DateFrom <= tempPriceList.ElementAt(j).DateFrom &&
                                        tempPriceList.ElementAt(i).DateTo >= tempPriceList.ElementAt(j).DateFrom
                                    )
                                    ||
                                    (
                                        tempPriceList.ElementAt(i).DateFrom >= tempPriceList.ElementAt(j).DateFrom &&
                                        tempPriceList.ElementAt(i).DateFrom <= tempPriceList.ElementAt(j).DateTo
                                    )
                                )
                              ) {
                                  MessageBox.Show(this, "Please fix record - " + i + " and record -" + j + " have same record of date, type and condition. Please remove one", "Information");
                                  return;
                            }
                        }
                    }


                    sqlPriceListRepository = new SqlPriceListRepository();
                    listPriceDeleteExistsData.Clear();
                    listIndexPriceDeleteExistsData.Clear();
                    List<int> indexDeleted = new List<int>();

                    for (int i = 0; i < tempPriceList.Count; i++) {
                        Guid exists = Guid.Empty;

                        exists = sqlPriceListRepository.GetPriceCustomerByShippingLines(tempPriceList.ElementAt(i).DateFrom, 
                                                    tempPriceList.ElementAt(i).DateTo,
                                                    tempPriceList.ElementAt(i).TypeID.ToString(),
                                                    tempPriceList.ElementAt(i).ConditionID.ToString(), 
                                                    cbSupplier.SelectedValue.ToString(),
                                                    cbDestination.SelectedValue.ToString(),
                                                    searchResultCustomer.ID.ToString());

                        if (!Constant.VisitaJayaPerkasaApplication.anyConnection)
                            MessageBox.Show(this, "Please check your connection", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        else if (! exists.ToString().Equals(Guid.Empty.ToString())) { 
                            DialogResult dResult = MessageBox.Show(this, "Record - " + i + " has already exist. \n If you don't want to override this data, so your data not will be save. \n Do you want to override ?", "Confirmation", MessageBoxButtons.YesNo);
                            if (dResult == DialogResult.Yes){
                                listPriceDeleteExistsData.Add(exists);
                                listIndexPriceDeleteExistsData.Add(i);
                            }
                            else
                                indexDeleted.Add(i);
                        }
                    }


                    for (int i = indexDeleted.Count - 1; i >= 0; i--)
                        tempPriceList.RemoveAt(indexDeleted.ElementAt(i));

                    for (int i = 0; i < listPriceDeleteExistsData.Count; i++) {
                        for (int j = i+1; j < listPriceDeleteExistsData.Count; j++) {
                            if (listPriceDeleteExistsData.ElementAt(i) == listPriceDeleteExistsData.ElementAt(j)) {
                                MessageBox.Show(this, "Please fix record -" + listIndexPriceDeleteExistsData.ElementAt(i) + " and record -" + listIndexPriceDeleteExistsData.ElementAt(j) + " have same record of date, type and condition. Please remove one", "Information");
                                return;   
                            }
                        }
                    }

                    sqlPriceListRepository = null;
                }
                else if (cboTypeSupplier.Text.ToLower().Equals("dooring agent")) {
                    for (int i = 0; i < PriceListGridView.RowCount; i++)
                    {
                        VisitaJayaPerkasa.Entities.PriceList objPriceList = new VisitaJayaPerkasa.Entities.PriceList();

                        string id = (PriceListGridView.Rows[i].Cells[0].Value.ToString().Equals("")) ? Guid.Empty.ToString() : PriceListGridView.Rows[i].Cells[0].Value.ToString();
                        objPriceList.ID = Utility.Utility.ConvertToUUID(id);

                        id = (PriceListGridView.Rows[i].Cells[1].Value.ToString().Equals("")) ? Utility.Utility.DefaultDateTime().ToString() : PriceListGridView.Rows[i].Cells[1].Value.ToString();
                        objPriceList.DateFrom = Utility.Utility.ConvertStringToDate(id);
                        if (objPriceList.DateFrom.ToString().Equals(Utility.Utility.DefaultDateTime().ToString()))
                        {
                            MessageBox.Show(this, "Please fill date from in line " + i, "Information");
                            return;
                        }

                        id = (PriceListGridView.Rows[i].Cells[2].Value.ToString().Equals("")) ? Utility.Utility.DefaultDateTime().ToString() : PriceListGridView.Rows[i].Cells[2].Value.ToString();
                        objPriceList.DateTo = Utility.Utility.ConvertStringToDate(id);
                        if (objPriceList.DateTo.ToString().Equals(Utility.Utility.DefaultDateTime().ToString()))
                        {
                            MessageBox.Show(this, "Please fill date to in line " + i, "Information");
                            return;
                        }

                        id = (PriceListGridView.Rows[i].Cells[5].Value.ToString().Equals("")) ? Guid.Empty.ToString() : PriceListGridView.Rows[i].Cells[5].Value.ToString();
                        objPriceList.TypeID = Utility.Utility.ConvertToUUID(id);
                        if (objPriceList.TypeID.ToString().Equals(Guid.Empty.ToString()))
                        {
                            MessageBox.Show(this, "Please fill type in line " + i, "Information");
                            return;
                        }

                        id = (PriceListGridView.Rows[i].Cells[9].Value.ToString().Equals("")) ? "-1" : PriceListGridView.Rows[i].Cells[9].Value.ToString();
                        objPriceList.PriceSupplier = Utility.Utility.ConvertStringToDecimal(id);
                        if (objPriceList.PriceSupplier.ToString().Equals("-1"))
                        {
                            MessageBox.Show(this, "Please fill price supplier in line and check your price in line " + i, "Information");
                            return;
                        }

                        if (objPriceList.DateFrom.Date > objPriceList.DateTo.Date)
                        {
                            MessageBox.Show(this, "Please correct datefrom and dateto in line " + i, "Information");
                            return;
                        }

                        tempPriceList.Add(objPriceList);
                        objPriceList = null;
                    }


                    for (int i = 0; i < tempPriceList.Count; i++)
                    {
                        for (int j = i + 1; j < tempPriceList.Count; j++)
                        {
                            if (
                                (
                                    tempPriceList.ElementAt(i).TypeID.ToString().Equals(tempPriceList.ElementAt(j).TypeID.ToString())
                                )
                                &&
                                (
                                    (
                                        tempPriceList.ElementAt(i).DateFrom <= tempPriceList.ElementAt(j).DateFrom &&
                                        tempPriceList.ElementAt(i).DateTo >= tempPriceList.ElementAt(j).DateFrom
                                    )
                                    ||
                                    (
                                        tempPriceList.ElementAt(i).DateFrom >= tempPriceList.ElementAt(j).DateFrom &&
                                        tempPriceList.ElementAt(i).DateFrom <= tempPriceList.ElementAt(j).DateTo
                                    )
                                )
                              )
                            {
                                MessageBox.Show(this, "Please fix record - " + i + " and record -" + j + " have same record of date and type. Please remove one", "Information");
                                return;
                            }
                        }
                    }


                    sqlPriceListRepository = new SqlPriceListRepository();
                    listPriceDeleteExistsData.Clear();
                    listIndexPriceDeleteExistsData.Clear();
                    List<int> indexDeleted = new List<int>();

                    for (int i = 0; i < tempPriceList.Count; i++)
                    {
                        Guid exists = Guid.Empty;
                        exists = sqlPriceListRepository.GetPriceCustomerByDooringAgent(
                                                    tempPriceList.ElementAt(i).DateFrom,
                                                    tempPriceList.ElementAt(i).DateTo,
                                                    tempPriceList.ElementAt(i).TypeID.ToString(),
                                                    cbSupplier.SelectedValue.ToString(),
                                                    cbDestination.SelectedValue.ToString(),
                                                    cboRecipient.SelectedValue.ToString());

                        if (!Constant.VisitaJayaPerkasaApplication.anyConnection)
                            MessageBox.Show(this, "Please check your connection", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        else if (!exists.ToString().Equals(Guid.Empty.ToString()))
                        {
                            DialogResult dResult = MessageBox.Show(this, "Record - " + i + " has already exist. \n If you don't want to override this data, so your data not will be save. \n Do you want to override ?", "Confirmation", MessageBoxButtons.YesNo);
                            if (dResult == DialogResult.Yes){
                                listPriceDeleteExistsData.Add(exists);
                                listIndexPriceDeleteExistsData.Add(i);
                            }
                            else
                                indexDeleted.Add(i);
                        }
                    }

                    for (int i = indexDeleted.Count - 1; i >= 0; i--)
                        tempPriceList.RemoveAt(indexDeleted.ElementAt(i));

                    for (int i = 0; i < listPriceDeleteExistsData.Count; i++)
                    {
                        for (int j = i + 1; j < listPriceDeleteExistsData.Count; j++)
                        {
                            if (listPriceDeleteExistsData.ElementAt(i) == listPriceDeleteExistsData.ElementAt(j))
                            {
                                MessageBox.Show(this, "Please fix record -" + listIndexPriceDeleteExistsData.ElementAt(i) + " and record -" + listIndexPriceDeleteExistsData.ElementAt(j) + " have same record of date and type. Please remove one", "Information");
                                return;
                            }
                        }
                    }

                    sqlPriceListRepository = null;
                }
                else if (cboTypeSupplier.Text.ToLower().Equals("trucking"))
                {
                    for (int i = 0; i < PriceListGridView.RowCount; i++)
                    {
                        VisitaJayaPerkasa.Entities.PriceList objPriceList = new VisitaJayaPerkasa.Entities.PriceList();

                        string id = (PriceListGridView.Rows[i].Cells[0].Value.ToString().Equals("")) ? Guid.Empty.ToString() : PriceListGridView.Rows[i].Cells[0].Value.ToString();
                        objPriceList.ID = Utility.Utility.ConvertToUUID(id);

                        id = (PriceListGridView.Rows[i].Cells[1].Value.ToString().Equals("")) ? Utility.Utility.DefaultDateTime().ToString() : PriceListGridView.Rows[i].Cells[1].Value.ToString();
                        objPriceList.DateFrom = Utility.Utility.ConvertStringToDate(id);
                        if (objPriceList.DateFrom.ToString().Equals(Utility.Utility.DefaultDateTime().ToString()))
                        {
                            MessageBox.Show(this, "Please fill date from in line " + i, "Information");
                            return;
                        }

                        id = (PriceListGridView.Rows[i].Cells[2].Value.ToString().Equals("")) ? Utility.Utility.DefaultDateTime().ToString() : PriceListGridView.Rows[i].Cells[2].Value.ToString();
                        objPriceList.DateTo = Utility.Utility.ConvertStringToDate(id);
                        if (objPriceList.DateTo.ToString().Equals(Utility.Utility.DefaultDateTime().ToString()))
                        {
                            MessageBox.Show(this, "Please fill date to in line " + i, "Information");
                            return;
                        }

                        id = (PriceListGridView.Rows[i].Cells[5].Value.ToString().Equals("")) ? Guid.Empty.ToString() : PriceListGridView.Rows[i].Cells[5].Value.ToString();
                        objPriceList.TypeID = Utility.Utility.ConvertToUUID(id);
                        if (objPriceList.TypeID.ToString().Equals(Guid.Empty.ToString()))
                        {
                            MessageBox.Show(this, "Please fill type in line " + i, "Information");
                            return;
                        }

                        id = (PriceListGridView.Rows[i].Cells[9].Value.ToString().Equals("")) ? "-1" : PriceListGridView.Rows[i].Cells[9].Value.ToString();
                        objPriceList.PriceSupplier = Utility.Utility.ConvertStringToDecimal(id);
                        if (objPriceList.PriceSupplier.ToString().Equals("-1"))
                        {
                            MessageBox.Show(this, "Please fill price supplier in line and check your price in line " + i, "Information");
                            return;
                        }

                        id = (PriceListGridView.Rows[i].Cells[12].Value.ToString().Equals("")) ? "-1" : PriceListGridView.Rows[i].Cells[12].Value.ToString();
                        objPriceList.PriceCourier = Utility.Utility.ConvertStringToDecimal(id);
                        if (objPriceList.PriceCourier.ToString().Equals("-1"))
                        {
                            MessageBox.Show(this, "Please fill price courier in line and check your price in line " + i, "Information");
                            return;
                        }

                        if (objPriceList.DateFrom.Date > objPriceList.DateTo.Date)
                        {
                            MessageBox.Show(this, "Please correct datefrom and dateto in line " + i, "Information");
                            return;
                        }

                        tempPriceList.Add(objPriceList);
                        objPriceList = null;
                    }


                    for (int i = 0; i < tempPriceList.Count; i++)
                    {
                        for (int j = i + 1; j < tempPriceList.Count; j++)
                        {
                            if (
                                (
                                    tempPriceList.ElementAt(i).TypeID.ToString().Equals(tempPriceList.ElementAt(j).TypeID.ToString())
                                )
                                &&
                                (
                                    (
                                        tempPriceList.ElementAt(i).DateFrom <= tempPriceList.ElementAt(j).DateFrom &&
                                        tempPriceList.ElementAt(i).DateTo >= tempPriceList.ElementAt(j).DateFrom
                                    )
                                    ||
                                    (
                                        tempPriceList.ElementAt(i).DateFrom >= tempPriceList.ElementAt(j).DateFrom &&
                                        tempPriceList.ElementAt(i).DateFrom <= tempPriceList.ElementAt(j).DateTo
                                    )
                                )
                              )
                            {
                                MessageBox.Show(this, "Please fix record - " + i + " and record -" + j + " have same record of date and type. Please remove one", "Information");
                                return;
                            }
                        }
                    }


                    sqlPriceListRepository = new SqlPriceListRepository();
                    listPriceDeleteExistsData.Clear();
                    listIndexPriceDeleteExistsData.Clear();
                    List<int> indexDeleted = new List<int>();

                    for (int i = 0; i < tempPriceList.Count; i++)
                    {
                        Guid exists = Guid.Empty;
                        exists = sqlPriceListRepository.GetPriceCustomerByTrucking(tempPriceList.ElementAt(i).DateFrom,
                                                    tempPriceList.ElementAt(i).DateTo,
                                                    tempPriceList.ElementAt(i).TypeID.ToString(),
                                                    cbSupplier.SelectedValue.ToString(),
                                                    searchResultCustomer.ID.ToString(),
                                                    cboStuffingPlace.SelectedValue.ToString());

                        if (!Constant.VisitaJayaPerkasaApplication.anyConnection)
                            MessageBox.Show(this, "Please check your connection", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        else if (!exists.ToString().Equals(Guid.Empty.ToString()))
                        {
                            DialogResult dResult = MessageBox.Show(this, "Record - " + i + " has already exist. \n If you don't want to override this data, so your data not will be save. \n Do you want to override ?", "Confirmation", MessageBoxButtons.YesNo);
                            if (dResult == DialogResult.Yes){
                                listPriceDeleteExistsData.Add(exists);
                                listIndexPriceDeleteExistsData.Add(i);
                            }
                            else
                                indexDeleted.Add(i);
                        }
                    }


                    for (int i = indexDeleted.Count - 1; i >= 0; i--)
                        tempPriceList.RemoveAt(indexDeleted.ElementAt(i));

                    for (int i = 0; i < listPriceDeleteExistsData.Count; i++)
                    {
                        for (int j = i + 1; j < listPriceDeleteExistsData.Count; j++)
                        {
                            if (listPriceDeleteExistsData.ElementAt(i) == listPriceDeleteExistsData.ElementAt(j))
                            {
                                MessageBox.Show(this, "Please fix record -" + listIndexPriceDeleteExistsData.ElementAt(i) + " and record -" + listIndexPriceDeleteExistsData.ElementAt(j) + " have same record of date and type. Please remove one", "Information");
                                return;
                            }
                        }
                    }

                    sqlPriceListRepository = null;
                }

                    /*
                else if (cboTypeSupplier.Text.ToLower().Equals("general"))
                {
                    for (int i = 0; i < PriceListGridView.RowCount; i++)
                    {
                        VisitaJayaPerkasa.Entities.PriceList objPriceList = new VisitaJayaPerkasa.Entities.PriceList();

                        string id = (PriceListGridView.Rows[i].Cells[0].Value.ToString().Equals("")) ? Guid.Empty.ToString() : PriceListGridView.Rows[i].Cells[0].Value.ToString();
                        objPriceList.ID = Utility.Utility.ConvertToUUID(id);

                        id = (PriceListGridView.Rows[i].Cells[1].Value.ToString().Equals("")) ? Utility.Utility.DefaultDateTime().ToString() : Utility.Utility.ChangeDateMMDD(PriceListGridView.Rows[i].Cells[1].Value.ToString());
                        objPriceList.DateFrom = Utility.Utility.ConvertStringToDate(id);
                        if (objPriceList.DateFrom.ToString().Equals(Utility.Utility.DefaultDateTime().ToString()))
                        {
                            MessageBox.Show(this, "Please fill date from in line " + i, "Information");
                            return;
                        }

                        id = (PriceListGridView.Rows[i].Cells[2].Value.ToString().Equals("")) ? Utility.Utility.DefaultDateTime().ToString() : Utility.Utility.ChangeDateMMDD(PriceListGridView.Rows[i].Cells[2].Value.ToString());
                        objPriceList.DateFrom = Utility.Utility.ConvertStringToDate(id);
                        if (objPriceList.DateFrom.ToString().Equals(Utility.Utility.DefaultDateTime().ToString()))
                        {
                            MessageBox.Show(this, "Please fill date to in line " + i, "Information");
                            return;
                        }

                        id = (PriceListGridView.Rows[i].Cells[8].Value.ToString().Equals("")) ? "-1" : PriceListGridView.Rows[i].Cells[8].Value.ToString();
                        objPriceList.PriceSupplier = Utility.Utility.ConvertStringToDecimal(id);
                        if (objPriceList.PriceSupplier.ToString().Equals("-1"))
                        {
                            MessageBox.Show(this, "Please fill price supplier in line and check your price in line " + i, "Information");
                            return;
                        }

                        if (objPriceList.DateFrom.Date > objPriceList.DateTo.Date)
                        {
                            MessageBox.Show(this, "Please correct datefrom and dateto in line " + i, "Information");
                            return;
                        }

                        tempPriceList.Add(objPriceList);
                        objPriceList = null;
                    }


                    for (int i = 0; i < tempPriceList.Count; i++)
                    {
                        for (int j = i + 1; j < tempPriceList.Count; j++)
                        {
                            if (PriceListGridView.Rows[i].Cells[1].Value.ToString().Equals(PriceListGridView.Rows[j].Cells[1].Value.ToString())
                                && PriceListGridView.Rows[i].Cells[2].Value.ToString().Equals(PriceListGridView.Rows[j].Cells[2].Value.ToString()))
                            {
                                MessageBox.Show(this, "Record -" + i + " and record -" + j + " have same record of date. Please remove one", "Information");
                                return;
                            }

                        }
                    }
                }
                */


                SqlParameter[] sqlParamDeletedPrice = null;
                SqlParameter[] sqlParamInsert = null;
                if (listPriceDeleteExistsData.Count > 0)
                {
                    string[] key = new string[listPriceDeleteExistsData.Count];
                    object[] value = new object[listPriceDeleteExistsData.Count];

                    for (int j = 0; j < listPriceDeleteExistsData.Count; j++)
                    {
                        key[j] = "priceID";
                        value[j] = listPriceDeleteExistsData.ElementAt(j);
                    }

                    sqlParamDeletedPrice = SqlUtility.SetSqlParameter(key, value);
                }

                if (tempPriceList.Count > 0)
                {
                    //14 is field who any in below for
                    string[] key = new string[tempPriceList.Count * 14];
                    object[] value = new object[tempPriceList.Count * 14];

                    int nn = 0;
                    for (int j = 0; j < tempPriceList.Count; j++)
                    {
                        key[nn] = "price_id";
                        value[nn++] = Guid.NewGuid();

                        key[nn] = "dateFrom";
                        value[nn++] = tempPriceList.ElementAt(j).DateFrom;

                        key[nn] = "dateTo";
                        value[nn++] = tempPriceList.ElementAt(j).DateTo;

                        key[nn] = "supplier_id";
                        if (cbSupplier.SelectedIndex >= 0)
                            value[nn++] = listSupplier[cbSupplier.SelectedIndex].Id;
                        else value[nn++] = Guid.Empty;

                        key[nn] = "destination";
                        if (cbDestination.SelectedIndex >= 0)
                            value[nn++] = listCity[cbDestination.SelectedIndex].ID;
                        else value[nn++] = Guid.Empty;

                        key[nn] = "type_cont_id";
                        value[nn++] = tempPriceList.ElementAt(j).TypeID;

                        key[nn] = "condition_id";
                        value[nn++] = tempPriceList.ElementAt(j).ConditionID;

                        key[nn] = "price_supplier";
                        value[nn++] = tempPriceList.ElementAt(j).PriceSupplier;

                        key[nn] = "customer_id";
                        if (searchResultCustomer != null)
                            value[nn++] = searchResultCustomer.ID;
                        else value[nn++] = Guid.Empty;

                        key[nn] = "price_customer";
                        value[nn++] = tempPriceList.ElementAt(j).PriceCustomer;

                        key[nn] = "stuffing_id";
                        if (cboStuffingPlace.SelectedIndex >= 0)
                            value[nn++] = listWarehouse[cboStuffingPlace.SelectedIndex].Id;
                        else value[nn++] = Guid.Empty;

                        key[nn] = "recipient_id";
                        if (cboRecipient.SelectedIndex >= 0)
                            value[nn++] = listRecipient[cboRecipient.SelectedIndex].ID;
                        else value[nn++] = Guid.Empty;

                        key[nn] = "price_courier";
                        value[nn++] = tempPriceList.ElementAt(j).PriceCourier;

                        key[nn] = "item";
                        value[nn++] = DBNull.Value;
                    }

                    sqlParamInsert = SqlUtility.SetSqlParameter(key, value);
                    if (sqlPriceListRepository == null)
                        sqlPriceListRepository = new SqlPriceListRepository();
                    if (sqlPriceListRepository.SavePriceList(
                        (sqlParamDeletedPrice == null) ? null : sqlParamDeletedPrice,
                        sqlParamInsert))
                    {
                        MessageBox.Show(this, "Success saving !", "Information");
                        listPriceDeleteExistsData.Clear();
                        listIndexPriceDeleteExistsData.Clear();
                    }
                    else if (!Constant.VisitaJayaPerkasaApplication.anyConnection)
                    {
                        MessageBox.Show(this, "Please check your connection", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    else
                    {
                        MessageBox.Show(this, "Failed save data !", "Information");
                        return;
                    }
                }

                PriceListGridView.Rows.Clear();
                PriceListGridView.Enabled = false;
            }
        }
Example #5
0
        public PriceList()
        {
            InitializeComponent();
            sqlPriceListRepository = new SqlPriceListRepository();
            sqlCityRepository = new SqlCityRepository();
            sqlCustomerRepository = new SqlCustomerRepository();
            sqlRecipientRepository = new SqlRecipientRepository();
            sqlWareHouseRepository = new SqlWareHouseRepository();

            listPriceDeleteExistsData = new List<Guid>();
            listIndexPriceDeleteExistsData = new List<int>();

            listTypeOfSupplier = sqlPriceListRepository.GetTypeOfSupplier(0);
            if (!Constant.VisitaJayaPerkasaApplication.anyConnection)
                MessageBox.Show(this, "Please check your connection", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

            cboTypeSupplier.SelectedValueChanged -= new EventHandler(cboTypeSupplier_SelectedValueChanged);
            cboTypeSupplier.DataSource = listTypeOfSupplier;
            cboTypeSupplier.DisplayMember = "CategoryName";
            cboTypeSupplier.ValueMember = "ID";
            cboTypeSupplier.SelectedIndex = -1;
            cboTypeSupplier.SelectedText = Constant.VisitaJayaPerkasaApplication.cboDefaultText;
            cboTypeSupplier.SelectedValueChanged += new EventHandler(cboTypeSupplier_SelectedValueChanged);

            listCity = sqlCityRepository.GetCity();
            if (!Constant.VisitaJayaPerkasaApplication.anyConnection)
                MessageBox.Show(this, "Please check your connection", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

            cbDestination.DataSource = listCity;
            cbDestination.DisplayMember = "CityName";
            cbDestination.ValueMember = "ID";
            cbDestination.SelectedIndex = -1;
            cbDestination.SelectedText = Constant.VisitaJayaPerkasaApplication.cboDefaultText;



            listRecipient = sqlRecipientRepository.GetRecipient();
            if (!Constant.VisitaJayaPerkasaApplication.anyConnection)
                MessageBox.Show(this, "Please check your connection", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

            cboRecipient.DataSource = listRecipient;
            cboRecipient.DisplayMember = "Name";
            cboRecipient.ValueMember = "ID";
            cboRecipient.SelectedIndex = -1;
            cboRecipient.SelectedText = Constant.VisitaJayaPerkasaApplication.cboDefaultText;

            listWarehouse = sqlWareHouseRepository.GetWareHouse();
            if (!Constant.VisitaJayaPerkasaApplication.anyConnection)
                MessageBox.Show(this, "Please check your connection", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

            cboStuffingPlace.DataSource = listWarehouse;
            cboStuffingPlace.DisplayMember = "Address";
            cboStuffingPlace.ValueMember = "Id";
            cboStuffingPlace.SelectedIndex = -1;
            cboStuffingPlace.SelectedText = Constant.VisitaJayaPerkasaApplication.cboDefaultText;

            cbSupplier.Enabled = false;
            cboRecipient.Enabled = false;
            cbDislayAll.Visible = false;
            cbDislayAll.Enabled = false;
            sqlPriceListRepository = null;
            PriceListGridView.Enabled = false;
            sqlCityRepository = null;

            pickerFrom.Value = DateTime.Today;
            pickerTo.Value = DateTime.Today;
        }
Example #6
0
        private void LoadData() {
            sqlPriceListRepository = new SqlPriceListRepository();
            PriceListGridView.ReadOnly = false;

            if (cboTypeSupplier.Text.ToLower().Equals("shipping lines"))
            {
                listPriceList = sqlPriceListRepository.GetPriceListByCriteria(pickerFrom.Value.Date, pickerTo.Value.Date,
                    cbSupplier.SelectedValue.ToString(), cbDestination.SelectedValue.ToString(), (! cbDislayAll.Checked) ? searchResultCustomer.ID.ToString() : "", "", "", 1, "");


                if (!Constant.VisitaJayaPerkasaApplication.anyConnection)
                    MessageBox.Show(this, "Please check your connection", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                if(cbDislayAll.Checked)
                    PriceListGridView.ReadOnly = true;
            }
            else if (cboTypeSupplier.Text.ToLower().Equals("dooring agent")) {
                listPriceList = sqlPriceListRepository.GetPriceListByCriteria(pickerFrom.Value.Date, pickerTo.Value.Date,
                    cbSupplier.SelectedValue.ToString(), cbDestination.SelectedValue.ToString(), "", (! cbRecipientDisplay.Checked) ? cboRecipient.SelectedValue.ToString() : "", "", 1, "");
                if (!Constant.VisitaJayaPerkasaApplication.anyConnection)
                    MessageBox.Show(this, "Please check your connection", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                

                if (cbRecipientDisplay.Checked)
                    PriceListGridView.ReadOnly = true;
            }
            else if (cboTypeSupplier.Text.ToLower().Equals("trucking")) {
                listPriceList = sqlPriceListRepository.GetPriceListByCriteria(pickerFrom.Value.Date, pickerTo.Value.Date,
                    cbSupplier.SelectedValue.ToString(), "", (!cbDislayAll.Checked) ? searchResultCustomer.ID.ToString() : "", "", cboStuffingPlace.SelectedValue.ToString(), 1, "");
                if (!Constant.VisitaJayaPerkasaApplication.anyConnection)
                    MessageBox.Show(this, "Please check your connection", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                

                if (cbDislayAll.Checked)
                    PriceListGridView.ReadOnly = true;
            }
            else if (cboTypeSupplier.Text.ToLower().Equals("general")) {
                listPriceList = sqlPriceListRepository.GetPriceListByCriteria(pickerFrom.Value.Date, pickerTo.Value.Date,
                    cbSupplier.SelectedValue.ToString(), "", "", 
                    "", "", 1, "");

                if (!Constant.VisitaJayaPerkasaApplication.anyConnection)
                    MessageBox.Show(this, "Please check your connection", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                
            }



            PriceListGridView.Enabled = true;
            if (listPriceList != null)
            {
                for (int i = 0; i < listPriceList.Count(); i++)
                {
                    object[] obj = {listPriceList.ElementAt(i).ID, 
                        listPriceList.ElementAt(i).DateFrom, 
                        listPriceList.ElementAt(i).DateTo,
                        listPriceList.ElementAt(i).SupplierID, 
                        listPriceList.ElementAt(i).Destination,
                        listPriceList.ElementAt(i).TypeID, 
                        listPriceList.ElementAt(i).ConditionID,
                        listPriceList.ElementAt(i).StuffingID,
                        listPriceList.ElementAt(i).Recipient,
                        listPriceList.ElementAt(i).PriceSupplier,
                        listPriceList.ElementAt(i).CustomerID,
                        listPriceList.ElementAt(i).PriceCustomer,
                        listPriceList.ElementAt(i).PriceCourier
                    };
                    PriceListGridView.Rows.Add(obj);
                }
            }

            sqlPriceListRepository = null;
        }
Example #7
0
        private void RefreshTypeSupplier() {
            PriceListGridView.Rows.Clear();
            PriceListGridView.DataSource = null;
            PriceListGridView.Enabled = false;

            sqlPriceListRepository = new SqlPriceListRepository();
            listSupplier = sqlPriceListRepository.GetSupplier(Utility.Utility.ConvertToUUID(cboTypeSupplier.SelectedValue.ToString()));
            if (!Constant.VisitaJayaPerkasaApplication.anyConnection)
                MessageBox.Show(this, "Please check your connection", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

            cbSupplier.Enabled = true;
            cbSupplier.DataSource = listSupplier;
            cbSupplier.DisplayMember = "SupplierName";
            cbSupplier.ValueMember = "Id";
            cbSupplier.SelectedIndex = -1;
            cbSupplier.Text = "-- Choose --";

            sqlPriceListRepository = null;
        }
Example #8
0
        private void radButtonElement1_Click(object sender, EventArgs e)
        {
            //save
            if (cbSupplier.Text.Equals(Constant.VisitaJayaPerkasaApplication.cboDefaultText))
                MessageBox.Show(this, "Please choose supplier name", "Information");
            else if (etItem.Text.Trim().Length == 0)
                MessageBox.Show(this, "Please fill item", "Information");
            else if (etPrice.Text.Trim().Length == 0)
                MessageBox.Show(this, "Please fill price", "Information");
            else
            {
                try
                {
                    Convert.ToInt32(etPrice.Text.Trim());
                }
                catch (Exception err)
                {
                    MessageBox.Show(this, "price must be numeric", "Information");
                    Logging.Error("AtkEdit.cs - " + err.Message);
                    return;
                }


                sqlPriceListRepository = new SqlPriceListRepository();


                if (wantToCreateNew)
                {
                    SqlParameter[] sqlParam = SqlUtility.SetSqlParameter(new string[] { "dateFrom", "item", "suplier_id" }, new object[] { Utility.Utility.ChangeDateMMDD(pickerDate.Value.Date.ToString()), etItem.Text.Trim(), cbSupplier.SelectedValue });

                    if (sqlPriceListRepository.GetExistsDatePriceATK(sqlParam, wantToCreateNew))
                    {
                        MessageBox.Show(this, "Your data has already exist. \nDelete it first", "Information");
                        return;
                    }
                    else if (!Constant.VisitaJayaPerkasaApplication.anyConnection)
                    {
                        MessageBox.Show(this, "Please check your connection", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    sqlParam = null;
                    SqlParameter[] sqlParamInsert = null;

                    //14 is field who any in below for
                    string[] key = new string[14];
                    object[] value = new object[14];

                    int nn = 0;

                    key[nn] = "price_id";
                    value[nn++] = Guid.NewGuid();

                    key[nn] = "dateFrom";
                    value[nn++] = pickerDate.Value;

                    key[nn] = "dateTo";
                    value[nn++] = DBNull.Value;

                    key[nn] = "supplier_id";
                    value[nn++] = Utility.Utility.ConvertToUUID(cbSupplier.SelectedValue.ToString());

                    key[nn] = "destination";
                    value[nn++] = Guid.Empty;

                    key[nn] = "type_cont_id";
                    value[nn++] = Guid.Empty;

                    key[nn] = "condition_id";
                    value[nn++] = Guid.Empty;

                    key[nn] = "price_supplier";
                    value[nn++] = Convert.ToInt32(etPrice.Text.Trim());

                    key[nn] = "customer_id";
                    value[nn++] = Guid.Empty;

                    key[nn] = "price_customer";
                    value[nn++] = DBNull.Value;

                    key[nn] = "stuffing_id";
                    value[nn++] = Guid.Empty;

                    key[nn] = "recipient_id";
                    value[nn++] = Guid.Empty;

                    key[nn] = "price_courier";
                    value[nn++] = DBNull.Value;

                    key[nn] = "item";
                    value[nn++] = etItem.Text.Trim();

                    sqlParamInsert = SqlUtility.SetSqlParameter(key, value);
                    if (sqlPriceListRepository.SavePriceList(null, sqlParamInsert))
                    {
                        MessageBox.Show(this, "Success saving !", "Information");
                        radButtonElement2.PerformClick();
                    }
                    else if (!Constant.VisitaJayaPerkasaApplication.anyConnection)
                        MessageBox.Show(this, "Please check your connection", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    else
                        MessageBox.Show(this, "Failed save data !", "Information");

                    sqlParamInsert = null;
                }
                else {
                    SqlParameter[] sqlParam = SqlUtility.SetSqlParameter(new string[] { "dateFrom", "item", "supplier_id", "price_id" }, new object[] { Utility.Utility.ChangeDateMMDD(pickerDate.Value.Date.ToString()), etItem.Text.Trim(), cbSupplier.SelectedValue, this.price.ID });

                    if (sqlPriceListRepository.GetExistsDatePriceATK(sqlParam, wantToCreateNew))
                    {
                        MessageBox.Show(this, "Your data has already exist. \nDelete it first", "Information");
                        return;
                    }
                    else if (!Constant.VisitaJayaPerkasaApplication.anyConnection)
                    {
                        MessageBox.Show(this, "Please check your connection", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    sqlParam = null;



                    SqlParameter[] sqlParamEdit = SqlUtility.SetSqlParameter(new string[] { "supplier_id", "dateFrom", "item", "price_supplier", "price_id" }, new object[] { Utility.Utility.ConvertToUUID(cbSupplier.SelectedValue.ToString()), pickerDate.Value.Date, etItem.Text.Trim(), etPrice.Text.Trim(), this.price.ID });
                    if (sqlPriceListRepository.EditPriceATK(sqlParamEdit))
                    {
                        MessageBox.Show(this, "Success Edit Price ATK", "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 Price ATK", "Information");
                    }

                    sqlParamEdit = null;
                }
            }

            sqlPriceListRepository = null;
        }
        private void LoadData() {
            SqlPriceListRepository sqlPriceListRepository = new SqlPriceListRepository();

            listPrice = sqlPriceListRepository.GetPriceListByCriteria(pickerFrom.Value.Date, pickerTo.Value.Date,
                "", cbDestination.SelectedValue.ToString(), searchResultCustomer.ID.ToString(),
                "", "", 0, cboType.SelectedValue.ToString());

            radGridView1.Enabled = true;

            if (!Constant.VisitaJayaPerkasaApplication.anyConnection)
                MessageBox.Show(this, "Please check your connection", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            else if (listPrice != null)
            {
                for (int i = 0; i < listPrice.Count(); i++)
                {
                    object[] obj = {listPrice.ElementAt(i).ID, 
                        listPrice.ElementAt(i).DateFrom,
                        listPrice.ElementAt(i).DateTo,
                        listPrice.ElementAt(i).CustomerID,
                        listPrice.ElementAt(i).Destination,
                        listPrice.ElementAt(i).TypeID, 
                        listPrice.ElementAt(i).ConditionID,
                        listPrice.ElementAt(i).PriceCustomer
                                   };
                    radGridView1.Rows.Add(obj);
                }
            }

            sqlPriceListRepository = 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;
            }
        }