예제 #1
0
        private void dataGridView_Sensores_RowLeave(object sender, DataGridViewCellEventArgs e)
        {
            Guid   Id;
            string Numero     = "";
            string TipoSensor = "";
            string Ubicacion  = "";

            bool TS = false, U = false, N = false;

            if (this.dataGridView_Sensores.Rows[e.RowIndex].Cells[0].Value == null)
            {
                Id = Guid.NewGuid();
                dataGridView_Sensores.Rows[e.RowIndex].Cells[0].Value = Id;
            }
            else
            {
                Id = Guid.Parse(dataGridView_Sensores.Rows[e.RowIndex].Cells[0].Value.ToString());
            }
            if (dataGridView_Sensores.Rows[e.RowIndex].Cells[1].Value != null)
            {
                Numero = dataGridView_Sensores.Rows[e.RowIndex].Cells[1].Value.ToString();
                N      = true;
            }
            else
            {
                N = false;
                dataGridView_Sensores.Rows[e.RowIndex].Cells[1].ErrorText = "Ingresa numero de sensor";
            }
            if (dataGridView_Sensores.Rows[e.RowIndex].Cells[2].Value != null)
            {
                TipoSensor = dataGridView_Sensores.Rows[e.RowIndex].Cells[2].Value.ToString();
                TS         = true;
            }
            else
            {
                dataGridView_Sensores.Rows[e.RowIndex].Cells[2].ErrorText = "Escribe un tipo de sensor";
                TS = false;
            }
            if (dataGridView_Sensores.Rows[e.RowIndex].Cells[3].Value != null)
            {
                U         = true;
                Ubicacion = dataGridView_Sensores.Rows[e.RowIndex].Cells[3].Value.ToString();
                dataGridView_Sensores.Rows[e.RowIndex].Cells[3].ErrorText = null;
            }
            else
            {
                U = false;
                dataGridView_Sensores.Rows[e.RowIndex].Cells[3].ErrorText = "Ingresa Ubicacion del sensor";
            }
            if (U && TS && N)
            {
                try
                {
                    db.InsertSensores(Id, IdCliente, Numero, TipoSensor, Ubicacion, DateTime.Now, Guid.Parse("8bead89f-b0ca-4ca9-9268-4de6c727e3a2"), true);
                }
                catch (Exception ex)
                {
                    db.UpdateSensores(Id, IdCliente, Numero, TipoSensor, Ubicacion, DateTime.Now, Guid.Parse("8bead89f-b0ca-4ca9-9268-4de6c727e3a2"), true);
                }
            }
        }