Exemplo n.º 1
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            string strErr = "";

            if (this.txtRoleName.Text.Trim().Length == 0)
            {
                strErr += "RoleName不能为空!\\n";
            }
            if (this.txtDescription.Text.Trim().Length == 0)
            {
                strErr += "Description不能为空!\\n";
            }
            if (!PageValidate.IsDateTime(txtvalidateDate.Text))
            {
                strErr += "validateDate格式错误!\\n";
            }

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            string   RoleName     = this.txtRoleName.Text;
            string   Description  = this.txtDescription.Text;
            DateTime validateDate = DateTime.Parse(this.txtvalidateDate.Text);

            zs.Model.Sys_Role model = new zs.Model.Sys_Role();
            model.RoleName     = RoleName;
            model.Description  = Description;
            model.validateDate = validateDate;

            zs.BLL.Sys_Role bll = new zs.BLL.Sys_Role();
            bll.Add(model);
            Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "add.aspx");
        }
Exemplo n.º 2
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(zs.Model.Sys_Role model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into Sys_Role(");
            strSql.Append("RoleName,Description,validateDate)");
            strSql.Append(" values (");
            strSql.Append("@RoleName,@Description,@validateDate)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@RoleName",     SqlDbType.VarChar, 20),
                new SqlParameter("@Description",  SqlDbType.VarChar, 50),
                new SqlParameter("@validateDate", SqlDbType.DateTime)
            };
            parameters[0].Value = model.RoleName;
            parameters[1].Value = model.Description;
            parameters[2].Value = model.validateDate;

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

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(zs.Model.Sys_Role model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update Sys_Role set ");
            strSql.Append("RoleName=@RoleName,");
            strSql.Append("Description=@Description,");
            strSql.Append("validateDate=@validateDate");
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@RoleName",     SqlDbType.VarChar,   20),
                new SqlParameter("@Description",  SqlDbType.VarChar,   50),
                new SqlParameter("@validateDate", SqlDbType.DateTime),
                new SqlParameter("@ID",           SqlDbType.Int, 4)
            };
            parameters[0].Value = model.RoleName;
            parameters[1].Value = model.Description;
            parameters[2].Value = model.validateDate;
            parameters[3].Value = model.ID;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 4
0
 private void ShowInfo(int ID)
 {
     zs.BLL.Sys_Role   bll   = new zs.BLL.Sys_Role();
     zs.Model.Sys_Role model = bll.GetModel(ID);
     this.lblID.Text           = model.ID.ToString();
     this.txtRoleName.Text     = model.RoleName;
     this.txtDescription.Text  = model.Description;
     this.txtvalidateDate.Text = model.validateDate.ToString();
 }
Exemplo n.º 5
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public zs.Model.Sys_Role GetModel(int ID)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 ID,RoleName,Description,validateDate from Sys_Role ");
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@ID", SqlDbType.Int, 4)
            };
            parameters[0].Value = ID;

            zs.Model.Sys_Role model = new zs.Model.Sys_Role();
            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]["RoleName"] != null && ds.Tables[0].Rows[0]["RoleName"].ToString() != "")
                {
                    model.RoleName = ds.Tables[0].Rows[0]["RoleName"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Description"] != null && ds.Tables[0].Rows[0]["Description"].ToString() != "")
                {
                    model.Description = ds.Tables[0].Rows[0]["Description"].ToString();
                }
                if (ds.Tables[0].Rows[0]["validateDate"] != null && ds.Tables[0].Rows[0]["validateDate"].ToString() != "")
                {
                    model.validateDate = DateTime.Parse(ds.Tables[0].Rows[0]["validateDate"].ToString());
                }
                return(model);
            }
            else
            {
                return(null);
            }
        }