/// <summary> /// 控件行命令事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void repInfo_ItemCommand(object source, RepeaterCommandEventArgs e) { if (e.CommandName.Equals("del")) { int id = Convert.ToInt32(e.CommandArgument); TypeInfoService.Delete(id); sp.InitBindData(this.repInfo, pager1, "TypeInfo", "id", sear()); } if (e.CommandName.Equals("mod")) { Label lblName = e.Item.FindControl("lblName") as Label; lblName.Visible = false; TextBox txtName = e.Item.FindControl("txtModName") as TextBox; txtName.Visible = true; LinkButton lbtnMod = e.Item.FindControl("lbtnMod") as LinkButton; lbtnMod.Visible = false; LinkButton lbtnSave = e.Item.FindControl("lbtnSave") as LinkButton; lbtnSave.Visible = true; this.hidId.Value = e.CommandArgument.ToString(); } if (e.CommandName.Equals("save")) { TextBox txtName = e.Item.FindControl("txtModName") as TextBox; string name = txtName.Text.Trim(); if (name.Length == 0) { ScriptManager.RegisterStartupScript(UpdatePanel1, GetType(), "", "alert('名称不能为空!');", true); return; } TypeInfo nt = TypeInfoService.GetModel(Convert.ToInt32(hidId.Value)); if (nt != null) { nt.typeName = name; nt.id = Convert.ToInt32(e.CommandArgument); if (TypeInfoService.Exists(nt)) { ScriptManager.RegisterStartupScript(UpdatePanel1, GetType(), "", "alert('名称已经存在!');", true); sp.InitBindData(this.repInfo, pager1, "TypeInfo", "id", sear()); return; } TypeInfoService.Update(nt.id, nt.typeName); } sp.InitBindData(this.repInfo, pager1, "TypeInfo", "id", sear()); } }
/// <summary> /// 添加事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Button1_Click(object sender, EventArgs e) { lblError.Text = ""; TypeInfo item = new TypeInfo(); if (ddlParent.SelectedValue == "0") { lblError.Text = "请选择大类!"; return; } item.infoType = Convert.ToInt32(ddlParent.SelectedValue); if (this.txtTitle.Text.Trim().Length == 0) { lblError.Text = "分类名称不能为空!"; return; } item.typeName = txtTitle.Text.Trim(); item.typeValue = 0; item.remark = ""; item.status = 1; item.remark = ""; item.addTime = DateTime.Now; item.addUser = 0; if (Session["loginUser"] != null) { item.addUser = (Session["loginUser"] as AdminUser).id; } string hidId = this.hidId.Value; if (TypeInfoService.Exists(item)) { lblError.Text = "该分类以及存在"; return; } TypeInfoService.Add(item); txtTitle.Text = ""; sp.InitBindData(this.repInfo, pager1, "TypeInfo", "id", sear()); }