Exemplo n.º 1
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public zs.Model.Tbl_Message GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 id,name,mail,tel,conts,askTime,reply,replyTime,isShow from Tbl_Message ");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@id", SqlDbType.Int, 4)
            };
            parameters[0].Value = id;

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

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["id"] != null && ds.Tables[0].Rows[0]["id"].ToString() != "")
                {
                    model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
                }
                if (ds.Tables[0].Rows[0]["name"] != null && ds.Tables[0].Rows[0]["name"].ToString() != "")
                {
                    model.name = ds.Tables[0].Rows[0]["name"].ToString();
                }
                if (ds.Tables[0].Rows[0]["mail"] != null && ds.Tables[0].Rows[0]["mail"].ToString() != "")
                {
                    model.mail = ds.Tables[0].Rows[0]["mail"].ToString();
                }
                if (ds.Tables[0].Rows[0]["tel"] != null && ds.Tables[0].Rows[0]["tel"].ToString() != "")
                {
                    model.tel = ds.Tables[0].Rows[0]["tel"].ToString();
                }
                if (ds.Tables[0].Rows[0]["conts"] != null && ds.Tables[0].Rows[0]["conts"].ToString() != "")
                {
                    model.conts = ds.Tables[0].Rows[0]["conts"].ToString();
                }
                if (ds.Tables[0].Rows[0]["askTime"] != null && ds.Tables[0].Rows[0]["askTime"].ToString() != "")
                {
                    model.askTime = DateTime.Parse(ds.Tables[0].Rows[0]["askTime"].ToString());
                }
                if (ds.Tables[0].Rows[0]["reply"] != null && ds.Tables[0].Rows[0]["reply"].ToString() != "")
                {
                    model.reply = ds.Tables[0].Rows[0]["reply"].ToString();
                }
                if (ds.Tables[0].Rows[0]["replyTime"] != null && ds.Tables[0].Rows[0]["replyTime"].ToString() != "")
                {
                    model.replyTime = DateTime.Parse(ds.Tables[0].Rows[0]["replyTime"].ToString());
                }
                if (ds.Tables[0].Rows[0]["isShow"] != null && ds.Tables[0].Rows[0]["isShow"].ToString() != "")
                {
                    model.isShow = int.Parse(ds.Tables[0].Rows[0]["isShow"].ToString());
                }
                return(model);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 2
0
 private void ShowInfo(int id)
 {
     zs.BLL.Tbl_Message   bll   = new zs.BLL.Tbl_Message();
     zs.Model.Tbl_Message model = bll.GetModel(id);
     this.lblid.Text        = model.id.ToString();
     this.txtname.Text      = model.name;
     this.txtmail.Text      = model.mail;
     this.txttel.Text       = model.tel;
     this.txtconts.Text     = model.conts;
     this.txtaskTime.Text   = model.askTime.ToString();
     this.txtreply.Text     = model.reply;
     this.txtreplyTime.Text = model.replyTime.ToString();
     this.txtisShow.Text    = model.isShow.ToString();
 }
Exemplo n.º 3
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(zs.Model.Tbl_Message model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update Tbl_Message set ");
            strSql.Append("name=@name,");
            strSql.Append("mail=@mail,");
            strSql.Append("tel=@tel,");
            strSql.Append("title=@title,");
            strSql.Append("conts=@conts,");
            strSql.Append("askTime=@askTime,");
            strSql.Append("reply=@reply,");
            strSql.Append("replyTime=@replyTime,");
            strSql.Append("isShow=@isShow");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@name",      SqlDbType.VarChar,    10),
                new SqlParameter("@mail",      SqlDbType.VarChar,    50),
                new SqlParameter("@tel",       SqlDbType.VarChar,    20),
                new SqlParameter("@title",     SqlDbType.VarChar,    50),
                new SqlParameter("@conts",     SqlDbType.VarChar,   550),
                new SqlParameter("@askTime",   SqlDbType.DateTime),
                new SqlParameter("@reply",     SqlDbType.VarChar,   550),
                new SqlParameter("@replyTime", SqlDbType.DateTime),
                new SqlParameter("@isShow",    SqlDbType.Int,         4),
                new SqlParameter("@id",        SqlDbType.Int, 4)
            };
            parameters[0].Value = model.name;
            parameters[1].Value = model.mail;
            parameters[2].Value = model.tel;
            parameters[3].Value = model.title;
            parameters[4].Value = model.conts;
            parameters[5].Value = model.askTime;
            parameters[6].Value = model.reply;
            parameters[7].Value = model.replyTime;
            parameters[8].Value = model.isShow;
            parameters[9].Value = model.id;

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

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

            strSql.Append("insert into Tbl_Message(");
            strSql.Append("name,mail,tel,title,conts,askTime,reply,replyTime,isShow)");
            strSql.Append(" values (");
            strSql.Append("@name,@mail,@tel,@title,@conts,@askTime,@reply,@replyTime,@isShow)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@name",      SqlDbType.VarChar,    10),
                new SqlParameter("@mail",      SqlDbType.VarChar,    50),
                new SqlParameter("@tel",       SqlDbType.VarChar,    20),
                new SqlParameter("@title",     SqlDbType.VarChar,    50),
                new SqlParameter("@conts",     SqlDbType.VarChar,   550),
                new SqlParameter("@askTime",   SqlDbType.DateTime),
                new SqlParameter("@reply",     SqlDbType.VarChar,   550),
                new SqlParameter("@replyTime", SqlDbType.DateTime),
                new SqlParameter("@isShow",    SqlDbType.Int, 4)
            };
            parameters[0].Value = model.name;
            parameters[1].Value = model.mail;
            parameters[2].Value = model.tel;
            parameters[3].Value = model.title;
            parameters[4].Value = model.conts;
            parameters[5].Value = model.askTime;
            parameters[6].Value = model.reply;
            parameters[7].Value = model.replyTime;
            parameters[8].Value = model.isShow;

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

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Exemplo n.º 5
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            string strErr = "";

            if (this.txtname.Text.Trim().Length == 0)
            {
                strErr += "name不能为空!\\n";
            }
            if (this.txtmail.Text.Trim().Length == 0)
            {
                strErr += "mail不能为空!\\n";
            }
            if (this.txttel.Text.Trim().Length == 0)
            {
                strErr += "tel不能为空!\\n";
            }
            if (this.txtconts.Text.Trim().Length == 0)
            {
                strErr += "conts不能为空!\\n";
            }
            if (!PageValidate.IsDateTime(txtaskTime.Text))
            {
                strErr += "askTime格式错误!\\n";
            }
            if (this.txtreply.Text.Trim().Length == 0)
            {
                strErr += "reply不能为空!\\n";
            }
            if (!PageValidate.IsDateTime(txtreplyTime.Text))
            {
                strErr += "replyTime格式错误!\\n";
            }
            if (!PageValidate.IsNumber(txtisShow.Text))
            {
                strErr += "是否显示格式错误!\\n";
            }

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            string   name      = this.txtname.Text;
            string   mail      = this.txtmail.Text;
            string   tel       = this.txttel.Text;
            string   conts     = this.txtconts.Text;
            DateTime askTime   = DateTime.Parse(this.txtaskTime.Text);
            string   reply     = this.txtreply.Text;
            DateTime replyTime = DateTime.Parse(this.txtreplyTime.Text);
            int      isShow    = int.Parse(this.txtisShow.Text);

            zs.Model.Tbl_Message model = new zs.Model.Tbl_Message();
            model.name      = name;
            model.mail      = mail;
            model.tel       = tel;
            model.conts     = conts;
            model.askTime   = askTime;
            model.reply     = reply;
            model.replyTime = replyTime;
            model.isShow    = isShow;

            zs.BLL.Tbl_Message bll = new zs.BLL.Tbl_Message();
            bll.Add(model);
            Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "add.aspx");
        }