public CreateARequier(Product prod, Center ToCenter, int number) { try { CenterTo = ToCenter; Matr = new int[Centers.Count][]; Matr[0] = new int[] { 0, 276, 351, 289 }; Matr[1] = new int[] { 276, 0, 235, 565 }; Matr[2] = new int[] { 351, 235, 0, 632 }; Matr[3] = new int[] { 289, 565, 632, 0 }; controller = new RepositoryController(); CentersObjects = controller.GetDBCenters(); CentersObjects.Remove(ToCenter); CentersWithProducts = new ObservableCollection <Center>(); ProductPosition position; foreach (Center center in CentersObjects) { position = controller.GetDBCenterProductsPosition(center).Where(p => p.product.Id == prod.Id).Where(pp => pp.numberOfProduct >= number).FirstOrDefault(); if (position != null && center.CenterName != ToCenter.CenterName) { CentersWithProducts.Add(center); } } if (CentersWithProducts.Count != 0) { CenterFrom = CentersWithProducts[0]; for (int i = 0; i < CentersWithProducts.Count; i++) { if (GetDistance(CentersWithProducts[i]) < GetDistance(CenterFrom)) { CenterFrom = CentersWithProducts[i]; } } } else { throw new Exception("Ни в одном центре нет такого количества товаров"); } //Создать заказ и отправить в БД requier = new Require(number, prod, CenterTo, CenterFrom); OpenCloseOrder.GetInstance(EmployeeWindow.GetInstance().employe).Requiers.Add(requier); } catch (Exception e) { MessageBox.Show(e.Message); } }
public void Execute() { //OpenCloseOrder.GetInstance(employee).Requiers.Clear(); OpenCloseOrder.GetInstance(employee).Requiers.Add(controller.GetDBRequiersTo(employee.center)[controller.GetDBRequiersTo(employee.center).Count - 1]); }