Beispiel #1
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            string strErr = "";

            if (this.txtsname.Text.Trim().Length == 0)
            {
                strErr += "sname不能为空!\\n";
            }
            if (this.txtsdescription.Text.Trim().Length == 0)
            {
                strErr += "sdescription不能为空!\\n";
            }

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            string sname        = this.txtsname.Text;
            string sdescription = this.txtsdescription.Text;

            myhouse.Model.Section model = new myhouse.Model.Section();
            model.sname        = sname;
            model.sdescription = sdescription;

            myhouse.BLL.SectionService bll = new myhouse.BLL.SectionService();
            bll.Add(model);
            Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "add.aspx");
        }
Beispiel #2
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(myhouse.Model.Section model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update t_section set ");
            strSql.Append("sname=@sname,");
            strSql.Append("sdescription=@sdescription");
            strSql.Append(" where sid=@sid");
            SqlParameter[] parameters =
            {
                new SqlParameter("@sname",        SqlDbType.VarChar,  30),
                new SqlParameter("@sdescription", SqlDbType.VarChar, 200),
                new SqlParameter("@sid",          SqlDbType.Int, 4)
            };
            parameters[0].Value = model.sname;
            parameters[1].Value = model.sdescription;
            parameters[2].Value = model.sid;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #3
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(myhouse.Model.Section model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into t_section(");
            strSql.Append("sname,sdescription)");
            strSql.Append(" values (");
            strSql.Append("@sname,@sdescription)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@sname",        SqlDbType.VarChar, 30),
                new SqlParameter("@sdescription", SqlDbType.VarChar, 200)
            };
            parameters[0].Value = model.sname;
            parameters[1].Value = model.sdescription;

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

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Beispiel #4
0
 private void ShowInfo(int sid)
 {
     myhouse.BLL.SectionService bll   = new myhouse.BLL.SectionService();
     myhouse.Model.Section      model = bll.GetModel(sid);
     this.lblsid.Text          = model.sid.ToString();
     this.lblsname.Text        = model.sname;
     this.lblsdescription.Text = model.sdescription;
 }
Beispiel #5
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public myhouse.Model.Section DataRowToModel(DataRow row)
 {
     myhouse.Model.Section model = new myhouse.Model.Section();
     if (row != null)
     {
         if (row["sid"] != null && row["sid"].ToString() != "")
         {
             model.sid = int.Parse(row["sid"].ToString());
         }
         if (row["sname"] != null)
         {
             model.sname = row["sname"].ToString();
         }
         if (row["sdescription"] != null)
         {
             model.sdescription = row["sdescription"].ToString();
         }
     }
     return(model);
 }
Beispiel #6
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public myhouse.Model.Section GetModel(int sid)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 sid,sname,sdescription from t_section ");
            strSql.Append(" where sid=@sid");
            SqlParameter[] parameters =
            {
                new SqlParameter("@sid", SqlDbType.Int, 4)
            };
            parameters[0].Value = sid;

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

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