//fungsi: Handle Ketika data pada database telah ditambahkan protected void dsPunishmentEdit_Inserted(object sender, System.Web.UI.WebControls.SqlDataSourceStatusEventArgs e) { //Seleksi apakah terjadi error atau tidak //jika tidak ada record yang ter insert maka terjadi error if (e.AffectedRows == 0) { ExceptionDetails.Text = lblCannotUpdate.Text; //& " (" & e.Exception.Message & ")" e.ExceptionHandled = true; if (!isEntrySambung()) { setInitialComponent(); } } else { //Catat ke Log rtwin.azlib.AddUserAct(Session["UserID"].ToString(), "2431", e.Command.Parameters["@NIP"].Value.ToString() + "," + e.Command.Parameters["@TGL_AWAL"].Value.ToString(), Application["strCn"].ToString()); ExceptionDetails.Text = "Data telah di simpan"; GvPunishment.DataBind(); setInitialComponent(); } if (!isEntrySambung()) { showGridView(true); } }
//fungsi: Refresh GridView protected void btnRefresh_Click(object sender, EventArgs e) { if (Page.IsValid) { //update ke grid GvPunishment.DataBind(); } }
protected void GvPunishment_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Show") { if (Page.IsValid) { GridViewRow row = (GridViewRow)((LinkButton)e.CommandSource).NamingContainer; GvPunishment.SelectedIndex = row.RowIndex; GvPunishment.DataBind(); string sTahun; if (ddlTahun.Text == DateTime.Now.Year.ToString()) { sTahun = azlib.FirstDate(DateTime.Now, "en").ToString(); } else { sTahun = "'1/1/" + Convert.ToString(Convert.ToInt32(ddlTahun.Text) + 1) + "'"; } dsMangkir.SelectCommand = "select TGL_MASUK from q_AbsenHarianDetil where MANGKIR = 1 AND PIN = '" + ((LinkButton)row.Cells[0].FindControl("lnkCol0Item")).Text + "' AND TGL_MASUK >= '1/1/" + ddlTahun.Text + "' AND TGL_MASUK < '" + sTahun + "'"; dsMangkir.DataBind(); lblTitleRincianMangkir.Text = "Rincian ketidakhadiran PIN " + ((LinkButton)row.Cells[0].FindControl("lnkCol0Item")).Text; lblTitleRincianMangkir.Visible = true; gvMangkir.Visible = true; dsAkumulasiMangkir.SelectCommand = "SELECT [JML_JAM_LAMBAT_CPTPLG],[KONVERSI_MANGKIR] FROM [q_LambatCepatPulang]where PIN = '" + ((LinkButton)row.Cells[0].FindControl("lnkCol0Item")).Text + "' AND TAHUN = " + ddlTahun.Text + ""; dsAkumulasiMangkir.DataBind(); if (gvAkumulasiMangkir.Rows.Count > 0) { lblTitleAkumulasiMangkir.Text = "Akumulasi Keterlambatan dan Cepat Pulang PIN " + ((LinkButton)row.Cells[0].FindControl("lnkCol0Item")).Text; lblTitleAkumulasiMangkir.Visible = true; gvAkumulasiMangkir.Visible = true; } } } else if (e.CommandName == "TambahPelanggaran") { FvPunishment.DefaultMode = FormViewMode.Insert; FvPunishment.ChangeMode(FormViewMode.Insert); showGridView(false); ImageButton b = (ImageButton)e.CommandSource; GridViewRow myRow = (GridViewRow)b.NamingContainer; ((TextBox)FvPunishment.FindControl("txtItem0FormView")).Text = GvPunishment.DataKeys[myRow.RowIndex].Value.ToString(); ((TextBox)FvPunishment.FindControl("txtItem0FormView")).Enabled = false; TextBox txtNIP = (TextBox)FvPunishment.FindControl("txtItem0FormView"); Label lblNama = (Label)FvPunishment.FindControl("lblItem1FormView"); setNama(txtNIP, lblNama); ((LinkButton)FvPunishment.FindControl("lnkItem0FormView")).Visible = false; ((TextBox)FvPunishment.FindControl("txtItem2FormView")).Text = (azlib.FirstDate(DateTime.Now, "id")).ToShortDateString(); int iLamaPotongan; iLamaPotongan = Convert.ToInt32(((Label)(myRow.Cells[8].FindControl("lblCol11Item"))).Text.ToString()); ((TextBox)FvPunishment.FindControl("txtItem3FormView")).Text = (azlib.FirstDate(DateTime.Now, "id")).AddMonths(iLamaPotongan).AddDays(-1).ToShortDateString(); ((DropDownList)FvPunishment.FindControl("ddlItem4FormView")).SelectedValue = ((Label)(myRow.Cells[3].FindControl("lblCol3Item"))).Text.ToString(); } }
//fungsi: Handle Ketika data pada database telah didelete protected void dsPunishment_Deleted(object sender, System.Web.UI.WebControls.SqlDataSourceStatusEventArgs e) { //Seleksi apakah terjadi error atau tidak //jika tidak ada record yang ter delete maka terjadi error if (e.AffectedRows == 0) { ExceptionDetails.Text = lblCannotUpdate.Text; e.ExceptionHandled = true; } else { //Catat ke Log rtwin.azlib.AddUserAct(Session["UserID"].ToString(), "2433", e.Command.Parameters["@NIP"].Value.ToString() + "," + e.Command.Parameters["@TGL_AWAL"].Value.ToString(), Application["strCn"].ToString()); } GvPunishment.DataBind(); }
protected void txtHalaman_TextChanged(object sender, EventArgs e) { GridViewRow rowPager = GvPunishment.BottomPagerRow; TextBox txtHalaman = (TextBox)(rowPager.Cells[0].FindControl("txtHalaman")); try { if (int.Parse(txtHalaman.Text) <= GvPunishment.PageCount + 1 && int.Parse(txtHalaman.Text) > 0) { GvPunishment.PageIndex = (int.Parse(txtHalaman.Text)) - 1; GvPunishment.DataBind(); } } catch (Exception) { txtHalaman.Text = (GvPunishment.PageIndex + 1).ToString(); } }