Ejemplo n.º 1
0
        /*This method means the method DeleteOnSubmit status delete data into a pending state, 
         * then the method SubmitChanges performs the necessary changes within the database, this method requires the necessary arguments for deleting data, 
         * all the while using the class that exposes all ContactDataContext methods 
         * needed in the iteration with the data as we shall see in subsequent methods.
         * Is then performed using a foreach loop iteration variable iddeletejob and will be eliminated on all data that 
         * satisfy the predicate in the Where operator, for both the table job for the person table.
         */
        public static void DeleteData(string name, string surname)
        {
            using (var ctx = new ContactDataContext(Properties.Settings.Default.path))
            {
                try
                {
                    var ideletejob = ctx.PERSON.Where(w => w.NAME.Equals(name) && w.SURNAME.Equals(surname));

                    foreach (var item in ideletejob.ToList())
                    {
                        var deletejob = ctx.JOB.Where(w => w.IDPERSON.Equals(item.ID));

                        if (!deletejob.Any()) return;
                        ctx.JOB.DeleteOnSubmit(deletejob.First());

                        var deleteperson = ctx.PERSON
                            .Where(w => w.NAME.Equals(name) && w.SURNAME.Equals(surname));

                        if (!deleteperson.Any()) return;

                        ctx.PERSON.DeleteOnSubmit(deleteperson.First());
                        ctx.SubmitChanges();
                    }
                }

                catch (System.Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show(ex.Message);
                }
            }
        }
Ejemplo n.º 2
0
        /*This method means the method SubmitChanges performs the necessary changes within the database, 
         * this method requires the necessary arguments for the update data, all the while by ContactDataContext class that exposes all the methods needed in the               *iteration with the data, runs a foreach loop on the variable idupdateperson and updated all the data that meets the conditions 
         * of the predicate in the Where operator.
         */
        public static void UpdateData(string name, string surname, string address, string zipcode, string city, string state, string activity)
        {
            using (var ctx = new ContactDataContext(Properties.Settings.Default.path))
            {
                var idperson = ctx.PERSON.Where(w => w.NAME.Equals(name) && w.SURNAME.Equals(surname));

                foreach (var itemperson in idperson.ToList())
                {
                    var updateperson = ctx.PERSON.Where(w => w.NAME.Equals(name) && w.SURNAME.Equals(surname));

                    itemperson.NAME = name.ToUpper();
                    itemperson.SURNAME = surname.ToUpper();
                    itemperson.ADDRESS = address.ToUpper();
                    itemperson.ZIPCODE = zipcode.ToUpper();
                    itemperson.CITY = city.ToUpper();

                    var idjob = ctx.JOB.Where(w => w.IDPERSON.Equals(itemperson.ID));

                    foreach (var itemjob in idjob.ToList())
                    {
                        var updatejob = ctx.JOB.Where(w => w.ID.Equals(itemperson.ID));

                        itemjob.STATE = state;
                        itemjob.ACTIVITY = activity;
                    }

                    ctx.SubmitChanges();
                }
            }
        }
Ejemplo n.º 3
0
        /*This method means the method InsertOnSubmit status insert data into a pending state, 
         * then the method SubmitChanges performs the necessary changes within the database, this method requires the necessary arguments for entering data, 
         * all the while using the class that exposes all ContactDataContext methods 
         * needed in the iteration with the data as we shall see in subsequent methods.
         */
        public static void InsertData(string name, string surname, string address, string zipcode, string city, string state, string activity)
        {
            using (var ctx = new ContactDataContext(Properties.Settings.Default.path))
            {
                var newperson = new PERSON
                {
                    NAME = name.ToUpper(),
                    SURNAME = surname.ToUpper(),
                    ADDRESS = address.ToUpper(),
                    ZIPCODE = zipcode.ToUpper(),
                    CITY = city.ToUpper()
                };

                ctx.PERSON.InsertOnSubmit(newperson);
                ctx.SubmitChanges();


                var newjob = new JOB
                {
                    IDPERSON = newperson.ID,
                    STATE = state,
                    ACTIVITY = activity
                };

                ctx.JOB.InsertOnSubmit(newjob);
                ctx.SubmitChanges();
            }
        }