private void btnUpdate_Click(object sender, EventArgs e) { if (loggedInAgt == null) { mainForm.btnSignIn_Click(null, null); } else { Supplier supplier = new Supplier(); // declare products List variable and instantiate new List<Supplier> object List <Supplier> suppliers = new List <Supplier>(); suppliers = SupplierDB.GetSuppliers().OrderBy(s => s.SupplierId).ToList(); supplier = suppliers[cmbSuppliers.SelectedIndex]; // check if product to be updated already exists in Products_Suppliers // table and if so, the user may not update it. if (SupplierDB.IsInProductsSuppliers(supplier)) { MessageBox.Show("This supplier is already being used in " + " the Products_Suppliers table and you may not update it."); return; } Supplier newSupplier = new Supplier(); newSupplier.SupplierId = Convert.ToInt32(txtSupplierId.Text); newSupplier.SupName = txtSupplierName.Text; bool result = SupplierDB.UpdateSupplier(supplier, newSupplier); DisplaySuppliers(cmbSuppliers.SelectedIndex); } }
//clicks the button to delete the supplier from the batabase private void btnDeleteSup_Click(object sender, EventArgs e) { DialogResult result = MessageBox.Show("Are you sure?", "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { sup.SupplierId = Convert.ToInt32(txtSupplierId.Text); sup.SupName = cmbSupId.Text; try { if (!SupplierDB.DeleteSupplier(sup)) { MessageBox.Show("Another user has updated or deleted that supplier.", "Database Error"); } else { tabSuppliersDefaultStatus(); } } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } } }
public void LoadProductSupplierList() { suppliers = SupplierDB.GetAllSuppliers(); products_suppliers = ProductSupplierDB.GetProductSuppliers(); var sup = from prod_supp in products_suppliers join supp in suppliers on prod_supp.SupplierId equals supp.SupplierId where prod_supp.ProductId == (int)productIdComboBox.SelectedItem select new { prod_supp.SupplierId, supp.SupName, prod_supp.ProductId, prod_supp.ProductSupplierId }; lvProductSupplier.Items.Clear(); int i = 0; foreach (var s in sup) { lvProductSupplier.Items.Add(s.SupplierId.ToString()); lvProductSupplier.Items[i].SubItems.Add(s.SupName); lvProductSupplier.Items[i].SubItems.Add(s.ProductId.ToString()); lvProductSupplier.Items[i].SubItems.Add(s.ProductSupplierId.ToString()); i++; } }
/// <summary> /// Check the fields to see if values exist, if not display appropriate messageboxes /// Update the database with the edited Supplier name, the supplierID cannot be edited /// </summary> private void btnUpdate_Click(object sender, EventArgs e) { if (cmbSupplierID.Text == "") { MessageBox.Show("Please select a Supplier ID"); } else if ((txtSupName.Text == "") || (txtSupName.Text == "")) { MessageBox.Show("Please enter a Supplier Name"); } else { int supplierID = Convert.ToInt32(cmbSupplierID.Text); txtSupID.Text = Convert.ToString(supplierID); string supName = txtSupName.Text; SupplierDB.UpdateSuppliers(supplierID, supName); RefreshRecords(supplierID); MessageBox.Show("Supplier name has been changed from: " + oldSupName + " to: " + supName); cmbSupplierID.SelectedItem = supplierID; } btnUpdate.Visible = false; btnEditSupplier.Visible = true; lblFeedBack.Text = ""; }
private void btnAddProduct_Click(object sender, EventArgs e) { string message = ""; string messageBoxTitle = ""; if (validaterClass.isProvided(txtAddProductName, "Product Name needs to be provided")) { string addProductName = txtAddProductName.Text; DialogResult dialogResult = MessageBox.Show("Are you sure to create the product with Name - \"" + txtAddProductName.Text + "\"?", "Create/ Update Confirmation", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { SupplierDB ado = new SupplierDB(); try { //Insert Product Name perProduct.AddProduct(addProductName); txtAddProductName.Text = ""; } catch (Exception ex) { message = ex.Message; messageBoxTitle = "Update Supplier Error"; } } } }
/// <summary> /// Jorge: On load, Add or Modify form /// </summary> private void frmAddModifyProdSupplier_Load(object sender, EventArgs e) { //prodId = ProductSupplierDB.GetProductIdsForProdSup(); prodId = ProductDB.GetAllProducts(); productIdComboBox.DataSource = prodId; productIdComboBox.DisplayMember = "ProdName"; productIdComboBox.ValueMember = "ProductId"; //supId = ProductSupplierDB.GetSupplierIdsForProdSup(); supId = SupplierDB.GetAllSuppliers(); supplierIdComboBox.DataSource = supId; supplierIdComboBox.DisplayMember = "SupName"; supplierIdComboBox.ValueMember = "SupplierId"; if (addProductSupplier) // if this is Add { this.Text = "Add Product Supplier"; DisplayCurrentProdSupplier(); } else // modify { this.Text = "Modify Product Supplier"; DisplayCurrentProdSupplier(); } }
private void btnAdd_Click(object sender, EventArgs e) { supplier = new Supplier(); //declares a new supplier object this.PutProductAndSupplierData(supplier); //puts the user inputs into the supplier object try { //tries addeding product to supplier supplier.SupplierID = SupplierDB.AddProductToSupplier(supplier); } catch (Exception ex) //if it fails, throw exception { MessageBox.Show(ex.Message, ex.GetType().ToString()); } //Gets all suppliers for the suppliersList object suppliersList = SupplierDB.GetAllSuppliersForList(); //Gets all products for the products object products = ProductDB.GetAllProducts(); //gets all suppliers for suppliers object suppliers = SupplierDB.GetAllSupplierIDAndName(); //gives the supplierdatagridview to the suppliers object SupplierGrid.DataSource = suppliersList; //gives the productID combobox to the products object productIDComboBox.DataSource = products; //gives the Product Name combobox to the products object prodNameComboBox.DataSource = products; //gives the Supplier Name combobox to the suppliers object supNameComboBox.DataSource = suppliers; //gives the SupplierID combobox to the suppliers object supplierIDComboBox.DataSource = suppliers; }
/// <summary> /// Whenever user selects a Supplier, check if user is allowed to submit. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void cmbSupplier_SelectedIndexChanged(object sender, EventArgs e) { //If we should not over-ride this event, run this code. if (overrideEventSupplier_SelectedIndexChanged == false) { if (cmbSupplier.SelectedItem != null && cmbSupplier.SelectedItem.ToString() != "") { mostRecentlySelectedSupplier = cmbSupplier.SelectedItem.ToString(); cmbSupplier.Items.Clear(); cmbSupplier.Items.Add(mostRecentlySelectedSupplier); } else { mostRecentlySelectedSupplier = ""; cmbSupplier.Items.Clear(); } foreach (string supplier in SupplierDB.GetSuppliersForPPS(cmbProduct.SelectedItem.ToString())) { cmbSupplier.Items.Add(supplier); } overrideEventSupplier_SelectedIndexChanged = true; cmbSupplier.SelectedIndex = 0; isReadyForSubmission(); } //If this event was over-ridden, don't over-ride it next time. else { overrideEventSupplier_SelectedIndexChanged = false; } }
/// <summary> /// Set the fields /// Check to see if the selected supplier ID already exists and whether the fields are empty /// If conditions are met, insert a new supplier with an auto generated ID and specified supplier name into the database /// </summary> private void btnAddSupplier_Click(object sender, EventArgs e) { int supplierID = Convert.ToInt32(txtSupID.Text); string supName = txtSupName.Text; bool SupplierExists = SupplierDB.CheckDataBase(supplierID); if (supName == "" || supName == "") { MessageBox.Show("Please enter a name for the supplier"); cmbSupplierID.SelectedIndex = 0; } else if (SupplierExists == false) { SupplierDB.InsertSupplier(supplierID, supName); MessageBox.Show("Supplier with ID: " + supplierID + " AND Suplier Name: " + supName + " Added"); cmbSupplierID.SelectedItem = cmbSupplierID.Items[cmbSupplierID.Items.Count - 1]; } else { MessageBox.Show("Supplier with ID: " + supplierID + " already exists"); } RefreshRecords(supplierID); DisplaySuppliers(); cmbSupplierID.SelectedItem = supplierID; btnAddSupplier.Visible = false; btnNewSpplier.Visible = true; lblFeedBack.Text = ""; }
//On load event private void frmAddProductsToSuppliers_Load(object sender, EventArgs e) { this.Text = "Add Products to Suppliers"; //names the form when it loads try { //Gets all suppliers for the suppliersList object suppliersList = SupplierDB.GetAllSuppliersForList(); //Gets all products for the products object products = ProductDB.GetAllProducts(); //gets all suppliers for suppliers object suppliers = SupplierDB.GetAllSupplierIDAndName(); //gives the supplierdatagridview to the suppliers object SupplierGrid.DataSource = suppliersList; //gives the productID combobox to the products object productIDComboBox.DataSource = products; //gives the Product Name combobox to the products object prodNameComboBox.DataSource = products; //gives the Supplier Name combobox to the suppliers object supNameComboBox.DataSource = suppliers; //gives the SupplierID combobox to the suppliers object supplierIDComboBox.DataSource = suppliers; } catch (Exception ex) //throws exception if it can't assign data sources { MessageBox.Show("Error while loading Products data: " + ex.Message, ex.GetType().ToString()); } }
private void btnDelete_Click(object sender, EventArgs e) { if (loggedInAgt == null) { mainForm.btnSignIn_Click(null, null); } else { // create Supplier object to be deleted Supplier supplier = new Supplier(); supplier.SupplierId = Convert.ToInt32(txtSupplierId.Text); supplier.SupName = txtSupplierName.Text; if (SupplierDB.IsInProductsSuppliers(supplier)) { MessageBox.Show("This supplier is already being used in " + " the Products_Suppliers table and you may not delete it."); return; } bool result = SupplierDB.DeleteSupplier(supplier); DisplaySuppliers(cmbSuppliers.SelectedIndex - 1); } }
// Next Action Handling - Quynh Nguyen (Queenie) private void btnNextSup_Click(object sender, EventArgs e) { string message = ""; string messageBoxTitle = ""; if (validaterClass.isProvided(txtSupplierName, "The field \"Supplier Name\" must be provided")) { DialogResult dialogResult = MessageBox.Show("Are you sure to create/update the supplier with Name - \"" + txtSupplierName.Text + "\"?", "Create/ Update Confirmation", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) // User wants to insert/ update Supplier { SupplierDB ado = new SupplierDB(); try { if (this.editedSupplier == null || editedSupplier.SupplierId == -1) // insert supplier { editedSupplier = new Supplier(-1, txtSupplierName.Text); messageBoxTitle = "Adding Supplier"; if (ado.InsertSuppliers(editedSupplier)) { message = "The supplier \"" + txtSupplierName.Text + "\" was created sussccefully"; } else { message = "The supplier \"" + txtSupplierName.Text + "\" was not created sussccefully"; } } else //update supplier { editedSupplier.SupName = txtSupplierName.Text; // set new supplier name supplier object messageBoxTitle = "Updating Supplier"; if (ado.UpdateSupplier(editedSupplier)) { message = "The supplier \"" + txtSupplierName.Text + "\" was updated sussccefully"; } else { message = "The supplier \"" + txtSupplierName.Text + "\" was not updated sussccefully"; } } if (!String.IsNullOrEmpty(message)) { MessageBox.Show(message, messageBoxTitle); } } catch (Exception ex) { message = ex.Message; messageBoxTitle = "Update Supplier Error"; } this.Close(); } } }
private void reloadData() { packageList = PackageDB.GetAllPackages(); productsList = ProductDB.GetProducts(); suppliersList = SupplierDB.GetSuppliers(); prodSuppList = ProductsSupplierDB.GetAllProductsSuppliers(); pkgProdSuppList = PackagesProductsSuppliersDB.GetPackagesProductsSuppliers(); }
/// <summary> /// If user is adding a product, the dropdowns should be blank. /// If user is modifying a product, the dropdowns should reflect /// the product user is modifying. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void frmPPSAddModify_Load(object sender, EventArgs e) { foreach (string product in ProductDB.GetAllProducts()) { cmbProduct.Items.Add(product); } //Set form appearance, and update title lable with package name. cmbProduct.DropDownStyle = ComboBoxStyle.DropDownList; cmbSupplier.DropDownStyle = ComboBoxStyle.DropDownList; lblPackageName.Text = "Package: " + mainPackageForm.currentlySelectedPackageName; //If user tries to submit a duplicate record, a message will tell //the user, "STOP, YOU CANNOT SUBMIT THIS." //This message is not required at Form_Load. lblGandalf.Visible = false; //If no product was selected when user launched this form dialog, //then user is adding a product to the package. //If user is adding, clear the combo box selections. if (mainPackageForm.currentlySelectedProductName == "" && mainPackageForm.currentlySelectedSupplierName == "") { isAddAndNotModify = true; btnSubmit.Text = "Add"; cmbProduct.SelectedIndex = 0; cmbSupplier.Enabled = false; } //If user is modifying, have the combo boxes select the product and supplier //user had selected in the Packages form. else { isAddAndNotModify = false; btnSubmit.Text = "Update"; cmbProduct.SelectedItem = mainPackageForm.currentlySelectedProductName; //The currently selected Supplier will probably be in the middle of the combo //box list. When user opens the list on the combo box, it will scroll down //the list to where the currently selected Supplier is. I do not want it //to scroll down. I want user to see the list from the beginning. Therefore, //add the currently selected Supplier to the list before adding the complete //list of suppliers. That way, it will be at the top of the combo box list, //and the list will not have to scroll down to it. cmbSupplier.Items.Clear(); cmbSupplier.Items.Add(mainPackageForm.currentlySelectedSupplierName); foreach (string supplier in SupplierDB.GetSuppliersForPPS(mainPackageForm.currentlySelectedProductName)) { cmbSupplier.Items.Add(supplier); } overrideEventSupplier_SelectedIndexChanged = true; cmbSupplier.SelectedIndex = 0; lblGandalf.Visible = false; } }
private void SupplierName(int forId) { SupplierDB db = new SupplierDB(); Supplier supplier = new Supplier(); supplier = db.SelectById(forId); lblSupplier.Text = Convert.ToString(supplier.Name); }
private void GetHomePageInfo() { List <int> duration = new List <int>(); List <decimal> subCost = new List <decimal>(); int rows, rowDuration, minDuration, maxDuration; decimal minBasePrice, maxBasePrice, rowSubCost; subTotalChecked = checkBox1.Checked; packageList = PackageDB.GetPackages(); rows = packageList.Count; txtPackageCount.Text = rows.ToString(); if (subTotalChecked) { for (int i = 0; i < rows; i++) { rowSubCost = (decimal)packageList[i].PkgBasePrice + (decimal)packageList[i].PkgAgencyCommission; subCost.Add(rowSubCost); } minBasePrice = subCost.Min(); txtMinBasePrice.Text = minBasePrice.ToString("c"); maxBasePrice = subCost.Max(); txtMaxBasePrice.Text = maxBasePrice.ToString("c"); } else { minBasePrice = packageList.Min(r => r.PkgBasePrice); txtMinBasePrice.Text = minBasePrice.ToString("c"); maxBasePrice = packageList.Max(r => r.PkgBasePrice); txtMaxBasePrice.Text = maxBasePrice.ToString("c"); } for (int i = 0; i < rows; i++) { rowDuration = (int)((DateTime)packageList[i].PkgEndDate - (DateTime)packageList[i].PkgStartDate).TotalDays; duration.Add(rowDuration); } minDuration = duration.Min(); txtMinDuration.Text = minDuration.ToString(); maxDuration = duration.Max(); txtMaxDuration.Text = maxDuration.ToString(); supplierList = SupplierDB.GetSuppliers(); txtTotalNumSuppliers.Text = supplierList.Count.ToString(); engagedSuppliers = SupplierDB.GetEngagedSuppliers(); txtEngagedSuppliers.Text = engagedSuppliers.Count.ToString(); productList = ProductDB.GetProducts(); txtTotalNumProducts.Text = productList.Count.ToString(); engagedProducts = ProductDB.GetEngagedProducts(); txtEngagedProducts.Text = engagedProducts.Count.ToString(); }
public static List <Supplier> ListOfSupplier(int page, int pageSize, string searchValue, out int rowCount) { if (page < 1) { page = 1; } rowCount = SupplierDB.Count(searchValue); return(SupplierDB.List(page, pageSize, searchValue)); }
private void btnAdd_Click(object sender, EventArgs e) { if (loggedInAgt == null) { mainForm.btnSignIn_Click(null, null); } else { // declare suppliers List variable and instantiate new List<Supplier> object List <Supplier> suppliers = new List <Supplier>(); // assign suppliers to return of GetSuppliers method call suppliers = SupplierDB.GetSuppliers(); // validate input if (Validator.IsPresent(txtSupplierName)) { if ((txtSupplierName.Text.Length > 255)) { MessageBox.Show("The Supplier Name is too long (>255). Please adjust."); return; } // text boxes validated // now check that the entered Supplier Name does not already exist in the database foreach (Supplier supp in suppliers) { if (txtSupplierName.Text != "" && supp.SupName == txtSupplierName.Text) { MessageBox.Show("The Supplier Name already exists in the database"); return; } } // business logic here is to determine the largest SupplierId in the database // and then assign this value + 1, to the new Supplier entry // Find largest SupplierID int maxId = SupplierDB.FindMaxSupplierId(suppliers); // create Supplier object to be added with new Id Supplier supplier = new Supplier(); supplier.SupplierId = ++maxId; supplier.SupName = txtSupplierName.Text; // problem below because Add Supplier should not return Id bool result = SupplierDB.AddSupplier(supplier); // assign suppliers to return of GetSuppliers method call List <Supplier> newList = SupplierDB.GetSuppliers(); suppliers = newList.OrderBy(s => s.SupplierId).ToList(); // find index of new object in the sorted list int indSorted = SupplierDB.FindIndexofId(suppliers, supplier.SupplierId); // int numSuppliers = suppliers.Count(); DisplaySuppliers(indSorted); } } }
// get the lastest suppliers list private void refreshCmbSupIdItems() { List <Supplier> suppliers; cmbSupId.Items.Clear(); suppliers = SupplierDB.GetAllSuppliers(); // get the latest suppliers' data //add items to the SupId combobox which the displaymember is SupName and valuemember is SupplierID cmbSupId.Items.AddRange(suppliers.ToArray()); //initialize the selected index and the method of cmbSupId_SelectedValueChanged would excute }
private void btnAddSuppProd_Click(object sender, EventArgs e) { Products_Suppliers prodSupp = new Products_Suppliers(); prodSupp.ProductId = Convert.ToInt32(cbProductforCombination.SelectedValue); prodSupp.SupplierId = Convert.ToInt32(cbSupplierIDForCombined.SelectedValue); Products_SuppliersDB.AddProductsSuppliers(prodSupp); lblAddSuppProd.Text = "Supplier/Product Combo has been added"; supplierDataGridView.DataSource = SupplierDB.GetSuppliers(); }
// CARREGA TODOS OS FORNECEDORES NO DDLSUPPLIER private void CarrySupplier() { SupplierDB db = new SupplierDB(); DataSet ds = db.SelectAllActive(); ddlSupplier.DataSource = ds.Tables[0].DefaultView; ddlSupplier.DataTextField = "for_nome"; ddlSupplier.DataValueField = "for_id"; ddlSupplier.DataBind(); ddlSupplier.Items.Insert(0, "Selecione"); }
private void frmSupplierManager_Load_1(object sender, EventArgs e) { btnDeleteSupplier.Visible = false; btnUpdate.Visible = false; btnAddSupplier.Visible = false; suppliers = SupplierDB.GetSuppliers(); dataGrid.DataSource = suppliers; DisplaySuppliers(); cmbSupplierID.SelectedIndex = 0; }
private void productDataGridView_Click(object sender, EventArgs e) { int row, productID; pkgId = selected.PackageId; row = productDataGridView.CurrentRow.Index; productID = (int)productDataGridView.Rows[row].Cells["dataGridViewTextBoxColumn1"].Value; supplierDataGridView.DataSource = SupplierDB.GetSupplierbyPkgProdId(pkgId, productID); }
private void frmSuppliers_Load(object sender, EventArgs e) { // declare suppliers List variable and instantiate new List<Supplier> object List <Supplier> suppliers = new List <Supplier>(); // assign suppliers to return of GetSuppliers nethod call //suppliers = SupplierDB.GetSuppliers(); suppliers = (SupplierDB.GetSuppliers()).OrderBy(s => s.SupplierId).ToList(); // bind suppliers list to combo box cmbSuppliers.DataSource = suppliers; }
/// <summary> /// Danh sách supplier /// </summary> /// <param name="page">trang</param> /// <param name="pageSize">tổng số trang</param> /// <param name="searchValue">giá trị tìm kiếm</param> /// <returns></returns> public static List <Supplier> Suppliers_List(int page, int pageSize, string searchValue) { if (page < 1) { page = 1; } if (pageSize <= 0) { pageSize = 30; } return(SupplierDB.List(page, pageSize, searchValue)); }
//event for if the product combo box selection has changed //display the corresponding supplier for the product private void cbProdName_SelectionChangeCommitted(object sender, EventArgs e) { cbSupName.SelectedValue = -1; List <Supplier> suppliers = new List <Supplier>(); product = new Product(); product.ProductID = (int)cbProdName.SelectedValue; suppliers = SupplierDB.GetSuppliersForProducts(product); cbSupName.DataSource = suppliers; cbSupName.DisplayMember = "SupName"; cbSupName.ValueMember = "SupplierId"; }
/// <summary> /// /// </summary> /// <returns></returns> public static List <Supplier> ListOfSupplier(int page, int pagaSize, string searchValue) { if (page < 1) { page = 1; } if (pagaSize < 0) { pagaSize = 2000; } return(SupplierDB.List(page, pagaSize, searchValue)); }
// INSERE O EMAIL DO FORNCEDOR NO TXTEMAIL private void AddEmail(int id) { if (!hasSupplier()) { return; } SupplierDB db = new SupplierDB(); Supplier supplier = db.SelectById(id); txtEmail.Text = supplier.Email.ToString(); }
private void prodNameComboBox_SelectedValueChanged(object sender, EventArgs e) { ComboBox cmb = (ComboBox)sender; if (cmb.SelectedValue == null) { return; } suppliers = SupplierDB.GetSupplier((int)cmb.SelectedValue); supplierDataGridView.DataSource = suppliers; }
private void frmSupplierAddModify_Load(object sender, EventArgs e) { if (addSupplier)//add button was pressed { this.Text = "Add Supplier"; txtSupplierId.Text = SupplierDB.GetNextSupplierID().ToString();//get next supplier id } else // modify button was pressed { this.Text = "Modify Supplier"; this.DisplaySupplier(); } }