Пример #1
0
        public void addMother(Mother mother)      //is XML
        {
            var temp = (from m in XML_Source.Mothers.Elements()
                        where Convert.ToInt64(m.Element("id").Value) == mother._momID
                        select m).FirstOrDefault();

            if (temp != null)
            {
                throw new Exception("you are trying to add an existing mother.\n");
            }


            TimeSpan totalWeeklyHours = new TimeSpan();

            for (int i = 0; i < 6; i++)
            {
                totalWeeklyHours += (mother._endHour[i] - mother._startHour[i]);
                // totalWeeklyHours += (endHoure.Value - startHoure.Value);
            }
            mother._monthHours = ((totalWeeklyHours.Days * 24 + totalWeeklyHours.Hours + totalWeeklyHours.Minutes / 60.0) * 4);

            //dal.addMother(thisMom);

            // DataSource.motherList.Add(mother);



            XML_Source.Mothers.Add(mother.toXML());
            XML_Source.SaveMothers();
        }
Пример #2
0
        public void deleteMother(long thisMom)            //is XML
        {
            XElement motherElement = (from n in XML_Source.Mothers.Elements()
                                      where Convert.ToInt32(n.Element("id").Value) == thisMom
                                      select n).FirstOrDefault();

            if (motherElement == null)
            {
                throw new Exception("you are trying to delete a mother that does not exist\n");
            }

            // deleates childs that are related to the mother
            XElement ChildtDelete = (from n in XML_Source.Children.Elements()
                                     where Convert.ToInt64(n.Element("id").Value) == thisMom
                                     select n).FirstOrDefault();

            if (ChildtDelete != null)
            {
                ChildtDelete.Remove();
            }

            // deleates contracts that are related to the mother
            XElement ContractDelete = (from n in XML_Source.Contracts.Elements()
                                       where Convert.ToInt64(n.Element("id").Value) == thisMom
                                       select n).FirstOrDefault();

            if (ContractDelete != null)
            {
                ContractDelete.Remove();
            }


            motherElement.Remove();
            XML_Source.SaveMothers();



            ////else

            //// 1. delete all children of thisMom
            //var deleteAllKids = DataSource.childList.Where(c => c._momID == thisMom);

            //foreach (var child in deleteAllKids)
            //{
            //    DataSource.childList.Remove(child);
            //}

            //// 2. delete contractList that refers to thisMom (by her kids)
            //DataSource.contractList.RemoveAll(c => c._childID == thisMom);

            //// 3. now we can remove the thisMom
            //DataSource.motherList.RemoveAt(index);
            //XML_Source.Mothers.Remove(motherElement);
        }
Пример #3
0
        public void updateMother(Mother mother)           //is XML
        {
            XElement motherElement = (from m in XML_Source.Mothers.Elements()
                                      where Convert.ToInt32(m.Element("id").Value) == mother._momID
                                      select m).FirstOrDefault();

            if (motherElement != null)
            {
                motherElement.Remove();
                XML_Source.Mothers.Add(mother.toXML());
                XML_Source.SaveMothers();
            }
            else
            {
                throw new Exception("Mother doesn't exist in the system");
            }
        }