Exemplo n.º 1
0
        private void SavePropositionExecute(object obj)
        {
            if (_addNewProposition.IsCreated && !_saveFlag)
            {

                // tworzy obiekt z aktualnymi danymi tabeli Proposition i dodaje go do bazy

                // !! PROPOSITION !!
                string propstate;
                if (SelectedPropState != null)
                    propstate = SelectedPropState; //TODO uaktualnić ewentualnie z enuma lub obgadać jak rozwiązać
                else
                    propstate = _propStates[0];
                var propositionToBase = new Proposition
                {
                    Id_user = _userId,
                    UpdateDate = _addNewProposition.UpdateDate,
                    Status = propstate  //TODO uaktualnić ewentualnie z enuma lub obgadać jak rozwiązać

                };
                _ctx.Proposition.Add(propositionToBase);
                _addNewProposition.IsCreated = false;
                _ctx.SaveChanges();

                /* wyciągnięcie Id dodanej propozycji który potrzebny bedzie przy dodawaniu
                 * do bazy pozostałych tabel (klucz obcy) */

                var lastPropId = (from prop in _ctx.Proposition
                                  select prop).ToList().Last();
                int currentPropositionId = lastPropId.Id;

                //------------------------------
                // !! PROPCLIENT !!
                PropositionClient.Id_proposition = currentPropositionId;
                _ctx.PropClient.Add(PropositionClient);

                //------------------------------
                // !! PROPRESERVATIONDETAILS !!
                PropositionReservDetails.Id_proposition = currentPropositionId;
                if (PropositionReservDetails.Hall != " ")
                    _ctx.PropReservationDetails.Add(PropositionReservDetails);

                //------------------------------
                // !! PROPHALLEQUPMENT !!

                // dodaje do bazy tylko te elementy listy, które posiadaja nazwe i cene brutto TODO: review solution
                for (int i = 0; i < _propHallEquipment.Count; i++)
                {
                    if (_propHallEquipment[i].Things != null && _propHallEquipment[i].BruttoPrice != null
                        && _propHallEquipment[i].Amount != null && _propHallEquipment[i].Days != null
                        && _propHallEquipment[i].Things != " " && _propHallEquipment[i].BruttoPrice != 0)
                    {
                        _propHallEquipment[i].Id_proposition = currentPropositionId;
                        _ctx.PropHallEquipment.Add(_propHallEquipment[i]);
                    }
                }
                //------------------------------
                // !! PROPHALLEQUPMENTDISCOUNT !!
                HallEquipmentDiscount.Id_proposition = currentPropositionId;
                _ctx.PropHallEquipmentDiscount.Add(HallEquipmentDiscount);

                //------------------------------
                // !! PROPMENUMERGES !!
                for (int i = 0; i < PropMenuMerges.Count; i++)
                {
                    PropMenuMerges[i].Id_proposition = currentPropositionId;
                    _ctx.PropMenuMerge.Add(PropMenuMerges[i]);
                }

                //------------------------------
                // !! PROPMENUPOSITIONS !!
                for (int i = 0; i < _propMenuPositions.Count; i++)
                {
                    if (_propMenuPositions[i].TypeOfService != null && _propMenuPositions[i].Amount != null &&
                        _propMenuPositions[i].Days != null && _propMenuPositions[i].TypeOfService != " ")
                    {
                        _propMenuPositions[i].Id_proposition = currentPropositionId;
                        _ctx.PropMenuPosition.Add(_propMenuPositions[i]);
                    }
                }

                //------------------------------
                // !! PROPACCOMODATIONS !!
                for (int i = 0; i < _propAccomodations.Count; i++)
                {
                    if (_propAccomodations[i].Amount != null && _propAccomodations[i].Days != null)
                    {
                        _propAccomodations[i].Id_proposition = currentPropositionId;
                        _ctx.PropAccomodation.Add(_propAccomodations[i]);
                    }
                }

                //------------------------------
                // !! PROPACCOMODATIONSDISCOUNT !!

                PropAccomDiscount.Id_proposition = currentPropositionId;
                _ctx.PropAccomodationDiscount.Add(PropAccomDiscount);

                //------------------------------
                // !! PROPEXTRASERVICES !!
                for (int i = 0; i < _propExtraServ.Count; i++)
                {
                    if (_propExtraServ[i].ServiceType != null && _propExtraServ[i].BruttoPrice != null &&
                        _propExtraServ[i].Days != null && _propExtraServ[i].Amount != null &&
                        _propExtraServ[i].ServiceType != " ")
                    {
                        _propExtraServ[i].Id_proposition = currentPropositionId;
                        _ctx.PropExtraServices.Add(_propExtraServ[i]);
                    }
                }

                //------------------------------
                // !! PROPPAYMENTSUGGESTIONS !!

                _propPaymentSugg.Id_proposition = currentPropositionId;
                _ctx.PropPaymentSuggestions.Add(_propPaymentSugg);

                try
                {
                    _ctx.SaveChanges();
                }
                catch (DbEntityValidationException e)
                {
                    foreach (var eve in e.EntityValidationErrors)
                    {
                        Console.WriteLine(@"Entity of type ""{0}"" in state ""{1}"" has the following validation errors:",
                            eve.Entry.Entity.GetType().Name, eve.Entry.State);
                        foreach (var ve in eve.ValidationErrors)
                        {
                            Console.WriteLine(@"- Property: " + ve.PropertyName + ", Error: " + ve.ErrorMessage);
                        }
                    }
                    MessageBox.Show(e.ToString());
                    throw;
                }
                Xceed.Wpf.Toolkit.MessageBox.Show("Dodano nową propozycję cenową!", "Informacja", MessageBoxButton.OK, MessageBoxImage.Information);

                // po dodaniu propozycji odśwież listę propozycji
                ChangeView(false);
                SelectAllPropositions();
            }
            else
            {

                //Edycja Propozycji
                // !! PROPCLIENT !!
                var prop = (from q in _ctx.Proposition
                            where q.Id == _idProposition
                            select q).SingleOrDefault();

                int idProposition = _idProposition;
                prop.Status = SelectedPropState;
                prop.UpdateDate = AddNewProposition.UpdateDate;
                prop.Id_user = _userId;
                _ctx.SaveChanges();
                var editClient = (from q in _ctx.PropClient
                                  where q.Id_proposition == idProposition
                                  select q).SingleOrDefault();
                if (editClient != null)
                {
                    //editClient.Id_proposition = idProposition;
                    editClient.CompanyName = PropositionClient.CompanyName;
                    editClient.CompanyAdress = PropositionClient.CompanyAdress;
                    editClient.NIP = PropositionClient.NIP;
                    editClient.CustomerFullName = PropositionClient.CustomerFullName;
                    editClient.PhoneNum = PropositionClient.PhoneNum;

                }
                else
                {
                    PropClient addNewClient = new PropClient();

                    addNewClient.Id_proposition = idProposition;
                    addNewClient.CompanyName = PropositionClient.CompanyName;
                    addNewClient.CompanyAdress = PropositionClient.CompanyAdress;
                    addNewClient.NIP = PropositionClient.NIP;
                    addNewClient.CustomerFullName = PropositionClient.CustomerFullName;
                    addNewClient.PhoneNum = PropositionClient.PhoneNum;
                    _ctx.PropClient.Add(addNewClient);

                }
                //-Edycja----------------------
                // !! PROPRESERVATIONDETAILS !!

                var propReservation = (from q in _ctx.PropReservationDetails
                                       where q.Id_proposition == _idProposition
                                       select q).SingleOrDefault();
                if (propReservation == null)
                {
                    PropReservationDetails addPropReservationDetails = new PropReservationDetails();
                    addPropReservationDetails.Id_proposition = _idProposition;
                    addPropReservationDetails.StartData = PropositionReservDetails.StartData;
                    addPropReservationDetails.EndData = PropositionReservDetails.EndData;
                    addPropReservationDetails.Hall = PropositionReservDetails.Hall;
                    addPropReservationDetails.HallSetting = PropositionReservDetailsHallSetting;
                    addPropReservationDetails.PeopleNumber = PropositionReservDetailsPeopleNumber;
                    addPropReservationDetails.EndTime = PropositionReservDetails.EndTime;
                    addPropReservationDetails.StartTime = PropositionReservDetails.StartTime;
                    //ddPropReservationDetails.Proposition = PropositionReservDetails.Proposition;
                    _ctx.PropReservationDetails.Add(addPropReservationDetails);

                }
                else
                {
                    //propReservation.Id_proposition = _idProposition;
                    propReservation.StartData = PropositionReservDetailsStartData;
                    propReservation.EndData = PropositionReservDetailsEndData;
                    propReservation.Hall = PropositionReservDetailsHall;
                    propReservation.HallSetting = PropositionReservDetailsHallSetting;
                    propReservation.PeopleNumber = PropositionReservDetailsPeopleNumber;
                    propReservation.EndTime = PropositionReservDetailsEndTime;
                    propReservation.StartTime = PropositionReservDetailsStartTime;
                    //propReservation.Proposition = PropositionReservDetails.Proposition;

                }

                _ctx.SaveChanges();

                var dicount = (from q in _ctx.PropHallEquipmentDiscount
                               where q.Id_proposition == idProposition
                               select q).SingleOrDefault();
                if (dicount != null)
                {
                    dicount.Discount = PropHallEquipmentDiscountValue;
                    dicount.StandardPrice = HallPrice;
                }
                else
                {
                    PropHallEquipmentDiscount newDiscount = new PropHallEquipmentDiscount();
                    newDiscount.Id_proposition = _idProposition;
                    newDiscount.StandardPrice = HallPrice;
                    newDiscount.Discount = PropHallEquipmentDiscountValue;
                }
                _ctx.SaveChanges();

                var propEquipment = (from q in _ctx.PropHallEquipment
                                     where q.Id_proposition == idProposition
                                     select q).ToList();
                var myRegex = new Regex(@"Sala *");
                var hall = propEquipment.Find(f => myRegex.IsMatch(f.Things));
                if (hall != null)
                {
                    if (PropHallEqAmount0 != null && PropHallEqDays0 != null)
                    {
                        hall.Things = PropHallEqThing0;
                        hall.Days = PropHallEqDays0;
                        hall.Amount = PropHallEqAmount0;
                        hall.BruttoPrice = PropHallEqBrutto0;
                        hall.Vat = PropHallEqVat0;
                        propEquipment.Remove(hall);
                        _ctx.SaveChanges();
                    }

                }
                else if (PropHallEqThing0 != null)
                {
                    PropHallEquipment newqEquipment = new PropHallEquipment();
                    newqEquipment.Things = PropHallEqThing0;
                    newqEquipment.Amount = PropHallEqAmount0;
                    newqEquipment.Days = PropHallEqDays0;
                    newqEquipment.BruttoPrice = PropHallEqBrutto0;
                    newqEquipment.Vat = PropHallEqVat0;
                    newqEquipment.Id_proposition = _idProposition;
                    _ctx.PropHallEquipment.Add(newqEquipment);
                }
                //wposażenie

                _ctx.SaveChanges();

                if (PropHallEqThing1 != null)
                {
                    var thing1 = propEquipment.ElementAtOrDefault(0);
                    if (thing1 != null)
                    {
                        thing1.Id_proposition = _idProposition;
                        thing1.Things = PropHallEqThing1;
                        thing1.Amount = PropHallEqAmount1;
                        thing1.Days = PropHallEqDays1;
                        thing1.Vat = PropHallEqVat1;
                        thing1.BruttoPrice = PropHallEqBrutto1;
                    }
                    else
                    {
                        PropHallEquipment newqEquipment = new PropHallEquipment();
                        newqEquipment.Things = PropHallEqThing1;
                        newqEquipment.Amount = PropHallEqAmount1;
                        newqEquipment.Days = PropHallEqDays1;
                        newqEquipment.BruttoPrice = PropHallEqBrutto1;
                        newqEquipment.Id_proposition = _idProposition;
                        newqEquipment.Vat = PropHallEqVat1;
                        _ctx.PropHallEquipment.Add(newqEquipment);

                    }
                }
                _ctx.SaveChanges();
                if (PropHallEqThing2 != null)
                {
                    var thing1 = propEquipment.ElementAtOrDefault(1);
                    if (thing1 != null)
                    {
                        thing1.Id_proposition = _idProposition;
                        thing1.Things = PropHallEqThing2;
                        thing1.Amount = PropHallEqAmount2;
                        thing1.Days = PropHallEqDays2;
                        thing1.BruttoPrice = PropHallEqBrutto2;
                        thing1.Vat = PropHallEqVat2;
                    }
                    else
                    {
                        PropHallEquipment newqEquipment = new PropHallEquipment();
                        newqEquipment.Things = PropHallEqThing2;
                        newqEquipment.Amount = PropHallEqAmount2;
                        newqEquipment.Days = PropHallEqDays2;
                        newqEquipment.BruttoPrice = PropHallEqBrutto2;
                        newqEquipment.Id_proposition = _idProposition;
                        newqEquipment.Vat = PropHallEqVat2;
                        _ctx.PropHallEquipment.Add(newqEquipment);

                    }
                }
                _ctx.SaveChanges();
                if (PropHallEqThing3 != null)
                {
                    var thing1 = propEquipment.ElementAtOrDefault(2);
                    if (thing1 != null)
                    {
                        thing1.Id_proposition = _idProposition;
                        thing1.Things = PropHallEqThing3;
                        thing1.Amount = PropHallEqAmount3;
                        thing1.Days = PropHallEqDays3;
                        thing1.BruttoPrice = PropHallEqBrutto3;
                        thing1.Vat = PropHallEqVat3;
                    }
                    else
                    {
                        PropHallEquipment newqEquipment = new PropHallEquipment();
                        newqEquipment.Things = PropHallEqThing3;
                        newqEquipment.Amount = PropHallEqAmount3;
                        newqEquipment.Days = PropHallEqDays3;
                        newqEquipment.BruttoPrice = PropHallEqBrutto3;
                        newqEquipment.Id_proposition = _idProposition;
                        newqEquipment.Vat = PropHallEqVat3;
                        _ctx.PropHallEquipment.Add(newqEquipment);

                    }
                }
                _ctx.SaveChanges();
                if (PropHallEqThing4 != null)
                {
                    var thing1 = propEquipment.ElementAtOrDefault(3);
                    if (thing1 != null)
                    {
                        thing1.Id_proposition = _idProposition;
                        thing1.Things = PropHallEqThing4;
                        thing1.Amount = PropHallEqAmount4;
                        thing1.Days = PropHallEqDays4;
                        thing1.BruttoPrice = PropHallEqBrutto4;
                        thing1.Vat = PropHallEqVat4;
                    }
                    else
                    {
                        PropHallEquipment newqEquipment = new PropHallEquipment();
                        newqEquipment.Things = PropHallEqThing4;
                        newqEquipment.Amount = PropHallEqAmount4;
                        newqEquipment.Days = PropHallEqDays4;
                        newqEquipment.BruttoPrice = PropHallEqBrutto4;
                        newqEquipment.Id_proposition = _idProposition;
                        newqEquipment.Vat = PropHallEqVat4;
                        _ctx.PropHallEquipment.Add(newqEquipment);

                    }
                }

                if (PropHallEqThing5 != null)
                {
                    var thing1 = propEquipment.ElementAtOrDefault(4);
                    if (thing1 != null)
                    {
                        thing1.Id_proposition = _idProposition;
                        thing1.Things = PropHallEqThing5;
                        thing1.Amount = PropHallEqAmount5;
                        thing1.Days = PropHallEqDays5;
                        thing1.BruttoPrice = PropHallEqBrutto5;
                        thing1.Vat = PropHallEqVat5;
                    }
                    else
                    {
                        PropHallEquipment newqEquipment = new PropHallEquipment();
                        newqEquipment.Things = PropHallEqThing5;
                        newqEquipment.Amount = PropHallEqAmount5;
                        newqEquipment.Days = PropHallEqDays5;
                        newqEquipment.BruttoPrice = PropHallEqBrutto5;
                        newqEquipment.Id_proposition = _idProposition;
                        newqEquipment.Vat = PropHallEqVat5;
                        _ctx.PropHallEquipment.Add(newqEquipment);
                        _ctx.SaveChanges();

                    }
                }
                _ctx.SaveChanges();

                var propEquipment1 = (from q in _ctx.PropHallEquipment
                                      where q.Id_proposition == idProposition
                                      select q).ToList();
                foreach (var check in propEquipment1)
                {
                    if (check.Things == " " || check.Things == null
                        || check.Days == null || check.Days == 0
                        || check.Amount == 0 || check.Amount == null
                        || check.BruttoPrice == 0)
                    {
                        _ctx.PropHallEquipment.Remove(check);
                    }
                }
                _ctx.SaveChanges();
                //Gastronomia
                var editGastronomic = (from q in _ctx.PropMenuPosition
                                       where q.Id_proposition == _idProposition
                                       select q).ToList();

                    var service = editGastronomic.ElementAtOrDefault(0);
                    if (service != null)
                    {

                        service.Id_proposition = idProposition;
                        service.TypeOfService = PropMenuTypeOfServ0;
                        service.Amount = PropMenuPosAmount0;
                        service.Days = PropMenuPosDays0;
                        service.MergeType = SetMenuPosDefaultMergeType(PropMenuTypeOfServ0);
                        service.BruttoPrice = SetMenuPosDefaultBrutto(PropMenuTypeOfServ0);
                        service.Vat = SetMenuPosDefaultVat(PropMenuTypeOfServ0);

                    }
                    else
                    {
                        PropMenuPosition newPosition = new PropMenuPosition();
                        newPosition.Id_proposition = idProposition;
                        newPosition.TypeOfService = PropMenuTypeOfServ0;
                        newPosition.Amount = PropMenuPosAmount0;
                        newPosition.Days = PropMenuPosDays0;
                        newPosition.MergeType = SetMenuPosDefaultMergeType(PropMenuTypeOfServ0);
                        newPosition.BruttoPrice = SetMenuPosDefaultBrutto(PropMenuTypeOfServ0);
                        newPosition.Vat = SetMenuPosDefaultVat(PropMenuTypeOfServ0);
                        _ctx.PropMenuPosition.Add(newPosition);
                    }

                _ctx.SaveChanges();

                    var service1 = editGastronomic.ElementAtOrDefault(1);
                    if (service1 != null)
                    {
                        service1.Id_proposition = idProposition;
                        service1.TypeOfService = PropMenuTypeOfServ1;
                        service1.Amount = PropMenuPosAmount1;
                        service1.Days = PropMenuPosDays1;
                        service1.MergeType = SetMenuPosDefaultMergeType(PropMenuTypeOfServ1);
                        service1.BruttoPrice = SetMenuPosDefaultBrutto(PropMenuTypeOfServ1);
                        service1.Vat = SetMenuPosDefaultVat(PropMenuTypeOfServ1);

                    }
                    else
                    {
                        PropMenuPosition newPosition = new PropMenuPosition();
                        newPosition.Id_proposition = idProposition;
                        newPosition.TypeOfService = PropMenuTypeOfServ1;
                        newPosition.Amount = PropMenuPosAmount1;
                        newPosition.Days = PropMenuPosDays1;
                        newPosition.MergeType = SetMenuPosDefaultMergeType(PropMenuTypeOfServ1);
                        newPosition.BruttoPrice = SetMenuPosDefaultBrutto(PropMenuTypeOfServ1);
                        newPosition.Vat = SetMenuPosDefaultVat(PropMenuTypeOfServ1);
                        _ctx.PropMenuPosition.Add(newPosition);
                    }

                _ctx.SaveChanges();

                    var service2 = editGastronomic.ElementAtOrDefault(2);
                    if (service2 != null)
                    {
                        service2.Id_proposition = idProposition;
                        service2.TypeOfService = PropMenuTypeOfServ2;
                        service2.Amount = PropMenuPosAmount2;
                        service2.Days = PropMenuPosDays2;
                        service2.MergeType = SetMenuPosDefaultMergeType(PropMenuTypeOfServ2);
                        service2.BruttoPrice = SetMenuPosDefaultBrutto(PropMenuTypeOfServ2);
                        service2.Vat = SetMenuPosDefaultVat(PropMenuTypeOfServ2);

                    }
                    else
                    {
                        PropMenuPosition newPosition = new PropMenuPosition();
                        newPosition.Id_proposition = idProposition;
                        newPosition.TypeOfService = PropMenuTypeOfServ2;
                        newPosition.Amount = PropMenuPosAmount2;
                        newPosition.Days = PropMenuPosDays2;
                        newPosition.MergeType = SetMenuPosDefaultMergeType(PropMenuTypeOfServ2);
                        newPosition.BruttoPrice = SetMenuPosDefaultBrutto(PropMenuTypeOfServ2);
                        newPosition.Vat = SetMenuPosDefaultVat(PropMenuTypeOfServ2);
                        _ctx.PropMenuPosition.Add(newPosition);
                    }

                _ctx.SaveChanges();
                    var service3 = editGastronomic.ElementAtOrDefault(3);
                    if (service3 != null)
                    {
                        service3.Id_proposition = idProposition;
                        service3.TypeOfService = PropMenuTypeOfServ3;
                        service3.Amount = PropMenuPosAmount3;
                        service3.Days = PropMenuPosDays3;
                        service3.MergeType = SetMenuPosDefaultMergeType(PropMenuTypeOfServ3);
                        service3.BruttoPrice = SetMenuPosDefaultBrutto(PropMenuTypeOfServ3);
                        service3.Vat = SetMenuPosDefaultVat(PropMenuTypeOfServ3);

                    }
                    else
                    {
                        PropMenuPosition newPosition = new PropMenuPosition();
                        newPosition.Id_proposition = idProposition;
                        newPosition.TypeOfService = PropMenuTypeOfServ3;
                        newPosition.Amount = PropMenuPosAmount3;
                        newPosition.Days = PropMenuPosDays3;
                        newPosition.MergeType = SetMenuPosDefaultMergeType(PropMenuTypeOfServ3);
                        newPosition.BruttoPrice = SetMenuPosDefaultBrutto(PropMenuTypeOfServ3);
                        newPosition.Vat = SetMenuPosDefaultVat(PropMenuTypeOfServ3);
                        _ctx.PropMenuPosition.Add(newPosition);
                    }

                _ctx.SaveChanges();

                    var service4 = editGastronomic.ElementAtOrDefault(4);
                    if (service4 != null)
                    {
                        service4.Id_proposition = idProposition;
                        service4.TypeOfService = PropMenuTypeOfServ4;
                        service4.Amount = PropMenuPosAmount4;
                        service4.Days = PropMenuPosDays4;
                        service4.MergeType = SetMenuPosDefaultMergeType(PropMenuTypeOfServ4);
                        service4.BruttoPrice = SetMenuPosDefaultBrutto(PropMenuTypeOfServ4);
                        service4.Vat = SetMenuPosDefaultVat(PropMenuTypeOfServ4);

                    }
                    else
                    {
                        PropMenuPosition newPosition = new PropMenuPosition();
                        newPosition.Id_proposition = idProposition;
                        newPosition.TypeOfService = PropMenuTypeOfServ4;
                        newPosition.Amount = PropMenuPosAmount4;
                        newPosition.Days = PropMenuPosDays4;
                        newPosition.MergeType = SetMenuPosDefaultMergeType(PropMenuTypeOfServ4);
                        newPosition.BruttoPrice = SetMenuPosDefaultBrutto(PropMenuTypeOfServ4);
                        newPosition.Vat = SetMenuPosDefaultVat(PropMenuTypeOfServ4);
                        _ctx.PropMenuPosition.Add(newPosition);
                    }

                _ctx.SaveChanges();

                    var service5 = editGastronomic.ElementAtOrDefault(5);
                    if (service5 != null)
                    {
                        service5.Id_proposition = idProposition;
                        service5.TypeOfService = PropMenuTypeOfServ5;
                        service5.Amount = PropMenuPosAmount5;
                        service5.Days = PropMenuPosDays5;
                        service5.MergeType = SetMenuPosDefaultMergeType(PropMenuTypeOfServ5);
                        service5.BruttoPrice = SetMenuPosDefaultBrutto(PropMenuTypeOfServ5);
                        service5.Vat = SetMenuPosDefaultVat(PropMenuTypeOfServ5);

                    }
                    else
                    {
                        PropMenuPosition newPosition = new PropMenuPosition();
                        newPosition.Id_proposition = idProposition;
                        newPosition.Amount = PropMenuPosAmount5;
                        newPosition.Days = PropMenuPosDays5;
                        newPosition.MergeType = SetMenuPosDefaultMergeType(PropMenuTypeOfServ5);
                        newPosition.BruttoPrice = SetMenuPosDefaultBrutto(PropMenuTypeOfServ5);
                        newPosition.Vat = SetMenuPosDefaultVat(PropMenuTypeOfServ5);
                        _ctx.PropMenuPosition.Add(newPosition);
                    }

                _ctx.SaveChanges();

                    var service6 = editGastronomic.ElementAtOrDefault(6);
                    if (service6 != null)
                    {
                        service6.Id_proposition = idProposition;
                        service6.TypeOfService = PropMenuTypeOfServ6;
                        service6.Amount = PropMenuPosAmount6;
                        service6.Days = PropMenuPosDays6;
                        service6.MergeType = SetMenuPosDefaultMergeType(PropMenuTypeOfServ6);
                        service6.BruttoPrice = SetMenuPosDefaultBrutto(PropMenuTypeOfServ6);
                        service6.Vat = SetMenuPosDefaultVat(PropMenuTypeOfServ6);

                    }
                    else
                    {
                        PropMenuPosition newPosition = new PropMenuPosition();
                        newPosition.Id_proposition = idProposition;
                        newPosition.TypeOfService = PropMenuTypeOfServ6;
                        newPosition.Amount = PropMenuPosAmount6;
                        newPosition.Days = PropMenuPosDays6;
                        newPosition.MergeType = SetMenuPosDefaultMergeType(PropMenuTypeOfServ6);
                        newPosition.BruttoPrice = SetMenuPosDefaultBrutto(PropMenuTypeOfServ6);
                        newPosition.Vat = SetMenuPosDefaultVat(PropMenuTypeOfServ6);
                        _ctx.PropMenuPosition.Add(newPosition);
                    }

                _ctx.SaveChanges();
                var clearGast = (from q in _ctx.PropMenuPosition
                                 where q.Id_proposition == _idProposition
                                 select q).ToList();
                var tmpClearGast =
                    clearGast.FindAll(
                        item =>
                            item.Amount == null || item.Amount == 0
                            || item.Days == null || item.Days == 0 ||
                            item.TypeOfService == " " || item.TypeOfService == null).ToList();
                _ctx.PropMenuPosition.RemoveRange(tmpClearGast);

                var merge = (from q in _ctx.PropMenuMerge
                             where q.Id_proposition == idProposition
                             select q).ToList();
                merge[0].DefaultValue = PropMenuMerge0;
                merge[1].DefaultValue = PropMenuMerge1;
                merge[2].DefaultValue = PropMenuMerge2;
                merge[3].DefaultValue = PropMenuMerge3;
                merge[4].DefaultValue = PropMenuMerge4;
                _ctx.SaveChanges();

                var room = (from q in _ctx.PropAccomodation
                            where q.Id_proposition == idProposition
                            select q).ToList();
                for (int i = 0; i < room.Count; i++)
                {
                    switch (room[i].TypeOfRoom)
                    {
                        case "POKÓJ 1-OSOBOWY":
                            room[i].Amount = PropAccomAmount0;
                            room[i].Days = PropAccomDays0;
                            room[i].BruttoPrice = PropAccomBrutto0;
                            room[i].Vat = PropAccomVat0;
                            break;
                        case "POKÓJ 2-OSOBOWY":
                            room[i].Amount = PropAccomAmount1;
                            room[i].Days = PropAccomDays1;
                            room[i].BruttoPrice = PropAccomBrutto1;
                            room[i].Vat = PropAccomVat1;
                            break;
                        case "POKÓJ BUSSINES 1-OSOBOWY":
                            room[i].Amount = PropAccomAmount2;
                            room[i].Days = PropAccomDays2;
                            room[i].BruttoPrice = PropAccomBrutto2;
                            room[i].Vat = PropAccomVat2;
                            break;
                        case "POKÓJ BUSSINES 2-OSOBOWY":
                            room[i].Amount = PropAccomAmount3;
                            room[i].Days = PropAccomDays3;
                            room[i].BruttoPrice = PropAccomBrutto3;
                            room[i].Vat = PropAccomVat3;
                            break;
                        case "APARTAMENT":
                            room[i].Amount = PropAccomAmount4;
                            room[i].Days = PropAccomDays4;
                            room[i].BruttoPrice = PropAccomBrutto4;
                            room[i].Vat = PropAccomVat4;
                            break;
                        case "POKOJ DLA NIEPEŁNOSPRAWNYCH":
                            room[i].Amount = PropAccomAmount5;
                            room[i].Days = PropAccomDays5;
                            room[i].BruttoPrice = PropAccomBrutto5;
                            room[i].Vat = PropAccomVat5;
                            break;
                    }
                }
                for (int i = 0; i < _roomExistList.Count; i++)
                {
                    switch (_roomExistList[i])
                    {
                        case "POKÓJ 1-OSOBOWY":
                            if (PropAccomAmount0 != null && PropAccomDays0 != null && PropAccomAmount0 != 0 && PropAccomDays0 != 0)
                            {
                                PropAccomodation newroom = new PropAccomodation();
                                newroom.Id_proposition = _idProposition;
                                newroom.Amount = PropAccomAmount0;
                                newroom.BruttoPrice = PropAccomBrutto0;
                                newroom.Days = PropAccomDays0;
                                newroom.TypeOfRoom = PropAccomTypeOfRoom0;
                                newroom.Vat = PropAccomVat0;
                                _ctx.PropAccomodation.Add(newroom);
                            }
                            break;
                        case "POKÓJ 2-OSOBOWY":
                            if (PropAccomAmount1 != null && PropAccomDays1 != null && PropAccomAmount1 != 0 && PropAccomDays1 != 0)
                            {
                                PropAccomodation newroom = new PropAccomodation();
                                newroom.Id_proposition = _idProposition;
                                newroom.Amount = PropAccomAmount1;
                                newroom.BruttoPrice = PropAccomBrutto1;
                                newroom.Days = PropAccomDays1;
                                newroom.TypeOfRoom = PropAccomTypeOfRoom1;
                                newroom.Vat = PropAccomVat1;
                                _ctx.PropAccomodation.Add(newroom);
                            }
                            break;
                        case "POKÓJ BUSSINES 1-OSOBOWY":
                            if (PropAccomAmount2 != null && PropAccomDays2 != null && PropAccomAmount2 != 0 && PropAccomDays2 != 0)
                            {
                                PropAccomodation newroom = new PropAccomodation();
                                newroom.Id_proposition = _idProposition;
                                newroom.Amount = PropAccomAmount2;
                                newroom.BruttoPrice = PropAccomBrutto2;
                                newroom.Days = PropAccomDays2;
                                newroom.TypeOfRoom = PropAccomTypeOfRoom2;
                                newroom.Vat = PropAccomVat2;
                                _ctx.PropAccomodation.Add(newroom);
                            }
                            break;
                        case "POKÓJ BUSSINES 2-OSOBOWY":
                            if (PropAccomAmount3 != null && PropAccomDays3 != null && PropAccomAmount3 != 0 && PropAccomDays3 != 0)
                            {
                                PropAccomodation newroom = new PropAccomodation();
                                newroom.Id_proposition = _idProposition;
                                newroom.Amount = PropAccomAmount3;
                                newroom.BruttoPrice = PropAccomBrutto3;
                                newroom.Days = PropAccomDays3;
                                newroom.TypeOfRoom = PropAccomTypeOfRoom3;
                                newroom.Vat = PropAccomVat3;
                                _ctx.PropAccomodation.Add(newroom);
                            }
                            break;
                        case "APARTAMENT":
                            if (PropAccomAmount4 != null && PropAccomDays4 != null && PropAccomAmount4 != 0 && PropAccomDays5 != 0)
                            {
                                PropAccomodation newroom = new PropAccomodation();
                                newroom.Id_proposition = _idProposition;
                                newroom.Amount = PropAccomAmount4;
                                newroom.BruttoPrice = PropAccomBrutto4;
                                newroom.Days = PropAccomDays4;
                                newroom.TypeOfRoom = PropAccomTypeOfRoom4;
                                newroom.Vat = PropAccomVat4;
                                _ctx.PropAccomodation.Add(newroom);
                            }
                            break;
                        case "POKOJ DLA NIEPEŁNOSPRAWNYCH":
                            if (PropAccomAmount5 != null && PropAccomDays5 != null && PropAccomAmount5 != 0 && PropAccomDays5 != 0)
                            {
                                PropAccomodation newroom = new PropAccomodation();
                                newroom.Id_proposition = _idProposition;
                                newroom.Amount = PropAccomAmount5;
                                newroom.BruttoPrice = PropAccomBrutto5;
                                newroom.Days = PropAccomDays5;
                                newroom.TypeOfRoom = PropAccomTypeOfRoom5;
                                newroom.Vat = PropAccomVat5;
                                _ctx.PropAccomodation.Add(newroom);
                            }
                            break;
                    }
                }
                var clearAcc =
                    (from q in _ctx.PropAccomodation
                     where q.Id_proposition == _idProposition
                     select q).ToList().FindAll(item => item.Amount == 0
                         || item.Amount == null || item.Days == 0
                         || item.Days == null);
                _ctx.PropAccomodation.RemoveRange(clearAcc);
                _ctx.SaveChanges();

                var mergeaccom = (from q in _ctx.PropAccomodationDiscount
                                  where q.Id_proposition == _idProposition
                                  select q).SingleOrDefault();
                mergeaccom.Discount = PropAccomDiscountValue;
                _ctx.SaveChanges();
                // usługi dodatkowe
                var propextr = (from q in _ctx.PropExtraServices
                                where q.Id_proposition == idProposition
                                select q).ToList();

                var parking = new Regex(@"PARKING .+");

                if (PropExtraServType0 != null)
                {

                    var position = propextr.Find(f => parking.IsMatch(f.ServiceType));

                    if (position != null)
                    {
                        position.ServiceType = PropExtraServType0;
                        position.Amount = PropExtraServAmount0;
                        position.Days = PropExtraServDays0;
                        position.BruttoPrice = PropExtraServBrutto0;
                        position.Vat = PropExtraServVat0;
                        propextr.Remove(position);
                    }

                    else
                    {

                        PropExtraServices newextra = new PropExtraServices();
                        newextra.Id_proposition = idProposition;
                        newextra.ServiceType = PropExtraServType0;
                        newextra.Amount = PropExtraServAmount0;
                        newextra.Days = PropExtraServDays0;
                        newextra.BruttoPrice = PropExtraServBrutto0;
                        newextra.Vat = PropExtraServVat0;
                        _ctx.PropExtraServices.Add(newextra);
                    }
                }

                if (PropExtraServType1 != null)
                {

                    if (propextr.ElementAtOrDefault(0) != null)
                    {
                        propextr[0].ServiceType = PropExtraServType1;
                        propextr[0].Amount = PropExtraServAmount1;
                        propextr[0].Days = PropExtraServDays1;
                        propextr[0].BruttoPrice = PropExtraServBrutto1;
                        propextr[0].Vat = PropExtraServVat1;
                    }
                    else
                    {

                        PropExtraServices newextra = new PropExtraServices();
                        newextra.Id_proposition = idProposition;
                        newextra.ServiceType = PropExtraServType1;
                        newextra.Amount = PropExtraServAmount1;
                        newextra.Days = PropExtraServDays1;
                        newextra.BruttoPrice = PropExtraServBrutto1;
                        newextra.Vat = PropExtraServVat1;
                        _ctx.PropExtraServices.Add(newextra);
                    }
                }
                if (PropExtraServType2 != null)
                {

                    if (propextr.ElementAtOrDefault(1) != null)
                    {
                        propextr[1].ServiceType = PropExtraServType2;
                        propextr[1].Amount = PropExtraServAmount2;
                        propextr[1].Days = PropExtraServDays2;
                        propextr[1].BruttoPrice = PropExtraServBrutto2;
                        propextr[1].Vat = PropExtraServVat2;
                    }
                    else
                    {

                        PropExtraServices newextra = new PropExtraServices();
                        newextra.Id_proposition = idProposition;
                        newextra.ServiceType = PropExtraServType2;
                        newextra.Amount = PropExtraServAmount2;
                        newextra.Days = PropExtraServDays2;
                        newextra.BruttoPrice = PropExtraServBrutto2;
                        newextra.Vat = PropExtraServVat2;
                        _ctx.PropExtraServices.Add(newextra);
                    }
                }
                if (PropExtraServType3 != null)
                {

                    if (propextr.ElementAtOrDefault(2) != null)
                    {
                        propextr[2].ServiceType = PropExtraServType3;
                        propextr[2].Amount = PropExtraServAmount3;
                        propextr[2].Days = PropExtraServDays3;
                        propextr[2].BruttoPrice = PropExtraServBrutto3;
                        propextr[2].Vat = PropExtraServVat3;
                    }
                    else
                    {

                        PropExtraServices newextra = new PropExtraServices();
                        newextra.Id_proposition = idProposition;
                        newextra.ServiceType = PropExtraServType3;
                        newextra.Amount = PropExtraServAmount3;
                        newextra.Days = PropExtraServDays3;
                        newextra.BruttoPrice = PropExtraServBrutto3;
                        newextra.Vat = PropExtraServVat3;
                        _ctx.PropExtraServices.Add(newextra);
                    }
                }

                _ctx.SaveChanges();
                var extrClear = (from x in _ctx.PropExtraServices
                                 where x.Id_proposition == _idProposition
                                 select x).ToList().FindAll(item => item.Days == null ||
                                                             item.Amount == null || item.Days == 0 ||
                                                             item.Amount == 0 || item.ServiceType == " "
                                                             || item.ServiceType == "" || item.BruttoPrice == 0f && !parking.IsMatch(item.ServiceType));

                _ctx.PropExtraServices.RemoveRange(extrClear);

                _ctx.SaveChanges();
                var paysug = (from q in _ctx.PropPaymentSuggestions
                              where q.Id_proposition == _idProposition
                              select q).SingleOrDefault();
                if (paysug != null)
                {
                    paysug.PaymentForm = PaymentSuggestPaymentForm;
                    paysug.InvoiceServiceName = PaymentSuggestInvServName;
                    paysug.CarPark = PaymentSuggestCarPark;
                    paysug.IndividualOrders = PaymentSuggestIndividOrder;

                }
                else
                {
                    PropPaymentSuggestions paysug1 = new PropPaymentSuggestions();
                    paysug1.Id_proposition = idProposition;
                    paysug1.PaymentForm = PaymentSuggestPaymentForm;
                    paysug1.InvoiceServiceName = PaymentSuggestInvServName;
                    paysug1.CarPark = PaymentSuggestCarPark;
                    paysug1.IndividualOrders = PaymentSuggestIndividOrder;
                    _ctx.PropPaymentSuggestions.Add(paysug1);
                }
                _ctx.SaveChanges();

                Xceed.Wpf.Toolkit.MessageBox.Show("Edytowano istniejącą propozycję cenową!", "Informacja", MessageBoxButton.OK, MessageBoxImage.Information);
                SelectedProposition = null;
                _idProposition = 0;
                SelectAllPropositions();
                ChangeView(false);
            }
        }
Exemplo n.º 2
0
 private void InitializeObjects()
 {
     _propositionClient = new PropClient();
     _propositionReservDetails = new PropReservationDetails();
     _hallCapacity = new PropReservationDetails_Dictionary_HallCapacity();
     _propHallEquipmentDiscount = new PropHallEquipmentDiscount();
     _propHallEquipment = new List<PropHallEquipment>(6);
     _secondTabNettoPrice = new List<decimal>(6);
     _secondTabNettoValue = new List<decimal>(6);
     _secondTabBruttoValue = new List<decimal>(6);
     _vatList = new List<float?>(2);
     _propMenuPositions = new List<PropMenuPosition>(7);
     _thirdTabNettoPrice = new List<decimal?>(7);
     _propMenuMerges = new List<PropMenuMerge>(5);
     _thirdTabNettoValue = new List<decimal>(7);
     _thirdTabBruttoValue = new List<decimal>(7);
     _propAccomodations = new List<PropAccomodation>(6);
     _propAccomDictionary = new List<PropAccomodation_Dictionary>();
     _propAccomDiscount = new PropAccomodationDiscount();
     _vatList4 = new List<float?>(2);
     _fourthTabNettoPrice = new List<decimal?>(6);
     _fourthTabNettoValue = new List<decimal>(6);
     _fourthTabBruttoValue = new List<decimal>(6);
     _propExtraServ = new List<PropExtraServices>(2);
     _fifthTabNettoPrice = new List<decimal?>(4);
     _fifthTabNettoValue = new List<decimal>(4);
     _fifthTabBruttoValue = new List<decimal>(4);
     _propPaymentSugg = new PropPaymentSuggestions();
     _selectedType = new List<string>(7);
     _filter = new List<string>(7);
     _propMenuGastThingDict0 = new ObservableCollection<string>();
     _propMenuGastThingDict1 = new ObservableCollection<string>();
     _propMenuGastThingDict2 = new ObservableCollection<string>();
     _propMenuGastThingDict3 = new ObservableCollection<string>();
     _propMenuGastThingDict4 = new ObservableCollection<string>();
     _propMenuGastThingDict5 = new ObservableCollection<string>();
     _propMenuGastThingDict6 = new ObservableCollection<string>();
 }