private void btnScanDoc_Click(object sender, EventArgs e)
        {
            foreach (Form form in Application.OpenForms)
            {
                if (form.Name == "frmDocumentScanner")
                {
                    form.Activate();
                    return;
                }
            }

            if (bool.Parse(ConfigurationManager.AppSettings["UseScanner"].ToString()))
            {
                GlobalClass.CurrentDocument     = null;
                GlobalClass.CurrentDocumentName = string.Empty;

                frmDocumentScanner documentScanner = new frmDocumentScanner();

                DialogResult docScanResult = documentScanner.ShowDialog();

                if (docScanResult == DialogResult.OK)
                {
                    if (GlobalClass.CurrentDocument == null)
                    {
                        MessageBox.Show("Please scan document again.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }

                    if (passDocuments == null)
                    {
                        passDocuments = new List <PassDocument>();
                    }

                    passDocuments.Add(new PassDocument()
                    {
                        EntryDate = DateTime.Now, EntryUserID = GlobalClass.LoggedInUserID, NSGPassID = nsgPassId, DocumentName = GlobalClass.CurrentDocumentName, DocumentPhoto = (byte[])imgConverter.ConvertTo(GlobalClass.CurrentDocument, typeof(byte[]))
                    });

                    dgvDocuments.Rows.Add(new[] { "0", GlobalClass.CurrentDocumentName });
                }
            }
            else
            {
                openFileDialog.Filter      = "JPG Files (*.jpg)";
                openFileDialog.Multiselect = false;

                if (openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    Image document = (Image)imgConverter.ConvertFrom((object)openFileDialog.OpenFile());

                    passDocuments.Add(new PassDocument()
                    {
                        EntryDate = DateTime.Now, EntryUserID = GlobalClass.LoggedInUserID, NSGPassID = nsgPassId, DocumentName = openFileDialog.FileName, DocumentPhoto = (byte[])imgConverter.ConvertTo(document, typeof(byte[]))
                    });

                    dgvDocuments.Rows.Add(new[] { "0", openFileDialog.FileName });
                }
            }
        }
        private void dgvDocuments_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            var senderGrid = (DataGridView)sender;

            if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn && e.RowIndex >= 0)
            {
                GlobalClass.CurrentDocumentName = senderGrid.Rows[e.RowIndex].Cells["DocumentName"].Value.ToString();
                GlobalClass.CurrentDocument     = (Image)imgConverter.ConvertFrom(passDocuments.Where(pd => pd.DocumentName == senderGrid.Rows[e.RowIndex].Cells["DocumentName"].Value.ToString()).FirstOrDefault().DocumentPhoto);

                frmDocumentScanner documentScanner = new frmDocumentScanner();
                documentScanner.ShowDialog();
            }
        }