private void btnDeleterecord_Click(object sender, EventArgs e)
        {
            int    rowNum   = examineeDataGridView.CurrentCell.RowIndex;
            string examinID = examineeDataGridView[0, rowNum].Value.ToString();

            DialogResult answer = MessageBox.Show("Are you sure you want to delete " + examinID + "?", "Confirm", MessageBoxButtons.OKCancel);

            if (answer == DialogResult.OK)
            {
                using (ExamineeDataContext dbContext = new ExamineeDataContext())
                {
                    try
                    {
                        Examinee currentExaminee = (from exe in dbContext.Examinees
                                                    where exe.ExamineeID == Convert.ToInt32(examinID)
                                                    select exe).SingleOrDefault();

                        dbContext.Examinees.DeleteOnSubmit(currentExaminee);
                        dbContext.SubmitChanges();
                        RefreshGridView();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, ex.GetType().ToString());
                    }
                }
            }
        }
Exemple #2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (isAdd)
            {
                if (Validator.IsPresent(examineeIDTextBox) &&
                    Validator.IsPresent(examineeFirstnameTextBox) &&
                    Validator.IsPresent(examineeLastnameTextBox) &&
                    Validator.IsPresent(examineeEmailTextBox))
                {
                    Examinee newExaminee = new Examinee // create product using provided data
                    {
                        ExamineeID        = Convert.ToInt32(examineeIDTextBox.Text),
                        ExamineeFirstname = examineeFirstnameTextBox.Text,
                        ExamineeLastname  = examineeLastnameTextBox.Text,
                        ExamineeEmail     = examineeEmailTextBox.Text
                    };
                    using (ExamineeDataContext dbContext = new ExamineeDataContext())
                    {
                        dbContext.Examinees.InsertOnSubmit(newExaminee);
                        dbContext.SubmitChanges();
                    }
                    DialogResult = DialogResult.OK;
                }
                else // validation  failed
                {
                    DialogResult = DialogResult.Cancel;
                }
            }

            else // it is Modify
            {
                if (Validator.IsPresent(examineeIDTextBox) &&
                    Validator.IsPresent(examineeFirstnameTextBox) &&
                    Validator.IsPresent(examineeLastnameTextBox) &&
                    Validator.IsPresent(examineeEmailTextBox))
                {
                    try
                    {
                        int examinID = Convert.ToInt32(examineeIDTextBox.Text);
                        // ExamineeDataContext db2 = new ExamineeDataContext();
                        Examinee examin2 = new Examinee();
                        examin2 = db2.Examinees.Single(x => x.ExamineeID == examinID);
                        examin2.ExamineeFirstname = examineeFirstnameTextBox.Text;
                        examin2.ExamineeLastname  = examineeLastnameTextBox.Text;
                        examin2.ExamineeID        = Convert.ToInt32(examineeIDTextBox.Text);
                        examin2.ExamineeEmail     = examineeEmailTextBox.Text;
                        db2.SubmitChanges();
                    }
                    catch (DBConcurrencyException)
                    {
                        MessageBox.Show("Other user changed or deleted data. Try Again", "Concurrency Error");
                    }
                    //Handling for general exception
                    catch (Exception ex)
                    {
                        MessageBox.Show("Other error while saving changes: " + ex.Message,
                                        ex.GetType().ToString());
                    }
                }
                else // validation failed
                {
                    DialogResult = DialogResult.Cancel;
                }
            }
        }
 partial void DeleteExaminee(Examinee instance);
 partial void UpdateExaminee(Examinee instance);
 partial void InsertExaminee(Examinee instance);