Example #1
0
        private bool AddToClasses(FullSailClass course)
        {
            ListViewItem item = new ListViewItem();

            item.Text = course.ToString();
            item.Tag  = course;
            switch (course.Track)
            {
            case "Central":
                item.ImageIndex = 0;
                break;

            case "iOS":
                item.ImageIndex = 1;
                break;

            case "Android":
                item.ImageIndex = 2;
                break;

            default:
                break;
            }
            lsv_Classes.Items.Add(item);

            return(true);
        }
Example #2
0
        private bool FillFields(ListViewItem item)
        {
            // fill in data from selected index item
            FullSailClass course = (FullSailClass)item.Tag;

            txt_CName.Text   = course.CourseName;
            txt_CNumber.Text = course.CourseNumber;
            nud_Term.Value   = course.Term;
            nud_Hours.Value  = (decimal)course.CreditHours;
            cbx_Track.Text   = course.Track;

            return(true);
        }
Example #3
0
        private bool UpdateData(FullSailClass course)
        {
            string stm = "UPDATE Classes " +
                         "SET CourseName = @CName, CourseNumber = @CNumber, Term = @Term, CreditHours = @CHours, Track = @Track " +
                         "WHERE ID = @itemId;";

            MySqlCommand cmd = new MySqlCommand(stm, conn);

            cmd.Parameters.AddWithValue("@itemId", course.ID);
            cmd.Parameters.AddWithValue("@CName", course.CourseName);
            cmd.Parameters.AddWithValue("@CNumber", course.CourseNumber);
            cmd.Parameters.AddWithValue("@Term", course.Term);
            cmd.Parameters.AddWithValue("@CHours", course.CreditHours);
            cmd.Parameters.AddWithValue("@Track", course.Track);

            MySqlDataReader rdr = cmd.ExecuteReader();

            rdr.Close();

            return(true);
        }
Example #4
0
        //------------------------------------------------------------------------------------

        //-------------------------------------MYSQL FUNCS------------------------------------
        private bool RetrieveData()
        {
            // create the SQL statement
            string sql = "SELECT * " +
                         "FROM Classes;";

            // create the data adapter
            MySqlDataAdapter adr = new MySqlDataAdapter(sql, conn);

            // set the type for the SELECT command
            adr.SelectCommand.CommandType = CommandType.Text;

            // The fill method adds rows  to match the data source
            adr.Fill(itemData);

            // we can also get a couple of the rows
            numOfRows = itemData.Select().Length;

            // make sure we don't go out of range
            while (currentRow < itemData.Rows.Count)
            {
                // instantiate object to hold data
                FullSailClass course = new FullSailClass();

                course.ID           = int.Parse(itemData.Rows[currentRow]["ID"].ToString());
                course.CourseName   = itemData.Rows[currentRow]["CourseName"].ToString();
                course.CourseNumber = itemData.Rows[currentRow]["CourseNumber"].ToString();
                course.Term         = int.Parse(itemData.Rows[currentRow]["Term"].ToString());
                course.CreditHours  = double.Parse(itemData.Rows[currentRow]["CreditHours"].ToString());
                course.Track        = itemData.Rows[currentRow]["Track"].ToString();

                // add to the list
                AddToClasses(course);

                // advance rows
                currentRow++;
            }

            return(true);
        }
Example #5
0
        // button handles delete and cancel
        private void btn_Delete_Click(object sender, EventArgs e)
        {
            if (btn_Delete.Text == "Cancel")
            {
                // refill in the feilds with the appropriate data
                FillFields(lsv_Classes.Items[0]);

                // deactivate fields
                txt_CName.Enabled     = false;
                txt_CNumber.Enabled   = false;
                nud_Term.Enabled      = false;
                nud_Hours.Enabled     = false;
                cbx_Track.Enabled     = false;
                btn_NewCourse.Enabled = true;

                // change buttons to origional purpose
                btn_Edit.Text   = "Edit";
                btn_Delete.Text = "Delete";
            }
            else
            {
                // deletes the course from the database
                FullSailClass course = (FullSailClass)lsv_Classes.SelectedItems[0].Tag;
                string        stm    = "DELETE FROM Classes " +
                                       "WHERE ID = @itemId;";

                MySqlCommand cmd = new MySqlCommand(stm, conn);
                cmd.Parameters.AddWithValue("@itemId", course.ID);

                MySqlDataReader rdr = cmd.ExecuteReader();
                rdr.Close();

                // deletes from view list
                lsv_Classes.SelectedItems[0].Remove();

                // Fill in Fields with first item info
                FillFields(lsv_Classes.Items[0]);
            }
        }
Example #6
0
        //------------------------------------------------------------------------------------

        //-------------------------------------FIELDS FUNCS-----------------------------------
        private bool ValidatesTextInputs(FullSailClass course)
        {
            // if textfields have all whitespace returns null
            if (string.IsNullOrWhiteSpace(txt_CName.Text))
            {
                course.CourseName = null;
            }
            else
            {
                course.CourseName = txt_CName.Text;
            }

            if (string.IsNullOrWhiteSpace(txt_CNumber.Text))
            {
                course.CourseNumber = null;
            }
            else
            {
                course.CourseNumber = txt_CNumber.Text;
            }

            return(true);
        }
Example #7
0
        // save for a prinatble format in text file
        private void tsmi_Save_Click(object sender, EventArgs e)
        {
            try
            {
                SaveFileDialog saveFileDialog1 = new SaveFileDialog();

                saveFileDialog1.Filter           = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
                saveFileDialog1.DefaultExt       = ".txt";
                saveFileDialog1.FilterIndex      = 2;
                saveFileDialog1.RestoreDirectory = true;

                if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    // Code to write the stream goes here.
                    using (StreamWriter sw = new StreamWriter(saveFileDialog1.FileName))
                    {
                        sw.WriteLine("-----Full Sail Classes For Bachelores Of Mobile Development-----");
                        sw.WriteLine();

                        sw.WriteLine("-------------------Central------------------");
                        foreach (ListViewItem item in lsv_Classes.Items)
                        {
                            FullSailClass course = (FullSailClass)item.Tag;

                            if (course.Track == "Central")
                            {
                                sw.WriteLine($"\t{course.CourseName}-{course.CourseNumber}:");
                                sw.WriteLine("Term:".PadRight(15) + course.Term);
                                sw.WriteLine("Credit Hours:".PadRight(15) + course.CreditHours);
                                sw.WriteLine("Track:".PadRight(15) + course.Track);
                            }
                        }

                        sw.WriteLine();

                        sw.WriteLine("-------------------iOS------------------");
                        foreach (ListViewItem item in lsv_Classes.Items)
                        {
                            FullSailClass course = (FullSailClass)item.Tag;

                            if (course.Track == "iOS")
                            {
                                sw.WriteLine($"\t{course.CourseName}-{course.CourseNumber}:");
                                sw.WriteLine("Term:".PadRight(15) + course.Term);
                                sw.WriteLine("Credit Hours:".PadRight(15) + course.CreditHours);
                                sw.WriteLine("Track:".PadRight(15) + course.Track);
                            }
                        }

                        sw.WriteLine();

                        sw.WriteLine("-------------------Android------------------");
                        foreach (ListViewItem item in lsv_Classes.Items)
                        {
                            FullSailClass course = (FullSailClass)item.Tag;

                            if (course.Track == "Android")
                            {
                                sw.WriteLine($"\t{course.CourseName}-{course.CourseNumber}:");
                                sw.WriteLine("Term:".PadRight(15) + course.Term);
                                sw.WriteLine("Credit Hours:".PadRight(15) + course.CreditHours);
                                sw.WriteLine("Track:".PadRight(15) + course.Track);
                            }
                        }

                        sw.Close();
                    }
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Error in Saving Data!");
            }
        }
Example #8
0
        //------------------------------------------------------------------------------------

        //------------------------------------BUTTON CLICKS-----------------------------------

        // button handles edit/save edit/save
        private void btn_Edit_Click(object sender, EventArgs e)
        {
            if (btn_Edit.Text == "Save Edit")
            {
                // create a new object to hold the new data
                FullSailClass updatedCourse = (FullSailClass)lsv_Classes.SelectedItems[0].Tag;

                ValidatesTextInputs(updatedCourse);
                updatedCourse.Term        = int.Parse(nud_Term.Value.ToString());
                updatedCourse.CreditHours = double.Parse(nud_Hours.Value.ToString());
                updatedCourse.Track       = cbx_Track.Text;

                try
                {
                    // update the database
                    UpdateData(updatedCourse);

                    // equal the new data to the selected items
                    lsv_Classes.SelectedItems[0].Text = updatedCourse.ToString();
                    lsv_Classes.SelectedItems[0].Tag  = updatedCourse;

                    // deactivate fields
                    txt_CName.Enabled   = false;
                    txt_CNumber.Enabled = false;
                    nud_Term.Enabled    = false;
                    nud_Hours.Enabled   = false;
                    cbx_Track.Enabled   = false;

                    // change buttons to origional purpose
                    btn_Edit.Text         = "Edit";
                    btn_Delete.Text       = "Delete";
                    btn_NewCourse.Enabled = true;
                }
                catch (Exception)
                {
                    MessageBox.Show("Do Not Leave Blank");
                }
            }
            else if (btn_Edit.Text == "Add")
            {
                try
                {
                    // add new info to a new FullSailClass object
                    FullSailClass course = new FullSailClass();

                    ValidatesTextInputs(course);
                    course.Term        = (int)nud_Term.Value;
                    course.CreditHours = (double)nud_Hours.Value;
                    course.Track       = cbx_Track.Text;

                    // gets the last added item from database and increments its ID for new item
                    FullSailClass temp = (FullSailClass)lsv_Classes.Items[lsv_Classes.Items.Count - 1].Tag;
                    course.ID = temp.ID + 1;

                    // add to the list
                    AddToClasses(course);

                    // add to database
                    string stm = "INSERT INTO Classes(ID, CourseName, CourseNumber, Term, CreditHours, Track) " +
                                 "VALUES(@itemId, @cName, @cNumber, @term, @cHours, @track)";

                    MySqlCommand cmd = new MySqlCommand(stm, conn);
                    cmd.Parameters.AddWithValue("@itemId", course.ID);
                    cmd.Parameters.AddWithValue("@cName", course.CourseName);
                    cmd.Parameters.AddWithValue("@cNumber", course.CourseNumber);
                    cmd.Parameters.AddWithValue("@term", course.Term);
                    cmd.Parameters.AddWithValue("@cHours", course.CreditHours);
                    cmd.Parameters.AddWithValue("@track", course.Track);

                    MySqlDataReader rdr = cmd.ExecuteReader();
                    rdr.Close();

                    // change buttons to origional purpose
                    btn_Edit.Text   = "Edit";
                    btn_Delete.Text = "Delete";
                }
                catch (Exception)
                {
                    MessageBox.Show("Do Not Leave Blank");
                }
            }
            else
            {
                // enables changes
                txt_CName.Enabled   = true;
                txt_CNumber.Enabled = true;
                nud_Term.Enabled    = true;
                nud_Hours.Enabled   = true;
                cbx_Track.Enabled   = true;

                // change names of buttons to change the functionality
                btn_Edit.Text   = "Save Edit";
                btn_Delete.Text = "Cancel";
            }
        }