Example #1
0
 private void buttonGuardar_Click(object sender, EventArgs e)
 {
     if (superValidator.Validate())
     {
         if (cliente == null)
             cliente = new Cliente();
         String nombre = this.textBoxNombre.Text;
         String area = this.textBoxArea.Text;
         if (textBoxId.Text != null ? textBoxId.Text.Length > 0 : false)
         {
             cliente.Id = Convert.ToInt32(textBoxId.Text);
         }
         cliente.Nombre = nombre;
         cliente.Area = area;
         cliente.IsDocente = false;
         this.DialogResult = System.Windows.Forms.DialogResult.OK;
         this.Dispose();
     }
 }
 void showFormCliente(Cliente cliente)
 {
     FormCliente formCliente = new FormCliente();
     if (cliente != null)
     {
         formCliente.Cliente = cliente;
     }
     DialogResult result = formCliente.ShowDialog();
     if (result.Equals(DialogResult.OK))
     {
         cliente = formCliente.Cliente;
         if (cliente != null)
         {
             bool saved = false;
             if (cliente.Id > 0)
             {
                 saved = conexion.actualizarCliente(cliente);
             }
             else
             {
                 saved = conexion.insertCliente(ref cliente);
             }
             if (saved)
             {
                 loadClientes();
                 int index = clientes.FindIndex(element => element.Id == cliente.Id);
                 if (index >= 0 && index < clientes.Count)
                 {
                     comboBoxCliente.SelectedIndex = index;
                 }
             }
         }
     }
     superValidator.Validate();
 }
 void loadClientes()
 {
     Cliente empty = new Cliente();
     clientes = new List<Cliente>();
     clientes.Add(empty);
     List<Cliente> clientesT = conexion.getClientes();
     if (clientesT != null)
     {
         clientes.AddRange(clientesT);
     }
     comboBoxCliente.DataSource = clientes;
     comboBoxCliente.DisplayMember = "NombreCompleto";
 }
 private void buttonX1_Click(object sender, EventArgs e)
 {
     Cliente cliente = new Cliente();
     cliente.Nombre = comboBoxCliente.Text;
     showFormCliente(cliente);
 }
 private void buttonEdit_Click(object sender, EventArgs e)
 {
     Cliente cliente = (Cliente)comboBoxCliente.SelectedItem;
     if (cliente == null)
     {
         cliente = new Cliente();
         cliente.Nombre = comboBoxCliente.Text;
     }
     showFormCliente(cliente);
 }
Example #6
0
        public Boolean actualizarCliente(Cliente cliente)
        {
            bool updated = false;
            if (!cliente.IsDocente)
            {
                this.connection.Open();
                this.command = this.connection.CreateCommand();
                this.transaction = this.connection.BeginTransaction();
                this.command.Connection = this.connection;
                this.command.Transaction = this.transaction;

                try
                {
                    this.command.CommandText = "Update cliente set nombre=@nombre,area=@area where id_cliente=@id;";
                    this.command.Parameters.Add(new SqlParameter("@nombre", SqlDbType.NVarChar, 50));
                    this.command.Parameters.Add(new SqlParameter("@id", SqlDbType.Int));
                    this.command.Parameters.Add(new SqlParameter("@area", SqlDbType.NVarChar, 50));
                    this.command.Parameters["@nombre"].Value = cliente.Nombre;
                    this.command.Parameters["@area"].Value = cliente.Area;
                    this.command.Parameters["@id"].Value = cliente.Id;
                    this.command.ExecuteNonQuery();
                    this.transaction.Commit();
                    updated = true;
                }
                catch (Exception e)
                {
                    try
                    {
                        this.transaction.Rollback();
                        //throw new Exception("Error al Actualizar." + e.Message);
                    }
                    catch (Exception ex)
                    {
                        //throw new Exception("Error al rollback accion." + ex.Message);
                    }
                }
                finally
                {
                    this.connection.Close();
                }
            }
            return updated;
        }
Example #7
0
        public Boolean insertCliente(ref Cliente cliente)
        {
            bool inserted = false;
            if (!cliente.IsDocente)
            {
                this.connection.Open();
                this.command = this.connection.CreateCommand();
                this.transaction = this.connection.BeginTransaction();
                this.command.Connection = this.connection;
                this.command.Transaction = this.transaction;

                try
                {
                    this.command.CommandText = "insert into cliente(nombre,area) values(@nombre,@area);" + "SELECT CAST(scope_identity() AS int)";
                    this.command.Parameters.Add(new SqlParameter("@nombre", SqlDbType.NVarChar, 50));
                    this.command.Parameters.Add(new SqlParameter("@area", SqlDbType.NVarChar, 50));

                    this.command.Parameters["@nombre"].Value = cliente.Nombre;
                    this.command.Parameters["@area"].Value = cliente.Area;
                    this.lastUpdated = this.command.ExecuteScalar().ToString();
                    cliente.Id = Convert.ToInt32(lastUpdated);
                    this.transaction.Commit();
                    inserted = true;
                }
                catch (Exception e)
                {
                    try
                    {
                        transaction.Rollback();
                        //throw new Exception("Error al insertar registro. " + e.Message);
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("Error al roolback accion. " + ex.Message);
                    }
                }
                finally
                {
                    this.connection.Close();
                }
            }
            return inserted;
        }
Example #8
0
 /*--------------------Catalogo de Clientes-------------------------*/
 public List<Cliente> getClientes()
 {
     SqlDataReader dataReader = null;
     List<Cliente> clientes = new List<Cliente>();
     try
     {
         string query = "Select * from cliente";
         command = new SqlCommand(query, connection);
         command.Connection.Open();
         dataReader = command.ExecuteReader();
         while (dataReader.Read())
         {
             int id = Convert.ToInt32(dataReader["id_cliente"].ToString());
             String nombre = dataReader["nombre"].ToString();
             String area = dataReader["area"].ToString();
             Cliente cliente = new Cliente();
             cliente.Id = id;
             cliente.Nombre = nombre;
             cliente.Area = area;
             cliente.IsDocente = false;
             clientes.Add(cliente);
         }
         dataReader.Close();
         /*query = "Select * from docente";
         command = new SqlCommand(query, connection);
         dataReader = command.ExecuteReader();
         while (dataReader.Read())
         {
             int id = Convert.ToInt32(dataReader["id_docente"].ToString());
             String nombre = dataReader["nombre"].ToString();
             String area = "Academica";
             Cliente cliente = new Cliente();
             cliente.Id = id;
             cliente.Nombre = nombre;
             cliente.Area = area;
             cliente.IsDocente = true;
             clientes.Add(cliente);
         }*/
         return clientes;
     }
     catch (Exception e)
     {
         return null;
         //throw new Exception("Error al obtener datos de Usuario. " + e.Message.ToString());
     }
     finally
     {
         command.Connection.Close();
     }
 }
Example #9
0
        public List<AsignacionVarios> getAsignacionesVarios(String filtro)
        {
            SqlDataReader dataReader = null;
            List<AsignacionVarios> AsignacionesVarios = new List<AsignacionVarios>();
            try
            {

                string query = "Select * from Vista_AsignacionVarios WHERE " + filtro;
                command = new SqlCommand(query, connection);
                command.Connection.Open();
                dataReader = command.ExecuteReader();
                while (dataReader.Read())
                {
                    AsignacionVarios asig = new AsignacionVarios();
                    asig.ID = Convert.ToInt32(dataReader["id_asignacion"].ToString());
                    asig.Aula = new Aula();
                    asig.Aula.Id = Convert.ToInt32(dataReader["id_aula"].ToString());
                    asig.Aula.IdTipo = Convert.ToInt32(dataReader["aula_id_tipo"].ToString());
                    asig.Aula.Nombre = dataReader["aula_descripcion"].ToString();
                    asig.Aula.Capacidad = Convert.ToInt32(dataReader["aula_capacidad"].ToString());
                    asig.Aula.IdEdificio = Convert.ToInt32(dataReader["edificioId"].ToString());
                    asig.Aula.NombreEdificio = dataReader["edificioDescripcion"].ToString();
                    asig.Aula.Piso = Convert.ToInt32(dataReader["aulaPiso"].ToString());
                    asig.Aula.IdEstado = Convert.ToInt32(dataReader["estadoId"].ToString());
                    asig.Aula.NombreEstado = dataReader["estadoDescripcion"].ToString();
                    asig.Aula.Referencia = dataReader["aulaReferencia"].ToString();
                    asig.Inicio = Convert.ToDateTime(dataReader["inicio"].ToString());
                    asig.Fin = Convert.ToDateTime(dataReader["fin"].ToString());
                    asig.TipoUso = new AulaTipoUso();
                    asig.TipoUso.Id = Convert.ToInt32(dataReader["tipoUsoId"].ToString());
                    asig.TipoUso.Descripcion = dataReader["tipoUsoDescripcion"].ToString();
                    asig.Observaciones = dataReader["observaciones"].ToString();
                    Serie serie = null;
                    String s = dataReader["serie"].ToString();
                    if (s != null)
                    {
                        if (s.Length > 0 && s != "0")
                        {
                            serie = new Serie();
                            serie.ID = Convert.ToInt32(s);
                            serie.Descripcion = dataReader["serieDescripcion"].ToString();
                        }
                    }
                    asig.Serie = serie;
                    String id_cliente = dataReader["id_cliente"].ToString();
                    if (id_cliente != null ? id_cliente.Length>0:false)
                    {
                        Cliente cliente = new Cliente();
                        cliente.Id = Convert.ToInt32(id_cliente);
                        cliente.Nombre = dataReader["nombre_cliente"].ToString();
                        cliente.Area = dataReader["area_cliente"].ToString();
                        asig.Cliente = cliente;
                    }
                    AsignacionesVarios.Add(asig);
                }
                return AsignacionesVarios;
            }
            catch (Exception e)
            {
                throw new Exception("Error al obtener datos de AulaEstado. " + e.Message.ToString());
            }
            finally
            {
                command.Connection.Close();
            }
        }
Example #10
0
        public Boolean borrarCliente(Cliente cliente)
        {
            bool deleted = false;
            if (!cliente.IsDocente)
            {
                this.connection.Open();
                this.command = this.connection.CreateCommand();
                this.transaction = this.connection.BeginTransaction();

                this.command.Connection = this.connection;
                this.command.Transaction = this.transaction;

                try
                {
                    this.command.CommandText = "delete from cliente where id_cliente=@id;";
                    this.command.Parameters.Add(new SqlParameter("@id", SqlDbType.Int));
                    this.command.Parameters["@id"].Value = cliente.Id;
                    this.command.ExecuteNonQuery();
                    this.transaction.Commit();
                    deleted = true;
                }
                catch (Exception e)
                {
                    try
                    {
                        this.transaction.Rollback();
                        //throw new Exception("Error al borrar registro. " + e.Message);

                    }
                    catch (Exception ex)
                    {
                        //throw new Exception("Error al rollback acción. " + ex.Message);
                    }
                }
                finally
                {
                    this.connection.Close();
                }
            }
            return deleted;
        }