public static async void WithdrawMoneyAsync(decimal money, Shift shift) //изъ¤тие средств { using (CashboxDataContext db = new CashboxDataContext()) { try { db.DBConnectionCheck(); db.Shifts.Attach(shift); if (shift.CurrentCash >= money) { shift.CurrentCash -= money; shift.CashWithdrawn += money; await db.SaveChangesAsync(); TransactionCompleted?.Invoke(shift, new ShiftTransactionEventArgs("—редства успешно изъ¤ты!", true)); } else { TransactionCompleted?.Invoke(shift, new ShiftTransactionEventArgs("Ќевозможно изъ¤ть введенную сумму, так как в кассе находитс¤ меньше средств, чем требуетс¤", false)); } } catch (Exception e) { TransactionCompleted?.Invoke(shift, new ShiftTransactionEventArgs(e.Message + "\n—редства изъ¤ты не были!", false)); } } }
public override async void ReturnItemAsync(Shift currShift) //асинхронный возврат { using (CashboxDataContext db = new CashboxDataContext()) { try { db.DBConnectionCheck(); Return _return = db.Returns.FirstOrDefault(r => r.SId == currShift.SId && r.IId == this.IId); Item item = db.Items.First(i => i.IId == this.IId); if (_return == null) { db.Returns.Add(new Return(currShift, this)); } else { _return.Number += this.Number; } item.Number += this.Number; db.Shifts.Attach(currShift); currShift.CashReturned += this.Price * this.Number; currShift.CurrentCash -= this.Price * this.Number; await db.SaveChangesAsync(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
public override async void SellItemAsync(Shift currShift) //асинхронная продажа { using (CashboxDataContext db = new CashboxDataContext()) { try { db.DBConnectionCheck(); Sale sale = db.Sales.FirstOrDefault(s => s.SId == currShift.SId && s.IId == this.IId); Item item = db.Items.First(i => i.IId == this.IId); if (sale == null) { db.Sales.Add(new Sale(currShift, this)); } else { sale.Number += this.Number; } item.Number -= this.Number; db.Shifts.Attach(currShift); currShift.CashReceived += this.Price * this.Number; currShift.CurrentCash += this.Price * this.Number; await db.SaveChangesAsync(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
public override async void ReturnItemAsync(Shift currShift) //асинхронный возврат товара { using (CashboxDataContext db = new CashboxDataContext()) { try { db.DBConnectionCheck(); db.Shifts.Attach(currShift); FreeItem fItem = db.FreeItems.First(f => f.SId == currShift.SId); fItem.CashSum -= this.Price * this.Number; currShift.CashReturned += this.Price * this.Number; currShift.CurrentCash -= this.Price * this.Number; await db.SaveChangesAsync(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
public static async void AddMoneyAsync(decimal money, Shift shift) //внесение средств { using (CashboxDataContext db = new CashboxDataContext()) { try { db.DBConnectionCheck(); db.Shifts.Attach(shift); shift.CashAdded += money; shift.CurrentCash += money; await db.SaveChangesAsync(); TransactionCompleted?.Invoke(shift, new ShiftTransactionEventArgs("—редства успешно добавлены!", true)); } catch (Exception e) { TransactionCompleted?.Invoke(shift, new ShiftTransactionEventArgs(e.Message + "\n—редства добавлены не были!", false)); } } }