private void PurchaseItem(object sender, EventArgs args) { try { if (string.IsNullOrEmpty(stationLbl.ClassId) || string.IsNullOrEmpty(productLbl.ClassId) || string.IsNullOrEmpty(qty.Text) || string.IsNullOrEmpty(price.Text)) { Task.Run(async() => await PopupNavigation.Instance.PushAsync(new MessageBox("All fields should be filled", MessageType.Regular, this), true)); } else { if (purchase == null) { purchase = new Models.Purchase { Key = Guid.NewGuid().ToString(), Lotid = (configuration.Purchases.Count() == 0) ? "LotId1" : "LotId" + (Convert.ToInt64(Regex.Match(configuration.Purchases.Last().Lotid, @"\d+$").Value) + 1), DateOfPurchase = DateTime.Now.Date, Farmer = questionaire.Key, ConfigurationId = configuration.OID, CreatedBy = User.Key } } ; purchase.Price = Convert.ToDecimal(price.Text); purchase.Quantity = Convert.ToDecimal(qty.Text); purchase.Product = int.Parse(productLbl.ClassId); purchase.Station = int.Parse(stationLbl.ClassId); purchase.TotalAmount = Convert.ToDecimal(price.Text) * Convert.ToDecimal(qty.Text); var configPurchase = configuration.Purchases.Find(x => x.Key == purchase.Key); if (configPurchase == null) { configuration.Purchases.Add(purchase); } else { configPurchase = purchase; } AiDataStore.SaveConfiguration(configuration); Navigation.RemovePage(this); } } catch (Exception ex) { } }
public Purchase(Models.Purchase purchase = null, Questionaire questionaire = null) { InitializeComponent(); configuration = AiDataStore.GetConfiguration(); this.questionaire = questionaire; this.purchase = purchase; Question qn = questionaire.Sections.FirstOrDefault().Questions.Find(x => x.QuestionText == "Name"); if (qn != null) { name.Text = qn.Answers.FirstOrDefault().AnswerText; } if (purchase != null) { Init(); } }
private async void Sure_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(BookIDBox.Text) || string.IsNullOrEmpty(SaleNumberBox.Text) || string.IsNullOrEmpty(SalePriceBox.Text)) { return; } if (select != null) { int n = int.Parse(SaleNumberBox.Text); float n2 = float.Parse(SalePriceBox.Text); SaleNumberBox.Text = ""; SalePriceBox.Text = ""; if (n > select.Number) { await new MessageDialog("这种书没有多么多了!").ShowAsync(); return; } // 库存记录 if (StockUtil.QueryStock(select.Book.BId.ToString()) == null) { StockViewModel.GetInstance().AddStock(new Models.Stock { Book = select.Book, Number = 0, OfferPrice = select.Price, SalePrice = n2 }); } StockViewModel.GetInstance().UpdateStock(select.Book.BId, n); SupplierStockUtil.UpdateSupplierStock(select.Supplier.SId, select.Book.BId, 0 - n); // 进货记录 Models.Purchase purchase = new Models.Purchase { Book = select.Book, Number = n, Time = DateTimeOffset.Now, Supplier = select.Supplier, Price = select.Price }; PurchaseUtil.AddPurchase(purchase); await new MessageDialog("进货成功了!").ShowAsync(); } else { await new MessageDialog("没有这种书供应,请重新输入书籍编号!").ShowAsync(); } BookIDBox.Text = ""; }
public JsonResult SavePurchase(pharmacy.Models.Purchase p) { bool status = false; if (p != null) { //new purchase object using the data from the viewmodel : PurchaseEntryVM pharmacy.Models.Purchase purchase = new Models.Purchase { ID = p.ID, Date = p.Date, SupplierID = p.SupplierID, Amount = p.Amount, Discount = p.Discount, Tax = p.Tax, GrandTotal = p.GrandTotal, IsPaid = p.IsPaid, Description = p.Description, LastUpdated = DateTime.Now }; purchase.PurchaseItem = new List <PurchaseItem>(); //populating the PurchaseItems from the PurchaseItems within ViewModel : PurchaseEntryVM foreach (var i in p.PurchaseItem) { purchase.PurchaseItem.Add(i); } //add purchase // finally save changes. service.AddPurchaseAndPurchseItems(purchase); service.InsertOrUpdateInventory(p.PurchaseItems); //if everything is sucessful, set status to true. status = true; } // return the status in form of Json return(new JsonResult { Data = new { status = status } }); }