Пример #1
0
        private void ProfessorForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            dgvProfessor[0, 0].Selected = true;

            // ----------------------------------------------------------------------------------------------
            //
            var db = new LINQDataContext();

            for (int rowCounter = 0; rowCounter < dgvProfessor.RowCount - 1; rowCounter++)
            {
                //
                // search dgvProfessor.rows in db.Professor
                //
                int ID_No = 0;
                int.TryParse(dgvProfessor[0, rowCounter].Value.ToString(), out ID_No);
                // Define the query expression.
                IEnumerable <int> query =
                    from prof in db.Professors
                    where prof.ID == ID_No
                    select prof.ID;

                if (query.ToArray().Length > 0) // EDIT
                {
                    db.ProfessorEdit(ID_No,
                                     (dgvProfessor[1, rowCounter].Value != null) ? (string)dgvProfessor[1, rowCounter].Value.ToString() : "",
                                     (dgvProfessor[2, rowCounter].Value != null) ? (string)dgvProfessor[2, rowCounter].Value.ToString() : "",
                                     (dgvProfessor[3, rowCounter].Value != null && dgvProfessor[3, rowCounter].Value.ToString().ValidateEmail()) ?
                                     (string)dgvProfessor[3, rowCounter].Value.ToString() : "",
                                     (dgvProfessor[4, rowCounter].Value != null) ? (string)dgvProfessor[4, rowCounter].Value.ToString() : "",
                                     (dgvProfessor[6, rowCounter].Value != null) ? (string)dgvProfessor[6, rowCounter].Value.ToString() : "");
                }
                else // SAVE NEW
                {
                    db.ProfessorSave(ID_No,
                                     (dgvProfessor[1, rowCounter].Value != null) ? (string)dgvProfessor[1, rowCounter].Value.ToString() : "",
                                     (dgvProfessor[2, rowCounter].Value != null) ? (string)dgvProfessor[2, rowCounter].Value.ToString() : "",
                                     (dgvProfessor[3, rowCounter].Value != null && dgvProfessor[3, rowCounter].Value.ToString().ValidateEmail()) ?
                                     (string)dgvProfessor[3, rowCounter].Value.ToString() : "",
                                     (dgvProfessor[4, rowCounter].Value != null) ? (string)dgvProfessor[4, rowCounter].Value.ToString() : "",
                                     (dgvProfessor[6, rowCounter].Value != null) ? (string)dgvProfessor[6, rowCounter].Value.ToString() : "");
                }
            }

            db.Dispose();
        }
        private void ProfessorForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            dgvProfessor[0, 0].Selected = true;

            // ----------------------------------------------------------------------------------------------
            //
            var db = new LINQDataContext();

            for (int rowCounter = 0; rowCounter < dgvProfessor.RowCount - 1; rowCounter++)
            {
                //
                // search dgvProfessor.rows in db.Professor
                //
                int ID_No = 0;
                int.TryParse(dgvProfessor[0, rowCounter].Value.ToString(), out ID_No);
                // Define the query expression.
                IEnumerable<int> query =
                    from prof in db.Professors
                    where prof.ID == ID_No
                    select prof.ID;

                if (query.ToArray().Length > 0) // EDIT
                {
                    db.ProfessorEdit(ID_No,
                        (dgvProfessor[1, rowCounter].Value != null) ? (string)dgvProfessor[1, rowCounter].Value.ToString() : "",
                        (dgvProfessor[2, rowCounter].Value != null) ? (string)dgvProfessor[2, rowCounter].Value.ToString() : "",
                        (dgvProfessor[3, rowCounter].Value != null && dgvProfessor[3, rowCounter].Value.ToString().ValidateEmail()) ?
                        (string)dgvProfessor[3, rowCounter].Value.ToString() : "",
                        (dgvProfessor[4, rowCounter].Value != null) ? (string)dgvProfessor[4, rowCounter].Value.ToString() : "",
                        (dgvProfessor[6, rowCounter].Value != null) ? (string)dgvProfessor[6, rowCounter].Value.ToString() : "");
                }
                else // SAVE NEW
                {
                    db.ProfessorSave(ID_No,
                        (dgvProfessor[1, rowCounter].Value != null) ? (string)dgvProfessor[1, rowCounter].Value.ToString() : "",
                        (dgvProfessor[2, rowCounter].Value != null) ? (string)dgvProfessor[2, rowCounter].Value.ToString() : "",
                        (dgvProfessor[3, rowCounter].Value != null && dgvProfessor[3, rowCounter].Value.ToString().ValidateEmail()) ?
                        (string)dgvProfessor[3, rowCounter].Value.ToString() : "",
                        (dgvProfessor[4, rowCounter].Value != null) ? (string)dgvProfessor[4, rowCounter].Value.ToString() : "",
                        (dgvProfessor[6, rowCounter].Value != null) ? (string)dgvProfessor[6, rowCounter].Value.ToString() : "");
                }
            }

            db.Dispose();
        }