Beispiel #1
0
        /*
         * Button1_Click:
         * When a new request is added, the changes are first reflected in the savefile,
         * then the form is updated based on the savefile. There is likely a better way to do this,
         * but it ensures the save file is always up to date.
         */
        private void Button1_Click(object sender, EventArgs e) //As soon as the BrightnessRequest is added, changes are reflected in the file
        {
            running.stopThread();
            FileManager fm = new FileManager(fileLoc, fileNameR);

            String[] rawData         = null;
            double   inputBrightness = 1.0;

            //If the input is not valid
            if (!Time24Hours.isValid24HTime(textBox1.Text, ':') || !Time24Hours.isValid24HTime(textBox2.Text, ':') || !double.TryParse(textBox3.Text, out inputBrightness))
            {
                inputError1();
                return;
            }

            //Convert user input to time values
            Time24Hours startT = Time24Hours.stringTo24HTime(textBox1.Text + ":00", ':');
            Time24Hours endT   = Time24Hours.stringTo24HTime(textBox2.Text + ":00", ':');

            //Assemble request
            BrightnessRequest newReq = BrightnessRequest.fromString(0, startT.toFileString() + ";" + endT.toFileString() + ";" + inputBrightness.ToString());

            if (newReq != null && !newReq.isValid()) //Check if request is valid
            {
                inputError1();
                return;
            }


            foreach (BrightnessRequest BR in requests)
            {
                if (newReq.getStartTime().fallsInbetween(BR.getStartTime(), BR.getEndTime()) || newReq.getEndTime().fallsInbetween(BR.getStartTime(), BR.getEndTime()))
                {
                    inputError2(BR.orderNum);
                    return;
                }
                if (newReq.getStartTime().equals(BR.getStartTime()) || newReq.getEndTime().equals(BR.getEndTime()))
                {
                    inputError2(BR.orderNum);
                    return;
                }
            }
            requests.Add(newReq);       //Add request to list

            fm.saveAllBR(requests);     //Save all requests
            fm.initialize(ref rawData); //Load all requests to string
            loadRequests(rawData);      //Overwrite
            displayEvents();

            textBox1.Clear();
            textBox2.Clear();
            textBox3.Clear();

            running.startThread();
        }
Beispiel #2
0
        private void loadRequests(string[] rawData) //Loads requests from a string array to the BR list
        {
            requests.Clear();
            if (rawData == null)
            {
                return;
            }

            int count = 1;

            foreach (string s in rawData)
            {
                BrightnessRequest temp = BrightnessRequest.fromString(count, s);
                if (temp != null && temp.isValid())
                {
                    requests.Add(temp);
                    count++;
                }
            }
        }