Skip to content

Commit

Permalink
Read file and create file function
Browse files Browse the repository at this point in the history
  • Loading branch information
adeirjunior committed Sep 18, 2024
1 parent 812075a commit 6690e16
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 10 deletions.
22 changes: 22 additions & 0 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "hmsoft"
version = "0.1.0"
description = "A Tauri App"
description = "Hotel Management Software"
authors = ["you"]
edition = "2021"

Expand All @@ -11,6 +11,7 @@ edition = "2021"
tauri-build = { version = "1", features = [] }

[dependencies]
csv = "1.1"
tauri = { version = "1", features = [ "window-unminimize", "window-hide", "window-maximize", "window-unmaximize", "window-show", "window-minimize", "window-close", "window-start-dragging", "shell-open"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
Expand Down
34 changes: 30 additions & 4 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,41 @@
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]

// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
use std::fs::File;
use std::path::Path;
use std::io::prelude::*;
use csv;

fn check_file(path: &str) -> bool {
Path::new(path).exists()
}

fn create_file(path: &str) -> std::io::Result<()> {
let mut file = File::create(path)?;
file.write_all(b"Name,Age,City\nJohn,30,New York\nJane,25,San Francisco\n")?;
Ok(())
}

#[tauri::command]
fn greet(name: &str) -> String {
format!("Hello, {}! You've been greeted from Rust!", name)
fn read_from_file(path: &str) -> Result<(), String> {

if !check_file(path) {
create_file(path).map_err(|e| e.to_string())?;
println!("File created: {}", path);
}

let mut reader = csv::Reader::from_path(path).map_err(|e| e.to_string())?;

for result in reader.records() {
let record = result.map_err(|e| e.to_string())?;
println!("{:?}", record);
}
Ok(())
}

fn main() {
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![greet])
.invoke_handler(tauri::generate_handler![read_from_file])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
2 changes: 1 addition & 1 deletion src/components/charts/bar-graph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export function BarGraph() {
<Card>
<CardHeader className="flex flex-col items-stretch space-y-0 border-b p-0 sm:flex-row">
<div className="flex flex-1 flex-col justify-center gap-1 px-6 py-5 sm:py-6">
<CardTitle>Grafico de barras - Interativo</CardTitle>
<CardTitle>Grafico de Barras - Interativo</CardTitle>
<CardDescription>
Mostrando o total de visitantes dos ultimos 3 meses
</CardDescription>
Expand Down
2 changes: 1 addition & 1 deletion src/components/charts/pie-graph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export function PieGraph() {
return (
<Card className="flex flex-col">
<CardHeader className="items-center pb-0">
<CardTitle>Grafico de Pizza - Cisculo com Texto</CardTitle>
<CardTitle>Grafico de Pizza - Circulo com Texto</CardTitle>
<CardDescription>Janeiro - Junho 2024</CardDescription>
</CardHeader>
<CardContent className="flex-1 pb-0">
Expand Down
6 changes: 3 additions & 3 deletions src/lib/constants/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export const navItems: NavItem[] = [
label: 'Dashboard'
},
{
title: 'Usuário',
title: 'Cliente',
href: '/dashboard/user',
icon: 'User',
label: 'user'
Expand All @@ -136,8 +136,8 @@ export const navItems: NavItem[] = [
label: 'profile'
},
{
title: 'Kanban',
href: '/dashboard/kanban',
title: 'Sala',
href: '/dashboard/room',
icon: 'Kanban',
label: 'kanban'
},
Expand Down

0 comments on commit 6690e16

Please sign in to comment.