Esempio n. 1
0
        private void dgvProfessor_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
        {
            int id = 0;

            if (int.TryParse(e.Row.Cells[0].Value.ToString(), out id))
            {
                var db = new LINQDataContext();
                // Define the query expression.
                IEnumerable <int> query = from priority in db.Priority_Professors
                                          where priority.Professor_ID == id
                                          select priority.Class_ID;
                //
                // if exist data in table ?
                //
                if (query.ToArray().Length > 0)
                {
                    string class_ID_List = "";
                    foreach (var anyClass in query)
                    {
                        class_ID_List += anyClass.ToString() + " and ";
                    }
                    class_ID_List = class_ID_List.Substring(0, class_ID_List.Length - 4);

                    e.Cancel = true;

                    MessageBox.Show("Information classes with class numbers " +
                                    class_ID_List + "is related to Professor " +
                                    ((e.Row.Cells[1].Value != null) ? e.Row.Cells[1].Value.ToString() : "NULL") +
                                    ".\n First, this information can change classes.", "Delete Row Error",
                                    MessageBoxButtons.OK, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1);
                }
                else
                {
                    db.ClassroomDeleteProf(id);
                    db.ProfessorDelete(id);
                }
                db.Dispose();
            }
        }
        private void dgvProfessor_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
        {
            int id = 0;
            if (int.TryParse(e.Row.Cells[0].Value.ToString(), out id))
            {
                var db = new LINQDataContext();
                // Define the query expression.
                IEnumerable<int> query = from priority in db.Priority_Professors
                                         where priority.Professor_ID == id
                                         select priority.Class_ID;
                //
                // if exist data in table ?
                //
                if (query.ToArray().Length > 0)
                {
                    string class_ID_List = "";
                    foreach (var anyClass in query)
                    {
                        class_ID_List += anyClass.ToString() + " and ";
                    }
                    class_ID_List = class_ID_List.Substring(0, class_ID_List.Length - 4);

                    e.Cancel = true;

                    MessageBox.Show("Information classes with class numbers " +
                        class_ID_List + "is related to Professor " +
                        ((e.Row.Cells[1].Value != null) ? e.Row.Cells[1].Value.ToString() : "NULL") +
                        ".\n First, this information can change classes.", "Delete Row Error",
                        MessageBoxButtons.OK, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1);
                }
                else
                {
                    db.ClassroomDeleteProf(id);
                    db.ProfessorDelete(id);
                }
                db.Dispose();
            }
        }