# Dialog專案 :::info :bulb:專案名稱:HRM v1.0 (填寫員工基本資料) 專案緣起:為了使人資部門能夠更輕鬆且方便地收集員工的基本資料,我們開發了一個TUI互動選單模式的應用程式。透過這個應用程式,人資部門可以同時向全體員工發送問卷,並且方便地統計和回收資料。 創作者:Jason Yu 創作日期:2023年6月19日 最後更新:2023年6月19日 適用系統:Ubuntu 20.04以上、Rucky Linux 8以上、CentOS 7以上 ::: **程式碼內容:** :::success vim hrm.sh #新增一個sh檔,並給予執行權限 (chmod +x hrm.sh) ::: ``` BACKTITLE="人力資源系統" Test() { dialog --title "員工基本資料表" --yesno "是否填寫?" 20 50 result=$? if [ $result -eq 0 ]; then dialog --title "身分認證" --inputbox "請輸入姓名。" 20 50 2> /tmp/name.txt name=$(cat /tmp/name.txt) if [[ -n "$name" ]]; then dialog --title "人資部" --msgbox "您的姓名是:$name" 20 50 Select else dialog --title "錯誤" --msgbox "姓名為必填欄位,請重新輸入。" 20 50 Test fi else Exit fi } Select() { while true; do dialog --title "選單" --menu "請選擇填寫項目:" 20 50 20 \ 1 "新增員工資料" \ 2 "適職測驗" \ 3 "福委會-社團選擇" \ 4 "考勤異動" \ 5 "退出" 2>/tmp/menuchoice.txt result=$? if [ $result -eq 0 ]; then choice=$(cat /tmp/menuchoice.txt) case $choice in 1) AddEmployee ;; 2) PersonalityTest ;; 3) PickYourGroup ;; 4) CheckEmployment ;; 5) Exit ;; *) dialog --title "錯誤" --msgbox "請重新選擇。" 20 50 ;; esac else Exit fi done } AddEmployee() { exec 3>&1 EmployeeInfo=$(dialog --title "新增資料" --clear \ --backtitle "$BACKTITLE" \ --form "請於下方填寫您的資訊" 24 60 10 \ "姓名:" 1 2 "$name" 1 14 48 0 \ "性別:" 2 2 "" 2 14 48 0 \ "年齡:" 3 2 "" 3 14 48 0 \ "部門職位:" 4 2 "" 4 14 48 0 \ "薪水:" 5 2 "" 5 14 48 0 \ 2>&1 1>&3) if [ $? -eq 0 ]; then dialog --title "新增完成" --msgbox "$EmployeeInfo" 24 60 else dialog --title "錯誤" --msgbox "取消新增員工資料。" 20 30 fi Select } PersonalityTest() { Score=0 Question1 } Question1() { dialog --title "適職測驗" --yesno "問題 1:您擅長與團隊一起工作嗎?" 20 50 result=$? if [ $result -eq 0 ]; then CalculateScore 20 Question2 else Question2 fi } Question2() { dialog --title "適職測驗" --yesno "問題 2:您喜歡與人溝通嗎?" 20 50 result=$? if [ $result -eq 0 ]; then CalculateScore 20 Question3 else Question3 fi } Question3() { dialog --title "適職測驗" --yesno "問題 3:您會對於正確的事物據理力爭嗎?" 20 50 result=$? if [ $result -eq 0 ]; then CalculateScore 20 Question4 else Question4 fi } Question4() { dialog --title "適職測驗" --yesno "問題 4:您喜歡學習新知識嗎?" 20 50 result=$? if [ $result -eq 0 ]; then CalculateScore 20 Question5 else Question5 fi } Question5() { dialog --title "適職測驗" --yesno "問題 5:您喜歡獨立解決問題嗎?" 20 50 result=$? if [ $result -eq 0 ]; then CalculateScore 20 Bar else Bar fi } Bar() { ( sleep 1 echo "10" sleep 1 echo "50" sleep 1 echo "100" ) | dialog --title "統計結果" --gauge "正在結算您的成績" 10 60 0 ShowResult Select } CalculateScore() { score=$1 Score=$((Score + score)) } ShowResult() { dialog --title "適職測驗結果" --msgbox "您的得分為:$Score" 20 50 Select } PickYourGroup() { dialog --title "社團選擇" --checklist "請選擇您想參加的社團(可多選):" 20 50 20 \ 1.羽球社 "時間:每周一、三、五" off \ 2.登山社 "時間:每週二、四" off \ 3.慢跑社 "時間:周末" off 2>/tmp/groupchoice.txt if [ $? -eq 0 ]; then group_choice=$(cat /tmp/groupchoice.txt) dialog --title "社團選擇" --msgbox "您選擇的社團是:$group_choice" 20 50 Select else Select fi } CheckEmployment() { options=( "事假" "無給付薪水" off "病假" "半薪" off "公假" "需檢附憑證" off "特休假" "有給付薪水" off ) selection=$(dialog --title "請假申請" --radiolist "請選擇假別:" 20 50 4 "${options[@]}" 2>&1 >/dev/tty) if [ -n "$selection" ]; then dialog --title "考勤異動" --msgbox "您選擇了:$selection" 20 50 dialog --title "考勤異動" --msgbox "申請已提交給人事部,請於月底確認異動是否成功。" 20 50 Select else dialog --title "考勤異動" --msgbox "您沒有選擇任何假別。" 20 50 Select fi } Exit() { dialog --title "退出" --msgbox "感謝您使用人力資源系統,再見!" 20 50 clear exit 0 } Test ``` **操作畫面說明** :::danger 請確保終端機有下載dialog!(sudo apt-get install dialog) ::: ``` ./hrm.sh #執行名為hrm.sh ``` :::info 畫面一:選擇是否填寫資料表 :::  :::info 畫面二:選擇(是),進入身分認證;(否)則是跳出結束回答 :::  :::info 畫面三:填寫姓名取得身分認證-若填寫空值會有防呆機制畫面跳出 :::  :::info 畫面四:進入選單後選擇第一題填寫(會自動帶入剛剛身分認證之畫面) :::  :::info 畫面五:進入選單後選擇第二題填寫(連續答5題是非題) :::  :::info 畫面六:第二題填寫完後會有統整分數進度條(約莫等待3秒) :::  :::info 畫面七:總得分 :::  :::info 畫面八:進入選單後選擇第三題填寫(多選題),結束後呈現結果 :::  :::info 畫面九:進入選單後選擇第四題填寫(單選題),結束後呈現結果與異動通知 :::  :::info 畫面十:選擇退出即結束程式 ::: 
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up