Esempio n. 1
0
        private void BtnAddStudent_Click(object sender, EventArgs e)
        {
            frmAddEditStudent frm = new frmAddEditStudent(this);

            frm.lblLibrarian.Text = admin;
            frm.btnUpdate.Enabled = false;
            frm.Show();
        }
Esempio n. 2
0
        private void GunaDataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            //Load to labels
            lblName.Text    = gunaDataGridView1[4, e.RowIndex].Value.ToString() + " " + gunaDataGridView1[3, e.RowIndex].Value.ToString();
            lblStudNo.Text  = gunaDataGridView1[2, e.RowIndex].Value.ToString();
            lblCourse.Text  = gunaDataGridView1[5, e.RowIndex].Value.ToString();
            lblYear.Text    = gunaDataGridView1[6, e.RowIndex].Value.ToString();
            lblGender.Text  = gunaDataGridView1[7, e.RowIndex].Value.ToString();
            lblContact.Text = gunaDataGridView1[8, e.RowIndex].Value.ToString();
            lblEmail.Text   = gunaDataGridView1[9, e.RowIndex].Value.ToString();
            lblAddress.Text = gunaDataGridView1[10, e.RowIndex].Value.ToString();
            byte[]       imgbytes = (byte[])gunaDataGridView1[11, e.RowIndex].Value;
            MemoryStream mstream  = new MemoryStream(imgbytes);

            stImage.Image = Image.FromStream(mstream);

            string colName = gunaDataGridView1.Columns[e.ColumnIndex].Name;

            if (colName == "Edit")
            {
                frmAddEditStudent frm = new frmAddEditStudent(this);
                frm.lblLibrarian.Text = admin;
                frm.btnSave.Enabled   = false;
                frm.lblTitle.Text     = "Edit Student Details";
                frm.lblID.Text        = gunaDataGridView1[1, e.RowIndex].Value.ToString();
                frm.txtStudNo.Text    = gunaDataGridView1[2, e.RowIndex].Value.ToString();
                frm.txtLname.Text     = gunaDataGridView1[3, e.RowIndex].Value.ToString();
                frm.txtFname.Text     = gunaDataGridView1[4, e.RowIndex].Value.ToString();
                frm.cboCourse.Text    = gunaDataGridView1[5, e.RowIndex].Value.ToString();
                frm.cboYear.Text      = gunaDataGridView1[6, e.RowIndex].Value.ToString();
                frm.txtContact.Text   = gunaDataGridView1[8, e.RowIndex].Value.ToString();
                frm.txtEmail.Text     = gunaDataGridView1[9, e.RowIndex].Value.ToString();
                frm.txtAddress.Text   = gunaDataGridView1[10, e.RowIndex].Value.ToString();
                //Load Image
                byte[]       bytes = (byte[])gunaDataGridView1[11, e.RowIndex].Value;
                MemoryStream ms    = new MemoryStream(bytes);
                frm.studImage.Image = Image.FromStream(ms);
                //Retrieve gender value to radio button
                if (gunaDataGridView1[7, e.RowIndex].Value.ToString() == "Male")
                {
                    frm.rbMale.Checked = true;
                }
                else
                {
                    frm.rbFemale.Checked = true;
                }
                //Show
                frm.Show();
            }
            else if (colName == "Delete")
            {
                if (MyMessageBox.ShowMessage("Are you sure you want to delete this record?", "Delete Record", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    cn.Open();
                    cm = new SqlCommand("UPDATE tblStudent SET accountStat = 'Deactivated' WHERE studentID like '" + gunaDataGridView1[1, e.RowIndex].Value.ToString() + "'", cn);
                    cm.ExecuteNonQuery();
                    cn.Close();

                    RemoveStudentLogs();
                    popupNotifier.ContentText = "Record has been successfully removed!";
                    popupNotifier.Popup();
                    LoadRecords();
                }
            }
        }