private void SaveButton_Click(object sender, EventArgs e) { if (!Validation.IsAllValid(Detail.Controls)) { return; } using (var repository = new SaleRepository()) { if (saleID > 0) { var sale = repository.GetSale(saleID); sale.Sold = SoldDatePicker.Value.Date; sale.CustomerName = CustomerNameTextBox.Text; repository.UpdateSale(sale); repository.Commit(); saleID = sale.ID; } else { var sale = new Sale { ID = (int)IDTextBox.Text.AsInt(), Sold = SoldDatePicker.Value.Date, CustomerName = CustomerNameTextBox.Text }; repository.InsertSale(sale); repository.Commit(); saleID = sale.ID; } } ViewSaleDetailTab(saleID, false); }
private void AddButton_Click(object sender, EventArgs e) { var productIDs = ProductGrid.SelectedRows.Cast <DataGridViewRow>() .Select(x => (int)x.Cells[ProductGrid_ID.Name].Value.AsInt()) .ToList(); using (var repository = new SaleRepository()) { repository.AddSaleItems(saleID, productIDs); repository.Commit(); } Close(); }
private void RemoveSaleItemButton_Click(object sender, EventArgs e) { var saleItemOrders = SaleItemGrid.SelectedRows.Cast <DataGridViewRow>() .Select(x => (short)x.Cells[SaleItemGrid_Order.Name].Value.AsShort()) .ToList(); using (var repository = new SaleRepository()) { repository.RemoveSaleItems(saleID, saleItemOrders); repository.Commit(); } ViewSaleDetailTab(saleID, true); }
private void SaveSaleItemButton_Click(object sender, EventArgs e) { foreach (DataGridViewRow row in SaleItemGrid.Rows) { short order = (short)row.Cells[SaleItemGrid_Order.Name].Value.AsShort(); using (var repository = new SaleRepository()) { var saleItem = repository.GetSaleItem(saleID, order); saleItem.Quantity = (int)row.Cells[SaleItemGrid_Quantity.Name].Value.AsInt(); repository.UpdateSaleItem(saleItem); repository.Commit(); } } ViewSaleDetailTab(saleID, true); }
private void ApproveButton_Click(object sender, EventArgs e) { DialogResult result; if (IsSaleItemChanged) { result = MessageBox.Show(Resources.SaleApproveUnsavedItemsText.FormatWith(saleID), Resources.SaleApproveConfirmationCaption, MessageBoxButtons.YesNoCancel); switch (result) { case DialogResult.Yes: SaveSaleItemButton_Click(sender, e); break; case DialogResult.Cancel: return; } } else { result = MessageBox.Show(Resources.SaleApproveConfirmationText.FormatWith(saleID), Resources.SaleApproveConfirmationCaption, MessageBoxButtons.YesNo); if (result == DialogResult.No) { return; } } using (var repository = new SaleRepository()) { repository.ApproveSale(saleID); repository.CalculateComponentStockQuantity(saleID); repository.Commit(); } ViewSaleDetailTab(saleID, true); }
/// <summary> /// Sync logic for sale table /// </summary> private void SyncTable_Sale() { var localTable = new SaleRepository<Sale>(_localSessionContext); var remoteTable = new SaleRepository<Sale>(_remoteSessionContext); OnSyncStart?.Invoke(this, new SyncStartedArgs("Sale")); #region SyncCode var count = 0; var total = localTable.Count(); foreach (var row in localTable.GetAll()) { // Find a sync record that matches our related column var recordProduct = _recordRepository.GetByLocalId(row.ProductId, "product_table"); var recordStore = _recordRepository.GetByLocalId(row.StoreId, "store_table"); // Update our related column with the remote ID to prevent reference errors // Update product relation if (recordProduct != null) row.ProductId = recordProduct.Remote_Id; // Update store relation if (recordStore != null) row.StoreId = recordStore.Remote_Id; // Copy object and save (this removes ID) var newObject = ObjectCopy.Copy(row); remoteTable.Save(newObject); // Save changes to remote remoteTable.Commit(); OnUpdateStatus?.Invoke(this, new ProgressEventArgs("Synced entity " + ++count + "/" + total)); // Remove after successful remove localTable.Remove(row); localTable.Commit(); } #endregion }