public bool LoadFromDBFile(string dbPath) { if (string.IsNullOrEmpty(dbPath)) { return(false); } m_dbPath = dbPath; var sqlCnn = new SQLiteConnection(); sqlCnn.ConnectionString = string.Format("Data Source={0};Version = 3", dbPath); sqlCnn.Open(); var cmd = sqlCnn.CreateCommand(); cmd.CommandText = "Select * FROM material"; var reader = cmd.ExecuteReader(); if (reader == null) { MyDebug.WriteLine("Error loading Material data from DBFile!"); return(false); } m_ingredientList.Clear(); m_indexMap.Clear(); while (reader.Read()) { int column = 0; var matData = new IngredientData(); matData.id = reader.GetInt32Safe(column++); matData.key = reader.GetStringSafe(column++); matData.food_id = reader.GetInt32Safe(column++); matData.price = reader.GetInt32Safe(column++); matData.texture = reader.GetStringSafe(column++); string colName = reader.GetName(column); if (colName.Contains("name_")) { string location = colName.Substring(5); matData.display_name.Add(location, reader.GetStringSafe(column)); } else if (colName.Contains("position")) { //int mapId = int.Parse(colName.Substring(8)); matData.display_position.Add(colName.Substring(8), reader.GetStringSafe(column)); } column++; m_ingredientList.Add(matData); m_indexMap.AddValue(matData.key, matData.id, m_ingredientList.Count - 1); } reader.Close(); cmd.Dispose(); sqlCnn.Close(); sqlCnn.Dispose(); return(true); }
public bool LoadFromDBFile(string dbPath) { if (string.IsNullOrEmpty(dbPath)) { return(false); } m_dbPath = dbPath; var sqlCnn = new SQLiteConnection(); sqlCnn.ConnectionString = string.Format("Data Source={0};Version = 3", dbPath); sqlCnn.Open(); var cmd = sqlCnn.CreateCommand(); cmd.CommandText = "Select customer_id,customer_key,displayname_cn,isLeftGarbage,type,sourceDir,icon_file FROM customerInfo"; var reader = cmd.ExecuteReader(); if (reader == null) { MyDebug.WriteLine("Error loading customer data from DBFile!"); return(false); } m_customerList.Clear(); m_indexMap.Clear(); while (reader.Read()) { int column = 0; var cusData = new CustomerData(); cusData.id = reader.GetInt32Safe(column++); cusData.key = reader.GetStringSafe(column++); cusData.display_name.Add("cn", reader.GetStringSafe(column++)); cusData.can_litter = reader.GetInt32Safe(column++) > 0; cusData.type = reader.GetStringSafe(column++); string sourceDir = reader.GetStringSafe(column++); string iconName = reader.GetStringSafe(column++); cusData.icon_texture = sourceDir + iconName; m_customerList.Add(cusData); m_indexMap.AddValue(cusData.key, cusData.id, m_customerList.Count - 1); } reader.Close(); sqlCnn.Close(); sqlCnn.Dispose(); return(true); }
public bool LoadFromDBFile(string dbPath) { if (string.IsNullOrEmpty(dbPath)) { return(false); } m_dbPath = dbPath; var sqlCnn = new SQLiteConnection("data source=" + dbPath); sqlCnn.Open(); var cmd = sqlCnn.CreateCommand(); cmd.CommandText = "SELECT * FROM Map"; var reader = cmd.ExecuteReader(); if (reader == null) { MyDebug.WriteLine("Failed to load map data from Map"); return(false); } m_mapDataList.Clear(); m_indexMap.Clear(); while (reader.Read()) { int column = 0; var mapData = new MapData(); mapData.id = reader.GetInt32Safe(column++); mapData.key = reader.GetStringSafe(column++); mapData.display_name.Add("cn", reader.GetStringSafe(column++)); string containLv = reader.GetStringSafe(column++); int spIdx = containLv.IndexOf(','); mapData.start_level = containLv.Substring(0, spIdx).ToInt32(); mapData.end_level = containLv.Substring(spIdx + 1).ToInt32(); mapData.level_count = mapData.end_level - mapData.start_level + 1; //cloumnName = reader.GetName(column); object value = reader.GetValue(column++); if (value != null) { string foods = value.ToString(); if (!string.IsNullOrEmpty(foods)) { mapData.food_list = new List <string>(foods.Split(new[] { ';' }, System.StringSplitOptions.RemoveEmptyEntries)); } } value = reader.GetValue(column++); if (value != null) { string customers = value.ToString(); if (!string.IsNullOrEmpty(customers)) { mapData.customer_list = new List <string>(customers.Split(new[] { ';' }, System.StringSplitOptions.RemoveEmptyEntries)); } } value = reader.GetValue(column++); if (value != null) { string spCustomers = value.ToString(); if (!string.IsNullOrEmpty(spCustomers)) { mapData.special_customer_list = new List <string>(spCustomers.Split(new[] { ';' }, System.StringSplitOptions.RemoveEmptyEntries)); } } m_mapDataList.Add(mapData); m_indexMap.AddValue(mapData.key, mapData.id, m_mapDataList.Count - 1); } reader.Close(); sqlCnn.Close(); return(true); }
public bool LoadFromDBFile(string dbPath) { if (string.IsNullOrEmpty(dbPath)) { return(false); } m_dbpath = dbPath; var cwCnn = new SQLiteConnection(); cwCnn.ConnectionString = string.Format("Data Source={0};Version=3", dbPath); cwCnn.Open(); string sql_select = "SELECT CookingWareID,KeyName,lv,type,specialEffects,name_cn,Coin,Cash,BaseWorkTime,WorkSpeed,BurnSpeed,Makecount,ScopeMap,DefaultFoodID,ArmaturePath,Thumbnails FROM cookingware"; SQLiteCommand cmd = cwCnn.CreateCommand(); cmd.CommandText = sql_select; var reader = cmd.ExecuteReader(); if (reader == null) { MyDebug.WriteLine("Error reading CW Data from DBFile"); return(false); } m_cookwareList.Clear(); m_indexMap.Clear(); while (reader.Read()) { var cwData = new CookwareData(); int column = 0; cwData.id = reader.GetInt32Safe(column++); cwData.key = reader.GetStringSafe(column++); cwData.level = reader.GetInt32Safe(column++); cwData.functions.Add(reader.GetStringSafe(column++)); cwData.special_effects.Add(reader.GetStringSafe(column++)); cwData.display_name.Add("cn", reader.GetStringSafe(column++)); cwData.price.coin = reader.GetInt32Safe(column++); cwData.price.gem = reader.GetInt32Safe(column++); cwData.base_work_time = reader.GetFloatSafe(column++); cwData.work_speed = reader.GetInt32Safe(column++) * 0.01f; cwData.burn_speed = reader.GetInt32Safe(column++) * 0.01f; cwData.make_count = reader.GetInt32Safe(column++); string scopeMapStr = reader.GetStringSafe(column++); if (!string.IsNullOrEmpty(scopeMapStr)) { if (scopeMapStr.Contains(",")) { var mapList = scopeMapStr.Split(','); foreach (string map in mapList) { int mapId = int.Parse(map); cwData.scopeMap.Add(mapId); } } else if (scopeMapStr.Contains("-")) { int spIdx = scopeMapStr.IndexOf('-'); int start = int.Parse(scopeMapStr.Substring(0, spIdx)); int end = int.Parse(scopeMapStr.Substring(spIdx + 1, scopeMapStr.Length - spIdx - 1)); for (int i = start; i <= end; i++) { cwData.scopeMap.Add(i); } } } cwData.default_food_id = reader.GetInt32Safe(column++); cwData.animation = reader.GetStringSafe(column++); cwData.icon_texture = reader.GetStringSafe(column++); m_cookwareList.Add(cwData); m_indexMap.AddValue(cwData.key, cwData.id, m_cookwareList.Count - 1); } reader.Close(); cmd.Dispose(); cwCnn.Close(); cwCnn.Dispose(); return(true); }
public bool LoadFromDBFile(string dbPath) { if (string.IsNullOrEmpty(dbPath)) { return(false); } m_dbPath = dbPath; var sqlCnn = new SQLiteConnection(); string cnnStr = string.Format("Data Source={0};Version=3", dbPath); sqlCnn.ConnectionString = cnnStr; sqlCnn.Open(); string sql_select = "SELECT FoodID,KeyName,name_cn,TexturePath,FoodPrice,MakeTime,BurnTime,CookingwareType,Materiallist FROM food"; SQLiteCommand cmd = sqlCnn.CreateCommand(); cmd.CommandText = sql_select; var reader = cmd.ExecuteReader(); if (reader == null) { MyDebug.WriteLine("Error reading Food Data from DBFile"); return(false); } m_indexMap.Clear(); m_foodList.Clear(); while (reader.Read()) { int column = 0; var foodData = new FoodData(); foodData.id = reader.GetInt32Safe(column++); foodData.key = reader.GetStringSafe(column++); foodData.display_name.Add("cn", reader.GetStringSafe(column++)); foodData.texture = reader.GetStringSafe(column++); foodData.price = reader.GetInt32Safe(column++); foodData.cook_time = reader.GetFloatSafe(column++); foodData.burn_time = reader.GetFloatSafe(column++); string cwTypeStr = reader.GetStringSafe(column++); if (cwTypeStr.Contains(":")) { int pos = cwTypeStr.IndexOf(':'); foodData.cookware_type = cwTypeStr.Substring(0, pos).ToInt32(); foodData.shapeIndex = cwTypeStr.Substring(pos + 1, cwTypeStr.Length - pos - 1).ToInt32(); } else { if (cwTypeStr.Length > 0) { foodData.cookware_type = cwTypeStr.ToInt32(); } } string ingredients = reader.GetStringSafe(column++); if (ingredients.Length > 0) { foodData.ingredients = new List <string>(ingredients.Split(';')); } m_foodList.Add(foodData); m_indexMap.AddValue(foodData.key, foodData.id, m_foodList.Count - 1); } reader.Close(); cmd.Dispose(); sqlCnn.Close(); sqlCnn.Dispose(); for (int i = 0; i < m_foodList.Count; ++i) { FoodData fd = m_foodList[i]; getCookingStep(fd.key, ref fd); fd.suggested_price = calcFoodPrice(fd.key); } return(true); }