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

            DataBaseManager.ExecuteQuery(query);

            query = string.Format("DELETE FROM topologiaHidraulica " +
                                  "WHERE Sistema = '{0}'", dataObject.Name);
            DataBaseManager.ExecuteQuery(query);
        }
Exemple #2
0
        public static int UpdateObject(HydroSystem dataObject)
        {
            bool   isNew = false;
            string query = string.Format("SELECT sistema " +
                                         "FROM {0} " +
                                         "WHERE Id = {1}", table, dataObject.Id);

            OleDbDataReader reader = DataBaseManager.ReadData(query);

            if (!reader.Read())
            {
                query = string.Format("INSERT INTO {0}(sistema, turbinamientoMinimo, turbinamientoMaximo, FactorEnergia, EtapaEntrada) " +
                                      "VALUES(@Name, @MinTurbinedOutflow, @MaxTurbinedOutflow, @EnergyFactor, @InitialPeriod)", table);
                isNew = true;
            }
            else
            {
                query = string.Format("UPDATE {0} SET " +
                                      "sistema = @Name, " +
                                      "turbinamientoMinimo = @MinTurbinedOutflow, " +
                                      "turbinamientoMaximo = @MaxTurbinedOutflow, " +
                                      "FactorEnergia = @EnergyFactor, " +
                                      "EtapaEntrada = @InitialPeriod " +
                                      "WHERE Id = @Id", table);
            }
            DataBaseManager.DbConnection.Close();

            using (OleDbCommand command = new OleDbCommand(query, DataBaseManager.DbConnection))
            {
                command.Parameters.Add("@Name", OleDbType.VarChar);
                command.Parameters.Add("@MinTurbinedOutflow", OleDbType.Numeric);
                command.Parameters.Add("@MaxTurbinedOutflow", OleDbType.Numeric);
                command.Parameters.Add("@EnergyFactor", OleDbType.Numeric);
                command.Parameters.Add("@InitialPeriod", OleDbType.Numeric);
                command.Parameters.Add("@Id", OleDbType.Numeric);

                DataBaseManager.DbConnection.Open();

                command.Parameters["@Name"].Value = dataObject.Name;
                command.Parameters["@MinTurbinedOutflow"].Value = dataObject.MinTurbinedOutflow;
                command.Parameters["@MaxTurbinedOutflow"].Value = dataObject.MaxTurbinedOutflow;
                command.Parameters["@EnergyFactor"].Value       = dataObject.EnergyFactor;
                command.Parameters["@InitialPeriod"].Value      = dataObject.StartPeriod;
                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);
            }
        }
Exemple #3
0
 public HydroSystemViewModel(HydroSystem hydroSystem)
 {
     this.hydroSystem = hydroSystem;
 }
Exemple #4
0
 /* Constructor needed to add rows in the RadGridView control */
 public HydroSystemViewModel()
 {
     hydroSystem = new HydroSystem();
 }