private void purchaseButtonClick(object sender, EventArgs e) { using (var db = new Model.BudgetModel()) { var purchase = new Purchase(); purchase.DateTime = purchaseDateTimePicker.Value; var selectedSource = purchaseComboBox.SelectedItem as ListBoxItem; if (selectedSource == null) { MessageBox.Show("Выберите источник"); return; } purchase.Source = db.Sources.Find(selectedSource.Id); db.Purchases.Add(purchase); db.SaveChanges(); IdPurchase = purchase.Id; ChekItemForm chekItemForm = new ChekItemForm(IdPurchase); if (chekItemForm.ShowDialog(this) == DialogResult.OK) UpdateDataGrid(); else { db.Purchases.Remove(purchase); db.SaveChanges(); UpdateDataGrid(); } } }
private void AddButtonClick(object sender, RoutedEventArgs e) { using (var db = new Model.BudgetModel()) { var purchase = new Purchase(); purchase.DateTime = purchaseDataTime.SelectedDate.Value; var selectedSource = purchaseCmbBox.SelectedItem as ListBoxItem; if (selectedSource == null) { MessageBox.Show("Выберите источник"); return; } purchase.Source = db.Sources.Find(selectedSource.Id); db.Purchases.Add(purchase); db.SaveChanges(); ChekItemWindow chekItemWindow = new ChekItemWindow(purchase.Id); chekItemWindow.ShowDialog(); } UpdateDataGrid(); }
// Purchases & Sales: public static List<Purchase> GetPurchases(DateTime initialDate, DateTime finalDate) { // Create an empty list of purchases: List<Purchase> purchases = new List<Purchase>(); if (!InitializeCompany()) return purchases; StdBELista purchasesQuery = PriEngine.Engine.Consulta( "SELECT CabecCompras.Id AS CabecComprasId, CabecCompras.Nome AS CabecComprasNome, CabecCompras.Entidade AS CabecComprasEntidade, CabecCompras.Moeda AS CabecComprasMoeda, CabecCompras.DataDoc AS CabecComprasDataDoc, CabecCompras.TipoDoc AS CabecComprasTipoDoc, CabecCompras.DataVencimento AS CabecComprasDataVencimento, CabecCompras.DataDescarga AS CabecComprasDataDescarga, " + "LinhasCompras.Id AS LinhasComprasId, LinhasCompras.PrecoLiquido AS LinhasComprasPrecoLiquido, " + "Artigo.Artigo AS ArtigoId, Artigo.Marca AS ArtigoMarca, Artigo.Modelo AS ArtigoModelo, Artigo.Descricao AS ArticoDescricao, Artigo.TipoArtigo AS ArtigoTipoArtigo, " + "Familias.Familia AS FamiliaId, Familias.Descricao AS FamiliaDescricao, " + "Iva.Taxa AS IvaTaxa " + "FROM CabecCompras " + "INNER JOIN LinhasCompras ON LinhasCompras.IdCabecCompras=CabecCompras.Id " + "INNER JOIN Artigo ON Artigo.Artigo=LinhasCompras.Artigo " + "INNER JOIN Familias ON Artigo.Familia=Familias.Familia " + "INNER JOIN Iva ON LinhasCompras.CodIva = Iva.Iva " + "WHERE CabecCompras.DataDoc >= '" + initialDate.ToString("yyyyMMdd") + "' AND CabecCompras.DataDoc <= '" + finalDate.ToString("yyyyMMdd") + "' " + "ORDER BY CabecCompras.DataDoc" ); while (!purchasesQuery.NoFim()) { Purchase purchase = new Purchase(); // Set values: purchase.ID = purchasesQuery.Valor("LinhasComprasId"); purchase.DocumentDate = ParseDate(purchasesQuery, "CabecComprasDataDoc"); purchase.DocumentType = purchasesQuery.Valor("CabecComprasTipoDoc"); purchase.DueDate = ParseDate(purchasesQuery, "CabecComprasDataVencimento"); purchase.ReceptionDate = ParseDate(purchasesQuery, "CabecComprasDataDescarga"); purchase.SupplierId = purchasesQuery.Valor("CabecComprasEntidade"); purchase.SupplierName = purchasesQuery.Valor("CabecComprasNome"); purchase.Value = new Money(purchasesQuery.Valor("LinhasComprasPrecoLiquido"), purchasesQuery.Valor("CabecComprasMoeda")); purchase.Iva = purchasesQuery.Valor("IvaTaxa") / 100.0; Product product = new Product(); product.Id = purchasesQuery.Valor("ArtigoId"); product.Brand = purchasesQuery.Valor("ArtigoMarca"); product.Model = purchasesQuery.Valor("ArtigoModelo"); product.Description = purchasesQuery.Valor("ArticoDescricao"); product.FamilyId = purchasesQuery.Valor("FamiliaId"); product.FamilyDescription = purchasesQuery.Valor("FamiliaDescricao"); purchase.Product = product; // Add purchase to the list: purchases.Add(purchase); // Next line in the purchase document: purchasesQuery.Seguinte(); } return purchases; }