コード例 #1
0
        /// <summary>
        /// ����һ������
        /// </summary>
        /// <param name="model">model</param>
        public int AddRecord(PUserRoleData model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("set nocount on; ");
            strSql.Append("insert into PUserRole(");
            strSql.Append("empId,roleId)");
            strSql.Append(" values (");
            strSql.Append("@empId,@roleId)");
            strSql.Append("; select @@identity; set nocount off; ");
            SqlParameter[] parameters = {
                    new SqlParameter("@empId", SqlDbType.Int),
                    new SqlParameter("@roleId", SqlDbType.Int)
                };
            parameters[0].Value = model.empId;
            parameters[1].Value = model.roleId;

            int id = 0;
            try
            {
                object ret = SqlHelper.ExecuteScalar(this.connection, this.transaction, CommandType.Text, strSql.ToString(), parameters);

                if (ret != null && ret != DBNull.Value)
                {
                    id = Convert.ToInt32(ret);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return id;
        }
コード例 #2
0
 protected void AddRole_Click(object sender, EventArgs e)
 {
     if (this.roleList.SelectedIndex > -1)
     {
         PUserRoleData model = new PUserRoleData();
         PUserRoleBB userRoleBB = new PUserRoleBB();
         try
         {
             model.empId = this.EmpId;
             model.roleId = Convert.ToInt32(this.roleList.SelectedValue);
             userRoleBB.AddRecord(model);
             this.BindDataList(this.roleList.SelectedIndex, 0);
         }
         finally
         {
             userRoleBB.Dispose();
         }
     }
 }
コード例 #3
0
 /// <summary>
 /// ����һ������
 /// </summary>
 /// <param name="model">model</param>
 public bool ModifyRecord(PUserRoleData model)
 {
     return this.userRoleDB.ModifyRecord(model);
 }
コード例 #4
0
 /// <summary>
 /// ����һ������
 /// </summary>
 /// <param name="model">model</param>
 public int AddRecord(PUserRoleData model)
 {
     return this.userRoleDB.AddRecord(model);
 }
コード例 #5
0
        /// <summary>
        /// ����һ������
        /// </summary>
        /// <param name="model">model</param>
        public bool ModifyRecord(PUserRoleData model)
        {
            bool ret = false;
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update PUserRole set ");
            strSql.Append("empId=@empId,");
            strSql.Append("roleId=@roleId");
            strSql.Append(" where id = @id ");
            SqlParameter[] parameters = {
                    new SqlParameter("@id", SqlDbType.Int),
                    new SqlParameter("@empId", SqlDbType.Int),
                    new SqlParameter("@roleId", SqlDbType.Int)
                };
            parameters[0].Value = model.id;
            parameters[1].Value = model.empId;
            parameters[2].Value = model.roleId;

            try
            {
                SqlHelper.ExecuteNonQuery(this.connection, this.transaction, CommandType.Text, strSql.ToString(), parameters);
                ret = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return ret;
        }
コード例 #6
0
        /// <summary>
        /// �õ�һ��model
        /// </summary>
        /// <param name="id">����ֵ</param>
        /// <returns>model</returns>
        public PUserRoleData GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * from PUserRole");
            strSql.Append(" where id = @id ");
            SqlParameter[] parameters = {
                    new SqlParameter("@id", SqlDbType.Int)
                };
            parameters[0].Value = id;

            PUserRoleData model = new PUserRoleData();
            DataSet ds = SqlHelper.ExecuteDataset(this.connection, this.transaction, CommandType.Text, strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                DataRow row = ds.Tables[0].Rows[0];
                if (row["id"] != DBNull.Value)
                {
                    model.id = Convert.ToInt32(row["id"]);
                }
                if (row["empId"] != DBNull.Value)
                {
                    model.empId = Convert.ToInt32(row["empId"]);
                }
                if (row["roleId"] != DBNull.Value)
                {
                    model.roleId = Convert.ToInt32(row["roleId"]);
                }
                return model;
            }
            else
            {
                return null;
            }
        }