Beispiel #1
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Maticsoft.Model.Message model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update Message set ");
            strSql.Append("UserName=@UserName,");
            strSql.Append("Title=@Title,");
            strSql.Append("Content=@Content,");
            strSql.Append("Time=@Time,");
            strSql.Append("Email=@Email,");
            strSql.Append("Mobile=@Mobile,");
            strSql.Append("Phone=@Phone,");
            strSql.Append("Mark=@Mark,");
            strSql.Append("S1=@S1");
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@UserName", SqlDbType.NVarChar,   50),
                new SqlParameter("@Title",    SqlDbType.NVarChar,   50),
                new SqlParameter("@Content",  SqlDbType.NVarChar,   -1),
                new SqlParameter("@Time",     SqlDbType.DateTime),
                new SqlParameter("@Email",    SqlDbType.NVarChar,   50),
                new SqlParameter("@Mobile",   SqlDbType.Char,       11),
                new SqlParameter("@Phone",    SqlDbType.Char,       11),
                new SqlParameter("@Mark",     SqlDbType.Int,         4),
                new SqlParameter("@S1",       SqlDbType.NVarChar,  100),
                new SqlParameter("@ID",       SqlDbType.Int, 4)
            };
            parameters[0].Value = model.UserName;
            parameters[1].Value = model.Title;
            parameters[2].Value = model.Content;
            parameters[3].Value = model.Time;
            parameters[4].Value = model.Email;
            parameters[5].Value = model.Mobile;
            parameters[6].Value = model.Phone;
            parameters[7].Value = model.Mark;
            parameters[8].Value = model.S1;
            parameters[9].Value = model.ID;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #2
0
 private void ShowInfo(int ID)
 {
     Maticsoft.BLL.Message   bll   = new Maticsoft.BLL.Message();
     Maticsoft.Model.Message model = bll.GetModel(ID);
     this.lblID.Text       = model.ID.ToString();
     this.lblUserName.Text = model.UserName;
     this.lblTitle.Text    = model.Title;
     this.lblContent.Text  = model.Content;
     this.lblTime.Text     = model.Time.ToString();
     this.lblEmail.Text    = model.Email;
     this.lblMobile.Text   = model.Mobile;
     this.lblPhone.Text    = model.Phone;
     this.lblMark.Text     = model.Mark.ToString();
     this.lblS1.Text       = model.S1;
 }
Beispiel #3
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public Maticsoft.Model.Message DataRowToModel(DataRow row)
 {
     Maticsoft.Model.Message model = new Maticsoft.Model.Message();
     if (row != null)
     {
         if (row["ID"] != null && row["ID"].ToString() != "")
         {
             model.ID = int.Parse(row["ID"].ToString());
         }
         if (row["UserName"] != null)
         {
             model.UserName = row["UserName"].ToString();
         }
         if (row["Title"] != null)
         {
             model.Title = row["Title"].ToString();
         }
         if (row["Content"] != null)
         {
             model.Content = row["Content"].ToString();
         }
         if (row["Time"] != null && row["Time"].ToString() != "")
         {
             model.Time = DateTime.Parse(row["Time"].ToString());
         }
         if (row["Email"] != null)
         {
             model.Email = row["Email"].ToString();
         }
         if (row["Mobile"] != null)
         {
             model.Mobile = row["Mobile"].ToString();
         }
         if (row["Phone"] != null)
         {
             model.Phone = row["Phone"].ToString();
         }
         if (row["Mark"] != null && row["Mark"].ToString() != "")
         {
             model.Mark = int.Parse(row["Mark"].ToString());
         }
         if (row["S1"] != null)
         {
             model.S1 = row["S1"].ToString();
         }
     }
     return(model);
 }
Beispiel #4
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Maticsoft.Model.Message model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into Message(");
            strSql.Append("UserName,Title,Content,Time,Email,Mobile,Phone,Mark,S1)");
            strSql.Append(" values (");
            strSql.Append("@UserName,@Title,@Content,@Time,@Email,@Mobile,@Phone,@Mark,@S1)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@UserName", SqlDbType.NVarChar,  50),
                new SqlParameter("@Title",    SqlDbType.NVarChar,  50),
                new SqlParameter("@Content",  SqlDbType.NVarChar,  -1),
                new SqlParameter("@Time",     SqlDbType.DateTime),
                new SqlParameter("@Email",    SqlDbType.NVarChar,  50),
                new SqlParameter("@Mobile",   SqlDbType.Char,      11),
                new SqlParameter("@Phone",    SqlDbType.Char,      11),
                new SqlParameter("@Mark",     SqlDbType.Int,        4),
                new SqlParameter("@S1",       SqlDbType.NVarChar, 100)
            };
            parameters[0].Value = model.UserName;
            parameters[1].Value = model.Title;
            parameters[2].Value = model.Content;
            parameters[3].Value = model.Time;
            parameters[4].Value = model.Email;
            parameters[5].Value = model.Mobile;
            parameters[6].Value = model.Phone;
            parameters[7].Value = model.Mark;
            parameters[8].Value = model.S1;

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

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Beispiel #5
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Maticsoft.Model.Message GetModel(int ID)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 ID,UserName,Title,Content,Time,Email,Mobile,Phone,Mark,S1 from Message ");
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@ID", SqlDbType.Int, 4)
            };
            parameters[0].Value = ID;

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

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }
Beispiel #6
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            string strErr = "";

            if (this.txtUserName.Text.Trim().Length == 0)
            {
                strErr += "称呼不能为空!\\n";
            }
            if (this.txtTitle.Text.Trim().Length == 0)
            {
                strErr += "标题不能为空!\\n";
            }
            if (this.txtContent.Text.Trim().Length == 0)
            {
                strErr += "内容不能为空!\\n";
            }
            if (!PageValidate.IsDateTime(txtTime.Text))
            {
                strErr += "发布时间格式错误!\\n";
            }
            if (this.txtEmail.Text.Trim().Length == 0)
            {
                strErr += "电子邮箱不能为空!\\n";
            }
            if (this.txtMobile.Text.Trim().Length == 0)
            {
                strErr += "手机不能为空!\\n";
            }
            if (this.txtPhone.Text.Trim().Length == 0)
            {
                strErr += "电话不能为空!\\n";
            }
            if (!PageValidate.IsNumber(txtMark.Text))
            {
                strErr += "Mark格式错误!\\n";
            }
            if (this.txtS1.Text.Trim().Length == 0)
            {
                strErr += "备用不能为空!\\n";
            }

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            string   UserName = this.txtUserName.Text;
            string   Title    = this.txtTitle.Text;
            string   Content  = this.txtContent.Text;
            DateTime Time     = DateTime.Parse(this.txtTime.Text);
            string   Email    = this.txtEmail.Text;
            string   Mobile   = this.txtMobile.Text;
            string   Phone    = this.txtPhone.Text;
            int      Mark     = int.Parse(this.txtMark.Text);
            string   S1       = this.txtS1.Text;

            Maticsoft.Model.Message model = new Maticsoft.Model.Message();
            model.UserName = UserName;
            model.Title    = Title;
            model.Content  = Content;
            model.Time     = Time;
            model.Email    = Email;
            model.Mobile   = Mobile;
            model.Phone    = Phone;
            model.Mark     = Mark;
            model.S1       = S1;

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