private void LoadData()
        {
            nsgStudent = DB.NSGStudents.Where(s => s.NSGStudentID == nsgStudentId).FirstOrDefault();

            txtFirstName.Text               = nsgStudent.FirstName;
            txtLastName.Text                = nsgStudent.LastName;
            cmbGender.Text                  = nsgStudent.Gender;
            cmbClass.Text                   = nsgStudent.Class;
            cmbSchool.SelectedValue         = nsgStudent.SchoolID;
            cmbBusRouteNumber.SelectedValue = nsgStudent.BusRouteID;
            cmbPickupPoint.SelectedValue    = nsgStudent.BusRouteDetailID;
            txtGuardianName.Text            = nsgStudent.GuardianName;
            txtMobileNo.Text                = nsgStudent.MobileNo;
            cmbRelationship.SelectedValue   = nsgStudent.RelationshipID;
            txtEmployeeId.Text              = nsgStudent.NSGEmployeeCode;
            cmbRank.SelectedValue           = nsgStudent.RankID;
            cmbUnit.SelectedValue           = nsgStudent.UnitID;
            cmbQuarterType.SelectedValue    = nsgStudent.QuarterTypeID;
            txtQuarterNumber.Text           = nsgStudent.QuarterNumber.ToString();
            dteIssueDate.Value              = nsgStudent.IssueDate;
            dteExpiryDate.Value             = Convert.ToDateTime(nsgStudent.ExpiryDate);
            dteBirthDate.Value              = nsgStudent.BirthDate;

            chkActive.Checked = nsgStudent.IsActive;

            if (nsgStudent.PassHolderPhoto.Length > 0)
            {
                picVisitorPhoto.Image = (Image)imgConverter.ConvertFrom(nsgStudent.PassHolderPhoto);
            }

            LoadDocuments();
        }
        private void RefreshMe(bool reEntry = false)
        {
            if (reEntry)
            {
                nsgStudentId = 0;
            }

            nsgStudent              = null;
            studentDocuments        = null;
            txtFirstName.Text       = string.Empty;
            txtLastName.Text        = string.Empty;
            cmbGender.SelectedIndex = -1;
            cmbClass.SelectedIndex  = -1;
            cmbSchool.SelectedIndex = -1;

            txtGuardianName.Text          = string.Empty;
            txtMobileNo.Text              = string.Empty;
            cmbRelationship.SelectedIndex = -1;
            txtEmployeeId.Text            = string.Empty;
            cmbRank.SelectedIndex         = -1;
            cmbUnit.SelectedIndex         = -1;
            cmbQuarterType.SelectedIndex  = -1;
            txtQuarterNumber.Text         = string.Empty;

            dteIssueDate.Value  = DateTime.Today;
            dteExpiryDate.Value = new DateTime(DateTime.Today.Year + 1, 3, 31);

            dteBirthDate.Value = DateTime.Today;

            chkActive.Checked = true;

            picVisitorPhoto.Image = null;

            if (nsgStudentId > 0)
            {
                LoadData();
                this.Text = "NSG Pass [EDIT] - " + (nsgStudentId).ToString().PadLeft(6, '0');
            }
            else
            {
                var nsgLastStudent = DB.NSGStudents.OrderByDescending(s => s.NSGStudentID).FirstOrDefault();

                if (nsgLastStudent == null)
                {
                    this.Text = "NSG Pass [ADD] - 000001";
                }
                else
                {
                    this.Text = "NSG Pass [ADD] - " + (nsgLastStudent.NSGStudentID + 1).ToString().PadLeft(6, '0');
                }
            }
        }
        private void btnEnter_Click(object sender, EventArgs e)
        {
            if (!ValidateMainControls())
            {
                return;
            }

            try
            {
                if (nsgStudent == null)
                {
                    nsgStudent             = new NSGStudent();
                    nsgStudent.EntryDate   = DateTime.Now;
                    nsgStudent.EntryUserID = GlobalClass.LoggedInUserID;
                }
                else
                {
                    nsgStudent.UpdateDate   = DateTime.Now;
                    nsgStudent.UpdateUserID = GlobalClass.LoggedInUserID;
                }

                nsgStudent.FirstName = txtFirstName.Text;
                nsgStudent.LastName  = txtLastName.Text;
                nsgStudent.BirthDate = dteBirthDate.Value;

                nsgStudent.Gender           = cmbGender.Text;
                nsgStudent.Class            = cmbClass.Text;
                nsgStudent.SchoolID         = Convert.ToInt16(cmbSchool.SelectedValue);
                nsgStudent.BusRouteID       = Convert.ToInt16(cmbBusRouteNumber.SelectedValue);
                nsgStudent.BusRouteDetailID = Convert.ToInt16(cmbPickupPoint.SelectedValue);

                nsgStudent.GuardianName    = txtGuardianName.Text;
                nsgStudent.MobileNo        = txtMobileNo.Text;
                nsgStudent.RelationshipID  = Convert.ToInt16(cmbRelationship.SelectedValue);
                nsgStudent.NSGEmployeeCode = txtEmployeeId.Text;

                nsgStudent.RankID        = Convert.ToInt16(cmbRank.SelectedValue);
                nsgStudent.UnitID        = Convert.ToInt16(cmbUnit.SelectedValue);
                nsgStudent.QuarterTypeID = Convert.ToInt16(cmbQuarterType.SelectedValue);
                nsgStudent.QuarterNumber = Convert.ToInt16(txtQuarterNumber.Text);

                nsgStudent.IssueDate  = dteIssueDate.Value;
                nsgStudent.ExpiryDate = dteExpiryDate.Value;
                nsgStudent.IsActive   = chkActive.Checked;

                byte[] passHolderImage = (byte[])imgConverter.ConvertTo(picVisitorPhoto.Image, typeof(byte[]));

                nsgStudent.PassHolderPhoto = passHolderImage;

                if (nsgStudent.NSGStudentID == 0)
                {
                    DB.NSGStudents.Add(nsgStudent);
                }

                DB.SaveChanges();

                nsgStudentId = nsgStudent.NSGStudentID;

                SaveDocuments();

                DialogResult msgResponse = MessageBox.Show("Student Pass information saved successfully.\nDo you want to continue with Print?", this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);

                if (msgResponse == DialogResult.Yes)
                {
                    btnPrint_Click(null, null);
                }

                msgResponse = MessageBox.Show("Do you want to continue with Pass Entry?", this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);

                if (msgResponse == DialogResult.Yes)
                {
                    RefreshMe(true);
                }
                else
                {
                    btnCancel_Click(null, null);
                }
            }
            catch (Exception ex)
            {
                this.Cursor = Cursors.Default;
                MessageBox.Show(ex.Message, this.Text + " : btnEnter_Click : " + ex.Source, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }