Пример #1
0
        public void AddBus(DO.Bus bus)
        {
            XElement bussRootElem;

            try
            {
                bussRootElem = XmlTools.LoadListFromXMLElement(bussPath);
            }
            catch (DO.XmlFileLoadCreateException ex)
            {
                throw ex;
            }
            var temp = (from b in bussRootElem.Elements()
                        where b.Element("LicenseNum").Value == bus.LicenseNum.ToString()
                        select b).FirstOrDefault();

            if (temp != null)
            {
                if (!bool.Parse(temp.Element("IsDeleted").Value))
                {
                    throw new DO.BadBusException(bus.LicenseNum, "Duplicate License number of bus");
                }
            }

            bussRootElem.Add(XmlTools.CreateElement(bus));
            XmlTools.SaveListToXMLElement(bussRootElem, bussPath);
        }
Пример #2
0
        public void UpdateBus(DO.Bus bus)
        {
            XElement bussRootElem = XmlTools.LoadListFromXMLElement(bussPath);

            var busNode = (from b in bussRootElem.Elements()
                           where b.Element("LicenseNum").Value == bus.LicenseNum.ToString()
                           select b).FirstOrDefault();

            if (busNode == null)
            {
                throw new DO.BadBusException(0, "bus not found");
            }
            if (busNode.Element("IsDeleted").Value == true.ToString())
            {
                throw new DO.BadBusException(bus.LicenseNum, "bus not found");
            }

            busNode.UpdateElement(bus);
            XmlTools.SaveListToXMLElement(bussRootElem, bussPath);
        }