Exemplo n.º 1
0
        //inserting data into database

        public bool insertSubject(SubjectClass s)
        {
            //creating a default return type and setting its value to false
            bool isSuccess = false;

            //connect database
            SQLiteConnection conn = new Classes.SqliteHelper().GetSQLiteConnection();

            try
            {
                //creating a Sql query ti insert data
                string sql = "Insert into Subject(OfferdYear,OfferdSemester,SubjectName,SubjectCode,NoOfLectureHours,NoOfTutorilaHours,NoOfLabHours,NoOfEvaluationHours) VALUES(@OfferdYear,@OfferdSemester,@SubjectName,@SubjectCode,@NoOfLectureHours,@NoOfTutorialHours,@NoOfLabHours,@NoOfEvaluationHours)";

                //creatng a Sql command using sql and cmd

                SQLiteCommand cmd = new SQLiteCommand(sql, conn);

                cmd.Parameters.AddWithValue("@OfferdYear", s.OfferdYear);
                cmd.Parameters.AddWithValue("@OfferdSemester", s.OfferdSemester);
                cmd.Parameters.AddWithValue("@SubjectName", s.SubjectName);
                cmd.Parameters.AddWithValue("@SubjectCode", s.SubjectCode);
                cmd.Parameters.AddWithValue("@NoOfLectureHours", s.NoOfLectureHours);
                cmd.Parameters.AddWithValue("@NoOfTutorialHours", s.NoOfTutorialHours);
                cmd.Parameters.AddWithValue("@NoOfLabHours", s.NoOfLabHours);
                cmd.Parameters.AddWithValue("@NoOfEvaluationHours", s.NoOfEvaluationHours);

                // connection open here

                conn.Open();
                int rows = cmd.ExecuteNonQuery();

                //if the queryrun successfully the the value of rows will be greater than zero slse if value will be 0

                if (rows > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                conn.Close();
            }
            return(isSuccess);
        }
Exemplo n.º 2
0
        //method to update data in databse form our application

        public bool UpdateSubject(SubjectClass s)
        {
            //create a default return type and set its default values to false

            bool             isSuccess = false;
            SQLiteConnection conn      = new Classes.SqliteHelper().GetSQLiteConnection();

            try
            {
                string sql = "update Subject set OfferdYear = @OfferdYear, OfferdSemester = @OfferdSemester, SubjectName = @SubjectName, SubjectCode = @SubjectCode, NoOfLectureHours = @NoOfLectureHours, NoOfTutorilaHours = @NoOfTutorialHours,NoOfLabHours = @NoOfLabHours, NoOfEvaluationHours = @NoOfEvaluationHours where SubjectCode = @SubjectCode";

                SQLiteCommand cmd = new SQLiteCommand(sql, conn);

                //create paramters to add values

                cmd.Parameters.AddWithValue("@OfferdYear", s.OfferdYear);
                cmd.Parameters.AddWithValue("@OfferdSemester", s.OfferdSemester);
                cmd.Parameters.AddWithValue("@SubjectName", s.SubjectName);
                cmd.Parameters.AddWithValue("@SubjectCode", s.SubjectCode);
                cmd.Parameters.AddWithValue("@NoOfLectureHours", s.NoOfLectureHours);
                cmd.Parameters.AddWithValue("@NoOfTutorialHours", s.NoOfTutorialHours);
                cmd.Parameters.AddWithValue("@NoOfLabHours", s.NoOfLabHours);
                cmd.Parameters.AddWithValue("@NoOfEvaluationHours", s.NoOfEvaluationHours);

                conn.Open();

                int rows = cmd.ExecuteNonQuery();

                //if the query run successfully the the value of rows will be greater than zero slse if value will be 0

                if (rows > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                conn.Close();
            }
            return(isSuccess);
        }
Exemplo n.º 3
0
        public bool DeleteSubject(SubjectClass s)
        {
            //create a default value and set its value to false
            bool isSuccess = false;

            //creating Sql connection

            SQLiteConnection conn = new Classes.SqliteHelper().GetSQLiteConnection();


            try
            {
                //sql to delete Data
                string sql = "Delete from Subject where SubjectCode = @SubjectCode";


                //creating sql command

                SQLiteCommand cmd = new SQLiteCommand(sql, conn);
                cmd.Parameters.AddWithValue("@SubjectCode", s.SubjectCode);

                //open connection
                conn.Open();

                int rows = cmd.ExecuteNonQuery();

                ////if the query run successfully the the value of rows will be greater than zero slse if value will be 0
                if (rows > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                //close the connection
                conn.Close();
            }
            return(isSuccess);
        }