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

            strSql.Append("update RoleType set ");
            strSql.Append("RoleName=@RoleName,");
            strSql.Append("Remark=@Remark,");
            strSql.Append("Priority=@Priority");
            strSql.Append(" where RoleID=@RoleID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@RoleName", SqlDbType.VarChar,  50),
                new SqlParameter("@Remark",   SqlDbType.VarChar, 500),
                new SqlParameter("@Priority", SqlDbType.Int,       4),
                new SqlParameter("@RoleID",   SqlDbType.Int, 4)
            };
            parameters[0].Value = model.RoleName;
            parameters[1].Value = model.Remark;
            parameters[2].Value = model.Priority;
            parameters[3].Value = model.RoleID;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #2
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(WebDemo.Model.WebDemo.RoleType model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into RoleType(");
            strSql.Append("RoleName,Remark,Priority)");
            strSql.Append(" values (");
            strSql.Append("@RoleName,@Remark,@Priority)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@RoleName", SqlDbType.VarChar,  50),
                new SqlParameter("@Remark",   SqlDbType.VarChar, 500),
                new SqlParameter("@Priority", SqlDbType.Int, 4)
            };
            parameters[0].Value = model.RoleName;
            parameters[1].Value = model.Remark;
            parameters[2].Value = model.Priority;

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

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Пример #3
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            string strErr = "";

            if (this.txtRoleName.Text.Trim().Length == 0)
            {
                strErr += "RoleName不能为空!\\n";
            }
            if (this.txtRemark.Text.Trim().Length == 0)
            {
                strErr += "备注信息不能为空!\\n";
            }
            if (!PageValidate.IsNumber(txtPriority.Text))
            {
                strErr += "Priority格式错误!\\n";
            }

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            string RoleName = this.txtRoleName.Text;
            string Remark   = this.txtRemark.Text;
            int    Priority = int.Parse(this.txtPriority.Text);

            WebDemo.Model.WebDemo.RoleType model = new WebDemo.Model.WebDemo.RoleType();
            model.RoleName = RoleName;
            model.Remark   = Remark;
            model.Priority = Priority;

            WebDemo.BLL.WebDemo.RoleType bll = new WebDemo.BLL.WebDemo.RoleType();
            bll.Add(model);
            Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "add.aspx");
        }
Пример #4
0
 private void ShowInfo(int RoleID)
 {
     WebDemo.BLL.WebDemo.RoleType   bll   = new WebDemo.BLL.WebDemo.RoleType();
     WebDemo.Model.WebDemo.RoleType model = bll.GetModel(RoleID);
     this.lblRoleID.Text   = model.RoleID.ToString();
     this.txtRoleName.Text = model.RoleName;
     this.txtRemark.Text   = model.Remark;
     this.txtPriority.Text = model.Priority.ToString();
 }
Пример #5
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public WebDemo.Model.WebDemo.RoleType DataRowToModel(DataRow row)
 {
     WebDemo.Model.WebDemo.RoleType model = new WebDemo.Model.WebDemo.RoleType();
     if (row != null)
     {
         if (row["RoleID"] != null && row["RoleID"].ToString() != "")
         {
             model.RoleID = int.Parse(row["RoleID"].ToString());
         }
         if (row["RoleName"] != null)
         {
             model.RoleName = row["RoleName"].ToString();
         }
         if (row["Remark"] != null)
         {
             model.Remark = row["Remark"].ToString();
         }
         if (row["Priority"] != null && row["Priority"].ToString() != "")
         {
             model.Priority = int.Parse(row["Priority"].ToString());
         }
     }
     return(model);
 }
Пример #6
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public WebDemo.Model.WebDemo.RoleType GetModel(int RoleID)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 RoleID,RoleName,Remark,Priority from RoleType ");
            strSql.Append(" where RoleID=@RoleID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@RoleID", SqlDbType.Int, 4)
            };
            parameters[0].Value = RoleID;

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

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