expensedal.cs

来自「工作流方面的简单实例」· CS 代码 · 共 105 行

CS
105
字号
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace BLLandDAL
{
    public class ExpenseDAL
    {
        string connStr = "Data Source=(local);Initial Catalog=MyProject;User ID=sa;Password=000000";
        SqlConnection mysqlconn;

        public ExpenseDAL()
        {
            mysqlconn = new SqlConnection(connStr);
            if (mysqlconn.State == ConnectionState.Closed)
            {
                mysqlconn.Open();
            }
        }
        /// <summary>
        /// open database connection
        /// </summary>
        private  void OpenDBConn()
        {
            mysqlconn = new SqlConnection(connStr);
            if (mysqlconn.State == ConnectionState.Closed)
            {
                mysqlconn.Open();
            }
        }
        /// <summary>
        /// close database connection
        /// </summary>
        private void CloseDBConn()
        {
            if (mysqlconn.State == ConnectionState.Open)
            {
                mysqlconn.Close();
            }
        }

        //按照状态进行查询
        public DataTable GetAllExpenseAccountByStatus(string status)        
        {
            OpenDBConn();
            SqlCommand ExpAccount = new SqlCommand("ExpenseAccount_GetAllByStatus", mysqlconn);
            ExpAccount.CommandType = CommandType.StoredProcedure;

            ExpAccount.Parameters.Add("@AppStatus", SqlDbType.VarChar, 50);
            ExpAccount.Parameters["@AppStatus"].Value = status;

            SqlDataAdapter sda = new SqlDataAdapter(ExpAccount);
            DataSet ds = new DataSet();
            sda.Fill(ds);
            DataTable mydt = ds.Tables[0];

            CloseDBConn();
            return mydt;
           
        }

        //按照名称查询报销单
        public DataTable GetAllExpenseAccountByName(string UserName)
        {
            OpenDBConn();
            SqlCommand ExpAccount = new SqlCommand("ExpenseAccount_GetAllByUserName", mysqlconn);
            ExpAccount.CommandType = CommandType.StoredProcedure;

            ExpAccount.Parameters.Add("@UserName", SqlDbType.VarChar, 50);
            ExpAccount.Parameters["@UserName"].Value = UserName;

            SqlDataAdapter sda = new SqlDataAdapter(ExpAccount);
            DataSet ds = new DataSet();
            sda.Fill(ds);
            DataTable mydt = ds.Tables[0];

            CloseDBConn();
            return mydt;

        }

        //保存报销单的内容
        public void insertExpenseAccount(ExpenseAccountInfo eainfo)
        {
            OpenDBConn();
            SqlCommand ExpAccount = new SqlCommand("ExpenseAccount_Insert", mysqlconn);

            ExpAccount.CommandType = CommandType.StoredProcedure;
            ExpAccount.Parameters.Add("@ExpenseID", SqlDbType.UniqueIdentifier);
            ExpAccount.Parameters.Add("@Amount", SqlDbType.Money);
            ExpAccount.Parameters.Add("@Createdby", SqlDbType.VarChar,50);

            ExpAccount.Parameters["@ExpenseID"].Value = eainfo.ExpID;
            ExpAccount.Parameters["@Amount"].Value = eainfo.Amount;
            ExpAccount.Parameters["@Createdby"].Value = eainfo.UserName;
            ExpAccount.ExecuteNonQuery();

            CloseDBConn();
        }

    }
}

⌨️ 快捷键说明

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