Example #1
0
 private void button1_Click(object sender, EventArgs e)
 {
     //Проверить заполнение эементов формы
     if (maskedTextBox1.Text == "" ||
         maskedTextBox2.Text == "" ||
         maskedTextBox3.Text == "" ||
         textBox5.Text == "" ||
         listBox1.SelectedIndex == -1)
     {
         MessageBox.Show(
             "Заполните все элементы формы",
             "Сообщение",
             MessageBoxButtons.OK,
             MessageBoxIcon.Information,
             MessageBoxDefaultButton.Button1,
             MessageBoxOptions.DefaultDesktopOnly);
     }
     else
     {
         int id = 1;
         // выкрутить id для формы
         foreach (Form1.Ivit ivit in Form1._form._newRoot.ivits)
         {
             if (id <= ivit.id)
             {
                 id = ivit.id + 1;
             }
         }
         int roomId = 1;
         foreach (Form1.Room room in Form1._form._newRoot.rooms)
         {
             if (listBox1.Items[listBox1.SelectedIndex].ToString() == room.name)
             {
                 roomId = room.id;
             }
         }
         // заполнить объект и создать
         Form1.Ivit newIvit = new Form1.Ivit();
         newIvit.id       = id;
         newIvit.status   = "";
         newIvit.roomID   = roomId;
         newIvit.ip       = Regex.Replace(maskedTextBox1.Text.Replace(",", "."), "0*([0-9]+)", "${1}");
         newIvit.port     = Convert.ToInt32(maskedTextBox2.Text);
         newIvit.sirialID = Convert.ToInt32(maskedTextBox3.Text);
         newIvit.name     = textBox5.Text;
         newIvit.temp     = "0";
         newIvit.wet      = "0";
         Form1._form._newRoot.ivits.Add(newIvit);
         Form1._form.saveJConfig();
         this.Hide();
     }
 }
Example #2
0
 private void button1_Click(object sender, EventArgs e)
 {
     foreach (DataGridViewRow row in this.dataGridView1.Rows)
     {
         if (row.Cells["ID"].Value != null)
         {
             Form1.Ivit ivit = Form1._form._newRoot.ivits.Where(iv => iv.id == Convert.ToInt32(row.Cells["ID"].Value.ToString())).ToList()[0];
             ivit.name     = row.Cells["Name"].Value.ToString();
             ivit.port     = Convert.ToInt32(row.Cells["Port"].Value.ToString());
             ivit.ip       = row.Cells["IP"].Value.ToString();
             ivit.sirialID = Convert.ToInt32(row.Cells["SerialID"].Value.ToString());
             ivit.tempPK   = Convert.ToInt32(row.Cells["tempPK"].Value.ToString());
             ivit.wetPK    = Convert.ToInt32(row.Cells["wetPK"].Value.ToString());
         }
     }
     Form1._form.saveJConfig();
 }