public bool createAndInsertToDB() { Console.WriteLine("createAndInsertToDB"); //insert into yw_account(guid) values('8902'); string cmdstring = "insert into " + tableName + " ("; string values = "values("; Type tp = GetType(); List <string> columns = DBSerializer.getDBColoumns(tp); List <string> defines = DBSerializer.getDBDefines(tp); for (int i = 0; i < columns.Count; ++i) { cmdstring += columns[i] + ","; FieldInfo field = tp.GetField(columns[i]); values += "'" + DBSerializer.serializeField(field.FieldType, field.GetValue(this)) + "',"; } cmdstring = cmdstring.Remove(cmdstring.Length - 1); values = values.Remove(values.Length - 1); cmdstring = cmdstring + ") " + values + ");"; Console.WriteLine("createAndInsertToDB:" + cmdstring); return(DataInitializer.DB_insert(tableName, cmdstring));; }
public static string serializePKG(DBPkg pkg) { Console.WriteLine("serializePKG"); Type tp = pkg.GetType(); List <string> columns = DBSerializer.getDBColoumns(tp); Console.WriteLine("serializePKG" + columns.Count.ToString()); XmlDocument doc = new XmlDocument(); XmlElement root = doc.CreateElement("db_data"); doc.AppendChild(root); root.SetAttribute("type", tp.FullName); root.SetAttribute("guid", pkg.guid); for (int i = 0; i < columns.Count; ++i) { XmlElement argnode = doc.CreateElement("field"); root.AppendChild(argnode); FieldInfo field = tp.GetField(columns[i]); argnode.SetAttribute("type", field.FieldType.Name); argnode.SetAttribute("name", columns[i]); argnode.SetAttribute("value", DBSerializer.serializeField(field.FieldType, field.GetValue(pkg))); } System.IO.MemoryStream ms = new System.IO.MemoryStream(1024); doc.Save(ms); return(Encoding.UTF8.GetString(ms.ToArray())); }
private string getCreateString(Type tp) { string cmdString = "("; List <string> columns = DBSerializer.getDBColoumns(tp); List <string> defines = DBSerializer.getDBDefines(tp); for (int i = 0; i < columns.Count; ++i) { cmdString += columns[i]; cmdString += " " + defines[i] + ","; } cmdString = cmdString.Remove(cmdString.Length - 1, 1); cmdString += ");"; Console.WriteLine("CmdString: " + cmdString); return(cmdString); }