Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            string strErr = "";

            if (this.txtname.Text == "")
            {
                strErr += "name不能为空!\\n";
            }
            if (this.txtzhaiyao.Text == "")
            {
                strErr += "zhaiyao不能为空!\\n";
            }

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            string   name    = this.txtname.Text;
            string   zhaiyao = this.txtzhaiyao.Text;
            DateTime Time    = DateTime.Now;

            ROYcms.Sys.Model.ROYcms_Role model = new ROYcms.Sys.Model.ROYcms_Role();
            model.name    = name;
            model.zhaiyao = zhaiyao;
            model.Time    = Time;

            ROYcms.Sys.BLL.ROYcms_Role bll = new ROYcms.Sys.BLL.ROYcms_Role();
            bll.Add(model);
        }
Exemple #2
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public ROYcms.Sys.Model.ROYcms_Role GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 id,name,zhaiyao,Time from " + PubConstant.date_prefix + "Role ");
            strSql.Append(" where id=@id ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@id", SqlDbType.Int, 4)
            };
            parameters[0].Value = id;

            ROYcms.Sys.Model.ROYcms_Role model = new ROYcms.Sys.Model.ROYcms_Role();
            DataSet ds = DbHelpers.GetDataSet(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["id"].ToString() != "")
                {
                    model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
                }
                model.name    = ds.Tables[0].Rows[0]["name"].ToString();
                model.zhaiyao = ds.Tables[0].Rows[0]["zhaiyao"].ToString();
                if (ds.Tables[0].Rows[0]["Time"].ToString() != "")
                {
                    model.Time = DateTime.Parse(ds.Tables[0].Rows[0]["Time"].ToString());
                }
                return(model);
            }
            else
            {
                return(null);
            }
        }
Exemple #3
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(ROYcms.Sys.Model.ROYcms_Role model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into " + PubConstant.date_prefix + "Role(");
            strSql.Append("name,zhaiyao,Time)");
            strSql.Append(" values (");
            strSql.Append("@name,@zhaiyao,@Time)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@name",    SqlDbType.VarChar,  50),
                new SqlParameter("@zhaiyao", SqlDbType.VarChar, 100),
                new SqlParameter("@Time",    SqlDbType.DateTime)
            };
            parameters[0].Value = model.name;
            parameters[1].Value = model.zhaiyao;
            parameters[2].Value = model.Time;

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

            if (obj == null)
            {
                return(1);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Exemple #4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="id"></param>
 private void ShowInfo(int id)
 {
     ROYcms.Sys.BLL.ROYcms_Role   bll   = new ROYcms.Sys.BLL.ROYcms_Role();
     ROYcms.Sys.Model.ROYcms_Role model = bll.GetModel(id);
     this.lblid.Text      = model.id.ToString();
     this.txtname.Text    = model.name;
     this.txtzhaiyao.Text = model.zhaiyao;
     // this.txtTime.Text = model.Time.ToString();
 }
Exemple #5
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(ROYcms.Sys.Model.ROYcms_Role model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update " + PubConstant.date_prefix + "Role set ");
            strSql.Append("name=@name,");
            strSql.Append("zhaiyao=@zhaiyao,");
            strSql.Append("Time=@Time");
            strSql.Append(" where id=@id ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@id",      SqlDbType.Int,       4),
                new SqlParameter("@name",    SqlDbType.VarChar,  50),
                new SqlParameter("@zhaiyao", SqlDbType.VarChar, 100),
                new SqlParameter("@Time",    SqlDbType.DateTime)
            };
            parameters[0].Value = model.id;
            parameters[1].Value = model.name;
            parameters[2].Value = model.zhaiyao;
            parameters[3].Value = model.Time;

            DbHelpers.NonQuery(strSql.ToString(), parameters);
        }