protected void ibtnAdd_Click(object sender, ImageClickEventArgs e) { AusTypeInfo ausTypeInfo = new AusTypeInfo(); ausTypeInfo.id = Convert.ToInt32(Request.QueryString["id"]);//得到当前更改类别的id ausTypeInfo.typename = this.txtTypeName.Text.ToString(); if (this.iscy.Checked) { ausTypeInfo.iscy = "y"; } else { ausTypeInfo.iscy = "n"; } AusTypeInfo ausTypeInfocount = AusTypeInfoManager.GetModelByTypename(this.txtTypeName.Text.ToString());//得到该类别名称的实例 控制不会出现重复的类型名称 if (ausTypeInfocount == null) { bool count = AusTypeInfoManager.Update(ausTypeInfo); if (count == true) { Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "add", "<script>alert('更新成功');window.location='AusTypeList.aspx'</script>", false); } else { Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "add", "<script>alert('更新失败')</script>", false); } } else { if (ausTypeInfocount.id == ausTypeInfo.id)//判断其与所需要更新的类别的ID是否一样,如果一样可以更新。如果不一样就不能更新 { bool count = AusTypeInfoManager.Update(ausTypeInfo); if (count == true) { Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "add", "<script>alert('更新成功');window.location='AusTypeList.aspx'</script>", false); } else { Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "add", "<script>alert('更新失败')</script>", false); } } else { Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "", "alert('类型名称不能重复!');", true); } } }
protected void cuslist_ItemCommand(object source, RepeaterCommandEventArgs e) { string id = e.CommandArgument.ToString(); switch (e.CommandName) { case "Delete": AusTypeInfo typeInfo = AusTypeInfoManager.getAusTypesById(Convert.ToInt32(id)); string typeName = typeInfo.typename; int count = AusDetialInfoManager.getAusDetialInfoByAusType(typeName); if (count > 0) { this.Page.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('费用类别正在使用中,无法删除!');", true); } else { bool del = AusTypeInfoManager.Delete(Convert.ToInt32(id)); if (del == true) { Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "add", "<script>alert('删除成功');window.location='AusTypeList.aspx'</script>", false); } else { Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "add", "<script>alert('删除失败')</script>", true); } } break; case "Update": Response.Redirect("UpdateAusType.aspx?id=" + id); break; case "Tick": AusTypeInfo typeInfo1 = AusTypeInfoManager.getAusTypesById(Convert.ToInt32(id)); typeInfo1.iscy = "y"; AusTypeInfoManager.Update(typeInfo1); break; case "TurnBack": AusTypeInfo typeInfo2 = AusTypeInfoManager.getAusTypesById(Convert.ToInt32(id)); typeInfo2.iscy = "n"; AusTypeInfoManager.Update(typeInfo2); break; } dataBind(); }