static void Main(string[] args) { //Create the chain links Approver jennifer = new HeadChef(); Approver mitchell = new PurchasingManager(); Approver olivia = new GeneralManager(); //Create the chain jennifer.SetSupervisor(mitchell); mitchell.SetSupervisor(olivia); // Generate and process purchase requests PurchaseOrder p = new PurchaseOrder(1, 20, 69, "Spices"); jennifer.ProcessRequest(p); p = new PurchaseOrder(2, 300, 1389, "Fresh Veggies"); jennifer.ProcessRequest(p); p = new PurchaseOrder(3, 500, 4823.99, "Beef"); jennifer.ProcessRequest(p); p = new PurchaseOrder(4, 4, 12099, "Ovens"); jennifer.ProcessRequest(p); // Wait for user Console.ReadKey(); }
public static void ChainOfResponsibility() { //Create the chain links Approver jennifer = new HeadChef(); Approver mitchell = new PurchasingManager(); Approver olivia = new GeneralManager(); //Create the chain jennifer.SetSupervisor(mitchell); mitchell.SetSupervisor(olivia); // Generate and process purchase requests PurchaseOrder p = new PurchaseOrder(1, 20, 69, "Spices"); jennifer.ProcessRequest(p); p = new PurchaseOrder(2, 300, 1389, "Fresh Veggies"); jennifer.ProcessRequest(p); p = new PurchaseOrder(3, 500, 4823.99, "Beef"); jennifer.ProcessRequest(p); p = new PurchaseOrder(4, 4, 12099, "Ovens"); jennifer.ProcessRequest(p); }
static void Client() { Approver jordan = new GeneralManager(null); Approver haley = new PurchasingManager(jordan); Approver betsy = new HeadChef(haley); PurchaseOrder po1 = new PurchaseOrder("Spices", 20, 3.50m); betsy.ProcessRequest(po1); Console.WriteLine(po1); PurchaseOrder po2 = new PurchaseOrder("Fresh Veggies", 300, 8); betsy.ProcessRequest(po2); Console.WriteLine(po2); PurchaseOrder po3 = new PurchaseOrder("Beef", 500, 9.23m); betsy.ProcessRequest(po3); Console.WriteLine(po3); PurchaseOrder po4 = new PurchaseOrder("Ovens", 5, 5000.21m); try { betsy.ProcessRequest(po4); } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine(po4); } }
public void TestSelectPurchasingNoCompleteByGoodsId() { _stubPurchasing.SelectPurchasingNoCompleteByGoodsIdGuidListOfGuid = (guid, list) => true; _stubIGoodsInfoSao.GetRealGoodsIdsByGoodsIdGuid = guid => new List <Guid> { new Guid("7AE62AF0-EB1F-49C6-8FD1-128D77C84698") }; _purchasingManager = new PurchasingManager(_stubPurchasing, _stubIGoodsInfoSao, _stubIPurchasingDetail, null, null); var result = _purchasingManager.SelectPurchasingNoCompleteByGoodsId(new Guid("C1F14A7B-3119-4A3B-BDAB-782AC80359BA"), new List <Guid>()); Assert.IsTrue(result); }
public void Init() { _stubPurchasing.GetPurchasingByIdGuid = guid => new PurchasingInfo { PurchasingID = new Guid("7AE62AF0-EB1F-49C6-8FD1-128D77C84698"), PurchasingState = (int)PurchasingState.Purchasing, PurchasingNo = "采购单编号" }; _stubPurchasing.GetPurchasingListDateTimeDateTimeGuidGuidPurchasingStatePurchasingTypeStringGuidGuid = (time, dateTime, arg3, arg4, arg5, arg6, arg7, arg8, arg9) => new List <PurchasingInfo>(); _stubPurchasing.GetPurchasingListDateTimeDateTimeGuidGuidPurchasingStatePurchasingTypeStringListOfGuidGuidGuid = (time, dateTime, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10) => new List <PurchasingInfo>(); _purchasingManager = new PurchasingManager(_stubPurchasing, _stubIGoodsInfoSao, _stubIPurchasingDetail, _companyCussent, _procurementTicketLimitDal); }
public ActionResult Create(PurchasingManager createPurchasingManager) { var CurrentUser = User.Identity.GetUserId(); try { createPurchasingManager.ApplicationUserId = CurrentUser; db.PurchasingManagers.Add(createPurchasingManager); db.SaveChanges(); return(RedirectToAction("Index", "Order")); } catch { return(View()); } }
static void Main(string[] args) { #region Publication // Create a list of books to be published, including cover type and publication cost. var books = new List <Book> { new Book("The Stand", "Stephen King", CoverType.Paperback, 35000), new Book("The Hobbit", "J.R.R. Tolkien", CoverType.Paperback, 25000), new Book("The Name of the Wind", "Patrick Rothfuss", CoverType.Digital, 7500), new Book("To Kill a Mockingbird", "Harper Lee", CoverType.Hard, 65000), new Book("1984", "George Orwell", CoverType.Paperback, 22500), new Book("Jane Eyre", "Charlotte Brontë", CoverType.Hard, 82750) }; // Create specifications for individual cover types. var digitalCoverSpec = new Specification <Book>(book => book.CoverType == CoverType.Digital); var hardCoverSpec = new Specification <Book>(book => book.CoverType == CoverType.Hard); var paperbackCoverSpec = new Specification <Book>(book => book.CoverType == CoverType.Paperback); // Create budget spec for cost exceeding $75000. var extremeBudgetSpec = new Specification <Book>(book => book.PublicationCost >= 75000); // Create budget spec for cost between $50000 and $75000. var highBudgetSpec = new Specification <Book>(book => book.PublicationCost >= 50000 && book.PublicationCost < 75000); // Create budget spec for cost between $25000 and $50000. var mediumBudgetSpec = new Specification <Book>(book => book.PublicationCost >= 25000 && book.PublicationCost < 50000); // Create budget spec for cost below $25000. var lowBudgetSpec = new Specification <Book>(book => book.PublicationCost < 25000); // Default spec, always returns true. var defaultSpec = new Specification <Book>(book => true); // Create publication process instance, used to pass Action<T> to Employee instances. var publicationProcess = new PublicationProcess(); // Create employees with various positions. var ceo = new Employee <Book>("Alice", Position.CEO, publicationProcess.PublishBook); var president = new Employee <Book>("Bob", Position.President, publicationProcess.PublishBook); var cfo = new Employee <Book>("Christine", Position.CFO, publicationProcess.PublishBook); var director = new Employee <Book>("Dave", Position.DirectorOfPublishing, publicationProcess.PublishBook); // Default employee, used as successor of CEO and to handle unpublishable books. var defaultEmployee = new Employee <Book>("INVALID", Position.Default, publicationProcess.FailedPublication); // Director can handle digital low budget only. director.SetSpecification(digitalCoverSpec.And(lowBudgetSpec)); // CFO can handle digital/paperbacks that are medium or high budget. cfo.SetSpecification(digitalCoverSpec.Or(paperbackCoverSpec).And(mediumBudgetSpec.Or(highBudgetSpec))); // President can handle all medium/high budget. president.SetSpecification(mediumBudgetSpec.Or(highBudgetSpec)); // CEO can handle all extreme budget. ceo.SetSpecification(extremeBudgetSpec); // Default employee can handle only default specification (all). defaultEmployee.SetSpecification(defaultSpec); // Set chain of responsibility: CEO > President > CFO > Director. director.SetSuccessor(cfo); cfo.SetSuccessor(president); president.SetSuccessor(ceo); ceo.SetSuccessor(defaultEmployee); // Loop through books, trying to publish, starting at bottom of chain of responsibility (Director). books.ForEach(book => director.PublishBook(book)); #endregion // TODO => Add specification pattern here. #region Restaurant //Create the chain links Approver jennifer = new HeadChef(); Approver mitchell = new PurchasingManager(); Approver olivia = new GeneralManager(); //Create the chain jennifer.SetSupervisor(mitchell); mitchell.SetSupervisor(olivia); // Generate and process purchase requests PurchaseOrder p = new PurchaseOrder(1, 20, 69, "Spices"); jennifer.ProcessRequest(p); p = new PurchaseOrder(2, 300, 1389, "Fresh Veggies"); jennifer.ProcessRequest(p); p = new PurchaseOrder(3, 500, 4823.99, "Beef"); jennifer.ProcessRequest(p); p = new PurchaseOrder(4, 4, 12099, "Ovens"); jennifer.ProcessRequest(p); #endregion // Wait for user Console.ReadKey(); }
/// <summary>Grid操作 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void SemiStockGrid_OnItemCommand(object sender, GridCommandEventArgs e) { var item = e.Item as GridDataItem; if (item != null) { var dataItem = item; var stockId = new Guid(dataItem.GetDataKeyValue("StockId").ToString()); var storageInfo = _storageRecordDao.GetStorageRecord(stockId); //作废 if (e.CommandName == "Cancellation") { #region --> Cancellation var personnelInfo = CurrentSession.Personnel.Get(); if (storageInfo.StockType == (int)StorageRecordType.BorrowIn) { string description = "[借入单作废] " + personnelInfo.RealName + "[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "]"; var borrowLendInfo = _borrowLendDao.GetBorrowLendInfo(stockId); if (borrowLendInfo != null) { var outStorageInfo = _storageRecordDao.GetStorageRecord(borrowLendInfo.BorrowLendId); if (outStorageInfo != null) { //作废借入返回单 _storageManager.NewSetStateStorageRecord(outStorageInfo.StockId, StorageRecordState.Canceled, description); } } //作废借入单 _storageManager.NewSetStateStorageRecord(stockId, StorageRecordState.Canceled, description); //入库单作废操作记录添加 WebControl.AddOperationLog(personnelInfo.PersonnelId, personnelInfo.RealName, stockId, storageInfo.TradeCode, OperationPoint.StorageInManager.Cancel.GetBusinessInfo(), string.Empty); } else { Guid purid = _storageRecordDao.GetStorageRecord(stockId).LinkTradeID; IList <PurchasingDetailInfo> dlist = _purchasingDetail.Select(purid); var purchasingManager = new PurchasingManager(_purchasing, null, null, null, null); using (var ts = new TransactionScope(TransactionScopeOption.Required)) { if (dlist.Count > 0) { bool flag = true; if (dlist.Any(dInfo => dInfo.RealityQuantity >= 1)) { purchasingManager.PurchasingUpdate(purid, PurchasingState.PartComplete); flag = false; } if (flag) { purchasingManager.PurchasingUpdate(purid, PurchasingState.Purchasing); } } string description = "[入库作废] " + CurrentSession.Personnel.Get().RealName + "[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "]"; _storageManager.NewSetStateStorageRecord(stockId, StorageRecordState.Canceled, description); //入库单作废操作记录添加 WebControl.AddOperationLog(personnelInfo.PersonnelId, personnelInfo.RealName, stockId, storageInfo.TradeCode, OperationPoint.StorageInManager.Cancel.GetBusinessInfo(), string.Empty); ts.Complete(); } } #endregion } RAM.ResponseScripts.Add("setTimeout(function(){ refreshGrid(); }, " + GlobalConfig.PageAutoRefreshDelayTime + ");"); } }
// GET: PurchasingManager/Create public ActionResult Create() { PurchasingManager createPurchasingManager = new PurchasingManager(); ; return(View(createPurchasingManager)); }
public void TestPurchaseInProcess() { #region 供应商与公司无绑定 PASS _stubPurchasing.GetPurchasingByIdGuid = guid => new PurchasingInfo { PurchasingID = new Guid("F6B8F8E4-CFE6-44CC-BED0-A73FDF3A5335"), PurchasingState = (int)PurchasingState.Purchasing, PurchasingNo = "PH15010915002", CompanyID = new Guid("368D2C97-2AF3-49DE-897E-0106110A891B") }; _stubPurchasing.GetGoodsAmountListGuid = guid => new List <PurchasingGoodsAmountInfo> { new PurchasingGoodsAmountInfo { AmountPrice = 800, GoodsCode = "KD180502", IsOut = true, PurchasingFilialeId = new Guid("7AE62AF0-EB1F-49C6-8FD1-128D77C84698"), PurchasingId = new Guid("F6B8F8E4-CFE6-44CC-BED0-A73FDF3A5335") } }; _purchasingManager.PurchaseInProcess(Guid.NewGuid()); Assert.IsTrue(true); #endregion #region 供应商和公司有绑定 可是没有设置采购额度 PASS _purchasingManager = new PurchasingManager(_stubPurchasing, _stubIGoodsInfoSao, _stubIPurchasingDetail, _companyCussent, _procurementTicketLimitDal); _stubPurchasing.GetPurchasingByIdGuid = guid => new PurchasingInfo { PurchasingID = new Guid("F6B8F8E4-CFE6-44CC-BED0-A73FDF3A5335"), PurchasingState = (int)PurchasingState.Purchasing, PurchasingNo = "PH15010915002", CompanyID = new Guid("2729D339-8F6A-4224-941A-0D1E337D0818") }; _purchasingManager.PurchaseInProcess(Guid.NewGuid()); Assert.IsTrue(true); #endregion #region 供应商和公司绑定 且 绑定一个公司的采购额度设置 开票与不开票 PASS _stubPurchasing.GetPurchasingByIdGuid = guid => new PurchasingInfo { PurchasingID = new Guid("F6B8F8E4-CFE6-44CC-BED0-A73FDF3A5335"), PurchasingState = (int)PurchasingState.Purchasing, PurchasingNo = "PH15010915002", CompanyID = new Guid("6D713C0F-26E4-4DD6-B7E2-143AA1B09F1C") }; _purchasingManager = new PurchasingManager(_stubPurchasing, _stubIGoodsInfoSao, _stubIPurchasingDetail, _companyCussent, _procurementTicketLimitDal); _purchasingManager.PurchaseInProcess(Guid.NewGuid()); Assert.IsTrue(true); _purchasingManager = new PurchasingManager(_stubPurchasing, _stubIGoodsInfoSao, _stubIPurchasingDetail, _companyCussent, _procurementTicketLimitDal); _purchasingManager.PurchaseInProcess(Guid.NewGuid()); Assert.IsTrue(true); #endregion #region 采购公司绑定多个公司 或者 有设置多个额度 _stubPurchasing.GetPurchasingByIdGuid = guid => new PurchasingInfo { PurchasingID = new Guid("F6B8F8E4-CFE6-44CC-BED0-A73FDF3A5335"), PurchasingState = (int)PurchasingState.Purchasing, PurchasingNo = "PH15010915002", CompanyID = new Guid("7B03EBDE-5214-4A07-845A-2ED73309AC1A") }; // //所有额度大于采购额度 PASS _stubPurchasing.GetGoodsAmountListGuid = guid => new List <PurchasingGoodsAmountInfo> { new PurchasingGoodsAmountInfo { AmountPrice = 100, GoodsCode = "KD180502", IsOut = true, PurchasingFilialeId = new Guid("7AE62AF0-EB1F-49C6-8FD1-128D77C84698"), PurchasingId = new Guid("F6B8F8E4-CFE6-44CC-BED0-A73FDF3A5335") } }; _purchasingManager = new PurchasingManager(_stubPurchasing, _stubIGoodsInfoSao, _stubIPurchasingDetail, _companyCussent, _procurementTicketLimitDal); _purchasingManager.PurchaseInProcess(Guid.NewGuid()); Assert.IsTrue(true); //至少有一个采购额度>设置额度 PASS _stubPurchasing.GetGoodsAmountListGuid = guid => new List <PurchasingGoodsAmountInfo> { new PurchasingGoodsAmountInfo { AmountPrice = 800, GoodsCode = "KD180502", IsOut = true, PurchasingFilialeId = new Guid("7AE62AF0-EB1F-49C6-8FD1-128D77C84698"), PurchasingId = new Guid("F6B8F8E4-CFE6-44CC-BED0-A73FDF3A5335") }, new PurchasingGoodsAmountInfo { AmountPrice = 600, GoodsCode = "KD180404", IsOut = true, PurchasingFilialeId = new Guid("7AE62AF0-EB1F-49C6-8FD1-128D77C84698"), PurchasingId = new Guid("F6B8F8E4-CFE6-44CC-BED0-A73FDF3A5335") } }; _purchasingManager = new PurchasingManager(_stubPurchasing, _stubIGoodsInfoSao, _stubIPurchasingDetail, _companyCussent, _procurementTicketLimitDal); _purchasingManager.PurchaseInProcess(Guid.NewGuid()); Assert.IsTrue(true); //所有的设置额度小与采购额度 //a、一个采购商品 PASS _stubPurchasing.GetGoodsAmountListGuid = guid => new List <PurchasingGoodsAmountInfo> { new PurchasingGoodsAmountInfo { AmountPrice = 1500, GoodsCode = "KD180502", IsOut = true, PurchasingFilialeId = new Guid("7AE62AF0-EB1F-49C6-8FD1-128D77C84698"), PurchasingId = new Guid("F6B8F8E4-CFE6-44CC-BED0-A73FDF3A5335") } }; _purchasingManager = new PurchasingManager(_stubPurchasing, _stubIGoodsInfoSao, _stubIPurchasingDetail, _companyCussent, _procurementTicketLimitDal); _purchasingManager.PurchaseInProcess(Guid.NewGuid()); Assert.IsTrue(true); //b、多个采购商品 //有且有一条设置额度大于等于采购额度 PASS _stubPurchasing.GetGoodsAmountListGuid = guid => new List <PurchasingGoodsAmountInfo> { new PurchasingGoodsAmountInfo { AmountPrice = 1000, GoodsCode = "KD180502", IsOut = true, PurchasingFilialeId = new Guid("7AE62AF0-EB1F-49C6-8FD1-128D77C84698"), PurchasingId = new Guid("F6B8F8E4-CFE6-44CC-BED0-A73FDF3A5335") }, new PurchasingGoodsAmountInfo { AmountPrice = 600, GoodsCode = "KD180404", IsOut = true, PurchasingFilialeId = new Guid("7AE62AF0-EB1F-49C6-8FD1-128D77C84698"), PurchasingId = new Guid("F6B8F8E4-CFE6-44CC-BED0-A73FDF3A5335") } }; _purchasingManager = new PurchasingManager(_stubPurchasing, _stubIGoodsInfoSao, _stubIPurchasingDetail, _companyCussent, _procurementTicketLimitDal); _purchasingManager.PurchaseInProcess(Guid.NewGuid()); Assert.IsTrue(true); //所有的采购额度大于设置额度 //必开发票 _stubPurchasing.GetGoodsAmountListGuid = guid => new List <PurchasingGoodsAmountInfo> { new PurchasingGoodsAmountInfo { AmountPrice = 1000, GoodsCode = "RS142503", IsOut = true, PurchasingFilialeId = new Guid("7AE62AF0-EB1F-49C6-8FD1-128D77C84698"), PurchasingId = new Guid("F6B8F8E4-CFE6-44CC-BED0-A73FDF3A5335") }, new PurchasingGoodsAmountInfo { AmountPrice = 1500, GoodsCode = "RS142503", IsOut = true, PurchasingFilialeId = new Guid("7AE62AF0-EB1F-49C6-8FD1-128D77C84698"), PurchasingId = new Guid("F6B8F8E4-CFE6-44CC-BED0-A73FDF3A5335") } }; _stubIPurchasingDetail.SelectGuid = guid => new List <PurchasingDetailInfo> { new PurchasingDetailInfo { GoodsCode = "RS142503" } }; _purchasingManager.PurchaseInProcess(Guid.NewGuid()); Assert.IsTrue(true); //非必开发票 _stubPurchasing.GetPurchasingByIdGuid = guid => new PurchasingInfo { PurchasingID = new Guid("FDF72345-75B1-4E5A-8591-24519923BFE3"), PurchasingState = (int)PurchasingState.Purchasing, PurchasingNo = "PH15010915002", CompanyID = new Guid("7744DEB3-0DCF-4D8B-8B94-8FDB26ABFADF") }; _purchasingManager = new PurchasingManager(_stubPurchasing, _stubIGoodsInfoSao, _stubIPurchasingDetail, _companyCussent, _procurementTicketLimitDal); _purchasingManager.PurchaseInProcess(Guid.NewGuid()); Assert.IsTrue(true); //异常测试 _stubPurchasing.PurchasingInsertPurchasingInfo = guid => { throw new Exception("ces"); }; _purchasingManager.PurchaseInProcess(Guid.NewGuid()); Assert.IsTrue(true); #endregion }
//批量删除 protected void btn_Del_Click(object sender, EventArgs e) { if (Request["ckId"] != null) { IGoodsOrder goodsOrder = new GoodsOrder(GlobalConfig.DB.FromType.Read); var purchasingManager = new PurchasingManager(new Purchasing(GlobalConfig.DB.FromType.Read), _goodsCenterSao, null, null, null); IStorageRecordDao storageRecordDao = new StorageRecordDao(GlobalConfig.DB.FromType.Read); var errorMsg = new StringBuilder(); var goodsIdList = new List <Guid>(); var goodsIdsAndGoodsNamesAndGoodsAuditState = Request["ckId"].Split(','); List <int> stockStates = new List <int> { (int)StorageRecordState.WaitAudit, (int)StorageRecordState.Refuse, (int)StorageRecordState.Refuse, (int)StorageRecordState.Approved, (int)StorageRecordState.Finished }; foreach (var item in goodsIdsAndGoodsNamesAndGoodsAuditState) { var goodsId = new Guid(item.Split('&')[0]); string goodsName = item.Split('&')[1]; if (goodsOrder.SelectSemiStockAtOneYearByGoodsId(goodsId, null, null, 365, stockStates)) { errorMsg.Append("“").Append(goodsName).Append("”该商品1年内有进行过出入库记录,不允许删除!").Append("\\n"); continue; } if (purchasingManager.SelectPurchasingNoCompleteByGoodsId(goodsId, null)) { errorMsg.Append("“").Append(goodsName).Append("”该商品存在未完成的采购单,不允许删除!").Append("\\n"); continue; } if (storageRecordDao.IsExistNormalStorageRecord(goodsId, null)) { errorMsg.Append("“").Append(goodsName).Append("”该商品存在未审核的出入库单据,不允许删除!").Append("\\n"); continue; } if (CacheCollection.Filiale.GetHeadList().Where(f => f.FilialeTypes.Contains((int)FilialeType.EntityShop)).Any(source => StockSao.IsExistGoodsStock(source.ID, goodsId, new List <Guid>()))) { errorMsg.Append("“").Append(goodsName).Append("”此商品门店有库存,不允许删除!").Append("\\n"); continue; } goodsIdList.Add(goodsId); } if (!string.IsNullOrEmpty(errorMsg.ToString())) { MessageBox.Show(this, errorMsg.ToString()); } else { //删除主商品 string errorMessage; var personnel = CurrentSession.Personnel.Get(); var isSuccess = _goodManager.DeleteGoods(goodsIdList, personnel.RealName, personnel.PersonnelId, out errorMessage); if (isSuccess) { MessageBox.AppendScript(this, "setTimeout(function(){ refreshGrid(); }, " + GlobalConfig.PageAutoRefreshDelayTime + ");"); MessageBox.Show(this, "主商品删除成功!"); } else { MessageBox.Show(this, "主商品删除失败!"); } } } else { MessageBox.Show(this, "请选择相关数据!"); } }