示例#1
0
    private BasicFood GetBasicFoodData(string id, string lang)
    {
        BasicFood x = new BasicFood();

        try {
            Prices P = new Prices();
            // TODO: loadPrices
            using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + Server.MapPath("~/App_Data/" + dataBase))) {
                connection.Open();
                string sql = string.Format("SELECT id, basicFood FROM bacisFoods WHERE id = '{0}'", id);
                using (SQLiteCommand command = new SQLiteCommand(sql, connection)) {
                    using (SQLiteDataReader reader = command.ExecuteReader()) {
                        while (reader.Read())
                        {
                            x.id        = reader.GetValue(0) == DBNull.Value ? null : reader.GetString(0);
                            x.basicFood = reader.GetValue(1) == DBNull.Value ? null : t.Tran(reader.GetString(1), lang);
                            //if (prices != null) x.price = prices.Find(a => a.food.title == x.basicFood);
                            //xx.Add(x);
                        }
                    }
                }
            }
            return(x);
        } catch (Exception e) {
            L.SendErrorLog(e, null, null, "ShoppingList", "GetBasicFoodData");
            return(x);
        }
    }
示例#2
0
    private List <BasicFood> LoadBasicFoodsData(bool isDistinct, string userId, string lang)
    {
        List <BasicFood> xx = new List <BasicFood>();

        try {
            Prices P      = new Prices();
            var    prices = P.LoadData(userId, null);
            // TODO: loadPrices
            using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + Server.MapPath("~/App_Data/" + dataBase))) {
                connection.Open();
                string sql = string.Format("SELECT id, basicFood FROM bacisFoods WHERE basicFood IS NOT NULL {0}", isDistinct ? "GROUP BY basicFood" : "");
                using (SQLiteCommand command = new SQLiteCommand(sql, connection)) {
                    using (SQLiteDataReader reader = command.ExecuteReader()) {
                        while (reader.Read())
                        {
                            BasicFood x = new BasicFood();
                            x.id = reader.GetValue(0) == DBNull.Value ? null : reader.GetString(0);
                            if (isDistinct)
                            {
                                x.food = reader.GetValue(1) == DBNull.Value ? null : t.Tran(reader.GetString(1), lang);
                            }
                            else
                            {
                                x.basicFood = reader.GetValue(1) == DBNull.Value ? null : t.Tran(reader.GetString(1), lang);
                            }
                            if (prices != null)
                            {
                                x.price = prices.Find(a => a.food.title == x.basicFood);
                            }
                            xx.Add(x);
                        }
                    }
                }
            }
            return(xx);
        } catch (Exception e) {
            L.SendErrorLog(e, null, null, "ShoppingList", "LoadBasicFoodsData");
            return(xx);
        }
    }