93 lines
4.2 KiB
C#
93 lines
4.2 KiB
C#
using System;
|
|
using System.Data;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Data.SqlClient;
|
|
using System.Text;
|
|
|
|
namespace XMLExtractor
|
|
{
|
|
public class TemplateStrutturaModelli
|
|
{
|
|
public int idReport { get; set; }
|
|
public int idModello { get; set; }
|
|
public int idCapitolo { get; set; }
|
|
public int capitoloChiaveLayout { get; set; }
|
|
public int idParagrafo { get; set; }
|
|
public int paragrafoChiaveLayout { get; set; }
|
|
public int idSezione { get; set; }
|
|
public int sezioneChiaveLayout { get; set; }
|
|
public int chiaveIntegrazione { get; set; }
|
|
public int integrazioneChiaveLayout { get; set; }
|
|
public int ordinamento { get; set; }
|
|
|
|
public int isPresent(SqlConnection conn) {
|
|
string sqlCommand =
|
|
"idReport = @idReport AND" +
|
|
"idModello = @idModello AND " +
|
|
"idCapitolo = @idCapitolo AND " +
|
|
"idSezione = @idSezione";
|
|
|
|
SqlCommand cmd = new SqlCommand("SELECT ID from TemplateStrutturaModelli WHERE " + sqlCommand, conn);
|
|
cmd.Parameters.AddWithValue("@idReport", this.idReport);
|
|
cmd.Parameters.AddWithValue("@idModello", this.idModello);
|
|
cmd.Parameters.AddWithValue("@idCapitolo", this.idCapitolo);
|
|
cmd.Parameters.AddWithValue("@idSezione", this.idSezione);
|
|
|
|
return cmd.ExecuteScalar() != null ? Convert.ToInt32(cmd.ExecuteScalar()) : 0;
|
|
}
|
|
|
|
public DataTable readTable(SqlConnection conn) {
|
|
|
|
SqlCommand cmd = new SqlCommand(Utility.TEMPLATE_STRUTTURA_MODELLI_SELECT, conn);
|
|
SqlDataReader reader = cmd.ExecuteReader();
|
|
DataTable dt = new DataTable();
|
|
dt.Load(cmd.ExecuteReader());
|
|
reader.Close();
|
|
return dt;
|
|
}
|
|
|
|
public int writeDB(SqlConnection conn) {
|
|
string sqlAttributes = "idReport = @idReport AND "
|
|
+ "idModello = @idModello AND "
|
|
+ "idCapitolo = @idCapitolo AND "
|
|
+ "idSezione = @idSezione AND "
|
|
+ "idParagrafo = @idParagrafo AND "
|
|
+ "Capitolo_ChiaveLayout = @capitolo_ChiaveLayout AND "
|
|
+ "Sezione_ChiaveLayout = @sezione_ChiaveLayout AND "
|
|
+ "Ordinamento = @ordinamento";
|
|
|
|
SqlCommand cmdCount = new SqlCommand("SELECT count(*) FROM TemplateStrutturaModelli WHERE " + sqlAttributes, conn);
|
|
int rowsUpdatedInserted = 0;
|
|
cmdCount = this.setParameters(cmdCount);
|
|
if ((int)cmdCount.ExecuteScalar() != 1)
|
|
{
|
|
SqlCommand insertTo = new SqlCommand("INSERT into TemplateStrutturaModelli "
|
|
+ "(ID, idReport, idModello, idCapitolo, idSezione, idParagrafo, Capitolo_ChiaveLayout, Sezione_ChiaveLayout, "
|
|
+ "Paragrafo_ChiaveLayout, ChiaveIntegrazione, Integrazione_ChiaveLayout, Ordinamento) "
|
|
+ "VALUES (" + Utility.TEMPLATE_STRUTTURA_MODELLO + ",@idReport, @idModello, @idCapitolo, @idSezione, @idParagrafo, @capitolo_ChiaveLayout, "
|
|
+ "@sezione_ChiaveLayout, NULL, NULL, NULL, @ordinamento)"
|
|
, conn);
|
|
insertTo = this.setParameters(insertTo);
|
|
rowsUpdatedInserted = insertTo.ExecuteNonQuery();
|
|
}
|
|
return rowsUpdatedInserted;
|
|
}
|
|
|
|
|
|
public SqlCommand setParameters(SqlCommand cmdCount)
|
|
{
|
|
cmdCount.Parameters.AddWithValue("@idReport", this.idReport);
|
|
cmdCount.Parameters.AddWithValue("@idModello", this.idModello);
|
|
cmdCount.Parameters.AddWithValue("@idCapitolo", this.idCapitolo);
|
|
cmdCount.Parameters.AddWithValue("@idSezione", this.idSezione);
|
|
cmdCount.Parameters.AddWithValue("@idParagrafo", this.idParagrafo);
|
|
cmdCount.Parameters.AddWithValue("@capitolo_ChiaveLayout", this.capitoloChiaveLayout);
|
|
cmdCount.Parameters.AddWithValue("@sezione_ChiaveLayout", this.sezioneChiaveLayout);
|
|
cmdCount.Parameters.AddWithValue("@ordinamento", this.ordinamento);
|
|
|
|
return cmdCount;
|
|
}
|
|
}
|
|
}
|