Saturday, 11 July 2015

Binary image

You can not simply bind binary image to a control. You have to create an HttpHandler(.ashx) that process the image.

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Web;

namespace DisplayImages
{
    /// <summary>
    /// Summary description for Handler1
    /// </summary>
    public class Handler1 : System.Web.IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            using (SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["conString"].ConnectionString))
            {
                const string SQL = "SELECT Image,ImageName FROM ImageToDB WHERE [ID] = @ID";
                SqlCommand myCommand = new SqlCommand(SQL, myConnection);
                myCommand.Parameters.AddWithValue("@ID", 4);

                myConnection.Open();
                SqlDataReader myReader = myCommand.ExecuteReader();

                if (myReader.Read())
                {
                    //byte[] buffer = GetPictureFromSomewhere();
                    context.Response.ContentType = "image/jpg";
                    context.Response.OutputStream.Write(((byte[])myReader["Image"]), 0, ((byte[])myReader["Image"]).Length);
                    //(byte[])myReader["Image"]
                    //string base64String = Convert.ToBase64String((byte[])myReader["Image"], 0, ((byte[])myReader["Image"]).Length);
                    //image.ImageUrl = "data:image/jpg;base64," + base64String;
                    //Image1.Visible = true;
                }

                myReader.Close();
                myConnection.Close();
            }           
        }

        public bool IsReusable
        {
            get { return false; }
        }
    }
}

add the follwong code in default.aspx, design code is below the c# code

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace DisplayImages
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                
            }
        }

        protected void btnUpload_Click(object sender, EventArgs e)
        {
            // Read the file and convert it to Byte Array
            string filePath = FileUpload1.PostedFile.FileName;
            string filename = Path.GetFileName(filePath);
            string ext = Path.GetExtension(filename);
            string contenttype = String.Empty;

            //Set the contenttype based on File Extension
            switch (ext)
            {
                case ".doc":
                    contenttype = "application/vnd.ms-word";
                    break;
                case ".docx":
                    contenttype = "application/vnd.ms-word";
                    break;
                case ".xls":
                    contenttype = "application/vnd.ms-excel";
                    break;
                case ".xlsx":
                    contenttype = "application/vnd.ms-excel";
                    break;
                case ".jpg":
                    contenttype = "image/jpg";
                    break;
                case ".png":
                    contenttype = "image/png";
                    break;
                case ".gif":
                    contenttype = "image/gif";
                    break;
                case ".pdf":
                    contenttype = "application/pdf";
                    break;
            }
            if (contenttype != String.Empty)
            {

                Stream fs = FileUpload1.PostedFile.InputStream;
                BinaryReader br = new BinaryReader(fs);
                Byte[] bytes = br.ReadBytes((Int32)fs.Length);

                //insert the file into database
                string strQuery = "insert into ImageToDB(Image,ImageName)" +
                   " values (@Image, @ImageName)";
                SqlCommand cmd = new SqlCommand(strQuery);
                cmd.Parameters.Add("@Image", SqlDbType.Binary).Value = bytes;
                cmd.Parameters.Add("@ImageName", SqlDbType.VarChar).Value = filename;
                //cmd.Parameters.Add("@Data", SqlDbType.Binary).Value = bytes;
                InsertUpdateData(cmd);
                lblMessage.ForeColor = System.Drawing.Color.Green;
                lblMessage.Text = "File Uploaded Successfully";
            }
            else
            {
                lblMessage.ForeColor = System.Drawing.Color.Red;
                lblMessage.Text = "File format not recognised." +
                  " Upload Image/Word/PDF/Excel formats";
            }
        }

        private Boolean InsertUpdateData(SqlCommand cmd)
        {
            String strConnString = System.Configuration.ConfigurationManager
            .ConnectionStrings["conString"].ConnectionString;
            SqlConnection con = new SqlConnection(strConnString);
            cmd.CommandType = CommandType.Text;
            cmd.Connection = con;
            try
            {
                con.Open();
                cmd.ExecuteNonQuery();
                return true;
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
                return false;
            }
            finally
            {
                con.Close();
                con.Dispose();
            }
        }
        private void BinaryToImage()
        {
            try
            {
                int PictureID = Convert.ToInt32(Request.QueryString["ID"]);

                using (SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["conString"].ConnectionString))
                {
                    const string SQL = "SELECT Image,ImageName FROM ImageToDB WHERE [ID] = @ID";
                    SqlCommand myCommand = new SqlCommand(SQL, myConnection);
                    myCommand.Parameters.AddWithValue("@ID", 4);

                    myConnection.Open();
                    SqlDataReader myReader = myCommand.ExecuteReader();

                    if (myReader.Read())
                    {
                        //Response.ContentType = myReader["MIME"].ToString();
                        Response.BinaryWrite((byte[])myReader["Image"]);
                    }

                    myReader.Close();
                    myConnection.Close();
                }
            }
            catch (Exception ex)
            {
                Response.Write(ex.ToString());
            }
        }

        protected void Show_Click(object sender, EventArgs e)
        {
            image.ImageUrl = "~/Handler1.ashx";          
            //image.ImageUrl = BinaryToImage();
            //BinaryToImage();
        }
    }
}

Design page of default.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="DisplayImages.Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:FileUpload ID="FileUpload1" runat="server" />
        <asp:Button ID="btnUpload" runat="server" Text="Upload"
            OnClick="btnUpload_Click" />
        <br />
        <asp:Button ID="Show" runat="server" OnClick="Show_Click" Text="Show" />
        <br />
        <asp:Label ID="lblMessage" runat="server" Text=""
            Font-Names="Arial"></asp:Label>
        <asp:Image ID="image" runat="server" />
    </form>
</body>
</html>

Web.config file

<?xml version="1.0"?>

<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->

<configuration>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
  </system.webServer>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />

    <httpModules>
      <add name="Picture" type="Picture"/>
    </httpModules>
  </system.web>
  <connectionStrings>
    <add name="conString" connectionString="Server=SUNDARI-PC\SQLSERVER2012; Database=test; Integrated Security=True"/>
  </connectionStrings >
  <!--<configuration>
  <system.web>
    <httpModules>
      <add name="Picture" type="Picture"/>
     </httpModules>
  </system.web>
</configuration>-->
</configuration>



In your web.config you should add:
<httpHandlers>
    ...
    <add path="ImageHandler.ashx" type="Actilog.Parametre.Famille.ImageHandler"
      verb="*" validate="false" />
    ...
</httpHandlers>
To allow Asp.Net to manage every requests containig "ImageHandler.ashx" with the correct IHttpHandler class. And remember to add:
<system.webServer>
    <handlers>
    ...
    <add name="ImageHandler" path="ImageHandler.ashx" type="Actilog.Parametre.Famille.ImageHandler"
          verb="*" validate="false" />
    ...
    </handlers>
</system.webServer>

Sunday, 7 June 2015

jquery settimeout

setTimeout(function () {

window.location.href="form location";},2000);

or
in default.aspx design

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        body
        {
            font-family: Arial;
            font-size: 10pt;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    Enter Name:
    <asp:TextBox ID="txtName" runat="server" />
    <br />
    <asp:Button Text="Submit" runat="server" OnClick="Submit" /><br />
    <br />
    <asp:Label ID="lblMessage" ForeColor="Green" Font-Bold="true" Text="Form has been submitted successfully."
        runat="server" Visible="false" />
    <script type="text/javascript">
       
        window.onload = function () {
            debugger;
            var seconds = 5;
            setTimeout(function () {
                document.getElementById("<%=lblMessage.ClientID %>").style.display = "none";
            }, seconds * 1000);
        };
    </script>
    </form>
</body>
</html>

in code behind

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Submit(object sender, EventArgs e)
    {
        lblMessage.Visible = true;
    }
}

Jquery popup

1. put <script src="AppResource/JS/jquery-1.9.1.min.js" type="text/javascript"></script>  and
<script src="AppResource/JS/jquery-ui.js" type="text/javascript"></script>  into master page or corresponding page.

2. Inside aspx page write below codes

<script type="text/javascript">

function Confirmpopup(){
$('#hider').fadeIn("slow");
$("#divConfirm").dialog({modal:true})
}

function CloseModalWnd(){
$('#hider').fadeOut("slow");
$(".ui-dialog-content").dialog().dialog("close");

function HideModalWind() {
$("#hider").hide();
$("#divConfirm").hide();
}

<style type="text/css">

.ui-dialog-content ui-widget-content{
width: 800px !import;
height:500px !import;
}

#divConfirm{
background-color:white;
width:1000px !import;
margin-top: -40px;
height:500px !impotant;
margin-left:-200px;
}
</style>

3. In code behind

declare globaly

 bool isHideModel=true;

write
protected override void onInit(EventArgs e)
{
if(isHideModel)
ScriptManager.RegisterStartupScript(Page, typeof(Page),"Hidepopout","HideModalWind();",true);
}

in button click to display popup code

protected void popout_click(object sender, EventArgs e)
{
ScriptManager.RegisterStartupScript('Page,typeof(Page),"popout","Confirmpopup();",true);
}

4. ok close button inside popup

<input type="button" id="btnOk" value="Ok" onClick=""/>
<input type="button" id="btnClose" value="Close" style="Width: 50px; font-weight:bold;" onClick="CloseModalWnd();" />

Sunday, 24 May 2015

Properties

Customer Registration

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using UTool;
using Utility;
using GoldTree.Entity;
using GoldTree.DAL;
using Sagacity.JMSysSplash.WinApps;
using System.IO;
using GoldTree.Transaction;

namespace GoldTree
{
    public partial class CustomerRegistration : UTool.FormTemplate,UTool.IOMethod
    {
        #region instance member

        TransType _transType;
        public decimal bonus = 0;
        public int period = 0;
        public int Customerperiod = 0;
        public string Type = "";
        nominee nominee = new nominee();
       
        #endregion

        #region Constructor

        public CustomerRegistration()
        {
            InitializeComponent();
        }

        #endregion

        #region private method

        public void FillScheme()
        {
            IList<Scheme_Master> schemeMaster = new List<Scheme_Master>();
            DataSet dsMast = SchemeMasterData.selectForScheme();
            DataRow[] dr = dsMast.Tables["SchemeMaster"].Select();
            foreach (DataRow dtr in dr)
            {
                if (dtr["STATUS"].ToString() != TransType.Delete.ToString())
                {
                    schemeMaster.Add(new Scheme_Master
                    {
                        SchemeId = UDF.ToIntiger(dtr["SchemeId"].ToString()),
                        SchemeName = dtr["SchemeName"].ToString(),
                    });
                }
            }
            schemeMaster.Insert(0, new Scheme_Master { SchemeId = 0, SchemeName = "--Select One--" });
            cmbScheme.DataSource = schemeMaster;
            cmbScheme.DisplayMember = "SchemeName";
            cmbScheme.ValueMember = "SchemeId";
            cmbScheme.SelectedIndex = 0;
        }

        private void DisplayCustomerInformation(int custId)
        {
            try
            {
                UDF.clearCtrl(new Control[] { vtbName, vtbCardNo, cmbGender, vtbAddress1, vtbAddress2, vtbEmail, vtbContactNo, vtbPhoto });
                DataSet dsMast = CustomerRegistrationData.selectForCustomerInformation(custId);
                foreach (DataRow dr in dsMast.Tables[0].Rows)
                {
                    vtbName.Tag = UDF.ToIntiger(dr["CustomerId"].ToString());
                    vtbName.Text = dr["Name"].ToString();
                    vtbCardNo.Text = dr["CardNo"].ToString();
                    cmbGender.Text = dr["Gender"].ToString();
                    vtbAddress1.Text = dr["Address1"].ToString();
                    vtbAddress2.Text = dr["Address2"].ToString();
                    vtbEmail.Text = dr["Email"].ToString();
                    vtbContactNo.Text = dr["ContactNo"].ToString();
                    if (dr["Photo"].ToString() == "")
                    {
                        vtbPhoto.Text = "";
                        pctImage.Image = null;
                    }
                    else
                    {
                        vtbPhoto.Text = Application.StartupPath + "\\" + @"Image" + "\\" + dr["Photo"].ToString();
                        pctImage.Image = Image.FromFile(@"" + vtbPhoto.Text + "");
                    }
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }

        private void DisplayCustomerRegistration(int Id)
        {
            try
            {
                UDF.clearCtrl(new Control[] { vtbName, vtbCardNo, cmbGender, vtbAddress1, vtbAddress2, vtbEmail, vtbContactNo, vtbPhoto, vtbPremiumvalue, vtbSchemeValue, vtbIncetive, vtbMaturityValue, vtbPremiumWt, vtbSchemeWt, vtbIncentiveWt, vtbMaturityWt, dtpMaturityDate });
                DataSet dsMast = CustomerRegistrationData.selectForCustomerRegistration(Id);
                foreach (DataRow dr in dsMast.Tables[0].Rows)
                {
                    recordNo.Text = dr["RegistrationNo"].ToString();
                    recordNo.Tag = UDF.ToIntiger(dr["RegistrationNo"].ToString());
                    recordDate.Value = Convert.ToDateTime(dr["RegistrationDate"].ToString());
                    vtbName.Tag = UDF.ToIntiger(dr["CustomerId"].ToString());
                    vtbName.Text = dr["Name"].ToString();
                    vtbCardNo.Text = dr["CardNo"].ToString();
                    cmbGender.Text = dr["Gender"].ToString();
                    vtbAddress1.Text = dr["Address1"].ToString();
                    vtbAddress2.Text = dr["Address2"].ToString();
                    vtbEmail.Text = dr["Email"].ToString();
                    vtbContactNo.Text = dr["ContactNo"].ToString();
                   
                    cmbScheme.Text = dr["SchemeName"].ToString();
                    cmbScheme.SelectedValue = UDF.ToIntiger(dr["SchemeId"].ToString());
                    vtbPremiumvalue.Text = dr["PremiumAmount"].ToString();
                    vtbSchemeValue.Text = dr["SchemeValue"].ToString();
                    vtbIncetive.Text = dr["Incentive"].ToString();
                    vtbMaturityValue.Text = dr["MaturityAmount"].ToString();
                    vtbPremiumWt.Text = dr["PremiumWeight"].ToString();
                    vtbSchemeWt.Text = dr["SchemeWeight"].ToString();
                    vtbIncentiveWt.Text = dr["IncentiveWeight"].ToString();
                    vtbMaturityWt.Text = dr["MaturityWeight"].ToString();
                    dtpMaturityDate.Value = Convert.ToDateTime(dr["MaturityDate"].ToString());
                    #region nominee information
                    Nominee_Entity objnom_Entity = new Nominee_Entity();
                    objnom_Entity.RegistrationNo = UDF.ToIntiger(dr["RegistrationNo"].ToString());
                    objnom_Entity.Name = dr["NomineeName"].ToString();
                    objnom_Entity.IdentityProof = dr["IdentityProof"].ToString();
                    objnom_Entity.Relation = dr["Relation"].ToString();
                    objnom_Entity.Photo = dr["NomineePhoto"].ToString();
                    objnom_Entity.Email = dr["NomineeEmail"].ToString();
                    objnom_Entity.ContactNo = dr["NomineeContactNo"].ToString();
                    objnom_Entity.CorrespondenceAddress1 = dr["CorrespondenceAddress1"].ToString();
                    objnom_Entity.CorrespondenceAddress2 = dr["CorrespondenceAddress2"].ToString();
                    nominee_Entity = objnom_Entity;
                    #endregion

                    if (dr["Photo"].ToString() == "")
                    {
                        vtbPhoto.Text = "";
                        pctImage.Image = null;
                    }
                    else
                    {
                        vtbPhoto.Text = Application.StartupPath + "\\" + @"Image" + "\\" + dr["Photo"].ToString();
                        pctImage.Image = Image.FromFile(@"" + vtbPhoto.Text + "");
                    }
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }

        private void Displayscheme()
        {
            try
            {
                    DataSet dsMast = SchemeMasterData.selectForScheme(Convert.ToInt32(cmbScheme.SelectedValue));
                    DataRow dr = dsMast.Tables["SchemeMaster"].Select().First();
                    bonus = Convert.ToDecimal(dr["Bonus"].ToString());
                    period = UDF.ToIntiger(dr["Period"].ToString());
                    Customerperiod = UDF.ToIntiger(dr["Customerperiod"].ToString());
                    Type = dr["Type"].ToString();
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }

        private decimal DisplayRate()
        {
            DataSet dsMast = RateMasterData.selectForRate();
            DataRow dr = dsMast.Tables["RateMaster"].Select().First();
            decimal rate = Convert.ToDecimal(dr["Rate"].ToString());
            return rate;
        }

        private void PrintVoucher()
        {
            IList<int> value = new List<int>();
            File.Delete(@"D:\Document Print\CustomerRegistrationPrint.htm");
            FileStream fileStream = new FileStream(@"D:\Document Print\CustomerRegistrationPrint.htm", FileMode.OpenOrCreate, FileAccess.Write);
            StreamWriter streamWriter = new StreamWriter(fileStream);
            streamWriter.BaseStream.Seek(0, SeekOrigin.End);

            streamWriter.WriteLine(@"<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>");
            streamWriter.WriteLine(@"<html xmlns='http://www.w3.org/1999/xhtml'>");
            streamWriter.WriteLine(@"<head>");
            streamWriter.WriteLine(@"<title>");
            streamWriter.WriteLine(@"</title>");
            streamWriter.WriteLine(@"</head>");

            streamWriter.WriteLine(@"<body style='font-size: 9px; font-family: Verdana; margin-top: 10px; margin-left: 60px;margin-right: 50px;'>");

            streamWriter.WriteLine(@"<table  width='90%' align='center' cellpadding='0' cellspacing='0' height: '100px'>");

            streamWriter.WriteLine(@"<tr>");
            streamWriter.WriteLine(@"<td align='center' style='font-size: 14px;' colspan='0'>");
            streamWriter.WriteLine(@"<b>" + Program.CompanyName.ToUpper() + " </b>");

            streamWriter.WriteLine(@"<br />");

            streamWriter.WriteLine(@"<font style='font-size: 11px;'>" + Program.Address1 + "</font>");
            streamWriter.WriteLine(@"<br />");
            streamWriter.WriteLine(@"<font style='font-size: 11px;'>" + Program.Address2 + "</font>");
            streamWriter.WriteLine(@"<br />");
            streamWriter.WriteLine(@"<br />");
            streamWriter.WriteLine(@"</td>");
            streamWriter.WriteLine(@"</tr>");

            streamWriter.WriteLine(@"<tr>");
            streamWriter.WriteLine("<td align='center' valign='top' style='font-size: 14px;' colspan='2'><b>Customer Registration</b></td>");
            streamWriter.WriteLine(@"</tr>");
            streamWriter.WriteLine(@"<br />");

            streamWriter.WriteLine(@"<tr>");
            streamWriter.WriteLine(@"<td align='right' valign='top' style='font-size: 11px;' colspan='2'>&nbsp;&nbsp;Registration No:" + recordNo.Text + "<br/></td>");
            streamWriter.WriteLine(@"</tr>");
            streamWriter.WriteLine(@"<br />");
            streamWriter.WriteLine(@"<tr>");
            streamWriter.WriteLine(@"<td align='right' valign='top' style='font-size: 11px;' colspan='2'>Date:" + recordDate.Value.ToString("dd-MMM-yyyy") + "<br/></td>");
            streamWriter.WriteLine(@"</tr>");
            streamWriter.WriteLine(@"<tr>");




            streamWriter.WriteLine(@"<tr>");
            streamWriter.WriteLine(@"<td colspan='2'>");

            streamWriter.WriteLine(@"<table width='100%' align='right' cellpadding='0' cellspacing='0'>");
            streamWriter.WriteLine(@"<tr>");
            streamWriter.WriteLine(@"<td>");
            streamWriter.WriteLine(@"<table width='100%'  cellpadding='4' cellspacing='0' align='right'>");

            streamWriter.WriteLine(@"<tr>");
            streamWriter.WriteLine(@"<td style='width: 20%;'>");
            streamWriter.WriteLine(@"Customer Name");
            streamWriter.WriteLine(@"</td>");
            streamWriter.WriteLine(@"<td style='width: 2%;'>:</td>");
            streamWriter.WriteLine(@"<td align='left'>");
            streamWriter.WriteLine(vtbName.Text);
            streamWriter.WriteLine(@"</td>");
            streamWriter.WriteLine(@"</tr>");


            streamWriter.WriteLine(@"<tr>");
            streamWriter.WriteLine(@"<td style='width: 20%;'>");
            streamWriter.WriteLine(@"Card No");
            streamWriter.WriteLine(@"</td>");
            streamWriter.WriteLine(@"<td style='width: 2%;'>:</td>");
            streamWriter.WriteLine(@"<td align='left'>");
            streamWriter.WriteLine(vtbCardNo.Text);
            streamWriter.WriteLine(@"</td>");
            streamWriter.WriteLine(@"</tr>");

            streamWriter.WriteLine(@"<tr>");
            streamWriter.WriteLine(@"<td style='width: 20%;'>");
            streamWriter.WriteLine(@"Scheme Type");
            streamWriter.WriteLine(@"</td>");
            streamWriter.WriteLine(@"<td style='width: 2%;'>:</td>");
            streamWriter.WriteLine(@"<td align='left'>");
            streamWriter.WriteLine(cmbScheme.Text);
            streamWriter.WriteLine(@"</td>");
            streamWriter.WriteLine(@"</tr>");        


            streamWriter.WriteLine(@"<tr>");
            streamWriter.WriteLine(@"<td style='width: 10%;'>");
            streamWriter.WriteLine(@"Date of Maturity");
            streamWriter.WriteLine(@"</td>");
            streamWriter.WriteLine(@"<td style='width: 2%;'>:</td>");
            streamWriter.WriteLine(@"<td align='left'>");
            streamWriter.WriteLine(dtpMaturityDate.Value.ToString("dd-MMM-yyyy"));
            streamWriter.WriteLine(@"</td>");
            streamWriter.WriteLine(@"</tr>");

            streamWriter.WriteLine(@"</table>");
            streamWriter.WriteLine(@"</td>");
            streamWriter.WriteLine(@"</tr>");
            streamWriter.WriteLine(@"</table>");
         
            streamWriter.Flush();
            streamWriter.Close();
            //PrintPreview frmPrintPreview = new PrintPreview();
            //frmPrintPreview.DocumentSource = @"D:\Document Print\OldPurchaseRegisterPrint.htm";
            //frmPrintPreview.Show();
            System.Diagnostics.Process.Start(@"D:\Document Print\CustomerRegistrationPrint.htm");
        }

        #endregion

        #region IOMethod Members

        #region nominee property

        private Nominee_Entity _nominee_Entity;
        public Nominee_Entity nominee_Entity
        {
            get { return _nominee_Entity; }
            set { _nominee_Entity = value; }
        }

        #endregion

        public string ModuleId
        {
            get { return "107"; }
        }

        public int RecordId
        {
            get;
            set;
        }

        public new UTool.TransType Refresh()
        {
            UDF.clearCtrl(new Control[] { vtbName, vtbCardNo, cmbGender, vtbAddress1, vtbAddress2, vtbEmail, vtbContactNo, vtbPhoto, vtbPremiumvalue, vtbSchemeValue, vtbIncetive, vtbMaturityValue, dtpMaturityDate });
            pctImage.Image = null;
            _transType = TransType.Refresh;
            return _transType;
        }

        public UTool.TransType Add()
        {
            try
            {
                UDF.clearCtrl(new Control[] { vtbName, vtbCardNo, cmbGender, vtbAddress1, vtbAddress2, vtbEmail, vtbContactNo, vtbPhoto, vtbPremiumvalue, vtbSchemeValue, vtbIncetive, vtbMaturityValue, vtbPremiumWt, vtbSchemeWt, vtbIncentiveWt, vtbMaturityWt, dtpMaturityDate });
                UDF.enableCtrl(new Control[] { vtbName, vtbCardNo, cmbGender, cmbScheme, vtbAddress1, vtbAddress2, vtbEmail, vtbContactNo, vtbPhoto, vtbPremiumvalue, vtbSchemeValue, vtbIncetive, vtbMaturityValue, vtbPremiumWt, vtbSchemeWt, vtbIncentiveWt, vtbMaturityWt, dtpMaturityDate, btnBrowse }, true);
                pctImage.Image = null;
                vtbName.Focus();
                recordNo.Text = "Generating";
                vtbCardNo.Text = "Generating";
                recordDate.Value = System.DateTime.Now.Date;
                cmbGender.Text = "Select One";
                cmbGender.Items.Insert(0, "Select One");
                cmbGender.Items.Insert(1, "Male");
                cmbGender.Items.Insert(2, "Female");
                cmbGender.SelectedIndex = 0;
                cmbScheme.SelectedIndex = 0;
                vtbSchemeValue.Text = "0.00";
                vtbIncetive.Text = "0.00";
                vtbMaturityValue.Text = "0.00";
                vtbPremiumWt.Text = "0.000";
                vtbSchemeWt.Text = "0.000";
                vtbIncentiveWt.Text = "0.000";
                vtbMaturityWt.Text = "0.000";
                nominee_Entity = null;
                _transType = TransType.Add;
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
            return _transType;
        }

        public UTool.TransType Edit()
        {
            try
            {
                UDF.enableCtrl(new Control[] { vtbName, vtbCardNo, cmbGender, cmbScheme, vtbAddress1, vtbAddress2, vtbEmail, vtbContactNo, vtbPhoto, vtbPremiumvalue, vtbSchemeValue, vtbIncetive, vtbMaturityValue, vtbPremiumWt, vtbSchemeWt, vtbIncentiveWt, vtbMaturityWt, dtpMaturityDate, btnBrowse }, true);
                vtbName.Select();
                vtbName.Focus();
                cmbGender.Items.Insert(0, "--Select One--");
                cmbGender.Items.Insert(1, "Male");
                cmbGender.Items.Insert(2, "Female");
                vtbCardNo.ReadOnly = true;
                _transType = TransType.Edit;
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
            return _transType;
        }

        public UTool.TransType Save()
        {
            try
            {
                #region vallidation checking
                if (vtbName.Text.Trim() == "")
                {
                    MessageBox.Show("Please Enter a valid Name.");
                    vtbName.Focus();
                    return _transType;
                }
                if (vtbCardNo.Text.Trim() == "")
                {
                    MessageBox.Show("Please Enter a valid No.");
                    vtbCardNo.Focus();
                    return _transType;
                }
                //DataSet dsMast = CustomerMasterData.selectForCustomer();
                //DataRow[] dr = dsMast.Tables["CustomerMaster"].Select("CardNo = '"+vtbCardNo.Text.Trim()+"'");
                //if (_transType == TransType.Add)
                //{
                //    if (dr.Count() > 0)
                //    {
                //        MessageBox.Show("Duplicate card no.");
                //        vtbCardNo.Focus();
                //        return _transType;
                //    }
                //}

               else if (_transType == TransType.Edit)
                    vtbCardNo.ReadOnly = true;
                if (cmbGender.SelectedIndex == 0)
                {
                    MessageBox.Show("Please Enter Gender");
                    cmbGender.Focus();
                    return _transType;
                }
                if (cmbScheme.SelectedIndex == 0)
                {
                    MessageBox.Show("Please Enter a valid Scheme");
                    cmbScheme.Focus();
                    return _transType;
                }
                if (vtbPremiumvalue.Text == "" || Convert.ToDecimal(vtbPremiumvalue.Text) <= 0)
                {
                    Displayscheme();
                    if (Type == "Money")
                    {
                        MessageBox.Show("Please Enter a valid Premium value");
                        vtbPremiumvalue.Focus();
                        return _transType;
                    }
                }

                #endregion
                int result = 0;
                CustomerRegistrationData customerRegistrationData = new CustomerRegistrationData();

                Customer_Master customerMaster = new Customer_Master
                {
                    //CustomerId = UDF.ToIntiger(vtbName.Tag),
                    Name = vtbName.Text,
                    CompanyId = Program.CompanyId,                  
                    CardNo = vtbCardNo.Text,
                    Gender = cmbGender.Text,
                    Address1 = vtbAddress1.Text,
                    Address2 = vtbAddress2.Text,
                    Email = vtbEmail.Text,
                    ContactNo = vtbContactNo.Text,
                    Photo = vtbPhoto.Text.Substring(vtbPhoto.Text.LastIndexOf('\\') + 1)
                };

                Customer_Registration customerregistration = new Customer_Registration
                {
                    RegistrationDate = Convert.ToDateTime(recordDate.Value.Date.ToString()),
                    SchemeId = Convert.ToInt32(cmbScheme.SelectedValue),
                    PremiumAmount = Convert.ToDecimal(vtbPremiumvalue.Text),
                    Schemevalue =  Convert.ToDecimal(vtbSchemeValue.Text),
                    Incentive = Convert.ToDecimal(vtbIncetive.Text),
                    PremiumWeight = Convert.ToDecimal(vtbPremiumWt.Text),
                    SchemeWeight = Convert.ToDecimal(vtbSchemeWt.Text),
                    IncentiveWeight = Convert.ToDecimal(vtbIncentiveWt.Text),
                    MaturityDate = Convert.ToDateTime(dtpMaturityDate.Value.Date.ToString()),
                    MaturityAmount = Convert.ToDecimal(vtbMaturityValue.Text),
                    MaturityWeight = Convert.ToDecimal(vtbMaturityWt.Text),
                };


                if (_transType == TransType.Add)
                {
                    customerMaster.CustomerId = UDF.ToIntiger(vtbName.Tag);
                    customerMaster.Status = "New";
                    customerregistration.RegistrationNo = 0;
                    customerregistration.Status = "New";
                    if (nominee_Entity == null)
                    {
                        MessageBox.Show("Nominee is not mentioned");
                        return TransType.Add;
                    }
                    else
                        nominee_Entity.Status = "New";
                    result = customerRegistrationData.Upsert(nominee_Entity, customerMaster, customerregistration, TransType.Save, UDF.ToIntiger(ModuleId));
                    recordNo.Text = result.ToString();
                }
                else if (_transType == TransType.Edit)
                {
                    customerMaster.CustomerId = UDF.ToIntiger(vtbName.Tag);
                    customerMaster.Status = "Modified";
                    customerregistration.RegistrationNo = UDF.ToIntiger(recordNo.Tag);
                    customerregistration.Status = "Modified";
                    nominee_Entity.Status = "Modified";
                    result = customerRegistrationData.Upsert(nominee_Entity, customerMaster, customerregistration, TransType.Edit, UDF.ToIntiger(ModuleId));
                }
                if (result > 0)
                {
                    DisplayCustomerRegistration(result);
                    MessageBox.Show("Successfully Saved");
                    UDF.enableCtrl(new Control[] { vtbName, vtbCardNo, cmbGender, vtbAddress1, vtbAddress2, vtbEmail, vtbContactNo, vtbPhoto,cmbScheme,dtpMaturityDate }, false);
                    vtbPremiumWt.ReadOnly = false;
                    _transType = TransType.Save;
                }
                else
                {
                    MessageBox.Show("Problem in Save");
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }

            return _transType;

        }

        public UTool.TransType Cancel()
        {
            UDF.clearCtrl(new Control[] { vtbName, vtbCardNo, cmbGender, vtbAddress1, vtbAddress2, vtbEmail, vtbContactNo, vtbPhoto, vtbPremiumvalue, vtbSchemeValue, vtbIncetive, vtbMaturityValue, vtbPremiumWt, vtbSchemeWt, vtbIncentiveWt, vtbMaturityWt, dtpMaturityDate });
            UDF.enableCtrl(new Control[] { vtbName, vtbCardNo, cmbGender, cmbScheme, vtbAddress1, vtbAddress2, vtbEmail, vtbContactNo, vtbPhoto, vtbPremiumvalue, vtbSchemeValue, vtbIncetive, vtbMaturityValue, vtbPremiumWt, vtbSchemeWt, vtbIncentiveWt, vtbMaturityWt, dtpMaturityDate }, false);
            cmbGender.Text = "--Select One--";
            pctImage.Image = null;
            _transType = TransType.Cancel;
            return _transType;
        }

        public UTool.TransType Delete()
        {
            throw new NotImplementedException();
        }

        public UTool.TransType Open()
        {
            try
            {
                IList<ListViewItem> lstItem = new List<ListViewItem>();
                DataSet dsMast = CustomerRegistrationData.selectForCustomerRegistration();
                DataRow[] dr = dsMast.Tables["viewCustomerRegistration"].Select();
                foreach (DataRow dtr in dr)
                {
                    if (dtr["STATUS"].ToString() != TransType.Delete.ToString())
                    {
                        ListViewItem lvi = new ListViewItem(dtr["RegistrationNo"].ToString());
                        lvi.SubItems.Add(dtr["Name"].ToString());
                        lstItem.Add(lvi);
                    }
                }
                ViewDialog objViewDiolog = new ViewDialog();
                objViewDiolog.SetDataSource(lstItem, new string[] { "Registration No", "Name", "" }, new HorizontalAlignment[] { HorizontalAlignment.Center, HorizontalAlignment.Left, HorizontalAlignment.Left }, new int[] { 100, 180, 0 });
                objViewDiolog.Text = "Registration Numbers.";
                objViewDiolog.ShowDialog();
                if (objViewDiolog.lvwData.SelectedItems.Count <= 0)
                    return (UTool.TransType)_transType;
                DisplayCustomerRegistration(UDF.ToIntiger(objViewDiolog.lvwData.SelectedItems[0].Text));
                RecordId = UDF.ToIntiger(objViewDiolog.lvwData.SelectedItems[0].Text);
                _transType = TransType.Open;
            }

            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
            return _transType;
        }

        public UTool.TransType MoveFirst()
        {
            throw new NotImplementedException();
        }

        public UTool.TransType MoveLast()
        {
            throw new NotImplementedException();
        }

        public UTool.TransType MoveNext()
        {
            try
            {
                DataSet dsMast = CustomerRegistrationData.selectForCustomerRegistrationNext(UDF.ToIntiger(recordNo.Tag));
                DataRow[] dr = dsMast.Tables["viewCustomerRegistration"].Select();
                if (dr.Length > 0)
                {
                    DisplayCustomerRegistration(UDF.ToIntiger(dr[0]["RegistrationNo"].ToString()));
                    RecordId = UDF.ToIntiger(dr[0]["RegistrationNo"].ToString());
                    _transType = TransType.MoveNext;
                }
                else MessageBox.Show("No records");
            }

            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
            return _transType;
        }

        public UTool.TransType MovePrevious()
        {
            try
            {
                DataSet dsMast = CustomerRegistrationData.selectForCustomerRegistrationPrevious(UDF.ToIntiger(recordNo.Tag));
                DataRow[] dr = dsMast.Tables["viewCustomerRegistration"].Select();
                if (dr.Length > 0)
                {
                    DisplayCustomerRegistration(UDF.ToIntiger(dr[0]["RegistrationNo"].ToString()));
                    RecordId = UDF.ToIntiger(dr[0]["RegistrationNo"].ToString());
                    _transType = TransType.MoveNext;
                }
                else MessageBox.Show("No records");

            }

            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
            return _transType;
        }

        public UTool.TransType Print()
        {
            PrintVoucher();
            return _transType;
        }

        public UTool.TransType PrintPreview()
        {
            throw new NotImplementedException();
        }

        #endregion

        #region key down event

        private void vtbName_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                if (vtbName.Text.Trim() == "")
                {
                    MessageBox.Show("Please Enter a valid Name.");
                    vtbName.Focus();
                    return;
                }
                else vtbCardNo.Focus();
            }
        }

        private void vtbCardNo_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                DataSet dsMast = CustomerMasterData.selectForCustomer();
                DataRow[] dr = dsMast.Tables["CustomerMaster"].Select("CardNo = '" + vtbCardNo.Text.Trim() + "'");
                if (_transType == TransType.Add)
                {
                    if (dr.Count() > 0)
                    {
                        MessageBox.Show("Duplicate card no.");
                        vtbCardNo.Focus();
                        return;
                    }
                }

                if (vtbCardNo.Text.Trim() == "")
                {
                    MessageBox.Show("Please Enter a valid No.");
                    vtbCardNo.Focus();
                    return;
                }
                else cmbGender.Focus();
            }
        }

        private void cmbGender_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                if (cmbGender.SelectedIndex == 0)
                {
                    MessageBox.Show("Please Enter Gender");
                    cmbGender.Focus();
                    return;
                }
            else
                vtbAddress1.Focus();
        }

        private void vtbAddress1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                vtbAddress2.Focus();
        }

        private void vtbAddress2_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                vtbEmail.Focus();
        }

        private void vtbEmail_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                vtbContactNo.Focus();
        }

        private void vtbContactNo_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                vtbPhoto.Focus();
        }

        private void vtbPhoto_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                cmbScheme.Focus();
        }

        private void vtbPremiumvalue_KeyDown(object sender, KeyEventArgs e)
        {
            try
            {
                if (e.KeyCode == Keys.Enter)
                {
                    if (vtbPremiumvalue.Text == "" || Convert.ToDecimal(vtbPremiumvalue.Text) <= 0)
                    {
                        MessageBox.Show("Please Enter a valid Premium value");
                        vtbPremiumvalue.Focus();
                        return;
                    }
                    if (cmbScheme.SelectedIndex != 0)
                    {
                        if (Convert.ToDecimal(vtbPremiumvalue.Text) == 0 || Convert.ToDecimal(vtbPremiumvalue.Text) < 499)
                        {
                            MessageBox.Show("Premium value should not be zero or less than 500");
                            vtbPremiumvalue.Focus();
                            return;
                        }
                        Displayscheme();//it gives information about bonus,period,scheme and Customerperiod
                        if (Type == "Money")
                        {
                                vtbSchemeValue.Text = string.Format("{0:f2}", (Convert.ToDecimal(vtbPremiumvalue.Text) * Customerperiod));
                                vtbIncetive.Text = string.Format("{0:f2}", Convert.ToDecimal((vtbPremiumvalue.Text)) * bonus);
                                vtbMaturityValue.Text = string.Format("{0:f2}", Convert.ToDecimal(vtbSchemeValue.Text) + Convert.ToDecimal(vtbIncetive.Text));
                        }
                        else if (Type == "Gold")
                        {
                            if (Program.Alias == "Dwarka")
                            {
                                vtbSchemeValue.Text = string.Format("{0:f2}", (Convert.ToDecimal(vtbPremiumvalue.Text) * Customerperiod));
                                vtbIncetive.Text = string.Format("{0:f2}", Convert.ToDecimal((vtbPremiumvalue.Text)) * bonus);
                                vtbMaturityValue.Text = string.Format("{0:f2}", Convert.ToDecimal(vtbSchemeValue.Text) + Convert.ToDecimal(vtbIncetive.Text));
                                vtbPremiumWt.Text = "0.00";
                                vtbSchemeWt.Text = "0.00";
                                //vtbSchemeValue.Text = "0.00";
                                vtbIncentiveWt.Text = "0.00";
                                //vtbIncetive.Text = "0.00";
                                vtbMaturityWt.Text = "0.00";

                            }
                            else
                            {
                                decimal currRate = DisplayRate();
                                vtbPremiumWt.Text = string.Format("{0:f2}", (Convert.ToDecimal(vtbPremiumvalue.Text) / currRate));
                                vtbSchemeWt.Text = string.Format("{0:f2}", Customerperiod * Convert.ToDecimal(vtbPremiumWt.Text));
                                vtbSchemeValue.Text = string.Format("{0:f2}", Convert.ToDecimal(vtbSchemeWt.Text) * currRate);
                                vtbIncentiveWt.Text = string.Format("{0:f2}", bonus * Convert.ToDecimal(vtbPremiumWt.Text));
                                vtbIncetive.Text = string.Format("{0:f2}", Convert.ToDecimal(vtbIncentiveWt.Text) * currRate);
                                vtbMaturityWt.Text = string.Format("{0:f2}", Convert.ToDecimal(vtbSchemeWt.Text) + Convert.ToDecimal(vtbIncentiveWt.Text));
                                vtbMaturityValue.Text = string.Format("{0:f2}", Convert.ToDecimal(vtbMaturityWt.Text) * currRate);
                            }
                        }
                    }
                    dtpMaturityDate.Focus();
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }

        private void cmbScheme_KeyDown(object sender, KeyEventArgs e)
        {
            try
            {
                if (e.KeyCode == Keys.Enter)
                {
                    if (cmbScheme.SelectedIndex == 0)
                    {
                        MessageBox.Show("choose scheme from combo");
                        return;
                    }
                    Displayscheme();
                    if (Type == "Gold")
                    {
                        if (Program.IsGsValFix == "yes")// This is for dwarka
                        {
                            if(Program.Alias == "Dwarka")
                            {
                                vtbPremiumvalue.Text = "0.00";                              
                                vtbSchemeValue.Text = "0.00";
                                vtbIncetive.Text = "0.00";
                                vtbMaturityValue.Text = "0.00";
                                vtbPremiumvalue.Focus();
                                return;
                            }
                            else
                            {
                            vtbPremiumvalue.Text = "0.00";
                            vtbPremiumWt.ReadOnly = false;
                            vtbSchemeValue.Text = "0.00";
                            vtbIncetive.Text  = "0.00";
                            vtbMaturityValue.Text  = "0.00";
                            vtbPremiumWt.Focus();
                            return;
                            }
                        }
                        if (Program.IsGsValFix == "no")// This is for epari
                        {

                            vtbPremiumvalue.ReadOnly = true;
                            vtbPremiumWt.ReadOnly = true;
                            vtbPremiumvalue.Text = "0.00";
                            vtbSchemeValue.Text = "0.00";
                            vtbIncetive.Text  = "0.00";
                            vtbMaturityValue.Text  = "0.00";
                            dtpMaturityDate.Focus();
                            return;
                        }
                        else
                        { dtpMaturityDate.Focus(); vtbPremiumWt.Text = ""; vtbPremiumWt.ReadOnly = true; }
                    }
                    else
                    {
                        if (_transType == TransType.Add)
                        {
                            vtbPremiumvalue.Focus();
                            return;
                        }
                        if (_transType == TransType.Edit)
                        {
                            vtbPremiumvalue.Focus();
                            return;
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }

        private void vtbPremiumWt_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                dtpMaturityDate.Focus();
        }

        #endregion
       
        #region Load event

        private void frmCustomerRegistration_Load(object sender, EventArgs e)
        {
            UDF.enableCtrl(new Control[] { vtbName, vtbCardNo, cmbGender, cmbScheme, vtbAddress1, vtbAddress2, vtbEmail, vtbContactNo, vtbPhoto, vtbPremiumvalue, vtbSchemeValue, vtbIncetive, vtbMaturityValue, dtpMaturityDate }, false);
            FillScheme();
           
            _transType = TransType.Refresh;
        }

        #endregion

        #region click event

        private void btnBrowse_Click(object sender, EventArgs e)
        {
            try
            {
                string str = Application.StartupPath + @"\Image\";
                string fileName1 = "";
                OpenFileDialog openFileDialog = new OpenFileDialog();
                openFileDialog.RestoreDirectory = true;
                openFileDialog.CheckFileExists = true;
                openFileDialog.AddExtension = true;
                if (openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    string fileName = System.DateTime.Now.ToString("dd-MM-yyyy-hh-mm-ss") + openFileDialog.FileName.Substring(openFileDialog.FileName.LastIndexOf('\\') + 1);

                    fileName1 = openFileDialog.FileName.Substring(openFileDialog.FileName.LastIndexOf('\\') + 1);
                    vtbPhoto.Text = openFileDialog.FileName;
                    vtbPhoto.Tag = fileName.Replace('-', '0');
                }
                pctImage.Visible = true;

                pctImage.Image = Image.FromFile(@"" + vtbPhoto.Text + "");
                pctImage.Image.Save(str + @"" + fileName1 + "");
                cmbScheme.Focus();
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }

        private void btnCustomerNameBrowse_Click(object sender, EventArgs e)
        {
            try
            {
                IList<ListViewItem> lstItem = new List<ListViewItem>();
                DataSet dsMast = CustomerMasterData.selectForCustomer();
                DataRow[] dr = dsMast.Tables["CustomerMaster"].Select();
                foreach (DataRow dtr in dr)
                {
                    if (dtr["STATUS"].ToString() != TransType.Delete.ToString())
                    {
                        ListViewItem lvi = new ListViewItem(dtr["CustomerId"].ToString());
                        lvi.SubItems.Add(dtr["Name"].ToString());
                        lvi.SubItems.Add(dtr["CardNo"].ToString());
                        lstItem.Add(lvi);
                    }
                }
                ViewDialog objViewDiolog = new ViewDialog();
                objViewDiolog.SetDataSource(lstItem, new string[] { "CustomerId", "Name", "CardNo" }, new HorizontalAlignment[] { HorizontalAlignment.Center, HorizontalAlignment.Left, HorizontalAlignment.Left }, new int[] { 0, 180, 100 });
                objViewDiolog.Text = "Customer Name";
                objViewDiolog.ShowDialog();
                if (objViewDiolog.lvwData.SelectedItems.Count <= 0)
                    return;
                DisplayCustomerInformation(UDF.ToIntiger(objViewDiolog.lvwData.SelectedItems[0].Text));
                UDF.enableCtrl(new Control[] { vtbName, vtbCardNo, cmbGender, vtbAddress1, vtbAddress2, vtbEmail, vtbContactNo, vtbPhoto, btnBrowse }, false);
                cmbScheme.Focus();
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }

        #endregion

        #region key press event

        private void cmbGender_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.KeyChar = (char)Keys.None;//it is written to read only the combo box cmbGender
        }

        #endregion

        #region link lable

        private void lnklblNominee_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
                if (_transType == TransType.Add)//nominee_Entity = null- is written becoz in add mode it clears the data of corresponding text box of nominee form
                   nominee_Entity = null;
             
                nominee nominee = new nominee();
                nominee.nominee_Entity = nominee_Entity;//nominee_Entity- it retrives data in open mode
                nominee.ShowDialog();
                if (nominee_Entity == null)
                {
                    nominee_Entity = nominee.nominee_Entity;
                }
                if (_transType == TransType.Edit)//in edit mode the value comes from nominee form is assigned to nominee_Entity
                    nominee_Entity = nominee.nominee_Entity;
        }
       
        #endregion

    }
}

Nominee

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using GoldTree.Entity;
using Utility;

namespace GoldTree.Transaction
{
    public partial class nominee : Form
    {

        #region Constructor

        public nominee()
        {
            InitializeComponent();
        }

        #endregion

        #region key down event

        private void Name_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                IdentityProof.Focus();
        }
        
        private void IdentityProof_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                Relation.Focus();
        } 
        
        private void Relation_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                Email.Focus();
        } 
        
        private void Email_KeyDown(object sender, KeyEventArgs e)
        {  
            if (e.KeyCode == Keys.Enter)
                ContactNo.Focus();
        }
        
        private void ContactNo_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                CorrespondenceAddress1.Focus();
        }

        private void CorrespondenceAddress1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                CorrespondenceAddress2.Focus();
        }
        
        private void CorrespondenceAddress2_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                Photo.Focus();
        }

        #endregion

        #region nominee properties

        private Nominee_Entity _nominee_Entity;
        public Nominee_Entity nominee_Entity
        {
            get { return _nominee_Entity; }
            set { _nominee_Entity = value; }
        }

        #endregion
        
        #region click event

        private void btnOK_Click(object sender, EventArgs e)
        {
            //UDF.clearCtrl(new Control[] { _Name, IdentityProof, Photo, Email, ContactNo, CorrespondenceAddress1, CorrespondenceAddress2 });
            Nominee_Entity data = new Nominee_Entity
            {

                Name = _Name.Text,
                RegistrationNo = UDF.ToIntiger(_Name.Tag),
                IdentityProof = IdentityProof.Text,
                Relation = Relation.Text,
                Photo = Photo.Text.Substring(Photo.Text.LastIndexOf('\\') + 1),
                Email = Email.Text,
                ContactNo = ContactNo.Text,
                CorrespondenceAddress1 = CorrespondenceAddress1.Text,
                CorrespondenceAddress2 = CorrespondenceAddress2.Text,
            };
            nominee_Entity = data;
            this.Close();
        }     
        
        private void btnBrowse_Click(object sender, EventArgs e)
        {
            try
            {
                string str = Application.StartupPath + @"\Image\";
                string fileName1 = "";
                OpenFileDialog openFileDialog = new OpenFileDialog();
                openFileDialog.RestoreDirectory = true;
                openFileDialog.CheckFileExists = true;
                openFileDialog.AddExtension = true;
                if (openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    string fileName = System.DateTime.Now.ToString("dd-MM-yyyy-hh-mm-ss") + openFileDialog.FileName.Substring(openFileDialog.FileName.LastIndexOf('\\') + 1);

                    fileName1 = openFileDialog.FileName.Substring(openFileDialog.FileName.LastIndexOf('\\') + 1);
                    Photo.Text = openFileDialog.FileName;
                    Photo.Tag = fileName.Replace('-', '0');
                }
                pctImage.Visible = true;

                pctImage.Image = Image.FromFile(@"" + Photo.Text + "");
                pctImage.Image.Save(str + @"" + fileName1 + "");
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }
        
        #endregion
        
        #region load event

        private void nominee_Load(object sender, EventArgs e)
        {
            try
            {
                if (nominee_Entity != null)
                {
                    _Name.Text = nominee_Entity.Name;
                    _Name.Tag = nominee_Entity.RegistrationNo;
                    IdentityProof.Text = nominee_Entity.IdentityProof;
                    Relation.Text = nominee_Entity.Relation;
                    Email.Text = nominee_Entity.Email;
                    ContactNo.Text = nominee_Entity.ContactNo;
                    CorrespondenceAddress1.Text = nominee_Entity.CorrespondenceAddress1;
                    CorrespondenceAddress2.Text = nominee_Entity.CorrespondenceAddress2;

                    if (nominee_Entity.Photo == "")
                    {
                        pctImage.Image = null;
                    }
                    else
                    {
                        Photo.Text = Application.StartupPath + "\\" + @"Image" + "\\" + nominee_Entity.Photo;
                        pctImage.Image = Image.FromFile(@"" + Photo.Text + "");
                    }
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        } 
        
        #endregion

    }
}