private void _toolStripMenuItemCreatePurchase_Click(object sender, EventArgs e) { if (_directivesViewer.SelectedItems.Count != 1) { return; } var records = GlobalObjects.CasEnvironment.NewLoader.GetObjectList <RequestForQuotationRecordDTO, RequestForQuotationRecord>(new Filter("ParentPackageId", _directivesViewer.SelectedItem.ItemId)); if (records.Any(i => i.SupplierPrice.Count == 0)) { MessageBox.Show("Please add supplier for all products.", "Message infomation", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } var editForm = new CreatePurchaseOrderForm(_directivesViewer.SelectedItems[0]); if (editForm.ShowDialog() == DialogResult.OK) { MessageBox.Show("Create purchase successful", "Message infomation", MessageBoxButtons.OK, MessageBoxIcon.Information); _directivesViewer.SelectedItems[0].Status = WorkPackageStatus.Published; _directivesViewer.SelectedItems[0].PublishingDate = DateTime.Now; _directivesViewer.SelectedItems[0].PublishedByUser = GlobalObjects.CasEnvironment.IdentityUser.ToString(); _directivesViewer.SelectedItems[0].PublishedById = GlobalObjects.CasEnvironment.IdentityUser.ItemId; GlobalObjects.CasEnvironment.NewKeeper.Save(_directivesViewer.SelectedItems[0]); AnimatedThreadWorker.RunWorkerAsync(); } }
private void _toolStripMenuItemPublish_Click(object sender, EventArgs e) { if (_directivesViewer.SelectedItems.Count == 0) { return; } if (_directivesViewer.SelectedItems[0] is RequestForQuotation) { var editForm = new CreatePurchaseOrderForm(_directivesViewer.SelectedItems[0] as RequestForQuotation); if (editForm.ShowDialog() == DialogResult.OK) { MessageBox.Show("Create purchase successful", "Message infomation", MessageBoxButtons.OK, MessageBoxIcon.Information); foreach (var rfq in _directivesViewer.SelectedItems) { if (rfq.Status == WorkPackageStatus.Published) { MessageBox.Show("Initional Order " + rfq.Title + " is already publisher.", (string)new GlobalTermsProvider()["SystemName"], MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); continue; } rfq.Status = WorkPackageStatus.Published; rfq.PublishingDate = DateTime.Now; rfq.PublishedByUser = GlobalObjects.CasEnvironment.IdentityUser.ToString(); rfq.PublishedById = GlobalObjects.CasEnvironment.IdentityUser.ItemId; GlobalObjects.CasEnvironment.NewKeeper.Save(rfq as BaseEntityObject); SendQuotationOrder(rfq as RequestForQuotation); } } AnimatedThreadWorker.RunWorkerAsync(); } else if (_directivesViewer.SelectedItems[0] is InitialOrder) { var initial = _directivesViewer.SelectedItems[0] as InitialOrder; var quatation = new RequestForQuotation { Parent = initial, ParentType = initial.SmartCoreObjectType, Title = initial.Title, OpeningDate = DateTime.Now, Author = initial.Author, Remarks = initial.Remarks, Number = initial.Number, }; GlobalObjects.CasEnvironment.NewKeeper.Save(quatation); var initialRecords = GlobalObjects.CasEnvironment.NewLoader.GetObjectList <InitialOrderRecordDTO, InitialOrderRecord>(new Filter("ParentPackageId", initial.ItemId)); var ids = initialRecords.Select(i => i.ProductId); if (ids.Count() > 0) { var product = GlobalObjects.CasEnvironment.NewLoader.GetObjectList <AccessoryDescriptionDTO, Product>(new Filter("ItemId", ids)); foreach (var addedInitialOrderRecord in initialRecords) { addedInitialOrderRecord.Product = product.FirstOrDefault(i => i.ItemId == addedInitialOrderRecord.ProductId); } } foreach (var record in initialRecords) { var newquatationRecord = new RequestForQuotationRecord(quatation.ItemId, record.Product, record.Quantity); newquatationRecord.Priority = record.Priority; newquatationRecord.Measure = record.Measure; newquatationRecord.DeferredCategory = record.DeferredCategory; newquatationRecord.CostCondition = record.CostCondition; newquatationRecord.DestinationObjectType = record.DestinationObjectType; newquatationRecord.DestinationObjectId = record.DestinationObjectId; newquatationRecord.Remarks = record.Remarks; newquatationRecord.LifeLimit = new Lifelength(record.LifeLimit); newquatationRecord.LifeLimitNotify = new Lifelength(record.LifeLimitNotify); GlobalObjects.CasEnvironment.Keeper.Save(newquatationRecord); } initial.Status = WorkPackageStatus.Published; initial.PublishingDate = DateTime.Now; initial.PublishedByUser = GlobalObjects.CasEnvironment.IdentityUser.ToString(); initial.PublishedById = GlobalObjects.CasEnvironment.IdentityUser.ItemId; GlobalObjects.CasEnvironment.NewKeeper.Save(initial); var form = new QuatationOrderFormNew(quatation); if (form.ShowDialog() == DialogResult.OK) { MessageBox.Show("Create quatation successful", "Message infomation", MessageBoxButtons.OK, MessageBoxIcon.Information); } AnimatedThreadWorker.RunWorkerAsync(); } else if (_directivesViewer.SelectedItems[0] is PurchaseOrder) { var purch = _directivesViewer.SelectedItem as PurchaseOrder; //var form = new MoveProductForm(purch); //if (form.ShowDialog() == DialogResult.OK) //{ purch.Status = WorkPackageStatus.Published; purch.PublishingDate = DateTime.Now; purch.PublishedByUser = GlobalObjects.CasEnvironment.IdentityUser.ToString(); purch.PublishedById = GlobalObjects.CasEnvironment.IdentityUser.ItemId; GlobalObjects.CasEnvironment.NewKeeper.Save(purch); SendPurchaseOrder(purch); //} AnimatedThreadWorker.RunWorkerAsync(); } }