码迷,mamicode.com
首页 > 其他好文 > 详细

药品信息管理系统前端开发(1)

时间:2020-03-02 22:22:40      阅读:97      评论:0      收藏:0      [点我收藏+]

标签:tar   前端   address   like   文本   rip   pen   事先   rom   

<?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.Configuration;

namespace 药品信息管理系统
{
    public class DBHelper
    {
        public static string connString =
            ConfigurationManager.ConnectionStrings["Sql"].ConnectionString;
        
        }
    }
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace 药品信息管理系统
{
    public partial class frm_LogIn : Form
    {
        
        /// <summary>
        /// 私有属性:用户;
        /// </summary>
        private Admin  Admin
        {
            get;
            set;
        }

        /// <summary>
        /// 公有方法:构造函数;
        /// </summary>
        public frm_LogIn()
        {
            InitializeComponent();
            this.StartPosition = FormStartPosition.CenterScreen;                                    //本窗体启动位置设为屏幕中央;
            this.Admin = new Admin ();                                                                 //实例化用户,并赋予本窗体的相应属性;
        }
       

        private void frm_login_Load(object sender, EventArgs e)
        {

        }

        /// <summary>
        /// 私有方法:点击登录按钮;
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        

        /// <summary>
        /// 私有方法:点击注册按钮;
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        

        private void btn_login_Click_1(object sender, EventArgs e)
        {
            this.Admin.ANo = this.txt_ANo.Text.Trim();                                            //将文本框的文本清除首尾的空格后,赋予用户的相应属性;
            this.Admin.Pwd = this.txt_pwd.Text.Trim();

            AdminBll.LogIn(this.Admin);                                                              //调用业务逻辑层的静态方法,对用户执行登录操作;
            MessageBox.Show(this.Admin.Message);                                                    //在消息框中显示登录消息;
            if (!this.Admin.HasLoggedIn)                                                            //若用户未完成登录,即登录失败;
            {
                this.txt_pwd.Focus();                                                         //密码文本框获得焦点;此时将触发事件,并再次执行验证用户号的方法,从而将用户的消息覆盖为验证用户号的结果,故需事先在消息框中显示登录消息;
                this.txt_pwd.SelectAll();                                                     //密码文本框内所有文本被选中;
            }
            else 
            {
                frm_Content frmcontent = new frm_Content();
                frmcontent.ShowDialog(this);
            }
        }

        private void btn_register_Click(object sender, EventArgs e)
        {
            frm_SignUp signUpForm = new frm_SignUp();                                              //声明并实例化注册窗体;
            signUpForm.ShowDialog(this);   
        }
    }
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace 药品信息管理系统
{
    public partial class frm_SignUp : Form
    {
        /// <summary>
        /// 私有属性:用户;
        /// </summary>
        private Admin  Admin
        {
            get;
            set;
        }

        public frm_SignUp()
        {
            InitializeComponent();
            this.StartPosition = FormStartPosition.CenterScreen;                                //本窗体启动位置设为屏幕中央; 
            this.Admin = new Admin ();                                                             //实例化用户,并赋予本窗体的相应属性;
        }
        private void frm_SignUp_Load(object sender, EventArgs e)
        {
            
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void btn_SignUp_Click(object sender, EventArgs e)
        {
            if (this.txt_ANo.Text.Trim() == "")                                              //若用户号文本框为空;
            {
                MessageBox.Show("用户号不能为空!");                                            //给出错误提示;
                this.txt_ANo.Focus();                                                        //用户号文本框获得焦点;
                return;                                                                         //返回;
            }
            if (this.txt_pwd.Text.Trim() == "")                                            //若密码文本框为空;
            {
                MessageBox.Show("密码不能为空!");                                              //给出错误提示;
                this.txt_pwd.Focus();                                                      //密码文本框获得焦点;
                return;                                                                         //返回;
            }
            if (txt_pwd.Text.ToString() != txt_pwd2.Text.ToString())
            {
                MessageBox.Show("两次密码输入不一致");
                this.txt_pwd2.Focus();
                return;
            }
            this.Admin .ANo  = this.txt_ANo.Text.Trim();                                         //将文本框的文本清除首尾的空格后,赋予用户的相应属性;
            this.Admin.Pwd = this.txt_pwd.Text.Trim();
            this.Admin.AName = this.txt_name.Text.Trim();
            AdminBll.SignUp(this.Admin);                                                          //调用业务逻辑层的静态方法,对用户执行注册操作;       
            MessageBox.Show(this.Admin.Message);  
            
        }

        private void txt_pwd_TextChanged(object sender, EventArgs e)
        {

        }

       
    }
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;

namespace 药品信息管理系统
{
    public partial class frm_Content : Form
    {
        SqlDataAdapter da;
        DataSet ds;
        private Client  Client
        {
            get;
            set;
        }
        public frm_Content()
        {
            InitializeComponent();
            this.StartPosition = FormStartPosition.CenterScreen;                                //本窗体启动位置设为屏幕中央; 
            this.Client = new Client ();   
        }

        private void frm_Content_Load(object sender, EventArgs e)
        {
            // TODO: 这行代码将数据加载到表“medicineDataSet.tb_Client”中。您可以根据需要移动或移除它。
           

        }

        private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {

        }

        private void btn_ClientManage_Click(object sender, EventArgs e)
        {
            gb_Client.Visible = true;
            gb_supply.Visible = false;
            gb_xitong.Visible = false;
        }

        private void btn_seek_Click(object sender, EventArgs e)
        {

            using (SqlConnection sqlConnection = new SqlConnection(DBHelper.connString))
            {                  //配置管理器从App.config读取连接字符串;
                SqlCommand sqlCommand1 = sqlConnection.CreateCommand();                             //调用SQL连接的方法CreateCommand来创建SQL命令;该命令将绑定SQL连接;
                sqlCommand1.CommandText = "select * from tb_Client " + "where CNO=‘" + this.txt_Name.Text.ToString() + "";                                    //指定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())
                {

                    this.txt_CNo.Text = sqlDataReader["CNO"].ToString();
                    this.txt_CName.Text = sqlDataReader["CName"].ToString();
                    this.txt_CTel.Text = sqlDataReader["CTel"].ToString();
                    this.txt_CAddr.Text = sqlDataReader["CAddress"].ToString();

                }
                sqlDataReader.Close();
                sqlConnection.Close();
            }
            
        }

        private void btn_Add_Click(object sender, EventArgs e)
        {
            this.Client.CNo = this.txt_CNo.Text.Trim();                                         //将文本框的文本清除首尾的空格后,赋予用户的相应属性;
            this.Client .CName  = this.txt_CName.Text.Trim();
            this.Client.CTel = this.txt_CTel.Text.Trim();
            this.Client.CAddress = this.txt_CAddr.Text.Trim();
            ClientBll.Add(this.Client );                                                          //调用业务逻辑层的静态方法,对用户执行注册操作;       
            MessageBox.Show(this.Client.Message);  
        }

        private void btn_seekName_Click(object sender, EventArgs e)
        {
            using (SqlConnection sqlConnection = new SqlConnection(DBHelper.connString))
            {
                SqlCommand sqlCommand1 = sqlConnection.CreateCommand();                             //调用SQL连接的方法CreateCommand来创建SQL命令;该命令将绑定SQL连接;
                sqlCommand1.CommandText = "select * from tb_Client where CName in (select CName from tb_Client where CName like ‘%" + this.txt_name1.Text.ToString() + "%‘)";                                 //指定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())
                {

                    this.txt_CNo.Text = sqlDataReader["CNO"].ToString();
                    this.txt_CName.Text = sqlDataReader["CName"].ToString();
                    this.txt_CTel.Text = sqlDataReader["CTel"].ToString();
                    this.txt_CAddr.Text = sqlDataReader["CAddress"].ToString();

                }
                sqlDataReader.Close();
                sqlConnection.Close();
            }
        }
        //未完成
        private void btn_alter_Click(object sender, EventArgs e)
        {
            using (SqlConnection sqlConnection = new SqlConnection(DBHelper.connString))
            {
                sqlConnection.Open(); //配置管理器从App.config读取连接字符串;
                // SqlCommand sqlCommand1 = sqlConnection.CreateCommand();                             //调用SQL连接的方法CreateCommand来创建SQL命令;该命令将绑定SQL连接;
                //sqlCommand1.CommandText = "update tb_Client set CName =‘"+this.txt_CName .Text .ToString ()+"‘,CTel =‘ "+this .txt_CTel .Text .ToString ()+"‘ ,CAddress =‘ "+this .txt_CAddr .Text .ToString ()+"‘where CNO =‘ "+this.txt_CNo .Text .ToString ()+"‘;";                                 //指定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);
                string str = "update tb_Client set CName=‘" + this.txt_CName.Text + "‘,CTel=‘" + this.txt_CTel.Text + "‘,CAddress=‘" + this.txt_CAddr.Text + "‘ where CNO=‘" + this.txt_CNo.Text + "";
                SqlCommand sqlCommand1 = new SqlCommand(str, sqlConnection);
                //sqlConnection.Open();                                                               //打开SQL连接;
                int i = sqlCommand1.ExecuteNonQuery();
                if (i == 1)
                {
                    MessageBox.Show("OK");
                }
                else
                    MessageBox.Show("not OK");
                sqlConnection.Close();
            }
        }

        private void btn_Delete_Click(object sender, EventArgs e)
        {
            using (SqlConnection sqlConnection = new SqlConnection(DBHelper.connString))
            {
                sqlConnection.Open(); //配置管理器从App.config读取连接字符串;
                // SqlCommand sqlCommand1 = sqlConnection.CreateCommand();                             //调用SQL连接的方法CreateCommand来创建SQL命令;该命令将绑定SQL连接;
                //sqlCommand1.CommandText = "update tb_Client set CName =‘"+this.txt_CName .Text .ToString ()+"‘,CTel =‘ "+this .txt_CTel .Text .ToString ()+"‘ ,CAddress =‘ "+this .txt_CAddr .Text .ToString ()+"‘where CNO =‘ "+this.txt_CNo .Text .ToString ()+"‘;";                                 //指定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);
                string str = "delete from tb_Client where CNO=‘" + this.txt_CNo.Text + "";
                SqlCommand sqlCommand1 = new SqlCommand(str, sqlConnection);
                //sqlConnection.Open();                                                               //打开SQL连接;
                int i = sqlCommand1.ExecuteNonQuery();
                if (i == 1)
                {
                    MessageBox.Show("OK");
                }
                else
                    MessageBox.Show("not OK");
                sqlConnection.Close();
            }
        }

        private void btn_xiaoshou_Click(object sender, EventArgs e)
        {
            gb_Client.Visible = false;
            gb_xitong.Visible = true;
            gb_supply.Visible = false;
        }

        private void btn_caigou_Click(object sender, EventArgs e)
        {
            gb_Client.Visible = false;
            gb_xitong.Visible = false;
            gb_supply.Visible = true;
        }

        private void gb_supply_Enter(object sender, EventArgs e)
        {

        }

        private void btn_Sadd_Click(object sender, EventArgs e)
        {
            using (SqlConnection sqlConnection = new SqlConnection(DBHelper.connString))
            {
                sqlConnection.Open();
                string str = " insert tb_Supply (SupplyNO ,SupplyName ,Address ,SupplyTel )values(‘" + this.txt_SNO.Text + "‘,‘" + this.txt_SName.Text + "‘,‘" + this.txt_SAddress.Text + "‘,‘" + this.txt_STel.Text + "‘)";
                SqlCommand sqlCommand1 = new SqlCommand(str, sqlConnection);
                //sqlConnection.Open();                                                               //打开SQL连接;
                int i = sqlCommand1.ExecuteNonQuery();
                if (i == 1)
                {
                    MessageBox.Show("OK");
                }
                else
                    MessageBox.Show("not OK");
                sqlConnection.Close();
            }

        }

        private void btn_Salter_Click(object sender, EventArgs e)
        {
            using (SqlConnection sqlConnection = new SqlConnection(DBHelper.connString))
            {
                sqlConnection.Open();
                string str = "update tb_Supply set SupplyName=‘" + this.txt_SName.Text + "‘,SupplyTel=‘" + this.txt_STel.Text + "‘,Address=‘" + this.txt_SAddress.Text + "‘ where SupplyNO=‘" + this.txt_SNO.Text + "";
                SqlCommand sqlCommand1 = new SqlCommand(str, sqlConnection);
                //sqlConnection.Open();                                                               //打开SQL连接;
                int i = sqlCommand1.ExecuteNonQuery();
                if (i == 1)
                {
                    MessageBox.Show("OK");
                }
                else
                    MessageBox.Show("not OK");
                sqlConnection.Close();
            }
        }

        private void btn_SSeek_Click(object sender, EventArgs e)
        {
            using (SqlConnection sqlConnection = new SqlConnection(DBHelper.connString))
            {                     
                SqlCommand sqlCommand1 = sqlConnection.CreateCommand();                             //调用SQL连接的方法CreateCommand来创建SQL命令;该命令将绑定SQL连接;
                sqlCommand1.CommandText = "select * from tb_Supply where SupplyName in (select SupplyName from tb_Supply where SupplyName like ‘%" + txt_supplyname.Text + "%‘)"; //this.txt_supplyname.Text.ToString()                                //指定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())
                {

                    this.txt_SNO.Text = sqlDataReader["SupplyNO"].ToString();
                    this.txt_SName.Text = sqlDataReader["SupplyName"].ToString();
                    this.txt_STel.Text = sqlDataReader["SupplyTel"].ToString();
                    this.txt_SAddress.Text = sqlDataReader["Address"].ToString();

                }
                sqlDataReader.Close();
                sqlConnection.Close();
            }
        }

        private void btn_SDelete_Click(object sender, EventArgs e)
        {
            using (SqlConnection sqlConnection = new SqlConnection(DBHelper.connString))
            {
                sqlConnection.Open();
                string str = "delete from tb_Supply where SupplyNO=‘" + this.txt_SNO.Text + "";
                SqlCommand sqlCommand1 = new SqlCommand(str, sqlConnection);
                //sqlConnection.Open();                                                               //打开SQL连接;
                int i = sqlCommand1.ExecuteNonQuery();
                if (i == 1)
                {
                    MessageBox.Show("OK");
                }
                else
                    MessageBox.Show("not OK");
                sqlConnection.Close();
            }

        }

        private void btn_chaxun_Click(object sender, EventArgs e)
        {

        }

        private void seek_Click(object sender, EventArgs e)
        {
            fill();
        }
        public void fill() //Datagridview的连接
        {
            string sql = "select CNO,CName from tb_client";
            using (SqlConnection sqlConnection = new SqlConnection(DBHelper.connString)) //DBHelper类书16页
            {
                da = new SqlDataAdapter(sql, sqlConnection);
                ds = new DataSet();
                da.Fill(ds); //Fill();方法
                supplyseek.DataSource = ds.Tables[0];
            }
        
        }
        

       
    }
}
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 AName
        {
            get;
            set;
        }
        public bool HasLoggedIn
        {
            get;
            set;
        }
        public bool HasSignedUp
        {
            get;
            set;
        }
        /// 公有属性:是否雷同;
        /// (即存在用户号雷同的用户)
        public bool IsDuplicate
        {
            get;
            set;
        }
        /// 公有属性:消息;
        /// (用于返回验证结果)
        /// </summary>
        public string Message
        {
            get;
            set;
        }

    }
}
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 string Message
        {
            get;
            set;
        }
        public bool HasAdd
        {
            get;
            set;
        }
        public bool HasDelete
        {
            get;
            set;
        }
        public bool HasAlter
        {
            get;
            set;
        }
        public bool IsDuplicate
        {
            get;
            set;
        }
    }
}
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 = "adm_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);
            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;                                                                 //返回受影响行数;
        }
    }
}
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);
            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 ;                                                                   //返回用户个数;
       // }

    }
}

 

药品信息管理系统前端开发(1)

标签:tar   前端   address   like   文本   rip   pen   事先   rom   

原文地址:https://www.cnblogs.com/xxnzmy/p/12398137.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!