Esempio n. 1
0
        private void dgvCourse_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 classs in db.Classes
                    where classs.Course_ID == id
                    select classs.Class_ID;
                //
                // if exist data in class 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 Course " +
                                    ((e.Row.Cells[10].Value != null) ? e.Row.Cells[10].Value.ToString() : "NULL") +
                                    ".\n First, this information can change classes.", "Delete Row Error",
                                    MessageBoxButtons.OK, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1);
                }
                else
                {
                    db.CourseDelete(id);
                }
                db.Dispose();
            }
        }
        private void dgvCourse_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 classs in db.Classes
                    where classs.Course_ID == id
                    select classs.Class_ID;
                //
                // if exist data in class 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 Course " +
                        ((e.Row.Cells[10].Value != null) ? e.Row.Cells[10].Value.ToString() : "NULL") +
                        ".\n First, this information can change classes.", "Delete Row Error",
                        MessageBoxButtons.OK, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1);
                }
                else
                {
                    db.CourseDelete(id);
                }
                db.Dispose();
            }
        }