Metin2 - Shopviewer

10/31/2012 01:57 #SoNiice#1
Heyho,

da ich vor einiger Zeit mal einen Shopviewer für mich und 'nen Freund gebastelt habe um zu schauen wie weit er mit den Shops ist, dachte ich mir, mache ich ihn nun public. Das Tool ließt aus eurer Datenbank die Shopnamen aus und dementsprechend danach die Items, wenn ihr auf den jeweiligen Shop klickt.

Anleitung:

1. Dateien runterladen!
2. "mysql.cfg" im selben Ordner erstellen mit den folgenden Syntax: "IP;User;PW"!
3. Tool starten und staunen!

Wer mir bei der ganzen Sache nicht vertrauen will, hier ist der Source, jaja ich weiß, echt unordentlich gecodet, war auch ein Zeitprojekt.

Code:
using Microsoft.Win32;
using MySql.Data.MySqlClient;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Shop_Creator___M2
{
    public partial class MainWindow : Window
    {
        string connectionDetails;

        int shopCounter = 0;

        public static IEnumerable<T> FindVisualChildren<T>(DependencyObject depObj) where T : DependencyObject
        {
            if (depObj != null)
            {
                for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
                {
                    DependencyObject child = VisualTreeHelper.GetChild(depObj, i);
                    if (child != null && child is T)
                    {
                        yield return (T)child;
                    }

                    foreach (T childOfChild in FindVisualChildren<T>(child))
                    {
                        yield return childOfChild;
                    }
                }
            }
        }


        public MainWindow()
        {
            InitializeComponent();
            if (File.Exists("mysql.cfg"))
            {
                try
                {
                    connectionDetails = "SERVER=" + ReadFile("mysql.cfg").Split(';')[0] + ";" +
                                        "DATABASE=player;" +
                                        "UID=" + ReadFile("mysql.cfg").Split(';')[1] + ";" +
                                        "PASSWORD=" + ReadFile("mysql.cfg").Split(';')[2] + ";";
                }
                catch
                {
                    MessageBox.Show("Bitte schreibe erst deine Daten in die mysql.cfg", "ERROR: Config", MessageBoxButton.OK, MessageBoxImage.Error);
                    Close();
                }
            }
            else
            {
                MessageBox.Show("Bitte erstelle erst die mysql.cfg", "ERROR: Config", MessageBoxButton.OK, MessageBoxImage.Error);
                Close();
            }
        }

        private void btnClose_MouseEnter(object sender, MouseEventArgs e)
        {
            btnClose.Source = new BitmapImage(new Uri("/Images/close_h.png", UriKind.Relative));
        }

        private void btnClose_MouseLeave(object sender, MouseEventArgs e)
        {
            btnClose.Source = new BitmapImage(new Uri("/Images/close.png", UriKind.Relative));
        }

        private void btnClose_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            btnClose.Source = new BitmapImage(new Uri("/Images/close_c.png", UriKind.Relative));
        }

        private void btnClose_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            btnClose.Source = new BitmapImage(new Uri("/Images/close_h.png", UriKind.Relative));
            Close();
        }

        private void Grid_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                MySqlConnection connection = new MySqlConnection(connectionDetails);
                MySqlCommand command = connection.CreateCommand();
                command.CommandText = "SELECT vnum, name FROM shop";
                MySqlDataReader reader;
                connection.Open();
                reader = command.ExecuteReader();

                while (reader.Read())
                {
                    actualShops.Items.Add(reader.GetValue(0) + " : " + reader.GetString(1));
                    shopCounter++;
                }
                connection.Close();
            }
            catch
            {
                MessageBox.Show("Bitte schreibe die richtigen Daten in die mysql.cfg", "ERROR: Config", MessageBoxButton.OK, MessageBoxImage.Error);
                Close();
            } 
        }

        private void itemProtoValue_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            itemProtoName.SelectedIndex = itemProtoValue.SelectedIndex;
        }

        private void itemProtoName_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            itemProtoValue.SelectedIndex = itemProtoName.SelectedIndex;
        }

        private void actualShops_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            actualItems.Items.Clear();
            for (int i = 0; i < 40; i++)
            {
                foreach (Image item in FindVisualChildren<Image>(window))
                {
                    if (item.Name.StartsWith("item_" + i.ToString()))
                    {
                        mainGrid.Children.Remove(item);
                    }
                }
            }
            
            string vnum = actualShops.SelectedItem.ToString().Substring(0,2);
            MySqlConnection connection = new MySqlConnection(connectionDetails);
            MySqlCommand command = connection.CreateCommand();
            command.CommandText = "SELECT name FROM shop_item WHERE shop_vnum = " + vnum;
            MySqlDataReader reader;
            connection.Open();
            reader = command.ExecuteReader();

            while (reader.Read())
            {
                actualItems.Items.Add(reader.GetString(0));
            }
            connection.Close();


            MySqlConnection connection2 = new MySqlConnection(connectionDetails);
            MySqlCommand command2 = connection2.CreateCommand();
            for (int i = 0; i < actualItems.Items.Count; i++)
            {

                command2.CommandText = "SELECT size, vnum FROM item_proto WHERE locale_name = '" + actualItems.Items[i].ToString() + "'";
                MySqlDataReader reader2;
                connection2.Open();
                reader2 = command2.ExecuteReader();

                while (reader2.Read())
                {
                    string value = reader2.GetInt32(1).ToString();

                    if (i < 5)
                    {
                        Image img = new Image();
                        img.Margin = new Thickness(shopItems.Margin.Left + (32 * i), shopItems.Margin.Top, 0, 0);
                        img.HorizontalAlignment = HorizontalAlignment.Left;
                        img.VerticalAlignment = VerticalAlignment.Top;
                        img.Name = "item_" + i.ToString();
                        img.Width = 32;
                        img.Height = 32 * reader2.GetInt32(0);
                        img.Stretch = Stretch.Fill;
                        while (value.Length != 5)
                        {
                            value = "0" + value;
                        }
                        if (Int32.Parse(value) <= 17229 && value != "11901" && value != "11902" && value != "11903" && value != "11904")
                        {
                            value = value.Substring(0, 4);
                            value += "0";
                        }
                        img.Source = new BitmapImage(new Uri("/Images/" + value + ".png", UriKind.Relative));
                        img.ToolTip = actualItems.Items[i].ToString();
                        mainGrid.Children.Add(img);
                    }
                    else if (i >= 5 && i < 10)
                    {
                        foreach (Image item in FindVisualChildren<Image>(window))
                        {
                            if (item.Name == "item_" + (i - 5).ToString())
                            {
                                Image img = new Image();
                                img.Margin = new Thickness(shopItems.Margin.Left + (32 * (i - 5)), shopItems.Margin.Top + item.Height, 0, 0);
                                img.HorizontalAlignment = HorizontalAlignment.Left;
                                img.VerticalAlignment = VerticalAlignment.Top;
                                img.Name = "item_" + i.ToString();
                                img.Width = 32;
                                img.Height = 32 * reader2.GetInt32(0);
                                img.Stretch = Stretch.Fill;
                                while (value.Length != 5)
                                {
                                    value = "0" + value;
                                }
                                if (Int32.Parse(value) <= 17229 && value != "11901" && value != "11902" && value != "11903" && value != "11904")
                                {
                                    value = value.Substring(0, 4);
                                    value += "0";
                                }
                                img.Source = new BitmapImage(new Uri("/Images/" + value + ".png", UriKind.Relative));
                                img.ToolTip = actualItems.Items[i].ToString();
                                mainGrid.Children.Add(img);
                            }
                        }
                    }
                    else if (i >= 10 && i < 15)
                    {
                        foreach (Image item in FindVisualChildren<Image>(window))
                        {
                            if (item.Name == "item_" + (i - 10).ToString())
                            {
                                foreach (Image item2 in FindVisualChildren<Image>(window))
                                {
                                    if (item2.Name == "item_" + (i - 5).ToString())
                                    {
                                        Image img = new Image();
                                        img.Margin = new Thickness(shopItems.Margin.Left + (32 * (i - 10)), shopItems.Margin.Top + item.Height + item2.Height, 0, 0);
                                        img.HorizontalAlignment = HorizontalAlignment.Left;
                                        img.VerticalAlignment = VerticalAlignment.Top;
                                        img.Name = "item_" + i.ToString();
                                        img.Width = 32;
                                        img.Height = 32 * reader2.GetInt32(0);
                                        img.Stretch = Stretch.Fill;
                                        while (value.Length != 5)
                                        {
                                            value = "0" + value;
                                        }
                                        if (Int32.Parse(value) <= 17229 && value != "11901" && value != "11902" && value != "11903" && value != "11904")
                                        {
                                            value = value.Substring(0, 4);
                                            value += "0";
                                        }
                                        img.Source = new BitmapImage(new Uri("/Images/" + value + ".png", UriKind.Relative));
                                        img.ToolTip = actualItems.Items[i].ToString();
                                        mainGrid.Children.Add(img);
                                    }
                                }
                            }
                        }
                    }
                    else if (i >= 15 && i < 20)
                    {
                        foreach (Image item in FindVisualChildren<Image>(window))
                        {
                            if (item.Name == "item_" + (i - 15).ToString())
                            {
                                foreach (Image item2 in FindVisualChildren<Image>(window))
                                {
                                    if (item2.Name == "item_" + (i - 10).ToString())
                                    {
                                        foreach (Image item3 in FindVisualChildren<Image>(window))
                                        {
                                            if (item3.Name == "item_" + (i - 5).ToString())
                                            {
                                                Image img = new Image();
                                                img.Margin = new Thickness(shopItems.Margin.Left + (32 * (i - 15)), shopItems.Margin.Top + item.Height + item2.Height + item3.Height, 0, 0);
                                                img.HorizontalAlignment = HorizontalAlignment.Left;
                                                img.VerticalAlignment = VerticalAlignment.Top;
                                                img.Name = "item_" + i.ToString();
                                                img.Width = 32;
                                                img.Height = 32 * reader2.GetInt32(0);
                                                img.Stretch = Stretch.Fill;
                                                while (value.Length != 5)
                                                {
                                                    value = "0" + value;
                                                }
                                                if (Int32.Parse(value) <= 17229 && value != "11901" && value != "11902" && value != "11903" && value != "11904")
                                                {
                                                    value = value.Substring(0, 4);
                                                    value += "0";
                                                }
                                                img.Source = new BitmapImage(new Uri("/Images/" + value + ".png", UriKind.Relative));
                                                img.ToolTip = actualItems.Items[i].ToString();
                                                mainGrid.Children.Add(img);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else if (i >= 20 && i < 25)
                    {
                        foreach (Image item in FindVisualChildren<Image>(window))
                        {
                            if (item.Name == "item_" + (i - 20).ToString())
                            {
                                foreach (Image item2 in FindVisualChildren<Image>(window))
                                {
                                    if (item2.Name == "item_" + (i - 15).ToString())
                                    {
                                        foreach (Image item3 in FindVisualChildren<Image>(window))
                                        {
                                            if (item3.Name == "item_" + (i - 10).ToString())
                                            {
                                                foreach (Image item4 in FindVisualChildren<Image>(window))
                                                {
                                                    if (item4.Name == "item_" + (i - 5).ToString())
                                                    {
                                                        Image img = new Image();
                                                        img.Margin = new Thickness(shopItems.Margin.Left + (32 * (i - 20)), shopItems.Margin.Top + item.Height + item2.Height + item3.Height + item4.Height, 0, 0);
                                                        img.HorizontalAlignment = HorizontalAlignment.Left;
                                                        img.VerticalAlignment = VerticalAlignment.Top;
                                                        img.Name = "item_" + i.ToString();
                                                        img.Width = 32;
                                                        img.Height = 32 * reader2.GetInt32(0);
                                                        img.Stretch = Stretch.Fill;
                                                        while (value.Length != 5)
                                                        {
                                                            value = "0" + value;
                                                        }
                                                        if (Int32.Parse(value) <= 17229 && value != "11901" && value != "11902" && value != "11903" && value != "11904")
                                                        {
                                                            value = value.Substring(0, 4);
                                                            value += "0";
                                                        }
                                                        img.Source = new BitmapImage(new Uri("/Images/" + value + ".png", UriKind.Relative));
                                                        img.ToolTip = actualItems.Items[i].ToString();
                                                        mainGrid.Children.Add(img);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else if (i >= 25 && i < 30)
                    {
                        foreach (Image item in FindVisualChildren<Image>(window))
                        {
                            if (item.Name == "item_" + (i - 25).ToString())
                            {
                                foreach (Image item2 in FindVisualChildren<Image>(window))
                                {
                                    if (item2.Name == "item_" + (i - 20).ToString())
                                    {
                                        foreach (Image item3 in FindVisualChildren<Image>(window))
                                        {
                                            if (item3.Name == "item_" + (i - 15).ToString())
                                            {
                                                foreach (Image item4 in FindVisualChildren<Image>(window))
                                                {
                                                    if (item4.Name == "item_" + (i - 10).ToString())
                                                    {
                                                        foreach (Image item5 in FindVisualChildren<Image>(window))
                                                        {
                                                            if (item5.Name == "item_" + (i - 5).ToString())
                                                            {
                                                                Image img = new Image();
                                                                img.Margin = new Thickness(shopItems.Margin.Left + (32 * (i - 25)), shopItems.Margin.Top + item.Height + item2.Height + item3.Height + item4.Height + item5.Height, 0, 0);
                                                                img.HorizontalAlignment = HorizontalAlignment.Left;
                                                                img.VerticalAlignment = VerticalAlignment.Top;
                                                                img.Name = "item_" + i.ToString();
                                                                img.Width = 32;
                                                                img.Height = 32 * reader2.GetInt32(0);
                                                                img.Stretch = Stretch.Fill;
                                                                while (value.Length != 5)
                                                                {
                                                                    value = "0" + value;
                                                                }
                                                                if (Int32.Parse(value) <= 17229 && value != "11901" && value != "11902" && value != "11903" && value != "11904")
                                                                {
                                                                    value = value.Substring(0, 4);
                                                                    value += "0";
                                                                }
                                                                img.Source = new BitmapImage(new Uri("/Images/" + value + ".png", UriKind.Relative));
                                                                img.ToolTip = actualItems.Items[i].ToString();
                                                                mainGrid.Children.Add(img);
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else if (i >= 30 && i < 35)
                    {
                        foreach (Image item in FindVisualChildren<Image>(window))
                        {
                            if (item.Name == "item_" + (i - 30).ToString())
                            {
                                foreach (Image item2 in FindVisualChildren<Image>(window))
                                {
                                    if (item2.Name == "item_" + (i - 25).ToString())
                                    {
                                        foreach (Image item3 in FindVisualChildren<Image>(window))
                                        {
                                            if (item3.Name == "item_" + (i - 20).ToString())
                                            {
                                                foreach (Image item4 in FindVisualChildren<Image>(window))
                                                {
                                                    if (item4.Name == "item_" + (i - 15).ToString())
                                                    {
                                                        foreach (Image item5 in FindVisualChildren<Image>(window))
                                                        {
                                                            if (item5.Name == "item_" + (i - 10).ToString())
                                                            {
                                                                foreach (Image item6 in FindVisualChildren<Image>(window))
                                                                {
                                                                    if (item6.Name == "item_" + (i - 5).ToString())
                                                                    {
                                                                        Image img = new Image();
                                                                        img.Margin = new Thickness(shopItems.Margin.Left + (32 * (i - 30)), shopItems.Margin.Top + item.Height + item2.Height + item3.Height + item4.Height + item5.Height + item6.Height, 0, 0);
                                                                        img.HorizontalAlignment = HorizontalAlignment.Left;
                                                                        img.VerticalAlignment = VerticalAlignment.Top;
                                                                        img.Name = "item_" + i.ToString();
                                                                        img.Width = 32;
                                                                        img.Height = 32 * reader2.GetInt32(0);
                                                                        img.Stretch = Stretch.Fill;
                                                                        while (value.Length != 5)
                                                                        {
                                                                            value = "0" + value;
                                                                        }
                                                                        if (Int32.Parse(value) <= 17229 && value != "11901" && value != "11902" && value != "11903" && value != "11904")
                                                                        {
                                                                            value = value.Substring(0, 4);
                                                                            value += "0";
                                                                        }
                                                                        img.Source = new BitmapImage(new Uri("/Images/" + value + ".png", UriKind.Relative));
                                                                        img.ToolTip = actualItems.Items[i].ToString();
                                                                        mainGrid.Children.Add(img);
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else if (i >= 35 && i < 40)
                    {
                        foreach (Image item in FindVisualChildren<Image>(window))
                        {
                            if (item.Name == "item_" + (i - 35).ToString())
                            {
                                foreach (Image item2 in FindVisualChildren<Image>(window))
                                {
                                    if (item2.Name == "item_" + (i - 30).ToString())
                                    {
                                        foreach (Image item3 in FindVisualChildren<Image>(window))
                                        {
                                            if (item3.Name == "item_" + (i - 25).ToString())
                                            {
                                                foreach (Image item4 in FindVisualChildren<Image>(window))
                                                {
                                                    if (item4.Name == "item_" + (i - 20).ToString())
                                                    {
                                                        foreach (Image item5 in FindVisualChildren<Image>(window))
                                                        {
                                                            if (item5.Name == "item_" + (i - 15).ToString())
                                                            {
                                                                foreach (Image item6 in FindVisualChildren<Image>(window))
                                                                {
                                                                    if (item6.Name == "item_" + (i - 10).ToString())
                                                                    {
                                                                        foreach (Image item7 in FindVisualChildren<Image>(window))
                                                                        {
                                                                            if (item7.Name == "item_" + (i - 10).ToString())
                                                                            {
                                                                                Image img = new Image();
                                                                                img.Margin = new Thickness(shopItems.Margin.Left + (32 * (i - 35)), shopItems.Margin.Top + item.Height + item2.Height + item3.Height + item4.Height + item5.Height + item6.Height + item7.Height, 0, 0);
                                                                                img.HorizontalAlignment = HorizontalAlignment.Left;
                                                                                img.VerticalAlignment = VerticalAlignment.Top;
                                                                                img.Name = "item_" + i.ToString();
                                                                                img.Width = 32;
                                                                                img.Height = 32 * reader2.GetInt32(0);
                                                                                img.Stretch = Stretch.Fill;
                                                                                while (value.Length != 5)
                                                                                {
                                                                                    value = "0" + value;
                                                                                }
                                                                                if (Int32.Parse(value) <= 17229 && value != "11901" && value != "11902" && value != "11903" && value != "11904")
                                                                                {
                                                                                    value = value.Substring(0, 4);
                                                                                    value += "0";
                                                                                }
                                                                                img.Source = new BitmapImage(new Uri("/Images/" + value + ".png", UriKind.Relative));
                                                                                img.ToolTip = actualItems.Items[i].ToString();
                                                                                mainGrid.Children.Add(img);
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                connection2.Close();
            }
        }

        public string ReadFile(String sFilename)
        {
            string sContent = "";

            if (File.Exists(sFilename))
            {
                StreamReader myFile = new StreamReader(sFilename, System.Text.Encoding.Default);
                sContent = myFile.ReadToEnd();
                myFile.Close();
            }
            return sContent;
        }
    }
}
Ein Dank hierbei an [Only registered and activated users can see links. Click Here To Register...], da ich sein Clientdesign für Celestia2 missbraucht habe! :>

Archiv ist im Anhang..

Best Regards,
SoNiice

//edit:

Screenshot:

[Only registered and activated users can see links. Click Here To Register...]

Vielleicht mache ich daraus auch noch 'nen Shopcreator, mal sehen..
10/31/2012 02:10 [PixeL]#2
so nice! :D
10/31/2012 02:31 FbFunnY#3
schaut sehr gut aus
10/31/2012 10:19 Lewfire#4
Lol.
Nice! ist ja mal richtig geil Danke.
10/31/2012 10:54 .Rebel#5
is nice but we all know you and not for the best reasons :P

scanning etc
no trust
10/31/2012 11:00 #SoNiice#6
Quote:
Originally Posted by .Rebel View Post
is nice but we all know you and not for the best reasons :P

scanning etc
no trust
Whatever you try to tell me, Haters gonna hate somewhere else. The source is attached too btw.

@Marcely,
Weiß ist das das neue Gut, glaub mir.
10/31/2012 17:32 Red Firestar#7
wow nice danke *-*
10/31/2012 18:28 Syuki#8
Quote:
Originally Posted by SoNiice View Post
@Marcely,
Weiß ist das das neue Gut, glaub mir.
Und blau ist das neue gelb in der grünen Pflanze? :awesome:
Ich baus mir mal ein :P
10/31/2012 18:44 .Marcel'#9
Schönes Tool, mal was Sinnvolles nach langer zeit.

Das sind Releases, und nicht diese 01815 crap Homepagedesigns, und Charselectbilder usw.
10/31/2012 20:28 *~.ιηνιη¢ιвℓє.~*#10
gefällt mir *-* danke für´s teilen :)
10/31/2012 21:03 thespeedyy#11
wenn ich ein shop öffne kommt programm funkt nicht mehr :o
10/31/2012 22:06 Mr. 'Avenue™#12
Das Programm stirbt schneller als Oma's im Koma.. -.-'

"Das Programm funktioniert nicht mehr"
10/31/2012 22:47 ηice#13
Sehr nett :)
Danke
11/01/2012 11:33 #SoNiice#14
Ein Programm kann nicht einfach nicht mehr funtkionieren. Ihr müsst dann schon was gemacht haben, was ihr anscheinend nicht solltet oder eure Datenbank entspricht nicht dem Standard. Möglicherweise den Shops keine Namen zugewiesen?