// BOTON GUARDAR CLICK //ALTA CLIENTE
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            if (ModoForm == TipoForm.Modificacion)
            {
                Entidades.Cliente cli = new Entidades.Cliente();

                cli.DniCuil  = txtDniCuil.Text;
                cli.Nombre   = txtNombre.Text;
                cli.Apellido = txtApellido.Text;
                cli.Email    = txtEmail.Text;
                cli.Tel1     = txtTel1.Text;
                cli.Tel2     = txtTel2.Text;

                Datos_ClienteAdapter.Actualizar(cli, dniActual);
            }
            else if (ModoForm == TipoForm.Alta)
            {
                // Genero una nueva instancia de la entidad
                Entidades.Cliente cli = new Entidades.Cliente();

                // Valido Datos
                if (Validar())
                {
                    try
                    {
                        // TXT to nuevoCliente

                        cli.DniCuil  = txtDniCuil.Text;
                        cli.Nombre   = txtNombre.Text;
                        cli.Apellido = txtApellido.Text;
                        cli.Email    = txtEmail.Text;
                        cli.Tel1     = txtTel1.Text;
                        cli.Tel2     = txtTel2.Text;


                        // nuevoCliente to Base de Datos (capa de datos)
                        Datos_ClienteAdapter.AñadirNuevo(cli);
                    }
                    catch (Exception ex)
                    {
                        // Muestro cualquier error de la aplicacion
                        MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    finally
                    {
                        // Libero objetos
                        cli = null;
                    }
                }
            }
            this.Close();
        }
Exemple #2
0
        // *****************************************************************


        private void ImportarClientes()
        {
            OpenFileDialog OpenFileDialog = new OpenFileDialog();


            if (OpenFileDialog.ShowDialog() == DialogResult.OK)
            {
                /*
                 *              //En DataSource especificas la ruta del archivo  @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=""Excel 8.0;HDR=YES;IMEX=1;""", OpenFileDialog.FileName);
                 *          string CadenaConexion = String.Format(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=""Excel 8.0;HDR=YES;IMEX=1;""", OpenFileDialog.FileName); //@"Provider=Microsoft.Jet.OLEDB.4.0;" + @"Data Source=C:\Clientes2.xls;" + @"Extended Properties=" + '"' + "Excel 8.0;HDR=YES" + '"';
                 *
                 *
                 *  OleDbConnection con= new OleDbConnection(CadenaConexion);
                 *
                 *  //Usuario y dirección son columnas en la hoja de excel
                 *  string strSQL="SELECT dni, nombre, apellido, email FROM [hoja1$]";
                 *
                 *  OleDbDataAdapter da=new OleDbDataAdapter(strSQL,con);
                 *
                 *  DataSet ds=new DataSet();
                 *
                 *  da.Fill(ds);
                 *
                 *
                 *
                 *              for(int i = 0; i< ds.Tables[0].Rows.Count; i++)
                 *              {
                 *                      Entidades.Cliente clienteDeExcel = new Entidades.Cliente();
                 *                      clienteDeExcel.DniCuil = ds.Tables[0].Rows[i].Field<Double>(0).ToString();
                 *                  clienteDeExcel.Nombre = ds.Tables[0].Rows[i].Field<String>(1);
                 *                  clienteDeExcel.Apellido = ds.Tables[0].Rows[i].Field<String>(2);
                 *                  clienteDeExcel.Email = ds.Tables[0].Rows[i].Field<String>(3);
                 *
                 *                  Datos_ClienteAdapter.AñadirNuevo(clienteDeExcel);
                 *              }
                 *
                 */



                string connectionString = String.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=""Excel 8.0;HDR=YES;IMEX=1;""", OpenFileDialog.FileName);
                string sqlExcel         = String.Format("select * from [{0}$]", "Hoja1");

                DataSet ExDataSet = new DataSet();
                //
                OleDbConnection  ExConexion    = new OleDbConnection(connectionString);
                OleDbCommand     OleDbCommand  = new OleDbCommand(sqlExcel, ExConexion);
                OleDbDataAdapter ExDataAdapter = new OleDbDataAdapter(OleDbCommand);
                //
                ExDataAdapter.Fill(ExDataSet);

                Entidades.Cliente clienteDeExcel = new Entidades.Cliente();

                for (int i = 0; i < ExDataSet.Tables[0].Rows.Count; i++)
                {
                    clienteDeExcel.DniCuil  = ExDataSet.Tables[0].Rows[i].Field <String>(0).ToString();
                    clienteDeExcel.Nombre   = ExDataSet.Tables[0].Rows[i].Field <String>(1);
                    clienteDeExcel.Apellido = ExDataSet.Tables[0].Rows[i].Field <String>(2);
                    clienteDeExcel.Email    = ExDataSet.Tables[0].Rows[i].Field <String>(3);
                    clienteDeExcel.Tel1     = ExDataSet.Tables[0].Rows[i].Field <Double>(4).ToString();
                    clienteDeExcel.Tel2     = ExDataSet.Tables[0].Rows[i].Field <Double>(5).ToString();

                    Datos_ClienteAdapter.AñadirNuevo(clienteDeExcel);
                }
            }
            ActualizarListado();
        }