GRIT VIEW删除事件
1.点选表格后找到事件 RowCommand
2.輸入gvGroupUser_RowCommand后双击 ------注分别为:GV属性ID名称—事件名
3. protected void gvGroupUser_RowCommand(object sender, GridViewCommandEventArgs e) ---使用传递到事件处理方法的GridViewCommandEventArgs对象确定引发事件的按钮的命令名 。GridViewCommandEventArgs e对象,与对象参数
{
pnlDevAuth.Visible = true; ------获取或设置一个值,该值指示服务器控件是否作为UI呈现在页面上 (nlDevAuth容器控件名称)
string v_DevGrpID = lblDevGrpID.Text; ------声明v_DevGrpID获取 lblDevGrpID.Text的内容 (v_DevGrpID 局部设备群组ID)
if (e.CommandName == "DelUserInGrp") ------获取命令名称 (CommandName属性。可以让窗体上的多个按钮来处理一个事件,可以标记多个按钮,使代码根据窗体上单击的按钮进行逻辑判断)
{
string uid = e.CommandArgument.ToString(); -------获取命令的参数
string ReturnStatus = string.Empty; -------表示空字符串,此字段为只读 (返回状态)
string ReturnID = string.Empty;
string ReturnMsg = string.Empty;
try
{
Coeno.Card.DevAuths.DelAuthGrpUser(Int32.Parse(uid), txtCurrentEmpID.Text, out ReturnStatus, out ReturnID, out ReturnMsg);
if (ReturnStatus == "1")
{
lblMsg.Text = ReturnMsg;
lblMsg.ForeColor = System.Drawing.Color.Blue;
labMsg.Text = ReturnMsg;
labMsg.ForeColor = System.Drawing.Color.Blue;
}
else
{
lblMsg.Text = ReturnMsg;
lblMsg.ForeColor = System.Drawing.Color.Red;
labMsg.Text = ReturnMsg;
labMsg.ForeColor = System.Drawing.Color.Red;
}
}
catch (Exception ex)
{
lblMsg.Text = "刪除失敗:" + ReturnMsg;
lblMsg.ForeColor = System.Drawing.Color.Red;
labMsg.Text = "刪除失敗:" + ReturnMsg;
labMsg.ForeColor = System.Drawing.Color.Red;
return;
}
}
DataTable dtDevGrpUsers = Coeno.Card.DevAuths.QueryDevGrpUsers(ddlSite.SelectedValue, ddlFactory.SelectedValue, v_DevGrpID, txtEmpIDAdd.Text, "", "1" );
gvGroupUser.DataSource = dtDevGrpUsers;
gvGroupUser.DataBind();
}
///刪除群組用戶(ByUID)
public static void DelAuthGrpUser(int v_UID, string v_CUser, out string v_ReturnStatus, out string v_ReturnID, out string v_ReturnMsg)
{
SqlConnection con = new SqlConnection(_connectionString);
SqlCommand comm = new SqlCommand( "Card_DevGrp_AuthDel_Emp" , con);
comm.CommandType = CommandType.StoredProcedure;
comm.Parameters.Add( "@UID" , SqlDbType.Int).Value = v_UID;
comm.Parameters.Add( "@CUser" , SqlDbType.NVarChar, 50).Value = v_CUser;
comm.Parameters.Add( "@ReturnStatus" , SqlDbType.NVarChar, 5);
comm.Parameters.Add( "@ReturnID" , SqlDbType.NVarChar, 10);
comm.Parameters.Add( "@ReturnMsg" , SqlDbType.NVarChar, 100);
comm.Parameters[ "@ReturnStatus" ].Direction = ParameterDirection.Output;
comm.Parameters[ "@ReturnID" ].Direction = ParameterDirection.Output;
comm.Parameters[ "@ReturnMsg" ].Direction = ParameterDirection.Output;
try
{
con.Open();
comm.ExecuteNonQuery();
v_ReturnStatus = comm.Parameters[ "@ReturnStatus" ].Value.ToString();
v_ReturnID = comm.Parameters[ "@ReturnID" ].Value.ToString();
v_ReturnMsg = comm.Parameters[ "@ReturnMsg" ].Value.ToString();
}
catch (Exception ex)
{
v_ReturnStatus = "0" ;
v_ReturnID = "999" ;
v_ReturnMsg = "Execute Stored Procedure Failed!!!(" + ex.Message + ")" ;
}
finally
{
con.Close();
}
}
///权限查询
查詢Card_Dev_AuthGrp_User且啟用
public static DataTable QueryDevGrpUsers(string v_Site, string v_FactoryID, string v_AuthGrpID, string v_EmpID, string v_EmpName, string v_Enableflag)
{
v_EmpID = Coeno.Web.SDBC.ToDBC(v_EmpID);
string sql = "SELECT a.UID,a.AuthGrpID,a.EmpID,a.EmpName,b.SiteID,b.FactoryAliasID,b.AuthGrpID,b.AuthGrpCName,c.DeptID,c.DeptName,c.BUID,c.SexID,a.EffectDayID,a.cuser
FROM Card_Dev_AuthGrp_User a,Card_Dev_AuthGrp b,HR_Emp_Now c
WHERE a.AuthGrpID=b.AuthGrpID and a.EmpID=c.EmpID" ;
string sql_where = " AND " ;
if (v_Site != "ALL" )
{
sql = sql + sql_where + "b.SiteID =' " + v_Site + " ' " ;
}
if (v_FactoryID != "ALL" )
{
sql = sql + sql_where + "b.FactoryID =' " + v_FactoryID + " ' " ;
}
if (v_AuthGrpID != "ALL" )
{
sql = sql + sql_where + "a.AuthGrpID =' " + v_AuthGrpID + " ' " ;
}
if (!string.IsNullOrEmpty(v_EmpID))
{
sql = sql + sql_where + "a.EmpID =' " + v_EmpID + " ' " ;
}
if (!string.IsNullOrEmpty(v_EmpName))
{
sql = sql + sql_where + "a.EmpName = N ' " + v_EmpName + " ' " ;
}
if (v_Enableflag != "ALL" )
{
sql = sql + sql_where + " a.EnableFlag=' " + v_Enableflag + " ' " ;
}
sql = sql + " ORDER BY EmpID " ;
SqlConnection con = new SqlConnection(_connectionString);
SqlDataAdapter dad = new SqlDataAdapter(sql, con);
DataSet dst = new DataSet();
try
{
con.Open();
dad.Fill(dst, "QueryDevGrpUsers" );
}
catch (SqlException e)
{
throw new Exception(e.Message);
}
finally
{
con.Close();
}
return dst.Tables[0];
}
<asp:ImageButton ID="ibDel" runat="server" ImageUrl="~/Images/Button/button_delete.gif"
CommandName="DelUserInGrp" CommandArgument='<%# Eval("UID")%>' ToolTip="刪除" OnClientClick="return confirm('確定要刪除該人員權限嗎?');" />