Exemple #1
0
 private void ShowInfo(int aid)
 {
     myhouse.BLL.AnnounceService bll   = new myhouse.BLL.AnnounceService();
     myhouse.Model.Announce      model = bll.GetModel(aid);
     this.lblaid.Text        = model.aid.ToString();
     this.lblwid.Text        = model.wid.ToString();
     this.txtapublisher.Text = model.apublisher;
     this.txtatime.Text      = model.atime.ToString();
     this.txtatitle.Text     = model.atitle;
     this.txtacontent.Text   = model.acontent;
     this.txtatype.Text      = model.atype;
 }
Exemple #2
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            string strErr = "";

            if (!PageValidate.IsNumber(txtwid.Text))
            {
                strErr += "wid格式错误!\\n";
            }
            if (this.txtapublisher.Text.Trim().Length == 0)
            {
                strErr += "apublisher不能为空!\\n";
            }
            if (!PageValidate.IsDateTime(txtatime.Text))
            {
                strErr += "atime格式错误!\\n";
            }
            if (this.txtatitle.Text.Trim().Length == 0)
            {
                strErr += "atitle不能为空!\\n";
            }
            if (this.txtacontent.Text.Trim().Length == 0)
            {
                strErr += "acontent不能为空!\\n";
            }
            if (this.txtatype.Text.Trim().Length == 0)
            {
                strErr += "atype不能为空!\\n";
            }

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            int      wid        = int.Parse(this.txtwid.Text);
            string   apublisher = this.txtapublisher.Text;
            DateTime atime      = DateTime.Parse(this.txtatime.Text);
            string   atitle     = this.txtatitle.Text;
            string   acontent   = this.txtacontent.Text;
            string   atype      = this.txtatype.Text;

            myhouse.Model.Announce model = new myhouse.Model.Announce();
            model.wid        = wid;
            model.apublisher = apublisher;
            model.atime      = atime;
            model.atitle     = atitle;
            model.acontent   = acontent;
            model.atype      = atype;

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

            strSql.Append("update t_announce set ");
            strSql.Append("apublisher=@apublisher,");
            strSql.Append("atime=@atime,");
            strSql.Append("atitle=@atitle,");
            strSql.Append("acontent=@acontent,");
            strSql.Append("atype=@atype");
            strSql.Append(" where aid=@aid");
            SqlParameter[] parameters =
            {
                new SqlParameter("@apublisher", SqlDbType.Char,        10),
                new SqlParameter("@atime",      SqlDbType.DateTime),
                new SqlParameter("@atitle",     SqlDbType.VarChar,     50),
                new SqlParameter("@acontent",   SqlDbType.VarChar,   1000),
                new SqlParameter("@atype",      SqlDbType.Char,         4),
                new SqlParameter("@aid",        SqlDbType.Int,          4),
                new SqlParameter("@wid",        SqlDbType.Int, 4)
            };
            parameters[0].Value = model.apublisher;
            parameters[1].Value = model.atime;
            parameters[2].Value = model.atitle;
            parameters[3].Value = model.acontent;
            parameters[4].Value = model.atype;
            parameters[5].Value = model.aid;
            parameters[6].Value = model.wid;

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

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

            strSql.Append("insert into t_announce(");
            strSql.Append("wid,apublisher,atime,atitle,acontent,atype)");
            strSql.Append(" values (");
            strSql.Append("@wid,@apublisher,@atime,@atitle,@acontent,@atype)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@wid",        SqlDbType.Int,          4),
                new SqlParameter("@apublisher", SqlDbType.Char,        10),
                new SqlParameter("@atime",      SqlDbType.DateTime),
                new SqlParameter("@atitle",     SqlDbType.VarChar,     50),
                new SqlParameter("@acontent",   SqlDbType.VarChar,   1000),
                new SqlParameter("@atype",      SqlDbType.Char, 4)
            };
            parameters[0].Value = model.wid;
            parameters[1].Value = model.apublisher;
            parameters[2].Value = model.atime;
            parameters[3].Value = model.atitle;
            parameters[4].Value = model.acontent;
            parameters[5].Value = model.atype;

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

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Exemple #5
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public myhouse.Model.Announce DataRowToModel(DataRow row)
 {
     myhouse.Model.Announce model = new myhouse.Model.Announce();
     if (row != null)
     {
         if (row["aid"] != null && row["aid"].ToString() != "")
         {
             model.aid = int.Parse(row["aid"].ToString());
         }
         if (row["wid"] != null && row["wid"].ToString() != "")
         {
             model.wid = int.Parse(row["wid"].ToString());
         }
         if (row["apublisher"] != null)
         {
             model.apublisher = row["apublisher"].ToString();
         }
         if (row["atime"] != null && row["atime"].ToString() != "")
         {
             model.atime = DateTime.Parse(row["atime"].ToString());
         }
         if (row["atitle"] != null)
         {
             model.atitle = row["atitle"].ToString();
         }
         if (row["acontent"] != null)
         {
             model.acontent = row["acontent"].ToString();
         }
         if (row["atype"] != null)
         {
             model.atype = row["atype"].ToString();
         }
     }
     return(model);
 }
Exemple #6
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public myhouse.Model.Announce GetModel(int aid)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 aid,wid,apublisher,atime,atitle,acontent,atype from t_announce ");
            strSql.Append(" where aid=@aid");
            SqlParameter[] parameters =
            {
                new SqlParameter("@aid", SqlDbType.Int, 4)
            };
            parameters[0].Value = aid;

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

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