private void Rent() { bool result = true; foreach (var item in ToBeRents) { item.StartDate = DateTime.Now; var rowid = _repo.Add(item); item.Book.AvailableCount -= item.Count; _repoBook.Update(item.Book); SendMsg(new UpdateCountMsg(item.Book)); result &= rowid > 0; if (result) { item.Id = rowid; Rents.Insert(0, item); } } if (result) { Status = string.Format("借出{0}!", result ? "成功" : "失败"); ToBeRents.Clear(); } }
public void AddRent() { if (null == CurrentPerson) { MessageBoxService.Show("请选择借书的人", "提示"); return; } if (null == CurrentBook) { MessageBoxService.Show("请选择要借的书", "提示"); return; } if (null != ToBeRents.FirstOrDefault(e => e.Book == CurrentBook)) { return; } if (CurrentBook.AvailableCount <= 0) { MessageBoxService.Show("这本书已经被借空了", "提示"); return; } var rent = new Rent { Person = CurrentPerson, Book = CurrentBook, StartDate = DateTime.Now, Count = 1, }; ToBeRents.Add(rent); }
public void DelRent() { if (null == ToBeRent || !ToBeRents.Contains(ToBeRent)) { return; } ToBeRents.Remove(ToBeRent); }
public void ConfirmRent() { if (null == CurrentPerson) { MessageBoxService.Show("请选择借书的人", "提示"); return; } if (ToBeRents.Count == 0) { MessageBoxService.Show("请选择要借的书", "提示"); return; } var tmp = ToBeRents.FirstOrDefault(e => e.Count > e.Book.AvailableCount); if (null != tmp) { MessageBoxService.Show(string.Format("[{0}]的数量超出了现有数量", tmp.Book.Name), "提示"); return; } var toRentCount = ToBeRents.Sum(e => e.Count); if (toRentCount + _rentCount > _canRentCount) { MessageBoxService.Show(string.Format("已借出{0}本 + 将借{1}本 > {2}本,每个人在借数量不超过{2}本", _rentCount, toRentCount, _canRentCount), "提示"); return; } var sb = new StringBuilder(); sb.AppendLine(string.Format("[{0}]将借出以下书籍:", CurrentPerson.Name)); foreach (var item in ToBeRents) { sb.AppendLine(string.Format("《{0}》 {1}本", item.Book.Name, item.Count)); } var log = sb.ToString(); sb.AppendLine("是否确认?"); if (MessageBoxService.Show(sb.ToString(), "提示", MessageBoxButton.YesNo) == MessageBoxResult.No) { return; } Rent(); Logger.DebugFormat("借出,{0}", log); }
public void Clear() { CurrentBook = null; ToBeRents.Clear(); QueryRent(); }