예제 #1
0
        public static int Compare(PaletteItem x, PaletteItem y)
        {
            int r = String.Compare(x.Title, y.Title, true);

            if (r == 0)
            {
                r = x.Id.CompareTo(y.Id);
            }
            return(r);
        }
예제 #2
0
        public PaletteItem Load(int paletteId)
        {
            PaletteItem pi = new PaletteItem();

            pi.Id = -1;
            using (SqlConnection conn = this.GetConnection())
            {
                string sql = @"SELECT p.ID, p.[DESCRIPTION], c.RGB, p.CLUSTER
FROM PALETTE_COLOR c, PALETTE p WHERE (p.ID = c.PALETTE_ID) AND (p.ID = " + paletteId.ToString() + @") ORDER BY p.ID, c.[ORDER]";

                SqlCommand cmd = new SqlCommand(sql, conn);

                SqlDataReader r = cmd.ExecuteReader();

                Color[] colors = new Color[32];
                int     p      = 0;
                while (r.Read())
                {
                    int x = r.GetInt32(0);
                    if (x != pi.Id)
                    {
                        pi.Id    = x;
                        p        = 0;
                        pi.Title = r.GetString(1);
                        if (r.IsDBNull(3))
                        {
                            pi.Cluster = 0;
                        }
                        else
                        {
                            pi.Cluster = r.GetInt32(3);
                        }
                    }
                    colors[p++] = PaletteManager.ColorFromInt(r.GetInt32(2));
                }
                r.Close();
                if (pi.Id > 0)
                {
                    pi = new PaletteItem(pi.Id, pi.Title, pi.Cluster, colors, p);
                }
            }
            return(pi);
        }
예제 #3
0
        private void AddForColors(SqlConnection conn, SortedDictionary <int, PaletteItem> list, string colorList, SortedDictionary <int, int> colorIndex, int mask, int maxCount, ref int count)
        {
            string sql = @"SELECT p.ID, p.[DESCRIPTION], c.RGB, p.CLUSTER
FROM PALETTE_COLOR c, PALETTE p
WHERE (p.ID = c.PALETTE_ID) AND
(p.ID IN (SELECT DISTINCT pc.PALETTE_ID FROM PALETTE_COLOR pc WHERE (pc.RGB IN ("
                         + colorList +
                         @")))) ORDER BY p.ID, c.[ORDER]";

            SqlCommand cmd = new SqlCommand(sql, conn);

            SqlDataReader r = cmd.ExecuteReader();

            int    id      = -1;
            string title   = null;
            int    cluster = -1;

            Color[] colors = new Color[32];
            int     p      = 0;
            bool    add    = false;

            while (r.Read())
            {
                int x = r.GetInt32(0);
                if (x != id)
                {
                    if (title != null)
                    {
                        if (add)
                        {
                            PaletteItem pal = new PaletteItem(id, title, cluster, colors, p);
                            if (PaletteManager.MatchMask(pal.Colors, colorIndex, mask))
                            {
                                list.Add(id, pal);
                                ++count;
                                if (count >= maxCount)
                                {
                                    break;
                                }
                            }
                        }
                    }
                    id = x;
                    if (list.ContainsKey(id))
                    {
                        add   = false;
                        p     = 0;
                        title = null;
                    }
                    else
                    {
                        add   = true;
                        p     = 0;
                        title = r.GetString(1);
                        if (r.IsDBNull(3))
                        {
                            cluster = 0;
                        }
                        else
                        {
                            cluster = r.GetInt32(3);
                        }
                    }
                }
                if (add)
                {
                    colors[p++] = PaletteManager.ColorFromInt(r.GetInt32(2));
                }
            }
            if (title != null)
            {
                if (add && (count < maxCount))
                {
                    PaletteItem pal = new PaletteItem(id, title, cluster, colors, p);
                    if (PaletteManager.MatchMask(pal.Colors, colorIndex, mask))
                    {
                        list.Add(id, pal);
                        ++count;
                    }
                }
            }

            r.Close();
            r = null;
        }