这篇是在前面两篇的基础上继续完善学生信息管理系统的功能。
(1)http://blog.csdn.net/wjf_1997/article/details/78474118
(2)http://blog.csdn.net/wjf_1997/article/details/78502039
实现的功能:删除
一、功能描述
删除功能从三个方面进行数据的删除,涉及到的函数有三个:
(1)delete_college_info():根据比较学院的编号进行删除
(2)delete_stu_info():根据比较学生的编号进行删除
(3)delete_stugrade_info():根据比较学生的编号进行删除
二、代码
2.1 delete_college_info()
delete_college_info(){
show_college_info;
echo "请输入要删除的学院的编号(若不存在,删除失败!):"
read collegeNo
export nowLine=0;
while read line
do
export nowLine=$(($nowLine+1))
nowCollegeNo=${line/,*/}
if [ "$nowCollegeNo" = "$collegeNo" ]; then
{
sed "$nowLine"d $DBCollegeInfoPath > $DBCollegeInfoPath"_back"
mv $DBCollegeInfoPath"_back" $DBCollegeInfoPath
echo "删除成功!"
}
else
{
echo "删除失败!"
}
fi
done<$DBCollegeInfoPath
show_college_info;
}
2.2 delete_stu_info()
delete_stu_info(){
show_stu_info;
echo "请输出要删除学生的编号(若不存在,删除失败!):"
read studentNo
export nowLine=0;
while read line
do
export nowLine=$(($nowLine+1))
echo $line":"$nowLine
lineStudentNo=${line/,*/}
if [ "$lineStudentNo" = "$studentNo" ]; then
{
#echo $nowLine "是当前行"
sed "$nowLine"d $DBStudentInfoPath > $DBStudentInfoPath"_back"
export delCount=$(($delCount+1))
mv $DBStudentInfoPath"_back" $DBStudentInfoPath
echo "删除成功!"
}
else
{
echo "删除失败!"
}
fi
done<$DBStudentInfoPath
show_stu_info;
}
2.3 delete_stugrade_info()
delete_stugrade_info(){
show_stugrade_info;
echo "请输出要删除学生的编号(若不存在,删除失败!):"
read studentNo
#export existFlag=false
export nowLine=0;
while read line
do
export nowLine=$(($nowLine+1))
lineStudentNo=${line/,*/}
if [ "$lineStudentNo" = "$studentNo" ]; then
{
sed "$nowLine"d $DBStudentGradeInfoPath > $DBStudentGradeInfoPath"_back"
mv $DBStudentGradeInfoPath"_back" $DBStudentGradeInfoPath
echo "删除成功!"
}
else
{
echo "删除失败!"
}
fi
done<$DBStudentGradeInfoPath
#while read line
#do
# lineStudentNo=${line/,*/}
#if [ "$lineStudentNo" = "$studentNo" ]; then
#{
# export existFlag=true
# break
#}
#fi
# done<$DBStudentInfoPath
#if [ "$existFlag" = "true" ]; then
#{
# export existFlag=false
# sed -i '/$studentNo/d' $DBStudentGradeInfoPath > $DBStudentGradeInfoPath"_back"
# mv $DBStudentGradeInfoPath"_back" $DBStudentGradeInfoPath
# echo "删除成功!"
# show_stugrade_info;
#}
#else {
# echo "删除失败!"
#}
show_stugrade_info;
}
分析:
通过运行情况可以分析出,在成绩删除中会出现问题。删除的时候,同一个人的不同学科成绩没有办法正确的删除。(以后找到解决办法再处理)
参考资料:
(1)vim环境配置脚本,让你的心情愉快:
http://blog.csdn.net/mengyafei43/article/details/46559911
https://www.cnblogs.com/ma6174/archive/2011/12/10/2283393.html
https://www.cnblogs.com/oxspirt/p/6206787.html