Esempio n. 1
0
        private void dgData_PreviewExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            VenusDbDataContext context        = new VenusDbDataContext();
            Familia            RegFamiliaGrid = dgData.SelectedItem as Familia;

            if (RegFamiliaGrid != null)
            {
                var familiaSeleccionada = (from fam in context.GetTable <Familia>()
                                           where fam.xempresa_id == RegFamiliaGrid.xempresa_id &&
                                           fam.xfamilia_id == RegFamiliaGrid.xfamilia_id
                                           select fam).SingleOrDefault();
                if (e.Command == DataGrid.DeleteCommand)
                {
                    if (!(MessageBox.Show("Are You Sure you want to Delete ?",
                                          "Confirm Delete !", MessageBoxButton.YesNo) == MessageBoxResult.Yes))
                    {
                        e.Handled = true;
                    }
                    else
                    {
                        context.Familia.DeleteOnSubmit(familiaSeleccionada);
                        context.SubmitChanges();
                        txtStatus.Text = "Success: Selected Data Deleted.";
                    }
                }
            }
        }
Esempio n. 2
0
        private void dgData_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
        {
            if (e.EditAction == DataGridEditAction.Commit)
            {
                VenusDbDataContext context = new VenusDbDataContext();
                Familia            famgrid = e.Row.DataContext as Familia;

                var matchedData = (from famtabla in context.GetTable <Familia>()
                                   where famgrid.xempresa_id == famtabla.xempresa_id &&
                                   famgrid.xfamilia_id == famtabla.xfamilia_id
                                   select famtabla).SingleOrDefault();

                if (matchedData == null)
                {
                    Table <Familia> famTable = context.GetTable <Familia>();

                    Familia registroFamilia = new Familia();
                    registroFamilia.xempresa_id  = famgrid.xempresa_id;
                    registroFamilia.xfamilia_id  = famgrid.xfamilia_id;
                    registroFamilia.xdescripcion = famgrid.xdescripcion;

                    famTable.InsertOnSubmit(registroFamilia);
                    famTable.Context.SubmitChanges();

                    txtStatus.Text = "Success: Data Inserted";
                }
                else
                {
                    matchedData.xdescripcion = famgrid.xdescripcion;
                    context.SubmitChanges();
                    txtStatus.Text = "Success: Data Updated";
                }
            }
        }