private void button3_Click(object sender, EventArgs e)
        {
            this.Hide();
            RoomList f1 = new RoomList();

            f1.ShowDialog();
        }
Beispiel #2
0
        //if we click delete button then the room will be deleted from the list and .cvs file.
        //and shows the home screen.
        private void button3_Click(object sender, EventArgs e)
        {
            string roomName = this.Text.ToString();

            // Deleting the content
            try
            {
                foreach (Node n in rlist)
                {
                    if (roomName.Equals(n.roomName.ToString()))
                    {
                        rlist.Remove(n);
                        break;
                    }
                }
                var file = @"C:\Users\anusha\Documents\Visual Studio 2013\Projects\sesprint1\sesprint1\rooms.csv";


                List <string> roomname = new List <string>();
                List <double> temp     = new List <double>();
                List <double> water    = new List <double>();
                List <double> humidity = new List <double>();
                List <double> plantbed = new List <double>();
                List <double> soil     = new List <double>();
                List <double> fert     = new List <double>();
                List <double> lig      = new List <double>();
                List <double> cot      = new List <double>();
                foreach (Node s in rlist)
                {
                    //var rm = new Node();

                    roomname.Add(s.roomName);
                    temp.Add(s.temperature);
                    water.Add(s.Water);
                    humidity.Add(s.Humidity);
                    plantbed.Add(s.PlantBed);
                    soil.Add(s.SoilAcidity);

                    fert.Add(s.Fertilizer);
                    lig.Add(s.Lighting);
                    cot.Add(s.cost);
                }
                var writer = new StringBuilder();
                for (int i = 0; i < rlist.Count(); i++)
                {
                    var newLine = string.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9}", roomname.ElementAt(i).ToString(), temp.ElementAt(i).ToString(), water.ElementAt(i).ToString(), humidity.ElementAt(i).ToString(), plantbed.ElementAt(i).ToString(), soil.ElementAt(i).ToString(), fert.ElementAt(i).ToString(), lig.ElementAt(i).ToString(), cot.ElementAt(i).ToString(), Environment.NewLine);
                    writer.Append(newLine);
                }
                File.WriteAllText(file, writer.ToString());
            }
            catch (Exception)
            { }
            this.Hide();
            RoomList f1 = new RoomList(roomName);
            // f1.Show();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            count++;
            var file = @"C:\Users\anusha\Documents\Visual Studio 2013\Projects\sesprint1\sesprint1\count.csv";

            List <string> example = new List <string>();

            example.Add(count.ToString());

            File.WriteAllLines(file, example);
            Boolean errorFlag = false;
            var     rm        = new Node();

            try
            {
                rm.roomName       = textBox1.Text;
                rm.O_Vtemperature = Double.Parse(textBox2.Text);
                rm.O_VWater       = Double.Parse(textBox3.Text);
                rm.O_VHumidity    = Double.Parse(textBox4.Text);
                rm.O_VSoilAcidity = Double.Parse(textBox5.Text);
                rm.O_VPlantBed    = Double.Parse(textBox6.Text);
                rm.O_VFertilizer  = Double.Parse(textBox7.Text);
                rm.O_VLighting    = Double.Parse(textBox8.Text);
                if (rm.roomName == "")
                {
                    rm.roomName = "room" + count;
                }
            }
            catch (FormatException)
            {
                MessageBox.Show("Please enter double datatype values");
                errorFlag = true;
            }
            catch (NullReferenceException)
            {
                //   textBox1.Text = "";
                textBox2.Text = "";
                textBox3.Text = "";
                textBox4.Text = "";
                textBox5.Text = "";
                textBox6.Text = "";
                textBox7.Text = "";
                textBox8.Text = "";
            }
            if (errorFlag == false)
            {
                MessageBox.Show("Room added successfully");
                this.Hide();

                RoomList f1 = new RoomList();
                Room     f2 = new Room(rm);
                f1.createnode(rm.roomName);
                f1.Show();
            }
        }