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,所以想写一个批处理来编 ...
随机推荐
- oracle删除数据后表空间仍过大问题解决方法
-----亲测有效------- --一.备份原始数据库库--1.备份空表--在plsql里面执行一下这句话 然后把结果集 再执行一把 再导数据select 'alter table '||table ...
- SevenZipSharp的入门教程(包含如何加密压缩,解密压缩)
(一)为什么选择7z 7z 是一种主流高效的压缩格式,它拥有极高的压缩比.在计算机科学中,7z是一种可以使用多种压缩算法进行数据压缩的档案格式.该格式最初被7-Zip实现并采 ...
- 在线SVN仓库实现:金山快盘+TortoiseSVN(Win)+SCPlugin(Mac)
前段时间一直在研究SVN在线托管,也尝试了网上推荐的免费托管网站. 但毕竟是是免费的,还是要受到比如空间大小.私有性等这样那样的限制,感觉有些麻烦. 而且,比较心疼自己在本地开发的时候积累的更新日志, ...
- Vue中应用CORS实现AJAX跨域,及它在 form data 和 request payload 的小坑处理
基本概念部分(一):理解CORS 说道Vue的跨域AJAX,我想先梳理一遍CORS跨域,"跨域资源共享"(Cross-origin resource sharing),它是一个W3 ...
- Java基础(3) -字符串
字符串-String 1.定义&&初始化 使用双引号把字符括起来 String str = "test"; 2.字符串的提取-substring String a ...
- C#窗体多语言切换(简繁)
多窗体最好继承一个父窗体,在父窗体Load事件中执行此方法 添加引用 using Microsoft.VisualBasic; #region 语言切换 /// <summary> /// ...
- Java系列 - 用Java8新特性进行Java开发太爽了
本人博客文章网址:https://www.peretang.com/using-java8s-new-features-to-coding-is-awesome/ 前言 从开始写博客到现在已经过去3个 ...
- 用 volume container 共享数据 - 每天5分钟玩转 Docker 容器技术(42)
volume container 是专门为其他容器提供 volume 的容器.它提供的卷可以是 bind mount,也可以是 docker managed volume.下面我们创建一个 volum ...
- 基于requirejs和angular搭建spa应用
接上篇,angular 实战部分,angular比较适合spa项目,这里不借助任何seed和构建工具,直接从零搭建,基本的angular项目结构大致包含如下几个部分: 1)app.js 入口 2)in ...
- C# Datatable.Select()用法简介
dt为一个DataTable,以dt为例说明dt.select()方法的功能: 1.dt.Select() 获取所有行数 例:Datarow[] drs=dt.Select(); 此时drs为dt数据 ...