コード例 #1
0
        /*private void dataGrid_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e) // Editing DataGrid Row
         * {
         *  DataGridHelper.EditDataGrid<Student>(e, table_name, dataGrid);
         *  load_data_grid();
         * }*/
        #endregion

        #region DataGrid: Deleting

        /*private void dataGrid_PreviewKeyDown(object sender, KeyEventArgs e) // Deleting DataGrid Row
         * {
         *  if (e.Key == Key.Delete)
         *  {
         *      e.Handled = DataGridHelper.DeleteDataGrid<Student>(dataGrid);
         *  }
         * }*/
        #endregion

        #region DataGrid: Filtering

        /*public void FilterValue(object sender, EventArgs e)
         * {
         *  DataGridHelper.FilterDataGrid<Student>(sender, e, dataGrid);
         * }*/
        #endregion

        /*
         #region DataGrid: Editing
         * private void dataGrid_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e) // Editing DataGrid Row
         * {
         *  var new_value = ((TextBox)e.EditingElement).Text.Trim(); // Getting entered value
         *  if (e.EditAction == DataGridEditAction.Commit && !new_value.Equals("")) // Checking entered value for empty
         *  {
         *      MessageBoxResult msgBox = MessageBox.Show("Вы действительно хотите изменить текушие данные?", "Изменение данных", MessageBoxButton.YesNo);
         *      if(msgBox == MessageBoxResult.Yes) // If answer YES
         *      {
         *          var selected_items = (Student)dataGrid.SelectedItem; // Getting DataGrid selected items(can get Student class properties)
         *          string column_name = e.Column.SortMemberPath; // Getting edited/changed column name
         *
         *          sqliteAdapter.ChangeValueById("students", selected_items.id, column_name, new_value);
         *          // TODO: Добавить проверку выполненности изменения данных в БД, если FALSE, то откат изменений в DataGrid
         *      }
         *      else { // If answer No
         *          dataGrid.CancelEdit(); //DataGridEditingUnit.Row
         *      }
         *  } else if (e.EditAction == DataGridEditAction.Cancel) { return; }
         *  else { dataGrid.CancelEdit(); } // Cancel editing row
         * }
         #endregion
         *
         #region DataGrid: Deleting
         * private void dataGrid_PreviewKeyDown(object sender, KeyEventArgs e) // Deleting DataGrid Row
         * {
         *  if(e.Key == Key.Delete)
         *  {
         *      MessageBoxResult msgBox = MessageBox.Show("Вы действительно хотите удалить данного студента?", "Удаление студента", MessageBoxButton.YesNo);
         *      if (msgBox == MessageBoxResult.Yes)
         *      {
         *          var selected_items = (Student)dataGrid.SelectedItem;
         *          sqliteAdapter.DeleteRowById("students", selected_items.id);
         *      } else { e.Handled = true; } // Cancel delete row
         *  }
         * }
         #endregion
         *
         #region DataGrid: Filtering
         * public void FilterValue(object sender, EventArgs e)
         * {
         *  dynamic control = (dynamic)sender;
         *  string filter = control.Text; // Entered Text
         *
         *  ICollectionView cv = CollectionViewSource.GetDefaultView(dataGrid.ItemsSource);
         *
         *  List<string> columns = new List<string>();
         *  Type propertyInfo = typeof(Student);
         *  foreach(PropertyInfo propertyName in propertyInfo.GetProperties()) columns.Add(propertyName.Name); // Get properties from Student class and add it to List columns
         *
         *  // add check edititem exception
         *  if (filter == "") cv.Filter = null;
         *  else
         *  {
         *      cv.Filter = o =>
         *      {
         *          Student p = (Student)o;
         *          foreach (string column in columns)
         *          {
         *              string filteredItem = propertyInfo.GetProperty(column).GetValue(p, null).ToString(); // Get property by name(List coumns) and get its value
         *              if (control.Name.Equals(column)) return filteredItem.ToUpper().StartsWith(filter.ToUpper()); // Find/Check filtered textbox by name and filter datagrid by entered value
         *          }
         *          return false;
         *      };
         *  }
         * }
         #endregion
         */
        #endregion

        private void Student_Hotkey(object sender, RoutedEventArgs e)
        {
            Button button = (Button)sender;

            switch (button.Name)
            {
            case "Student_add":
                new Student_Add().ShowDialog();
                break;

            case "Student_edit":
                if (dataGrid.SelectedIndex != -1)
                {
                    new Student_Edit(dataGrid.SelectedItem as Student).ShowDialog();
                }
                break;

            case "Student_del":
                if (dataGrid.SelectedIndex != -1)
                {
                    if (DataGridHelper.DeleteDataGrid <Student>(dataGrid) == false)
                    {
                        Helper.OStudents.Remove(Helper.OStudents.Where(i => i.Equals(dataGrid.SelectedItem)).Single());
                    }
                }
                break;

            default: break;
            }
        }
コード例 #2
0
        private void ButtonListener_Manage(object sender, RoutedEventArgs e)
        {
            Button button = (Button)sender;

            switch (button.Name)
            {
            case "btnAdd":
                new Pract_Add().ShowDialog();
                break;

            case "btnEdit":
                if (dataGrid.SelectedIndex != -1)
                {
                    new Pract_Edit(dataGrid.SelectedItem as Practise).ShowDialog();
                }
                break;

            case "btnDel":
                if (dataGrid.SelectedIndex != -1)
                {
                    if (DataGridHelper.DeleteDataGrid <Practise>(dataGrid) == false)                                    // Deleting row from DB
                    {
                        Helper.OPractise.Remove(Helper.OPractise.Where(i => i.Equals(dataGrid.SelectedItem)).Single()); // Deleting row from OCathedras(ObservableCollection)
                    }
                }
                break;

            default: break;
            }
        }
コード例 #3
0
        /*private void dataGrid_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e) // Editing DataGrid Row
         * {
         *  dataGridHelper.EditDataGrid<Group>(e, table_name, dataGrid);
         *  load_data_grid();
         * }*/
        #endregion

        #region DataGrid: Deleting

        /*private void dataGrid_PreviewKeyDown(object sender, KeyEventArgs e) // Deleting DataGrid Row
         * {
         *  if (e.Key == Key.Delete)
         *  {
         *      e.Handled = DataGridHelper.DeleteDataGrid<Group>(dataGrid);
         *  }
         * }*/
        #endregion

        #region DataGrid: Filtering

        /*public void FilterValue(object sender, EventArgs e)
         * {
         *  dataGridHelper.FilterDataGrid<Group>(sender, e, dataGrid);
         * }*/
        #endregion

        #endregion

        private void Group_Hotkey(object sender, RoutedEventArgs e)
        {
            Button button = (Button)sender;

            switch (button.Name)
            {
            case "Group_add":
                new Groups_Add().ShowDialog();
                break;

            case "Group_edit":
                if (dataGrid.SelectedIndex != -1)
                {
                    new Groups_Edit(dataGrid.SelectedItem as Group).ShowDialog();
                }
                break;

            case "Group_del":
                if (dataGrid.SelectedIndex != -1)
                {
                    if (DataGridHelper.DeleteDataGrid <Group>(dataGrid) == false)
                    {
                        string group_id = ((Group)dataGrid.SelectedItem).id;
                        Helper.OGroups.Remove(Helper.OGroups.Where(i => i.Equals(dataGrid.SelectedItem)).Single());     // Deleting row from OCathedras(ObservableCollection)
                        SQLiteAdapter.DeleteRowById("pract_types", $"[id_groupe]='{group_id}'");
                    }
                }
                break;

            default: break;
            }
        }
コード例 #4
0
        private void Controls_Buttons(object sender, RoutedEventArgs e)
        {
            if (contracts_list.SelectedIndex == -1)
            {
                return;
            }
            Button button = (Button)sender;

            switch (button.Name)
            {
            case "Contract_open":
                try { Process.Start(path_contracts + "Договор №" + Helper.OContracts.Where(i => i.Equals(contracts_list.SelectedItem)).Single().id); }
                catch { MessageBox.Show($"Ошибка открытия папки! Возможно сперва необходимо сформировать договор.", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error); }
                break;

            case "Contract_edit":
                new Contracts_Edit(contracts_list.SelectedItem as Classes.Contracts).ShowDialog();
                Helper.RefreshOCollection();
                break;

            case "Contract_del":
                if (DataGridHelper.DeleteDataGrid <Classes.Contracts>(contracts_list) == false)
                {
                    string id = ((Classes.Contracts)contracts_list.SelectedItem).id;
                    if (SQLiteAdapter.DeleteRowById("attach", $"[id_contract]='{id}'") == false)
                    {
                        Helper.OContracts.Remove(Helper.OContracts.Where(i => i.Equals(contracts_list.SelectedItem)).Single());     // Удаляем элемент из коллекции
                        if (Directory.Exists(path_contracts + $"Договор №{id}"))
                        {
                            Directory.Delete(path_contracts + $"Договор №{id}", true);     // Удаляем папку договора
                        }
                    }
                }
                break;

            default: break;
            }
        }
コード例 #5
0
        private void ButtonListener_Manage(object sender, RoutedEventArgs e)
        {
            Button button = (Button)sender;

            switch (button.Name)
            {
                #region Buttons attached to cathedras
            case "btnAdd_cathedra":
                new Cathedras_Add().ShowDialog();
                break;

            case "btnEdit_cathedra":
                if (CathedrasGrid.SelectedIndex != -1)
                {
                    new Cathedras_Edit(CathedrasGrid.SelectedItem as Cathedra).ShowDialog();
                }
                break;

            case "btnDel_cathedra":
                if (CathedrasGrid.SelectedIndex != -1)
                {
                    if (DataGridHelper.DeleteDataGrid <Cathedra>(CathedrasGrid) == false)                                      // Deleting row from DB
                    {
                        Helper.OCathedras.Remove(Helper.OCathedras.Where(i => i.Equals(CathedrasGrid.SelectedItem)).Single()); // Deleting row from OCathedras(ObservableCollection)
                    }
                }
                break;
                #endregion

                #region Buttons attached to employees
            case "btnAdd_employee":
                new Employee_Add().ShowDialog();
                break;

            case "btnEdit_employee":
                if (EmployeesGrid.SelectedIndex != -1)
                {
                    new Employee_Edit(EmployeesGrid.SelectedItem as Employee).ShowDialog();
                }
                break;

            case "btnDel_employee":
                if (EmployeesGrid.SelectedIndex != -1)
                {
                    if (DataGridHelper.DeleteDataGrid <Employee>(EmployeesGrid) == false)
                    {
                        Helper.OEmployees.Remove(Helper.OEmployees.Where(i => i.Equals(EmployeesGrid.SelectedItem)).Single());
                    }
                }
                break;
                #endregion

                #region Buttons attached to directions
            case "btnAdd_direction":
                new Direction_Add().ShowDialog();
                break;

            case "btnEdit_direction":
                if (DirectionsGrid.SelectedIndex != -1)
                {
                    new Direction_Edit(DirectionsGrid.SelectedItem as Direction).ShowDialog();
                }
                break;

            case "btnDel_direction":
                if (DirectionsGrid.SelectedIndex != -1)
                {
                    if (DataGridHelper.DeleteDataGrid <Direction>(DirectionsGrid) == false)
                    {
                        Helper.ODirections.Remove(Helper.ODirections.Where(i => i.Equals(DirectionsGrid.SelectedItem)).Single());
                    }
                }
                break;
                #endregion

            default: break;
            }
            //load_data_grid(); // Update dataGrid values
        }