public ELDesignation FetchDesignationsByID(int ID)
        {
            SqlCommand cmd;
            string qry = "";
            ELDesignation ObjELDesignation = new ELDesignation();
            SqlDataReader dr;
            try
            {
                conn.CreatConnection();

                qry = "SELECT * FROM Designation WHERE ID =@ID";

                cmd = new SqlCommand(qry, conn.con);

                SqlParameter param;

                param = new SqlParameter("@id", SqlDbType.Int);
                param.Direction = ParameterDirection.Input;
                param.Value = ID;
                cmd.Parameters.Add(param);

                foreach (SqlParameter Parameter in cmd.Parameters)
                {
                    if (Parameter.Value == null)
                    {
                        Parameter.Value = DBNull.Value;
                    }
                }

                dr = cmd.ExecuteReader();

                if (dr.HasRows)
                {
                    dr.Read();

                    ObjELDesignation.ID = Convert.ToInt32(dr["id"]);
                    ObjELDesignation.Code = dr["Code"].ToString();
                    ObjELDesignation.Name = dr["Name"].ToString();
                    ObjELDesignation.IsActive = Convert.ToBoolean(dr["IsActive"]);
                    ObjELDesignation.Creator = Convert.ToInt32(dr["Creator"]);
                    ObjELDesignation.Created = Convert.ToDateTime(dr["Created"]);

                }
                dr.Close();

                return ObjELDesignation;
            }
            catch (Exception ex)
            {
                UtilityLayer.Common.ErrorLog(DateTime.Now.ToString() + ex.Message + " " + ex.StackTrace + " " + "DLDesignation - FetchDesignationsByID");
                return null;
            }
            finally
            {
                conn.CloseConnection();
            }
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            ELDesignation objELDesignation = new ELDesignation();
            DLDesignation objDLDesignation = new DLDesignation();

            int newID = 0;

            if (lblDesignationID.Text.Length > 0)
            {
                objELDesignation.ID = Convert.ToInt32(lblDesignationID.Text);
            }
            else
            {
                newID = Common.GetNewID(tableName);
                objELDesignation.ID = newID;
            }

            objELDesignation.Code = txtCode.Text;
            objELDesignation.Name = txtName.Text;
            objELDesignation.Creator = 0;
            objELDesignation.Created = DateTime.Now;
            objELDesignation.IsActive = false;

            if (chkIsActive.Checked) objELDesignation.IsActive = true;

            if (Validations())
            {
                if (objDLDesignation.Add(objELDesignation) > 0)
                {
                    MessageBox.Show("Record Inserted");
                    // ClearControls();
                }
                else
                {
                    MessageBox.Show("Record not Inserted");
                }
            }
        }
        public int Add(ELDesignation objELDesignation)
        {
            int retValue = 0;
            SqlCommand cmd;
            string qry = "";
            object value;
            try
            {
                conn.CreatConnection();

                qry = "";

                qry = "SELECT COUNT(ID) FROM Designation WHERE ID =@ID ";

                cmd = new SqlCommand(qry, conn.con);

                SqlParameter param;

                param = new SqlParameter("@ID", SqlDbType.Int);
                param.Direction = ParameterDirection.Input;
                param.Value = objELDesignation.ID;
                cmd.Parameters.Add(param);

                foreach (SqlParameter Parameter in cmd.Parameters)
                {
                    if (Parameter.Value == null)
                    {
                        Parameter.Value = DBNull.Value;
                    }
                }

                value = cmd.ExecuteScalar();

                if (value != null && value.ToString() != "0")
                {
                    qry = "";
                    qry = "UPDATE Designation SET Code=@Code, Name =@Name,IsActive=@IsActive WHERE ID=@ID";

                    cmd = new SqlCommand(qry, conn.con);

                    param = new SqlParameter("@ID", SqlDbType.Int);
                    param.Direction = ParameterDirection.Input;
                    param.Value = objELDesignation.ID;
                    cmd.Parameters.Add(param);

                    param = new SqlParameter("@Code", SqlDbType.NVarChar);
                    param.Direction = ParameterDirection.Input;
                    param.Value = objELDesignation.Code;
                    cmd.Parameters.Add(param);

                    param = new SqlParameter("@Name", SqlDbType.NVarChar);
                    param.Direction = ParameterDirection.Input;
                    param.Value = objELDesignation.Name;
                    cmd.Parameters.Add(param);

                    param = new SqlParameter("@isActive", SqlDbType.Bit);
                    param.Direction = ParameterDirection.Input;
                    param.Value = objELDesignation.IsActive;
                    cmd.Parameters.Add(param);

                    foreach (SqlParameter Parameter in cmd.Parameters)
                    {
                        if (Parameter.Value == null)
                        {
                            Parameter.Value = DBNull.Value;
                        }
                    }

                    retValue = cmd.ExecuteNonQuery();
                }
                else
                {
                    qry = "";

                    qry = "INSERT INTO Designation (ID, CODE, NAME, CREATOR , CREATED, ISACTIVE) " +
                        " VALUES(@ID, @Code, @Name, @Creator, @Created, @IsActive) ";

                    cmd = new SqlCommand(qry, conn.con);

                    param = new SqlParameter("@ID", SqlDbType.Int);
                    param.Direction = ParameterDirection.Input;
                    param.Value = objELDesignation.ID;
                    cmd.Parameters.Add(param);

                    param = new SqlParameter("@Code", SqlDbType.NVarChar);
                    param.Direction = ParameterDirection.Input;
                    param.Value = objELDesignation.Code;
                    cmd.Parameters.Add(param);

                    param = new SqlParameter("@Name", SqlDbType.NVarChar);
                    param.Direction = ParameterDirection.Input;
                    param.Value = objELDesignation.Name;
                    cmd.Parameters.Add(param);

                    param = new SqlParameter("@Creator", SqlDbType.Int);
                    param.Direction = ParameterDirection.Input;
                    param.Value = objELDesignation.Creator;
                    cmd.Parameters.Add(param);

                    param = new SqlParameter("@Created", SqlDbType.DateTime);
                    param.Direction = ParameterDirection.Input;
                    param.Value = objELDesignation.Created;
                    cmd.Parameters.Add(param);

                    param = new SqlParameter("@isActive", SqlDbType.Bit);
                    param.Direction = ParameterDirection.Input;
                    param.Value = objELDesignation.IsActive;
                    cmd.Parameters.Add(param);

                    foreach (SqlParameter Parameter in cmd.Parameters)
                    {
                        if (Parameter.Value == null)
                        {
                            Parameter.Value = DBNull.Value;
                        }
                    }

                    retValue = cmd.ExecuteNonQuery();

                }
            }
            catch (Exception ex)
            {
                UtilityLayer.Common.ErrorLog(DateTime.Now.ToString() + ex.Message + " " + ex.StackTrace + " " + "DLDesignation - Add");
                return 0;
            }
            finally
            {
                conn.CloseConnection();
            }
            return retValue;
        }
        private void gvDesignation_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex > 0)
            {

                string strCode = gvDesignation.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
                string designationID = gvDesignation.Rows[e.RowIndex].Cells[0].Value.ToString();

                ELDesignation objELDesignation = new ELDesignation();
                DLDesignation objDLDesignation = new DLDesignation();

                objELDesignation = objDLDesignation.FetchDesignationsByID(Convert.ToInt32(designationID));

                if (objELDesignation != null)
                {
                    lblDesignationID.Text = objELDesignation.ID.ToString();
                    txtCode.Text = objELDesignation.Code;
                    txtName.Text = objELDesignation.Name;
                    chkIsActive.Checked = Convert.ToBoolean(objELDesignation.IsActive);
                }
            }
            gvDesignation.Visible = false;
        }