//根据id查询 public Organiz GetByID(int id) { //拿到这个对象 Organiz org = null; string sql = string.Format("select * from EHS_Organizationunit where ID={0}", id); //把对象填充到Function里并返回 using (SqlDataReader reader = DBHelper.ExecuteReader(sql, type)) { if (reader.HasRows) { if (reader.Read()) { org = new Organiz(); org.ID = reader.GetInt32(0); org.Name = reader.GetString(1); org.Explanation = reader.GetString(2); org.SortID = reader.GetInt32(3); org.SecretKey = reader.GetString(4); org.ParentID = reader.GetInt32(5); org.ParentCode = reader.GetString(6); org.MenuLevel = reader.GetInt32(7); } } } return(org); }
protected void Page_Load(object sender, EventArgs e) { if (Request["name"] != null) { //接受参数封装对象 Organiz org = new Organiz(); org.Name = Request["name"]; org.Explanation = Request["desc"]; org.SortID = Convert.ToInt32(Request["sortID"]); org.SecretKey = Request["secretKey"]; org.ParentID = Convert.ToInt32(Request["parentID"]); org.ParentCode = Request["parentCode"]; org.MenuLevel = Convert.ToInt32(Request["level"]); org.UpdateTime = DateTime.Now; org.IsDel = 0; //添加到数据库里面去 OrganizDal dal = new OrganizDal(); int rows = dal.Add(org); //返回执行结果 Response.Clear(); Response.ContentType = "text/plain"; Response.ContentEncoding = System.Text.Encoding.UTF8; Response.Write(rows); Response.End(); } }
protected void Page_Load(object sender, EventArgs e) { //第一次访问先展示用户数据 if (Request["id"] != null) { ShowData(); } if (Request["name"] != null) { //封装对象 org = new Organiz(); org.ID = Convert.ToInt32(Request["id"]); org.Name = Request["name"]; org.Explanation = Request["desc"]; org.SortID = Convert.ToInt32(Request["sortID"]); org.SecretKey = Request["secretKey"]; org.ParentID = Convert.ToInt32(Request["parentID"]); org.ParentCode = Request["parentCode"]; org.MenuLevel = Convert.ToInt32(Request["level"]); org.UpdateTime = DateTime.Now; //进行修改 OrganizDal dal = new OrganizDal(); int rows = dal.Update(org); org = dal.GetByID(Convert.ToInt32(Request["id"])); //返回执行结果 Response.Clear(); Response.ContentType = "text/plain"; Response.ContentEncoding = System.Text.Encoding.UTF8; Response.Write(rows); Response.End(); } //修改的时候 //if (Request["name"] != null) //{ // //封装对象 // org = new Organiz(); // org.ID = Convert.ToInt32(Request["id"]); // org.Name = Request["name"]; // org.Explanation = Request["desc"]; // org.SortID = Convert.ToInt32(Request["sortID"]); // org.SecretKey = Request["secretKey"]; // org.ParentID = Convert.ToInt32(Request["parentID"]); // org.ParentCode = Request["parentCode"]; // org.MenuLevel = Convert.ToInt32(Request["level"]); // org.UpdateTime = DateTime.Now; // //进行修改 // OrganizDal dal = new OrganizDal(); // org = dal.GetByID(Convert.ToInt32(Request["id1"])); // int rows = dal.Update(org); // //返回执行结果 // Response.Clear(); // Response.ContentType = "text/plain"; // Response.ContentEncoding = System.Text.Encoding.UTF8; // Response.Write(rows); // Response.End(); //} }
//修改 public int Update(Organiz org) { string sql = "update EHS_Organizationunit set Name=@name,Explanation=@explanation,SortID=@sortID,SecretKey=@secretKey,ParentID=@parentID,ParentCode=@parentCode,MenuLevel=@menuLevel,UpdateTime=@updateTime where ID=@id"; SqlParameter[] pms = { new SqlParameter("@id", org.ID), new SqlParameter("@name", org.Name), new SqlParameter("@explanation", org.Explanation), new SqlParameter("@sortID", org.SortID), new SqlParameter("@secretKey", org.SecretKey), new SqlParameter("@parentID", org.ParentID), new SqlParameter("@parentCode", org.ParentCode), new SqlParameter("@menuLevel", org.MenuLevel), new SqlParameter("@updateTime", org.UpdateTime), }; return((int)DBHelper.ExecuteNonQuery(sql, type, pms)); }
//添加 public int Add(Organiz org) { string sql = "insert into EHS_Organizationunit values(@name,@explanation,@sortID,@secretKey,@parentID,@parentCode,@menuLevel,@updateTime,@isDel)"; SqlParameter[] pms = { new SqlParameter("@name", org.Name), new SqlParameter("@explanation", org.Explanation), new SqlParameter("@sortID", org.SortID), new SqlParameter("@secretKey", org.SecretKey), new SqlParameter("@parentID", org.ParentID), new SqlParameter("@parentCode", org.ParentCode), new SqlParameter("@menuLevel", org.MenuLevel), new SqlParameter("@updateTime", org.UpdateTime), new SqlParameter("@isDel", org.IsDel) }; return((int)DBHelper.ExecuteNonQuery(sql, type, pms)); }
//查询个数 public Organiz GetNum() { Organiz org = null; string sql = "select count(ID),Name from EHS_Organizationunit where ID in (select OUID from EHS_RoleOU WHERE RoleID=18)"; using (SqlDataReader reader = DBHelper.ExecuteReader(sql, type)) { if (reader.HasRows) { if (reader.Read()) { org.Num = reader.GetInt32(0); org.Name = reader.GetString(1); } } } return(org); }
//展示用户数据的函数 private void ShowData() { OrganizDal dal = new OrganizDal(); org = dal.GetByID(Convert.ToInt32(Request["id"])); }