예제 #1
0
        public static void DeleteObject(VariableConventionalPlant dataObject)
        {
            string query = string.Format("DELETE FROM {0} " +
                                         "WHERE Id = {1}", table, dataObject.Id);

            DataBaseManager.ExecuteQuery(query);
        }
예제 #2
0
        public static int UpdateObject(VariableConventionalPlant dataObject)
        {
            bool   isNew = false;
            string query = string.Format("SELECT Recurso " +
                                         "FROM {0} " +
                                         "WHERE Id = {1}", table, dataObject.Id);

            OleDbDataReader reader = DataBaseManager.ReadData(query);

            if (!reader.Read())
            {
                query = string.Format("INSERT INTO {0}(Recurso, Segmento, FactorConsumo, GeneracionMaxima) " +
                                      "VALUES(@Name, @Segment, @ProductionFactor, @Max)", table);
                isNew = true;
            }
            else
            {
                query = string.Format("UPDATE {0} SET " +
                                      "Recurso = @Name, " +
                                      "Segmento = @Segment, " +
                                      "FactorConsumo = @ProductionFactor, " +
                                      "GeneracionMaxima = @Max " +
                                      "WHERE Id = @Id", table);
            }
            DataBaseManager.DbConnection.Close();

            using (OleDbCommand command = new OleDbCommand(query, DataBaseManager.DbConnection))
            {
                command.Parameters.Add("@Name", OleDbType.VarChar);
                command.Parameters.Add("@Segment", OleDbType.Numeric);
                command.Parameters.Add("@ProductionFactor", OleDbType.Numeric);
                command.Parameters.Add("@Max", OleDbType.Numeric);
                command.Parameters.Add("@Id", OleDbType.Numeric);

                DataBaseManager.DbConnection.Open();

                command.Parameters["@Name"].Value             = dataObject.Name;
                command.Parameters["@Segment"].Value          = dataObject.Segment;
                command.Parameters["@ProductionFactor"].Value = dataObject.ProductionFactor;
                command.Parameters["@Max"].Value = dataObject.Max;
                command.Parameters["@Id"].Value  = dataObject.Id;

                try
                {
                    int rowsAffected = command.ExecuteNonQuery();
                }
                catch
                {
                    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);
            }
        }
예제 #3
0
 public VariableConventionalPlantViewModel(VariableConventionalPlant variableConventionalPlant)
 {
     this.variableConventionalPlant = variableConventionalPlant;
 }
예제 #4
0
 /* Constructor needed to add rows in the RadGridView control */
 public VariableConventionalPlantViewModel()
 {
     variableConventionalPlant = new VariableConventionalPlant();
 }