C#控制台应用程序之旅游资源与线路管理系统
利用C#语言及SQL Server数据库编写的一个简化版旅游资源与线路管理系统
数据库中包含三张表:hotel表、tourist_spot表、lines表
用户分为管理员和普通用户,管理员拥有最高权限,可以对三张表进行增、删、改、查,而普通用户拥有部分权限,只能进行查询操作
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient; namespace ConsoleApp1
{
class Program
{
static string[] Users = new string[] { "a123", "abcd","admin","driver" };
static void Main(string[] args)
{
string str_id = "",str_password="";
Console.WriteLine(" ********************************");
Console.WriteLine(" ****欢迎您使用旅游资源及线路管理系统****");
Console.WriteLine(" ********************************\n");
Console.WriteLine("请你验证身份,以便于我们为您提供更加优质的服务!");
Console.Write("请输入您的账号:");
str_id = Console.ReadLine();
Console.Write("请输入您的密码:");
str_password = Console.ReadLine();
if (str_id == "root" && str_password == "root")
{
do
{
RootMenu();
Console.WriteLine("请选择:1、继续 2、退出");
} while (Console.ReadLine() == "");
Environment.Exit();
}
else if(isUser(str_id.Trim()))
{
if(str_password.Trim()=="admin")
do
{
User();
Console.WriteLine("请选择:1、继续 2、退出");
} while (Console.ReadLine() == "");
Environment.Exit();
}
} //判断是否为普通用户
static bool isUser(string x)
{
foreach (string i in Users)
if (x == i)
return true;
else
continue;
return false;
} //root管理菜单
static void RootMenu()
{
Console.Clear();
Console.WriteLine("您是超级管理员,拥有最高权限");
Console.WriteLine(" 1、酒店信息管理");
Console.WriteLine(" 2、景点信息管理");
Console.WriteLine(" 3、线路信息管理");
bool bool1 = true;
do
{
Console.Write("请输入序号选择你要管理的内容:");
string str = Console.ReadLine();
switch (str)
{
case "":
Console.Clear();
Console.WriteLine("欢迎进行酒店信息管理");
Console.WriteLine("1、酒店信息添加");
Console.WriteLine("2、酒店信息删除");
Console.WriteLine("3、酒店信息修改");
Console.WriteLine("4、酒店信息查询");
Root();
break;
case "":
Console.Clear();
Console.WriteLine("欢迎进行景点信息管理");
Console.WriteLine("1、景点信息添加");
Console.WriteLine("2、景点信息删除");
Console.WriteLine("3、景点信息修改");
Console.WriteLine("4、景点信息查询");
Root();
break; ;
case "":
Console.Clear();
Console.WriteLine("欢迎进行线路信息管理");
Console.WriteLine("1、线路信息添加");
Console.WriteLine("2、线路信息删除");
Console.WriteLine("3、线路信息修改");
Console.WriteLine("4、线路信息查询");
Root();
break;
default:
bool1 = false;
break;
}
} while (!bool1);
} //root函数,具有所有数据操作的权限
static void Root(int x)
{
switch (x)
{
case :
{
Console.Write("请选择:");
string str = "";
str = Console.ReadLine();
switch (str.Trim())
{
case "":
HotelAdd();
break;
case "":
HotelDelete();
break;
case "":
HotelAlter();
break;
case "":
HotelSelect();
break;
default:
Console.Write("非法操作!");
return;
}
}
break; case :
{
Console.Write("请选择:");
string str = "";
str = Console.ReadLine();
switch (str.Trim())
{
case "":
Tourist_spotAdd();
break;
case "":
Tourist_spotDelete();
break;
case "":
Tourist_spotAlter();
break;
case "":
Tourist_spotSelect();
break;
default:
Console.Write("非法操作!");
return;
}
}
break;
case :
{
Console.Write("请选择:");
string str = "";
str = Console.ReadLine();
switch (str.Trim())
{
case "":
LinesAdd();
break;
case "":
LinesDelete();
break;
case "":
LinesAlter();
break;
case "":
LinesSelect();
break;
default:
Console.Write("非法操作!");
return;
}
}
break;
default:
{
Console.Write("非法操作!");
return;
}
}
} //user函数,具有查询功能
static void User()
{
Console.Clear();
Console.WriteLine("您是普通用户,拥有查询权限");
Console.WriteLine(" 1、查询酒店信息");
Console.WriteLine(" 2、查询景点信息");
Console.WriteLine(" 3、查询线路信息");
Console.Write("请输入序号选择您要查询的内容:");
string str = Console.ReadLine();
switch(str)
{
case "":
HotelSelect();
break;
case "":
Tourist_spotSelect();
break;
case "":
LinesSelect();
break;
default:
Console.WriteLine("非法输入!");
return;
}
} //hotel信息管理函数
#region
//hotel信息添加
static void HotelAdd()
{
Console.WriteLine("请输入你要添加的酒店信息");
Console.Write("酒店名称:");
string str_hotel_name = Console.ReadLine() ;
Console.Write("酒店地址:");
string str_hotel_addr = Console.ReadLine();
Console.Write("酒店电话:");
string str_hotel_tel = Console.ReadLine();
Console.Write("酒店价格:");
int int_hotel_price = Convert.ToInt32(Console.ReadLine());
string StrCon = @"Data Source = .;Initial Catalog=tourResour_lines;" +
"Integrated Security = True;";
SqlConnection sqlCon = new SqlConnection(StrCon);
sqlCon.Open();
string isStr = @"insert into hotel values('" + str_hotel_name +"','" + str_hotel_addr + "',"
+ str_hotel_tel + ","+int_hotel_price+")";
SqlCommand sqlCmd = new SqlCommand(isStr, sqlCon);
sqlCmd.ExecuteNonQuery();
Console.WriteLine("酒店信息添加成功!");
sqlCon.Close();
} //hotel信息删除
static void HotelDelete()
{
Console.WriteLine("请输入你要删除的酒店信息");
Console.Write("酒店名称:");
string str_hotel_name = Console.ReadLine();
string StrCon = @"Data Source = .;Initial Catalog=tourResour_lines;" +
"Integrated Security = True;";
SqlConnection sqlCon = new SqlConnection(StrCon);
sqlCon.Open();
string isStr = @"delete from hotel where hotel_name ='" + str_hotel_name + "'";
SqlCommand sqlCmd = new SqlCommand(isStr, sqlCon);
sqlCmd.ExecuteNonQuery();
Console.WriteLine("酒店信息删除成功!");
sqlCon.Close();
} //hotel信息修改
static void HotelAlter()
{
Console.WriteLine("请输入要修改的酒店名称:");
Console.Write("酒店名称:");
string str_hotel_name_before = Console.ReadLine();
Console.WriteLine("请输入修改后的酒店信息");
Console.Write("酒店名称:");
string str_hotel_name = Console.ReadLine();
Console.Write("酒店地址:");
string str_hotel_addr = Console.ReadLine();
Console.Write("酒店电话:");
string str_hotel_tel = Console.ReadLine();
Console.Write("酒店价格:");
int int_hotel_price = Convert.ToInt32(Console.ReadLine());
string StrCon = @"Data Source = .;Initial Catalog=tourResour_lines;" +
"Integrated Security = True;";
SqlConnection sqlCon = new SqlConnection(StrCon);
sqlCon.Open();
string isStr = @"update hotel set hotel_name ='" + str_hotel_name +
"',hotel_addr='" + str_hotel_addr + "',hotel_tel ='" + str_hotel_tel
+ "',hotel_price=" + int_hotel_price + " where hotel_name='" + str_hotel_name_before + "'";
SqlCommand sqlCmd = new SqlCommand(isStr, sqlCon);
sqlCmd.ExecuteNonQuery();
Console.WriteLine("酒店信息修改成功!");
sqlCon.Close();
} //hotel信息查询
static void HotelSelect()
{
Console.WriteLine("请输入你要查询的酒店地址");
Console.Write("酒店地址:");
string str_hotel_addr = Console.ReadLine();
string StrCon = @"Data Source = .;Initial Catalog=tourResour_lines;" +
"Integrated Security = True;";
SqlConnection sqlCon = new SqlConnection(StrCon);
sqlCon.Open();
string isStr = @"select * from hotel where hotel_addr ='" + str_hotel_addr + "'";
string sltResult = "";
SqlCommand sqlCmd = new SqlCommand(isStr, sqlCon);
SqlDataReader reader = sqlCmd.ExecuteReader();
Console.WriteLine("查询结果:");
if (reader.HasRows)
{
while(reader.Read())
{
//记录每一条记录
sltResult += "名称:"+reader["hotel_name"].ToString() +"\t电话:" + reader["hotel_tel"].ToString()
+"\t价格:"+ reader["hotel_price"].ToString() + "\n";
}
Console.WriteLine(sltResult);
}
Console.WriteLine("酒店信息查询成功!");
sqlCon.Close();
}
#endregion //tourist_spot信息管理函数
#region
//tourist_spot信息添加
static void Tourist_spotAdd()
{
Console.WriteLine("请输入你要添加的景点信息");
Console.Write("景点名称:");
string str_Tourist_spot_name = Console.ReadLine();
Console.Write("景点地址:");
string str_Tourist_spot_addr = Console.ReadLine();
Console.Write("景点价格:");
int int_Tourist_spot_price = Convert.ToInt32(Console.ReadLine());
string StrCon = @"Data Source = .;Initial Catalog=tourResour_lines;" +
"Integrated Security = True;";
SqlConnection sqlCon = new SqlConnection(StrCon);
sqlCon.Open();
string isStr = @"insert into tourist_spot values('" + str_Tourist_spot_name + "','" + str_Tourist_spot_addr +
"'," + int_Tourist_spot_price + ")";
SqlCommand sqlCmd = new SqlCommand(isStr, sqlCon);
sqlCmd.ExecuteNonQuery();
Console.WriteLine("酒店信息添加成功!");
sqlCon.Close();
} //tourist_spot信息删除
static void Tourist_spotDelete()
{
Console.WriteLine("请输入你要删除的景点信息");
Console.Write("景点名称:");
string str_tourist_spot_name = Console.ReadLine();
string StrCon = @"Data Source = .;Initial Catalog=tourResour_lines;" +
"Integrated Security = True;";
SqlConnection sqlCon = new SqlConnection(StrCon);
sqlCon.Open();
string isStr = @"delete from tourist_spot where tourist_spot_name ='" + str_tourist_spot_name + "'";
SqlCommand sqlCmd = new SqlCommand(isStr, sqlCon);
sqlCmd.ExecuteNonQuery();
Console.WriteLine("景点信息删除成功!");
sqlCon.Close();
} //tourist_spot信息修改
static void Tourist_spotAlter()
{
Console.WriteLine("请输入要修改的景点名称:");
Console.Write("景点名称:");
string str_Tourist_spot_name_before = Console.ReadLine();
Console.WriteLine("请输入修改后的景点信息");
Console.Write("景点名称:");
string str_Tourist_spot_name = Console.ReadLine();
Console.Write("景点地址:");
string str_Tourist_spot_addr = Console.ReadLine();
Console.Write("景点价格:");
int int_Tourist_spot_price = Convert.ToInt32(Console.ReadLine());
string StrCon = @"Data Source = .;Initial Catalog=tourResour_lines;" +
"Integrated Security = True;";
SqlConnection sqlCon = new SqlConnection(StrCon);
sqlCon.Open();
string isStr = @"update tourist_spot set tourist_spot_name ='" + str_Tourist_spot_name +
"',tourist_spot_addr='" + str_Tourist_spot_addr + "',tourist_spot_price=" +
int_Tourist_spot_price + " where tourist_spot_name='" + str_Tourist_spot_name_before + "'";
SqlCommand sqlCmd = new SqlCommand(isStr, sqlCon);
sqlCmd.ExecuteNonQuery();
Console.WriteLine("景点信息修改成功!");
sqlCon.Close();
} //tourist_spot信息查询
static void Tourist_spotSelect()
{
Console.Write("请输入你要查询的景点地址:");
string str_Tourist_spot_addr = Console.ReadLine();
string StrCon = @"Data Source = .;Initial Catalog=tourResour_lines;" +
"Integrated Security = True;";
SqlConnection sqlCon = new SqlConnection(StrCon);
sqlCon.Open();
string isStr = @"select * from tourist_spot where tourist_spot_addr ='" + str_Tourist_spot_addr + "'";
string sltResult = "";
SqlCommand sqlCmd = new SqlCommand(isStr, sqlCon);
SqlDataReader reader = sqlCmd.ExecuteReader();
Console.WriteLine("查询结果:");
if (reader.HasRows)
{
while (reader.Read())
{
//记录每一条记录
sltResult += "名称:" + reader["tourist_spot_name"].ToString()
+ "\t价格:" + reader["tourist_spot_price"].ToString() + "\n";
}
Console.WriteLine(sltResult);
}
Console.WriteLine("景点信息查询成功!");
sqlCon.Close();
}
#endregion //lines信息管理函数
#region
//lines信息添加
static void LinesAdd()
{
Console.WriteLine("请输入你要添加的线路信息");
Console.Write("车次号码:");
string str_lines_num = Console.ReadLine();
Console.Write("发车时间:");
string str_lines_time = Console.ReadLine();
Console.Write("火车起点:");
string str_lines_from = Console.ReadLine();
Console.Write("火车终点:");
string str_lines_to = Console.ReadLine();
string StrCon = @"Data Source = .;Initial Catalog=tourResour_lines;" +
"Integrated Security = True;";
SqlConnection sqlCon = new SqlConnection(StrCon);
sqlCon.Open();
string isStr = @"insert into lines values('" + str_lines_num + "','" + str_lines_time + "','" +
str_lines_from + "','" + str_lines_to + "')";
SqlCommand sqlCmd = new SqlCommand(isStr, sqlCon);
sqlCmd.ExecuteNonQuery();
Console.WriteLine("线路信息添加成功!");
sqlCon.Close();
} //lines信息删除
static void LinesDelete()
{
Console.WriteLine("请输入你要删除的线路信息");
Console.Write("车次号码:");
string str_lines_num = Console.ReadLine();
string StrCon = @"Data Source = .;Initial Catalog=tourResour_lines;" +
"Integrated Security = True;";
SqlConnection sqlCon = new SqlConnection(StrCon);
sqlCon.Open();
string isStr = @"delete from lines where lines_num =" + str_lines_num ;
SqlCommand sqlCmd = new SqlCommand(isStr, sqlCon);
sqlCmd.ExecuteNonQuery();
Console.WriteLine("线路信息删除成功!");
sqlCon.Close();
} //lines信息修改
static void LinesAlter()
{
Console.WriteLine("请输入你要修改的线路信息");
Console.Write("车次号码:");
string str_lines_num_before = Console.ReadLine();
Console.WriteLine("请输入修改后的线路信息");
Console.Write("车次号码:");
string str_lines_num = Console.ReadLine();
Console.Write("发车时间:");
string str_lines_time = Console.ReadLine();
Console.Write("火车起点:");
string str_lines_from = Console.ReadLine();
Console.Write("火车终点:");
string str_lines_to = Console.ReadLine();
string StrCon = @"Data Source = .;Initial Catalog=tourResour_lines;" +
"Integrated Security = True;";
SqlConnection sqlCon = new SqlConnection(StrCon);
sqlCon.Open();
string isStr = @"update lines set lines_num ='" + str_lines_num + "',lines_time='" +
str_lines_time + "',lines_from='" + str_lines_from + "',lines_to='" + str_lines_to
+ "' where lines_num=" + str_lines_num_before;
SqlCommand sqlCmd = new SqlCommand(isStr, sqlCon);
sqlCmd.ExecuteNonQuery();
Console.WriteLine("线路信息修改成功!");
sqlCon.Close();
} //lines信息查询
static void LinesSelect()
{
Console.Write("请输入你要查询的车次号码:");
string str_lines_num = Console.ReadLine();
string StrCon = @"Data Source = .;Initial Catalog=tourResour_lines;" +
"Integrated Security = True;";
SqlConnection sqlCon = new SqlConnection(StrCon);
sqlCon.Open();
string isStr = @"select * from lines where lines_num =" + str_lines_num ;
string sltResult = "";
SqlCommand sqlCmd = new SqlCommand(isStr, sqlCon);
SqlDataReader reader = sqlCmd.ExecuteReader();
Console.WriteLine("查询结果:");
if (reader.HasRows)
{
while (reader.Read())
{
//记录每一条记录
sltResult += "车次号码:" + reader["lines_num"].ToString() + "\t发车时间:" +
reader["lines_time"].ToString() + "\t起始地点:" + reader["lines_from"].ToString() +
"\t终点城市:"+reader["lines_to"].ToString() + "\n";
}
Console.WriteLine(sltResult);
}
Console.WriteLine("线路信息查询成功!");
sqlCon.Close();
}
#endregion
}
}
作者:耑新新,发布于 博客园
转载请注明出处,欢迎邮件交流:zhuanxinxin@aliyun.com
C#控制台应用程序之旅游资源与线路管理系统的更多相关文章
- asp.net mvc引用控制台应用程序exe
起因:有一个控制台应用程序和一个web程序,web程序想使用exe程序的方法,这个时候就需要引用exe程序. 报错:使用web程序,引用exe程序 ,vs调试没有问题,但是部署到iis就报错,如下: ...
- Win32程序和控制台应用程序的项目互转设置
一般情况下,如果是windows程序,那么WinMain是入口函数,在VS2010中新建项目为"win32项目" 如果是dos控制台程序,那么main是入口函数,在VS2010中新 ...
- 【C#】1.2 控制台应用程序学习要点
分类:C#.VS2015 创建日期:2016-06-14 教材:十二五国家级规划教材<C#程序设计及应用教程>(第3版) 一.要点概述 <C#程序设计及应用教程>(第3版)的第 ...
- 【C++】第1章 在VS2015中用C++编写控制台应用程序
分类:C++.VS2015 创建日期:2016-06-12 一.简介 看到不少人至今还在用VC 6.0开发工具学习C++,其实VC 6.0开发工具早就被淘汰了.这里仅介绍学习C++时推荐使用的两种开发 ...
- c#取得控制台应用程序根目录
1.取得控制台应用程序的根目录方法 方法1.Environment.CurrentDirectory 取得或设置当前工作目录的完整限定路径方法2.AppDomain.CurrentDomain.Bas ...
- Web应用程序或者WinForm程序 调用 控制台应用程序及参数传递
有时候在项目中,会调用一个控制台应用程序去处理一些工作.那在我们的程序中要怎么样做才能调用一个控制台应用程序并将参数传递过去,控制台程序执行完后,我们的程序又怎样获取返回值?代码如下:调用代码: ...
- vc2010 win32 控制台应用程序中文乱码
vc2010 win32 控制台应用程序中文乱码 在 vc2010 上用 win32 控制台程序写些测试代码调用 windows api ,处理错误信息时,发现用 wprintf 输出的错误信息出现了 ...
- c# 隐藏 控制台应用程序
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.D ...
- 如何编写一个编译c#控制台应用程序的批处理程序
如何编写一个编译c#控制台应用程序的批处理程序 2011-03-22 18:14 dc毒蘑菇 | 浏览 579 次 最近在网上看了一个教程,是学C#的,但是我的机子上装不上vs,所以想写一个批处理来编 ...
随机推荐
- 单机部署 kubernets 方法汇总
#minikube : 可以方便的在本机用虚拟机创建一个开箱即用的Kubernetes集群 #kubeadm : 可以自动化的将多台Ubuntu或者CentOS主机组建成集群 #nanokube,ki ...
- JS监听div的resize事件
原文地址:http://zhangyiheng.com/blog/articles/div_resize.html 需求 开发过程中经常遇到的一个问题就是如何监听一个div的size变化. 比如我用c ...
- POJ 1459-Power Network(网络流-最大流-ISAP)C++
Power Network 时间限制: 1 Sec 内存限制: 128 MB 题目描述 A power network consists of nodes (power stations, cons ...
- ASP.NET Core配置Kestrel 网址Urls
ASP.NET Core中如何配置Kestrel Urls呢,大家可能都知道使用UseUrls() 方法来配置. 今天给介绍全面的ASP.NET Core 配置 Urls,使用多种方式配置Urls.让 ...
- 【Android Developers Training】 56. 更效率地加载大图片
注:本文翻译自Google官方的Android Developers Training文档,译者技术一般,由于喜爱安卓而产生了翻译的念头,纯属个人兴趣爱好. 原文链接:http://developer ...
- 【Android Developers Training】 44. 控制你应用的音量和播放
注:本文翻译自Google官方的Android Developers Training文档,译者技术一般,由于喜爱安卓而产生了翻译的念头,纯属个人兴趣爱好. 原文链接:http://developer ...
- 13.什么是javabean,以及使用原则
javabean简介 javabeans就是符合某种特定的规范的java类,使用javabeans的好处是解决代码的重复编写,减少代码 冗余,功能区分明确,提高了代码的维护性. javabean的设计 ...
- Socket实现-Socket I/O
Socket层的核心是两个函数:sosend()和soreceive().这两个函数负责处理所有Socket层和协议层之间的I/O操作. select()系统调用的作用是监控文件描述符的状态.一般用于 ...
- scrollMenu,一款可滚动的菜单插件 兼容pc和移动端
这个菜单 有两种样式 , 也可以通过animate.css加不同的动画效果!滚动的方式也有两种 一种为通用的overflow,另外一种是better-scroll的滚动效果 在线链接地址 ht ...
- Java 9 揭秘(8. JDK 9重大改变)
Tips 做一个终身学习的人. 在本章,主要介绍以下内容: 新的JDK版本控制方案是什么 如何使用Runtime.Version类解析JDK版本字符串 JDK JRE 9的新目录布局是什么 JDK 9 ...