Пример #1
0
        public void getClients(ref Model model)
        {
            mysql.open();
            string query = "SELECT * FROM klijent";
            mysql.setCmd(query);
            mysql.reader = mysql.cmd.ExecuteReader();

            while (mysql.reader.Read())
            {
                Client client = new Client();

                client.old_id = int.Parse(mysql.reader["idKlijenta"].ToString());
                client.fname = mysql.reader["ime"].ToString();
                client.lname = mysql.reader["prezime"].ToString();
                client.phone1 = mysql.reader["telefon"].ToString();
                client.phone2 = mysql.reader["telefon2"].ToString();
                client.email = mysql.reader["email"].ToString();
                client.fblink = mysql.reader["fblink"].ToString();
                client.notes = mysql.reader["napomene"].ToString();
                client.address = mysql.reader["adresa"].ToString();
                if (mysql.reader["rating"] != null && mysql.reader["rating"].ToString() != "")
                    client.rating = float.Parse(mysql.reader["rating"].ToString(), System.Globalization.CultureInfo.InvariantCulture);
                client.status = (int)mysql.reader["status"];

                model.clients.Add(client);
            }

            mysql.close();
        }
Пример #2
0
        public void getFiles(ref Model model)
        {
            DbMysql mysql2 = new DbMysql();
            mysql.open();
            string query1 = "SELECT * FROM tortedb.proizvod";
            string query2 = "SELECT slike.* FROM tortedb.slikeproizvod JOIN slike ON slikeproizvod.idSlike = slike.idSlike WHERE slikeproizvod.idProizvoda = @product_id";
            mysql.setCmd(query1);
            mysql2.open();
            mysql2.setCmd(query2);
            mysql2.addParam(MySql.Data.MySqlClient.MySqlDbType.Int32, "@product_id");

            using (mysql.reader = mysql.cmd.ExecuteReader())
            {
                while (mysql.reader.Read())
                {
                    Product product = new Product();
                    product.name = mysql.reader["naziv"].ToString();
                    product.price = mysql.reader["cena"].ToString();
                    product.weight = mysql.reader["tezina"].ToString();
                    product.quantity = mysql.reader["kolicina"].ToString();
                    product.description = mysql.reader["opis"].ToString();
                    product.old_group_id = (int)mysql.reader["idGrupe"];
                    product.old_id = (int)mysql.reader["idProizvoda"];

                    model.products.Add(product);

                }
            }

            foreach (Product product in model.products)
            {
                mysql2.cmd.Parameters["@product_id"].Value = product.old_id;
                using (mysql2.reader = mysql2.cmd.ExecuteReader())
                {
                    if (mysql2.reader.HasRows)
                    {
                        while (mysql2.reader.Read())
                        {
                            Picture pic = new Picture();
                            pic.old_id = int.Parse(mysql2.reader["idSlike"].ToString());
                            pic.name = mysql2.reader["naziv"].ToString();
                            pic.path = mysql2.reader["putanja"].ToString();
                            pic.size = int.Parse(mysql2.reader["velicina"].ToString());
                            pic.type = mysql2.reader["tip"].ToString();

                            product.pictures.Add(pic);
                        }
                    }
                }
            }
            mysql.close();
        }
Пример #3
0
        static void Main(string[] args)
        {
            Model model = new Model();
            Methods methods = new Methods();
            //Client client = new Client();

            Console.WriteLine("Fetching clients data...");
            methods.getClients(ref model);
            Console.WriteLine("Success!");

            Console.WriteLine("Fetching files and products...");
            methods.getFiles(ref model);

            Console.WriteLine("Success!");

            Console.WriteLine("Djoka");

            //foreach (Client loopClient in model.clients)
            //{
            //    loopClient.new_id = methods.insertClient(loopClient);
            //}

            foreach (Client client in model.clients)
                Console.WriteLine(client.fname + " " + client.old_id);

            int picturesCount = 0;
            foreach (Product product in model.products) {
                Console.WriteLine("Product name: {0} \n", product.name);
                if (product.pictures.Count == 0)
                    Console.WriteLine("No pictures for this product");
                else {
                    foreach (Picture pic in product.pictures) {
                        Console.WriteLine("Picture for this product: {0}", pic.name);
                        picturesCount++;
                    }
                }
            }

            Console.WriteLine("Products count: {0}, pictures count: {1}, clients count: {2}", model.products.Count, picturesCount, model.clients.Count);

            Console.ReadKey();
        }
Пример #4
0
 public void getOrders(ref Model model)
 {
 }