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

📄 picturedal.cs

📁 CRM管理系统 CRM管理系统
💻 CS
字号:
//------------------------------------
//版权所有:杭州商易信息技术有限公司
//功能描述:参数管理控制类
//    作者:沈伟
//    日期:2008/08/21
//------------------------------------/
using System;
using System.Data;
using System.Text;
using SystemFrameworks;
using System.Data.SqlClient;
namespace Itsv.DAL.SystemManage
{
    public class PictureDAL
    {
        public PictureDAL()
        { }

        #region  成员方法

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int pic_id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from pictures where pic_id=" + pic_id + "");
            object obj = DbHelperSQL.GetSingle(strSql.ToString());
            int cmdresult;
            if ((Object.Equals(obj, null)) || (Object.Equals(obj, System.DBNull.Value)))
            {
                cmdresult = 0;
            }
            else
            {
                cmdresult = int.Parse(obj.ToString());
            }
            if (cmdresult == 0)
            {
                return false;
            }
            else
            {
                return true;
            }
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Itsv.Model.Picture model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" Begin ");
            strSql.Append("insert into pictures(");
            strSql.Append("pic_name,pic_comment,pic_img,pic_type)");
            strSql.Append(" values (");
            strSql.Append("@pic_name,@pic_comment,@pic_img,@pic_type)");
            SqlParameter[] parameters = {
					new SqlParameter("@pic_name", SqlDbType.NVarChar),
					new SqlParameter("@pic_comment", SqlDbType.VarChar,100),
					new SqlParameter("@pic_img", SqlDbType.Image,16),
					new SqlParameter("@pic_type", SqlDbType.Int,4),
                    new SqlParameter("@pic_id", SqlDbType.Int,4)};
            strSql.Append(";");
            strSql.Append("set @pic_id=@@identity;");
            strSql.Append("end");
            parameters[0].Value = model.pic_name;
            parameters[1].Value = model.pic_comment;
            parameters[2].Value = model.pic_img;
            parameters[3].Value = model.pic_type;
            parameters[4].Direction = ParameterDirection.Output;
            DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            int a = Convert.ToInt32(parameters[4].Value.ToString());
            return a;
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(Itsv.Model.Picture model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update pictures set ");
            strSql.Append("pic_name=@pic_name,");
            strSql.Append("pic_comment=@pic_comment,");
            strSql.Append("pic_img=@pic_img,");
            strSql.Append("pic_type=@pic_type");
            strSql.Append(" where pic_id=@pic_id");
            SqlParameter[] parameters = {
					new SqlParameter("@pic_id", SqlDbType.Int,4),
					new SqlParameter("@pic_name", SqlDbType.NVarChar),
					new SqlParameter("@pic_comment", SqlDbType.VarChar,100),
					new SqlParameter("@pic_img", SqlDbType.Image,16),
					new SqlParameter("@pic_type", SqlDbType.Int,4)};
            parameters[0].Value = model.pic_id;
            parameters[1].Value = model.pic_name;
            parameters[2].Value = model.pic_comment;
            parameters[3].Value = model.pic_img;
            parameters[4].Value = model.pic_type;

            DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public void Delete(int pic_id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete pictures ");
            strSql.Append(" where pic_id=" + pic_id);
            DbHelperSQL.ExecuteSql(strSql.ToString());
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Itsv.Model.Picture GetModel(int pic_id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * from pictures ");
            strSql.Append(" where pic_id=" + pic_id);
            Itsv.Model.Picture model = new Itsv.Model.Picture();
            DataSet ds = DbHelperSQL.Query(strSql.ToString());
            model.pic_id = pic_id;
            if (ds.Tables[0].Rows.Count > 0)
            {
                model.pic_name = ds.Tables[0].Rows[0]["pic_name"].ToString();
                model.pic_comment = ds.Tables[0].Rows[0]["pic_comment"].ToString();
                if (ds.Tables[0].Rows[0]["pic_img"].ToString() != "")
                {
                    model.pic_img = null;//(byte[])ds.Tables[0].Rows[0]["pic_img"].ToString();
                }
                if (ds.Tables[0].Rows[0]["pic_type"].ToString() != "")
                {
                    model.pic_type = int.Parse(ds.Tables[0].Rows[0]["pic_type"].ToString());
                }
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * from pictures ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by pic_id ");
            return DbHelperSQL.Query(strSql.ToString());
        }
        #endregion  成员方法
    }
}

⌨️ 快捷键说明

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