⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 narnu.cs

📁 进存销系统..适合书店的进销存..功能可以满足一般的需求.很简单
💻 CS
字号:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;

namespace BookStore.DataAccess
{
    class Narnu
    {
        //提供一个打开的数据库联接
        public static SqlConnection GetConnection()
        {
            string source = "server=(local);integrated security=SSPI;database=BookShop";
            SqlConnection conn = new SqlConnection(source);
            conn.Open();
            return conn;
        }

        //获得一条SQL语句,在数据库中执行
        public static int DoSqlString(string select)
        {
            SqlCommand myCmd = new SqlCommand(select, GetConnection());
            
            return myCmd.ExecuteNonQuery();
        }

        //获得一条SQL语句,返回一个DataReader
        public static SqlDataReader GetDataReaderBySqlString(string select)
        {
            SqlCommand myCmd = new SqlCommand(select, GetConnection());
            return myCmd.ExecuteReader();
        }

        //获得SQL语句,返回object
        public static object GetObjectBySqlString(string select)
        {
            SqlCommand myCmd = new SqlCommand(select, GetConnection());
            return myCmd.ExecuteScalar();
        }

        //通过SQL语句,返回DataTable
        public static DataTable GetDataTableBySql(string select)
        {
            SqlDataAdapter myDA = new SqlDataAdapter(select, GetConnection());
            DataTable myDT = new DataTable();
            myDA.Fill(myDT);
            return myDT;
        }

        //获得SQL语句,返回DataSet
        public static DataSet GetDataSetBySqlString(string select)
        {
            ArrayList myAL = new ArrayList();
            myAL.AddRange(select.Split(new char[] { ' ' }));
            string tablename = myAL[myAL.IndexOf("from") + 1].ToString();
            SqlCommand myCmd = new SqlCommand(select, GetConnection());
            SqlDataAdapter myDA = new SqlDataAdapter(myCmd);
            DataSet myDT = new DataSet();
            myDA.Fill(myDT,tablename);
            return myDT;
        }

        //根据产品ID得到一个DataReader
        public static SqlDataReader GetProInfoByProID(int ProID)
        {
            string select = "select * from Products where ProductID='" + ProID + "'";
            return Narnu.GetDataReaderBySqlString(select);
        }

        //根据大分类名称获得分类ID
        public static object GetCategoryID(string name)
        {
            string select = "select CategoryID from Categories where CategoryName='"+name+"'";
            return Narnu.GetObjectBySqlString(select);
        }

        //根据小分类名称获得小分类ID
        public static object GetDetailCategoryID(string name)
        {
            string select = "select DetailCategoryID from DetailCategorys where Name='" + name + "'";
            return Narnu.GetObjectBySqlString(select);
        }

        //根据供应商名称获取供应商ID
        public static object GetSupplierID(string name)
        {
            string select = "select SupplierID from Suppliers where CompanyName='" + name + "'";
            return Narnu.GetObjectBySqlString(select);
        }

        //根据采购员姓名获取采购员ID
        public static object GetEmployeeID(string name)
        {
            string select = "select EmployeeID from Employees where Name='" + name + "'";
            return Narnu.GetObjectBySqlString(select);
        }

        //生成采购单的单条信息
        public static void InsertStockDetail(BusinessRule.Product product, string StockID,string Employee, int amount)
        {
            int EmployeeID =Convert.ToInt32(Narnu.GetEmployeeID(Employee).ToString());
            string select = "insert into StockDetails (DetailID,StockDetailID,ProductID,UnitPrice,Quantity,TotalPrice)" +
                "Values()";
            Narnu.DoSqlString(select);
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -