Exemplo n.º 1
0
        private void metroGrid1_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            Guid   Id;
            string Phone = "";
            string Relationship = "";
            int    Priority = 0;
            string Name = "";
            bool   N = false, R = false, P = false, PR = false;

            if (metroGrid_Contactos.Rows[e.RowIndex].Cells[0].Value == null)
            {
                Id = Guid.NewGuid();
                metroGrid_Contactos.Rows[e.RowIndex].Cells[0].Value = Id;
            }
            else
            {
                Id = Guid.Parse(metroGrid_Contactos.Rows[e.RowIndex].Cells[0].Value.ToString());
            }
            if (metroGrid_Contactos.Rows[e.RowIndex].Cells[1].Value != null)
            {
                Name = metroGrid_Contactos.Rows[e.RowIndex].Cells[1].Value.ToString();
                N    = true;
            }
            else
            {
                metroGrid_Contactos.Rows[e.RowIndex].Cells[1].ErrorText = "Escribe un Nombre";
                N = false;
            }
            if (metroGrid_Contactos.Rows[e.RowIndex].Cells[3].Value != null)
            {
                R            = true;
                Relationship = metroGrid_Contactos.Rows[e.RowIndex].Cells[3].Value.ToString();
            }
            else
            {
                R = false;
                metroGrid_Contactos.Rows[e.RowIndex].Cells[3].ErrorText = "Ingresa Relacion con el cliente";
            }
            if (metroGrid_Contactos.Rows[e.RowIndex].Cells[2].Value != null)
            {
                P     = true;
                Phone = metroGrid_Contactos.Rows[e.RowIndex].Cells[2].Value.ToString();
            }
            else
            {
                P = false;
                metroGrid_Contactos.Rows[e.RowIndex].Cells[2].ErrorText = "Escribe un numero de telefono";
            }
            if (metroGrid_Contactos.Rows[e.RowIndex].Cells[4].EditedFormattedValue != null && metroGrid_Contactos.Rows[e.RowIndex].Cells[4].EditedFormattedValue != "")
            {
                PR       = true;
                Priority = int.Parse(metroGrid_Contactos.Rows[e.RowIndex].Cells[4].EditedFormattedValue.ToString());
            }
            else
            {
                PR = false;
                metroGrid_Contactos.Rows[e.RowIndex].Cells[4].ErrorText = "Escribe la prioridad";
            }
            if (N && R && P && PR)
            {
                try {
                    db.InsertClienteContacto(Id, IdCliente, Name, "", Phone, Priority, DateTime.Now, Guid.Parse("8bead89f-b0ca-4ca9-9268-4de6c727e3a2"), true);
                } catch (Exception ex)
                {
                    db.UpdateClienteContactos(Id, IdCliente, Name, "", Phone, Priority, DateTime.Now, Guid.Parse("8bead89f-b0ca-4ca9-9268-4de6c727e3a2"), true);
                }
            }
        }