<?xml version="1.0" encoding="utf-8" ?> <configuration> <!-- 数据库连接串 --> <configSections> </configSections> <connectionStrings> <add name="Sql" connectionString="Server=(local);Database=medicine;Integrated Security=sspi" providerName="System.Data.SqlClient" /> <add name="药品信息管理系统.Properties.Settings.medicineConnectionString" connectionString="Data Source=1B3F3C3082DF468;Initial Catalog=medicine;Integrated Security=True" providerName="System.Data.SqlClient" /> </connectionStrings> </configuration>
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Drawing; namespace 药品信息管理系统 { public class ColorConfig { private Color _fontcolor = Color.White; /// <summary> /// 菜单字体颜色 /// </summary> public Color FontColor { get { return this._fontcolor; } set { this._fontcolor = value; } } private Color _marginstartcolor = Color.FromArgb(65, 105, 225); /// <summary> /// 下拉菜单坐标图标区域开始颜色 /// </summary> public Color MarginStartColor { get { return this._marginstartcolor; } set { this._marginstartcolor = value; } } private Color _marginendcolor = Color.FromArgb(25, 25, 112); /// <summary> /// 下拉菜单坐标图标区域结束颜色 /// </summary> public Color MarginEndColor { get { return this._marginendcolor; } set { this._marginendcolor = value; } } private Color _dropdownitembackcolor = Color.FromArgb(220, 220, 220); /// <summary> /// 下拉项背景颜色 /// </summary> public Color DropDownItemBackColor { get { return this._dropdownitembackcolor; } set { this._dropdownitembackcolor = value; } } private Color _dropdownitemstartcolor = Color.Blue; /// <summary> /// 下拉项选中时开始颜色 /// </summary> public Color DropDownItemStartColor { get { return this._dropdownitemstartcolor; } set { this._dropdownitemstartcolor = value; } } private Color _dorpdownitemendcolor = Color.FromArgb(11, 23, 70); /// <summary> /// 下拉项选中时结束颜色 /// </summary> public Color DropDownItemEndColor { get { return this._dorpdownitemendcolor; } set { this._dorpdownitemendcolor = value; } } private Color _menuitemstartcolor = Color.FromArgb(52, 106, 159); /// <summary> /// 主菜单项选中时的开始颜色 /// </summary> public Color MenuItemStartColor { get { return this._menuitemstartcolor; } set { this._menuitemstartcolor = value; } } private Color _menuitemendcolor = Color.FromArgb(73, 124, 174); /// <summary> /// 主菜单项选中时的结束颜色 /// </summary> public Color MenuItemEndColor { get { return this._menuitemendcolor; } set { this._menuitemendcolor = value; } } private Color _separatorcolor = Color.Black ; /// <summary> /// 分割线颜色 /// </summary> public Color SeparatorColor { get { return this._separatorcolor; } set { this._separatorcolor = value; } } private Color _mainmenubackcolor = Color.Gray ;//原为Coral /// <summary> /// 主菜单背景色 /// </summary> public Color MainMenuBackColor { get { return this._mainmenubackcolor; } set { this._mainmenubackcolor = value; } } private Color _mainmenustartcolor = Color.FromArgb(61, 89, 171); /// <summary> /// 主菜单背景开始颜色 /// </summary> public Color MainMenuStartColor { get { return this._mainmenustartcolor; } set { this._mainmenustartcolor = value; } } private Color _mainmenuendcolor = Color.FromArgb(34, 34, 34); /// <summary> /// 主菜单背景结束颜色 /// </summary> public Color MainMenuEndColor { get { return this._mainmenuendcolor; } set { this._mainmenuendcolor = value; } } private Color _dropdownborder = Color.FromArgb(40, 96, 151); /// <summary> /// 下拉区域边框颜色 /// </summary> public Color DropDownBorder { get { return this._dropdownborder; } set { this._dropdownborder = value; } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Configuration; namespace 药品信息管理系统 { public class DBHelper { public static string connString = ConfigurationManager.ConnectionStrings["Sql"].ConnectionString; } }
using System; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.Linq; using System.Text; using System.Windows.Forms; namespace 药品信息管理系统 { public partial class MyMenu : MenuStrip { public MyMenu() { InitializeComponent(); this.Renderer = new MyMenuRender();//设置渲染 } public MyMenu(IContainer container) { container.Add(this); InitializeComponent(); this.Renderer = new MyMenuRender();//设置渲染 } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Forms; using System.Drawing; using System.Drawing.Drawing2D; namespace 药品信息管理系统 { public class MyMenuRender : ToolStripProfessionalRenderer { ColorConfig colorconfig = new ColorConfig();//创建颜色配置类 /// <summary> /// 渲染整个背景 /// </summary> /// <param name="e"></param> protected override void OnRenderToolStripBackground(ToolStripRenderEventArgs e) { e.ToolStrip.ForeColor = colorconfig.FontColor; //如果是下拉 if (e.ToolStrip is ToolStripDropDown) { e.Graphics.FillRectangle(new SolidBrush(colorconfig.DropDownItemBackColor), e.AffectedBounds); } //如果是菜单项 else if (e.ToolStrip is MenuStrip) { Blend blend = new Blend(); float[] fs = new float[5] { 0f, 0.3f, 0.5f, 0.8f, 1f }; float[] f = new float[5] { 0f, 0.5f, 0.9f, 0.5f, 0f }; blend.Positions = fs; blend.Factors = f; FillLineGradient(e.Graphics, e.AffectedBounds, colorconfig.MainMenuStartColor, colorconfig.MainMenuEndColor, 90f, blend); } else { base.OnRenderToolStripBackground(e); } } /// <summary> /// 渲染下拉左侧图标区域 /// </summary> /// <param name="e"></param> protected override void OnRenderImageMargin(ToolStripRenderEventArgs e) { FillLineGradient(e.Graphics, e.AffectedBounds, colorconfig.MarginStartColor, colorconfig.MarginEndColor, 0f, null); } /// <summary> /// 渲染菜单项的背景 /// </summary> /// <param name="e"></param> protected override void OnRenderMenuItemBackground(ToolStripItemRenderEventArgs e) { if (e.ToolStrip is MenuStrip) { //如果被选中或被按下 if (e.Item.Selected || e.Item.Pressed) { Blend blend = new Blend(); float[] fs = new float[5] { 0f, 0.3f, 0.5f, 0.8f, 1f }; float[] f = new float[5] { 0f, 0.5f, 1f, 0.5f, 0f }; blend.Positions = fs; blend.Factors = f; FillLineGradient(e.Graphics, new Rectangle(0, 0, e.Item.Size.Width, e.Item.Size.Height), colorconfig.MenuItemStartColor, colorconfig.MenuItemEndColor, 90f, blend); } else base.OnRenderMenuItemBackground(e); } else if (e.ToolStrip is ToolStripDropDown) { if (e.Item.Selected) { FillLineGradient(e.Graphics, new Rectangle(0, 0, e.Item.Size.Width, e.Item.Size.Height), colorconfig.DropDownItemStartColor, colorconfig.DropDownItemEndColor, 90f, null); } } else { base.OnRenderMenuItemBackground(e); } } /// <summary> /// 渲染菜单项的分隔线 /// </summary> /// <param name="e"></param> protected override void OnRenderSeparator(ToolStripSeparatorRenderEventArgs e) { e.Graphics.DrawLine(new Pen(colorconfig.SeparatorColor), 0, 2, e.Item.Width, 2); } /// <summary> /// 渲染边框 /// </summary> /// <param name="e"></param> protected override void OnRenderToolStripBorder(ToolStripRenderEventArgs e) { if (e.ToolStrip is ToolStripDropDown) { e.Graphics.DrawRectangle(new Pen(colorconfig.DropDownBorder), new Rectangle(0, 0, e.AffectedBounds.Width - 1, e.AffectedBounds.Height - 1)); } else { base.OnRenderToolStripBorder(e); } } /// <summary> /// 渲染箭头 /// </summary> /// <param name="e"></param> protected override void OnRenderArrow(ToolStripArrowRenderEventArgs e) { e.ArrowColor = Color.Red;//设置为红色,当然还可以 画出各种形状 base.OnRenderArrow(e); } /// <summary> /// 填充线性渐变 /// </summary> /// <param name="g">画布</param> /// <param name="rect">填充区域</param> /// <param name="startcolor">开始颜色</param> /// <param name="endcolor">结束颜色</param> /// <param name="angle">角度</param> /// <param name="blend">对象的混合图案</param> private void FillLineGradient(Graphics g, Rectangle rect, Color startcolor, Color endcolor, float angle, Blend blend) { LinearGradientBrush linebrush = new LinearGradientBrush(rect, startcolor, endcolor, angle); if (blend != null) { linebrush.Blend = blend; } GraphicsPath path = new GraphicsPath(); path.AddRectangle(rect); g.SmoothingMode = SmoothingMode.AntiAlias; g.FillPath(linebrush, path); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; namespace 药品信息管理系统 { static class Program { /// <summary> /// 应用程序的主入口点。 /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new frm_LogIn()); } } }
--Admin.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace 药品信息管理系统 { public class Admin { public string ANo { get; set; } public string pwd { get; set; } public string tel { get; set; } public string AName { get; set; } public bool HasLoggedIn { get; set; } public bool HasSignedUp { get; set; } /// 公有属性:是否雷同; /// (即存在用户号雷同的用户) public bool IsDuplicate { get; set; } /// 公有属性:消息; /// (用于返回验证结果) /// </summary> public string Message { get; set; } } } --Client.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace 药品信息管理系统 { public class Client { public string CNo { get; set; } public string CName { get; set; } public string CTel { get; set; } public string CAddress { get; set; } public bool sex { get; set; } public DateTime RegistDate { get; set; } public DateTime Birthday { get; set; } public bool minsurance { get; set; } public string Message { get; set; } public bool HasAdd { get; set; } public bool HasDelete { get; set; } public bool HasAlter { get; set; } public bool IsDuplicate { get; set; } } }
--AdminDal.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data; //包含Ado.Net的各类数据对象; using System.Data.SqlClient; //包含访问SQL Server所需的各类对象; using System.Configuration; namespace 药品信息管理系统 { public static class AdminDal { public static int SelectCount(Admin admin) { SqlConnection sqlConnection = new SqlConnection(); //声明并实例化SQL连接; sqlConnection.ConnectionString = ConfigurationManager.ConnectionStrings["Sql"].ToString(); //配置管理器从App.config读取连接字符串; SqlCommand sqlCommand1 = sqlConnection.CreateCommand(); //调用SQL连接的方法CreateCommand来创建SQL命令;该命令将绑定SQL连接; sqlCommand1.CommandText = "adm_selectAdminCount"; //指定SQL命令的命令文本;命令文本为存储过程名称; sqlCommand1.CommandType = CommandType.StoredProcedure; //SQL命令的类型设为存储过程; sqlCommand1.Parameters.AddWithValue("@ANo", admin.ANo); //向SQL命令的参数集合添加参数的名称、值; sqlCommand1.Parameters.AddWithValue("@Pwd", admin.pwd); sqlConnection.Open(); //打开SQL连接; int adminCount = (int)sqlCommand1.ExecuteScalar(); //调用SQL命令的方法ExecuteScalar来执行命令,并接受单个结果(即标量); sqlConnection.Close(); //关闭SQL连接; return adminCount; //返回用户个数; } public static int Insert(Admin admin) { SqlConnection sqlConnection = new SqlConnection(); //声明并实例化SQL连接; sqlConnection.ConnectionString = ConfigurationManager.ConnectionStrings["Sql"].ToString(); //配置管理器从App.config读取连接字符串; SqlCommand sqlCommand = sqlConnection.CreateCommand(); //调用SQL连接的方法CreateCommand来创建SQL命令;该命令将绑定SQL连接; sqlCommand.CommandText = "admin_insertadmin"; //指定SQL命令的命令文本;命令文本为存储过程名称; sqlCommand.CommandType = CommandType.StoredProcedure; //SQL命令的类型设为存储过程; sqlCommand.Parameters.AddWithValue("@ANo", admin.ANo); //向SQL命令的参数集合添加参数的名称、值; sqlCommand.Parameters.AddWithValue("@pwd", admin.pwd); sqlCommand.Parameters.AddWithValue("@AName", admin.AName); sqlCommand.Parameters.AddWithValue("@tel", admin.tel); sqlConnection.Open(); //打开SQL连接; int rowAffected = 0; //声明整型变量,用于保存受影响行数 try //尝试; { rowAffected = sqlCommand.ExecuteNonQuery(); //调用SQL命令的方法ExecuteNonQuery来执行命令,向数据库写入数据,并返回受影响行数; } catch (SqlException sqlEx) //捕捉SQL异常; { if (sqlEx.Number == 2627) //若异常的编号为2627,则违反实体完整性,即插入了主键重复的记录; { admin.IsDuplicate = true; //存在雷同用户; } else { throw sqlEx; } } return rowAffected; //返回受影响行数; } } } --ClientDal.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.SqlClient; //包含访问SQL Server所需的各类对象; using System.Configuration; using System.Data; namespace 药品信息管理系统 { public class ClientDal { public static int Insert(Client client) { SqlConnection sqlConnection = new SqlConnection(); //声明并实例化SQL连接; sqlConnection.ConnectionString = ConfigurationManager.ConnectionStrings["Sql"].ToString(); //配置管理器从App.config读取连接字符串; SqlCommand sqlCommand = sqlConnection.CreateCommand(); //调用SQL连接的方法CreateCommand来创建SQL命令;该命令将绑定SQL连接; sqlCommand.CommandText = "cli_insertClient"; //指定SQL命令的命令文本;命令文本为存储过程名称; sqlCommand.CommandType = CommandType.StoredProcedure; //SQL命令的类型设为存储过程; sqlCommand.Parameters.AddWithValue("@CNo", client .CNo); //向SQL命令的参数集合添加参数的名称、值; sqlCommand.Parameters.AddWithValue("@CName", client .CName); sqlCommand.Parameters.AddWithValue("@CTel", client.CTel); sqlCommand.Parameters.AddWithValue("@CAddress", client.CAddress); sqlCommand.Parameters.AddWithValue("@sex", client.sex ); sqlCommand.Parameters.AddWithValue("@RegistDate", client.RegistDate ); sqlCommand.Parameters.AddWithValue("@Birthday", client.Birthday ); sqlCommand.Parameters.AddWithValue("@minsurance", client.minsurance ); //sqlCommand.Parameters.AddWithValue("@pinyin", client.pinyin ); sqlConnection.Open(); //打开SQL连接; int rowAffected = 0; //声明整型变量,用于保存受影响行数 try //尝试; { rowAffected = sqlCommand.ExecuteNonQuery(); //调用SQL命令的方法ExecuteNonQuery来执行命令,向数据库写入数据,并返回受影响行数; } catch (SqlException sqlEx) //捕捉SQL异常; { if (sqlEx.Number == 2627) //若异常的编号为2627,则违反实体完整性,即插入了主键重复的记录; { client.IsDuplicate = true; //存在雷同用户; } else { throw sqlEx; } } return rowAffected; //返回受影响行数; } //public static SqlDataReader Select(Client client) //{ //SqlConnection sqlConnection = new SqlConnection(); //声明并实例化SQL连接; //sqlConnection.ConnectionString = // ConfigurationManager.ConnectionStrings["Sql"].ToString(); //配置管理器从App.config读取连接字符串; //SqlCommand sqlCommand1 = sqlConnection.CreateCommand(); //调用SQL连接的方法CreateCommand来创建SQL命令;该命令将绑定SQL连接; //sqlCommand1.CommandText = "cli_selectClient"; //指定SQL命令的命令文本;命令文本为存储过程名称; //sqlCommand1.CommandType = CommandType.StoredProcedure; //SQL命令的类型设为存储过程; //sqlCommand1.Parameters.AddWithValue("@CNo", client .CNo ); //向SQL命令的参数集合添加参数的名称、值; //sqlCommand1.Parameters.AddWithValue("@CName", client .CName ); //sqlCommand1.Parameters.AddWithValue("@CTel", client.CTel ); //sqlCommand1.Parameters.AddWithValue("@CAddress", client.CAddress ); //sqlConnection.Open(); //打开SQL连接; //SqlDataReader sqlDataReader = sqlCommand1.ExecuteReader(); //while (sqlDataReader.Read()) //{ // string cno = sqlDataReader["@CNo"].ToString(); // string cname = sqlDataReader["@CName"].ToString(); // string ctel = sqlDataReader["@CTel"].ToString(); // string caddress = sqlDataReader["@CAddress"].ToString(); //} //sqlDataReader.Close(); //sqlConnection.Close(); //关闭SQL连接; //return sqlDataReader ; //返回用户个数; // } } } --SqlDBHelper.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data; using System.Data.SqlClient; using System.Configuration; namespace 药品信息管理系统 { class SqlDBHelper { public static string connString = ConfigurationManager.ConnectionStrings["Sql"].ConnectionString; public static string ConnectionString { get { return connString; } set { connString = value; } } } }
--AdminBll.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace 药品信息管理系统 { public static class AdminBll { /// 公有静态方法:登录; /// </summary> /// <param name="admin">用户</param> /// <returns>是否登录成功</returns> public static bool LogIn(Admin admin) { if (AdminDal.SelectCount(admin) == 1) //调用数据访问层的静态方法,查询与输入的用户号、密码匹配的记录行数; { //若匹配行数为1; admin.HasLoggedIn = true; //完成登录; admin.Message = "登录成功。"; //给出正确提示; } else //否则; { admin.HasLoggedIn = false; //未完成登录; admin.Message = "用户号/密码有误,请重新输入!"; //给出错误提示; } return admin.HasLoggedIn; //返回用户是否登录成功; } /// <summary> /// 公有静态方法:注册; /// </summary> /// <param name="admin">用户</param> /// <returns>是否注册成功</returns> public static bool SignUp(Admin admin) { int rowAffected1 = AdminDal.Insert(admin ); //调用数据访问层的静态方法来插入用户,并返回受影响行数; if (rowAffected1 == 1) //若受影响的行数为1; { admin.HasSignedUp = true; //完成注册; admin.Message = "注册成功。"; //给出正确提示; } else //否则; { admin.HasSignedUp = false; //未完成注册; if (admin.IsDuplicate) //若用户雷同; { admin.Message = "您注册的用户号已存在,请重新输入!\n"; //给出错误提示; } admin.Message += "注册失败!"; //给出错误提示; } return admin.HasSignedUp; //返回用户是否注册成功; } } } --ClientBll.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace 药品信息管理系统 { public class ClientBll { public static bool Add(Client client) { int rowAffected1 = ClientDal.Insert(client); //调用数据访问层的静态方法来插入用户,并返回受影响行数; if (rowAffected1 == 1) //若受影响的行数为1; { client.HasAdd = true; //完成注册; client.Message = "添加成功。"; //给出正确提示; } else //否则; { client.HasAdd = false; //未完成注册; if (client.IsDuplicate) //若用户雷同; { client.Message = "您添加的客户已存在,请重新输入!\n"; //给出错误提示; } client.Message += "添加失败!"; //给出错误提示; } return client.HasAdd; //返回用户是否注册成功; } } }
来源:https://www.cnblogs.com/xxnzmy/p/12397845.html