예제 #1
0
        public MainViewModel()
        {

            SaleCards = XMLParser.GetAllSaleCards();
            ChoosedCard = new SaleCardModel();
            UpdateWindow = new Command(arg => UpdateWindowMethod());
        }
 public ShowAllCardsViewModel()
 {
     //ClickCommand = new Command(arg => ClickMethod());
     SaleCard = new SaleCardModel { Discount=15, Surname="", Name="", Number=0, Balance=0};
     SaleCards = XMLParser.GetAllSaleCards();
     xmlp = new XMLParser();
 }
 public ShowBalanceViewModel()
 {
     ClickCommand = new Command(arg => findBalance());
     SaleCard = new SaleCardModel { Discount=15, Name="", Surname="",Number=0, Balance=0 };
     SaleCards = XMLParser.GetAllSaleCards();
    
     xmlp = new XMLParser();
 }
예제 #4
0
        public void AddSaleCard(SaleCardModel SaleCard)
        {
            XDocument doc = XDocument.Load(file);
            XElement card = new XElement("SaleCard",
                new XElement("discount", SaleCard.Discount),
                new XElement("number", SaleCard.Number),
                new XElement("surname", SaleCard.Surname),
                new XElement("name", SaleCard.Name),
                new XElement("balance", SaleCard.Balance));
                
            doc.Root.Add(card);
            doc.Save(file);

        }
 private void ClickMethod()
 {
    // MessageBox.Show("This is click command");
     foreach (SaleCardModel card in SaleCards)
     {
         if (card.Number.ToString().Equals(SaleCard.Number.ToString()))
         {
             MessageBox.Show("Данная карта уже существует");
             return;
         }
     }
    SaleCardModel newCard = new SaleCardModel(SaleCard.Number, SaleCard.Surname, SaleCard.Name);
    xmlp.AddSaleCard(newCard);
    MessageBox.Show("Карта была успешно зарегистрирована");
    
 }
예제 #6
0
        public static List<SaleCardModel> GetAllSaleCards()
        {
            XDocument doc = XDocument.Load(file);

            List<SaleCardModel> SaleCards = new List<SaleCardModel>();
            XNode node = doc.Root.FirstNode;

            while (node != null)
            {
                if (node.NodeType == System.Xml.XmlNodeType.Element)
                {
                    SaleCardModel SaleCard = new SaleCardModel();
                    XElement el = (XElement)node;

                    SaleCard.Number = Int32.Parse(el.Element("number").Value);
                    SaleCard.Surname = el.Element("surname").Value;
                    SaleCard.Name = el.Element("name").Value;
                    SaleCard.Balance = Single.Parse(el.Element("balance").Value);
                    SaleCards.Add(SaleCard);
                }
                node = node.NextNode;
            }
            return SaleCards;
        }