Пример #1
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Maticsoft.Model.NewsType model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update NewsType set ");
            strSql.Append("Name=@Name");
            strSql.Append(" where Id=@Id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Name", SqlDbType.VarChar, 50),
                new SqlParameter("@Id",   SqlDbType.Int, 4)
            };
            parameters[0].Value = model.Name;
            parameters[1].Value = model.Id;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #2
0
 private void ShowInfo(int Id)
 {
     Maticsoft.BLL.NewsType   bll   = new Maticsoft.BLL.NewsType();
     Maticsoft.Model.NewsType model = bll.GetModel(Id);
     this.lblId.Text   = model.Id.ToString();
     this.lblName.Text = model.Name;
 }
Пример #3
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Maticsoft.Model.NewsType model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into NewsType(");
            strSql.Append("Name)");
            strSql.Append(" values (");
            strSql.Append("@Name)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Name", SqlDbType.VarChar, 50)
            };
            parameters[0].Value = model.Name;

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

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Пример #4
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public Maticsoft.Model.NewsType DataRowToModel(DataRow row)
 {
     Maticsoft.Model.NewsType model = new Maticsoft.Model.NewsType();
     if (row != null)
     {
         if (row["Id"] != null && row["Id"].ToString() != "")
         {
             model.Id = int.Parse(row["Id"].ToString());
         }
         if (row["Name"] != null)
         {
             model.Name = row["Name"].ToString();
         }
     }
     return(model);
 }
Пример #5
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            string strErr = "";

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            String Name = this.txtName.Text;

            Maticsoft.Model.NewsType model = new Maticsoft.Model.NewsType();
            model.Name = Name;

            Maticsoft.BLL.NewsType bll = new Maticsoft.BLL.NewsType();
            bll.Add(model);
            Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "Add.aspx");
        }
Пример #6
0
        public void btnSave_Click(object sender, EventArgs e)
        {
            string strErr = "";

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            int    Id   = int.Parse(this.lblId.Text);
            String Name = this.txtName.Text;


            Maticsoft.Model.NewsType model = new Maticsoft.Model.NewsType();
            model.Id   = Id;
            model.Name = Name;

            Maticsoft.BLL.NewsType bll = new Maticsoft.BLL.NewsType();
            bll.Update(model);
            Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "list.aspx");
        }
Пример #7
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Maticsoft.Model.NewsType GetModel(int Id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 Id,Name from NewsType ");
            strSql.Append(" where Id=@Id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Id", SqlDbType.Int, 4)
            };
            parameters[0].Value = Id;

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

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