/// <summary> /// Run through all purchasing that takes place. /// </summary> public void BuyPhase() { // go through each pop in order of priority foreach (var buyer in Populous.PopsByPriority) { // go through their list of needs foreach (var needPair in buyer.TotalNeeds) { // Check that there is stuff that the pop // can trade for goods if (buyer.ForSale.All(x => x.Item2 <= 0)) { break; // if they don't they stop } // get the product and amount var need = needPair.Item1; var desired = needPair.Item2; // the units desired try { // Check if the product is available to buy if (ProductSupply.GetProductValue(need) <= 0) { // if nothing is available, add it to the shortfall. Shortfall.AddProducts(need, desired); continue; // and go to the next need } } catch (KeyNotFoundException) // If it doesn't exist in the supply at all. { // Add it in at 0 ProductSupply.IncludeProduct(need); // Subtract the missing product from shortfall. Shortfall.AddProducts(need, desired); continue; // and skip it here. } // Go to the market and buy what we can. var reciept = BuyGoodsFromMarket(buyer, need, desired); // process our reciept, getting how satisfied our need was. var satisfaction = reciept.GetProductValue(need); // Add satisfaction to our purchased good recorder _purchasedGoods.AddProducts(need, satisfaction); // Remove bought good from supply ProductSupply.SubtractProducts(need, satisfaction); // get the number of goods that couldn't be bought. var shortfall = desired - satisfaction; // add that to shortfall Shortfall.AddProducts(need, shortfall); } } // with all buying done, get surplus supply available by removing bought goods. _surplus.AddProducts(PurchasedGoods.Multiply(-1)); }
public static ProductSupply PopulateProductSupplyFromIDataReader(IDataReader dr) { ProductSupply result = new ProductSupply(); result.ApplyTaxRate = DataRecordHelper.GetDecimal(dr, "ApplyTaxRate"); result.CreateTime = DataRecordHelper.GetDateTime(dr, "CreateTime"); result.CreateUser = DataRecordHelper.GetInt32(dr, "CreateUser"); result.DeliverySpan = DataRecordHelper.GetString(dr, "DeliverySpan"); result.IncludeFreight = (FreightIncludeType?)DataRecordHelper.GetNullableInt32(dr, "IncludeFreight"); result.IncludeTax = (TaxIncludeType)DataRecordHelper.GetInt32(dr, "IncludeTax"); result.ModelID = DataRecordHelper.GetNullableInt32(dr, "ModelID"); result.ProductID = DataRecordHelper.GetInt32(dr, "ProductID"); result.QuoteEnd = DataRecordHelper.GetDateTime(dr, "QuoteEnd"); result.QuoteFrom = DataRecordHelper.GetDateTime(dr, "QuoteFrom"); result.QuoteMOQ = DataRecordHelper.GetNullableInt32(dr, "QuoteMOQ"); result.QuotePrice = DataRecordHelper.GetNullableDecimal(dr, "QuotePrice"); result.QuoteRenewal = DataRecordHelper.GetInt32(dr, "QuoteRenewal"); result.SupplierID = DataRecordHelper.GetInt32(dr, "SupplierID"); result.SupplyID = DataRecordHelper.GetInt32(dr, "SupplyID"); result.SupplyRegion = DataRecordHelper.GetNullableInt32(dr, "SupplyRegion"); result.SupplyStatus = (ComponentStatus)DataRecordHelper.GetInt32(dr, "SupplyStatus"); result.UpdateTime = DataRecordHelper.GetDateTime(dr, "UpdateTime"); result.UpdateUser = DataRecordHelper.GetInt32(dr, "UpdateUser"); result.WarrantySpan = DataRecordHelper.GetString(dr, "WarrantySpan"); return(result); }
protected void egvProducts_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { Product product = e.Row.DataItem as Product; Image productPicture = e.Row.FindControl("ProductPicture") as Image; Literal ltComming = e.Row.FindControl("ltComming") as Literal; if (productPicture != null) { productPicture.ImageUrl = product.GetDefaultImageUrl((int)productPicture.Width.Value, (int)productPicture.Height.Value); } HyperLink hyName = e.Row.FindControl("hlProductName") as HyperLink; Company c = Users.GetUser(product.CreateUser).Company; if (c != null && c.CompanyID != 0) { ProductSupply ps = ProductSupplyManager.GetProductSupply(product.ProductID, c.CompanyID); ltComming.Text = "[<a class=\"navCompany\" href='javascript:{}' onclick=\"showSupply(" + ps.SupplyID + ")\">" + c.CompanyName + "</a>] "; } else { ltComming.Text = "华宏"; } if (hyName != null) { hyName.Text = product.ProductName; hyName.NavigateUrl = GlobalSettings.RelativeWebRoot + "pages/view.aspx?product-product&ID=" + GlobalSettings.Encrypt(product.ProductID.ToString()); } } }
void BindSupply() { int id = int.Parse(Request.QueryString["ID"]); ProductSupply ps = ProductSupplyManager.GetProductSupply(id); Company c = Companys.GetCompany(ps.SupplierID); Area a = Areas.GetArea(c.CompanyRegion); string AN = "--"; if (a != null) { AN = a.RegionName; } ltCompanyName.Text = "<a class=\"navCompany\" href=\"javascript:{}\">[" + c.CompanyName + "]<div class=\"companyDetailsRemark_s\">" + "<div>区域:" + AN + "</div>" + "<div>组织机构代码:" + c.Orgcode + "</div>" + "<div>工商注册号码:" + c.Regcode + "</div>" + "<div>联系电话:" + c.Phone + "</div>" + "<div>公司传真:" + c.Fax + "</div>" + "<div>联系地址:" + c.Address + "</div>" + "<div>邮政编码:" + c.Zipcode + "</div>" + "<div>公司主页:" + c.Website + "</div>" + "</div></a>"; ltFaxRate.Text = ps.ApplyTaxRate.ToString("P2"); dsDeliverySpan.DateSpanValue = ps.DeliverySpan; ltCreateTime.Text = ps.CreateTime.ToShortDateString(); ltCreateUser.Text = Users.GetUser(ps.CreateUser).UserName; ltHasfeight.Text = (ps.IncludeFreight == FreightIncludeType.Include ? "是" : "<span class='needed'>否</span>"); ltIncludeTax.Text = (ps.IncludeTax == TaxIncludeType.Include ? "是" : "<span class='needed'>否</span>"); if (ps.SupplyRegion == null) { ltRegion.Text = "全国"; } else { AN = string.Empty; a = Areas.GetArea(ps.SupplyRegion.Value); if (a != null) { AN = a.RegionName; } ltRegion.Text = a.RegionName; } ltStartTime.Text = ps.QuoteFrom.ToShortDateString(); ltEndTime.Text = ps.QuoteEnd.ToShortDateString(); ltAmount.Text = (ps.QuoteMOQ == null ? "无要求" : ps.QuoteMOQ.Value.ToString()); ltPrice.Text = GlobalSettings.GetPrice(ps.QuotePrice); ltQuoteRenewal.Text = (ps.QuoteRenewal == 0 ? "无" : ps.QuoteRenewal + "月"); dsWS.DateSpanValue = ps.WarrantySpan; ltSupply.Text = (ps.SupplyStatus == ComponentStatus.Enabled ? "是" : "<span class='needed'>否</span>"); }
private static void SaveSupplies(EditProduct editProduct, int productID) { if (editProduct.Supply.Count != 0) { var productSupply = new ProductSupply(); productSupply.ProductID = productID; productSupply.SupplyType = SupplyType.AdminEdit; productSupply.Count = editProduct.Supply.Count; productSupply.Description = editProduct.Supply.Description; ProductSupplies.Insert(productSupply); } }
public void SellPhase() { // Get all goods up for sale. _productSupply = Populous.SellPhase(); // Reset Shortfall to zero. Shortfall = new ProductAmountCollection(); // Fill Surplus preemtively, we'll remove bought products later. _surplus = ProductSupply.Copy(); // While we're at it, also get total demand of all products _productDemand = Populous.TotalDemand(); // And the hypothetical total production available. _productionCapacity = Populous.TotalProduction(); }
public abstract ProductSupply UpdateProductSupply(ProductSupply ps, out DataActionStatus status);
/// <summary> /// 绑定信息 /// </summary> public void BindData() { int productID = Convert.ToInt32(Request.QueryString["ProductID"]); Product product = Products.GetProduct(productID); if (product == null) { throw new HHException(ExceptionType.ProductNotFound); } else { // 根据产品ID和公司ID查找产品供应信息 ProductSupply ps = ProductSupplyManager.GetProductSupply(product.ProductID, Profile.AccountInfo.CompanyID); if (ps == null) { throw new HHException(ExceptionType.ProductSupplyNotFound); } else { // 产品名称 lblProductName.Text = product.ProductName; // TODO: 产品型号 // 最短供货时间 txtDeliverySpan.DateSpanValue = ps.DeliverySpan; // 产品保修期 txtWarrantySpan.DateSpanValue = ps.WarrantySpan; // 供货单价 txtQuotePrice.Text = ps.QuotePrice.HasValue ? ps.QuotePrice.Value.ToString() : string.Empty; // 最小订货量 txtQuoteMOQ.Text = ps.QuoteMOQ.HasValue ? ps.QuoteMOQ.Value.ToString() : string.Empty; // 包含运费 ilIncludeFreight.SelectedValue = ps.IncludeFreight.HasValue ? (PriceIncludeType)ps.IncludeFreight : PriceIncludeType.Include; // 包含税 ilIncludeTax.SelectedValue = (PriceIncludeType)ps.IncludeTax; // 供货税率 txtApplyTaxRate.Text = ps.ApplyTaxRate.ToString(); // 供应区域 if (ps.SupplyRegion.HasValue) { hfRegionCode.Value = ps.SupplyRegion.Value.ToString(); try { Area a = Areas.GetArea(ps.SupplyRegion.Value); txtRegion.Text = a.RegionName; } catch { } } // 报价起始日期 if (ps.QuoteFrom == GlobalSettings.MinValue) { txtQuoteFrom.Text = string.Empty; } else { txtQuoteFrom.Text = ps.QuoteFrom.ToString("yyyy年MM月dd日"); } // 报价截止日期 if (ps.QuoteEnd == GlobalSettings.MaxValue) { txtQuoteEnd.Text = string.Empty; } else { txtQuoteEnd.Text = ps.QuoteEnd.ToString("yyyy年MM月dd日"); } // 报价自动续期周期 txtQuoteRenewal.Text = ps.QuoteRenewal.ToString(); // 是否启用 csSupplyStatus.SelectedValue = ps.SupplyStatus; } } }
protected void btnSave_Click(object sender, EventArgs e) { int productID = Convert.ToInt32(Request.QueryString["ProductID"]); Product product = Products.GetProduct(productID); if (product == null) { throw new HHException(ExceptionType.ProductNotFound); } else { // 根据产品ID和公司ID查找产品供应信息 ProductSupply ps = ProductSupplyManager.GetProductSupply(product.ProductID, Profile.AccountInfo.CompanyID); if (ps == null) { throw new HHException(ExceptionType.ProductSupplyNotFound); } else { // 产品名称 product.ProductName = lblProductName.Text; // TODO: 产品型号 // 最短供货时间 ps.DeliverySpan = txtDeliverySpan.DateSpanValue; // 产品保修期 ps.WarrantySpan = txtWarrantySpan.DateSpanValue; // 供货单价 if (string.IsNullOrEmpty(txtQuotePrice.Text)) { ps.QuotePrice = null; } else { ps.QuotePrice = Convert.ToDecimal(txtQuotePrice.Text); } // 最小订货量 if (string.IsNullOrEmpty(txtQuoteMOQ.Text)) { ps.QuoteMOQ = null; } else { ps.QuoteMOQ = Convert.ToInt32(txtQuoteMOQ.Text); } // 包含运费 ps.IncludeFreight = (FreightIncludeType)ilIncludeFreight.SelectedValue; // 包含税 ps.IncludeTax = (TaxIncludeType)ilIncludeTax.SelectedValue; // 供货税率 ps.ApplyTaxRate = Convert.ToDecimal(txtApplyTaxRate.Text); // 供应区域 int regionID = Convert.ToInt32(hfRegionCode.Value); if (regionID <= 0) { ps.SupplyRegion = null; } else { ps.SupplyRegion = regionID; } // 报价起始日期 ps.QuoteFrom = DateTime.Parse(txtQuoteFrom.Text); // 报价截止日期 ps.QuoteEnd = DateTime.Parse(txtQuoteEnd.Text); // 报价自动续期周期 ps.QuoteRenewal = Convert.ToInt32(txtQuoteRenewal.Text); // 是否启用 ps.SupplyStatus = csSupplyStatus.SelectedValue; // 开始更新 DataActionStatus state = ProductSupplyManager.Update(ps); if (state == DataActionStatus.Success) { throw new HHException(ExceptionType.Success, "修改成功!"); } else { throw new HHException(ExceptionType.Failed, "修改失败,请确认信息是否正确!"); } } } }