public List<Supplier> ListSuppliers()
        {
            List<Supplier> listSupplier = null;

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

                    using (SqlCommand command = new SqlCommand(
                        "SELECT s.supplier_id, s.category_id, s.supplier_name, s.address, s.phone, s.fax, s.email, s.contact_person, c.category_name, s.deleted, s.TypeOfPaymentId, s.TermOfPayment FROM [Supplier] s JOIN [CATEGORY] c " +
                        "ON (s.deleted is null OR s.deleted = '0') AND (c.deleted is null OR c.deleted = '0') AND s.category_id = c.category_id", con))
                    {
                        SqlDataReader reader = command.ExecuteReader();
                        while (reader.Read())
                        {
                            Supplier supplier = new Supplier();
                            supplier.Id = Utility.Utility.ConvertToUUID(reader.GetValue(0).ToString());
                            supplier.CategoryId = Utility.Utility.ConvertToUUID(reader.GetValue(1).ToString());
                            supplier.SupplierName = (Utility.Utility.IsDBNull(reader.GetValue(2))) ? null : reader.GetString(2);
                            supplier.Address = (Utility.Utility.IsDBNull(reader.GetValue(3))) ? null : reader.GetString(3);
                            supplier.Phone = (Utility.Utility.IsDBNull(reader.GetValue(4))) ? null : reader.GetString(4);
                            supplier.Fax = (Utility.Utility.IsDBNull(reader.GetValue(5))) ? null : reader.GetString(5);
                            supplier.Email = (Utility.Utility.IsDBNull(reader.GetValue(6))) ? null : reader.GetString(6);
                            supplier.ContactPerson = (Utility.Utility.IsDBNull(reader.GetValue(7))) ? null : reader.GetString(7);
                            supplier.CategoryName = (Utility.Utility.IsDBNull(reader.GetValue(8))) ? null : reader.GetString(8);

                            if(! (Utility.Utility.IsDBNull(reader.GetValue(10))))
                                supplier.TypeOfPayment = Utility.Utility.ConvertToUUID(reader.GetValue(10).ToString());
                            supplier.TermOfPayment = (Utility.Utility.IsDBNull(reader.GetValue(11))) ? null : reader.GetString(11);

                            if (listSupplier == null)
                                listSupplier = new List<Supplier>();

                            listSupplier.Add(supplier);
                            supplier = null;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Logging.Error("SqlSupplierRepository.cs - ListSuppliers() " + e.Message);
            }

            return listSupplier;
        }
        public List<Supplier> GetSupplier(Guid ID)
        {
            List<Supplier> listSupplier = null;

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

                    using (SqlCommand command = new SqlCommand(
                        "SELECT supplier_id, supplier_name FROM SUPPLIER " + 
                        "WHERE (deleted is null OR deleted = '0') AND category_id like '" + ID + "' ORDER BY supplier_name ASC"
                        , con))
                    {
                        SqlDataReader reader = command.ExecuteReader();
                        while (reader.Read())
                        {
                            Supplier supplier = new Supplier();
                            supplier.Id = Utility.Utility.ConvertToUUID(reader.GetValue(0).ToString());
                            supplier.SupplierName = reader.GetString(1); 

                            if (listSupplier == null)
                                listSupplier = new List<Supplier>();

                            listSupplier.Add(supplier);
                            supplier = null;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Logging.Error("SqlPriceListRepository.cs - GetSupplier() " + e.Message);
            }

            return listSupplier;
        }
Ejemplo n.º 3
0
        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;
            }
        }
        public List<Supplier> GetListSupplierForRecipient()
        {
            List<Supplier> listSupplier = null;

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

                    using (SqlCommand command = new SqlCommand(
                        "SELECT s.supplier_id, s.supplier_name FROM [Supplier] s WHERE (s.deleted is null OR s.deleted = '0') ", con))
                    {
                        SqlDataReader reader = command.ExecuteReader();
                        while (reader.Read())
                        {
                            Supplier supplier = new Supplier();
                            supplier.Id = Utility.Utility.ConvertToUUID(reader.GetValue(0).ToString());
                            supplier.SupplierName = (Utility.Utility.IsDBNull(reader.GetValue(1))) ? null : reader.GetString(1);

                            if (listSupplier == null)
                                listSupplier = new List<Supplier>();

                            listSupplier.Add(supplier);
                            supplier = null;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Logging.Error("SqlSupplierRepository.cs - GetListSupplierForRecipient() " + e.Message);
            }

            return listSupplier;
        }