票据/发票登记系统

时间:2016-01-23 21:25:56

标签: batch-file cmd invoice

嘿我决定尝试在我的电脑上制作账单/发票注册系统,因为我只是这样一个笨拙的混乱头,每次我收到账单,如果我不在那一刻支付它(因为我&# 39;忙着)我会忘记我把账单放在哪里。

所以我正在制作这个程序,如果我忘记原始纸张的位置,它会向我显示我需要的所有信息。
脚本本身工作正常。但我努力的部分是:

当我注册账单的所有细节时,它会在程序所在的用户名文件夹中创建一个文件夹,其中包含我付账单的实例名称。

然后在该文件夹中,它将创建一个包含所有信息的文本文件。如果我决定用不同的实例注册另一个账单。然后同样的事情再次发生。

然而,当它使用该文件将目录设置为实例名称时会出现错误。

有时它会出现在主程序文件夹中而不是用户文件夹中。有时候它会出现在文件夹里......

但现在它根本没有创建txt ......我想我把代码搞砸了,但是我无法弄清楚我把它搞砸了,所以我希望有人会看一下这个脚本。我只是无法看出错误的来源:P

@echo off
title Bill Registration.         V1.0-    Computer-ID: %USERNAME%%
goto registercheck
:main
cls
echo.
echo.
echo.
echo.
echo.
echo                                        User: %usrn%
echo                                    ===========================
echo                                    Bill register/database Menu
echo                                    ===========================
echo                                    ^| 1. -Register a bill    ^|
echo                                    ^| 2. -Check Bill Info    ^|
echo                                    ^| 3. -Edit bill          ^|
echo                                    ___________________________
set /P Q=".                                  Console: " 
IF %Q%==1 goto billreg
IF %Q%==2 goto checkbill
IF %Q%==3 goto editbill
IF "%Q%"=="" call invalid
echo.
echo.
echo.
echo.

:registercheck
cls
set usrn=
echo.
echo.
echo.
echo.
echo                                        User: Not logged in
echo                                    ===========================
echo                                            User Check
echo                                    ===========================
echo                                    ^|   Type Your username   ^|
echo                                    ^|   to check if it is    ^|
echo                                    ^|   Existing             ^|
echo                                    ___________________________
set /P usrn=".                                  Username:" 
if exist C:\Users\%USERNAME%\Documents\billregister\%usrn% goto login
if not exist C:\Users\%USERNAME%\Documents\billregister\%usrn% goto userreg
goto main
:invalid
:login
cls
echo  Please log in to your account!
set usr=
set /p usr=Username:
if {%usr%}=={} goto :login
set authenticated=
for /f "tokens=*" %%a in (C:\Users\%USERNAME%\Documents\billregister\%usrn%\usrn.dll) do (
    if {%%a}=={%usr%} set authenticated=true
)

if not defined authenticated (echo Invalid Username & goto :login)

:passwo
set pass=
set /p pass=Enter your password: 
if {%pass%}=={} goto :login
set authenticated=
for /f "tokens=*" %%a in (C:\Users\%USERNAME%\Documents\billregister\%usrn%\usrnp.dll) do (
    if {%%a}=={%pass%} set authenticated=true
)
if not defined authenticated (echo Invalid password & goto :login)
:loggedin
goto main


:userreg
cls
echo                                    ===========================
echo                                          Please Register
echo                                    ===========================
Set usrname=
set /p usrname=".                                  Username:" 
Set passw=
set /p passw=".                                  Password:"
MKDIR C:\Users\%USERNAME%\Documents\billregister\%usrname%\
echo %usrname%> C:\Users\%USERNAME%\Documents\billregister\%usrname%\usrn.dll
echo %passw%> C:\Users\%USERNAME%\Documents\billregister\%usrname%\usrnp.dll
goto login

:retrievebill
:checkbill
:billreg
cls
echo                                        User: %usrn%
echo                                    ===========================
echo                                         Bill register form
echo                                    ===========================
echo                                    ^|   Fill out the form    ^|
echo                                    ^|   In order to register ^|
echo                                    ^|   Your bills           ^|
echo                                    ___________________________
set orgname=
set /p orgname=".                                  Payment to(name):"                         
set orgacc=
set /p orgacc=".                                  Payment to account:"
set faknr=
set /P Faknr=".                                  FAKTURA-Number:" 
set  efakref=
set /p efakref=".                                  E-Faktura Ref:"
set totpay=
set /p totpay=".                                   Total ammount to pay:"
set duetodate=
set /p duetodate=".                                   Due to date:"
set kidnr=
set /p kidnr=".                                   KID-Number:"
set payfor=
set /p payfor="Write a short describtion of what you pay for:"
if exist cd/ C:\Users\%USERNAME%\Documents\billregister\%usrname%\bills\%orgname% goto writebill
if not exist cd/ exist C:\Users\%USERNAME%\Documents\billregister\%usrname%\bills\%orgname% goto makedirectory
:makedirectory
MKDIR C:\Users\%USERNAME%\Documents\billregister\%usrn%\bills\%orgname%\goto writebill


:writebill
(
    echo                                     E-Faktura Referance: %efakref%
    echo                                     KID-Number: %kidnr% 
    echo                                    =================================================================
    echo                                      Bill from: %orgname%                Faktura number: %faknr%
    echo                                    =================================================================                        
    echo                                    pay-to Account number: %orgacc%
    echo.
    echo                                    Due to date: %duetodate%
    echo.
    echo                                    Describtion of what you pay for:
    echo                                    ________________________________________________________________
    echo                                    %payfor%
    echo                                    ================================================================
    echo                                    Total Ammount to pay: %totpay% -NOK
    ) > C:\Users\%USERNAME%\Documents\billregister\%usrname%\bills\%orgname%\bill_%orgname%_faktura%faknr%.txt
Pause>nul

goto registeredbill
:registeredbill
cls
echo The bill is now saved
pause>Nul
goto billreg







:editbill

1 个答案:

答案 0 :(得分:0)

这是一次尝试。我无法理解你的登录方法所以我只是绕过了它。无论如何,我都获得了成功的回报。

我无法使用“检查您的帐单信息”选项。我认为我有一个简单的解决方法,但没有用于修复可能不会破坏的东西。

@echo on
rem Is the second % in the title a mistake?
rem also replaced [goto label] with [goto :label] because...reasons,
rem and quotes have been added to soothe my habit.

rem Also had to replace all instances of [usrn] with [usrname],
rem because flip flopping meant one could be left blank, thus ruining
rem a path directory.


title Bill Registration.         V1.0-    Computer-ID: %USERNAME%%

goto :registercheck

:main
cls
echo.
echo.
echo.
echo.
echo.
echo                                        User: %usrname%
echo                                    ===========================
echo                                    Bill register/database Menu
echo                                    ===========================
echo                                    ^| 1. -Register a bill    ^|
echo                                    ^| 2. -Check Bill Info    ^|
echo                                    ^| 3. -Edit bill          ^|
echo                                    ___________________________
set /P Q=".                                  Console: " 
IF %Q%==1 goto :billreg
IF %Q%==2 goto :checkbill
IF %Q%==3 goto :editbill
rem IF "%Q%"=="" call :invalid // Youre better off just using the next command, which i noted is present later on.
if not defined Q call :invalid
echo.
echo.
echo.
echo.


:registercheck
cls
set usrname=
echo.
echo.
echo.
echo.
echo                                        User: Not logged in
echo                                    ===========================
echo                                            User Check
echo                                    ===========================
echo                                    ^|   Type Your username   ^|
echo                                    ^|   to check if it is    ^|
echo                                    ^|   Existing             ^|
echo                                    ___________________________
set /P usrname=".                                  Username:" 
if exist "C:\Users\%USERNAME%\Documents\billregister\%usrname%" goto :login
if not exist "C:\Users\%USERNAME%\Documents\billregister\%usrname%" goto :userreg
goto :main
:invalid
:login
cls
echo  Please log in to your account!
set usr=
set /p usr=Username:
if {%usr%}=={} goto :login
set authenticated=
for /f "tokens=*" %%a in (C:\Users\%USERNAME%\Documents\billregister\%usrname%\usrname.dll) do (
    if {%%a}=={%usr%} set authenticated=true
)

if not defined authenticated (echo Invalid Username & goto :login)

:passwo
set pass=
set /p pass=Enter your password: 
if {%pass%}=={} goto :login
set authenticated=
for /f "tokens=*" %%a in (C:\Users\%USERNAME%\Documents\billregister\%usrname%\usrnamep.dll) do (
    if {%%a}=={%pass%} set authenticated=true
)
if not defined authenticated (echo Invalid password & goto :login)
:loggedin
goto :main


:userreg
cls
echo                                    ===========================
echo                                          Please Register
echo                                    ===========================
Set usrname=
set /p usrname=".                                  Username:" 
Set passw=
set /p passw=".                                  Password:"
MKDIR "C:\Users\%USERNAME%\Documents\billregister\%usrname%\"
echo %usrname% > "C:\Users\%USERNAME%\Documents\billregister\%usrname%\usrname.dll"
echo %passw% > "C:\Users\%USERNAME%\Documents\billregister\%usrname%\usrnamep.dll"
goto :login

:retrievebill
:checkbill
:billreg
cls
echo                                        User: %usrname%
echo                                    ===========================
echo                                         Bill register form
echo                                    ===========================
echo                                    ^|   Fill out the form    ^|
echo                                    ^|   In order to register ^|
echo                                    ^|   Your bills           ^|
echo                                    ___________________________
set orgname=
set /p orgname=".                                  Payment to(name):"                         
set orgacc=
set /p orgacc=".                                  Payment to account:"
set faknr=
set /P Faknr=".                                  FAKTURA-Number:" 
set  efakref=
set /p efakref=".                                  E-Faktura Ref:"
set totpay=
set /p totpay=".                                   Total ammount to pay:"
set duetodate=
set /p duetodate=".                                   Due to date:"
set kidnr=
set /p kidnr=".                                   KID-Number:"
set payfor=
set /p payfor="Write a short describtion of what you pay for:"
rem These two following lines just didnt work, so i made an else block instead.
if exist "C:\Users\%USERNAME%\Documents\billregister\%usrname%\bills\%orgname%" (
    goto :writebill
) else (
    goto :makedirectory
)
:makedirectory
MKDIR "C:\Users\%USERNAME%\Documents\billregister\%usrname%\bills\%orgname%\" & goto :writebill


:writebill
(
    echo                                     E-Faktura Referance: %efakref%
    echo                                     KID-Number: %kidnr% 
    echo                                    =================================================================
    echo                                      Bill from: %orgname%                Faktura number: %faknr%
    echo                                    =================================================================                        
    echo                                    pay-to Account number: %orgacc%
    echo.
    echo                                    Due to date: %duetodate%
    echo.
    echo                                    Describtion of what you pay for:
    echo                                    ________________________________________________________________
    echo                                    %payfor%
    echo                                    ================================================================
    echo                                    Total Ammount to pay: %totpay% -NOK
    ) > "C:\Users\%USERNAME%\Documents\billregister\%usrname%\bills\%orgname%\bill_%orgname%_faktura%faknr%.txt"
Pause>nul

goto :registeredbill
:registeredbill
cls
echo The bill is now saved
pause>Nul
goto :billreg







:editbill