protected void DLProdiDosen_SelectedIndexChanged(object sender, EventArgs e) { string CS = ConfigurationManager.ConnectionStrings["MainDb"].ConnectionString; using (SqlConnection con = new SqlConnection(CS)) { con.Open(); SqlCommand CmdDosen = new SqlCommand("SpGetDosen", con); CmdDosen.CommandType = System.Data.CommandType.StoredProcedure; CmdDosen.Parameters.AddWithValue("@id_prodi", this.DLProdiDosen.SelectedValue); DataTable TableDosen = new DataTable(); TableDosen.Columns.Add("NIDN"); TableDosen.Columns.Add("Nama"); using (SqlDataReader rdr = CmdDosen.ExecuteReader()) { if (rdr.HasRows) { this.PanelDetailDosen.Enabled = true; this.PanelDetailDosen.Visible = true; while (rdr.Read()) { DataRow datarow = TableDosen.NewRow(); datarow["NIDN"] = rdr["nidn"]; datarow["Nama"] = rdr["nama"]; TableDosen.Rows.Add(datarow); } //Fill Gridview this.GVDosen.DataSource = TableDosen; this.GVDosen.DataBind(); } else { //clear Gridview TableDosen.Rows.Clear(); TableDosen.Clear(); GVDosen.DataSource = TableDosen; GVDosen.DataBind(); this.PanelDetailDosen.Enabled = true; this.PanelDetailDosen.Visible = true; } } } }
protected void BtnCari_Click(object sender, EventArgs e) { if (this.DLCari.SelectedValue == "-1") { this.Page.ClientScript.RegisterStartupScript(this.GetType(), "ex", "alert('Pilih Jenis Pencarian');", true); return; } if (this.TbSearch.Text == "") { this.Page.ClientScript.RegisterStartupScript(this.GetType(), "ex", "alert('Ketik Kata Kunci Pencarian');", true); return; } if (this.TbSearch.Text.Length < 4) { this.Page.ClientScript.RegisterStartupScript(this.GetType(), "ex", "alert('Kata Kunci Minimal 4 Huruf atau Angka');", true); return; } string CS = ConfigurationManager.ConnectionStrings["MainDb"].ConnectionString; using (SqlConnection con = new SqlConnection(CS)) { try { con.Open(); SqlCommand CmdDosen = new SqlCommand("SpCariDosen", con); CmdDosen.CommandType = System.Data.CommandType.StoredProcedure; CmdDosen.Parameters.AddWithValue("@input", this.TbSearch.Text); DataTable TableDosen = new DataTable(); TableDosen.Columns.Add("NIDN"); TableDosen.Columns.Add("NAMA"); TableDosen.Columns.Add("HANDPHONE"); TableDosen.Columns.Add("ALAMAT"); using (SqlDataReader rdr = CmdDosen.ExecuteReader()) { if (rdr.HasRows) { this.PanelListDosen.Enabled = true; this.PanelListDosen.Visible = true; while (rdr.Read()) { DataRow datarow = TableDosen.NewRow(); datarow["NIDN"] = rdr["nidn"]; datarow["NAMA"] = rdr["nama"]; datarow["HANDPHONE"] = rdr["hp"]; datarow["ALAMAT"] = rdr["alamat"]; TableDosen.Rows.Add(datarow); } //Fill Gridview this.GVDosen.DataSource = TableDosen; this.GVDosen.DataBind(); } else { //clear Gridview TableDosen.Rows.Clear(); TableDosen.Clear(); GVDosen.DataSource = TableDosen; GVDosen.DataBind(); this.PanelListDosen.Enabled = false; this.PanelListDosen.Visible = false; this.Page.ClientScript.RegisterStartupScript(this.GetType(), "ex", "alert('Data Tidak Ditemukan');", true); return; } } // loop to cek status dosen for (int i = 0; i < this.GVDosen.Rows.Count; i++) { SqlCommand CmdAktif = new SqlCommand("select aktif from bak_dosen where nidn=@nidn", con); CmdAktif.CommandType = System.Data.CommandType.Text; CmdAktif.Parameters.AddWithValue("@nidn", this.GVDosen.Rows[i].Cells[0].Text.Trim()); using (SqlDataReader rdr = CmdAktif.ExecuteReader()) { if (rdr.HasRows) { while (rdr.Read()) { if (rdr["aktif"].ToString() == "yes") { CheckBox ch = (CheckBox)this.GVDosen.Rows[i].FindControl("CBAktif"); ch.Checked = true; } else if ((rdr["aktif"].ToString().Trim() == "no") || (rdr["aktif"].ToString().Trim() == "") || (rdr["aktif"] == DBNull.Value)) { CheckBox ch = (CheckBox)this.GVDosen.Rows[i].FindControl("CBAktif"); ch.Checked = false; } } } } } } catch (Exception ex) { this.Page.ClientScript.RegisterStartupScript(this.GetType(), "ex", "alert('" + ex.Message.ToString() + "');", true); return; } } }
protected void Load_Dosen() { string CS = ConfigurationManager.ConnectionStrings["MainDb"].ConnectionString; using (SqlConnection con = new SqlConnection(CS)) { try { con.Open(); SqlCommand CmdDosen = new SqlCommand("" + "SELECT bak_dosen.no, bak_dosen.nama, bak_dosen.nidn, bak_dosen.nik, bak_dosen.nip, bak_dosen.pangkat, bak_dosen.jabatan, bak_dosen.tmlahir, bak_dosen.tglahir, bak_dosen.pendidikan, " + "bak_dosen.prodi, bak_dosen.hp, bak_dosen.alamat, bak_dosen.aktif, bak_prog_study.prog_study " + "FROM bak_dosen INNER JOIN " + "bak_prog_study ON bak_dosen.prodi = bak_prog_study.id_prog_study " + "WHERE prodi = @prodi AND aktif = 'yes' AND (dosen_tim IS NULL OR dosen_tim != 'yes') ORDER BY nama ASC" + "", con); CmdDosen.CommandType = System.Data.CommandType.Text; CmdDosen.Parameters.AddWithValue("@prodi", this.Session["level"].ToString()); DataTable TableDosen = new DataTable(); TableDosen.Columns.Add("NIDN/NUP/NIDK"); TableDosen.Columns.Add("NAMA"); TableDosen.Columns.Add("AKTIF"); using (SqlDataReader rdr = CmdDosen.ExecuteReader()) { if (rdr.HasRows) { while (rdr.Read()) { DataRow datarow = TableDosen.NewRow(); datarow["NIDN/NUP/NIDK"] = rdr["nidn"]; datarow["NAMA"] = rdr["nama"]; datarow["AKTIF"] = rdr["aktif"]; TableDosen.Rows.Add(datarow); } //Fill Gridview this.GVDosen.DataSource = TableDosen; this.GVDosen.DataBind(); } else { //clear Gridview TableDosen.Rows.Clear(); TableDosen.Clear(); GVDosen.DataSource = TableDosen; GVDosen.DataBind(); this.Page.ClientScript.RegisterStartupScript(this.GetType(), "ex", "alert('Data Tidak Ditemukan');", true); return; } } //// loop to cek status dosen //for (int i = 0; i < this.GVDosen.Rows.Count; i++) //{ // SqlCommand CmdAktif = new SqlCommand("SpGetDosenByProdi", con); // CmdAktif.CommandType = System.Data.CommandType.StoredProcedure; // CmdAktif.Parameters.AddWithValue("@prodi", this.DLProdi.SelectedValue); // using (SqlDataReader rdr = CmdDosen.ExecuteReader()) // { // if (rdr.HasRows) // { // while (rdr.Read()) // { // if (rdr["aktif"].ToString() == "yes") // { // CheckBox ch = (CheckBox)this.GVDosen.Rows[i].FindControl("CBAktif"); // ch.Checked = true; // } // else if (rdr["aktif"].ToString() != "yes") // { // CheckBox ch = (CheckBox)this.GVDosen.Rows[i].FindControl("CBAktif"); // ch.Checked = false; // } // } // } // } //} } catch (Exception ex) { this.Page.ClientScript.RegisterStartupScript(this.GetType(), "ex", "alert('" + ex.Message.ToString() + "');", true); return; } } }