Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 5

using System;

using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Globalization;
using System.Text;
using System.Web.Services;
using System.IO;
public partial class ProjectMaster : System.Web.UI.Page
{
SqlConnection con = new
SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString);
clsDataControl clsData = new clsDataControl();
protected void Page_Load(object sender, EventArgs e)
{
try
{
if (!IsPostBack)
{
string urlName = Request.UrlReferrer.ToString();
BindDepartment();
generateID();
if (Convert.ToString(Session["Department"]) != "Software")
{
pnl_GridProjectView.Visible = false;
ddl_Projecttype.SelectedIndex =
ddl_Projecttype.Items.IndexOf(ddl_Projecttype.Items.FindByValue("Internal"));
//ddl_Projecttype.SelectedItem.Value = "Internal";
ddl_Projecttype.Enabled = false;
ddl_Projecttype.CssClass = "col-sm-2 form-control";
}
else
{
BindGridProject();
}
}
}
catch (Exception Ex)
{
throw Ex;
}
}

private void BindGridProject()


{
try
{
DataTable dt_project = clsData.Getdata("select * from
tbl_PMIS_Projects");
grd_project.DataSource = dt_project;
grd_project.DataBind();
}
catch (Exception)
{
throw;
}
}

protected void generateID()


{
string id1 = string.Empty;
string c = string.Empty;
try
{
c = clsData.GetSingleData("select COUNT(*) from tbl_PMIS_Projects where
project_id LIKE 'SW%'");

//int id = int.Parse(c) + 1;
if (c == String.Empty)
{
c = 0.ToString();
}
int count = Int32.Parse(c.ToString());
con.Open();

if (count > 0)
{
count++;
}
else
{
count = 0001;
}
id1 = "SW";

string id = String.Format("{0:D4}", count);


string year = DateTime.Now.ToString("yyyy");
id1 = id1 + year + id;
count = count + 1;
string projectId = id1;
txt_Projectid.Text = projectId;
//hdn_RequestNo.Value = txt_Projectid.Text;
con.Close();
//txt_Projectdesc.Attributes.Add("readonly", "readonly");
}
catch (Exception ex)
{
Response.Write(ex);
}
}
private void BindDepartment()
{
try
{
if (Convert.ToString(Session["Department"]) == "Software")
{
DataTable dt;
dt = clsData.Getdata("SELECT distinct Department FROM tbl_PMIS_Dept
order by Department asc ");
ddl_department.DataSource = dt;
ddl_department.DataTextField = "Department";
ddl_department.DataValueField = "Department";
ddl_department.DataBind();
ddl_department.Items.Insert(0, new ListItem("--Select--", "0"));
}
else
{
string Qry = "select id,Department from tbl_PMIS_Dept where
Department='" + Convert.ToString(Session["Department"]) + "'";
clsData.DrapDownBind(ddl_department, Qry, "Department", "id");
}
}
catch (Exception Ex)
{
throw Ex;
}
}
protected void btn_add_Click(object sender, EventArgs e)
{
try
{
string add_project;
string date = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
clsData.DynamicParameters.Add("@project_id", txt_Projectid.Text);
clsData.DynamicParameters.Add("@description", txt_Projectdesc.Text);
clsData.DynamicParameters.Add("@project_name", txt_Projectname.Text);
clsData.DynamicParameters.Add("@department",
ddl_department.SelectedItem.Text);
clsData.DynamicParameters.Add("@project_type",
ddl_Projecttype.SelectedItem.Text);
clsData.DynamicParameters.Add("@project_date", date);
add_project = "insert into
tbl_PMIS_Projects(project_id,description,project_name,project_type,project_date,dep
artment)
values(@project_id,@description,@project_name,@project_type,@project_date,@departme
nt)";
clsData.InsertOrUpdate(add_project, false, true);
clsData.DynamicParameters.Clear();
ClientScript.RegisterClientScriptBlock(this.GetType(), "", "$
('#alertContent').html('Project Added Successfully');$('#alertWin').modal('show');
", true);
if (Request.QueryString.Count > 0)
{
Response.Redirect("AddRequest.aspx");
}
}
catch (Exception Ex)
{
throw Ex;
}

}
protected void clear()
{
ddl_Projecttype.SelectedIndex = -1;
txt_Projectdesc.Text = string.Empty;
//txt_Projectid.Text = string.Empty;
txt_Projectname.Text = string.Empty;
ddl_department.SelectedIndex = -1;
}
protected void btn_Reset_Click(object sender, EventArgs e)
{
try
{
clear();
// Page.Response.Redirect(Page.Request.Url.ToString(), true);
}
catch (Exception Ex)
{
throw Ex;
}
}
protected void btn_back_Click(object sender, EventArgs e)
{
try
{
Response.Redirect("Dashboard.aspx");
}
catch (Exception Ex)
{
throw Ex;
}
}
protected void lnk_projectEditClick(object sender, CommandEventArgs e)
{
try
{
btn_add.Visible = false;
btn_edit.Visible = true;
string id = Convert.ToString(e.CommandArgument);
DataTable dt=clsData.Getdata("select * from tbl_PMIS_Projects where
p_id='" + id + "'");
lbl_id.Text = dt.Rows[0]["p_id"].ToString();
txt_Projectid.Text= dt.Rows[0]["project_id"].ToString();
txt_Projectname.Text= dt.Rows[0]["project_name"].ToString();
//ddl_Projecttype.SelectedIndex =
ddl_Projecttype.Items.IndexOf(ddl_Projecttype.Items.FindByText(dt.Rows[0]
["project_type"].ToString()));
//ddl_Projecttype.SelectedItem.Text = dt.Rows[0]
["project_type"].ToString();
ddl_Projecttype.SelectedIndex =
ddl_Projecttype.Items.IndexOf(ddl_Projecttype.Items.FindByText(dt.Rows[0]
["project_type"].ToString()));
ddl_department.SelectedIndex =
ddl_department.Items.IndexOf(ddl_department.Items.FindByValue(dt.Rows[0]
["department"].ToString()));
txt_Projectdesc.Text = dt.Rows[0]["description"].ToString();
}
catch (Exception)
{

throw;
}
}
protected void btn_edit_Click(object sender, EventArgs e)
{
try
{
string update = "update tbl_PMIS_Projects set project_name='" +
txt_Projectname.Text + "',project_type='" + ddl_Projecttype.SelectedItem.Text +
"',department='" + ddl_department.SelectedItem.Value + "',description='" +
txt_Projectdesc.Text + "' where p_id='" + lbl_id.Text + "'";
clsData.InsertOrUpdate(update, false, false);
ClientScript.RegisterClientScriptBlock(this.GetType(), "", "$
('#alertContent').html('Project details updated successfully');$
('#alertWin').modal('show'); ", true);

}
catch (Exception)
{

throw;
}
}
protected void lnk_projectDeleteClick(object sender, CommandEventArgs e)
{
try
{
LinkButton lnkEdit = (LinkButton)sender;
GridViewRow gvrow = (GridViewRow)lnkEdit.NamingContainer;
string id = Convert.ToString(e.CommandArgument);
string project = clsData.GetSingleData("select
project_id+'_'+project_name from tbl_PMIS_Projects where p_id='" + id + "'");
ClientScript.RegisterClientScriptBlock(this.GetType(), "", "$
('#lbl_id').html('" + id + "');$('#lbl_showhead').html('Project ID&Name :');$
('#lbl_show').html('" + project + "');$('#div_DeleteCancel').html('Are you sure to
Delete this Project?');$('#alertDeleteCancel').modal('show'); ", true);
BindGridProject();
}
catch (Exception)
{

throw;
}
}
[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_Projects where p_id=
'" + ID + "'", con);
cmd.ExecuteNonQuery();
con.Close();
}
}

You might also like