protected void ibtnAdd_Click(object sender, ImageClickEventArgs e) { AusTypeInfo ausTypeInfo = new AusTypeInfo(); 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.Add(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 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); } } }