Exemplo n.º 1
0
        public void AddContract(Contract contract, bool update)
        {
            // Searching for the contract number in the contract's XML file (returns 0 if not found)
            int temp = (from n in DataSourceXml.Contracts.Elements()
                        where int.Parse(n.Element("ContractNumber").Value) == contract.ContractNumber
                        select int.Parse(n.Element("ContractNumber").Value)).FirstOrDefault();

            if (temp != 0)
            {
                throw new Exception("ERROR: It's not a new contract !!!");
            }
            else
            {
                if (!update) // Makes sure that we don't updates an exist contract
                {
                    int theLastContractNumber = FIRST_SERIAL_CONTRACT;
                    if (DataSourceXml.Contracts.Elements().Any())
                    {
                        // Finds the number of the last contract that added
                        theLastContractNumber = (from n in DataSourceXml.Contracts.Elements()
                                                 select int.Parse(n.Element("ContractNumber").Value)).Max();
                    }
                    contract.ContractNumber = theLastContractNumber + 1; // Update the current contract number
                }
                DataSourceXml.Contracts.Add(contract.toXML());
                DataSourceXml.SaveInContracts();
            }
        }
Exemplo n.º 2
0
        //--------------menage mothers---------------//

        /// <summary>
        /// adds a mother to the data base
        /// Exception:
        /// in the data base is are a mother with the same ID
        /// </summary>
        /// <param name="mam">mother object to add</param>
        public void addMother(Mother mam)
        {
            if (DataSourceXml.MotherRoot.Elements().Any(x => (Convert.ToInt32(x.Element("Id").Value)) == mam.Id))
            {
                throw new DALException("ERROR: There is the same mother id already");
            }
            DataSourceXml.MotherRoot.Add(mam.MotherToXML());
            DataSourceXml.saveMothers();
        }
Exemplo n.º 3
0
        //--------------menage children----------------//

        /// <summary>
        /// adds a child to the data base
        /// Exception:
        /// there is are the same Id in the data base.
        /// </summary>
        /// <param name="child">child object to add </param>
        public void addChild(Child child)
        {
            if (DataSourceXml.ChildRoot.Elements().Any(x => (Convert.ToInt32(x.Element("Id").Value)) == child.Id))
            {
                throw new DALException("There is the same child id alredy");
            }
            DataSourceXml.ChildRoot.Add(child.Clone().ChildToXML());
            DataSourceXml.saveChildren();
        }
Exemplo n.º 4
0
        /// <summary>
        /// update mothers info in list
        /// </summary>
        /// <param name="mother"></param>
        public void updateMother(Mother mother)
        {
            XElement motherElement = (from m in DataSourceXml.Mothers.Elements()
                                      where Convert.ToInt32(m.Element("id").Value) == mother.id
                                      select m).FirstOrDefault();

            if (motherElement != null)
            {
                motherElement.ReplaceWith(mother.toXML());
                DataSourceXml.SaveMothers();
            }
            else
            {
                throw new Exception("the mother is not in the system.\n");
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// adds a mother to list
        /// </summary>
        /// <param name="mother"></param>
        public void addMother(Mother mother)
        {
            var temp = (from m in DataSourceXml.Mothers.Elements()
                        where Convert.ToInt32(m.Element("id").Value) == mother.id
                        select m).FirstOrDefault();

            if (temp == null)
            {
                DataSourceXml.Mothers.Add(mother.toXML());
                DataSourceXml.SaveMothers();
            }
            else
            {
                throw new Exception("you are trying to add a existing mother.\n");
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// gets a nanny from UI and updates the information in the DS
        /// </summary>
        /// <param name="nanny"></param>
        public void updateNanny(Nanny nanny)
        {
            XElement nannyElement = (from n in DS.DataSourceXml.Nannys.Elements()
                                     where Convert.ToInt32(n.Element("id").Value) == nanny.id
                                     select n).FirstOrDefault();

            if (nannyElement != null)
            {
                nannyElement.ReplaceWith(nanny.toXML());
                DataSourceXml.SaveNannys();
            }
            else
            {
                throw new Exception("the nanny is not in the system.\n");
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// removes a nanny from DS
        /// </summary>
        /// <param name="nanny"></param>
        public void deleteNanny(Nanny nanny)
        {
            XElement nannyElement = (from n in DataSourceXml.Nannys.Elements()
                                     where Convert.ToInt32(n.Element("id").Value) == nanny.id
                                     select n).FirstOrDefault();

            if (nannyElement != null)
            {
                nannyElement.Remove();
                DataSourceXml.SaveNannys();
            }
            else
            {
                throw new Exception("nanny is not in list\n");
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// updates contract info
        /// </summary>
        /// <param name="contract"></param>
        public void updateContract(Contract contract)
        {
            var temp = (from c in DataSourceXml.Contracts.Elements()
                        where Convert.ToInt32(c.Element("numberOfContract").Value) == contract.numberOfContract
                        select c).FirstOrDefault();

            if (temp != null)
            {
                temp.ReplaceWith(contract.toXML());
                DataSourceXml.SaveContracts();
            }
            else
            {
                throw new Exception("the contract is not in the system.\n");
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// removes a contract
        /// </summary>
        /// <param name="contract"></param>
        public void deleteContract(Contract contract)
        {
            XElement contractElement = (from n in DataSourceXml.Contracts.Elements()
                                        where Convert.ToInt32(n.Element("numberOfContract").Value) == contract.numberOfContract
                                        select n).FirstOrDefault();

            if (contractElement != null)
            {
                contractElement.Remove();
                DataSourceXml.SaveContracts();
            }
            else
            {
                throw new Exception("the contract is not in the system.\n");
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// checks if nanny exists in DS and then adds to DS
        /// </summary>
        /// <param name="nanny"></param>
        public void addNanny(Nanny nanny)
        {
            var temp = (from n in DataSourceXml.Nannys.Elements()
                        where Convert.ToInt32(n.Element("id").Value) == nanny.id
                        select n).FirstOrDefault();

            if (temp == null)
            {
                DataSourceXml.Nannys.Add(nanny.toXML());
                DataSourceXml.SaveNannys();
            }
            else
            {
                throw new Exception("nanny already in list\n");
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// adds a contract to list
        /// </summary>
        /// <param name="contract"></param>
        public void addContract(Contract contract)
        {
            var temp = (from c in DataSourceXml.Contracts.Elements()
                        where Convert.ToInt32(c.Element("numberOfContract").Value) == contract.numberOfContract
                        select c).FirstOrDefault();

            if (temp == null)
            {
                DataSourceXml.Contracts.Add(contract.toXML());
                DataSourceXml.SaveContracts();
            }
            else
            {
                throw new Exception("the contract is already in the system.\n");
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// updates child info
        /// </summary>
        /// <param name="child"></param>
        public void updateChild(Child child)
        {
            XElement childElement = (from c in DataSourceXml.Children.Elements()
                                     where Convert.ToInt32(c.Element("id").Value) == child.id
                                     select c).FirstOrDefault();

            if (childElement != null)
            {
                childElement.ReplaceWith(child.toXML());
                DataSourceXml.SaveChildren();
            }
            else
            {
                throw new Exception("the child is not in the system.\n");
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// removes child from list
        /// </summary>
        /// <param name="child"></param>
        public void deleteChild(Child child)
        {
            XElement childElement = (from n in DataSourceXml.Children.Elements()
                                     where Convert.ToInt32(n.Element("id").Value) == child.id
                                     select n).FirstOrDefault();

            if (childElement != null)
            {
                childElement.Remove();
                DataSourceXml.SaveChildren();
            }
            else
            {
                throw new Exception("child is not in the system\n");
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// adds child to list
        /// </summary>
        /// <param name="child"></param>
        public void addChild(Child child)
        {
            var temp = (from c in DataSourceXml.Children.Elements()
                        where Convert.ToInt32(c.Element("id").Value) == child.id
                        select c).FirstOrDefault();

            if (temp == null)
            {
                DataSourceXml.Children.Add(child.toXML());
                DataSourceXml.SaveChildren();
            }
            else
            {
                throw new Exception("you are trying to add a existing child.\n");
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// delete nanny from the collection
        /// </summary>
        /// <param name="id">id number of the nanny</param>
        public void removeNanny(int id)
        {
            XElement result = (from nanny in DataSourceXml.NannyRoot.Elements()
                               where Convert.ToInt32(nanny.Element("Id").Value) == id
                               select nanny).FirstOrDefault();

            if (result != null)
            {
                result.Remove();
                DataSourceXml.saveContracts();
            }
            else
            {
                throw new DALException("ERROR: There is no nanny with this id to remove");
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// deletes mother from list
        /// </summary>
        /// <param name="mother"></param>
        public void deleteMother(Mother mother)
        {
            XElement motherElement = (from n in DataSourceXml.Mothers.Elements()
                                      where Convert.ToInt32(n.Element("id").Value) == mother.id
                                      select n).FirstOrDefault();

            if (motherElement != null)
            {
                motherElement.Remove();
                DataSourceXml.SaveMothers();
            }
            else
            {
                throw new Exception("you are trying to delete a mother that does not exist\n");
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// dalete contract from the data base
        /// </summary>
        /// <param name="ContractNumber">contract number to remove</param>
        public void removeContract(int ContractNumber)
        {
            XElement result = (from contract in DataSourceXml.ContractRoot.Elements()
                               where Convert.ToInt32(contract.Element("ContractNumber").Value) == ContractNumber
                               select contract).FirstOrDefault();

            if (result != null)
            {
                result.Remove();
                DataSourceXml.saveContracts();
            }
            else
            {
                throw new DALException("ERROR: There is no contract with this number to remove");
            }
        }
Exemplo n.º 18
0
        public void removeMother(int id)
        {
            XElement result = (from mother in DataSourceXml.MotherRoot.Elements()
                               where Convert.ToInt32(mother.Element("Id").Value) == id
                               select mother).FirstOrDefault();

            if (result != null)
            {
                result.Remove();
                DataSourceXml.saveMothers();
            }
            else
            {
                throw new DALException("ERROR: There is no Mother with this id to remove");
            }
        }
Exemplo n.º 19
0
        //--------------menage nannis----------------//

        /// <summary>
        /// adds a nanny to the data base
        /// Exception:
        /// in the data base is are a nanny with the same ID
        /// </summary>
        /// <param name="nan">nanny object to add</param>
        public void addNanny(Nanny nan)
        {
            var check = (from nanny in DataSourceXml.NannyRoot.Elements()
                         where (Convert.ToInt32(nanny.Element("Id").Value)) == nan.Id
                         select nanny).FirstOrDefault();

            if (check == null)
            {
                DataSourceXml.NannyRoot.Add(nan.Clone().NannyToXml());
                DataSourceXml.saveNannis();
            }
            else
            {
                throw new Exception("There is the same nanny already");
            }
        }
Exemplo n.º 20
0
        /// <summary>
        /// delete a Child from the data base
        /// </summary>
        /// <param name="id">childs id to remove</param>
        public void removeChild(int id)
        {
            XElement result = (from child in DataSourceXml.ChildRoot.Elements()
                               where Convert.ToInt32(child.Element("Id").Value) == id
                               select child).FirstOrDefault();

            if (result != null)
            {
                result.Remove();
                DataSourceXml.saveChildren();
            }
            else
            {
                throw new DALException("ERROR: There is no Child with this id to remove");
            }
        }
Exemplo n.º 21
0
        public void RemoveChild(int childId)
        {
            // Searching for the child instance in the children XML file (returns null if not found)
            XElement childToRemove = (from n in DataSourceXml.Children.Elements()
                                      where int.Parse(n.Element("Id").Value) == childId
                                      select n).FirstOrDefault();

            if (childToRemove == null)
            {
                throw new Exception("ERROR: The child with id: " + childId + " not exist in the database !!!");
            }
            else
            {
                childToRemove.Remove();
                DataSourceXml.SaveInChildren();
            }
        }
Exemplo n.º 22
0
        public void RemoveMother(int motherId)
        {
            // Searching for the mother instance in the mother's XML file (returns null if not found)
            XElement motherToRemove = (from n in DataSourceXml.Mothers.Elements()
                                       where int.Parse(n.Element("Id").Value) == motherId
                                       select n).FirstOrDefault();

            if (motherToRemove == null)
            {
                throw new Exception("ERROR: The mother with id: " + motherId + " not exist in the database !!!");
            }
            else
            {
                motherToRemove.Remove();
                DataSourceXml.SaveInMothers();
            }
        }
Exemplo n.º 23
0
        public void AddNanny(Nanny nanny)
        {
            // Searching for the nanny ID in the nanny's XML file (returns 0 if not found)
            int temp = (from n in DataSourceXml.Nannies.Elements()
                        where int.Parse(n.Element("Id").Value) == nanny.Id
                        select int.Parse(n.Element("Id").Value)).FirstOrDefault();

            if (temp != 0)
            {
                throw new Exception("ERROR: The nanny with id: " + nanny.Id + " already exist in the database !!!");
            }
            else
            {
                DataSourceXml.Nannies.Add(nanny.toXML());
                DataSourceXml.SaveInNannies();
            }
        }
Exemplo n.º 24
0
        public void AddChild(Child child)
        {
            // Searching for the child ID in the children XML file (returns 0 if not found)
            int temp = (from n in DataSourceXml.Children.Elements()
                        where int.Parse(n.Element("Id").Value) == child.Id
                        select int.Parse(n.Element("Id").Value)).FirstOrDefault();

            if (temp != 0)
            {
                throw new Exception("ERROR: The child with id: " + child.Id + " already exist in the database !!!");
            }
            else
            {
                DataSourceXml.Children.Add(child.toXML());
                DataSourceXml.SaveInChildren();
            }
        }
Exemplo n.º 25
0
        public void AddMother(Mother mother)
        {
            // Searching for the mother ID in the mother's XML file (returns 0 if not found)
            int temp = (from n in DataSourceXml.Mothers.Elements()
                        where int.Parse(n.Element("Id").Value) == mother.Id
                        select int.Parse(n.Element("Id").Value)).FirstOrDefault();

            if (temp != 0)
            {
                throw new Exception("ERROR: The mother with id: " + mother.Id + " already exist in the database !!!");
            }
            else
            {
                DataSourceXml.Mothers.Add(mother.toXML());
                DataSourceXml.SaveInMothers();
            }
        }
Exemplo n.º 26
0
        public void RemoveNanny(int nannyId)
        {
            // Searching for the nanny instance in the nanny's XML file (returns null if not found)
            XElement nannyToRemove = (from n in DataSourceXml.Nannies.Elements()
                                      where int.Parse(n.Element("Id").Value) == nannyId
                                      select n).FirstOrDefault();

            if (nannyToRemove == null)
            {
                throw new Exception("ERROR: The nanny with id: " + nannyId + " not exist in the database !!!");
            }
            else
            {
                nannyToRemove.Remove();
                DataSourceXml.SaveInNannies();
            }
        }
Exemplo n.º 27
0
        public void RemoveContract(int contractNumber)
        {
            // Searching for the contract instance in the contract's XML file (returns null if not found)
            XElement contractToRemove = (from n in DataSourceXml.Contracts.Elements()
                                         where int.Parse(n.Element("ContractNumber").Value) == contractNumber
                                         select n).FirstOrDefault();

            if (contractToRemove == null)
            {
                throw new Exception("ERROR: The contract with serial number: " + contractNumber + " not exist in the database !!!");
            }
            else
            {
                contractToRemove.Remove();
                DataSourceXml.SaveInContracts();
            }
        }
Exemplo n.º 28
0
        //--------------menage contracts----------------//

        /// <summary>
        /// adds a contract to the data base
        /// Exception:
        /// there are a contract for this child
        /// in the data base no are a mother or nanny with approprite ID
        /// </summary>
        /// <param name="con">object of contract to add</param>
        public void addContract(Contract con)
        {
            if (DataSourceXml.ContractRoot.Elements().Any(x => (Convert.ToInt32(x.Element("ChildId").Value) == con.ChildId)))
            {
                throw new DALException("There is the same contract with this child id already");
            }
            if (DataSourceXml.NannyRoot.Elements().All(x => (Convert.ToInt32(x.Element("Id").Value) != con.NannyId)))
            {
                throw new DALException("ERROR: There is no are a nanny  with this id");
            }
            if (DataSourceXml.MotherRoot.Elements().All(x => (Convert.ToInt32(x.Element("Id").Value) != con.MotherId)))
            {
                throw new DALException("ERROR: There is no are a Mother with this id");
            }
            //con.ContractNumber = ++Range;

            DataSourceXml.ContractRoot.Add(con.Clone().ContantToXML());
            DataSourceXml.saveContracts();
        }
Exemplo n.º 29
0
        /// <summary>
        /// gives a contract a serial number
        /// </summary>
        /// <param name="contract"></param>
        /// <returns></returns>
        public bool initalizeContractNumber(Contract contract)
        {
            if (IdExist(contract.NannysId) && IdExist(getMotherId(contract.childId)))
            {
                //gets the serial number from XML file
                int contractsSerialNumber = Int32.Parse(DataSourceXml.ContractNumber.Element("serialNumber").Value);
                contract.numberOfContract = ++contractsSerialNumber;

                DataSourceXml.ContractNumber.Element("serialNumber").SetValue(contractsSerialNumber);
                DataSourceXml.SaveNumbers();

                contract.isSingedContract = true;           // now contract is signed

                return(true);
            }
            else
            {
                return(false);
            }
        }