Thursday, March 27, 2014

EDMX

  <asp:DropDownList ID="ddlSearch" DataTextField="COLUMN_NAME"  runat="server"></asp:DropDownList>

namespace Redhawk.Signal.Newsletter.Web.Pages.Modal
{
    public partial class Search : System.Web.UI.Page
    {
        string tableName;
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!Page.IsPostBack)
            {          
                tableName = Request.QueryString["tableName"];
                if(!string.IsNullOrEmpty(tableName))
                {
                    this.LoadSearchDropdownList(tableName);
                }
            }
        }

        private void LoadSearchDropdownList(string tableName)
        {
            List<Column> lst = new List<Column>();
            var _dbCon = new RedhawkSignalNewsletterEntities();
            var ds = from t1 in _dbCon.Database.SqlQuery<Column>("SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME ='" + tableName.ToString() + "'" )
                     select t1;
            if (tableName == "Templates")
            foreach (var m in ds)
            {
                if (m.COLUMN_NAME == "TemplateName" || m.COLUMN_NAME == "TemplateBody" || m.COLUMN_NAME == "TemplateDescription")
                    lst.Add(m);
            }
            else if (tableName == "fund")
            {
                foreach (var m in ds)
                {
                    if (m.COLUMN_NAME == "FundName" || m.COLUMN_NAME == "Ticker")
                        lst.Add(m);
                }
            }
            ddlSearch.DataSource = lst.ToList();
            ddlSearch.DataBind();
        }
 
        protected void btnSearch_Click(object sender, EventArgs e)
        {
           string columnName = ddlSearch.SelectedValue;
           string columnValue = txtSearchValue.Text.Trim();
            string tbl = Request.QueryString["tableName"];
            //string logoutRedirectURL = ("~/Pages/Home.aspx");
            //string logoutRedirectURL = ("~/Pages/Home.aspx?tbl=" + tbl);
            string logoutRedirectURL = ("~/Pages/Home.aspx?colName=" + columnName + "&colValue=" + columnValue);
            Response.Redirect(logoutRedirectURL,true);
           // Response.Redirect("~/Home.aspx");
        }
    }

    public class Column
    {
        public string COLUMN_NAME { get; set; }
    }
}


*********************************************************************************
public class ProductUser
{
public int ProductId { set; get; }
public string ProductName { set; get; }
}
 public ProductUser FiduciaryKProductByUser(int userId)
{
using (dbcntx = new FiduciaryKEntities())
{
var SQL = " SELECT vw_FiduciaryKProduct.Id AS ProductId, vw_FiduciaryKProduct.ProductName FROM FiduciaryK_User INNER JOIN FiduciaryK_ReferralChannel ON FiduciaryK_User.ReferralId = FiduciaryK_ReferralChannel.ReferralId INNER JOIN FiduciaryK_ChannelProduct CROSS JOIN vw_FiduciaryKProduct ON FiduciaryK_ChannelProduct.ProductId = vw_FiduciaryKProduct.Id where FiduciaryK_User.Id=" + userId;
ProductUser productUser = dbcntx.Database.SqlQuery<ProductUser>(SQL).First();
return productUser;
}
}
***********************************************************************************************************


























No comments:

Post a Comment