Example #1
0
        public static List <Projects_class> Load()
        {
            List <Projects_class> proj = new List <Projects_class>();
            StreamReader          inFile;
            Projects_class        pro;

            try
            {
                inFile = File.OpenText("project2.txt");

                while (!inFile.EndOfStream)
                {
                    pro              = new Projects_class();
                    pro.ID           = Int32.Parse(inFile.ReadLine());
                    pro.Project_name = inFile.ReadLine();
                    pro.Year         = Int32.Parse(inFile.ReadLine());
                    pro.Category     = inFile.ReadLine();



                    proj.Add(pro);
                }

                inFile.Close();

                return(proj);
            }
            catch
            {
                return(proj);
            }
        }
        //load the text file
        private void project_selection_form_Load(object sender, EventArgs e)
        {
            proj = projectDA.Load();
            MySqlConnection connection = new MySqlConnection(connec);

            connection.Open();
            string query1 = @"SELECT 
                                    *
                                 FROM internal_communication_4.projects AS p1";


            MySqlDataAdapter adapt = new MySqlDataAdapter(query1, connection);

            adapt.Fill(table);

            while (row < table.Rows.Count)
            {
                Projects_class su = new Projects_class();
                su.Project_name = (string)table.Rows[row]["project_name"];
                su.Category     = (string)table.Rows[row]["project_category"];
                su.Year         = Convert.ToInt32(table.Rows[row]["project_year"]);
                su.ID           = Convert.ToInt32(table.Rows[row]["project_id"]);
                project_list.Items.Add(su.Showproject());
                row += 1;
            }
            connection.Close();


            user_lbl.Text     = login_form.user_name;
            position_lbl.Text = login_form.user_position;

            //load subjects !!!!!!!!!!!!!!!!!!!!!!


            /*MySqlConnection connection = new MySqlConnection(connec);
             * connection.Open();
             * string query6 = "SELECT user_name, user_position FROM internal_communication_4.user AS u1 JOIN internal_communication_4.logs AS l1 ON u1.user_id = l1.user_user_id WHERE (log_current = 1)";
             * MySqlCommand command = new MySqlCommand(query6, connection);
             * MySqlDataReader reader;
             * reader = command.ExecuteReader();
             * while (reader.Read())
             * {
             *   user_lbl.Text = reader.GetString(0);
             *   position_lbl.Text = reader.GetString(1);
             * }
             * connection.Close();
             */
            try
            {
                MySqlConnection connection1 = new MySqlConnection(connec);
                //set projects as non active
                Projects_class pro = new Projects_class();
                pro.Proj_active = 2;
                connection1.Open();
                string       query7 = "UPDATE internal_communication_4.projects SET project_selection = @project_selection ";
                MySqlCommand comm   = connection1.CreateCommand();
                comm.CommandText = query7;
                comm.Parameters.AddWithValue("@project_selection", pro.Proj_active);
                comm.ExecuteNonQuery();
                connection1.Close();
            }
            catch
            { }
        }
        private void project_btn_Click(object sender, EventArgs e)
        {
            Projects_class pro = new Projects_class();

            this.Close();
        }
        private void Next_Click(object sender, EventArgs e)
        {
            //reset the current project to inactive in the database and clear the subject list
            Projects_class pro2 = new Projects_class();

            pro2.Proj_active = 2;
            MySqlConnection connection1 = new MySqlConnection(connec);

            connection1.Open();
            string       query8 = @"UPDATE internal_communication_4.projects 
                                SET project_selection = @project_selection 
                                WHERE (project_id = " + proID + ")";
            MySqlCommand comm1  = connection1.CreateCommand();

            comm1.CommandText = query8;
            comm1.Parameters.AddWithValue("@project_selection", pro2.Proj_active);
            comm1.ExecuteNonQuery();
            connection1.Close();

            subject_listbx.Items.Clear();

            //reset the subject active
            try
            {
                MySqlConnection connection2 = new MySqlConnection(connec);
                Subject_class   sub         = new Subject_class();
                sub.Subject_select = 2;
                connection2.Open();
                string       query10 = "UPDATE internal_communication_4.subjects SET subject_selection = @subject_selection";
                MySqlCommand comm    = connection2.CreateCommand();
                comm.CommandText = query10;
                comm.Parameters.AddWithValue("@subject_selection", sub.Subject_select);
                comm.ExecuteNonQuery();
                connection2.Close();
            }
            catch
            {
                MessageBox.Show("error, please repeat the process");
            }


            Projects_class pro = new Projects_class();

            pro.Proj_active = 1;
            selectedItems   = new ListBox.SelectedObjectCollection(project_list);
            selectedItems   = project_list.SelectedItems;
            int selectedIndex = project_list.SelectedIndex;

            if (selectedIndex != -1)
            {
                for (int i = selectedItems.Count - 1; i >= 0; i--)
                {
                    projIDii = selectedItems[i].ToString();
                }
                projIDiii = projIDii.Split(',');
                proID     = Convert.ToInt32(projIDiii[0]);
                MySqlConnection connection = new MySqlConnection(connec);
                connection.Open();
                string       query7 = @"UPDATE internal_communication_4.projects 
                                   SET project_selection = @project_selection 
                                   WHERE (project_id = " + proID + ")";
                MySqlCommand comm   = connection.CreateCommand();
                comm.CommandText = query7;
                comm.Parameters.AddWithValue("@project_selection", pro.Proj_active);
                comm.ExecuteNonQuery();
                connection.Close();
            }

            //selectedItems = new ListBox.SelectedObjectCollection(project_list);
            string project = Convert.ToString(selectedItems);

            if (selectedItems != null)
            {
                string[] projectdiv = project.Split(',');
                // subj = SubjectDA.Loadsub(projectdiv[0]);
                //   AddSubject(subj);


                try
                {
                    //fill listbox while loading
                    MySqlConnection connection = new MySqlConnection(connec);
                    connection.Open();
                    string query1 = @"SELECT 
                                    subject_id, 
                                    subject_name, 
                                    Project_project_id 
                                 FROM internal_communication_4.subjects AS s1 
                                    JOIN internal_communication_4.projects AS p1 
                                    ON s1.Project_project_id = p1.project_id 
                                 WHERE (project_selection = 1)";

                    table.Clear();
                    row = 0;
                    MySqlDataAdapter adapt = new MySqlDataAdapter(query1, connection);
                    adapt.Fill(table);

                    while (row < table.Rows.Count)
                    {
                        Subject_class su = new Subject_class();
                        su.Subject_id = Convert.ToInt32(table.Rows[row]["subject_id"]);
                        su.Subject    = (string)table.Rows[row]["subject_name"];
                        subject_listbx.Items.Add(su.Showsubject());
                        row += 1;
                    }

                    connection.Close();

                    selectedItems = null;
                    row           = 0;
                }
                catch
                {
                    MessageBox.Show("error, please repeat the process");
                }
            }
            else
            {
                MessageBox.Show("Please select a project");
            }
        }