tags:

views:

26

answers:

0

Hello, Please excuse my Question if it seams simple but i am lost and confused right now. i am new to WPF data binding. What i am tring to do is take a zip code from a textbox, than the program has a stored procedure to pull the data from. i have worked on this procedure for about 3 weeks now and have it giving me the results i need when executed. This is the stored procedure i am using.

    <code>
  ALTER   PROCEDURE dbo.report_top5_segments( @ZIPCODE varchar(5) )
    AS
    SET NOCOUNT ON

    -- 0 LOCALITY NAME
    SELECT GEOGRAPHY_NAME, GEO_ID
    FROM dbo.MBS_ZIP_NAMES
    WHERE
    GEO_TYPE = 31 AND GEO_ID like @ZIPCODE

    IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TOP5SEGMENTS]') AND type in (N'U'))
    DROP TABLE [dbo].[TOP5SEGMENTS]


    CREATE TABLE dbo.TOP5SEGMENTS (
     SEG_ID varchar(2) CONSTRAINT pkey PRIMARY KEY,
     SEG_NICK varchar(80) NULL
    )
    -- GENERATE TOP 5 SEGMENTS
    INSERT INTO dbo.TOP5SEGMENTS
    SELECT 
    TOP 5
    SEG_ID,
    SEG_NICK
    FROM 
    dbo.MBS_ZIP_LOOKUP_PRIZMNE
    WHERE 
    GEO_TYPE = 31 and GEO_ID=@ZIPCODE
    ORDER BY CY_HH DESC

    -- 1 TOP 5 SEGMENTS 
    SELECT 
    SEG_ID,
    SEG_NICK
    FROM dbo.TOP5SEGMENTS

    -- 2 LIFE TRAITS
    SELECT
    INFO.SEG_ID,
    LIFESTYLE_TRAIT1,
    LIFESTYLE_TRAIT2,
    LIFESTYLE_TRAIT3,
    LIFESTYLE_TRAIT4,
    LIFESTYLE_TRAIT5
    FROM
    dbo.SEG_01_PRIZMNE INFO
    JOIN dbo.TOP5SEGMENTS ON INFO.SEG_ID=dbo.TOP5SEGMENTS.SEG_ID  

    -- 3 DEMOGRAPHIC TRAITS
    SELECT
    INFO.SEG_ID,
    ETHNIC_DIVERSITY,
    FAMILY_TYPE,
    AGE_RANGES,
    EMPLOYMENT_LEVELS,
    EDUCATION_LEVELS,
    HOUSING_TYPES,
    URBANICITY,
    INCOME,
    INCOME_PRODUCING_ASSETS,
    SEGMENT_DESCRIPTION
    FROM
    dbo.SEG_01_PRIZMNE INFO
    JOIN dbo.TOP5SEGMENTS ON INFO.SEG_ID=dbo.TOP5SEGMENTS.SEG_ID  

    -- 4 SOCIAL [SEG_CLGRP]
    SELECT
    INFO.SEG_ID, 
    INFO.SEG_CLGRP, INFO.SEG_GNAME, INFO.SEG_NICK
    FROM
    dbo.MBS_GROUP_LOOKUP_PRIZMNE INFO
    JOIN dbo.TOP5SEGMENTS ON INFO.SEG_ID=dbo.TOP5SEGMENTS.SEG_ID  

    --  5 LIFESTAGE [SEG_LSGRP] 
    SELECT
    INFO.SEG_ID,
    INFO.SEG_LSGRP, INFO.SEG_GNAME, INFO.SEG_NICK
    FROM
    dbo.MBS_LIFESTAGE_LOOKUP_PRIZMNE INFO
    JOIN dbo.TOP5SEGMENTS ON INFO.SEG_ID=dbo.TOP5SEGMENTS.SEG_ID  

    -- 6 Group Description
    SELECT
    dbo.TOP5SEGMENTS.SEG_ID,
    CY_HH, CY_POP, CY_MEDHHINC, GROUP_DESCRIPTION
    FROM
    dbo.SEG_01_GROUP_PRIZMNE INFO
    JOIN dbo.MBS_GROUP_LOOKUP_PRIZMNE INFO2 ON INFO2.SEG_CLGRP=INFO.SEG_CLGRP
    JOIN dbo.TOP5SEGMENTS ON INFO2.SEG_ID=dbo.TOP5SEGMENTS.SEG_ID
</code>

Now What i am trying to do is have the 5 segments create 5 images out of 60 that i have. Then when one of the images are selected the view of the list box changes with the information that comes with that segment. Information below: Running [dbo].[report_top5_segments] ( @ZIPCODE = 10023 ). GEOGRAPHY_NAME GEO_ID


New York, NY 10023
No rows affected. (1 row(s) returned) SEG_ID SEG_NICK // Will return Images for Buttons


04 Young Digerati
07 Money & Brains
16 Bohemian Mix
26 The Cosmopolitans
29 American Dreams

No rows affected. (5 row(s) returned)


//The rest would be formated data displayed dependent on SEG_ID Image that was clicked// I can not list all 5 across as there isnt enough room to display. i will list 3 across.

SEG_ID | LIFESTYLE_TRAIT1 | LIFESTYLE_TRAIT2 | LIFESTYLE_TRAIT3

04 | Order from expedia.com | Go snowboarding | Reads The Economist 07 | Shop at Nordstrom | Contribute to NPR | Reads Sunday newspaper 16 | Shop at Express | Rent foreign videos | Reads Details 26 | Shop at Costco | Buy classical music | Read Wine Spectator 29 | Shop at Old Navy | Buy motivational tapes | Read Black Enterprise No rows affected. (5 row(s) returned)

SEG_ID | ETHNIC_DIVERSITY | FAMILY_TYPE | AGE_RANGES | Ect.. | Ect...

04 | White, Asian, Hispanic, Mix | Family Mix | 25-44 | Ect | Ect 07 | White, Black, Asian, Hispanic | Ect | Ect | Ect | Ect 16 | White, Black, Asian, Hispanic | Ect | Ect | Ect | Ect 26 | White, Black, Asian, Hispanic | Ect | Ect | Ect | Ect 29 | White, Black, Asian, Hispanic | Ect | Ect | Ect | Ect

SEG_ID | SEG_CLGRP | SEG_GNAME | SEG_NICK

04 | 01 | Urban Uptown | Young Digerati 07 | 01 | Urban Uptown | Money & Brains 16 | 01 | Urban Uptown | Bohemian Mix
26 | 01 | Urban Uptown | The Cosmopolitans
29 | 01 | Urban Uptown | American Dreams
No rows affected. (5 row(s) returned) SEG_ID | SEG_LSGRP | SEG_GNAME | SEG_NICK


04 | 02 | Young Achievers | Young Digerati
07 | 08 | Affluent Empty Nests | Money & Brains
16 | 02 | Young Achievers | Bohemian Mix
26 | 09 | Conservative Classics | The Cosmopolitans
29 | 05 | Young Accumulators | American Dreams
No rows affected. (5 row(s) returned) SEG_ID | CY_HH | CY_POP | CY_MEDHHINC | GROUP_DESCRIPTION


04 | 9572995 | 25134673 | 67483 |The five segments in Urban Uptown are home to the nation's wealthiest urban consumers. Members of this social group tend to be midscale to upscale, college educated and ethnically diverse, with above-average concentrations of Asian and Hispanic Americans.
07 | 9572995 | 25134673 | 67483 |The five segments in Urban Uptown are home to the nation's wealthiest urban consumers. Members of this social group tend to be midscale to upscale, college educated and ethnically diverse, with above-average concentrations of Asian and Hispanic Americans. 16 | 9572995 | 25134673 | 67483 |The five segments in Urban Uptown are home to the nation's wealthiest urban consumers. Members of this social group tend to be midscale to upscale, college educated and ethnically diverse, with above-average concentrations of Asian and Hispanic Americans. 26 | 9572995 | 25134673 | 67483 |The five segments in Urban Uptown are home to the nation's wealthiest urban consumers. Members of this social group tend to be midscale to upscale, college educated and ethnically diverse, with above-average concentrations of Asian and Hispanic Americans. 29 | 9572995 | 25134673 | 67483 |The five segments in Urban Uptown are home to the nation's wealthiest urban consumers. Members of this social group tend to be midscale to upscale, college educated and ethnically diverse, with above-average concentrations of Asian and Hispanic Americans. (5 row(s) returned) @RETURN_VALUE = 0 Finished running [dbo].[report_top5_segments].

I hope you understand and i made myself clear enough.

Also Sorry about the format if you cant read the data i can sent you a formated doc. for better reading.

Any Help would be greatly appriceated.

Thanks in advance

Rich

New code added

namespace clusters
{
    public class Segment
    {
      public static System.Data.DataSet Query( string zipcode_id )
        {
            /*                                  *
             *  Build list of top five segments *
             *                                  *
             */
            System.Data.DataSet dataSet = new System.Data.DataSet();
            using (System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand())
            {
                cmd.Connection = new System.Data.SqlClient.SqlConnection(Segment.GetConnectionString());

                cmd.CommandText = "dbo.report_top5_segments";

                cmd.CommandType = System.Data.CommandType.StoredProcedure;
                System.Data.SqlClient.SqlParameter param = cmd.CreateParameter();
                param.ParameterName = "@ZIPCODE";
                param.SqlDbType = System.Data.SqlDbType.NVarChar;
                param.Value = zipcode_id.ToString();
                try
                {
                    cmd.Parameters.Add(param);
                    System.Data.SqlClient.SqlDataAdapter adapater = new System.Data.SqlClient.SqlDataAdapter(cmd);
                    adapater.Fill( dataSet );
                }
                catch (Exception ex)
                {
                    throw ex;
                }

            }
            return dataSet;
        }
        public static System.Drawing.Image GetSegmentIcon(long number) {
            return GetImage("SEGMENTICON", number);
        }
        public static System.Drawing.Image GetMap(long number)
        {
            return GetImage("MAPS", number);
        }
        public static System.Drawing.Image GetLegend(long number)
        {
            return GetImage("LEGEND", number);
        }
        public static System.Drawing.Image GetImage(string tablename, long number)
        {
            System.Data.SqlClient.SqlDataReader sqlDataReader = null;
            using (System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand())
            {
                cmd.Connection = new System.Data.SqlClient.SqlConnection(Segment.GetConnectionString());

                cmd.CommandText = "SELECT THEIMAGE FROM " + tablename + " WHERE ID = @ID";

                cmd.CommandType = System.Data.CommandType.Text;
                System.Data.SqlClient.SqlParameter param = cmd.CreateParameter();
                param.ParameterName = "@ID";
                param.SqlDbType = System.Data.SqlDbType.Int;
                param.Value = number;
                try
                {
                    cmd.Parameters.Add(param);
                    cmd.Connection.Open();

                    sqlDataReader = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);

                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            if (sqlDataReader.Read())
            {
                System.IO.MemoryStream ms = new System.IO.MemoryStream((byte[])sqlDataReader["THEIMAGE"]);
                return System.Drawing.Image.FromStream(ms);
            }
            return (System.Drawing.Image)null;
        }
        public static void LoadInfoText(long number, System.Windows.Forms.RichTextBox descript, System.Windows.Forms.RichTextBox stats, System.Windows.Forms.RichTextBox demog){
            System.Data.SqlClient.SqlDataReader sqlDataReader = null;
            using (System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand())
            {
                cmd.Connection = new System.Data.SqlClient.SqlConnection(Segment.GetConnectionString());

                cmd.CommandText = "SELECT RTF0, RTF1 FROM SEGMENTRTF WHERE ID = @ID";

                cmd.CommandType = System.Data.CommandType.Text;
                System.Data.SqlClient.SqlParameter param = cmd.CreateParameter();
                param.ParameterName = "@ID";
                param.SqlDbType = System.Data.SqlDbType.Int;
                param.Value = number;
                try
                {
                    cmd.Parameters.Add(param);
                    cmd.Connection.Open();

                    sqlDataReader = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);

                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            if (sqlDataReader.Read())
            {
                if(stats != null)
                    stats.Rtf = Encoding.ASCII.GetString((byte[])sqlDataReader["RTF0"], 0, ((byte[])sqlDataReader["RTF0"]).GetLength(0));
                if (demog != null)
                demog.Rtf = Encoding.ASCII.GetString((byte[])sqlDataReader["RTF1"], 0, ((byte[])sqlDataReader["RTF1"]).GetLength(0));
            }

        }
    }
    public class ClusterList : CollectionBase, ICollection<clusters.Cluster>
    {
        public ClusterList()
        {
        }
        public clusters.Cluster this[int index]
        {
            get { return (clusters.Cluster)this.InnerList[index]; }
        }
        #region ICollection<Cluster> Members

        public void Add(Cluster item)
        {
            InnerList.Add(item);
        }

        public new void Clear()
        {
            InnerList.Clear();
        }
        public new int Count
        {
            get { return this.InnerList.Count; }
        }
        public bool Contains(Cluster item)
        {
            throw new Exception("The method or operation is not implemented.");
        }

        public void CopyTo(Cluster[] array, int arrayIndex)
        {
            throw new Exception("The method or operation is not implemented.");
        }

        public bool IsReadOnly
        {
            get { return true; }
        }

        public bool Remove(Cluster item)
        {
            throw new Exception("The method or operation is not implemented.");
        }

        #endregion

        #region IEnumerable<Cluster> Members

        public new IEnumerator<Cluster> GetEnumerator()
        {
            throw new Exception("The method or operation is not implemented.");
        }

        #endregion

        #region IEnumerable Members

        IEnumerator IEnumerable.GetEnumerator()
        {
            throw new Exception("The method or operation is not implemented.");
        }

        #endregion

    }
    public class Cluster
    {
        string nickname = "";
        Single percentusa = 0.0F;
        Single percentzip = 0.0F;
        long number = 0;
        public Cluster(long num)
        {
            //nickname = data[""].ToString();
            //percentusa = data[""].ToString();
            //percentzip = data[""].ToString();
            number = num;
        }
        public Cluster(System.Data.DataRow data)
        {
            nickname = data["SEG_NICK"].ToString();
            //percentusa = data[""].ToString();
            //percentzip = data[""].ToString();
            number = long.Parse(data["SEG_ID"].ToString());
        }
        public string Nickname
        {
            get { return nickname; }
        }
        public Single PercentUSA
        {
            get { return percentusa; }
        }
        public Single PercentZip
        {
            get { return percentzip; }
        }
        public long Number
        {
            get { return number; }
        }
        public void Create(long Number, Single Zip, Single USA, string Nickname)
        {
        }
        public static string GetObjectName(long number)
        {
            return string.Format("_{0}", number);
        }
    }
}

This is what i had in my windows forms application. iam tring to create it in WPF. i love WPF for simple applications but the databinding with views and viewmodel is killing me. lol

Maybe im just over thinking the app. but now im on a deadline.