public string GenerateXml(Scheme scheme, LRSRecord record) { MemoryStream ms = new MemoryStream(); XmlWriter xw = XmlWriter.Create(ms); xw.WriteStartDocument(); xw.WriteStartElement("item"); if (scheme != null) { foreach (SchemeRecord col in scheme) { xw.WriteStartElement(col.ColumnName); string value = record.Columns.SingleOrDefault(x => x.Key.Equals(col.ColumnName)).Value; xw.WriteString(value); xw.WriteEndElement(); } } xw.WriteEndElement(); xw.WriteEndDocument(); xw.Flush(); Byte[] buffer = new Byte[ms.Length]; buffer = ms.ToArray(); string xmlOutput = Encoding.UTF8.GetString(buffer); return xmlOutput; }
public Scheme GetLRSScheme(int id) { Scheme scheme = new Scheme(); SchemeRecord record = null; using (SqlCommand command = new SqlCommand("[dbo].[GetLRSSchemeAttr]") { CommandType = CommandType.StoredProcedure }) { command.Parameters.AddWithValue("@LRSSchemeId", id); using (IDataReader rdr = ExecuteReader(command)) { while (rdr.Read()) { record = new SchemeRecord() { Id = rdr["Id"].ToString().SmartParseDefault<int>(default(int)) , ColumnName = rdr["COLUMN_NAME"].ToString() , FriendlyName = rdr["FRIENDLY_NAME"].ToString() , DataType = rdr["DATA_TYPE"].ToString() , DisplayType = rdr["DISPLAY_TYPE"].ToString() , MaxLength = rdr["CHARACTER_MAXIMUM_LENGTH"].ToString().SmartParseDefault<int>(default(int)) , ColumnDefault = rdr["COLUMN_DEFAULT"].ToString() , IsNullable = rdr["IS_NULLABLE"].ToString().SmartParseDefault<bool>(false) , IsRequired = rdr["IS_REQUIRED"].ToString().SmartParseDefault<bool>(false) }; scheme.Add(record); } } } return scheme; }