203 lines
9.8 KiB
C#
203 lines
9.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Xml;
|
|
using System.Reflection;
|
|
using System.Data.SqlClient;
|
|
|
|
namespace XMLExtractor
|
|
{
|
|
public class Aspettative
|
|
{
|
|
public string posizione { get; set; }
|
|
public string descrizione { get; set; }
|
|
public int idCapitolo { get; set; }
|
|
public int idSezione { get; set; }
|
|
public int idPagina { get; set; }
|
|
public int idOrdinamento { get; set; }
|
|
public Dictionary<string, string> items { get; set; }
|
|
|
|
// NEW
|
|
public List<Legenda> legenda { get; set; }
|
|
|
|
public static int writeDB(SqlConnection conn, Dictionary<string, string> items)
|
|
{
|
|
if (items == null)
|
|
return 0;
|
|
string sqlCommand = "(idREP_IMM_MON_Item, keyItem1, valueItem1, keyItem2, valueItem2, keyItem3, valueItem3, "
|
|
+ "keyItem4, valueItem4, keyItem5, valueItem5, keyItem6, valueItem6, keyItem7, valueItem7, keyItem8, valueItem8, "
|
|
+ "keyItem9, valueItem9, keyItem10, valueItem10) "
|
|
+ "VALUES (@idREP_IMM_MON_Item, @keyItem1, @valueItem1, @keyItem2, @valueItem2, @keyItem3, @valueItem3, "
|
|
+ "@keyItem4, @valueItem4, @keyItem5, @valueItem5, @keyItem6, @valueItem6, @keyItem7, @valueItem7, @keyItem8, @valueItem8, "
|
|
+ "@keyItem9, @valueItem9, @keyItem10, @valueItem10)";
|
|
|
|
|
|
SqlCommand insertTo = new SqlCommand("INSERT INTO REP_IMM_MON_Item " + sqlCommand, conn);
|
|
int primaryKey = Convert.ToInt32((new SqlCommand("SELECT count(*) from REP_IMM_MON_Item", conn)).ExecuteScalar()) + 1;
|
|
|
|
int i = 1;
|
|
foreach (var item in items)
|
|
{
|
|
if ((i - 1) < items.Count)
|
|
{
|
|
insertTo.Parameters.AddWithValue("@keyItem" + i, item.Key);
|
|
insertTo.Parameters.AddWithValue("@valueItem" + i, item.Value);
|
|
}
|
|
|
|
i++;
|
|
}
|
|
|
|
for (int j = i; j <= 10; j++)
|
|
{
|
|
insertTo.Parameters.AddWithValue("@keyItem" + j, DBNull.Value);
|
|
insertTo.Parameters.AddWithValue("@valueItem" + j, DBNull.Value);
|
|
}
|
|
|
|
insertTo.Parameters.AddWithValue("@idREP_IMM_MON_Item", primaryKey);
|
|
int rowsUpdatedInserted = insertTo.ExecuteNonQuery();
|
|
if (rowsUpdatedInserted != 0)
|
|
return primaryKey;
|
|
return 0;
|
|
}
|
|
|
|
public static Dictionary<string, string> getItemsString(XmlNode attribute)
|
|
{
|
|
Dictionary<string, string> pointList = new Dictionary<string, string>();
|
|
List<String> chartValues;
|
|
foreach (XmlNode attr in attribute.ChildNodes)
|
|
{
|
|
chartValues = new List<String>();
|
|
foreach (XmlNode value in attr.ChildNodes)
|
|
{
|
|
chartValues.Add(value.InnerText);
|
|
}
|
|
pointList.Add(chartValues[0], Legenda.getSymbol(chartValues[1]));
|
|
}
|
|
|
|
return pointList;
|
|
}
|
|
}
|
|
|
|
public class AspettativeValoriImmobili : Aspettative
|
|
{
|
|
|
|
public void writeDB(SqlConnection conn)
|
|
{
|
|
string sqlCommand = "(idREP_IMM_MON_Aspettativa, idREP_IMM_MON_Pagina, idTipologia, descrizione, posizione, idREP_IMM_MON_Item, idREP_IMM_MON_Legenda) "
|
|
+ "VALUES (@idREP_IMM_MON_Aspettativa, @idREP_IMM_MON_Pagina, @idTipologia, @descrizione, @posizione, @idREP_IMM_MON_Item, @idREP_IMM_MON_Legenda) ";
|
|
|
|
|
|
SqlCommand insertTo = new SqlCommand("INSERT INTO REP_IMM_MON_Aspettative " + sqlCommand, conn);
|
|
insertTo.Parameters.AddWithValue("@idREP_IMM_MON_Pagina", this.idPagina);
|
|
insertTo.Parameters.AddWithValue("@idREP_IMM_MON_Aspettativa", Convert.ToInt32((new SqlCommand("SELECT count(*) from REP_IMM_MON_Aspettative", conn)).ExecuteScalar()) + 1);
|
|
insertTo.Parameters.AddWithValue("@idTipologia", 1);
|
|
insertTo.Parameters.AddWithValue("@descrizione", this.descrizione);
|
|
insertTo.Parameters.AddWithValue("@posizione", this.posizione);
|
|
insertTo.Parameters.AddWithValue("@idREP_IMM_MON_Item", writeDB(conn, this.items));
|
|
insertTo.Parameters.AddWithValue("@idREP_IMM_MON_Legenda", Legenda.writeDB(conn, this.legenda));
|
|
|
|
int rowsUpdatedInserted = insertTo.ExecuteNonQuery();
|
|
}
|
|
|
|
public List<string> getProperties()
|
|
{
|
|
List<string> properties = new List<string>();
|
|
AspettativeValoriImmobili objectChart = new AspettativeValoriImmobili();
|
|
foreach (var prop in objectChart.GetType().GetProperties())
|
|
{
|
|
properties.Add(prop.Name.ToLower());
|
|
}
|
|
|
|
properties.Remove("idcapitolo");
|
|
properties.Remove("idsezione");
|
|
properties.Remove("idpagina");
|
|
properties.Remove("idordinamento");
|
|
return properties;
|
|
}
|
|
|
|
public static void writeAspettativeValoriImmobili(XmlNode attribute, List<string> tagList, string nextTag, Data data)
|
|
{
|
|
AspettativeValoriImmobili aspettativeValoriImmobili = new AspettativeValoriImmobili();
|
|
foreach (XmlNode attr in attribute.ChildNodes)
|
|
if (!tagList.Contains(attr.Name.ToString()))
|
|
{
|
|
PropertyInfo propertyInfo = aspettativeValoriImmobili.GetType().GetProperty(attr.Name);
|
|
|
|
if (propertyInfo.PropertyType.Name.Equals("String"))
|
|
propertyInfo.SetValue(aspettativeValoriImmobili, Convert.ChangeType(attr.InnerText, propertyInfo.PropertyType), null);
|
|
else if (attr.Name.ToLower().Equals("legenda"))
|
|
propertyInfo.SetValue(aspettativeValoriImmobili, Convert.ChangeType(Legenda.getLegenda(attr), propertyInfo.PropertyType), null);
|
|
else
|
|
propertyInfo.SetValue(aspettativeValoriImmobili, Convert.ChangeType(getItemsString(attr), propertyInfo.PropertyType), null);
|
|
}
|
|
data.aspettativeValoriImmobiliList.Add(aspettativeValoriImmobili);
|
|
aspettativeValoriImmobili.idCapitolo = ReadXML.idCapitolo;
|
|
aspettativeValoriImmobili.idSezione = ReadXML.idSezione;
|
|
aspettativeValoriImmobili.idOrdinamento = ReadXML.idOrdinamento;
|
|
aspettativeValoriImmobili.idPagina = ReadXML.idPagina;
|
|
ReadXML.idOrdinamento++;
|
|
}
|
|
}
|
|
|
|
public class AspettativeVariazioneValore : Aspettative
|
|
{
|
|
public void writeDB(SqlConnection conn)
|
|
{
|
|
string sqlCommand = "(idREP_IMM_MON_Aspettativa, idREP_IMM_MON_Pagina, idTipologia, descrizione, posizione, idREP_IMM_MON_Item, idREP_IMM_MON_Legenda) "
|
|
+ "VALUES (@idREP_IMM_MON_Aspettativa, @idREP_IMM_MON_Pagina, @idTipologia, @descrizione, @posizione, @idREP_IMM_MON_Item, @idREP_IMM_MON_Legenda) ";
|
|
|
|
|
|
SqlCommand insertTo = new SqlCommand("INSERT INTO REP_IMM_MON_Aspettative " + sqlCommand, conn);
|
|
insertTo.Parameters.AddWithValue("@idREP_IMM_MON_Pagina", this.idPagina);
|
|
insertTo.Parameters.AddWithValue("@idREP_IMM_MON_Aspettativa", Convert.ToInt32((new SqlCommand("SELECT count(*) from REP_IMM_MON_Aspettative", conn)).ExecuteScalar()) + 1);
|
|
insertTo.Parameters.AddWithValue("@idTipologia", 2);
|
|
insertTo.Parameters.AddWithValue("@descrizione", this.descrizione);
|
|
insertTo.Parameters.AddWithValue("@posizione", this.posizione);
|
|
insertTo.Parameters.AddWithValue("@idREP_IMM_MON_Item", writeDB(conn, this.items));
|
|
insertTo.Parameters.AddWithValue("@idREP_IMM_MON_Legenda", Legenda.writeDB(conn, this.legenda));
|
|
|
|
int rowsUpdatedInserted = insertTo.ExecuteNonQuery();
|
|
}
|
|
|
|
public List<string> getProperties()
|
|
{
|
|
List<string> properties = new List<string>();
|
|
AspettativeVariazioneValore objectChart = new AspettativeVariazioneValore();
|
|
foreach (var prop in objectChart.GetType().GetProperties())
|
|
{
|
|
properties.Add(prop.Name.ToLower());
|
|
}
|
|
|
|
properties.Remove("idcapitolo");
|
|
properties.Remove("idsezione");
|
|
properties.Remove("idordinamento");
|
|
return properties;
|
|
}
|
|
|
|
public static void writeAspettativeVariazioneValore(XmlNode attribute, List<string> tagList, string nextTag, Data data)
|
|
{
|
|
AspettativeVariazioneValore aspettativeVariazioneValore = new AspettativeVariazioneValore();
|
|
foreach (XmlNode attr in attribute.ChildNodes)
|
|
if (!tagList.Contains(attr.Name.ToString()))
|
|
{
|
|
PropertyInfo propertyInfo = aspettativeVariazioneValore.GetType().GetProperty(attr.Name);
|
|
|
|
if (propertyInfo.PropertyType.Name.Equals("String"))
|
|
propertyInfo.SetValue(aspettativeVariazioneValore, Convert.ChangeType(attr.InnerText, propertyInfo.PropertyType), null);
|
|
else if (attr.Name.ToLower().Equals("legenda"))
|
|
propertyInfo.SetValue(aspettativeVariazioneValore, Convert.ChangeType(Legenda.getLegenda(attr), propertyInfo.PropertyType), null);
|
|
else
|
|
propertyInfo.SetValue(aspettativeVariazioneValore, Convert.ChangeType(getItemsString(attr), propertyInfo.PropertyType), null);
|
|
}
|
|
|
|
data.aspettativeVariazioneValoreList.Add(aspettativeVariazioneValore);
|
|
aspettativeVariazioneValore.idCapitolo = ReadXML.idCapitolo;
|
|
aspettativeVariazioneValore.idSezione = ReadXML.idSezione;
|
|
aspettativeVariazioneValore.idOrdinamento = ReadXML.idOrdinamento;
|
|
aspettativeVariazioneValore.idPagina = ReadXML.idPagina;
|
|
ReadXML.idOrdinamento++;
|
|
}
|
|
}
|
|
}
|