Exemplo n.º 1
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="reqData">The data we're storing</param>
        /// <param name="reqItem">The item in the list that it is</param>
        /// <param name="sID">The id (for updating on server)</param>
        public objectTask(string[] reqData, MaterialListViewItem reqItem, int sID)
        {
            data = reqData;
            lvItem = reqItem;
            id = sID;

            lvItem.highlightColor = Color.FromArgb(197, 225, 165);
            int result = 0;
            if (Int32.TryParse(data[1], out result))
            {
                stepLerp(result, 0, 0);
            }
        }
Exemplo n.º 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();
        }