protected void btnAdd_Click(object sender, EventArgs e) { PEmpPermissionsData empPermissionsData = new PEmpPermissionsData(); PEmpPermissionsBB empPermissionsBB = new PEmpPermissionsBB(); HEemployeeBB eemployeeBB = new HEemployeeBB(); try { //删除当前人员所有权限 empPermissionsBB.DeleteRecordByEmp(this.EmpId, 2); //保存权限 CheckBox checkBox = new CheckBox(); foreach (DataListItem item in this.DataList1.Items) { //获取ItemoNo Label label = (Label)item.FindControl("itemNo"); string itemNo = label.Text; if (itemNo.IndexOf('-') >= 0) { itemNo = itemNo.Substring(itemNo.LastIndexOf('-') + 1); } foreach (System.Web.UI.Control control in item.Controls) { if (control.GetType() == checkBox.GetType()) { if (((CheckBox)control).Checked == true && !eemployeeBB.HasPermissions(this.EmpId, itemNo, ((CheckBox)control).ToolTip)) { //保存权限 empPermissionsData.empId = this.EmpId; empPermissionsData.itemNo = itemNo; empPermissionsData.permissionsTypeNo = ((CheckBox)control).ToolTip; empPermissionsData.isSpecial = false; empPermissionsBB.AddRecord(empPermissionsData); } } } } } catch (Exception ex) { this.ClientScript.RegisterStartupScript(this.GetType(), "ShowErr", "ShowErr(\"" + Server.UrlEncode(ex.Message) + "\",3);", true); return; } finally { empPermissionsBB.Dispose(); eemployeeBB.Dispose(); } this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('保存成功!');", true); }
/// <summary> /// ����һ������ /// </summary> /// <param name="model">model</param> public int AddRecord(PEmpPermissionsData model) { StringBuilder strSql = new StringBuilder(); strSql.Append("set nocount on; "); strSql.Append("insert into PEmpPermissions("); strSql.Append("empId,itemNo,permissionsTypeNo,isSpecial,mark)"); strSql.Append(" values ("); strSql.Append("@empId,@itemNo,@permissionsTypeNo,@isSpecial,@mark)"); strSql.Append("; select @@identity; set nocount off; "); SqlParameter[] parameters = { new SqlParameter("@empId", SqlDbType.Int), new SqlParameter("@itemNo", SqlDbType.NVarChar,20), new SqlParameter("@permissionsTypeNo", SqlDbType.NVarChar,50), new SqlParameter("@isSpecial", SqlDbType.Bit), new SqlParameter("@mark", SqlDbType.NVarChar,200) }; parameters[0].Value = model.empId; parameters[1].Value = model.itemNo; parameters[2].Value = model.permissionsTypeNo; parameters[3].Value = model.isSpecial; parameters[4].Value = model.mark; 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; }
/// <summary> /// ����һ������ /// </summary> /// <param name="model">model</param> public bool ModifyRecord(PEmpPermissionsData model) { return this.empPermissionsDB.ModifyRecord(model); }
/// <summary> /// ����һ������ /// </summary> /// <param name="model">model</param> public int AddRecord(PEmpPermissionsData model) { return this.empPermissionsDB.AddRecord(model); }
/// <summary> /// ����һ������ /// </summary> /// <param name="model">model</param> public bool ModifyRecord(PEmpPermissionsData model) { bool ret = false; StringBuilder strSql = new StringBuilder(); strSql.Append("update PEmpPermissions set "); strSql.Append("empId=@empId,"); strSql.Append("itemNo=@itemNo,"); strSql.Append("permissionsTypeNo=@permissionsTypeNo,"); strSql.Append("isSpecial=@isSpecial,"); strSql.Append("mark=@mark"); strSql.Append(" where id = @id "); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int), new SqlParameter("@empId", SqlDbType.Int), new SqlParameter("@itemNo", SqlDbType.NVarChar,20), new SqlParameter("@permissionsTypeNo", SqlDbType.NVarChar,50), new SqlParameter("@isSpecial", SqlDbType.Bit), new SqlParameter("@mark", SqlDbType.NVarChar,200) }; parameters[0].Value = model.id; parameters[1].Value = model.empId; parameters[2].Value = model.itemNo; parameters[3].Value = model.permissionsTypeNo; parameters[4].Value = model.isSpecial; parameters[5].Value = model.mark; try { SqlHelper.ExecuteNonQuery(this.connection, this.transaction, CommandType.Text, strSql.ToString(), parameters); ret = true; } catch (Exception ex) { throw ex; } return ret; }
/// <summary> /// �õ�һ��model /// </summary> /// <param name="id">����ֵ</param> /// <returns>model</returns> public PEmpPermissionsData GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select * from PEmpPermissions"); strSql.Append(" where id = @id "); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int) }; parameters[0].Value = id; PEmpPermissionsData model = new PEmpPermissionsData(); 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["itemNo"] != DBNull.Value) { model.itemNo = Convert.ToString(row["itemNo"]); } if (row["permissionsTypeNo"] != DBNull.Value) { model.permissionsTypeNo = Convert.ToString(row["permissionsTypeNo"]); } if (row["isSpecial"] != DBNull.Value) { model.isSpecial = Convert.ToBoolean(row["isSpecial"]); } if (row["mark"] != DBNull.Value) { model.mark = Convert.ToString(row["mark"]); } return model; } else { return null; } }