Example #1
0
        /// <summary>
        /// Check if the student specified has to be chown in the datagrid
        /// </summary>
        /// <param name="st">student to check</param>
        /// <param name="f_name"></param>
        /// <param name="f_surname"></param>
        /// <param name="f_degree"></param>
        /// <returns></returns>
        private Boolean filterStudent(Student_item st, string f_name, string f_surname, degree f_degree)
        {
            if (f_name.Length != 0)
            {
                if (!st.St.name.Contains(f_name))
                {
                    return(false);
                }
            }

            if (f_surname.Length != 0)
            {
                if (!st.St.surname.Contains(f_surname))
                {
                    return(false);
                }
            }

            if (f_degree != null)
            {
                if (f_degree.isEmpty())
                {
                    return(st.Deg == null);
                }

                if (st.Deg == null)
                {
                    return(false);
                }

                if (!st.Deg.name.Equals(f_degree.name) || !st.Deg.code.Equals(f_degree.code))
                {
                    return(false);
                }
            }
            return(true);
        }
Example #2
0
        /// <summary>
        /// Function called when you finish to edit a datagrid cell
        /// Is the function that update the database with the new value
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Dg_students_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
        {
            TextBox t = e.EditingElement as TextBox;  // Assumes columns are all TextBoxes

            Student_item st_edit = (Student_item)dg_students.SelectedValue;

            switch (e.Column.DisplayIndex)
            {
            case COL_ID:
                MessageBox.Show("Are not allowed to change the id!");
                break;

            case COL_NAME:
                if (t.Text.Equals(st_edit.St.name))
                {
                    MessageBox.Show("No changes");
                    return;
                }

                using (var db = new lppDB())
                {
                    db.students.Where(st => st.id == st_edit.St.id).Set(p => p.name, t.Text).Update();
                    db.Close();
                }
                MessageBox.Show("The name has been changed from " +
                                st_edit.St.name + " to " + t.Text);

                break;

            case COL_SURNAME:
                if (t.Text.Equals(st_edit.St.surname))
                {
                    MessageBox.Show("No changes");
                    return;
                }
                using (var db = new lppDB())
                {
                    db.students.Where(st => st.id == st_edit.St.id).Set(p => p.surname, t.Text).Update();
                    db.Close();
                }

                MessageBox.Show("The surname has been changed from " +
                                st_edit.St.surname + " to " + t.Text);
                break;

            case COL_DEGREE:
                ComboBox cb_deg     = e.EditingElement as ComboBox;
                degree   d_selected = (degree)cb_deg.SelectedItem;
                if (cb_deg.SelectedIndex == -1 || d_selected.Equals(st_edit.St.degree))
                {
                    MessageBox.Show("No changes");
                    return;
                }

                this.updateDegree(st_edit.St, d_selected);

                MessageBox.Show("The degree has been changed from " +
                                st_edit.St.degree + " to " + cb_deg.SelectedItem);
                break;

            case COL_GID:
                if (t.Text.Equals(st_edit.St.govern_identifier))
                {
                    MessageBox.Show("No changes");
                    return;
                }
                using (var db = new lppDB())
                {
                    db.students.Where(st => st.id == st_edit.St.id).Set(p => p.govern_identifier, t.Text).Update();
                    db.Close();
                }

                MessageBox.Show("The govern id has been changed from " +
                                st_edit.St.govern_identifier + " to " + t.Text);
                break;

            default:
                MessageBox.Show("Wrong action");
                break;
            }
        }