Ejemplo n.º 1
0
        public DO.Bus GetBus(int licenseNum)
        {
            XElement bussRootElem = XmlTools.LoadListFromXMLElement(bussPath);

            DO.Bus bus = (from b in bussRootElem.Elements()
                          where int.Parse(b.Element("LicenseNum").Value) == licenseNum
                          select new DO.Bus()
            {
                LicenseNum = int.Parse(b.Element("LicenseNum").Value),
                FromDate = DateTime.Parse(b.Element("FromDate").Value),
                FuelRemain = double.Parse(b.Element("FuelRemain").Value),
                IsDeleted = bool.Parse(b.Element("IsDeleted").Value),
                KilometersAfterFueling = double.Parse(b.Element("KilometersAfterFueling").Value),
                KilometersAfterTreatment = double.Parse(b.Element("KilometersAfterTreatment").Value),
                LastTreatment = DateTime.Parse(b.Element("LastTreatment").Value),
                Status = (DO.BusStatus)Enum.Parse(typeof(DO.BusStatus), b.Element("Status").Value),
                TotalTrip = double.Parse(b.Element("TotalTrip").Value)
            }
                          ).FirstOrDefault();

            if (bus != null && !bus.IsDeleted)
            {
                return(bus);
            }
            else
            {
                throw new DO.BadBusException(licenseNum, "bus not found");
            }
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        public IEnumerable <DO.Bus> GetAllBuss()
        {
            var bussRootElem = XmlTools.LoadListFromXMLElement(bussPath);
            var list         = from b in bussRootElem.Elements()
                               where !bool.Parse(b.Element("IsDeleted").Value)
                               select new DO.Bus()
            {
                LicenseNum               = int.Parse(b.Element("LicenseNum").Value),
                FromDate                 = DateTime.Parse(b.Element("FromDate").Value),
                FuelRemain               = double.Parse(b.Element("FuelRemain").Value),
                IsDeleted                = bool.Parse(b.Element("IsDeleted").Value),
                KilometersAfterFueling   = double.Parse(b.Element("KilometersAfterFueling").Value),
                KilometersAfterTreatment = double.Parse(b.Element("KilometersAfterTreatment").Value),
                LastTreatment            = DateTime.Parse(b.Element("LastTreatment").Value),
                Status    = (DO.BusStatus)Enum.Parse(typeof(DO.BusStatus), b.Element("Status").Value),
                TotalTrip = double.Parse(b.Element("TotalTrip").Value)
            };

            return(list);
        }
Ejemplo n.º 4
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);
        }