Ejemplo n.º 1
0
        private List <Timetable> ReadTables(DataTable dataTable)
        {
            List <Timetable> timetables = new List <Timetable>();

            try
            {
                foreach (DataRow dr in dataTable.Rows)
                {
                    Activity_DAO activity_dao = new Activity_DAO();

                    Timetable timetable = new Timetable()
                    {
                        timetable_id = (int)dr["timetable_id"],
                        activity     = activity_dao.GetById((int)dr["activity_id"]),
                        startTime    = (DateTime)dr["start_time"],
                        endTime      = (DateTime)dr["end_time"],
                    };
                    timetable.nrOfSupervisors = timetable.activity.nrOfSupervisors;

                    timetables.Add(timetable);
                }
                return(timetables);
            }
            catch
            {
                ErrorDAO error = new ErrorDAO("Application couldn't read the timetable table");
            }
            return(null);
        }
Ejemplo n.º 2
0
        private List <Activity> ReadTables(DataTable dataTable)
        {
            List <Activity> activities = new List <Activity>();

            try
            {
                foreach (DataRow dr in dataTable.Rows)
                {
                    Activity activity = new Activity()
                    {
                        activity_id     = (int)dr["activity_id"],
                        activity_name   = (dr["activity_name"].ToString()),
                        nrOfStudents    = (int)dr["nrOfStudents"],
                        activity_Date   = (DateTime)dr["activity_date"],
                        nrOfSupervisors = (int)dr["nrOfSupervisors"]
                    };
                    activities.Add(activity);
                }
                return(activities);
            }
            catch
            {
                ErrorDAO error = new ErrorDAO("Application couldn't read the activity table");
            }
            return(null);
        }
Ejemplo n.º 3
0
        /* For Insert/Update/Delete Queries with an auto_increment id value*/
        protected int ExecuteEditQueryAutoIncrement(String query, SqlParameter[] sqlParameters)
        {
            SqlCommand command           = new SqlCommand();
            int        autoIncrementedId = -1;

            try
            {
                command.Connection  = OpenConnection();
                command.CommandText = query;
                command.Parameters.AddRange(sqlParameters);
                adapter.InsertCommand = command;

                autoIncrementedId = int.Parse(command.ExecuteScalar().ToString());
            }
            catch
            {
                ErrorDAO error = new ErrorDAO("ChapeauApp couldn't execute the query");
                throw;
            }
            finally
            {
                CloseConnection();
            }

            return(autoIncrementedId);
        }
Ejemplo n.º 4
0
        /* For Select Queries */
        protected DataTable ExecuteSelectQuery(String query, params SqlParameter[] sqlParameters)
        {
            SqlCommand command = new SqlCommand();
            DataTable  dataTable;
            DataSet    dataSet = new DataSet();

            try
            {
                command.Connection  = OpenConnection();
                command.CommandText = query;
                command.Parameters.AddRange(sqlParameters);
                command.ExecuteNonQuery();
                adapter.SelectCommand = command;
                adapter.Fill(dataSet);
                dataTable = dataSet.Tables[0];
            }
            catch
            {
                string   exp   = "SomerenApp couldn't execute the select query";
                ErrorDAO error = new ErrorDAO(exp);
                return(null);
            }
            finally
            {
                CloseConnection();
            }
            return(dataTable);
        }
Ejemplo n.º 5
0
 private void CloseConnection()
 {
     try
     {
         conn.Close();
     }
     catch
     {
         ErrorDAO error = new ErrorDAO("ChapeauApp couldn't close the connection");
     }
 }
Ejemplo n.º 6
0
 private void CloseConnection()
 {
     try
     {
         conn.Close();
     }
     catch
     {
         string   exp   = "SomerenApp couldn't close the connection";
         ErrorDAO error = new ErrorDAO(exp);
     }
 }
Ejemplo n.º 7
0
        /* For Insert/Update/Delete Queries with transaction */
        protected void ExecuteEditTranQuery(String query, SqlParameter[] sqlParameters, SqlTransaction sqlTransaction)
        {
            SqlCommand command = new SqlCommand(query, conn, sqlTransaction);

            try
            {
                command.Parameters.AddRange(sqlParameters);
                adapter.InsertCommand = command;
                command.ExecuteNonQuery();
            }
            catch
            {
                ErrorDAO error = new ErrorDAO("ChapeauApp couldn't execute the query");
            }
        }
Ejemplo n.º 8
0
 protected SqlConnection OpenConnection()
 {
     try
     {
         if (conn.State == ConnectionState.Closed || conn.State == ConnectionState.Broken)
         {
             conn.Open();
         }
         return(conn);
     }
     catch
     {
         ErrorDAO error = new ErrorDAO("ChapeauApp Couldn't open the connection");
         return(null);
     }
 }
Ejemplo n.º 9
0
        /* For Insert/Update/Delete Queries with transaction */
        protected void ExecuteEditTranQuery(String query, SqlParameter[] sqlParameters, SqlTransaction sqlTransaction)
        {
            SqlCommand command = new SqlCommand(query, conn, sqlTransaction);

            try
            {
                command.Parameters.AddRange(sqlParameters);
                adapter.InsertCommand = command;
                command.ExecuteNonQuery();
            }
            catch
            {
                string   exp   = "SomerenApp couldn't execute query";
                ErrorDAO error = new ErrorDAO(exp); // showmethod
                throw;
            }
        }
Ejemplo n.º 10
0
        protected SqlConnection OpenConnection()
        {
            try
            {
                if (conn.State == ConnectionState.Closed || conn.State == ConnectionState.Broken)
                {
                    conn.Open();
                }
            }
            catch
            {
                string   exp   = "SomerenApp couldn't open the connection";
                ErrorDAO error = new ErrorDAO(exp);
            }

            return(conn);
        }
Ejemplo n.º 11
0
        /* For Insert/Update/Delete Queries */
        protected void ExecuteEditQuery(String query, SqlParameter[] sqlParameters)
        {
            SqlCommand command = new SqlCommand();

            try
            {
                command.Connection  = OpenConnection();
                command.CommandText = query;
                command.Parameters.AddRange(sqlParameters);
                adapter.InsertCommand = command;
                command.ExecuteNonQuery();
            }
            catch
            {
                ErrorDAO error = new ErrorDAO("ChapeauApp couldn't execute the query");
                throw;
            }
            finally
            {
                CloseConnection();
            }
        }