Exemple #1
0
        public static List <Product> db_fill_FoodList(string type)
        {
            using (SQLiteConnection connection_sqlite = new SQLiteConnection(sqlitedb_connstr))
            {
                string sql_string = $"SELECT * FROM Product WHERE type = 'Main Menu' "; //default
                if (type.Equals("Main Menu"))
                {
                    sql_string = $"SELECT * FROM Product WHERE type = 'Main Menu' ";
                }
                if (type.Equals("Drinks"))
                {
                    sql_string = $"SELECT * FROM Product WHERE type = 'Drinks' ";
                }
                if (type.Equals("Desserts"))
                {
                    sql_string = $"SELECT * FROM Product WHERE type = 'Desserts' ";
                }


                List <Product> food_list = new List <Product>();
                using (SQLiteCommand command_sqlite = new SQLiteCommand(sql_string, connection_sqlite))
                {
                    try
                    {
                        command_sqlite.Connection.Open();
                        using (SQLiteDataReader dataReader = command_sqlite.ExecuteReader())
                        {
                            while (dataReader.Read())
                            {
                                Seller  seller  = new Seller();
                                Product product = new Product();
                                product.SetId(Convert.ToInt32(dataReader["id"]));
                                product.SetName(dataReader["name"].ToString());
                                product.SetPrice(Convert.ToDouble(dataReader["price"]));
                                product.SetType(dataReader["type"].ToString());
                                product.SetDescription(dataReader["description"].ToString());
                                product.SetImage(dataReader["image"].ToString());
                                product.SetCreate_date(Convert.ToDateTime(dataReader["create_date"]));
                                product.SetScore(Convert.ToInt16(dataReader["score"]));

                                seller.SetId(Convert.ToInt32(dataReader["owner"]));
                                product.SetOwner(DbSeller.get_seller_data_from_id(seller.GetId())); //Product.owner nesne tutuyor fakat Veri tabanından int id şeklinde aldıgımız için çektiğimiz id nin nesnesini alıyoruz

                                food_list.Add(product);
                            }
                        }
                        return(food_list);
                    }
                    catch (SQLiteException exception)
                    {
                        MessageBox.Show(exception.Message);
                    }
                    return(food_list);
                }
            }
        }
Exemple #2
0
        public static List <Comment> get_comments_of_active_user() //kullanıcının yaptığı yorumlar
        {
            using (SQLiteConnection connection_sqlite = new SQLiteConnection(sqlitedb_connstr))
            {
                string sql_string = ""; //default (hata olması durumu) if lere girip değişicek.
                if (Customer.activeCustomer != 0)
                {
                    sql_string = $"SELECT * FROM Comment WHERE customerComment = '{Customer.activeCustomer}' ";
                }
                if (Seller.activeSeller != 0)
                {
                    sql_string = $"SELECT * FROM Comment WHERE sellerComment = '{Seller.activeSeller}' ";
                }

                using (SQLiteCommand command_sqlite = new SQLiteCommand(sql_string, connection_sqlite))
                {
                    List <Comment> allComments = new List <Comment>();

                    try
                    {
                        command_sqlite.Connection.Open();
                        using (SQLiteDataReader dataReader = command_sqlite.ExecuteReader())
                        {
                            while (dataReader.Read())
                            {
                                Comment comment = new Comment();
                                comment.SetId(Convert.ToInt32(dataReader["id"]));
                                comment.SetText(dataReader["text"].ToString());
                                comment.SetCreateTime(Convert.ToDateTime(dataReader["create_date"]));
                                comment.SetCustomer(DbCustomer.get_customer_from_id(Convert.ToInt32(dataReader["customerComment"])));
                                comment.SetSeller(DbSeller.get_seller_data_from_id(Convert.ToInt32(dataReader["sellerComment"])));
                                comment.SetProduct(DbProduct.get_product_from_id(Convert.ToInt32(dataReader["product"])));

                                allComments.Add(comment); //listeye eklendi
                            }
                        }
                    }
                    catch (SQLiteException exception)
                    {
                        MessageBox.Show(exception.Message);
                    }

                    return(allComments);
                }
            }
        }
Exemple #3
0
        public static Product get_product_from_id(int product_id)
        {
            using (SQLiteConnection connection_sqlite = new SQLiteConnection(sqlitedb_connstr))
            {
                string sql_string = $"SELECT * FROM Product WHERE id = {product_id} "; //default

                Seller  seller  = new Seller();
                Product product = new Product();
                using (SQLiteCommand command_sqlite = new SQLiteCommand(sql_string, connection_sqlite))
                {
                    try
                    {
                        command_sqlite.Connection.Open();
                        using (SQLiteDataReader dataReader = command_sqlite.ExecuteReader())
                        {
                            if (dataReader.Read())
                            {
                                product.SetId(Convert.ToInt32(dataReader["id"]));
                                product.SetName(dataReader["name"].ToString());
                                product.SetPrice(Convert.ToDouble(dataReader["price"]));
                                product.SetType(dataReader["type"].ToString());
                                product.SetDescription(dataReader["description"].ToString());
                                product.SetImage(dataReader["image"].ToString());
                                product.SetCreate_date(Convert.ToDateTime(dataReader["create_date"]));
                                product.SetScore(Convert.ToInt16(dataReader["score"]));

                                seller.SetId(Convert.ToInt32(dataReader["owner"]));
                                product.SetOwner(DbSeller.get_seller_data_from_id(seller.GetId())); //Product.owner nesne tutuyor fakat Veri tabanından int id şeklinde aldıgımız için çektiğimiz id nin nesnesini alıyoruz
                            }
                        }
                        return(product);
                    }
                    catch (SQLiteException exception)
                    {
                        MessageBox.Show(exception.Message);
                    }
                    return(product);
                }
            }
        }
Exemple #4
0
        public static List <Comment> comments_of_product(int selected_product_id) //bir ürünün yorumlarını list şeklinde return ediyoruz
        {
            using (SQLiteConnection connection_sqlite = new SQLiteConnection(sqlitedb_connstr))
            {
                string sql_string = $"SELECT * FROM Comment WHERE product = '{selected_product_id}'"; //seçili ürünün yorumları

                using (SQLiteCommand command_sqlite = new SQLiteCommand(sql_string, connection_sqlite))
                {
                    List <Comment> allComments = new List <Comment>();

                    try
                    {
                        command_sqlite.Connection.Open();
                        using (SQLiteDataReader dataReader = command_sqlite.ExecuteReader())
                        {
                            while (dataReader.Read())
                            {
                                Comment comment = new Comment();
                                comment.SetId(Convert.ToInt32(dataReader["id"]));
                                comment.SetText(dataReader["text"].ToString());
                                comment.SetCreateTime(Convert.ToDateTime(dataReader["create_date"]));
                                comment.SetCustomer(DbCustomer.get_customer_from_id(Convert.ToInt32(dataReader["customerComment"])));
                                comment.SetSeller(DbSeller.get_seller_data_from_id(Convert.ToInt32(dataReader["sellerComment"])));
                                comment.SetProduct(DbProduct.get_product_from_id(Convert.ToInt32(dataReader["product"])));

                                allComments.Add(comment); //listeye eklendi
                            }
                        }
                    }
                    catch (SQLiteException exception)
                    {
                        MessageBox.Show(exception.Message);
                    }

                    return(allComments);
                }
            }
        }