Sei sulla pagina 1di 3

using System;

using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;

public partial class Department : System.Web.UI.Page


{
string Qry = String.Empty;
clsDataControl clsData = new clsDataControl();
SqlConnection con = new
SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bindGrid();
}
}
private void bindGrid()
{
try
{
DataTable DataRequest = clsData.Getdata("select id,Department,Dept_Type
from tbl_PMIS_Dept");
grd_deptdetails.DataSource = DataRequest;
grd_deptdetails.DataBind();
}
catch (Exception ex)
{
throw ex;
}
}
protected void lnk_deptdel_click(object sender, CommandEventArgs e)
{
LinkButton lnkEdit = (LinkButton)sender;
GridViewRow gvrow = (GridViewRow)lnkEdit.NamingContainer;
string id = Convert.ToString(e.CommandArgument);
string Department = clsData.GetSingleData("select Department from
tbl_PMIS_Dept where id= '" + id + "'");
//string Type = clsData.GetSingleData("select Dept_Type from tbl_PMIS_Dept
where id='" + id + "'");
ClientScript.RegisterClientScriptBlock(this.GetType(), "", "$
('#lbl_id').html('" + id + "');$('#lbl_showhead').html('Department :');$
('#lbl_show').html('" + Department + "');$('#div_DeleteCancel').html('Are you sure
to delete this Department?');$('#alertDeleteCancel').modal('show'); ", true);

bindGrid();
}
[System.Web.Services.WebMethod]
public static void deleteitem(string ID)
{
SqlConnection con = new
SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString);
con.Open();
SqlCommand cmd = new SqlCommand("Delete from tbl_PMIS_Dept where id= '" +
ID + "'", con);
cmd.ExecuteNonQuery();
con.Close();
}
protected void clear()
{
txt_Department.Text = string.Empty;
}

protected void btn_Save_Click(object sender, EventArgs e)


{
try
{
clsData.DynamicParameters.Clear();
clsData.DynamicParameters.Add("@Department",txt_Department.Text);
clsData.DynamicParameters.Add("@Dept_Type", Dept_Type.SelectedValue);
string Qry1 = "Select * from tbl_PMIS_Dept where Department='" +
txt_Department.Text.Trim().ToUpper() + "'";
DataTable dt = new DataTable();
SqlDataAdapter sda = new SqlDataAdapter(Qry1, con);
sda.Fill(dt);
if (dt.Rows.Count > 0)
{
ClientScript.RegisterClientScriptBlock(this.GetType(), "", "$
('#alertContent').html('Already Exist!');$('#alertWin').modal('show'); ", true);
}
else
{
string Qry = "insert into tbl_PMIS_Dept (Department,Dept_Type)
values (@Department,@Dept_Type) ";
clsData.InsertOrUpdate(Qry, false, true);
clsData.DynamicParameters.Clear();
ClientScript.RegisterClientScriptBlock(this.GetType(), "", "$
('#alertContent').html('Save Successfully');$('#alertWin').modal('show'); ", true);
}
clear();
bindGrid();
}
catch (Exception ex)
{
throw ex;
}
}

protected void lnk_deptedit_click(object sender, CommandEventArgs e)


{
btn_edit.Visible = true;
btn_Save.Visible = false;
LinkButton link_edit = (LinkButton)sender;
GridViewRow grid_view = (GridViewRow)link_edit.NamingContainer;
// GridView grid_view = (GridView)link_edit.NamingContainer;
string id = Convert.ToString(e.CommandArgument);
lbl_id.Text= id;
DataTable dt_dept = clsData.Getdata("select * from tbl_PMIS_Dept where
id='" + id + "'");
txt_Department.Text = dt_dept.Rows[0]["Department"].ToString();
Dept_Type.SelectedIndex =
Dept_Type.Items.IndexOf(Dept_Type.Items.FindByValue(dt_dept.Rows[0]
["Dept_Type"].ToString()));
// Dept_Type.SelectedIndex =
Dept_Type.Items.IndexOf(Dept_Type.Items.FindByValue(dt_dept.[2]
["Dept_Type"].ToString()));

protected void btn_edit_Click(object sender, EventArgs e)


{
clsData.DynamicParameters.Add("@Department", txt_Department.Text);
clsData.DynamicParameters.Add("@Dept_Type", Dept_Type.SelectedValue);
clsData.DynamicParameters.Add("id", lbl_id.Text);
string dept_edit = "Update tbl_PMIS_Dept set
Department=@Department,Dept_Type=@Dept_Type where id=@id";
clsData.InsertOrUpdate(dept_edit, false, true);
clsData.DynamicParameters.Clear();
// ClientScript.RegisterClientScriptBlock(this.GetType(), "", "$
('#alertcontent').html('Department Details has been Updated.');$
('#alertwin').modal('show');", true);

ClientScript.RegisterClientScriptBlock(this.GetType(), "", "$


('#alertContent').html('Department details has been updated.');$
('#alertWin').modal('show'); ", true);

}
}

Potrebbero piacerti anche