#! /bin/sh
insert_s()
{
file_name="/root/aillo/students.db"
dialog --title "Student: Insert a record " --inputbox "Please input the student's information in the sort:(id,name,college):" 20 50 2>tmp.txt
content=$(cat tmp.txt)
IFS=","
read sid sname sin
unset IFS
grep -c "$sid" $file_name>menu.txt
sid=$(cat menu.txt)
if [ "$sid" != "0" ];then
dialog --title "ERROR" --msgbox "Record has existed!" 20 30
else
echo "$content">>$file_name
dialog --title "Reply Info" --msgbox "Add successfully!" 10 30
fi
}
insert_c()
{
file_name="/root/aillo/colleges.db"
dialog --title "College: Insert a record " --inputbox "Please input the college's information in the sort(cid,cname):" 20 50 2>tmp.txt
content=$(cat tmp.txt)
IFS=","
read cid cname
unset IFS
grep -c "$cid" $file_name>tmp.txt
cid=$(cat tmp.txt)
if [ "$cid" != "0" ];then
dialog --title "ERROR" --msgbox "Record has existed!" 30 50
else
echo "$content">>$file_name
dialog --title "Reply Info" --msgbox "Add successfully!" 10 30
fi
}
delete_s()
{file_name="/root/aillo/students.db"
dialog --title "Student: Delete a record " --inputbox "Please input the ID of the student you want to delete:" 20 50 2>tmp.txt
read sid
grep -v $sid $file_name>tmp.txt
mv tmp.txt $file_name
dialog --title "Reply Info" --msgbox "the record has been delete!" 10 30
}
delete_c()
{file_name="/root/aillo/colleges.db"
dialog --title "College: Delete a record " --inputbox "Please input the ID of the college you want to delete:" 20 50 2>tmp.txt
read cid
grep -v $cid $file_name>tmp.txt
mv tmp.txt $file_name
dialog --title "Reply Info" --msgbox "the record has been delete!" 10 30
}
display_s()
{file_name="/root/aillo/students.db"
cat $file_name | while read line
do
echo $line>tmp.txt
IFS=","
read sid sname sin
echo "sid: $sid">>t.txt
echo "sname: $sname">>t.txt
echo "sin: $sin">>t.txt
echo "---------------------">>t.txt
IFS=" "
done
content=$(cat t.txt)
dialog --title "All Students' Info" --msgbox "$content" 50 50
rm t.txt
}
display_c()
{file_name="/root/aillo/colleges.db"
cat $file_name | while read line
do
echo $line>tmp.txt
IFS=","
read cid cname
echo "cid: $cid">>t.txt
echo "cname: $cname">>t.txt
echo "---------------------">>t.txt
IFS=" "
done
content=$(cat t.txt)
dialog --title "All colleges' Info" --msgbox "$content" 50 50
rm t.txt
}
count()
{
file_name="/root/aillo/students.db"
dialog --title "Count " --inputbox "Please input the id of college students you want to count:" 20 50 2>tmp.txt
read p1
dialog --title "Reply Info" --msgbox "There are `grep -c $p1 $file_name` students in the $p1 college!" 10 30
}
change_s()
{
file_name="/root/aillo/students.db"
dialog --title "Modify Student's Info " --inputbox "Please input the new information you want to modify in the sort(sid,sname,sin):" 20 50 2>tmp.txt
IFS=","
read p1 p2 p3
grep -v $p1 $file_name>tmp.txt
echo "$p1,$p2,$p3">>tmp.txt
IFS=" "
mv tmp.txt $file_name
dialog --title "Reply Info" --msgbox "The information has been modified!" 10 30
}
change_c()
{
file_name="/root/aillo/colleges.db"
dialog --title "Modify College's Info" --inputbox "Please input the new information:" 20 50 2>tmp.txt
IFS=","
read p1 p2
grep -v $p1 $file_name>tmp.txt
echo "$p1,$p2">>tmp.txt
IFS=" "
mv tmp.txt $file_name
dialog --title "Reply Info" --msgbox "The information has been modified!" 10 30
}
status=1
dialog --title " Students' Info Manage System" --msgbox "\\nWelccome to use the System!\\n" 10 35
if [ $? != 0 ];then
sleep 1
dialog --clear
exit 0
fi
while [ "$status" = "1" ]
do
dialog --title "Main Menu" --menu "Choices" 15 20 2 1 "Student" 2 "College" 2>tmp.txt
MY_CHOICE=$(cat tmp.txt)
if [ $? != 0 ];then
sleep 1
dialog --clear
exit 0
fi
if [ "$MY_CHOICE" = "1" ];then
dialog --title "Student Info Manage" --menu "Choose Operation" 20 30 7 1 "INSERT" 2 "DELETE" 3 "MODIFY" 4 "COUNT" 5 "DISPLAY" 6 "BACK" 7 "EXIT" 2>tmp.txt
if [ $? != 0 ];then
sleep 1
dialog --clear
exit 0
fi
choice_2=$(cat tmp.txt)
if [ "$choice_2" = "1" ];then
insert_s
elif [ "$choice_2" = "2" ];then
delete_s
elif [ "$choice_2" = "3" ];then
change_s
elif [ "$choice_2" = "4" ];then
count
elif [ "$choice_2" = "5" ];then
display_s
elif [ "$choice_2" = "6" ];then
continue
else
break
fi
else
dialog --title "College Info Manage" --menu "Choose Operation" 20 30 7 1 "INSERT" 2 "DELETE" 3 "MODIFY" 4 "COUNT" 5 "DISPLAY" 6 "BACK" 7 "EXIT" 2>tmp.txt
if [ $? != 0 ];then
sleep 1
dialog --clear
exit 0
fi
choice_2=$(cat tmp.txt)
if [ "$choice_2" = "1" ];then
insert_c
elif [ "$choice_2" = "2" ];then
delete_c
elif [ "$choice_2" = "3" ];then
change_c
elif [ "$choice_2" = "4" ];then
count
elif [ "$choice_2" = "5" ];then
display_c
elif [ "$choice_2" = "6" ];then
continue
else
break
fi
fi
dialog --yesno "Do you want to continue ?" 10 20
if [ $? = 0 ];then
status=1
else
status=0
fi
done
sleep 1
dialog --clear
exit 0