Ejemplo n.º 1
0
        private void SaveDependents()
        {
            try
            {
                foreach (var xe in db.t_TempEmpDependents.Where(p => p.EmpID == adminusers.Text))
                {
                    depName2         = xe.Name;
                    depBirthDate2    = Convert.ToString(xe.BirthDate);
                    depRelationship2 = xe.Relationship;
                    depOccupation2   = xe.Occupation;
                    depMaidenName2   = xe.MaidenName;

                    var newdep = new t_EmpDependents();
                    newdep.EmpID        = NewEmpID;
                    newdep.Name         = depName2;
                    newdep.BirthDate    = Convert.ToDateTime(depBirthDate2);
                    newdep.Relationship = depRelationship2;
                    newdep.Occupation   = depOccupation2;
                    newdep.MaidenName   = depMaidenName2;
                    newdep.LastUpdate   = DateTime.Now;
                    db.t_EmpDependents.Add(newdep);
                }

                db.SaveChanges();
                removeTempDependents();
            }
            catch { }
        }
        private void gridDependent_RowEditEnded(object sender, GridViewRowEditEndedEventArgs e)
        {
            if (e.EditAction == GridViewEditAction.Cancel)
            {
                return;
            }
            if (e.EditOperationType == GridViewEditOperationType.Insert)
            {
                try
                {
                    db.SaveChanges();
                    bindDependents();
                }
                catch { }
            }
            else if (e.EditOperationType == GridViewEditOperationType.Edit)
            {
                // try
                //{
                int ss = 0;

                foreach (var data in gridDependent.SelectedItems)
                {
                    t_EmpDependents myData = data as t_EmpDependents;
                    depName         = myData.Name;
                    depBirthDate    = Convert.ToString(myData.BirthDate);
                    depRelationship = myData.Relationship;
                    depOccupation   = myData.Occupation;
                    depMaidenName   = myData.MaidenName;
                    ss = Convert.ToInt32(myData.DependentID);
                }

                var dep = db.t_EmpDependents.Where(x => x.DependentID == ss).FirstOrDefault();

                dep.BirthDate    = Convert.ToDateTime(depBirthDate);
                dep.Relationship = depRelationship;
                dep.Occupation   = depOccupation;
                dep.MaidenName   = depMaidenName;

                db.Entry(dep).State = EntityState.Modified;

                db.SaveChanges();

                bindDependents();
                // }
                //catch { }
            }
        }
 private void gridDependent_AddingNewDataItem(object sender, Telerik.Windows.Controls.GridView.GridViewAddingNewEventArgs e)
 {
     try
     {
         var depen = new t_EmpDependents();
         depen.EmpID        = EmpID.Text;
         depen.Name         = depName;
         depen.BirthDate    = Convert.ToDateTime(depBirthDate);
         depen.Relationship = depRelationship;
         depen.Occupation   = depOccupation;
         depen.MaidenName   = depMaidenName;
         depen.LastUpdate   = DateTime.Now;
         e.NewObject        = depen;
         db.t_EmpDependents.Add(depen);
     }
     catch { }
 }
 private void gridDependent_PreviewKeyDown(object sender, KeyEventArgs e)
 {
     try
     {
         if (e.Key == Key.Delete)
         {
             foreach (var data in gridDependent.SelectedItems)
             {
                 t_EmpDependents myData = data as t_EmpDependents;
                 var             delete = db.t_EmpDependents.Where(p => p.EmpID == EmpID.Text && p.Name == myData.Name).FirstOrDefault();
                 db.t_EmpDependents.Remove(delete);
                 db.SaveChanges();
             }
         }
         else
         {
             return;
         }
     }
     catch { }
 }