Пример #1
0
        // button to add a product to the supplier
        private void btnProduct_Click(object sender, EventArgs e)
        {
            if (cmbProductBName.IsPresent())
            {
                // for adding a supplier
                if (add)
                {
                    Products_Suppliers product = new Products_Suppliers();
                    product.productid   = (int)cmbProductBName.SelectedValue;
                    product.productName = cmbProductBName.Text;

                    productSuppliers.Add(product);

                    RedisplayList();
                    cmbProductBName.SelectedIndex = -1;
                }
                //for modifing a supplier
                else
                {
                    Products_Suppliers product = new Products_Suppliers();
                    product.productid   = (int)cmbProductBName.SelectedValue;
                    product.productName = cmbProductBName.Text;
                    product.supplierid  = supplier.SupplierId;
                    try
                    {
                        Products_SuppliersDB.AddProdSupp(product);
                        productSuppliers = Products_SuppliersDB.GetAllProdSupOnID(supplierContact.SupplierId);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, ex.GetType().ToString());
                    }
                    RedisplayList();
                    cmbProductBName.SelectedIndex = -1;
                }
            }
        }
Пример #2
0
        // button for accepting the form
        private void btnAccept_Click(object sender, EventArgs e)
        {
            if (txtCName.IsPresent())
            {
                //for add
                if (add)
                {
                    this.createSupplierObjects();
                    try
                    {
                        SupplierDB.AddSupp(supplier);
                        SupplierContactsDB.AddSupp(supplierContact);

                        foreach (Products_Suppliers ps in productSuppliers)
                        {
                            ps.supplierid = supplier.SupplierId;
                            Products_SuppliersDB.AddProdSupp(ps);
                        }

                        this.DialogResult = DialogResult.OK;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, ex.GetType().ToString());
                    }
                }

                // for modify
                else
                {
                    SupplierContacts newSupplierinfo = new SupplierContacts();
                    newSupplierinfo.SupplierContactId = Convert.ToInt32(txtSCID.Text);
                    newSupplierinfo.SupConFirstName   = txtFirst.Text.ToString();
                    newSupplierinfo.SupConLastName    = txtLast.Text.ToString();
                    newSupplierinfo.SupConCompany     = txtCName.Text.ToString();
                    newSupplierinfo.SupConAddress     = txtAddress.Text.ToString();
                    newSupplierinfo.SupConCity        = txtCity.Text.ToString();
                    newSupplierinfo.SupConProv        = txtProv.Text.ToString();
                    newSupplierinfo.SupConPostal      = txtPO.Text.ToString();
                    newSupplierinfo.SupConCountry     = txtCountry.Text.ToString();
                    newSupplierinfo.SupConBusPhone    = txtPhone.Text.ToString();
                    newSupplierinfo.SupConFax         = txtFax.Text.ToString();
                    newSupplierinfo.SupConEmail       = txtEmail.Text.ToString();
                    newSupplierinfo.SupConURL         = txtURL.Text.ToString();
                    newSupplierinfo.AffiliationId     = "";
                    newSupplierinfo.SupplierId        = Convert.ToInt32(txtSCID.Text);

                    try
                    {
                        if (!SupplierContactsDB.UpdateSupplier(supplierContact, newSupplierinfo))
                        {
                            MessageBox.Show("That Supplier has been updated or deleted already.", "Database Error");
                            this.DialogResult = DialogResult.Retry;
                        }
                        else
                        {
                            supplierContact   = newSupplierinfo;
                            this.DialogResult = DialogResult.OK;
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, ex.GetType().ToString());
                    }
                }
            }
        }