public static List <product_suppliers> getProduct_Suppliers(string product_name, string supplier_name)
        {
            List <product_suppliers> product_supplier_info = new List <product_suppliers>();
            SqlConnection            connection            = connectionDB.GetConnection();
            string selectstatement = "select p.ProdName,s.SupName from Products_Suppliers ps " +
                                     "inner join Products p on p.ProductId = ps.ProductId " +
                                     "inner join Suppliers s on s.SupplierId = ps.supplierId " +
                                     "where p.ProdName = @ProdName and s.SupName = @Suppliername";
            SqlCommand selectCommand = new SqlCommand(selectstatement, connection);

            selectCommand.Parameters.AddWithValue("@ProdName", product_name);
            selectCommand.Parameters.AddWithValue("@Suppliername", supplier_name);
            try
            {
                connection.Open();
                SqlDataReader reader = selectCommand.ExecuteReader();
                while (reader.Read())
                {
                    product_suppliers initialize_info = new product_suppliers();
                    initialize_info.Productname  = reader["ProdName"].ToString();
                    initialize_info.Suppliername = reader["SupName"].ToString();
                    product_supplier_info.Add(initialize_info);
                }
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            finally
            {
                connection.Close();
            }
            return(product_supplier_info);
        }
Beispiel #2
0
        private void Btl_Insert_Click(object sender, EventArgs e)
        {
            if (Insert_GridView.SelectedRows.Count > 0)
            {
                product_suppliers itemToInsert = (product_suppliers)Insert_GridView.SelectedRows[0].DataBoundItem;
                foreach (package_product_supplier element in List_info)
                {
                    if (element.Productname == itemToInsert.Productname && element.suppliername == itemToInsert.Suppliername)
                    {
                        MessageBox.Show("this information already exists,Please insert a new value");
                    }
                }
                if (Package_Product_SupplierDB.insert_info(InsertName, itemToInsert.Productname, itemToInsert.Suppliername))
                {
                    MessageBox.Show("Sucessfully Inserted");
                }
                else
                {
                    MessageBox.Show("Insert failure Please contact Administrator");
                }

                /*
                 * TravelExperts info = new TravelExperts();
                 * List_info = Package_Product_SupplierDB.getPackageinfo(InsertName);
                 * info.DisplayBox_info(List_info);
                 */
            }
            else
            {
                MessageBox.Show("need to choose a row first");
            }
        }
Beispiel #3
0
 private void BtlUpdate_Click(object sender, EventArgs e)
 {
     if (Insert_GridView.SelectedRows.Count > 0)
     {
         product_suppliers itemToUpdate = (product_suppliers)Insert_GridView.SelectedRows[0].DataBoundItem;
         if (Package_Product_SupplierDB.Update_info(InsertName, selected.Productname, selected.suppliername, itemToUpdate.Productname, itemToUpdate.Suppliername))
         {
             oldSupplier.Text = itemToUpdate.Suppliername.ToString();
             oldProduct.Text  = itemToUpdate.Productname.ToString();
             MessageBox.Show("Row Updated");
         }
         else
         {
             MessageBox.Show("Fail to Update please contact Administrator");
         }
         //TravelExperts info = new TravelExperts();
         //List_info = Package_Product_SupplierDB.getPackageinfo(InsertName);
         //info.DisplayBox_info(List_info);
     }
     else
     {
         MessageBox.Show("No rows selected.");
     }
 }