Exemplo n.º 1
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Maticsoft.Model.BaseData model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update BaseData set ");
            strSql.Append("TableName=@TableName,");
            strSql.Append("KeyID=@KeyID,");
            strSql.Append("Name=@Name,");
            strSql.Append("IsActive=@IsActive,");
            strSql.Append("Display=@Display,");
            strSql.Append("ClassName=@ClassName");
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@TableName", SqlDbType.NVarChar, 50),
                new SqlParameter("@KeyID",     SqlDbType.Int,       4),
                new SqlParameter("@Name",      SqlDbType.NVarChar, 50),
                new SqlParameter("@IsActive",  SqlDbType.Int,       4),
                new SqlParameter("@Display",   SqlDbType.Int,       4),
                new SqlParameter("@ClassName", SqlDbType.NVarChar, 50),
                new SqlParameter("@ID",        SqlDbType.Int, 4)
            };
            parameters[0].Value = model.TableName;
            parameters[1].Value = model.KeyID;
            parameters[2].Value = model.Name;
            parameters[3].Value = model.IsActive;
            parameters[4].Value = model.Display;
            parameters[5].Value = model.ClassName;
            parameters[6].Value = model.ID;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Maticsoft.Model.BaseData model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into BaseData(");
            strSql.Append("TableName,KeyID,Name,IsActive,Display,ClassName)");
            strSql.Append(" values (");
            strSql.Append("@TableName,@KeyID,@Name,@IsActive,@Display,@ClassName)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@TableName", SqlDbType.NVarChar, 50),
                new SqlParameter("@KeyID",     SqlDbType.Int,       4),
                new SqlParameter("@Name",      SqlDbType.NVarChar, 50),
                new SqlParameter("@IsActive",  SqlDbType.Int,       4),
                new SqlParameter("@Display",   SqlDbType.Int,       4),
                new SqlParameter("@ClassName", SqlDbType.NVarChar, 50)
            };
            parameters[0].Value = model.TableName;
            parameters[1].Value = model.KeyID;
            parameters[2].Value = model.Name;
            parameters[3].Value = model.IsActive;
            parameters[4].Value = model.Display;
            parameters[5].Value = model.ClassName;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public Maticsoft.Model.BaseData DataRowToModel(DataRow row)
 {
     Maticsoft.Model.BaseData model = new Maticsoft.Model.BaseData();
     if (row != null)
     {
         if (row["ID"] != null && row["ID"].ToString() != "")
         {
             model.ID = int.Parse(row["ID"].ToString());
         }
         if (row["TableName"] != null)
         {
             model.TableName = row["TableName"].ToString();
         }
         if (row["KeyID"] != null && row["KeyID"].ToString() != "")
         {
             model.KeyID = int.Parse(row["KeyID"].ToString());
         }
         if (row["Name"] != null)
         {
             model.Name = row["Name"].ToString();
         }
         if (row["IsActive"] != null && row["IsActive"].ToString() != "")
         {
             model.IsActive = int.Parse(row["IsActive"].ToString());
         }
         if (row["Display"] != null && row["Display"].ToString() != "")
         {
             model.Display = int.Parse(row["Display"].ToString());
         }
         if (row["ClassName"] != null)
         {
             model.ClassName = row["ClassName"].ToString();
         }
     }
     return(model);
 }
Exemplo n.º 4
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Maticsoft.Model.BaseData GetModel(int ID)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 ID,TableName,KeyID,Name,IsActive,Display,ClassName from BaseData ");
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@ID", SqlDbType.Int, 4)
            };
            parameters[0].Value = ID;

            Maticsoft.Model.BaseData model = new Maticsoft.Model.BaseData();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }