protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { GridViewApproveLeave.DataBind(); } LoadLeaveDates(); }
protected void ButtonApproveLeaves_Click(object sender, EventArgs e) { foreach (GridViewRow row in GridViewApproveLeave.Rows) { CheckBox status = (row.Cells[3].FindControl("CheckBoxSelectReq") as CheckBox); string EmployeeID = (row.Cells[1].Text); string date = (row.Cells[4].Text); if (status.Checked) { updaterow(EmployeeID, "Approved", date); Label2.Text = V; } GridViewApproveLeave.DataBind(); } void updaterow(string EmployeeID, string Req_Status, string date) { try { SqlConnection con = new SqlConnection(strcon); string squery = "UPDATE dbo.[Leaves] set Req_Status='" + Req_Status + "' where Employee_ID='" + EmployeeID + "'AND Req_Date='" + date + "'"; if (con.State == ConnectionState.Closed) { con.Open(); } SqlCommand cmd = new SqlCommand(); cmd.CommandText = squery; cmd.Connection = con; cmd.ExecuteNonQuery(); con.Close(); } catch (Exception ex) { Response.Write("< script >alert ('" + ex.Message + "');</ Script >"); } } }
protected void ButtonDecSubmit_Click(object sender, EventArgs e) { if (DropDownListDeclineReason.SelectedItem.Text == "Other") { foreach (GridViewRow row in GridViewApproveLeave.Rows) { CheckBox status = (row.Cells[3].FindControl("CheckBoxSelectReq") as CheckBox); string EmployeeID = (row.Cells[1].Text); if (status.Checked) { updateNewrow(EmployeeID, "Declined"); Label2.Text = V; } GridViewApproveLeave.DataBind(); } } else { foreach (GridViewRow row in GridViewApproveLeave.Rows) { CheckBox status = (row.Cells[3].FindControl("CheckBoxSelectReq") as CheckBox); string EmployeeID = (row.Cells[1].Text); if (status.Checked) { updaterow(EmployeeID, "Declined"); Label2.Text = V; } GridViewApproveLeave.DataBind(); } } void updaterow(string EmployeeID, string Req_Status) { try { SqlConnection con = new SqlConnection(strcon); string squery = "UPDATE dbo.[Leaves] set Req_Status='" + Req_Status + "',Decline_ID='" + DropDownListDeclineReason.SelectedItem.Value + "' where Employee_ID='" + EmployeeID + "'"; if (con.State == ConnectionState.Closed) { con.Open(); } SqlCommand cmd = new SqlCommand(); cmd.CommandText = squery; cmd.Connection = con; cmd.ExecuteNonQuery(); con.Close(); } catch (Exception ex) { Response.Write("< script >alert ('" + ex.Message + "');</ Script >"); } } void updateNewrow(string EmployeeID, string Req_Status) { try { SqlConnection con = new SqlConnection(strcon); string squery = "UPDATE dbo.[Leaves] set Req_Status='" + Req_Status + "', Decline_ID='" + DropDownListDeclineReason.SelectedItem.Value + "' where Employee_ID='" + EmployeeID + "'"; string squery2 = "INSERT to dbo.[LeaveDeclineDes] Dec_Description values Dec_Description='" + TextBoxOther.Text + "'"; if (con.State == ConnectionState.Closed) { con.Open(); } SqlCommand cmd = new SqlCommand(); cmd.CommandText = squery; cmd.Connection = con; cmd.ExecuteNonQuery(); SqlCommand cmd2 = new SqlCommand(); cmd2.CommandText = squery; cmd2.Connection = con; cmd2.ExecuteNonQuery(); con.Close(); } catch (Exception ex) { Response.Write("< script >alert ('" + ex.Message + "');</ Script >"); } } }