Exemplo n.º 1
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";
                }
            }
        }
Exemplo n.º 2
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.";
                    }
                }
            }
        }
Exemplo n.º 3
0
        private void cargaDatos(string DescFam = "")
        {
            VenusDbDataContext context = new VenusDbDataContext();
            var result = from fam in context.Familia
                         where System.Data.Linq.SqlClient.SqlMethods.Like(fam.xdescripcion, "%" + DescFam + "%") || DescFam == ""
                         select fam;

            if (result.ToList().Count > 0)
            {
                txtStatus.Text = "Success: Read Operation";
            }
            dgData.ItemsSource = result.ToList();
        }