public static void DeleteObject(NonConventionalPlantBlock dataObject) { string query = string.Format("DELETE FROM {0} " + "WHERE Id = {1}", table, dataObject.Id); DataBaseManager.ExecuteQuery(query); }
public static int UpdateObject(NonConventionalPlantBlock dataObject) { bool isNew = false; string query = string.Format("SELECT tipo " + "FROM {0} " + "WHERE Id = {1}", table, dataObject.Id); OleDbDataReader reader = DataBaseManager.ReadData(query); if (!reader.Read()) { //query = string.Format("INSERT INTO {0} (tipo, periodo, Bloque, FactorReductor,id) " + // "VALUES(@Name, @Case,@Block, @ReductionFactor, @Id)", table); query = string.Format("INSERT INTO {0} (tipo, periodo, Bloque, FactorReductor) " + "VALUES(@Name, @Case,@Block, @ReductionFactor)", table); isNew = true; } else { query = string.Format("UPDATE {0} SET " + "tipo = @Name, " + "Bloque = @Block, " + "Periodo = @Case," + "FactorReductor = @ReductionFactor " + "WHERE Id = @Id", table); } DataBaseManager.DbConnection.Close(); using (OleDbCommand command = new OleDbCommand(query, DataBaseManager.DbConnection)) { command.Parameters.Add("@Name", OleDbType.VarChar); command.Parameters.Add("@Block", OleDbType.Numeric); command.Parameters.Add("@Case", OleDbType.Numeric); command.Parameters.Add("@ReductionFactor", OleDbType.Numeric); command.Parameters.Add("@Id", OleDbType.Numeric); DataBaseManager.DbConnection.Open(); command.Parameters["@Name"].Value = dataObject.Name; command.Parameters["@Block"].Value = dataObject.Block; command.Parameters["@Case"].Value = dataObject.Case; command.Parameters["@ReductionFactor"].Value = dataObject.ReductionFactor; command.Parameters["@Id"].Value = dataObject.Id; try { int rowsAffected = command.ExecuteNonQuery(); } catch (Exception e) { DataBaseManager.DbConnection.Close(); throw; } DataBaseManager.DbConnection.Close(); } if (isNew) { int id; query = string.Format("SELECT Max(Id) FROM {0}", table); reader = DataBaseManager.ReadData(query); reader.Read(); id = Convert.ToInt32(reader.GetValue(0)); DataBaseManager.DbConnection.Close(); return(id); } else { return(-1); } }
public NonConventionalPlantBlockViewModel(NonConventionalPlantBlock nonConventionalPlantBlock) { this.nonConventionalPlantBlock = nonConventionalPlantBlock; }
/* Constructor needed to add rows in the RadGridView control */ public NonConventionalPlantBlockViewModel() { nonConventionalPlantBlock = new NonConventionalPlantBlock(); nonConventionalPlantBlock.Block = 1; }