예제 #1
0
        /// <summary>
        /// Loads all the settings from the XML file "settings.xml" which is in the same directory as the executable.
        /// </summary>
        public static void load()
        {
            if (File.Exists("settings.xml"))
            {
                string text = File.ReadAllText("settings.xml");
                XMLChecker checker = new XMLChecker();


                if (checker.checkSafe(text))        //If we're good to go
                {
                    XmlTextReader reader = new XmlTextReader(new StringReader(text));

                    while (reader.Read())       //Parse the settings
                    {
                        if (reader.Name == "notifications")        //Gets the value for notify
                        {
                            bool result;
                            if (Boolean.TryParse(reader.ReadString(), out result))
                            {
                                notify = result;
                            }
                            else      //It isn't a boolean so we just default it, but let the user know
                            {
                                MessageBox.Show("Notification value is non-boolean, defaulted to true.", "Error", MessageBoxButtons.OK);
                                notify = true;
                            }
                        }

                        if (reader.Name == "server")        //Set the server
                        {
                            server = reader.ReadString();
                        }

                    }
                }
                else    //XML was bad, delete the file and try again (so we have a clean file)
                {
                    File.Delete("settings.xml");        
                    Setting.load();
                }

            }
            else   //No settings found, create a default file that is on the localhost for a server
            {
                server = "http://localhost/ticketSystem/webshield.php";
                notify = true;
                Setting.save();         //Create a default settings file
            }
        }
예제 #2
0
        /// <summary>
        /// Populates the list with the current tasks.
        /// <param name="alertNew" when true this highlights new tasks red></param>
        /// </summary>
        void populateList(bool alertNew)
        {
            int c = 0;
            WebClient client = new WebClient();
            string text = " E R R O R ";
            try
            {
                text = client.DownloadString(Setting.server + "?a=getList");
            }
            catch
            {
                MessageBox.Show(contactError, "Error", MessageBoxButtons.OK);
            }

            XMLChecker checker = new XMLChecker();

            if (checker.checkSafe(text))
            {
                XmlTextReader reader = new XmlTextReader(new StringReader(text));        //Contact the database to get a fresh list of tasks

                while (reader.Read())       //Parse the tasks as XML
                {
                    if (reader.Name == "ticket")        //If it's a ticket we...
                    {
                        string[] newData = new string[4];
                        newData[0] = reader["status"];
                        newData[1] = reader["progress"];
                        newData[2] = reader["type"];
                        newData[3] = reader["name"];
                        int id = -1;
                        if (!Int32.TryParse(reader["id"], out id))
                        {
                            MessageBox.Show("Non-integer value found in ticket ID.\nID: " + reader["id"], "Error", MessageBoxButtons.OK);
                            break;
                        }
                        bool existed = false;

                        if (taskDatas.ContainsKey(id))
                        {
                            for (int i = 0; i < 5; i++)
                            {
                                if (i == 4)
                                {
                                    existed = true;
                                    break;
                                }
                                if (taskDatas[id].getData()[i] != newData[i])
                                {
                                    if (!taskDatas[id].flagged)
                                        c++;
                                    break;
                                }

                            }
                        }

                        if (!existed)
                        {
                            MaterialListViewItem newlyMade;
                            if (!taskDatas.ContainsKey(id))
                            {
                                MaterialListViewItem mlvi = new MaterialListViewItem();
                                mlvi.Text = reader["name"];
                                newlyMade = mlvi;
                                tasks.Items.Add(mlvi);

                                objectTask toAdd = new objectTask(newData, newlyMade, id);
                                taskDatas.Add(id, toAdd);        //Add it to the list
                                if (alertNew)
                                {
                                    newlyMade.BackColor = highlightColor;
                                    
                                    toAdd.flagged = true;
                                    c++;
                                }
                            }
                            else
                            {
                                if (!alertNew)
                                    taskDatas[id].updateData(newData);
                                else
                                    taskDatas[id].updateData(newData, highlightColor);
                            }


                        }
                    }

                    if (reader.Name == "error")         //Something failed on the web end.
                    {
                        MessageBox.Show(reader["message"], "Error", MessageBoxButtons.OK);
                    }
                }

                curNotifications += c;
                if (c != 0)
                {
                    System.Media.SoundPlayer player = new System.Media.SoundPlayer();
                    player.SoundLocation = "alert.wav";
                    player.Play();
                    updateNotifications();
                }
            }
            else
            {
                MessageBox.Show("XML parsing error.", "Error", MessageBoxButtons.OK);
            }

            averageProgress();
        }