//检索栏,重置按钮 protected void BtnReset_Click(object sender, EventArgs e) { TxtSampleType.Text = ""; Bindc = ""; BindGridview(Bindc); UpdatePanel_SampleType.Update(); }
//GridView中编辑、删除 protected void Grid_SampleType_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Edit_Sampletype") { GridViewRow row = ((LinkButton)e.CommandSource).Parent.Parent as GridViewRow; Grid_SampleType.SelectedIndex = row.RowIndex; Clear(); Panel_NewSampletype.Visible = true; UpdatePanel_NewSampletype.Update(); LblState.Text = "Edit"; id = new Guid(e.CommandArgument.ToString()); ExpSampleType_ExpItems ST = expTestL.Search_ExpSampleType_ID(id)[0]; LblNewSampletype.Text = ST.EST_SampleType + " 编辑"; TxtNewSampletype.Text = ST.EST_SampleType; UpdatePanel_NewSampletype.Update(); } if (e.CommandName == "Delete_Sampletype") { GridViewRow row = ((LinkButton)e.CommandSource).Parent.Parent as GridViewRow; Grid_SampleType.SelectedIndex = row.RowIndex; Guid guid = new Guid(e.CommandArgument.ToString()); expTestL.Delete_ExpSampleType(guid); BindGridview(Bindc); UpdatePanel_SampleType.Update(); } }
static string Bindc = "";//记录检索栏检索条件用于绑定gridview1数据 #region 页面加载 protected void Page_Load(object sender, EventArgs e) { string Role = Request.QueryString["state"].ToString(); if (!IsPostBack) { Title = "样品类型维护页面"; if (!((Session["UserRole"].ToString().Contains("样品类型维护")) || (Session["UserRole"].ToString().Contains("样品类型查看")))) { Response.Redirect("~/Default.aspx"); } } if (Role == "Sample" && Session["UserRole"].ToString().Contains("样品类型维护")) { Button2.Visible = true; Grid_SampleType.Columns[3].Visible = true; Grid_SampleType.Columns[4].Visible = true; } else if (Role == "Sample" && Session["UserRole"].ToString().Contains("样品类型查看")) { Button2.Visible = false; Grid_SampleType.Columns[3].Visible = false; Grid_SampleType.Columns[4].Visible = false; } BindGridview(Bindc); UpdatePanel_SampleType.Update(); }
//维护窗口,提交按钮 protected void BtnSubmit_Click(object sender, EventArgs e) { if (LblState.Text == "New") { expSampleType_ExpItems.EST_SampleTypeID = Guid.NewGuid(); if (TxtNewSampletype.Text == "") { ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "alert", "alert('标记*的为必填项,请填写完整!')", true); return; } else if (TextLength(TxtNewSampletype.Text) > 50) { ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "alert", "alert('请输入字数不要超过25个!')", true); return; } else { expSampleType_ExpItems.EST_SampleType = TxtNewSampletype.Text; } expSampleType_ExpItems.EST_IsDeleted = false; try { if (expTestL.Insert_ExpSampleType(expSampleType_ExpItems) <= 0) { ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "alert", "alert('该样品类型已经存在!')", true); return; } //expTestL.Insert_ExpSampleType(expSampleType_ExpItems); } catch (Exception exc) { ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "alert", "alert('新增失败!" + exc + "')", true); } ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "alert", "alert('提交成功!')", true); Clear(); Bindc = ""; BindGridview(Bindc); Panel_NewSampletype.Visible = false; UpdatePanel_SampleType.Update(); UpdatePanel_NewSampletype.Update(); } if (LblState.Text == "Edit") { ExpSampleType_ExpItems ST = new ExpSampleType_ExpItems(); if (TxtNewSampletype.Text == "") { ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "alert", "alert('标记*的为必填项,请填写完整!')", true); return; } else if (TextLength(TxtNewSampletype.Text) > 50) { ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "alert", "alert('请输入字数不要超过25个!')", true); return; } else { ST.EST_SampleType = TxtNewSampletype.Text; } ST.EST_SampleTypeID = id; try { if (expTestL.Update_ExpSampleType(ST) <= 0) { ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "alert", "alert('该样品类型已经存在!')", true); return; } //expTestL.Update_ExpSampleType(ST); } catch (Exception ex) { ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "alert", "alert('编辑失败!" + ex + "')", true); return; } ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "alert", "alert('提交成功!')", true); Clear(); BindGridview(Bindc); Panel_NewSampletype.Visible = false; UpdatePanel_SampleType.Update(); UpdatePanel_NewSampletype.Update(); } }
//检索栏,检索按钮 protected void BtnSearch_Click(object sender, EventArgs e) { Bindc = TxtSampleType.Text; BindGridview(Bindc); UpdatePanel_SampleType.Update(); }