//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(); } }
//检索栏,新增样品类型按钮 protected void BtnNew_Click(object sender, EventArgs e) { Clear(); //this.Info_EMFM_Code.Text = Guid.NewGuid().ToString(); LblNewSampletype.Text = "新建样品类型"; Panel_NewSampletype.Visible = true; UpdatePanel_NewSampletype.Update(); LblState.Text = "New"; }
//维护窗口,提交按钮 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(); } }