/// <summary>
 /// Get all the datat from the database
 /// </summary>
 private void getAll()
 {
     try
     {
         packages           = PackagesDB.GetAllPackages();
         packages2          = PackagesDB.GetAllPackages(); //Two controls cannot share array data binding
         products           = ProductDB.GetAllProducts();
         products2          = ProductDB.GetAllProducts();  //Two controls cannot share array data binding
         suppliers          = SuppliersDB.GetAllSuppliers();
         products_suppliers = Products_SupplierDB.GetAllProduct_Suppliers();
     }
     catch (Exception ex) //Any Errors form the database read?
     {
         MessageBox.Show(ex.Message, ex.GetType().ToString());
     }
 }
Example #2
0
        private void LoadComboAndGrid()

        {
            SqlConnection connection = TravelExpertConnection.GetConnection();
            // we can get the Supname..
            string         query = "SELECT SupplierId, SupName from Suppliers order by SupName";
            SqlDataAdapter supp  = new SqlDataAdapter(query, connection);
            SqlCommand     cmd   = new SqlCommand(query, connection);
            DataTable      tab   = new DataTable();

            supp.Fill(tab);

            cboSupName.DataSource         = tab;
            cboSupName.DisplayMember      = "SupName";
            cboSupName.ValueMember        = "SupplierId";
            this.cboSupName.SelectedIndex = -1;
            //cmd.ExecuteNonQuery();
            suppliersDataGridView.DataSource = SuppliersDB.GetAllSuppliers();
        }
Example #3
0
 private void btnAddUpdate_Click(object sender, EventArgs e)
 {
     {
         using (SqlConnection connection = TravelExpertConnection.GetConnection())
         {
             if (Validator.IsPresent(txtSupName))
             {
                 connection.Open();
                 SqlCommand cmd = connection.CreateCommand();
                 cmd.CommandType = CommandType.Text;
                 cmd.CommandText = "update Suppliers set SupName='" + txtSupName.Text + "'" +
                                   "where SupplierId='" + cboSupName.SelectedValue + "'";
                 cmd.ExecuteNonQuery();
                 connection.Close();
             }
         }
         suppliersDataGridView.DataSource = SuppliersDB.GetAllSuppliers();
         LoadComboAndGrid();
         txtSupName.Text = "";
     }
 }
Example #4
0
        /// <summary>
        /// Load data for Product Suppliers tab
        /// </summary>
        /// <param name="productIndex">Current index of Product Supplier list. Optional parameter.</param>
        /// <returns>Rows affected by query, 1 for success and 0 for failure</returns>
        // @author Chi
        private void loadProductSupplierData(int productIndex = 0)
        {
            // Clear list box and data grid view
            lstboxSuppliers.Items.Clear();
            dataGridViewProdSuppliers.Columns.Clear();

            // Set current product's view to index of 'products' list (global variable).
            Products curProduct = products[productIndex];

            curProductSuppliers = ProductSupplierDB.GetProductSuppliersByProductID(curProduct.ProductID);

            // Display current product's ID and Name.
            txtPSProdID.Text   = curProduct.ProductID.ToString();
            txtPSProdName.Text = curProduct.ProductName;

            // Set customized properties for Data Grid View.
            dataGridViewProdSuppliers.AutoGenerateColumns = false;
            dataGridViewProdSuppliers.DataSource          = curProductSuppliers;

            // Created and bind custom column to data source's data property SupplierId.
            DataGridViewTextBoxColumn idColumn = new DataGridViewTextBoxColumn();

            idColumn.Name             = "Supplier's ID";
            idColumn.DataPropertyName = "SupplierId";
            idColumn.Width            = 100;
            idColumn.ReadOnly         = true;

            // Created and bind custom column to data source's data property SupName.
            DataGridViewTextBoxColumn nameColumn = new DataGridViewTextBoxColumn();

            nameColumn.Name             = "Supplier's Name";
            nameColumn.DataPropertyName = "SupName";
            nameColumn.Width            = 239;
            nameColumn.ReadOnly         = true;

            // Add data bound columns to Data Grid View.
            dataGridViewProdSuppliers.Columns.Add(idColumn);
            dataGridViewProdSuppliers.Columns.Add(nameColumn);

            // List of all suppliers
            List <Supplier> allSuppliers = SuppliersDB.GetAllSuppliers();

            // Get a list of suppliers that are currently not added to current product's suppliers list
            filteredSuppliers = new List <Supplier>(allSuppliers.Where(
                                                        Sup => curProductSuppliers.All(
                                                            sup2 => sup2.SupplierId != Sup.SupplierId
                                                            )));

            // Add/Update filtered list to list box to prevent customer from adding
            // same suppliers to product's supplier list.
            foreach (Supplier sup in filteredSuppliers)
            {
                // check if supplier name is null
                if (sup.SupName == null)
                {
                    lstboxSuppliers.Items.Add("");
                }
                else
                {
                    lstboxSuppliers.Items.Add(sup.SupName);
                }
            }
        }