private void button1_Click(object sender, EventArgs e) { try { if(!sKUComboBox.Items.Contains(sKUComboBox.Text)) throw new ArgumentException("SKU Does Not Exist."); var countsTable = new InventoryDataSetTableAdapters.CountsTableAdapter(); var count = countTextBox.Text.StartsWith("-") ? countTextBox.Text.Substring(1) : countTextBox.Text; countsTable.Insert(DateTime.Now, sKUComboBox.Text, int.Parse(count), !countTextBox.Text.StartsWith("-"), 1, textBox1.Text); DialogResult = DialogResult.OK; } catch (Exception ex) { MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void RefreshCounts() { foreach (var row in itemsDataGridView.Rows.Cast<DataGridViewRow>().Where(col => col.Cells[1].Value != null)) { var countsTableAdapter = new InventoryDataSetTableAdapters.CountsTableAdapter(); var dataAdd = Total(countsTableAdapter.GetData().Where(rowCount => rowCount.SKU == (string)row.Cells[1].Value && rowCount.Add)); var dataRemove = Total(countsTableAdapter.GetData().Where(rowCount => rowCount.SKU == (string)row.Cells[1].Value && !rowCount.Add)); row.Cells[6].Value = dataAdd - dataRemove; } }