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

📄 kitchendaoimpl.cs

📁 一个超市管理系统,没有错误,非常好,里面什么都有!很使用,很有用
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DaFanRongMIS.Model.Kitchen;

namespace DaFanRongMIS.Model.Kitchen
{
    public class KitchenDAOImpl:KitchenDAO
    {
        #region 增加
       public string AddKitchen(KitchenEntity Kitchen)
        {
            string str = "";

            //声明并设置SqlCommand命令
            
            SqlCommand cmdadd = new SqlCommand();
            cmdadd.Connection = Common.ConnectionDataBase.getConOpen();
            cmdadd.CommandType = CommandType.StoredProcedure;
            cmdadd.CommandText = "Add_Kitchen";
            
            //结束声明和设置SqlCommand命令


            //参数赋值
            SqlParameter ShopIDAdd = new SqlParameter("@ShopID", SqlDbType.VarChar, 2);
            ShopIDAdd.Value = Kitchen.ShopID;
            cmdadd.Parameters.Add(ShopIDAdd);

            SqlParameter IDAdd=new SqlParameter("@ID",SqlDbType.VarChar,2);
            IDAdd.Value = Kitchen.ID;
            cmdadd.Parameters.Add(IDAdd);

            SqlParameter NameAdd = new SqlParameter("@Name", SqlDbType.VarChar, 20);
            NameAdd.Value = Kitchen.Name;
            cmdadd.Parameters.Add(NameAdd);


            SqlParameter MemoAdd = new SqlParameter("@Memo", SqlDbType.VarChar, 2000);
            MemoAdd.Value = Kitchen.Memo;
            cmdadd.Parameters.Add(MemoAdd);
            //结束参数赋值

            //打开库,执行,关闭库
            try
            {

                cmdadd.Connection = Common.ConnectionDataBase.getConOpen();
                cmdadd.ExecuteNonQuery();
                str = "OK";

            }
            catch (Exception ee)
            {
                str = ee.Message;
            }
            finally
            {
                Common.ConnectionDataBase.getConClose();
            }
            //结束打开库,执行,关闭库
            
            return str;
        }
        #endregion

        #region 修改
       public string UpdateKitchen(KitchenEntity Kitchen)
        {
            string str = "";

            //声明并设置SqlCommand命令

            SqlCommand cmdupdate = new SqlCommand();
            cmdupdate.Connection = Common.ConnectionDataBase.getConOpen();
            cmdupdate.CommandType = CommandType.StoredProcedure;
            cmdupdate.CommandText = "Update__Kitchen";

            //结束声明和设置SqlCommand命令


            //参数赋值
            SqlParameter ShopIDUpdate = new SqlParameter("@ShopID", SqlDbType.VarChar, 2);
            ShopIDUpdate.Value = Kitchen.ShopID;
            cmdupdate.Parameters.Add(ShopIDUpdate);

            SqlParameter IDUpdate = new SqlParameter("@ID", SqlDbType.VarChar, 2);
            IDUpdate.Value = Kitchen.ID;
            cmdupdate.Parameters.Add(IDUpdate);

            SqlParameter NameUpdate = new SqlParameter("@Name", SqlDbType.VarChar, 20);
            NameUpdate.Value = Kitchen.Name;
            cmdupdate.Parameters.Add(NameUpdate);


            SqlParameter MemoUpdate = new SqlParameter("@Memo", SqlDbType.VarChar, 2000);
            MemoUpdate.Value = Kitchen.Memo;
            cmdupdate.Parameters.Add(MemoUpdate);
            //结束参数赋值

            //打开库,执行,关闭库
            try
            {

                cmdupdate.Connection = Common.ConnectionDataBase.getConOpen();

                cmdupdate.ExecuteNonQuery();

                str = "OK";

            }
            catch (Exception ee)
            {
                str = ee.Message;
            }
            finally
            {
                Common.ConnectionDataBase.getConClose();
            }
            //结束打开库,执行,关闭库

            return str;
        }
        #endregion

        #region 删除
       public string DeleteKitchen(KitchenEntity Kitchen)
        {
            string str = "";

            //声明并设置SqlCommand命令

            SqlCommand cmddelete = new SqlCommand();
            cmddelete.Connection = Common.ConnectionDataBase.getConOpen();
            cmddelete.CommandType = CommandType.StoredProcedure;
            cmddelete.CommandText = "Delete_Kitchen";

            //结束声明和设置SqlCommand命令


            //参数赋值
            SqlParameter ShopIDDelete = new SqlParameter("@ShopID", SqlDbType.VarChar, 2);
            ShopIDDelete.Value = Kitchen.ShopID;
            cmddelete.Parameters.Add(ShopIDDelete);

            SqlParameter IDDelete = new SqlParameter("@ID", SqlDbType.VarChar, 2);
            IDDelete.Value = Kitchen.ID;
            cmddelete.Parameters.Add(IDDelete);

         
            //结束参数赋值

            //打开库,执行,关闭库
            try
            {

                cmddelete.Connection = Common.ConnectionDataBase.getConOpen();

                cmddelete.ExecuteNonQuery();

                str = "OK";

            }
            catch (Exception ee)
            {
                str = ee.Message;
            }
            finally
            {
                Common.ConnectionDataBase.getConClose();
            }
            //结束打开库,执行,关闭库

            return str;
        }
        #endregion

        #region 查找(无条件)
        public DataTable SelectKitchen(KitchenEntity Kitchen)
        {
            SqlDataAdapter da = new SqlDataAdapter();
            DataSet ds = new DataSet();
            DataTable dt = new DataTable();
            SqlCommand cmd = new SqlCommand();
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "Select_Kitchen";
            cmd.Connection = Common.ConnectionDataBase.getConOpen();
            da.SelectCommand = cmd;
            da.Fill(ds);
            dt = ds.Tables[0];
            return dt;
        }
        #endregion

        #region 查找(有条件)
        public DataTable SelectedKitchen( KitchenEntity Kitchen)
        {
            SqlDataAdapter da = new SqlDataAdapter();
            DataSet ds = new DataSet();
            DataTable dt = new DataTable();
            SqlCommand cmdSelect = new SqlCommand();
            cmdSelect.CommandType = CommandType.StoredProcedure;
            cmdSelect.CommandText = "Selected_Kitchen";
            cmdSelect.Connection = Common.ConnectionDataBase.getConOpen();

            string str = "";

            //参数赋值
            SqlParameter ShopIDSelect = new SqlParameter("@ShopID", SqlDbType.VarChar, 2);
            ShopIDSelect.Value = Kitchen.ShopID;
            cmdSelect.Parameters.Add(ShopIDSelect);

            SqlParameter IDSelect = new SqlParameter("@ID", SqlDbType.VarChar, 2);
            IDSelect.Value = Kitchen.ID;
            cmdSelect.Parameters.Add(IDSelect);

            SqlParameter NameSelect = new SqlParameter("@Name", SqlDbType.VarChar, 20);
            NameSelect.Value = Kitchen.Name;
            cmdSelect.Parameters.Add(NameSelect);

            SqlParameter MemoSelect = new SqlParameter("@Memo", SqlDbType.VarChar, 2000);
            MemoSelect.Value = Kitchen.Memo;
            cmdSelect.Parameters.Add(MemoSelect);
            ////结束参数赋值

            da.SelectCommand = cmdSelect;
            da.Fill(ds);
            dt = ds.Tables[0];
            return dt;
        }

        #endregion

        #region 查找(最大编号)
        public DataTable SelectMaxIDKitchen(KitchenEntity Kitchen)
        {

            SqlDataAdapter da = new SqlDataAdapter();
            DataSet ds = new DataSet();
            DataTable dt = new DataTable();
            SqlCommand cmd = new SqlCommand();
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "SelectMaxID_Kitchen";
            cmd.Connection = Common.ConnectionDataBase.getConOpen();

            //参数赋值
            SqlParameter ShopIDSelect = new SqlParameter("@ShopID", SqlDbType.VarChar, 2);
            ShopIDSelect.Value = Kitchen.ShopID;
            cmd.Parameters.Add(ShopIDSelect);

            SqlParameter IDSelect = new SqlParameter("@ID", SqlDbType.VarChar, 2);
            IDSelect.Value = Kitchen.ID;
            cmd.Parameters.Add(IDSelect);

            SqlParameter NameSelect = new SqlParameter("@Name", SqlDbType.VarChar, 20);
            NameSelect.Value = Kitchen.Name;
            cmd.Parameters.Add(NameSelect);

            SqlParameter MemoSelect = new SqlParameter("@Memo", SqlDbType.VarChar, 2000);
            MemoSelect.Value = Kitchen.Memo;
            cmd.Parameters.Add(MemoSelect);
            ////结束参数赋值

            da.SelectCommand = cmd;
            da.Fill(ds);
            dt = ds.Tables[0];
            return dt;
        }
        #endregion

    }
}

⌨️ 快捷键说明

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