コード例 #1
0
ファイル: SomerenDB.cs プロジェクト: deelirious/ThePensioners
        public static List <SomerenModel.Activities> DB_getActivities()
        {
            // make a sql connection
            SqlConnection connection = openConnectionDB();
            // make a list to store data from DB into it
            List <SomerenModel.Activities> activityList = new List <SomerenModel.Activities>();
            // sql query
            string sqlQuery = "SELECT activity_id, activity_desc, numberofStudents, numberofSupervisors " +
                              "FROM Activities";

            // execute the sql query
            SqlCommand    command = new SqlCommand(sqlQuery, connection);
            SqlDataReader reader  = command.ExecuteReader();

            // read data from DB
            while (reader.Read())
            {
                SomerenModel.Activities activities = new SomerenModel.Activities();

                activities.setId((int)reader["activity_id"]);
                activities.setActivity_desc((string)reader["activity_desc"]);
                activities.setNumOfStudents((int)reader["numberofStudents"]);
                activities.setNumOfSupervisors((int)reader["numberofSupervisors"]);
                activityList.Add(activities);
            }
            // close all connections
            reader.Close();
            connection.Close();

            return(activityList);
        }
コード例 #2
0
ファイル: SomerenUI.cs プロジェクト: deelirious/ThePensioners
        public static void uppdateActivity(int id, string desc, int numOfStudents, int numberOfSupervisor)
        {
            // make a new variable of type SomerenModel.Activities in order to store data to it
            SomerenModel.Activities newActivity = new SomerenModel.Activities();

            // store data to the newActivity variable
            newActivity.setId(id);
            newActivity.setActivity_desc(desc);
            newActivity.setNumOfStudents(numOfStudents);
            newActivity.setNumOfSupervisors(numberOfSupervisor);

            // passing data to the DB layer
            SomerenDB.DB_uppdateActivity(newActivity);
        }
コード例 #3
0
ファイル: SomerenUI.cs プロジェクト: deelirious/ThePensioners
        public static void addActivity(string desc, int numOfStudents, int numberOfSupervisor)
        {
            // make a list for retrieving data from it
            List <SomerenModel.Activities> activities = new List <SomerenModel.Activities>();

            // linking the list to the DB connection in order to get data from it
            activities = SomerenDB.DB_getActivities();

            // make a new variable of type SomerenModel.Activities in order to store data to it
            SomerenModel.Activities newActivity = new SomerenModel.Activities();

            // make a list to store avtivity description in it
            List <string> activityDesc = new List <string>();

            // add avtivity description to the activityDesc list
            foreach (SomerenModel.Activities activity in activities)
            {
                activityDesc.Add(activity.getActivity_desc().ToLower());
            }

            // make a validation to know if the data entered is diffrenet from DB data
            if (activityDesc.Contains(desc.ToLower()))
            {
                // show a message if the entered data exists in the DB
                MessageBox.Show("You can not add the same activity twice, please enter another activity name!",
                                "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                //store data to the newActivity variable
                newActivity.setActivity_desc(desc);
                newActivity.setNumOfStudents(numOfStudents);
                newActivity.setNumOfSupervisors(numberOfSupervisor);
                // passing data to the DB layer
                SomerenDB.DB_addActivity(newActivity);

                // show a messagebox after a successfull addition
                MessageBox.Show("You have successfully added a new activity!!\n" +
                                "Enter Refresh the list to see the changes", "",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }