Ejemplo n.º 1
0
        //-------------------REMOVE OR DELETE ProductsSupplier --------------------------------------------------

        private void btnRemove_Click_1(object sender, EventArgs e)
        {
            selectedProductsSupplier = context.ProductsSuppliers.Find(selected_ProductsSupplierID);

            DialogResult result = MessageBox.Show($"Are you sure you want to delete {selectedProductsSupplier.ProductSupplierId}?",
                                                  "Confirm Delete", MessageBoxButtons.YesNo,
                                                  MessageBoxIcon.Warning);

            if (result == DialogResult.Yes)
            {
                try
                {
                    context.ProductsSuppliers.Remove(selectedProductsSupplier);
                    context.SaveChanges(true);
                    DisplayLVProductsSuppliers();
                }
                //catch (DbUpdateConcurrencyException ex)
                //{
                //    HandleConcurrencyError(ex);
                //}
                catch (DbUpdateException ex)
                {
                    HandleDataError(ex);
                }
                catch (Exception ex)
                {
                    HandleGeneralError(ex);
                }
            }
            ManageControls(false);
        }
Ejemplo n.º 2
0
        //-------------------MODIFY productsSupplier --------------------------------------------------
        private void btnModify_Click_1(object sender, EventArgs e)
        {
            //create second form
            frmAddModifyProdSupp secondForm = new frmAddModifyProdSupp();

            secondForm.isAdd = false;

            secondForm.productsSupplier = context.ProductsSuppliers.Find(selected_ProductsSupplierID);

            DialogResult result = secondForm.ShowDialog();//accept returns ok

            if (result == DialogResult.OK)
            {
                selectedProductsSupplier = secondForm.productsSupplier;
                try
                {
                    context.SaveChanges();
                    DisplayLVProductsSuppliers();
                }
                //catch (DbUpdateConcurrencyException ex)
                //{
                //    HandleConcurrencyError(ex);
                //}
                catch (DbUpdateException ex)
                {
                    HandleDataError(ex);
                }
                catch (Exception ex)
                {
                    HandleGeneralError(ex);
                }
            }

            ManageControls(false);
        }
        private void button1_Click(object sender, EventArgs e)
        {
            ProductsSuppliers info = new ProductsSuppliers();

            info = SuppliersFunctions.GetTwoValues(Convert.ToInt32(relationshipInitial.Text));

            productCurrent.Text  = info.ProdName;
            supplierCurrent.Text = info.SupName;
        }
Ejemplo n.º 4
0
        public static List <ProductsSuppliers> GetRelations()
        {
            string configString = ConfigurationManager.ConnectionStrings["TravelExperts"].ConnectionString;

            List <ProductsSuppliers> Suppliers = new List <ProductsSuppliers>();
            ProductsSuppliers        Sup;
            SqlConnection            con = new SqlConnection(configString);
            string selectQuery           = " select ProductSupplierId, ProductId, SupplierId from dbo.Products_Suppliers";

            SqlCommand cmd = new SqlCommand(selectQuery, con);

            try
            {
                con.Open();
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    Sup = new ProductsSuppliers();
                    Sup.ProductSupplierId = Convert.ToInt32(reader["ProductSupplierId"]);
                    if (reader["ProductId"] == DBNull.Value)
                    {
                        Sup.ProductId = null;
                    }
                    else
                    {
                        Sup.ProductId = Convert.ToInt32(reader["ProductId"]);
                    }

                    if (reader["SupplierId"] == DBNull.Value)
                    {
                        Sup.SupplierId = null;
                    }
                    else
                    {
                        Sup.SupplierId = Convert.ToInt32(reader["SupplierId"]);
                    }
                    //Sup.ProductId = Convert.ToInt32(reader["ProductId"]);
                    //Sup.SupplierId = Convert.ToInt32(reader["SupplierId"]);
                    Suppliers.Add(Sup);
                }
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            finally
            {
                con.Close();
            }
            return(Suppliers);
        }
Ejemplo n.º 5
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            //load productsSupplier data
            if (isAdd)
            {
                productsSupplier = new ProductsSuppliers();
            }

            //packageproductsSupplierID automatically generated and is not modified

            var selectedProduct  = cboProduct.SelectedValue.ToString();
            var selectedSupplier = cboSupplier.SelectedValue.ToString();

            productsSupplier.SupplierId = Convert.ToInt32(selectedSupplier);
            productsSupplier.ProductId  = Convert.ToInt32(selectedProduct);
            //set dialog result to ok
            this.DialogResult = DialogResult.OK;
        }
Ejemplo n.º 6
0
        //-------------------ADD productsSupplier--------------------------------------------------
        private void btnAdd_Click(object sender, EventArgs e)
        {
            //create second form
            frmAddModifyProdSupp addModifySupplier = new frmAddModifyProdSupp();

            addModifySupplier.isAdd            = true;
            addModifySupplier.productsSupplier = null;

            DialogResult result = addModifySupplier.ShowDialog();//accept returns ok

            //if dialogresult is ok, save productsSupplier, and display items in list view
            if (result == DialogResult.OK)
            {
                selectedProductsSupplier    = addModifySupplier.productsSupplier;
                selectedProductsSupplierIds = addModifySupplier.selectedProductsSupplierIds;

                try
                {
                    var newProductsSupplier = context.ProductsSuppliers.Add(selectedProductsSupplier);

                    context.SaveChanges();

                    DisplayLVProductsSuppliers();
                }
                //catch (DbUpdateConcurrencyException ex)
                //{
                //    HandleConcurrencyError(ex);
                //}
                catch (DbUpdateException ex)
                {
                    HandleDataError(ex);
                }
                catch (Exception ex)
                {
                    HandleGeneralError(ex);
                }
            }
        }
Ejemplo n.º 7
0
        public static ProductsSuppliers GetTwoValues(int ProdSupID)
        {
            string configString = ConfigurationManager.ConnectionStrings["TravelExperts"].ConnectionString;

            //List<ProductsSuppliers> InfoList = new List<ProductsSuppliers>();
            ProductsSuppliers info        = new ProductsSuppliers();
            SqlConnection     con         = new SqlConnection(configString);
            string            selectQuery = " select ProdName, SupName from dbo.Products_Suppliers ps " +
                                            "join Products p on ps.ProductId = p.ProductId " +
                                            "join Suppliers s on ps.SupplierId = s.SupplierId " +
                                            "where ProductSupplierId = @ProductSupplierId";

            SqlCommand cmd = new SqlCommand(selectQuery, con);

            cmd.Parameters.AddWithValue("@ProductSupplierId", ProdSupID);

            try
            {
                con.Open();
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    info.ProdName = Convert.ToString(reader["ProdName"]);
                    info.SupName  = Convert.ToString(reader["SupName"]);
                }
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            finally
            {
                con.Close();
            }
            return(info);
        }