protected void btnSave_Click(object sender, EventArgs e) { char[] RValueArray = new Char[100]; for (int i = 0; i < MyRepeater.Items.Count; i++) { CheckBoxList checkBoxItem = (CheckBoxList)(MyRepeater.Controls[i].FindControl("MyCheckBoxList")); for (int j = 0; j < checkBoxItem.Items.Count; j++) { RValueArray[int.Parse(checkBoxItem.Items[j].Value)] = checkBoxItem.Items[j].Selected ? '1' : '0'; //RValue += checkBoxItem.Items[j].Selected ? 1 : 0; } } String RValue = new String(RValueArray); string RoleValue = RValue; string RoleNumber = this.txtRoleNumber.Text; string RoleName = this.txtRoleName.Text; string RoleDescription = this.txtRoleDescription.Text; CHSS.Model.CRole model = new CHSS.Model.CRole(); model.RoleNumber = RoleNumber; model.RoleName = RoleName; model.RoleValue = RoleValue; model.RoleDescription = RoleDescription; CHSS.BLL.CRole bll = new CHSS.BLL.CRole(); bll.Add(model); Response.Redirect("Show.aspx?id=" + (bll.GetMaxId() - 1)); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(CHSS.Model.CRole model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update CRole set "); strSql.Append("RoleNumber=@RoleNumber,"); strSql.Append("RoleName=@RoleName,"); strSql.Append("RoleValue=@RoleValue,"); strSql.Append("RoleDescription=@RoleDescription"); strSql.Append(" where RID=@RID"); SqlParameter[] parameters = { new SqlParameter("@RoleNumber", SqlDbType.VarChar, 50), new SqlParameter("@RoleName", SqlDbType.NVarChar, 50), new SqlParameter("@RoleValue", SqlDbType.VarChar, 100), new SqlParameter("@RoleDescription", SqlDbType.NVarChar, 200), new SqlParameter("@RID", SqlDbType.Int, 4) }; parameters[0].Value = model.RoleNumber; parameters[1].Value = model.RoleName; parameters[2].Value = model.RoleValue; parameters[3].Value = model.RoleDescription; parameters[4].Value = model.RID; int rows = DBHelper.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(CHSS.Model.CRole model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into CRole("); strSql.Append("RoleNumber,RoleName,RoleValue,RoleDescription)"); strSql.Append(" values ("); strSql.Append("@RoleNumber,@RoleName,@RoleValue,@RoleDescription)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@RoleNumber", SqlDbType.VarChar, 50), new SqlParameter("@RoleName", SqlDbType.NVarChar, 50), new SqlParameter("@RoleValue", SqlDbType.VarChar, 100), new SqlParameter("@RoleDescription", SqlDbType.NVarChar, 200) }; parameters[0].Value = model.RoleNumber; parameters[1].Value = model.RoleName; parameters[2].Value = model.RoleValue; parameters[3].Value = model.RoleDescription; object obj = DBHelper.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public CHSS.Model.CRole DataRowToModel(DataRow row) { CHSS.Model.CRole model = new CHSS.Model.CRole(); if (row != null) { if (row["RID"] != null && row["RID"].ToString() != "") { model.RID = int.Parse(row["RID"].ToString()); } if (row["RoleNumber"] != null) { model.RoleNumber = row["RoleNumber"].ToString(); } if (row["RoleName"] != null) { model.RoleName = row["RoleName"].ToString(); } if (row["RoleValue"] != null) { model.RoleValue = row["RoleValue"].ToString(); } if (row["RoleDescription"] != null) { model.RoleDescription = row["RoleDescription"].ToString(); } } return(model); }
private void ShowInfo(int RID) { CHSS.BLL.CRole bll = new CHSS.BLL.CRole(); CHSS.Model.CRole model = bll.GetModel(RID); this.txtRID.Text = model.RID.ToString(); this.txtRoleNumber.Text = model.RoleNumber; this.txtRoleName.Text = model.RoleName; this.txtRoleDescription.Text = model.RoleDescription; RValue = model.RoleValue.ToCharArray(); DataSet ds = new CHSS.BLL.CModule().GetAllList(); MyRepeater.DataSource = ds; MyRepeater.DataBind(); //int recordCount = new CHSS.BLL.CModule().GetRecordCount(""); //for (int i = 0; i < recordCount; i++) //{ // CheckBoxList checkBoxItem = (CheckBoxList)(MainDiv.FindControl("CheckBoxList" + (i + 1).ToString())); // for (int j = 0; j < checkBoxItem.Items.Count; j++) // { // checkBoxItem.Items[j].Selected = RValue[i * 4 + j] == '1' ? true : false; // //if (RValue[i * 4 + j] == '1') // // checkBoxItem.Items[j].Selected = true; // //else // // checkBoxItem.Items[j].Selected = false; // } //} }
private void ShowInfo(int RID) { CHSS.BLL.CRole bll = new CHSS.BLL.CRole(); CHSS.Model.CRole model = bll.GetModel(RID); this.txtRID.Text = model.RID.ToString(); this.txtRoleNumber.Text = model.RoleNumber; this.txtRoleName.Text = model.RoleName; this.txtRoleDescription.Text = model.RoleDescription; RValue = model.RoleValue.ToCharArray(); DataSet ds = new CHSS.BLL.CModule().GetAllList(); MyRepeater.DataSource = ds; MyRepeater.DataBind(); }
/// <summary> /// 得到一个对象实体 /// </summary> public CHSS.Model.CRole GetModel(int RID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 RID,RoleNumber,RoleName,RoleValue,RoleDescription from CRole "); strSql.Append(" where RID=@RID"); SqlParameter[] parameters = { new SqlParameter("@RID", SqlDbType.Int, 4) }; parameters[0].Value = RID; CHSS.Model.CRole model = new CHSS.Model.CRole(); DataSet ds = DBHelper.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }