Exemple #1
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            //Delete Employee
            int      id  = Convert.ToInt32(tbID.Text);
            EMPLOYEE emp = new EMPLOYEE();

            try
            {
                //Show a confirmation message before delete
                if (MessageBox.Show("Are you sure?", "DELETE", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    if (emp.deleteEmployee(id))
                    {
                        MessageBox.Show("Employee Deleted", "DELETE", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        //clear fields
                        tbID.Text      = "";
                        tbname.Text    = "";
                        tbcontact.Text = "";
                        tbaddr.Text    = "";
                        tbemail.Text   = "";
                        comboBox1.Text = "";
                        tbsal.Text     = "";
                        pbpic.Image    = null;
                        tbnic.Text     = "";
                    }
                    else
                    {
                        MessageBox.Show("Employee is not Deleted", "DELETE", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Update", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            /* int id = Convert.ToInt32(tbID.Text);
             * string name = tbname.Text;
             * string tel = tbcontact.Text;
             * string addr = tbaddr.Text;
             * string email = tbemail.Text;
             * string empType = comboBox1.Text;
             * string sal = tbsal.Text;
             * string nic = tbnic.Text;
             *
             * try
             * {
             *   //Get Image
             *   MemoryStream photo = new MemoryStream();
             *   pbpic.Image.Save(photo, pbpic.Image.RawFormat);
             *
             *   if (emp.deleteEmployee(id))
             *   {
             *       MessageBox.Show("The employee details are deleted", "DELETE", MessageBoxButtons.OK, MessageBoxIcon.Information);
             *
             *   }
             *   else
             *   {
             *       MessageBox.Show("Something went wrong", "DELETE", MessageBoxButtons.OK, MessageBoxIcon.Error);
             *   }
             *
             *
             * }
             * catch (Exception ex)
             * {
             *   MessageBox.Show(ex.Message, "DELETE", MessageBoxButtons.OK, MessageBoxIcon.Error);
             * }
             */
        }