Beispiel #1
0
        public SupplyDTO UpdateSupplyInformation(SupplyDTO supply)
        {
            var supplyRepository = new SupplyRepository();
            var supplyId         = supplyRepository.UpdateSupply(supply);

            return(supplyRepository.GetSupplyById(supplyId));
        }
        public SupplyViewModel(SupplyUC view)
        {
            View             = view;
            SupplyRepository = new SupplyRepository();
            Supplies         = SupplyRepository.GetAll();

            Create = new RelayCommand(param => CreateExecute());
            Remove = new RelayCommand(param => RemoveExecute());
        }
Beispiel #3
0
        private void SetRibbonButtons(RibbonMode mode)
        {
            bool isApproved;

            if (supplyID > 0)
            {
                using (var repository = new SupplyRepository())
                {
                    isApproved = repository.GetSupply(supplyID).IsApproved;
                }
            }

            else
            {
                isApproved = false;
            }

            switch (mode)
            {
            case RibbonMode.Listing:
                FilterButton.Enabled        = true;
                NewButton.Enabled           = true;
                EditButton.Enabled          = false;
                SaveButton.Enabled          = false;
                CancelButton.Enabled        = false;
                ApproveButton.Enabled       = false;
                AddSupplyItemButton.Enabled = false;
                break;

            case RibbonMode.Detail:
                FilterButton.Enabled         = false;
                NewButton.Enabled            = false;
                EditButton.Enabled           = !isApproved;
                SaveButton.Enabled           = false;
                CancelButton.Enabled         = false;
                ApproveButton.Enabled        = !isApproved;
                AddSupplyItemButton.Enabled  = !isApproved;
                SaveSupplyItemButton.Enabled = IsSupplyItemChanged;
                break;

            case RibbonMode.Edit:
                FilterButton.Enabled           = false;
                NewButton.Enabled              = false;
                EditButton.Enabled             = false;
                SaveButton.Enabled             = true;
                CancelButton.Enabled           = true;
                ApproveButton.Enabled          = false;
                AddSupplyItemButton.Enabled    = false;
                RemoveSupplyItemButton.Enabled = false;
                SaveSupplyItemButton.Enabled   = false;
                break;
            }
        }
 public CreateSupplyViewModel(SupplyRepository supplyRepository, CreateSupplyWindow view)
 {
     View             = view;
     View.DataContext = this;
     SupplyRepository = supplyRepository;
     CreatedSupply    = new Supply();
     Delivered        = new List <DeliveredToWareHouse>();
     CreateProduct    = new RelayCommand(param => ExecuteCreateProduct());
     Accept           = new RelayCommand(param => ExecuteAccept());
     Time             = DateTime.Now;
     Date             = DateTime.Now;
 }
Beispiel #5
0
        public EventServiceTests()
        {
            DataContext      _DataContext = new DataContext();
            FixedExampleData exampleData  = new FixedExampleData();

            exampleData.GenerateData(_DataContext);
            SaleRepository     _SaleRepository     = new SaleRepository(_DataContext);
            CustomerRepository _CustomerRepository = new CustomerRepository(_DataContext);
            ProductRepository  _ProductRepository  = new ProductRepository(_DataContext);
            SupplyRepository   _SupplyRepository   = new SupplyRepository(_DataContext);

            _EventService = new EventService(_CustomerRepository, _ProductRepository,
                                             _SaleRepository, _SupplyRepository);
        }
Beispiel #6
0
        private void RemoveSupplyItemButton_Click(object sender, EventArgs e)
        {
            var supplyItemOrders = SupplyItemGrid.SelectedRows.Cast <DataGridViewRow>()
                                   .Select(x => (short)x.Cells[SupplyItemGrid_Order.Name].Value.AsShort())
                                   .ToList();

            using (var repository = new SupplyRepository())
            {
                repository.RemoveSupplyItems(supplyID, supplyItemOrders);
                repository.Commit();
            }

            ViewSupplyDetailTab(supplyID, true);
        }
Beispiel #7
0
        private void AddButton_Click(object sender, EventArgs e)
        {
            var componentIDs = ComponentGrid.SelectedRows.Cast <DataGridViewRow>()
                               .Select(x => (int)x.Cells[ComponentGrid_ID.Name].Value.AsInt())
                               .ToList();

            using (var repository = new SupplyRepository())
            {
                repository.AddSupplyItems(supplyID, componentIDs);
                repository.Commit();
            }

            Close();
        }
Beispiel #8
0
        private void FilterButton_Click(object sender, EventArgs e)
        {
            RibbonMode = RibbonMode.Listing;

            var filter = new ComponentFilter
            {
                ComponentTypeID = (FilterComponentTypeDropDown.SelectedValue.AsByte() == 0) ? null : FilterComponentTypeDropDown.SelectedValue.AsByte(),
                Name            = FilterNameTextBox.Text,
                ProductID       = (FilterProductDropDown.SelectedValue.AsInt() == 0) ? null : FilterProductDropDown.SelectedValue.AsInt()
            };

            using (var repository = new SupplyRepository())
            {
                ComponentGrid.DataSource = repository.GetComponentsForPopup(supplyID, filter);
            }
        }
Beispiel #9
0
        private void ViewSupplyDetailTab(int id, bool isSupplyItemIncluded)
        {
            using (var repository = new SupplyRepository())
            {
                if (id > 0)
                {
                    IsWork     = false;
                    RibbonMode = RibbonMode.Detail;

                    ChangeControlsEnabled(DetailTab.Controls, false, false);

                    var supply = repository.GetSupply(id);

                    IDTextBox.Text            = supply.ID.ToString();
                    DeliveredDatePicker.Value = supply.Delivered;
                    SupplierNameTextBox.Text  = supply.SupplierName;
                    DescriptionTextBox.Text   = supply.Description;

                    if (isSupplyItemIncluded)
                    {
                        SupplyItemGrid.DataSource = repository.GetSupplyItems(id);
                        IsSupplyItemChanged       = false;
                        SupplyItemGrid.Enabled    = !supply.IsApproved;
                    }

                    SupplyTabControl.SelectedTab = DetailTab;

                    SupplyItemGrid.ClearSelection();
                }
                else
                {
                    IsWork     = true;
                    RibbonMode = RibbonMode.Edit;

                    ChangeControlsEnabled(DetailTab.Controls, true, true);

                    IDTextBox.Enabled = false;
                    IDTextBox.Text    = repository.GetNextSupplyID().ToString();

                    SupplyTabControl.SelectedTab = DetailTab;
                }
            }
        }
Beispiel #10
0
        private void FilterButton_Click(object sender, EventArgs e)
        {
            var filter = new SupplyFilter
            {
                ID                = FilterIDTextBox.Text.AsInt(),
                SupplierName      = FilterSupplierNameTextBox.Text,
                ComponentID       = (FilterComponentDropDown.SelectedValue.AsInt() == 0) ? null : FilterComponentDropDown.SelectedValue.AsInt(),
                DeliveredFrom     = (FilterDeliveredFromDatePicker.Format == DateTimePickerFormat.Custom) ? null : FilterDeliveredFromDatePicker.Value.Date.AsDateTime(),
                DeliveredTo       = (FilterDeliveredToDatePicker.Format == DateTimePickerFormat.Custom) ? null : FilterDeliveredToDatePicker.Value.Date.AsDateTime(),
                IsNotApprovedOnly = FilterIsNotApprovedOnlyCheckBox.Checked
            };

            using (var repository = new SupplyRepository())
            {
                SupplyGrid.DataSource = repository.GetSupplies(filter);
            }

            SupplyGrid.ClearSelection();
        }
Beispiel #11
0
        private void SaveSupplyItemButton_Click(object sender, EventArgs e)
        {
            foreach (DataGridViewRow row in SupplyItemGrid.Rows)
            {
                short order = (short)row.Cells[SupplyItemGrid_Order.Name].Value.AsShort();

                using (var repository = new SupplyRepository())
                {
                    var supplyItem = repository.GetSupplyItem(supplyID, order);

                    supplyItem.Quantity = (int)row.Cells[SupplyItemGrid_Quantity.Name].Value.AsInt();

                    repository.UpdateSupplyItem(supplyItem);
                    repository.Commit();
                }
            }

            ViewSupplyDetailTab(supplyID, true);
        }
Beispiel #12
0
        private void SaveButton_Click(object sender, EventArgs e)
        {
            if (!Validation.IsAllValid(Detail.Controls))
            {
                return;
            }

            using (var repository = new SupplyRepository())
            {
                if (supplyID > 0)
                {
                    var supply = repository.GetSupply(supplyID);

                    supply.Delivered    = DeliveredDatePicker.Value.Date;
                    supply.SupplierName = SupplierNameTextBox.Text;
                    supply.Description  = DescriptionTextBox.Text;

                    repository.UpdateSupply(supply);
                    repository.Commit();

                    supplyID = supply.ID;
                }
                else
                {
                    var supply = new Supply
                    {
                        ID           = (int)IDTextBox.Text.AsInt(),
                        Delivered    = DeliveredDatePicker.Value.Date,
                        SupplierName = SupplierNameTextBox.Text,
                        Description  = DescriptionTextBox.Text
                    };

                    repository.InsertSupply(supply);
                    repository.Commit();

                    supplyID = supply.ID;
                }
            }

            ViewSupplyDetailTab(supplyID, false);
        }
        private void ExecuteAccept()
        {
            if (Delivered.Count > 0 && Delivered.First().ProductId != 0)
            {
                try
                {
                    Date = Date.Date;
                    Date = Date.AddHours(Time.Hour);
                    Date = Date.AddMinutes(Time.Minute);
                    if (Date > DateTime.Now)
                    {
                        Date = DateTime.Now;
                    }
                    CreatedSupply.Date = Date;
                    CreatedSupply.DeliveredToWareHouse = Delivered;

                    using (ProductRepository productRepository = new ProductRepository())
                    {
                        foreach (var delivered in Delivered)
                        {
                            Product deliveredProduct = productRepository.GetById(delivered.ProductId);
                            deliveredProduct.Amount += delivered.Amount;
                            productRepository.SaveChanges();
                        }
                    }

                    SupplyRepository.Add(CreatedSupply);
                    SupplyRepository.SaveChanges();
                    (View.Owner.DataContext as SupplyViewModel).Update();
                    View.Close();
                }
                catch (Exception)
                {
                    MessageBox.Show("Непредвиденная ошибка");
                }
            }
            else
            {
                MessageBox.Show("Таблица не может быть пустой или содержать нулевые значения");
            }
        }
Beispiel #14
0
        private void ApproveButton_Click(object sender, EventArgs e)
        {
            DialogResult result;

            if (IsSupplyItemChanged)
            {
                result = MessageBox.Show(Resources.SupplyApproveUnsavedItemsText.FormatWith(supplyID), Resources.SupplyApproveConfirmationCaption, MessageBoxButtons.YesNoCancel);

                switch (result)
                {
                case DialogResult.Yes:
                    SaveSupplyItemButton_Click(sender, e);
                    break;

                case DialogResult.Cancel:
                    return;
                }
            }
            else
            {
                result = MessageBox.Show(Resources.SupplyApproveConfirmationText.FormatWith(supplyID), Resources.SupplyApproveConfirmationCaption, MessageBoxButtons.YesNo);

                if (result == DialogResult.No)
                {
                    return;
                }
            }

            using (var repository = new SupplyRepository())
            {
                repository.ApproveSupply(supplyID);
                repository.CalculateComponentStockQuantity(supplyID);
                repository.Commit();
            }

            ViewSupplyDetailTab(supplyID, true);
        }
 private void RemoveExecute()
 {
     SupplyRepository.RemoveById((View.DataSupplies.SelectedItem as Supply).Id);
     SupplyRepository.SaveChanges();
     Update();
 }
        public ResponseDTO UpdateOrderStatus(OrderStatusDTO order)
        {
            try
            {
                var orderRepository         = new OrderRepository();
                var supplyRepository        = new SupplyRepository();
                var productSupplyRepository = new ProductSupplyRepository();
                if (order.OrderStatusId == 3)
                {
                    orderRepository.UpdateOrderStatus(order);
                    return(new ResponseDTO()
                    {
                        Status = 1,
                        Message = "Pedido Rechazado"
                    });
                }
                else
                {
                    var currentoOrder = orderRepository.GetOrder(order.OrderId);
                    if (currentoOrder.OrderStatusId != 1)
                    {
                        return(new ResponseDTO()
                        {
                            Status = 1,
                            Message = "El Pedido ya fue atendido"
                        });
                    }
                    // var currentSupplies = supplyRepository.GetSupplies();

                    var serviceReference = new SupplyServiceReference.SupplyServieClient();
                    var currentSupplies  = serviceReference.ListAllSupplyInformation();

                    var usedSupplies = new List <SupplyDTO>();
                    foreach (var odetail in currentoOrder.OrderDetails)
                    {
                        var supplies = productSupplyRepository.GetSuppliesByProduct(odetail.ProductId);
                        foreach (var supply in supplies)
                        {
                            var csupply = usedSupplies.FirstOrDefault(p => p.SupplyId == supply.SupplyId);
                            if (csupply != null)
                            {
                                csupply.Quantity = csupply.Quantity + supply.Quantity * odetail.Quantity;
                            }
                            else
                            {
                                var newcsupply = new SupplyDTO();
                                newcsupply.SupplyId = supply.SupplyId;
                                newcsupply.Quantity = supply.Quantity * odetail.Quantity;
                                usedSupplies.Add(newcsupply);
                            }
                        }
                    }

                    foreach (var item in usedSupplies)
                    {
                        var csupply = currentSupplies.FirstOrDefault(p => p.SupplyId == item.SupplyId);
                        if (item.Quantity > csupply.Quantity)
                        {
                            order.OrderStatusId = 3;
                            orderRepository.UpdateOrderStatus(order);
                            return(new ResponseDTO()
                            {
                                Status = 1,
                                Message = "Pedido Rechazado Automaticamente por falta de Stock"
                            });
                        }
                    }

                    foreach (var item in usedSupplies)
                    {
                        var csupply = currentSupplies.FirstOrDefault(p => p.SupplyId == item.SupplyId);
                        csupply.Quantity = csupply.Quantity - item.Quantity;
                        //supplyRepository.UpdateSupply(csupply);
                        serviceReference.UpdateSupplyInformation(csupply);
                    }
                    orderRepository.UpdateOrderStatus(order);
                    return(new ResponseDTO()
                    {
                        Status = 1,
                        Message = "Pedido Aprobado"
                    });
                }
            }
            catch (Exception ex)
            {
                return(new ResponseDTO()
                {
                    Status = 0,
                    Message = "A ocurrido un error"
                });
            }
        }
        public StatsViewModel(StatsUC view)
        {
            OrderRepository  = new OrderRepository();
            SupplyRepository = new SupplyRepository();
            View             = view;

            List <Order>  approvedOrders = OrderRepository.FindByPredicate(order => order.State == State.Approved).ToList();
            List <Supply> supplies       = SupplyRepository.GetAll();

            DateTime today    = DateTime.Now.Date;
            DateTime monthAgo = today.AddMonths(-1);

            Plot = new PlotModel();
            Plot.LegendPosition = LegendPosition.TopCenter;
            Plot.Title          = "Статистика за месяц";

            LineSeries income = new LineSeries()
            {
                Color = OxyColor.FromRgb(0, 200, 0), Title = "Доходы"
            };
            LineSeries consumption = new LineSeries()
            {
                Color = OxyColor.FromRgb(200, 0, 0), Title = "Расходы"
            };
            LineSeries profit = new LineSeries()
            {
                Color = OxyColor.FromRgb(200, 150, 0), Title = "Прибыль"
            };
            LineSeries axis = new LineSeries()
            {
                Color = OxyColor.FromRgb(0, 0, 0)
            };

            decimal incomeOfDay      = 0;
            decimal consumptionOfDay = 0;

            Plot.Axes.Add(new DateTimeAxis
            {
                Position        = AxisPosition.Bottom,
                AbsoluteMinimum = DateTimeAxis.ToDouble(monthAgo),
                AbsoluteMaximum = DateTimeAxis.ToDouble(today),
                StringFormat    = "dd MMMM",
                Title           = "Дата",
                TitleFontWeight = OxyPlot.FontWeights.Bold
            });

            Plot.Axes.Add(new LinearAxis
            {
                Position        = AxisPosition.Left,
                Title           = "б.р.",
                TitleFontWeight = OxyPlot.FontWeights.Bold
            });

            for (DateTime date = monthAgo; date <= today; date = date.AddDays(1))
            {
                incomeOfDay += approvedOrders
                               .Where(order => order.Date > date && order.Date <= date.AddDays(1))
                               .Sum(order => order.Ordered.Sum(ordered => ordered.Product.Price * ordered.Amount));

                consumptionOfDay += supplies
                                    .Where(supply => supply.Date > date && supply.Date <= date.AddDays(1))
                                    .Sum(supply => supply.DeliveredToWareHouse.Sum(delivered => delivered.Price * delivered.Amount));

                double incomeDouble      = Convert.ToDouble(incomeOfDay);
                double consumptionDouble = Convert.ToDouble(consumptionOfDay);

                income.Points.Add(new DataPoint(DateTimeAxis.ToDouble(date), incomeDouble));
                consumption.Points.Add(new DataPoint(DateTimeAxis.ToDouble(date), consumptionDouble));
                profit.Points.Add(new DataPoint(DateTimeAxis.ToDouble(date), incomeDouble - consumptionDouble));
                axis.Points.Add(new DataPoint(DateTimeAxis.ToDouble(date), 0));
            }

            Plot.Series.Add(axis);
            Plot.Series.Add(income);
            Plot.Series.Add(consumption);
            Plot.Series.Add(profit);
        }
Beispiel #18
0
        //public SupplyDTO InsertSupplyInformation(SupplyDTO supply)
        //{
        //    var supplyRepository = new SupplyRepository();
        //    return supplyRepository.InsertSupply(supply);
        //}

        public List <SupplyDTO> ListAllSupplyInformation()
        {
            var supplyRepository = new SupplyRepository();

            return(supplyRepository.GetSupplies());
        }
        public TRepository GetRepository <TRepository>(IUnitOfWork unitOfWork)
            where TRepository : class

        {
            //if (typeof(TRepository) == typeof(IResultPaperRepository))
            //{
            //    dynamic repo = new ResultPaperRepository();
            //    repo.UnitOfWork = unitOfWork;
            //    return (TRepository)repo;
            //}

            if (typeof(TRepository) == typeof(IHospitalSuggestionRepository))
            {
                dynamic repo = new HospitalSuggestionRepository();
                repo.UnitOfWork = unitOfWork;
                return((TRepository)repo);
            }
            if (typeof(TRepository) == typeof(ISupplyRepository))
            {
                dynamic repo = new SupplyRepository();
                repo.UnitOfWork = unitOfWork;
                return((TRepository)repo);
            }
            if (typeof(TRepository) == typeof(IAccountRepository))
            {
                dynamic repo = new AccountRepository();
                repo.UnitOfWork = unitOfWork;
                return((TRepository)repo);
            }
            if (typeof(TRepository) == typeof(ILabTestRepository))
            {
                dynamic repo = new LabTestRepository();
                repo.UnitOfWork = unitOfWork;
                return((TRepository)repo);
            }
            if (typeof(TRepository) == typeof(ISampleRepository))
            {
                dynamic repo = new SampleRepository();
                repo.UnitOfWork = unitOfWork;
                return((TRepository)repo);
            }
            if (typeof(TRepository) == typeof(ISampleGroupRepository))
            {
                dynamic repo = new SampleGroupRepository();
                repo.UnitOfWork = unitOfWork;
                return((TRepository)repo);
            }
            if (typeof(TRepository) == typeof(IAppointmentRepository))
            {
                dynamic repo = new AppointmentRepository();
                repo.UnitOfWork = unitOfWork;
                return((TRepository)repo);
            }

            if (typeof(TRepository) == typeof(ISampleGettingRepository))
            {
                dynamic repo = new SampleGettingRepository();
                repo.UnitOfWork = unitOfWork;
                return((TRepository)repo);
            }
            if (typeof(TRepository) == typeof(IEmployeeRepository))
            {
                dynamic repo = new EmployeeRepository();
                repo.UnitOfWork = unitOfWork;
                return((TRepository)repo);
            }

            if (typeof(TRepository) == typeof(ILabTestingIndexRepository))
            {
                dynamic repo = new LabTestingIndexRepository();
                repo.UnitOfWork = unitOfWork;
                return((TRepository)repo);
            }

            if (typeof(TRepository) == typeof(IImportPaperDetailRepository))
            {
                dynamic repo = new ImportPaperDetailRepository();
                repo.UnitOfWork = unitOfWork;
                return((TRepository)repo);
            }
            if (typeof(TRepository) == typeof(IImportPaperRepository))
            {
                dynamic repo = new ImportPaperRepository();
                repo.UnitOfWork = unitOfWork;
                return((TRepository)repo);
            }
            if (typeof(TRepository) == typeof(IExportPaperDetailRepository))
            {
                dynamic repo = new ExportPaperDetailRepository();
                repo.UnitOfWork = unitOfWork;
                return((TRepository)repo);
            }
            if (typeof(TRepository) == typeof(IExportPaperRepository))
            {
                dynamic repo = new ExportPaperRepository();
                repo.UnitOfWork = unitOfWork;
                return((TRepository)repo);
            }
            if (typeof(TRepository) == typeof(IPatientRepository))
            {
                dynamic repo = new PatientRepository();
                repo.UnitOfWork = unitOfWork;
                return((TRepository)repo);
            }
            if (typeof(TRepository) == typeof(ISlotRepository))
            {
                dynamic repo = new SlotRepository();
                repo.UnitOfWork = unitOfWork;
                return((TRepository)repo);
            }
            if (typeof(TRepository) == typeof(ITableRepository))
            {
                dynamic repo = new TableRepository();
                repo.UnitOfWork = unitOfWork;
                return((TRepository)repo);
            }

            if (typeof(TRepository) == typeof(IFeedbackRepository))
            {
                dynamic repo = new FeedbackRepository();
                repo.UnitOfWork = unitOfWork;
                return((TRepository)repo);
            }

            if (typeof(TRepository) == typeof(ILabTestingRepository))
            {
                dynamic repo = new LabTestingRepository();
                repo.UnitOfWork = unitOfWork;
                return((TRepository)repo);
            }

            if (typeof(TRepository) == typeof(ITokenRepository))
            {
                dynamic repo = new TokenRepository();
                repo.UnitOfWork = unitOfWork;
                return((TRepository)repo);
            }
            if (typeof(TRepository) == typeof(ITableRepository))
            {
                dynamic repo = new TableRepository();
                repo.UnitOfWork = unitOfWork;
                return((TRepository)repo);
            }
            if (typeof(TRepository) == typeof(IPatientAccountRepository))
            {
                dynamic repo = new PatientAccountRepository();
                repo.UnitOfWork = unitOfWork;
                return((TRepository)repo);
            }

            TRepository repository = null;

            TryGetRepositoryPartial <TRepository>(unitOfWork, ref repository);
            return(repository);
        }
Beispiel #20
0
 public SupplyService()
 {
     supplyRepository = new SupplyRepository();
 }
 public void Update() => Supplies = SupplyRepository.GetAll();
 public CreateSupplyWindow(SupplyRepository supplyRepository, SupplyUC owner) : this()
 {
     Owner = owner;
     var vm = new CreateSupplyViewModel(supplyRepository, this);
 }