Exemplo n.º 1
0
        public static VendedoresDTO Create(VendedoresDTO vendedores)
        {
            int rowsAffected = 0;

            using (SqlConnection conn = new SqlConnection(DAOHelper.connectionString))
            {
                if (conn.State != ConnectionState.Open)
                {
                    conn.Open();
                }

                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection  = conn;
                    cmd.CommandText = @"INSERT INTO Vendedores (Id, Nombre, Apellido, Legajo, Turno) 
                                        VALUES ([id],'[nombre]','[apellido]','[legajo]','[turno]')";

                    int proximoId = DAOHelper.GetNextId("Vendedores");
                    vendedores.Id = proximoId;

                    //Reemplazo los valores de los campos en el query.
                    cmd.CommandText = cmd.CommandText.Replace("[id]", proximoId.ToString());
                    cmd.CommandText = cmd.CommandText.Replace("[nombre]", vendedores.Nombre);
                    cmd.CommandText = cmd.CommandText.Replace("[apellido]", vendedores.Apellido);
                    cmd.CommandText = cmd.CommandText.Replace("[legajo]", vendedores.Legajo);
                    cmd.CommandText = cmd.CommandText.Replace("[turno]", vendedores.Turno);

                    //Ejecuto el update.
                    rowsAffected = cmd.ExecuteNonQuery();
                }
            }

            return(vendedores);
        }
Exemplo n.º 2
0
        public static VentasCabeceraDTO Create(VentasCabeceraDTO venta)
        {
            int rowsAffected = 0;

            using (SqlConnection conn = new SqlConnection(DAOHelper.connectionString))
            {
                if (conn.State != ConnectionState.Open)
                {
                    conn.Open();
                }

                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection  = conn;
                    cmd.CommandText = @"INSERT INTO VentasCabecera (Id, IdCliente, IdVendedor, Fecha, Observaciones) 
                                        VALUES ([id],'[idcliente]','[idvendedor]',[fecha],[observaciones])";

                    int proximoId = DAOHelper.GetNextId("VentasCabecera");
                    venta.Id = proximoId;

                    //Reemplazo los valores de los campos en el query.
                    cmd.CommandText = cmd.CommandText.Replace("[id]", venta.Id.ToString());
                    cmd.CommandText = cmd.CommandText.Replace("[idcliente]", venta.IdCliente.ToString());
                    cmd.CommandText = cmd.CommandText.Replace("[idvendedor]", venta.IdVendedor.ToString());
                    cmd.CommandText = cmd.CommandText.Replace("[fecha]", venta.Fecha.ToString("yyyy-mm-dd"));
                    cmd.CommandText = cmd.CommandText.Replace("[observaciones]", venta.Observaciones);

                    //Ejecuto el update.
                    rowsAffected = cmd.ExecuteNonQuery();
                }
            }

            return(venta);
        }
Exemplo n.º 3
0
        public static VentasDetalleDTO AgregarDetalle(int idcabecera, int idarticulo, string precioventa)
        {
            using (SqlConnection con = new SqlConnection(DAOHelper.connectionString))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    if (con.State != ConnectionState.Open)
                    {
                        con.Open();
                    }

                    cmd.Connection  = con;
                    cmd.CommandText = "INSERT INTO VentasDetalle (Id, IdVentaCabecera, IdArticulo, PrecioUnitario, Cantidad) VALUES ([id], '[idventacabecera]', '[idarticulo]', '[precio]', 1)";

                    int id = DAOHelper.GetNextId("VentasDetalle");
                    cmd.CommandText = cmd.CommandText.Replace("[id]", id.ToString());
                    cmd.CommandText = cmd.CommandText.Replace("[idventacabecera]", idcabecera.ToString());
                    cmd.CommandText = cmd.CommandText.Replace("[idarticulo]", idarticulo.ToString());
                    cmd.CommandText = cmd.CommandText.Replace("[precio]", precioventa.ToString());

                    cmd.ExecuteNonQuery();

                    VentasDetalleDTO aux = new VentasDetalleDTO();

                    return(aux);
                }
            }
        }
Exemplo n.º 4
0
        public static ArticuloDTO Create(ArticuloDTO articulo)
        {
            int rowsAffected = 0;

            using (SqlConnection conn = new SqlConnection(DAOHelper.connectionString))
            {
                if (conn.State != ConnectionState.Open)
                {
                    conn.Open();
                }

                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection  = conn;
                    cmd.CommandText = @"INSERT INTO Articulos (Id, Nombre, Descripcion, PrecioVenta, PrecioCompra, Stock) 
                                        VALUES ([id],'[nombre]','[descripcion]',[precioVenta],[precioCompra],[stock])";

                    int proximoId = DAOHelper.GetNextId("Articulos");
                    articulo.Id = proximoId;

                    //Reemplazo los valores de los campos en el query.
                    cmd.CommandText = cmd.CommandText.Replace("[id]", proximoId.ToString());
                    cmd.CommandText = cmd.CommandText.Replace("[nombre]", articulo.Nombre);
                    cmd.CommandText = cmd.CommandText.Replace("[descripcion]", articulo.Descripcion);
                    cmd.CommandText = cmd.CommandText.Replace("[precioVenta]", articulo.PrecioVenta.ToString());
                    cmd.CommandText = cmd.CommandText.Replace("[precioCompra]", articulo.PrecioCompra.ToString());
                    cmd.CommandText = cmd.CommandText.Replace("[stock]", articulo.Stock.ToString());

                    //Ejecuto el update.
                    rowsAffected = cmd.ExecuteNonQuery();
                }
            }

            return(articulo);
        }
Exemplo n.º 5
0
        public static VentasDetalleDTO Create(VentasDetalleDTO venta)
        {
            int rowsAffected = 0;

            using (SqlConnection conn = new SqlConnection(DAOHelper.connectionString))
            {
                if (conn.State != ConnectionState.Open)
                {
                    conn.Open();
                }

                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection  = conn;
                    cmd.CommandText = @"INSERT INTO VentasDetalle (Id, IdArticulo, IdVentaCabecera, PrecioUnitario, Cantidad) 
                                        VALUES ([id],'[idarticulo]','[idventacabecera]',[preciounitario],[cantidad])";

                    int proximoId = DAOHelper.GetNextId("VentasDetalle");
                    venta.Id = proximoId;

                    //Reemplazo los valores de los campos en el query.
                    cmd.CommandText = cmd.CommandText.Replace("[id]", proximoId.ToString());
                    cmd.CommandText = cmd.CommandText.Replace("[idarticulo]", venta.IdArticulo.ToString());
                    cmd.CommandText = cmd.CommandText.Replace("[idventacabecera]", venta.IdVentaCabecera.ToString());
                    cmd.CommandText = cmd.CommandText.Replace("[preciounitario]", venta.PrecioUnitario.ToString(System.Globalization.CultureInfo.InvariantCulture));       //El "InvariantCulture" es para que el ToString() ponga los decimales con '.' en lugar de ','.
                    cmd.CommandText = cmd.CommandText.Replace("[cantidad]", venta.Cantidad.ToString());

                    //Ejecuto el update.
                    rowsAffected = cmd.ExecuteNonQuery();
                }
            }

            return(venta);
        }
Exemplo n.º 6
0
        public static ClienteDTO NewAccount(string nombre, string direccion, string telefono, string email, string usuario, string contraseña)
        {
            using (SqlConnection con = new SqlConnection(DAOHelper.connectionString))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    if (con.State != ConnectionState.Open)
                    {
                        con.Open();
                    }

                    cmd.Connection  = con;
                    cmd.CommandText = "INSERT INTO Clientes (Id, Nombre, Direccion, Telefono, Email, Usuario, Contraseña) VALUES ([id], '[nombre]', '[direccion]', '[telefono]', '[email]', '[usuario]', '[contraseña]')";

                    int id = DAOHelper.GetNextId("Clientes");
                    cmd.CommandText = cmd.CommandText.Replace("[id]", id.ToString());
                    cmd.CommandText = cmd.CommandText.Replace("[nombre]", nombre.ToString());
                    cmd.CommandText = cmd.CommandText.Replace("[direccion]", direccion.ToString());
                    cmd.CommandText = cmd.CommandText.Replace("[telefono]", telefono.ToString());
                    cmd.CommandText = cmd.CommandText.Replace("[email]", email.ToString());
                    cmd.CommandText = cmd.CommandText.Replace("[usuario]", usuario.ToString());
                    cmd.CommandText = cmd.CommandText.Replace("[contraseña]", contraseña.ToString());

                    cmd.ExecuteNonQuery();

                    ClienteDTO aux = new ClienteDTO();

                    return(aux);
                }
            }
        }
Exemplo n.º 7
0
        public static ClientesDTO Create(ClientesDTO clientes)
        {
            int rowsAffected = 0;

            using (SqlConnection conn = new SqlConnection(DAOHelper.connectionString))
            {
                if (conn.State != ConnectionState.Open)
                {
                    conn.Open();
                }

                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection  = conn;
                    cmd.CommandText = @"INSERT INTO Clientes (Id, Nombre, Direccion, Telefono, Email) 
                                        VALUES ([id],'[nombre]','[direccion]','[telefono]','[email]')";

                    int proximoId = DAOHelper.GetNextId("Clientes");
                    clientes.Id = proximoId;

                    //Reemplazo los valores de los campos en el query.
                    cmd.CommandText = cmd.CommandText.Replace("[id]", proximoId.ToString());
                    cmd.CommandText = cmd.CommandText.Replace("[nombre]", clientes.Nombre).ToString();
                    cmd.CommandText = cmd.CommandText.Replace("[direccion]", clientes.Direccion).ToString();
                    cmd.CommandText = cmd.CommandText.Replace("[telefono]", clientes.Telefono).ToString();
                    cmd.CommandText = cmd.CommandText.Replace("[email]", clientes.Email).ToString();

                    //Ejecuto el update.
                    rowsAffected = cmd.ExecuteNonQuery();
                }
            }

            return(clientes);
        }
Exemplo n.º 8
0
        public static VentasCabeceraDTO AgregarCabecera(int idCliente, string fecha)
        {
            using (SqlConnection con = new SqlConnection(DAOHelper.connectionString))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    if (con.State != ConnectionState.Open)
                    {
                        con.Open();
                    }

                    cmd.Connection  = con;
                    cmd.CommandText = "INSERT INTO VentasCabecera (Id, Fecha, IdCliente, IdVendedor, Observaciones) VALUES ([id], '[fecha]', '[idcliente]', 1, 'Entrega en casa.')";

                    int id = DAOHelper.GetNextId("VentasCabecera");
                    cmd.CommandText = cmd.CommandText.Replace("[id]", id.ToString());
                    cmd.CommandText = cmd.CommandText.Replace("[fecha]", fecha.ToString());
                    cmd.CommandText = cmd.CommandText.Replace("[idcliente]", idCliente.ToString());

                    cmd.ExecuteNonQuery();

                    VentasCabeceraDTO aux = new VentasCabeceraDTO();
                    aux.Id = id;

                    return(aux);
                }
            }
        }
Exemplo n.º 9
0
        public static void Create(List <ArticuloDTO> articulos)
        {
            int idventascabecera = (DAOHelper.GetNextId("VentasCabecera") - 1);


            using (SqlConnection con = new SqlConnection(DAOHelper.connectionString))
            {
                if (con.State != ConnectionState.Open)
                {
                    con.Open();
                }

                foreach (var dto in articulos)
                {
                    int    id = (DAOHelper.GetNextId("VentasDetalle"));
                    string sqlNuevaVentaDetalle = "insert into VentasDetalle (id, idventacabecera,idarticulo,preciounitario,cantidad) values(" + id + " ," + idventascabecera + " ," + dto.Id + " ," + dto.PrecioVenta.ToString(System.Globalization.CultureInfo.InvariantCulture) + "," + 1 + ")";

                    using (SqlCommand cmd = new SqlCommand(sqlNuevaVentaDetalle, con))
                    {
                        cmd.ExecuteNonQuery();
                        con.Close();
                    }
                }
            }
        }
Exemplo n.º 10
0
        public static void Create(int idclientes)
        {
            int           id = DAOHelper.GetNextId("VentasCabecera");
            string        sqlNuevaVentaCabecera = "insert into VentasCabecera values(" + id + " ,'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "' ," + idclientes + ", " + "1" + " ,'ninguna')";
            SqlConnection con = new SqlConnection();

            con.ConnectionString = DAOHelper.connectionString;
            con.Open();
            SqlCommand cmd = new SqlCommand(sqlNuevaVentaCabecera, con);

            cmd.ExecuteNonQuery();
            con.Close();
        }
Exemplo n.º 11
0
        public void Create(ClienteDTO cliente)
        {
            int    id = DAOHelper.GetNextId("Clientes");
            string sqlNuevoUsuario = "insert into Clientes values(" + id + " ,'" + cliente.Nombre + "' ," + " '" + cliente.Direccion + "' " + " ,'" + cliente.Telefono + "' " + " ,'" + cliente.Email + "' ," + " '" + cliente.Usuario + "' ," + " '" + cliente.Contraseña + "' " + ")";

            SqlConnection con = new SqlConnection();

            con.ConnectionString = DAOHelper.connectionString;
            con.Open();
            SqlCommand cmd = new SqlCommand(sqlNuevoUsuario, con);

            cmd.ExecuteNonQuery();
            con.Close();
        }