コード例 #1
0
        public void AddTester(Tester t)
        {
            bool flag = true;

            flag = Tester_by_id(t.Id);
            if (flag == true)
            {
                throw new Exception("Tester " + t.Id + " is Already exist!!");
            }


            flag = Trainee_by_id(t.Id);
            if (flag == true)
            {
                throw new Exception("There is a trinee with id: " + t.Id + " is Already exist!!");
            }

            try
            {
                //Create new    Tester XElement file
                XElement id              = new XElement("id", t.Id);
                XElement firstName       = new XElement("firstName", t.Name);
                XElement lastName        = new XElement("lastName", t.FamilyName);
                XElement name            = new XElement("name", firstName, lastName);
                XElement BIRTH_DAY       = new XElement("BIRTH_DAY", t.BirthDate);
                XElement City            = new XElement("City", t.MyAddress.city);
                XElement Street          = new XElement("Street", t.MyAddress.streetName);
                XElement Number          = new XElement("Number", t.MyAddress.houseNumber);
                XElement Address         = new XElement("Address", City, Street, Number);
                XElement Gender          = new XElement("Gender", t.MyGender);
                XElement Type_car        = new XElement("Type_car", t.ExpiranceCar);
                XElement seniority       = new XElement("seniority", t.YearsOfExperience);
                XElement MaxTestsPerWeek = new XElement("MaxTestsPerWeek", t.MaxTestsPerWeek);
                XElement MaxDistance     = new XElement("MaxDistance", t.MaxDistance);

                XElement PhoneNumber = new XElement("PhoneNumber", t.PhoneNumber);
                XElement hours       = new XElement("hours", t.get_hours_s());
                XElement Password    = new XElement("Password", t.Password);
                XMLDS.Testers.Add(new XElement("tester", id, name, BIRTH_DAY, Address, Gender, Type_car, seniority, MaxTestsPerWeek, MaxDistance, PhoneNumber, hours, Password));
                XMLDS.SaveTesters();
            }
            catch
            {
                throw new Exception("File upload problem");
            }
        }
コード例 #2
0
        public void UpdateTester(Tester t)
        {
            try
            {
                // Testers_Root = XElement.Load(testersPath);
            }
            catch (Exception)
            {
            }
            Tester tester_t = new Tester();

            try
            {
                XElement testerElement = (from stu in XMLDS.Testers.Elements()
                                          where stu.Element("id").Value == t.Id
                                          select stu).FirstOrDefault();
                testerElement.Element("Gender").Value          = t.MyGender.ToString();
                testerElement.Element("BIRTH_DAY").Value       = t.BirthDate.ToString();
                testerElement.Element("Type_car").Value        = t.ExpiranceCar.ToString();
                testerElement.Element("seniority").Value       = t.YearsOfExperience.ToString();
                testerElement.Element("MaxTestsPerWeek").Value = t.MaxTestsPerWeek.ToString();
                testerElement.Element("MaxDistance").Value     = t.MaxDistance.ToString();
                testerElement.Element("PhoneNumber").Value     = t.PhoneNumber;
                testerElement.Element("hours").Value           = t.get_hours_s();
                //      testerElement.Element("Email").Value = tester.email;
                testerElement.Element("name").Element("firstName").Value = t.Name;
                testerElement.Element("name").Element("lastName").Value  = t.FamilyName;
                testerElement.Element("Address").Element("City").Value   = t.MyAddress.city;
                testerElement.Element("Address").Element("Street").Value = t.MyAddress.streetName;
                testerElement.Element("Address").Element("Number").Value = t.MyAddress.houseNumber.ToString();
                testerElement.Element("Password").Value = t.Password;
                XMLDS.SaveTesters();
            }
            catch (Exception Ex)
            {
                throw new Exception(Ex.ToString());
            }
        }
コード例 #3
0
        public void DeleteTester(string id)
        {
            if (Tester_by_id(id) == false)
            {
                throw new Exception("Tester " + id + " not exist!");
            }



            XElement tester_XElement;

            try
            {
                tester_XElement = (from stu in XMLDS.Testers.Elements()
                                   where stu.Element("id").Value == id
                                   select stu).FirstOrDefault();
                tester_XElement.Remove();
                XMLDS.SaveTesters();
            }
            catch
            {
            }
        }