private void button1_Click(object sender, EventArgs e) { //проверить одинаковые имена комнат bool flRoom = false; foreach (Form1.Room room in Form1._form._newRoot.rooms) { if (textBox2.Text == room.name) { flRoom = true; } } //Проверить заполнение эементов формы if (textBox2.Text == "" || label5.Text == "") { MessageBox.Show( "Заполните все элементы формы", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly); } else if (flRoom == true) { MessageBox.Show( "Такое название помещения уже существует. Измените название!", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly); } else { int id = 1; // выкрутить id для формы foreach (Form1.Room room in Form1._form._newRoot.rooms) { if (id <= room.id) { id = room.id + 1; } } // заполнить объект и создать Form1.Room newRoom = new Form1.Room(); newRoom.name = textBox2.Text; newRoom.id = id; newRoom.fon = label5.Text; Form1._form._newRoot.rooms.Add(newRoom); Form1._form.saveJConfig(); this.Hide(); } }
private void FormLists_Load(object sender, EventArgs e) { DataTable workTable = new DataTable("TableLists"); workTable.Columns.Add("ID", typeof(Int32)); workTable.Columns.Add("NameRoom", typeof(String)); workTable.Columns.Add("Name", typeof(String)); workTable.Columns.Add("Port", typeof(String)); workTable.Columns.Add("IP", typeof(String)); workTable.Columns.Add("SerialID", typeof(String)); workTable.Columns.Add("tempPK", typeof(Int32)); workTable.Columns.Add("wetPK", typeof(Int32)); DataRow workRow; foreach (Form1.Ivit ivit in Form1._form._newRoot.ivits) { workRow = workTable.NewRow(); Form1.Room room = Form1._form._newRoot.rooms.Where(ro => ro.id == ivit.roomID).ToList()[0]; workRow[0] = ivit.id; workRow[1] = room.name; workRow[2] = ivit.name; workRow[3] = ivit.port; workRow[4] = ivit.ip; workRow[5] = ivit.sirialID; workRow[6] = ivit.tempPK; workRow[7] = ivit.wetPK; workTable.Rows.Add(workRow); } this.dataGridView1.DataSource = workTable; this.dataGridView1.Columns["ID"].Width = 40; this.dataGridView1.Columns["ID"].ReadOnly = true; this.dataGridView1.Columns["NameRoom"].Width = 150; this.dataGridView1.Columns["NameRoom"].ReadOnly = true; this.dataGridView1.Columns["Name"].Width = 350; this.dataGridView1.Columns["Name"].ReadOnly = false; this.dataGridView1.Columns["Port"].Width = 60; this.dataGridView1.Columns["Port"].ReadOnly = false; this.dataGridView1.Columns["IP"].Width = 150; this.dataGridView1.Columns["IP"].ReadOnly = false; this.dataGridView1.Columns["SerialID"].Width = 60; this.dataGridView1.Columns["SerialID"].ReadOnly = false; this.dataGridView1.Columns["tempPK"].Width = 60; this.dataGridView1.Columns["tempPK"].ReadOnly = false; this.dataGridView1.Columns["wetPK"].Width = 60; this.dataGridView1.Columns["wetPK"].ReadOnly = false; }