예제 #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();
            }
        }
예제 #2
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();
            }
        }