public SupplierView(Entities.Supplier supplier)
        {
            InitializeComponent();
            sqlSupplierRepository = new SqlSupplierRepository();
            listSupplierDetail = sqlSupplierRepository.ListSupplierDetail(supplier.Id);

            if (!Constant.VisitaJayaPerkasaApplication.anyConnection)
                MessageBox.Show(this, "Please check your connection", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            else if (listSupplierDetail != null)
                SupplierDetailGridView.DataSource = listSupplierDetail;


            lblSupplierName.Text = supplier.SupplierName;
            lblCategoryName.Text = supplier.CategoryName;
            lblAddres.Text = supplier.Address;
            lblEmail.Text = supplier.Email;
            lblPhone.Text = supplier.Phone;
            lblFax.Text = supplier.Fax;
            lblContactPerson.Text = supplier.ContactPerson;

            if (supplier.CategoryName.Equals("Trucking")) {
                gbTrucking.Visible = true;
                List<string> listTemp = sqlSupplierRepository.ListTruckingNumber(supplier.Id);

                if (listTemp != null)
                    for (int i = 0; i < listTemp.Count; i++)
                        gvTrucking.Rows.Add(listTemp.ElementAt(i));

                listTemp = null;
            }
        }
        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 --";
        }
        public PelayaranEdit(VisitaJayaPerkasa.Entities.Pelayaran pelayaran, UserControl ucSupplier)
        {
            InitializeComponent();
            this.ucSupplier = ucSupplier;
            this.pelayaran = pelayaran;
            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);


            cbSupplier.DataSource = listSupplier;
            cbSupplier.DisplayMember = "SupplierName";
            cbSupplier.ValueMember = "Id";

            if (pelayaran == null)
            {
                wantToCreateVessel = true;
                listPelayaranDetail = new List<Entities.PelayaranDetail>();

                cbSupplier.SelectedValue = ((SupplierEdit)ucSupplier).newGuid;
            }
            else
            {
                wantToCreateVessel = false;
                cbSupplier.SelectedValue = pelayaran.supplierID;

                SqlPelayaranRepository sqlPelayaranRepository = new SqlPelayaranRepository();
                listPelayaranDetail = sqlPelayaranRepository.ListPelayaranDetail(pelayaran.ID);

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

                sqlPelayaranRepository = null;
            }
        }
        public void LoadDataInBackground()
        {
            sqlSupplierRepository = new SqlSupplierRepository();
            Supliers = null;

            string searchValue = radTextBoxElementSearchWord.Text;
            string searchKey = radComboBoxElement.Text;

            Supliers = sqlSupplierRepository.ListSuppliers();

            if (!Constant.VisitaJayaPerkasaApplication.anyConnection)
                MessageBox.Show(this, "Please check your connection", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            else if (Supliers != null)
            {
                if (!string.IsNullOrEmpty(searchValue) && !string.IsNullOrEmpty(searchKey))
                {
                    SqlParameter[] sqlParam;

                    switch (searchKey)
                    {
                        case "Supplier Name":
                            sqlParam = SqlUtility.SetSqlParameter(new string[] { "first_name" }, new object[] { searchValue });
                            Supliers = Supliers.Where(c => c.SupplierName.Contains(searchValue)).ToList<Entities.Supplier>();
                            break;
                    }

                    sqlParam = null;
                }
            }

            if (Supliers != null)
            {
                totalPage = Convert.ToInt32(Math.Ceiling(Convert.ToDecimal(Supliers.Count() / Convert.ToDecimal(pageSize))));
                currentPage = 1;
            }
            else
                totalPage = 0;
        }
Beispiel #5
0
        private void LoadCboGridView() {
            sqlSupplierRepository = new SqlSupplierRepository();
            sqlCityRepository = new SqlCityRepository();
            sqlTypeContRepository = new SqlTypeContRepository();
            sqlConditionRepository = new SqlConditionRepository();

                List<VisitaJayaPerkasa.Entities.Supplier> listTempSupplier = new List<Entities.Supplier>();
                listTempSupplier.Add(listSupplier.ElementAt(cbSupplier.SelectedIndex));


                ((GridViewComboBoxColumn)this.PriceListGridView.Columns[3]).DataSource = listTempSupplier;
                ((GridViewComboBoxColumn)this.PriceListGridView.Columns[3]).DisplayMember = "SupplierName";
                ((GridViewComboBoxColumn)this.PriceListGridView.Columns[3]).ValueMember = "Id";


                if (cboTypeSupplier.Text.ToLower().Equals("shipping lines") ||
                   cboTypeSupplier.Text.ToLower().Equals("dooring agent")
                    )
                {
                    List<VisitaJayaPerkasa.Entities.City> listTempCity = new List<Entities.City>();
                    listTempCity.Add(listCity.ElementAt(cbDestination.SelectedIndex));

                    ((GridViewComboBoxColumn)this.PriceListGridView.Columns[4]).DataSource = listTempCity;
                    ((GridViewComboBoxColumn)this.PriceListGridView.Columns[4]).DisplayMember = "CityName";
                    ((GridViewComboBoxColumn)this.PriceListGridView.Columns[4]).ValueMember = "ID";

                    listTempCity = null;
                }

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

                ((GridViewComboBoxColumn)this.PriceListGridView.Columns[5]).DataSource = listType;
                ((GridViewComboBoxColumn)this.PriceListGridView.Columns[5]).DisplayMember = "TypeName";
                ((GridViewComboBoxColumn)this.PriceListGridView.Columns[5]).ValueMember = "ID";


                if (cboTypeSupplier.Text.ToLower().Equals("shipping lines"))
                {
                    listCondition = sqlConditionRepository.GetConditions();
                    if (!Constant.VisitaJayaPerkasaApplication.anyConnection)
                        MessageBox.Show(this, "Please check your connection", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    ((GridViewComboBoxColumn)this.PriceListGridView.Columns[6]).DataSource = listCondition;
                    ((GridViewComboBoxColumn)this.PriceListGridView.Columns[6]).DisplayMember = "ConditionName";
                    ((GridViewComboBoxColumn)this.PriceListGridView.Columns[6]).ValueMember = "ID";
                }

                if (cboTypeSupplier.Text.ToLower().Equals("shipping lines") ||
                    cboTypeSupplier.Text.ToLower().Equals("trucking")
                    ) {
                    listCustomer = sqlCustomerRepository.ListCustomers();
                    if (!Constant.VisitaJayaPerkasaApplication.anyConnection)
                        MessageBox.Show(this, "Please check your connection", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    ((GridViewComboBoxColumn)this.PriceListGridView.Columns[10]).DataSource = listCustomer;
                    ((GridViewComboBoxColumn)this.PriceListGridView.Columns[10]).DisplayMember = "CustomerName";
                    ((GridViewComboBoxColumn)this.PriceListGridView.Columns[10]).ValueMember = "ID";
                }

                listTempSupplier = null;


            if (cboTypeSupplier.Text.ToLower().Equals("dooring agent")) {
                List<VisitaJayaPerkasa.Entities.Recipient> tempListRecipient = sqlRecipientRepository.GetRecipient();
                if (!Constant.VisitaJayaPerkasaApplication.anyConnection)
                    MessageBox.Show(this, "Please check your connection", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                ((GridViewComboBoxColumn)this.PriceListGridView.Columns[8]).DataSource = tempListRecipient;
                ((GridViewComboBoxColumn)this.PriceListGridView.Columns[8]).DisplayMember = "Name";
                ((GridViewComboBoxColumn)this.PriceListGridView.Columns[8]).ValueMember = "ID";

                tempListRecipient = null;
            }

            if (cboTypeSupplier.Text.ToLower().Equals("trucking"))
            {
                List<VisitaJayaPerkasa.Entities.WareHouse> tempListWarehouse = new List<Entities.WareHouse>();
                tempListWarehouse.Add(listWarehouse.ElementAt(cboStuffingPlace.SelectedIndex)); 
                
                ((GridViewComboBoxColumn)this.PriceListGridView.Columns[7]).DataSource = tempListWarehouse;
                ((GridViewComboBoxColumn)this.PriceListGridView.Columns[7]).DisplayMember = "Address";
                ((GridViewComboBoxColumn)this.PriceListGridView.Columns[7]).ValueMember = "Id";

                tempListWarehouse = null;
            }

            sqlSupplierRepository = null;
            sqlCityRepository = null;
            sqlTypeContRepository = null;
            sqlConditionRepository = null;
        }
        private void SaveData()
        {
            SqlSupplierRepository sqlSupplierRepository = null;

            if (wantToCreateVessel)
            {
                sqlSupplierRepository = new SqlSupplierRepository();
                newGuid = Guid.NewGuid();

                string[] strSqlParam = getStringSqlParameter();
                object[] objSqlParam = GetObjSqlParameter(newGuid);
                SqlParameter[] sqlParam = SqlUtility.SetSqlParameter(strSqlParam, objSqlParam);

                if (sqlSupplierRepository.CheckSupplier(sqlParam, Guid.Empty, true))
                {
                    DialogResult dResult = MessageBox.Show(this, "Supplier has already deleted. Do you want to activate ?", "Confirmation", MessageBoxButtons.YesNo);
                    if (dResult == DialogResult.Yes)
                    {
                        if (sqlSupplierRepository.ActivateSupplier(sqlParam))
                        {
                            MessageBox.Show(this, "Success Activate Supplier", "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 Activate Supplier", "Information");

                        sqlParam = null;
                    }
                    return;
                }
                else if (!Constant.VisitaJayaPerkasaApplication.anyConnection)
                {
                    MessageBox.Show(this, "Please check your connection", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else if (sqlSupplierRepository.CheckSupplier(sqlParam, Guid.Empty))
                {
                    MessageBox.Show(this, "Supplier has already exists", "Information");
                    return;
                }
                else if (!Constant.VisitaJayaPerkasaApplication.anyConnection)
                {
                    MessageBox.Show(this, "Please check your connection", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }


                if (sqlSupplierRepository.CreateSupplier(sqlParam, (groupBoxTrucking.Visible) ? gvTrucking.RowCount : 0, (groupBoxDestination.Visible) ? gvDestination.RowCount : 0))
                {
                    MessageBox.Show(this, "Success insert supplier data", "Information");

                    if (isSaveMasterSupplierDetail) {
                        SqlPelayaranRepository sqlPelayaranRepository = new SqlPelayaranRepository();

                        VisitaJayaPerkasa.Entities.Pelayaran pelayaran = sqlPelayaranRepository.GetPelayaranBySupplierID((wantToCreateVessel) ? newGuid.ToString() : this.supplier.Id.ToString());
                        UserControl controllers = new Pelayaran.PelayaranEdit(pelayaran, this);
                        Constant.VisitaJayaPerkasaApplication.mainForm.ShowUserControl(controllers);

                        sqlPelayaranRepository = null;
                    }
                    else
                        radButtonElement2.PerformClick();
                }
                else if (!Constant.VisitaJayaPerkasaApplication.anyConnection)
                    MessageBox.Show(this, "Please check your connection", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                else
                {
                    MessageBox.Show(this, "Cannot insert supplier data", "Information");
                }
                sqlSupplierRepository = null;
                strSqlParam = null;
                objSqlParam = null;
                sqlParam = null;
            }
            else
            {
                sqlSupplierRepository = new SqlSupplierRepository();
                string[] strSqlParam = getStringSqlParameter();
                object[] objSqlParam = GetObjSqlParameter(supplier.Id);
                SqlParameter[] sqlParam = SqlUtility.SetSqlParameter(strSqlParam, objSqlParam);

                if (sqlSupplierRepository.CheckSupplier(sqlParam, this.supplier.Id))
                {
                    MessageBox.Show(this, "supplier has already exist. if it has already deleted. you must activate it with create new data", "Information");
                    return;
                }
                else if (!Constant.VisitaJayaPerkasaApplication.anyConnection)
                {
                    MessageBox.Show(this, "Please check your connection", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                if (sqlSupplierRepository.EditSupplier(sqlParam, (groupBoxTrucking.Visible) ? gvTrucking.RowCount : 0, (groupBoxDestination.Visible) ? gvDestination.RowCount : 0))
                {
                    MessageBox.Show(this, "Success edit supplier data", "Information");

                    if (isSaveMasterSupplierDetail)
                    {
                        SqlPelayaranRepository sqlPelayaranRepository = new SqlPelayaranRepository();

                        VisitaJayaPerkasa.Entities.Pelayaran pelayaran = sqlPelayaranRepository.GetPelayaranBySupplierID(this.supplier.Id.ToString());
                        UserControl controllers = new Pelayaran.PelayaranEdit(pelayaran, this);
                        Constant.VisitaJayaPerkasaApplication.mainForm.ShowUserControl(controllers);

                        sqlPelayaranRepository = null;
                    }
                    else
                        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 supplier data", "Information");
                }

                sqlSupplierRepository = null;
                strSqlParam = null;
                objSqlParam = null;
                sqlParam = null;
            }
        }
        public SupplierEdit(VisitaJayaPerkasa.Entities.Supplier supplier)
        {
            InitializeComponent();
            sqlCategoryRepository = new SqlCategoryRepository();
            sqlPaymentRepository = new SqlPaymentRepository();
            sqlCityRepository = new SqlCityRepository();
            List<Category> listCategory = sqlCategoryRepository.GetCategories();
            List<Payment> listPayment = sqlPaymentRepository.GetListPayment();
            List<Entities.City> listCity = sqlCityRepository.GetCity();

            cboCategory.DataSource = listCategory;
            cboCategory.DisplayMember = "CategoryName";
            cboCategory.ValueMember = "ID";

            cbTypeOfPayment.DataSource = listPayment;
            cbTypeOfPayment.DisplayMember = "Name";
            cbTypeOfPayment.ValueMember = "ID";

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

            this.supplier = supplier;
            this.isSaveMasterSupplierDetail = false;
            sqlCityRepository = null;
            sqlPaymentRepository = null;

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

                wantToCreateVessel = true;
                listSupplierDetail = new List<Entities.SupplierDetail>();

                cboCategory.SelectedIndex = -1;
                cboCategory.Text = "-- Choose --";

                cbTypeOfPayment.SelectedIndex = -1;
                cbTypeOfPayment.Text = Constant.VisitaJayaPerkasaApplication.cboDefaultText;
            }
            else
            {
                wantToCreateVessel = false;
                etSupplierName.Text = supplier.SupplierName;
                cboCategory.SelectedItem = supplier.CategoryName;

                if (supplier.TypeOfPayment == null)
                {
                    cbTypeOfPayment.SelectedIndex = -1;
                    cbTypeOfPayment.Text = Constant.VisitaJayaPerkasaApplication.cboDefaultText;
                }
                else
                    cbTypeOfPayment.SelectedValue = supplier.TypeOfPayment;

                etTermOfPayment.Text = supplier.TermOfPayment;
                etAddress.Text = supplier.Address;
                etEmail.Text = supplier.Email;
                etPhone.Text = supplier.Phone;
                etFax.Text = supplier.Fax;
                etContactPerson.Text = supplier.ContactPerson;

                SqlSupplierRepository sqlSupplierRepository = new SqlSupplierRepository();
                listSupplierDetail = sqlSupplierRepository.ListSupplierDetail(supplier.Id);

                if (!Constant.VisitaJayaPerkasaApplication.anyConnection)
                {
                    MessageBox.Show(this, "Please check your connection", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else if (listSupplierDetail != null)
                    supplierDetailGridView.DataSource = listSupplierDetail;
                else
                    listSupplierDetail = new List<VisitaJayaPerkasa.Entities.SupplierDetail>();


                if (supplier.CategoryName.Equals("Trucking"))
                { 
                    List<string> listTemp = sqlSupplierRepository.ListTruckingNumber(supplier.Id);

                    if(listTemp != null)
                        for (int i = 0; i < listTemp.Count; i++)
                            gvTrucking.Rows.Add(listTemp.ElementAt(i));

                    listTemp = null;
                }
                else if (supplier.CategoryName.Equals("Dooring Agent"))
                {
                    List<Entities.City> listTemp = sqlSupplierRepository.ListCitySupplier(supplier.Id);
                    groupBoxDestination.Visible = true;

                    if (listTemp != null)
                        for (int i = 0; i < listTemp.Count; i++)
                        {
                            gvDestination.Rows.AddNew();

                            GridViewDataRowInfo gridViewRow = gvDestination.Rows[i];
                            gridViewRow.Cells["ID"].Value = listTemp.ElementAt(i).ID.ToString();
                            gridViewRow.Cells["CityName"].Value = listTemp.ElementAt(i).CityName;
                        }

                    listTemp = null;
                }

                sqlSupplierRepository = null;
            }
        }
        private void radButtonElementRemove_Click(object sender, EventArgs e)
        {
            if (SupplierGridView.SelectedRows.Count == 1)
            {
                sqlSupplierRepository = new SqlSupplierRepository();
                DialogResult dResult = MessageBox.Show(this, "Are you sure want delete master and detail this supplier ? ", "Confirmation", MessageBoxButtons.YesNo);
                if (dResult == DialogResult.Yes)
                {
                    GridViewRowInfo gridInfo = SupplierGridView.SelectedRows.First();
                    string id = gridInfo.Cells[0].Value.ToString();
                    SqlParameter[] sqlParam = SqlUtility.SetSqlParameter(new string[] { "supplier_id" }, new object[] { id });

                    if (sqlSupplierRepository.DeleteSupplier(sqlParam))
                    {
                        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 !");

                    sqlParam = null;
                }
            }
        }