private void saveconfig(dbstr item) { var list = getHisList(); var listr = list.Where(n => n.ip == item.ip).ToList(); foreach (var info in listr) { info.ip = item.ip; info.catlog = item.catlog; info.password = item.password; info.dbtype = item.dbtype; info.port = item.port; info.username = item.username; } if (listr.Count < 1) { list.Add(item); } using (System.IO.StringWriter stringWriter = new StringWriter(new StringBuilder())) { XmlSerializer xmlSerializer = new XmlSerializer(typeof(List <dbstr>)); xmlSerializer.Serialize(stringWriter, list); FileStream fs = new FileStream("dbhis.xml", FileMode.OpenOrCreate); StreamWriter sw = new StreamWriter(fs, Encoding.UTF8); sw.Write(stringWriter.ToString().Replace("utf-16", "utf-8")); sw.Close(); fs.Close(); } }
private void initDataBase(dbstr model) { DatabaseType dbType = DatabaseType.MySQL; string connectionStr = "Data Source={0};Initial Catalog={1};User ID={2};Password={3};"; connectionStr = string.Format(connectionStr, model.ip, model.catlog, model.username, model.password); if (model.dbtype.ToUpper() == "MSS") { dbType = DatabaseType.SqlServer2008; connectionStr += "Persist Security Info = True;"; } else if (model.dbtype.ToUpper() == "ORA") { dbType = DatabaseType.Oracle; } else if (model.dbtype.ToUpper() == "MYSQL") { connectionStr += "port=" + model.port + ";"; connectionStr += "charset=utf8;"; } db = new Database(connectionStr, dbType); }