private void NewOffer()
        {
            if (Validator.ValidateAll().IsValid)
            {
                if (order.Id == 0)
                {
                    order = UnitOfWork.Orders.Add(order);
                }

                var vm = new OfferCreationViewModel(new UnitOfWorkFactory());
                vm.Init();
                var windowView = new OfferCreationView(vm);

                if (windowView.ShowDialog() ?? false)
                {
                    var    offerNumber = vm.OfferNumber;
                    string fileName;
                    try
                    {
                        fileName = FileAccess.CreateDocumentFromTemplate(order.Customer, offerNumber, Properties.Settings.Default.OfferTemplatePath);
                    }
                    catch (Win32Exception)
                    {
                        MessageBox.Show("Das Dokument konnte nicht erstellt werden. Eventuell haben Sie die Vorlage noch geöffnet.", "Ein Fehler ist aufgetreten");
                        return;
                    }

                    var document = new Document
                    {
                        IssueDate    = DateTime.Now,
                        Name         = offerNumber,
                        Tag          = "Offerte",
                        RelativePath = fileName
                    };

                    document = UnitOfWork.Documents.Add(document);

                    var offer = new Offer
                    {
                        OfferNumber = offerNumber,
                        Order       = order,
                        Document    = document
                    };

                    offer = UnitOfWork.Offers.Add(offer);

                    UnitOfWork.Complete();

                    OfferList.Add(offer);

                    if (vm.OpenAfterSave ?? false)
                    {
                        Open(fileName);
                    }
                }
            }
        }
Exemple #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="Reader"></param>
        public override void ReadXml(XmlReader Reader)
        {
            // read baseclass part
            base.ReadXml(Reader);

            // shopbot
            Reader.ReadToFollowing(XMLTAG_BOT);
            IntervalBroadcast = GameTick.MSINSECOND * Convert.ToUInt32(Reader[XMLATTRIB_INTERVALBROADCAST]);
            IntervalSay       = GameTick.MSINSECOND * Convert.ToUInt32(Reader[XMLATTRIB_INTERVALSAY]);
            TellOnEnter       = Convert.ToBoolean(Reader[XMLATTRIB_TELLONENTER]);
            ChatPrefixString  = Reader[XMLATTRIB_CHATPREFIXSTRING];
            Shopname          = Reader[XMLATTRIB_SHOPNAME];

            // vars for lists
            string name;
            uint   unitprice;
            uint   amount;

            // offerlist
            OfferList.Clear();
            Reader.ReadToFollowing(XMLTAG_OFFERLIST);
            if (Reader.ReadToDescendant(XMLTAG_ITEM))
            {
                do
                {
                    name      = Reader[XMLATTRIB_NAME];
                    unitprice = Convert.ToUInt32(Reader[XMLATTRIB_UNITPRICE]);
                    amount    = Convert.ToUInt32(Reader[XMLATTRIB_COUNT]);

                    OfferList.Add(new ShopItem(name, unitprice, amount));
                }while (Reader.ReadToNextSibling(XMLTAG_ITEM));
            }

            // buylist
            BuyList.Clear();
            Reader.ReadToFollowing(XMLTAG_BUYLIST);
            if (Reader.ReadToDescendant(XMLTAG_ITEM))
            {
                do
                {
                    name      = Reader[XMLATTRIB_NAME];
                    unitprice = Convert.ToUInt32(Reader[XMLATTRIB_UNITPRICE]);
                    amount    = Convert.ToUInt32(Reader[XMLATTRIB_COUNT]);

                    BuyList.Add(new ShopItem(name, unitprice, amount));
                }while (Reader.ReadToNextSibling(XMLTAG_ITEM));
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="Document"></param>
        public override void ReadXml(XmlDocument Document)
        {
            // read baseclass part
            base.ReadXml(Document);

            uint    val_uint;
            bool    val_bool;
            XmlNode node;
            string  name;
            uint    unitprice;
            uint    amount;

            OfferList.Clear();
            BuyList.Clear();

            // basics

            node = Document.DocumentElement.SelectSingleNode(
                '/' + XMLTAG_CONFIGURATION + '/' + XMLTAG_BOT);

            if (node != null)
            {
                IntervalBroadcast = (node.Attributes[XMLATTRIB_INTERVALBROADCAST] != null && UInt32.TryParse(node.Attributes[XMLATTRIB_INTERVALBROADCAST].Value, out val_uint)) ?
                                    val_uint * GameTick.MSINSECOND : DEFAULTVAL_SHOPBOT_INTERVALBROADCAST * GameTick.MSINSECOND;

                IntervalSay = (node.Attributes[XMLATTRIB_INTERVALSAY] != null && UInt32.TryParse(node.Attributes[XMLATTRIB_INTERVALSAY].Value, out val_uint)) ?
                              val_uint * GameTick.MSINSECOND : DEFAULTVAL_SHOPBOT_INTERVALSAY * GameTick.MSINSECOND;

                TellOnEnter = (node.Attributes[XMLATTRIB_TELLONENTER] != null && Boolean.TryParse(node.Attributes[XMLATTRIB_TELLONENTER].Value, out val_bool)) ?
                              val_bool : DEFAULTVAL_SHOPBOT_TELLONENTER;

                ChatPrefixString = (node.Attributes[XMLATTRIB_CHATPREFIXSTRING] != null) ?
                                   node.Attributes[XMLATTRIB_CHATPREFIXSTRING].Value : DEFAULTVAL_SHOPBOT_CHATPREFIXSTRING;

                Shopname = (node.Attributes[XMLATTRIB_SHOPNAME] != null) ?
                           node.Attributes[XMLATTRIB_SHOPNAME].Value : DEFAULTVAL_SHOPBOT_SHOPNAME;
            }
            else
            {
                IntervalBroadcast = DEFAULTVAL_SHOPBOT_INTERVALBROADCAST * GameTick.MSINSECOND;
                IntervalSay       = DEFAULTVAL_SHOPBOT_INTERVALSAY * GameTick.MSINSECOND;
                TellOnEnter       = DEFAULTVAL_SHOPBOT_TELLONENTER;
                ChatPrefixString  = DEFAULTVAL_SHOPBOT_CHATPREFIXSTRING;
                Shopname          = DEFAULTVAL_SHOPBOT_SHOPNAME;
            }

            // offerlist

            node = Document.DocumentElement.SelectSingleNode(
                '/' + XMLTAG_CONFIGURATION + '/' + XMLTAG_BOT + '/' + XMLTAG_OFFERLIST);

            if (node != null)
            {
                foreach (XmlNode child in node.ChildNodes)
                {
                    if (child.Name != XMLTAG_ITEM)
                    {
                        continue;
                    }

                    name = (child.Attributes[XMLATTRIB_NAME] != null) ?
                           child.Attributes[XMLATTRIB_NAME].Value : DEFAULTVAL_OFFERLIST_NAME;

                    unitprice = (child.Attributes[XMLATTRIB_UNITPRICE] != null && UInt32.TryParse(child.Attributes[XMLATTRIB_UNITPRICE].Value, out val_uint)) ?
                                val_uint : DEFAULTVAL_OFFERLIST_UNITPRICE;

                    amount = (child.Attributes[XMLATTRIB_COUNT] != null && UInt32.TryParse(child.Attributes[XMLATTRIB_COUNT].Value, out val_uint)) ?
                             val_uint : DEFAULTVAL_OFFERLIST_AMOUNT;

                    OfferList.Add(new ShopItem(name, unitprice, amount));
                }
            }

            // buylist

            node = Document.DocumentElement.SelectSingleNode(
                '/' + XMLTAG_CONFIGURATION + '/' + XMLTAG_BOT + '/' + XMLTAG_BUYLIST);

            if (node != null)
            {
                foreach (XmlNode child in node.ChildNodes)
                {
                    if (child.Name != XMLTAG_ITEM)
                    {
                        continue;
                    }

                    name = (child.Attributes[XMLATTRIB_NAME] != null) ?
                           child.Attributes[XMLATTRIB_NAME].Value : DEFAULTVAL_OFFERLIST_NAME;

                    unitprice = (child.Attributes[XMLATTRIB_UNITPRICE] != null && UInt32.TryParse(child.Attributes[XMLATTRIB_UNITPRICE].Value, out val_uint)) ?
                                val_uint : DEFAULTVAL_OFFERLIST_UNITPRICE;

                    amount = (child.Attributes[XMLATTRIB_COUNT] != null && UInt32.TryParse(child.Attributes[XMLATTRIB_COUNT].Value, out val_uint)) ?
                             val_uint : DEFAULTVAL_OFFERLIST_AMOUNT;

                    BuyList.Add(new ShopItem(name, unitprice, amount));
                }
            }
        }
Exemple #4
0
        public async Task Init()
        {
            var request = await _requestService.GetById <Request>(Id);

            if (request.Inactive == true)
            {
                InActiveRequest = true;
                ActiveRequest   = false;
                return;
            }
            InitRequest(request);
            var address = await _addressService.GetById <Address>(request.DeliveryAddress);

            var country = await _countryService.GetById <Country>((int)address.CountryId);

            var status = await _statusService.GetById <Model.Status>(request.StatusId);

            InitStatus(status);

            Address    = $"{country.Name}, {address.ZipCode}, {address.City}";
            IsSupplier = JWTService.DecodeJWTRole() == Role.Supplier;
            IsClient   = !IsSupplier;

            if (IsClient)
            {
                var searchRequest = new OfferSearchRequest
                {
                    RequestId     = Id,
                    OfferStatusId = (int)Models.OfferStatus.Active
                };
                var offerList = await _offerService.GetAll <List <Offer> >(searchRequest);

                if (offerList.Count == 0)
                {
                    HaveAcceptedOffer = await RequestHaveAcceptedOffer();

                    HaveFinishedOffer = await RequestHaveFinishedOffer();

                    HaveActiveOffers = await RequestHaveActiveOffer();

                    var finishedOffer = await RequestHaveFinishedOfferWithoutRating();

                    if (!HaveAcceptedOffer && !finishedOffer)
                    {
                        ShowEditButton = true;
                    }

                    if (HaveFinishedOffer)
                    {
                        var list = await _ratingTypeService.GetAll <List <Model.RatingType> >();

                        RatingTypeList.Clear();
                        foreach (var rt in list)
                        {
                            RatingTypeList.Add(rt);
                        }
                    }
                }
                else
                {
                    ShowList = true;
                }

                OfferList.Clear();
                foreach (var offer in offerList)
                {
                    var supplier = await _authService.GetById(offer.UserId);

                    var supplierAddress = await _addressService.GetById <Address>((int)supplier.AddressId);

                    var supplierCountry = await _countryService.GetById <Country>((int)supplierAddress.CountryId);

                    var user = await _authService.GetById(offer.UserId);

                    var newOffer = new RequestDetailsOffers
                    {
                        Company    = user.Company,
                        UserFromId = offer.UserId,
                        Address    = supplierCountry.Name + ", " + supplierAddress.City,
                        OfferId    = offer.OfferId
                    };

                    OfferList.Add(newOffer);
                }
                OffersHeight = OfferList.Count * 65;
            }
            else
            {
                await InitFieldsVisibility();
            }

            var recommendedRequests = await _requestService.RecommendRequest <List <Request> >(Id);

            RecommendedRequests.Clear();
            foreach (var recRequest in recommendedRequests)
            {
                var toAddress = await _addressService.GetById <Address>(recRequest.DeliveryAddress);

                var toCountry = await _countryService.GetById <Country>((int)toAddress.CountryId);

                var fromUser = await _authService.GetById(recRequest.ClientId);

                var fromAddress = await _addressService.GetById <Address>((int)fromUser.AddressId);

                var fromCountry = await _countryService.GetById <Country>((int)fromAddress.CountryId);

                var requestModel = new RequestModel
                {
                    FromCountry = fromCountry.Name,
                    Price       = recRequest.Price,
                    RequestId   = recRequest.RequestId,
                    ToCountry   = toCountry.Name,
                    FullName    = $"{fromUser.FirstName} {fromUser.LastName}"
                };

                RecommendedRequests.Add(requestModel);
            }

            if (RecommendedRequests.Count > 0)
            {
                RecommendShowList = true;
            }
            else
            {
                RecommendShowList = false;
            }
        }