private void AddBtn_Click(object sender, EventArgs e) { if (!CanSave()) { return; } /* * if (MyDataGridView.SelectedRows.Count == 0) * { * decimal price = PriceTBox.Value; * int.TryParse(BillIdTbox.Text, out int InvoiceId); * var DR = (DataRowView)this.selectInvoices_ItemsBindingSource.AddNew(); * DR[InvoiceIdCol.DataPropertyName] = InvoiceId; * DR[itemIdCol.DataPropertyName] = ItemCodeCBox.SelectedValue; * DR[BarCodeCol.DataPropertyName] = ItemCodeCBox.Text; * DR[itemNameCol.DataPropertyName] = ItemNameCBox.Text; * DR[QuantityCol.DataPropertyName] = QtyTBox.Value; * DR[PriceCol.DataPropertyName] = price; * DR[TotalPriceCol.DataPropertyName] = Math.Round(price * QtyTBox.Value, 2); * } * MyDataGridView.ClearSelection(); */ selectInvoices_ItemsBindingSource.EndEdit(); MyDataGridView.EndEdit(); AddNewItem(); SetTotals(true); }
private void SaveInvoiceBtn_Click(object sender, EventArgs e) { if (!CanSave()) { return; } else if (MyDataGridView.RowCount < 1) { MessageBox.Show("Please add at least one item!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } selectInvoicesBindingSource.EndEdit(); selectInvoices_ItemsBindingSource.EndEdit(); MyDataGridView.EndEdit(); selectInvoicesTableAdapter.Update(myDataSet.SelectInvoices); selectInvoices_ItemsTableAdapter.Update(myDataSet.SelectInvoices_Items); }