public IEnumerable <PurchaseLog> GetPurchaseLogs() { List <PurchaseLog> purchaselogs = new List <PurchaseLog>(); using (var dbConnection = new SqlConnection(Settings.GetConnectionString())) { try { SqlCommand cmd = new SqlCommand("SelectAllPurchaseLogs", dbConnection); cmd.CommandType = CommandType.StoredProcedure; dbConnection.Open(); using (SqlDataReader dr = cmd.ExecuteReader()) { while (dr.Read()) { PurchaseLog purchaselog = new PurchaseLog(); purchaselog.PurchaseLogId = (int)dr["PurchaselogId"]; purchaselog.PurchaseName = dr["PurchaserName"].ToString(); purchaselog.PurchasePrice = (decimal)dr["PurchasePrice"]; purchaselog.SalesPersonId = dr["SalesPersonId"].ToString(); purchaselog.CarId = (int)dr["CarId"]; purchaselog.DateSold = (DateTime)dr["DateSold"]; purchaselog.PurchaseType = dr["PurchaseType"].ToString(); purchaselog.Email = dr["Email"].ToString(); purchaselog.Phone = dr["Phone"].ToString(); purchaselog.AddressOne = dr["AddressOne"].ToString(); purchaselog.AddressTwo = dr["AddressTwo"].ToString(); purchaselog.City = dr["City"].ToString(); purchaselog.ZipCode = dr["ZipCode"].ToString(); purchaselogs.Add(purchaselog); } } return(purchaselogs); } catch (Exception ex) { string errorMessage = String.Format(CultureInfo.CurrentCulture, "Exception Type: {0}, Message: {1}{2}", ex.GetType(), ex.Message, ex.InnerException == null ? String.Empty : String.Format(CultureInfo.CurrentCulture, " InnerException Type: {0}, Message: {1}", ex.InnerException.GetType(), ex.InnerException.Message)); System.Diagnostics.Debug.WriteLine(errorMessage); dbConnection.Close(); } return(purchaselogs); } }
public PurchaseLog addPurchaseLog(PurchaseLog purchaseLog) { Connection con = Connection.getConnection(); con.db.PurchaseLog.Add(purchaseLog); con.db.SaveChanges(); return(purchaseLog); }
/// <summary> /// 编辑仓库 /// </summary> /// <param name="Rid"></param> /// <returns></returns> public ActionResult Edit(int Rid) { var model = new PurchaseLog(); if (Rid > 0) { model = new DALPurchaseLog().GetSinglePurchaseLog(Rid); } return(View(model)); }
public int getLastID() { Connection con = Connection.getConnection(); PurchaseLog purchase = (from p in con.db.PurchaseLog orderby p.purchaseLogID descending select p).FirstOrDefault(); if (purchase == null) { return(0); } return(purchase.purchaseLogID); }
public PurchaseLog createNewPurchaseLog(string title, string desc, DateTime?purchaseDate, int totalPrice) { PurchaseLogMediator mediator = new PurchaseLogMediator(); PurchaseLog purchaseLog = new PurchaseLog(); purchaseLog.purchaseLogID = mediator.getLastID() + 1; purchaseLog.title = title; purchaseLog.description = desc; purchaseLog.purchaseDate = purchaseDate; purchaseLog.totalPrice = totalPrice; return(purchaseLog); }
/// <summary> /// 分页查询 /// </summary> /// <param name="model"></param> /// <param name="currentPage"></param> /// <param name="pageSize"></param> /// <returns></returns> public ActionResult PageList(PurchaseLog model, int currentPage = 1, int pageSize = 20) { int recordCount = 0; List <PurchaseLog> PurchaseLog = new DALPurchaseLog().QueryPagination(currentPage, pageSize, out recordCount, model).ToList(); ViewBag.RecordCount = recordCount; ViewBag.CurrentPage = currentPage; ViewBag.PageSize = pageSize; ViewBag.PageCount = Math.Ceiling((double)recordCount / (double)pageSize); ViewBag.Model = model; return(View(PurchaseLog)); }
// GET: PurchaseLogs/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } PurchaseLog purchaseLog = db.PurchaseLogs.Find(id); if (purchaseLog == null) { return(HttpNotFound()); } return(View(purchaseLog)); }
public ActionResult Create([Bind(Include = "PurchaseLogID,ItemOrderQTY,ItemID,PurchaseOrderID")] PurchaseLog purchaseLog, int id) { if (ModelState.IsValid) { Item items = db.Items.Find(purchaseLog.ItemID); items.ItemQTY = items.ItemQTY + purchaseLog.ItemOrderQTY; purchaseLog.PurchaseOrderID = id; db.PurchaseLogs.Add(purchaseLog); db.SaveChanges(); return(RedirectToAction("AddItems", "PurchaseOrders", new { id = purchaseLog.PurchaseOrderID })); } ViewBag.ItemID = new SelectList(db.Items, "ItemID", "ItemName", purchaseLog.ItemID); ViewBag.PurchaseOrderID = new SelectList(db.PurchaseOrders, "PurchaseOrderID", "PurchaseOrderDesc", purchaseLog.PurchaseOrderID); return(View(purchaseLog)); }
/// <summary> /// 添加/修改保存 /// </summary> /// <param name="model"></param> /// <returns></returns> public ActionResult Save(PurchaseLog model) { ResultMsg msg = new ResultMsg(); //修改 if (model.Rid > 0) { msg = new DALPurchaseLog().Update(model); } //添加 else if (model.Rid == 0) { msg = new DALPurchaseLog().Insert(model); } return(Json(new { Success = msg.Success, Result = msg.ReturnInt, ErrMsg = msg.ErrMsg })); }
public IHttpActionResult DeletePurchaseLog(int id) { PurchaseLog purchaseLog = db.PurchaseLogs.Find(id); if (purchaseLog == null) { return(NotFound()); } db.PurchaseLogs.Remove(purchaseLog); db.SaveChanges(); PurchaseLogDetailsDto response = new PurchaseLogDetailsDto { ID = purchaseLog.ID, Name = purchaseLog.Name, Budgets = purchaseLog.Budgets.Select(x => new BudgetDetailsDto { ID = x.ID, Balance = x.Balance, PurchaseLogID = x.PurchaseLogID }).ToList(), Savings = purchaseLog.Savings.Select(x => new SavingDetailsDto { ID = x.ID, Balance = x.Balance, GoalBalance = x.GoalBalance, Deadline = x.Deadline, Description = x.Description, PurchaseLogID = x.PurchaseLogID }).ToList(), PurchaseItems = purchaseLog.PurchaseItems.Select(x => new PurchaseItemDetailsDto { ID = x.ID, Amount = x.Amount, Date = x.Date, Comment = x.Comment, CategoryID = x.CategoryID, PurchaseLogID = x.PurchaseLogID }).ToList() }; return(Ok(response)); }
public ActionResult Purchase(PurchaseVehicleModel model) { if (ModelState.IsValid) { model.PurchaseViewModel = CreatePurchaseVehicleModel(model.CarId).PurchaseViewModel; model.PurchaseViewModel.Car.IsSold = true; Car car = new Car(); car = model.PurchaseViewModel.Car; _carsRepo.Update(car); PurchaseLog log = new PurchaseLog() { PurchaseName = model.Name, PurchasePrice = model.PurchasePrice, PurchaseType = model.PurchaseType, AddressOne = model.StreetOne, AddressTwo = model.StreetTwo, Phone = model.Phone, Email = model.Email, City = model.City, ZipCode = model.ZipCode, CarId = model.CarId, DateSold = DateTime.Today, SalesPersonId = User.Identity.Name }; _purchaseLogRepository.Insert(log); return(View("PurchaseLogConfirmation", model)); } else { model = CreatePurchaseVehicleModel(model.CarId); return(View("PurchaseView", model)); } }
public IHttpActionResult GetPurchaseLog(int id) { PurchaseLog purchaseLogTmp = db.PurchaseLogs.Find(id); PurchaseLogDetailsDto purchaseLog = new PurchaseLogDetailsDto { ID = purchaseLogTmp.ID, Name = purchaseLogTmp.Name, Budgets = purchaseLogTmp.Budgets.Select(x => new BudgetDetailsDto { ID = x.ID, Balance = x.Balance, PurchaseLogID = x.PurchaseLogID }).ToList(), Savings = purchaseLogTmp.Savings.Select(x => new SavingDetailsDto { ID = x.ID, Balance = x.Balance, GoalBalance = x.GoalBalance, Deadline = x.Deadline, Description = x.Description, PurchaseLogID = x.PurchaseLogID }).ToList(), PurchaseItems = purchaseLogTmp.PurchaseItems.Select(x => new PurchaseItemDetailsDto { ID = x.ID, Amount = x.Amount, Date = x.Date, Comment = x.Comment, CategoryID = x.CategoryID, PurchaseLogID = x.PurchaseLogID }).ToList() }; if (purchaseLog == null) { return(NotFound()); } return(Ok(purchaseLog)); }
public void CanInsertPurchaseLog() { PurchaseLog purchaseLog = new PurchaseLog { PurchaseType = "Bank Finance", PurchaseName = "Purchaser Five", PurchasePrice = 12000.00m, CarId = 2, DateSold = new DateTime(2014, 1, 1), SalesPersonId = "*****@*****.**", AddressOne = "106 Test Road", City = "Gloucester", ZipCode = "23072", Email = "*****@*****.**", Phone = "333-333-3333" }; PurchaseLogRepositoryADO repo = new PurchaseLogRepositoryADO(); repo.Insert(purchaseLog); var purchaseLogs = repo.GetPurchaseLogs().ToList(); Assert.AreEqual(5, purchaseLogs.Count); Assert.AreEqual("Purchaser Five", purchaseLogs[4].PurchaseName); Assert.IsNotNull(purchaseLogs[4].PurchaseLogId); Assert.AreEqual("*****@*****.**", purchaseLogs[4].SalesPersonId); Assert.AreEqual("Gloucester", purchaseLogs[4].City); Assert.AreEqual("106 Test Road", purchaseLogs[4].AddressOne); Assert.IsTrue(String.IsNullOrEmpty(purchaseLogs[4].AddressTwo)); Assert.AreEqual("23072", purchaseLogs[4].ZipCode); Assert.AreEqual("Bank Finance", purchaseLogs[4].PurchaseType); Assert.AreEqual(12000m, purchaseLogs[4].PurchasePrice); Assert.AreEqual(new DateTime(2014, 1, 1), purchaseLogs[4].DateSold); Assert.AreEqual("*****@*****.**", purchaseLogs[4].Email); Assert.AreEqual("333-333-3333", purchaseLogs[4].Phone); Assert.AreEqual(2, purchaseLogs[4].CarId); }
private void submitBtn_Click(object sender, RoutedEventArgs e) { string title = titleTxt.Text.Trim(); string desc = descTxt.Text.Trim(); DateTime?purchaseDate = this.purchaseDate.SelectedDate; string totalPriceStr = totalPriceTxt.Text.Trim(); int totalPrice; bool success = int.TryParse(totalPriceStr, out totalPrice); if (!success) { errorLbl.Text = "Total price must be a number!"; } else if (title == "" || desc == "" || !purchaseDate.HasValue) { errorLbl.Text = "Please input all field!"; } else { PurchaseLogFactory factory = new PurchaseLogFactory(); PurchaseLogMediator mediator = new PurchaseLogMediator(); PurchaseLog purchaseLog = mediator.addPurchaseLog(factory.createNewPurchaseLog(title, desc, purchaseDate, totalPrice)); if (purchaseLog == null) { MessageBox.Show("Add purchase log failed!"); } else { MessageBox.Show("Add purchase log success!"); } this.Close(); } }
public PurchaseLog addPurchaseLog(PurchaseLog purchaseLog) { PurchaseLogRepository repository = new PurchaseLogRepository(); return(repository.addPurchaseLog(purchaseLog)); }
public IHttpActionResult PutPurchaseLog(int id, PurchaseLogDetailsDto purchaseLog) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != purchaseLog.ID) { return(BadRequest()); } PurchaseLog currentPurchaseLog = new PurchaseLog { ID = purchaseLog.ID, Name = purchaseLog.Name, Budgets = purchaseLog.Budgets.Select(x => new Budget { ID = x.ID, Balance = x.Balance, PurchaseLogID = x.PurchaseLogID }).ToList(), Savings = purchaseLog.Savings.Select(x => new Saving { ID = x.ID, Balance = x.Balance, GoalBalance = x.GoalBalance, Deadline = x.Deadline, Description = x.Description, PurchaseLogID = x.PurchaseLogID }).ToList(), PurchaseItems = purchaseLog.PurchaseItems.Select(x => new PurchaseItem { ID = x.ID, Amount = x.Amount, Date = x.Date, Comment = x.Comment, CategoryID = x.CategoryID, PurchaseLogID = x.PurchaseLogID }).ToList() }; db.Entry(purchaseLog).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!PurchaseLogExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
async Task DevCardPurchase() { int maxCards = 2; GameInfo gameInfo = new GameInfo() { YearOfPlenty = maxCards, Knight = maxCards, VictoryPoint = maxCards, Monopoly = maxCards, RoadBuilding = maxCards }; using (var helper = new TestHelper(gameInfo)) { string player = (await helper.CreateGame())[0]; // game is now started // // get enough resources to buy all the cards - 5 * maxCards worth of devcarts var tr = new TradeResources() { Ore = maxCards * 5, Wheat = maxCards * 5, Sheep = maxCards * 5 }; var resources = await helper.GrantResourcesAndAssertResult(player, tr); Assert.Empty(resources.PlayedDevCards); // // buy dev cards for (int i = 0; i < maxCards * 5; i++) { resources = await helper.Proxy.DevCardPurchase(helper.GameName, player); Assert.Equal(maxCards * 5 - i - 1, resources.Ore); Assert.Equal(maxCards * 5 - i - 1, resources.Wheat); Assert.Equal(maxCards * 5 - i - 1, resources.Sheep); Assert.Equal(i + 1, resources.UnplayedDevCards); Assert.Null(helper.Proxy.LastError); Assert.Empty(helper.Proxy.LastErrorString); PurchaseLog purchaseLog = await helper.MonitorGetLastRecord <PurchaseLog>(player); Assert.Equal(CatanAction.Purchased, purchaseLog.Action); Assert.Equal(player, purchaseLog.PlayerName); Assert.Equal(Entitlement.DevCard, purchaseLog.Entitlement); Assert.Null(purchaseLog.UndoRequest); } Assert.Equal(0, resources.Wood); Assert.Equal(0, resources.Wheat); Assert.Equal(0, resources.Sheep); Assert.Equal(0, resources.Brick); Assert.Equal(0, resources.Ore); Assert.Equal(0, resources.GoldMine); // // these are for the "normal" game Assert.Equal(gameInfo.Knight, resources.Knights); Assert.Equal(gameInfo.VictoryPoint, resources.VictoryPoints); Assert.Equal(gameInfo.YearOfPlenty, resources.YearOfPlenty); Assert.Equal(gameInfo.Monopoly, resources.Monopoly); Assert.Equal(gameInfo.RoadBuilding, resources.RoadBuilding); // // try to buy a card w/ no resources resources = await helper.Proxy.DevCardPurchase(helper.GameName, player); Assert.Null(resources); Assert.NotNull(helper.Proxy.LastError); Assert.NotEmpty(helper.Proxy.LastErrorString); Assert.Equal(CatanError.DevCardsSoldOut, helper.Proxy.LastError.Error); // // grant resources for a devcard tr.Ore = tr.Wheat = tr.Sheep = 1; resources = await helper.Proxy.GrantResources(helper.GameName, player, tr); Assert.Equal(1, resources.Ore); Assert.Equal(1, resources.Wheat); Assert.Equal(1, resources.Sheep); Assert.Null(helper.Proxy.LastError); Assert.Empty(helper.Proxy.LastErrorString); var resourceLog = await helper.MonitorGetLastRecord <ResourceLog>(player); // // try to buy when you have resources -- still get an error resources = await helper.Proxy.DevCardPurchase(helper.GameName, player); Assert.Null(resources); Assert.NotNull(helper.Proxy.LastError); Assert.NotEmpty(helper.Proxy.LastErrorString); Assert.Equal(CatanError.DevCardsSoldOut, helper.Proxy.LastError.Error); // // setup to play YoP tr = new TradeResources() { Wood = 1, Brick = 1 }; tr.Brick = 1; for (int i = 0; i < resources.YearOfPlenty; i++) { resources = await helper.Proxy.PlayYearOfPlenty(helper.GameName, player, tr); Assert.NotNull(resources); Assert.Equal(1, resources.Ore); Assert.Equal(1, resources.Wheat); Assert.Equal(1, resources.Sheep); Assert.Equal(i + 1, resources.Wood); Assert.Equal(i + 1, resources.Brick); Assert.Equal(0, resources.GoldMine); } resources = await helper.Proxy.PlayRoadBuilding(helper.GameName, player); Assert.NotNull(resources); resources = await helper.Proxy.PlayRoadBuilding(helper.GameName, player); Assert.NotNull(resources); resources = await helper.Proxy.PlayRoadBuilding(helper.GameName, player); Assert.Equal(CatanError.NoMoreResource, helper.Proxy.LastError.Error); } }
public void Insert(PurchaseLog PurchaseLog) { PurchaseLog.PurchaseLogId = _purchaseLogs.Max(p => p.PurchaseLogId) + 1; _purchaseLogs.Add(PurchaseLog); }
public void Insert(PurchaseLog PurchaseLog) { using (var dbConnection = new SqlConnection(Settings.GetConnectionString())) { try { SqlCommand cmd = new SqlCommand("PurchaseLogInsert", dbConnection); cmd.CommandType = CommandType.StoredProcedure; SqlParameter param = new SqlParameter("@PurchaseLogId", SqlDbType.Int); param.Direction = ParameterDirection.Output; cmd.Parameters.Add(param); cmd.Parameters.AddWithValue("@PurchaserName", PurchaseLog.PurchaseName); cmd.Parameters.AddWithValue("@CarId", PurchaseLog.CarId); cmd.Parameters.AddWithValue("@AddressOne", PurchaseLog.AddressOne); if (String.IsNullOrEmpty(PurchaseLog.AddressTwo)) { cmd.Parameters.AddWithValue("@AddressTwo", DBNull.Value); } else { cmd.Parameters.AddWithValue("@AddressTwo", PurchaseLog.AddressTwo); } if (String.IsNullOrEmpty(PurchaseLog.Phone)) { cmd.Parameters.AddWithValue("@Phone", DBNull.Value); } else { cmd.Parameters.AddWithValue("@Phone", PurchaseLog.Phone); } if (String.IsNullOrEmpty(PurchaseLog.Email)) { cmd.Parameters.AddWithValue("@Email", DBNull.Value); } else { cmd.Parameters.AddWithValue("@Email", PurchaseLog.Email); } cmd.Parameters.AddWithValue("@City", PurchaseLog.City); cmd.Parameters.AddWithValue("@ZipCode", PurchaseLog.ZipCode); cmd.Parameters.AddWithValue("@PurchasePrice", PurchaseLog.PurchasePrice); cmd.Parameters.AddWithValue("@PurchaseType", PurchaseLog.PurchaseType); cmd.Parameters.AddWithValue("@SalesPersonId", PurchaseLog.SalesPersonId); cmd.Parameters.AddWithValue("@DateSold", PurchaseLog.DateSold); dbConnection.Open(); cmd.ExecuteNonQuery(); PurchaseLog.PurchaseLogId = (int)param.Value; } catch (Exception ex) { string errorMessage = String.Format(CultureInfo.CurrentCulture, "Exception Type: {0}, Message: {1}{2}", ex.GetType(), ex.Message, ex.InnerException == null ? String.Empty : String.Format(CultureInfo.CurrentCulture, " InnerException Type: {0}, Message: {1}", ex.InnerException.GetType(), ex.InnerException.Message)); System.Diagnostics.Debug.WriteLine(errorMessage); dbConnection.Close(); } } }
void Awake() { instance = this; }