private void GridSubCategory_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
        {
            bool ok = false;

            //var _emp = e.Row.Item as Employee;
            SubCategoryVO cat = e.Row.DataContext as SubCategoryVO;
            _cvm = (SubCategoryViewModel)ViewModel;
            cat.ModifiedDate = DateTime.Now;

            ok = _cvm.ManageSave(cat);

            //if (ok)
            //{
            //    MessageBox.Show(SubCategoryModule.Properties.Resources.SaveSuccess,
            //        SubCategoryModule.Properties.Resources.SaveSubCategoryResult,
            //        MessageBoxButton.OK,
            //        MessageBoxImage.Information);
            //}
            //else
            //{
            //    MessageBox.Show(SubCategoryModule.Properties.Resources.SaveSuccess,
            //        SubCategoryModule.Properties.Resources.SaveSubCategoryResult,
            //        MessageBoxButton.OK,
            //        MessageBoxImage.Exclamation);
            //}
        }
        private void GrdCountries_OnRowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
        {
            var country = e.Row.DataContext as Country;
            if (isInsertMode && country != null)
            {
                var insertRecord = MessageBox.Show("Do you want to add " + country.Name + " as a new country?",
                    "Confirm", MessageBoxButton.YesNo, MessageBoxImage.Question);
                if (insertRecord == MessageBoxResult.Yes)
                {
                    var newCountry = new Country();
                    newCountry.Name = country.Name;
                    newCountry.Language = country.Language;
                    newCountry.Flag = country.Flag;

                    GetDataContext().Countries.Add(newCountry);
                    
                    //dgEmp.ItemsSource = GetEmployeeList();
                    MessageBox.Show(country.Name + " has being added!",
                        "Inserting Record", MessageBoxButton.OK, MessageBoxImage.Information);
                }
                //else
                //    dgEmp.ItemsSource = GetEmployeeList();
            }
            //context.SaveChanges();
        }
Esempio n. 3
0
        void dg_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
        {
            if (e.EditAction == DataGridEditAction.Commit)
            {

            }
        }
        private void ViewerGrid_RowEditEnding(object sender, System.Windows.Controls.DataGridRowEditEndingEventArgs e)
        {
            // Save changes and tell other viewers about the change
            int currow = 0;

            currow = this.BankGrid.SelectedIndex;
            // Save current row so we can reposition correctly at end of the entire refresh process
            Flags.SqlBankCurrentIndex = currow;
            BankAccountViewModel ss = new BankAccountViewModel();

            ss = this.BankGrid.SelectedItem as BankAccountViewModel;
            // This is the NEW DATA from the current row
            SQLHandlers sqlh = new SQLHandlers();

            sqlh.UpdateDbRowAsync("BANKACCOUNT", ss, this.BankGrid.SelectedIndex);

            this.BankGrid.SelectedIndex = Flags.SqlBankCurrentIndex;
            this.BankGrid.ScrollIntoView(Flags.SqlBankCurrentIndex);
            // Notify EditDb to upgrade its grid
            if (Flags.CurrentEditDbViewer != null)
            {
                Flags.CurrentEditDbViewer.UpdateGrid("BANKACCOUNT");
            }

            // ***********  DEFINITE WIN  **********
            // This DOES trigger a notidfication to SQLDBVIEWER for sure !!!   14/5/21
            EventControl.TriggerViewerDataChanged(2, this.BankGrid.SelectedIndex, "BANKACCOUNT");
        }
 private void datagridItems_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
 {
     //Binding="{Binding BaseSalary,UpdateSourceTrigger=PropertyChanged}"
     SalarySheetItem item = (SalarySheetItem)e.Row.DataContext;
     //e.Row.DataContext修改后的数据对象
     new SalarySheetDAL().Update(item);
 }
Esempio n. 6
0
        private void GridCoffeePods_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
        {
            CoffeePodModel ctmGridModel = e.Row.DataContext as CoffeePodModel;

            if (ctmGridModel != null)
            {
                if (ctmGridModel.CoffeePodId > 0)
                {
                    //...Edit Code Here
                    DataAccess.UpdateCoffeePod(ctmGridModel);

                    //...Reload Grid
                    GridCoffeePods.ItemsSource = DataAccess.ReadData<CoffeePodModel>(DataFiles.FILE_COFFEE_PODS);
                }
                else
                {
                    //...Insert Code

                    //...Update ID
                    int iLastId = DataAccess.ReadDataAsList<CoffeePodModel>(DataFiles.FILE_COFFEE_PODS).Count() + 1;
                    ctmGridModel.CoffeePodId = iLastId;

                    //...Add to List
                    DataAccess.AddCoffeePod(ctmGridModel);

                    //...Reload Grid
                    GridCoffeePods.ItemsSource = DataAccess.ReadData<CoffeePodModel>(DataFiles.FILE_COFFEE_PODS);
                }
            }

            isEdit = false;
        }
Esempio n. 7
0
 private void DataGrid_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
 {
     DinerMax3000.Business.MenuItem newMenuItem = e.Row.Item as DinerMax3000.Business.MenuItem;
     if(newMenuItem != null &&e.EditAction==DataGridEditAction.Commit && e.Row.IsNewItem)
     {
         DinerMax3000.WPFClient.DinerMax3000ViewModel currentViewModel = (DinerMax3000.WPFClient.DinerMax3000ViewModel)DataContext;
         currentViewModel.NewMenuItems.Add(newMenuItem);
     }
 }
Esempio n. 8
0
        private static void OnRowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
        {
            var d = sender as DependencyObject;
            var c = d != null ? DataGridProperties.GetRowEditEndingCommand(d) : null;

            if (c != null && c.CanExecute(d))
            {
                c.Execute(d);
            }
        }
        private void GridCategory_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
        {
            bool ok = false;

            CategoryVO cat = e.Row.DataContext as CategoryVO;
            _cvm = (CategoryViewModel) ViewModel;
            cat.ModifiedDate = DateTime.Now;

            ok = _cvm.ManageSave(cat);          
        }
        private void dg_data_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
        {
            if (e.EditAction == DataGridEditAction.Commit)
            {

               // FormulaOneDriver driver = e.Row.DataContext as FormulaOneDriver;

               // driver.Save();

            }
        }
        private async void JavascriptGrid_OnRowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
        {
            if (e.EditAction != DataGridEditAction.Commit) return;
            var s = e.Row.DataContext as Scene;
            if (s != null)
                if (string.IsNullOrEmpty(s.Name))
                    s.Name = "New Command";

            //have to add , UpdateSourceTrigger=PropertyChanged to have the data updated in time for this event
            await SaveChangesAsync();
        }
Esempio n. 12
0
        private void UserList_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
        {
            try
            {
                // Approach: When user finish changes values of cells in row, trigger update
                // Get database Id of user from selected row in datagrid
                object item = UserList.SelectedItem;
                string ID = (UserList.SelectedCells[0].Column.GetCellContent(item) as TextBlock).Text;
                //MessageBox.Show(ID);

                //convert ID to int
                int selected = Int32.Parse(ID);

                //object which stores all deta from selected row
                dynamic userRow = UserList.SelectedItem;
                int tmp = 0;
                if (userRow.UserAccountType == "Administrator")
                {
                    tmp = 1;
                }
                else
                {
                    tmp = 2;
                }

                //MessageBox.Show(userRow.UserName);
                //MessageBox.Show(userRow.UserEmail);
                DiamondDBEntities _ctx = new DiamondDBEntities();
                Users userUpdate = (from user in _ctx.Users
                                    where user.Id == selected // int selected!!! you know what i want up to date
                                    select user).First();

                // update values in database by select from 'dynamic userRow' properties
                // UserName UserEmail etc. are in xaml in line:
                // <TextBox Text="{Binding UserLogin, UpdateSourceTrigger=PropertyChanged}"/>
                // need to update 'dynamic userRow' with Trigger, when user write text into cell

                userUpdate.Name = userRow.UserName;
                userUpdate.Surname = userRow.UserSurname;
                userUpdate.PhoneNum = userRow.UserPhoneNumber;
                userUpdate.Email = userRow.UserEmail;
                userUpdate.Position = userRow.UserPosition;
                userUpdate.AccountType = tmp;
                userUpdate.Login = userRow.UserLogin;

                _ctx.SaveChanges();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Esempio n. 13
0
 private void DataGrid_NhanVien_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
 {
     //Console.WriteLine("Edit");
     FrameworkElement element = DataGrid_NhanVien.Columns[12].GetCellContent(e.Row);
     if(element.GetType() == typeof(CheckBox))
     {
         if(((CheckBox)element).IsChecked == true)
         {
             FrameworkElement cellMaNhanVien = DataGrid_NhanVien.Columns[0].GetCellContent(e.Row);
             int MaNhanVien = Convert.ToInt32(((TextBlock)cellMaNhanVien).Text);
             lstSelectionNhanVien.Add(MaNhanVien);
         }
     }
 }
        private async void GroupsDataGrid_OnRowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
        {
            if (e.EditAction != DataGridEditAction.Commit) return;
            var group = e.Row.DataContext as Group;
            if (group != null)
            {
                if (group.Name == null)
                {
                    group.Name = "New Group";
                }
            }

            //have to add , UpdateSourceTrigger=PropertyChanged to have the data updated in time for this event
            await SaveChangesAsync();
        }
Esempio n. 15
0
        private void DataGrid_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
        {
            DinerMax3000.Business.MenuItem newMenuItem = e.Row.Item as DinerMax3000.Business.MenuItem; // cast datagrid row as a MenuItem object. IF it can't it will be null

            if (newMenuItem != null && e.EditAction==DataGridEditAction.Commit && e.Row.IsNewItem) { // if newMenuItem is not null && the datagrid action is commit (ike pressing enter etc) && datagrid edit is a new row

                // get data context from view model
                DinerMax3000.WPFClient.DinerMax3000ViewModel currentViewmodel =
                    (DinerMax3000.WPFClient.DinerMax3000ViewModel)DataContext;

                // Add MunuItem Object to list
                currentViewmodel.NewMenuItems.Add(newMenuItem);

            }
        }
 void propertyGrid_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
 {
     XbimReferencedModelViewModel modelWrapper = (XbimReferencedModelViewModel)e.Row.Item;
     try
     {
         //if build fails, cancel add row
         if (!modelWrapper.TryBuild(DataContext as XbimModel))
         {
             e.Cancel = true;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Something went wrong, object might not have been added\n\n" + ex.Message);
     }
 }
        private async void DataGrid_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
        {
            //code for update or create

            if (e.EditAction == DataGridEditAction.Commit)
            {
                await Dispatcher.BeginInvoke(new Action(() =>
                {
                    var vm = DataContext as InvoicesViewModel;
                    if (vm?.CreateOrUpdateInvoice(e.Row.Item as Invoice) == false)
                    {
                    }
                }), DispatcherPriority.Background);
            }

            mIsAdd = false;
            mIsEdit = false;
        }
Esempio n. 18
0
        private void Dgr_Companies_OnRowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
        {
            if (e.EditAction == DataGridEditAction.Commit)
            {
                var dg = sender as DataGrid;
                var dgr = (DataGridRow)dg.ItemContainerGenerator.ContainerFromIndex(dg.SelectedIndex);
                Action action = delegate
                {
                    var comp = e.Row.Item as Company;

                    if (dgr.IsNewItem) comp.Id = -1;

                    if (comp.Name == null || comp.Address == null || comp.BusinessType == null)
                    {
                        MessageBox.Show(
                            "Název, adresa a obor činnosti musí být vyplněny",
                            "Chyba",
                            MessageBoxButton.OK,
                            MessageBoxImage.Error);
                        (dg.ItemsSource as BindingList<Company>).Remove(comp);
                    }

                    if (!IcoValidator.IsValid(comp.Ico))
                    {
                        MessageBox.Show(
                            "Zadané IČO není validní",
                            "Chyba",
                            MessageBoxButton.OK,
                            MessageBoxImage.Error);
                        (dg.ItemsSource as BindingList<Company>).Remove(comp);
                    }
                    else
                    {
                        var compWithId = _companyService.SaveCompany(comp);

                        if (dg.ItemsSource != _companies)
                            _companies.Add(compWithId);
                    }

                };
                Dispatcher.BeginInvoke(action, System.Windows.Threading.DispatcherPriority.Background);
            }
        }
Esempio n. 19
0
        private void DgTags_OnRowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
        {
            var dg = (DataGrid)sender;

            var curRow = e.Row.DataContext as ProjectCollectionTag;
            if (curRow == null)
                return;

/*
            if (e.EditAction == DataGridEditAction.Commit)
            {
                if (curRow.Id == 0)
                {
                    var tags = (List<ProjectCollectionTag>)dg.ItemsSource;
                    curRow.Id = tags.Max(t => t.Id) + 1;

                }
            }
*/
        }
        private void scheduleDataGrid_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
        {
            var schedule = e.Row.Item as Schedule;
            if (schedule != null)
            {
                if (schedule.ScheduleID != 0)
                {
                    try
                    {
                        bool validInput = true;

                        if (dbContext.Cities.Find(schedule.StartCityID) == null)
                        {
                            MessageBox.Show("Start city Id is invalid! No such city in database!");
                            validInput = false;
                        }
                        else if (dbContext.Cities.Find(schedule.EndCityID) == null)
                        {
                            MessageBox.Show("End city Id is invalid! No such city in database!");
                            validInput = false;
                        }
                        else if (dbContext.Trains.Find(schedule.TrainID) == null)
                        {
                            MessageBox.Show("Train Id is invalid! No such train in database!");
                            validInput = false;
                        }
                        else if (schedule.DepartureTime < DateTime.Now)
                        {
                            MessageBox.Show("Cannot set past date for schedule!");
                            validInput = false;
                        }
                        else if (schedule.TravelTime > new TimeSpan(24, 0, 0))
                        {
                            MessageBox.Show("Travel time cannot be more than 24 hours!");
                            validInput = false;
                        }
                        else if (schedule.TicketPrice <= 0)
                        {
                            MessageBox.Show("Ticket price must be possitive number!");
                            validInput = false;
                        }

                        if (!validInput)
                        {
                            schedule.ScheduleID = beginEditSchedule.ScheduleID;
                            schedule.StartCityID = beginEditSchedule.StartCityID;
                            schedule.EndCityID = beginEditSchedule.EndCityID;
                            schedule.TrainID = beginEditSchedule.TrainID;
                            schedule.DepartureTime = beginEditSchedule.DepartureTime;
                            schedule.TravelTime = beginEditSchedule.TravelTime;
                            schedule.TicketPrice = beginEditSchedule.TicketPrice;
                            e.Row.Item = null;
                            e.Row.Item = schedule;
                        }
                        else
                        {
                            if (schedule.TrainID != beginEditSchedule.TrainID)
                            {
                                var oldTrain = dbContext.Trains.Find(beginEditSchedule.TrainID);
                                var newTrain = dbContext.Trains.Find(schedule.TrainID);

                                var seatsToRemove = from s in dbContext.Seats
                                                    where s.TrainID == oldTrain.TrainID
                                                          && s.ScheduleID == schedule.ScheduleID
                                                    select s;

                                var ticketsToRemove = from t in dbContext.Tickets
                                                      where t.TrainID == oldTrain.TrainID
                                                            && t.ScheduleID == schedule.ScheduleID
                                                      select t;

                                dbContext.Tickets.RemoveRange(ticketsToRemove);
                                dbContext.Seats.RemoveRange(seatsToRemove);

                                for (int i = 1; i <= newTrain.NumberOfSeats; i++)
                                {
                                    dbContext.Seats.Add(new Seat()
                                    {
                                        SeatNumber = i,
                                        TrainID = schedule.TrainID,
                                        ScheduleID = schedule.ScheduleID,
                                        Taken = false,
                                        Class = SeatClass.FirstClass
                                    });
                                }
                            }
                            else //if train is the same
                            {
                                var tickets = from t in dbContext.Tickets
                                              where t.TrainID == schedule.TrainID
                                                    && t.ScheduleID == schedule.ScheduleID
                                              select t;

                                foreach (var ticket in tickets)
                                {
                                    ticket.TripDateAndTime = schedule.DepartureTime;
                                }
                            }

                            dbContext.SaveChanges();

                            UpdateDataGrids();
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show($"Could not update database! Error message: {ex.Message}");
                    }
                }
            }
        }
        private void trainDataGrid_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
        {
            var train = e.Row.Item as Train;
            if (train != null)
            {
                if (train.TrainID != 0)
                {
                    try
                    {
                        if (train.NumberOfSeats <= 0)
                        {
                            MessageBox.Show("Seats number must be possitive! Nothing saved to database!");
                            train.NumberOfSeats = beginEditTrain.NumberOfSeats;
                            train.BriefDescription = beginEditTrain.BriefDescription;
                            e.Row.Item = null;
                            e.Row.Item = train;
                        }
                        else if (train.BriefDescription.Length < 1)
                        {
                            MessageBox.Show("Train must have a description! Nothing saved to database!");
                            train.NumberOfSeats = beginEditTrain.NumberOfSeats;
                            train.BriefDescription = beginEditTrain.BriefDescription;
                            e.Row.Item = null;
                            e.Row.Item = train;
                        }
                        else
                        {
                            if (train.NumberOfSeats < beginEditTrain.NumberOfSeats)
                            {
                                var seatsToRemove = from s in dbContext.Seats
                                                    where s.TrainID == train.TrainID
                                                          && s.SeatNumber > train.NumberOfSeats
                                                    select s;

                                var ticketsToRemove = from t in dbContext.Tickets
                                                      where t.TrainID == train.TrainID
                                                            && t.SeatNumber > train.NumberOfSeats
                                                      select t;

                                dbContext.Tickets.RemoveRange(ticketsToRemove);
                                dbContext.Seats.RemoveRange(seatsToRemove);
                            }
                            else if (train.NumberOfSeats > beginEditTrain.NumberOfSeats)
                            {
                                var schedulesForTrain = from s in dbContext.Schedules
                                                         where s.TrainID == train.TrainID
                                                         select s;

                                foreach (var schedule in schedulesForTrain)
                                {
                                    for (int i = beginEditTrain.NumberOfSeats; i < train.NumberOfSeats; i++)
                                    {
                                        dbContext.Seats.Add(new Seat()
                                        {
                                            SeatNumber = i + 1,
                                            TrainID = train.TrainID,
                                            ScheduleID = schedule.ScheduleID,
                                            Taken = false,
                                            Class = SeatClass.FirstClass
                                        });
                                    }
                                }
                            }
                            dbContext.SaveChanges();
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show($"Could not update database! Error message: {ex.Message}");
                    }
                }
                else
                {
                    try
                    {
                        if (train.NumberOfSeats <= 0)
                        {
                            MessageBox.Show("Seats number must be possitive! Nothing saved to database!");
                            var currentItemsSource = trainDataGrid.ItemsSource;
                            trainDataGrid.ItemsSource = null;
                            trainDataGrid.Items.Remove(e.Row);
                            trainDataGrid.ItemsSource = currentItemsSource;
                        }
                        else if (train.BriefDescription.Length < 1)
                        {
                            MessageBox.Show("Train must have a description! Nothing saved to database!");
                            var currentItemsSource = trainDataGrid.ItemsSource;
                            trainDataGrid.ItemsSource = null;
                            trainDataGrid.Items.Remove(e.Row);
                            trainDataGrid.ItemsSource = currentItemsSource;
                        }
                        else
                        {
                            dbContext.Trains.Add(train);
                            dbContext.SaveChanges();
                            e.Row.Item = null;
                            e.Row.Item = train;
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show($"Could not update database! Error message: {ex.Message}");
                    }
                }
            }

            beginEditTrain = null;
        }
        private void dataGrid1_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
        {
            var PosOfDay = e.Row.Item as PositionOfDay;

            if (PosOfDay.CurrentHour != PosOfDay.OldHour ||
                PosOfDay.CurrentMinute != PosOfDay.OldMinute ||
                !PosOfDay.CurrentNote.Equals(PosOfDay.OldNote) ||
                !PosOfDay.CurrentUser.Equals(PosOfDay.OldUser)
                )
            {
                ActionResult saveRes = Engine.RemoveNoteFromDB(PosOfDay.OldHour, PosOfDay.OldMinute);
                if (!saveRes.IsSuccess)
                {
                    MessageBox.Show(saveRes.ErrorMsg, "Error");
                }

                var fodg = new FieldsOfDataGrid()
                {
                    Hour = PosOfDay.CurrentHour,
                    Minute = PosOfDay.CurrentMinute,
                    Note = PosOfDay.CurrentNote,
                    User = PosOfDay.CurrentUser
                };

                ActionResult addNoteResult = Engine.AddNoteToDB(fodg);
                if (!addNoteResult.IsSuccess)
                {
                    MessageBox.Show(addNoteResult.ErrorMsg, "Error");
                }
            }
            Engine.UpdateOfPositions();
        }
        private void cityDataGrid_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
        {
            var city = e.Row.Item as City;
            if (city != null)
            {
                if (city.CityID != 0)
                {
                    try
                    {
                        if (city.Name.Length < 1)
                        {
                            MessageBox.Show("City should have a name! Nothing saved to database!");
                            city.Name = beginEditCity.Name;
                            e.Row.Item = null;
                            e.Row.Item = city;
                        }
                        else
                            dbContext.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show($"Could not update database! Error message: {ex.Message}");
                    }
                }
                else
                {
                    try
                    {
                        if (city.Name.Length < 1)
                        {
                            MessageBox.Show("City should have a name! Nothing saved to database!");
                            var currentItemsSource = trainDataGrid.ItemsSource;
                            trainDataGrid.ItemsSource = null;
                            trainDataGrid.Items.Remove(e.Row);
                            trainDataGrid.ItemsSource = currentItemsSource;
                        }
                        else
                        {
                            dbContext.Cities.Add(city);
                            dbContext.SaveChanges();
                            e.Row.Item = null;
                            e.Row.Item = city;
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show($"Could not update database! Error message: {ex.Message}");
                    }
                }
            }

            beginEditCity = null;
        }
 private void datagrid_RowEditEnding(object sender, System.Windows.Controls.DataGridRowEditEndingEventArgs e)
 {
     datagrid.CurrentCellChanged += Datagrid_CurrentCellChanged;
 }
 private async void DeviceGrid_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
 {
     if (e.EditAction != DataGridEditAction.Commit) return;
     //have to add , UpdateSourceTrigger=PropertyChanged to have the data updated intime for this event
     var result = await Context.TrySaveChangesAsync(_app.Cts.Token);
     if (result.HasError)
         await Log.ReportErrorFormatAsync(_app.Cts.Token, "Error saving device. {0}", result.Message);
 }
Esempio n. 26
0
 private void DataGrid_RowEditEnding(object sender, System.Windows.Controls.DataGridRowEditEndingEventArgs e)
 {
     _RecomputePrice();
     _RecomputePrice_Copy();
 }
Esempio n. 27
0
 void synchronizeValue(DataGridRowEditEndingEventArgs e, DataGrid grid)
 {
     Action action = delegate
     {
         int voltage = (e.Row.Item as GridRow).Voltage;
         foreach (GridRow row in grid.Items)
         {
             if (row.DPM == (e.Row.DataContext as GridRow).DPM)
             {
                 row.Voltage = voltage;
                 grid.Items.Refresh();
                 break;
             }
         }
     };
     Dispatcher.BeginInvoke(action, System.Windows.Threading.DispatcherPriority.Background);
 }
        /// <summary>
        ///     When added to the RowEditEnding event of a WPF DataGrid, if the user presses Tab while on the last cell of a row, the focus
        ///     is switched to the first cell of the next row, instead of another control altogether.
        ///     <see cref="Any_PreviewKeyDown_CheckTab" /> and <see cref="Any_PreviewKeyUp_CheckTab" /> should also be added as event handlers to the control.
        /// </summary>
        /// <param name="sender">The WPF DataGrid (or compatible) control from which the event was raised..</param>
        /// <param name="e">
        ///     The <see cref="DataGridRowEditEndingEventArgs" /> instance containing the event data.
        /// </param>
        public static void WPFDataGrid_RowEditEnding_GoToNewRowOnTab(object sender, DataGridRowEditEndingEventArgs e)
        {
            if (_isTabPressed && e.EditAction == DataGridEditAction.Commit)
            {
                var dataGrid = sender as DataGrid;

                Debug.Assert(dataGrid != null, "dataGrid != null");
                if (e.Row.Item == dataGrid.Items[dataGrid.Items.Count - 2])
                {
                    Window parentWindow = Window.GetWindow(dataGrid);
                    Debug.Assert(parentWindow != null, "parentWindow != null");
                    parentWindow.Dispatcher.BeginInvoke(new DispatcherOperationCallback(param =>
                        {
                            dataGrid.Focus();
                            dataGrid.SelectedIndex = dataGrid.Items.IndexOf(CollectionView.NewItemPlaceholder);
                            dataGrid.CurrentCell = new DataGridCellInfo(CollectionView.NewItemPlaceholder, dataGrid.Columns[0]);

                            //dataGrid.BeginEdit();
                            return null;
                        }), DispatcherPriority.Background, new object[] {null});
                }
            }
        }
Esempio n. 29
0
        /// <summary>
        ///     Invoked when the CancelEdit command is executed.
        /// </summary>
        protected virtual void OnExecutedCancelEdit(ExecutedRoutedEventArgs e)
        {
            DataGridCell cell = CurrentCellContainer;
            if (cell != null)
            {
                DataGridEditingUnit editingUnit = GetEditingUnit(e.Parameter);

                bool eventCanceled = false;
                if (cell.IsEditing)
                {
                    DataGridCellEditEndingEventArgs cellEditEndingEventArgs = new DataGridCellEditEndingEventArgs(cell.Column, cell.RowOwner, cell.EditingElement, DataGridEditAction.Cancel);
                    OnCellEditEnding(cellEditEndingEventArgs);

                    eventCanceled = cellEditEndingEventArgs.Cancel;
                    if (!eventCanceled)
                    {
                        cell.CancelEdit();
                        HasCellValidationError = false;
                        UpdateCellAutomationValueHolder(cell);
                    }
                }

                if (!eventCanceled &&
                    IsAddingOrEditingRowItem(editingUnit, cell.RowDataItem))
                {
                    bool cancelAllowed = true;

                    DataGridRowEditEndingEventArgs rowEditEndingEventArgs = new DataGridRowEditEndingEventArgs(cell.RowOwner, DataGridEditAction.Cancel);
                    OnRowEditEnding(rowEditEndingEventArgs);
                    cancelAllowed = !rowEditEndingEventArgs.Cancel;

                    if (cancelAllowed)
                    {
                        var bindingGroup = cell.RowOwner.BindingGroup;
                        if (bindingGroup != null)
                        {
                            bindingGroup.CancelEdit();
                        }

                        CancelRowItem();
                    }
                }

                // Update the state of row editing
                UpdateRowEditing(cell);

                if (!cell.RowOwner.IsEditing)
                {
                    // Allow the user to cancel the row and avoid being locked to that row.
                    // If the row is still not valid, it means that the source data is already
                    // invalid, and that is OK.
                    HasRowValidationError = false;

                    ReleaseCellAutomationValueHolders();
                }

                // CancelEdit and CommitEdit rely on IsAddingNewItem and IsEditingRowItem
                CommandManager.InvalidateRequerySuggested();
            }

            e.Handled = true;
        }
Esempio n. 30
0
        /// <summary>
        ///     Called just before row editing is ended.
        ///     Gives subclasses the opportunity to cancel the operation.
        /// </summary>
        protected virtual void OnRowEditEnding(DataGridRowEditEndingEventArgs e)
        {
            if (RowEditEnding != null)
            {
                RowEditEnding(this, e);
            }

            if (AutomationPeer.ListenerExists(AutomationEvents.InvokePatternOnInvoked))
            {
                DataGridAutomationPeer peer = DataGridAutomationPeer.FromElement(this) as DataGridAutomationPeer;
                if (peer != null)
                {
                    peer.RaiseAutomationRowInvokeEvents(e.Row);
                }
            }
        }
Esempio n. 31
0
        /// <summary>
        ///     Invoked when the CommitEdit command is executed.
        /// </summary>
        protected virtual void OnExecutedCommitEdit(ExecutedRoutedEventArgs e)
        {
            DataGridCell cell = CurrentCellContainer;
            bool validationPassed = true;
            if (cell != null)
            {
                DataGridEditingUnit editingUnit = GetEditingUnit(e.Parameter);

                bool eventCanceled = false;
                if (cell.IsEditing)
                {
                    DataGridCellEditEndingEventArgs cellEditEndingEventArgs = new DataGridCellEditEndingEventArgs(cell.Column, cell.RowOwner, cell.EditingElement, DataGridEditAction.Commit);
                    OnCellEditEnding(cellEditEndingEventArgs);

                    eventCanceled = cellEditEndingEventArgs.Cancel;
                    if (!eventCanceled)
                    {
                        validationPassed = cell.CommitEdit();
                        HasCellValidationError = !validationPassed;
                        UpdateCellAutomationValueHolder(cell);
                    }
                }

                // Consider commiting the row if:
                // 1. Validation passed on the cell or no cell was in edit mode.
                // 2. A cell in edit mode didn't have it's ending edit event canceled.
                // 3. The row is being edited or added and being targeted directly.
                if (validationPassed &&
                    !eventCanceled &&
                    IsAddingOrEditingRowItem(editingUnit, cell.RowDataItem))
                {
                    DataGridRowEditEndingEventArgs rowEditEndingEventArgs = new DataGridRowEditEndingEventArgs(cell.RowOwner, DataGridEditAction.Commit);
                    OnRowEditEnding(rowEditEndingEventArgs);

                    if (!rowEditEndingEventArgs.Cancel)
                    {
                        var bindingGroup = cell.RowOwner.BindingGroup;
                        if (bindingGroup != null)
                        {
                            // CommitEdit will invoke the bindingGroup's ValidationRule's, so we need to make sure that all of the BindingExpressions
                            // have already registered with the BindingGroup.  Synchronously flushing the Dispatcher to DataBind priority lets us ensure this.
                            // Had we used BeginInvoke instead, IsEditing would not reflect the correct value.
                            Dispatcher.Invoke(new DispatcherOperationCallback(DoNothing), DispatcherPriority.DataBind, bindingGroup);
                            validationPassed = bindingGroup.CommitEdit();
                        }

                        HasRowValidationError = !validationPassed;
                        if (validationPassed)
                        {
                            CommitRowItem();
                        }
                    }
                }

                if (validationPassed)
                {
                    // Update the state of row editing
                    UpdateRowEditing(cell);

                    if (!cell.RowOwner.IsEditing)
                    {
                        ReleaseCellAutomationValueHolders();
                    }
                }

                // CancelEdit and CommitEdit rely on IsAddingNewItem and IsEditingRowItem
                CommandManager.InvalidateRequerySuggested();
            }

            e.Handled = true;
        }
 protected virtual new void OnRowEditEnding(DataGridRowEditEndingEventArgs e)
 {
 }
Esempio n. 33
0
 private void options_floors_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
 {
     if (e.EditAction == DataGridEditAction.Commit)
     {
         var item = (FloorR)e.Row.Item;
         if (item.txtFloor == null)
         {
             
         }
     }
     else if (e.EditAction == DataGridEditAction.Cancel)
     {
     }
 }
Esempio n. 34
0
 private void memFrequencyTable_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
 {
     synchronizeValue(e, gpuFrequencyTable);
 }