private async Task LoadSales() { using (var scope = new Core.DbScope()) { dataGridView1.DataSource = await Core.InvoiceCore.Instance.GetSalesAsync(scope, DateTime.Today); } }
public async void Init(GoodType goodType) { scope = new DbScope(); goods = await InvoiceCore.Instance.GetGoodsAsync(scope); cmbGoodType.DataSource = goods.Select(g => g.Name).ToList(); cmbGoodType.SelectedItem = goodType.Name; await RebindGridAsync(goodType); cmbGoodType.SelectedIndexChanged += CmbGoodType_SelectedIndexChanged; }
public IEnumerable<Sale> GetSales(DbScope scope, DateTime startDate, DateTime endDate) { startDate = startDate.Date; endDate = endDate.Date.AddDays(1).AddSeconds(-1); if (startDate > endDate) { var t = endDate; endDate = startDate; startDate = t; } return scope.DataProvider.GetSales(startDate, endDate); }
private async void RefreshGrid() { scope.Submit(); scope = new DbScope(); var g = await InvoiceCore.Instance.GetGoodsAsync(scope); if (g == null) { MessageBox.Show("Шото пішло не так. Типи товару не підгрузились."); throw new ArgumentException("goodTypes"); } goodTypes = g.ToList(); GoodTypesLoaded(); }
public MainForm() { InitializeComponent(); this.Text += " " + Application.ProductVersion.ToString(); dateTimePicker1.Value = DateTime.Now; dateTimePicker2.Value = DateTime.Now; scope = new DbScope(); InvoiceCore.Instance.InitializationNotification += Instance_InitializationNotification; GoodTypesLoaded = () => BindGrid(); RefreshGrid(); }
public static Sale ToSale(this SaleParsed s, DbScope scope) { var customer = scope.DataProvider .GetCustomer(c => c.Name == s.Customer); if (customer == null) customer = new Customer() { Name = s.Customer }; return new Sale() { Customer = customer, Producer = s.Producer, DateTime = s.DateTime, GoodType = s.GoodType, Quantity = s.Quantity, Return = s.Return }; }
public IEnumerable<Customer> GetCustomers(DbScope scope) { return scope.DataProvider.GetCustomers(); }
public IEnumerable<Invoice> GetInvoicesByDatesRange(DbScope scope, DateTime startDate, DateTime endDate) { return GenerateInvoices(scope, GetSales(scope, startDate, endDate), Settings.Producer); }
public async Task<IEnumerable<SpecialPrice>> GetSpecialPricesAsync(DbScope scope, bool includeDeleted = false) { return await scope.DataProvider.GetAllAsync<SpecialPrice>(includeDeleted); }
public void ExportToDoc(DbScope scope, DateTime startDate, DateTime endDate, string savePath, string runningPath) { var inv = GetInvoicesByDatesRange(scope, startDate, endDate); if (!inv.Any()) throw new NoSalesException(); SaveInvoices(scope, inv, savePath, runningPath); }
public void SaveInvoices(DbScope scope, IEnumerable<Invoice> invoices, string path, string runningPath) { var generator = new InvoiceGenerator(); generator.CreateInOneDocument(invoices, path, runningPath); }
public void RemoveGoodType(DbScope scope, GoodType good) { scope.DataProvider.Remove(good); }
public void SaveGoodType(DbScope scope, GoodType goodType) { scope.DataProvider.SaveEntity(goodType); }
public IEnumerable<SpecialPrice> GetSpecialPrices(DbScope scope) { return scope.DataProvider.GetSpecialPrices(); }
private IEnumerable<Invoice> GenerateInvoices(DbScope scope, IEnumerable<Sale> sales, string producer) { var list = new List<Invoice>(); var dates = sales.Select(s => s.DateTime).Distinct(); var customers = sales.Select(s => s.Customer).Distinct(); foreach (var d in dates) { foreach (var c in customers) { var salesByCustomer = sales.Where(s => s.Customer.Name == c.Name && s.DateTime.Date == d.Date); if (!salesByCustomer.Any()) continue; var specialPrices =scope.DataProvider.GetSpecialPrices().Where(sp => sp.Customer == c); var invoice = new Invoice(); invoice.Customer = c; invoice.Producer = producer; invoice.DateTime = d; invoice.SoldItems = new List<SoldItem>(); foreach (var s in salesByCustomer) { var qt = (s.Quantity - s.Return) > 0 ? (s.Quantity - s.Return) : 0; var sPrice = specialPrices.FirstOrDefault(sp => sp.GoodType == s.GoodType); invoice.SoldItems.Add(new SoldItem(s.GoodType, qt, sPrice?.Price)); } list.Add(invoice); } } return list; }
public IEnumerable<Sale> ImportSalesFromXLS(DbScope scope, string path, IEnumerable<int> sheets, DateTime dateTime, bool saveToDb = true) { var goods = scope.DataProvider.GetGoods(); var producer = Settings.Producer; var importer = new ExcellImporter(); var sales = importer.ImportFromSheet(path, dateTime, sheets, goods, producer); var result = new List<Sale>(); NewCustomers = 0; foreach (var sale in sales) { var salesByDay = sale.Value.Select(s => s.ToSale(scope)).ToList(); NewCustomers += salesByDay.Count(s => !s.Customer.Id.HasValue); if (saveToDb) scope.DataProvider.AddSales(salesByDay); result.AddRange(salesByDay); } return result; }
private async void toDocButton_Click(object sender, EventArgs e) { var startDate = dateTimePicker1.Value.Date; var endDate = dateTimePicker2.Value.Date; try { scope.Submit(); scope = new DbScope(); var saveDlg = new SaveFileDialog(); saveDlg.Filter = ".docx|*.docx"; if (saveDlg.ShowDialog(this) == System.Windows.Forms.DialogResult.OK) { var runningPath = Application.StartupPath; statusProgress("Генеримо документ...", true); await Task.Run(() => InvoiceCore.Instance.ExportToDoc(scope, startDate, endDate, saveDlg.FileName, runningPath)); statusProgress("Документ готовий", false); return; } } catch (NoSalesException) { MessageBox.Show(string.Format("Немає продаж за {0}-{1}", startDate.ToShortDateString(), endDate.ToShortDateString())); } catch (Exception ex) { ShowErrorBox(ex); } statusProgress("", false); }
public void AddSpecialPrice(DbScope scope, GoodType good, Customer client, double price) { scope.DataProvider.AddSpecialPrice(good, client, price); }
public IEnumerable<Invoice> GenerateInvoicesByDate(DbScope scope, DateTime date) { IEnumerable<Sale> sales = scope.DataProvider.GetSales(date); return GenerateInvoices(scope, sales, Settings.Producer); }
public void ClearSales(DbScope scope) { scope.DataProvider.ClearSales(); }
public IEnumerable<GoodType> GetGoods(DbScope scope) { return scope.DataProvider.GetGoods(); }
public async Task<IEnumerable<Sale>> GetSalesAsync(DbScope scope, DateTime day) { return await scope.DataProvider.GetSalesAsync(day, day); }
public async Task<IEnumerable<GoodType>> GetGoodsAsync(DbScope scope, bool includeDeleted = false) { return await scope.DataProvider.GetAllAsync<GoodType>(includeDeleted); }
private void importButton_Click(object sender, EventArgs e) { try { var sheetDialog = new SelectSheetsDialog(); if (sheetDialog.ShowDialog(this) == System.Windows.Forms.DialogResult.OK) { var inv = InvoiceCore.Instance.ImportSalesFromXLS(scope, sheetDialog.FilePath, sheetDialog.Sheets, sheetDialog.DateTime); MessageBox.Show(string.Format("Імпортовано {0} продажів. {1} нових клієнтів.", inv.Count(), InvoiceCore.Instance.NewCustomers)); scope.Submit(); scope = new DbScope(); } } catch (Exception ex) { ShowErrorBox(ex); } }