//add buttom clicked private void AddButton_Click(object sender, EventArgs e) { string ItemName = this.itemName.Text.Trim(); string Category = category.Text.Trim(); try { double Price = Convert.ToDouble(price.Text); if (ItemName != null && ItemName != "" && Category != null && Category != "" && Price >= 0) { int RowIndex = helper.GetEmptyRowIndex(RecordsGridView); //create new instance of ItemRecords itemRecords = new ItemRecords(ItemName, Category, Price); itemRecords.AddToRecords(RowIndex, RecordsGridView); helper.ClearFields(itemName, price); MessageBox.Show("Record has successfully been added.", "Records Added", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Please fill up all fields properly.", "Fields Invalid", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (FormatException) { MessageBox.Show("Please enter a valid Price.", "Invalid Price", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Clears all the global /// </summary> public static void ClearValues() { AccountingGroups.Clear(); CostProfileGroups.Clear(); CountriesOfOrigin.Clear(); CustomerIdConversions.Clear(); ExternalIdTypes.Clear(); ItemCategories.Clear(); ItemGroups.Clear(); ItemIds.Clear(); ItemIdSuffixes.Clear(); ItemRecords.Clear(); Languages.Clear(); Licenses.Clear(); LocalItemIds.Clear(); MetaDescriptions.Clear(); PricingGroups.Clear(); ProductCategories.Clear(); ProductFormats.Clear(); ProductGoups.Clear(); ProductLines.Clear(); Properties.Clear(); PsStatuses.Clear(); RequestStatus.Clear(); SpecialCharacters.Clear(); TariffCodes.Clear(); Territories.Clear(); ToolTips.Clear(); UpcProductFormatExceptions.Clear(); Upcs.Clear(); UserNames.Clear(); UserRoles.Clear(); WebCategoryList.Clear(); }
//import button clicked private void ImportButton_Click(object sender, EventArgs e) { try { if (fileLocation.Text != null && fileLocation.Text != "") { TextFieldParser csvceader = new TextFieldParser(fileLocation.Text); csvceader.SetDelimiters(new string[] { "," }); while (!csvceader.EndOfData) { string[] rowdata = csvceader.ReadFields(); //create new instance of itemRecords and pass row index and grid to AddToRecords itemRecords = new ItemRecords(rowdata[0], rowdata[1], (Convert.ToDouble(rowdata[2]))); int rowIndex = helper.GetEmptyRowIndex(RecordsGridView); itemRecords.AddToRecords(rowIndex, RecordsGridView); helper.ClearFields(fileLocation); } MessageBox.Show("Records have successfully been imported.", "Records Imported", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("File location not specified.", "No Filepath selected", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { MessageBox.Show("One or more records couldn't be imported. " + ex.Message, "Couldn't import record", MessageBoxButtons.OK, MessageBoxIcon.Error); } }