Thursday, September 13, 2012

Approval Process..

using
System;

using
System.Collections.Generic;

using
System.Linq;

using
System.Text;

using
System.Drawing;

using
System.Data;

using
System.Web;

using
System.Collections;

using
System.Configuration;

using
System.Web.UI;

using
System.Web.UI.WebControls;

using
System.Web.UI.WebControls.WebParts;

using
System.Web.UI.HtmlControls;

using
AjaxControlToolkit;

using
System.Data.Sql;

using
System.Data.SqlClient;

using
System.Data.SqlTypes;

using
Microsoft.SharePoint;

using
Microsoft.SharePoint.WebControls;

using
Microsoft.SharePoint.WebPartPages;

using
System.Net.Mail;

using
System.Reflection;

using
System.DirectoryServices.AccountManagement;

using
System.Security.Principal;

using
System.Runtime.InteropServices;

using
System.Text.RegularExpressions;

namespace
LeaveApprovalProcess

{

public class LeaveApprovalProcess : System.Web.UI.WebControls.WebParts.WebPart

{



#region
ConnectionString

string ConnectionString = ConfigurationSettings.AppSettings["ConnectionString"].ToString();

#endregion



#region

Declaration_Controls

protected System.Web.UI.WebControls.Table tblMain = new System.Web.UI.WebControls.Table();

protected Label lblStatus = new Label();

protected System.Web.UI.WebControls.Table tblPartnerView = new System.Web.UI.WebControls.Table();

protected GridView gvLeaveApproval = new GridView();

protected Button btnSubmit = new Button();

protected Button btnCancel = new Button();

protected HiddenField hdnsoln = new HiddenField();

protected Panel pnlLeaveApproval = new Panel();





protected System.Web.UI.WebControls.Table tblLeaveApproval = new System.Web.UI.WebControls.Table();

protected Label lblUpdateStatus = new Label();

protected DropDownList ddlUpdateStatus = new DropDownList();

protected CheckBox chkActive = new CheckBox();

protected Label lblComments = new Label();

protected TextBox txtComments = new TextBox();

protected HiddenField hdnApprovalProcess = new HiddenField();

protected HiddenField hdnstatus = new HiddenField();

protected HiddenField hdnempid = new HiddenField();

HiddenField hdnapprover = new HiddenField();

HiddenField hdnappdisplayname = new HiddenField();

HiddenField hdnleavecaty = new HiddenField();

HiddenField hdnNofDays = new HiddenField();

HiddenField hdnrowid = new HiddenField();

HiddenField hdnRecentLType = new HiddenField();

HiddenField hdnRecentLDate = new HiddenField();

HiddenField hdnRecentLReason = new HiddenField();

HiddenField hdnRecentLFromdate = new HiddenField();

HiddenField hdnRecentLTodate = new HiddenField();

#endregion













#region

OnInitiate_Method

protected override void OnInit(EventArgs e)

{

try

{

base.OnInit(e);

this.InitializeComponent();



}

catch (Exception ex)

{

DisplayErroMessage(ex);

}

}

#endregion



#region

Initialize_Component

private void InitializeComponent()

{

//Initialize the controls

tblMain.ID = "tblMain";

tblMain.Width = Unit.Percentage(75);

tblMain.BorderColor = ColorTranslator.FromHtml("#8CC3FF");

tblMain.BackColor = ColorTranslator.FromHtml("#ffffff");

tblMain.BorderStyle = BorderStyle.Solid;

tblMain.BorderWidth = Unit.Pixel(1);

tblMain.CellPadding = 0;

tblMain.HorizontalAlign =
HorizontalAlign.Center;

tblLeaveApproval.ID = "tblLeaveApproval";

tblLeaveApproval.Width = Unit.Percentage(90);

tblLeaveApproval.CellPadding = 0;

tblLeaveApproval.HorizontalAlign =
HorizontalAlign.Center;

lblStatus.ID = "lblStatus";

hdnsoln.ID = "hdnsoln";

hdnempid.ID = "hdnempid";

hdnapprover.ID = "hdnapprover";

hdnappdisplayname.ID = "hdnappdisplayname";

hdnleavecaty.ID = "hdnleavecaty";

hdnNofDays.ID = "hdnNofDays";

hdnrowid.ID = "hdnrowid";

hdnRecentLType.ID = "hdnRecentLType";

hdnRecentLDate.ID = "hdnRecentLDate";

hdnRecentLReason.ID = "hdnRecentLReason";

hdnRecentLFromdate.ID = "hdnRecentLFromdate";

hdnRecentLTodate.ID = "hdnRecentLTodate";



gvLeaveApproval.ID =
"gvLeaveApproval";

pnlLeaveApproval.ID = "pnlLeaveApproval";

pnlLeaveApproval.Height = Unit.Pixel(250);

pnlLeaveApproval.ScrollBars = ScrollBars.Auto;

hdnsoln.ID = "hdnsoln";

btnSubmit.ID = "btnSubmit";

btnSubmit.Text = "Submit";

btnSubmit.ForeColor = Color.White;

btnSubmit.BackColor = ColorTranslator.FromHtml("#0869D6");

btnSubmit.Visible = false;

btnCancel.ID = "btnCancel";

btnCancel.Text = "Cancel";

btnCancel.ForeColor = Color.White;

btnCancel.BackColor = ColorTranslator.FromHtml("#0869D6");

btnCancel.Visible = false;



lblUpdateStatus.ID =
"lblUpdateStatus";

lblUpdateStatus.Text = "Select Status to Apply the Approval";

lblUpdateStatus.Visible = false;

ddlUpdateStatus.ID = "ddlUpdateStatus";

ddlUpdateStatus.Visible = false;

ddlUpdateStatus.AutoPostBack = true;

ddlUpdateStatus.SelectedIndexChanged += new EventHandler(ddlUpdateStatus_SelectedIndexChanged);

ddlUpdateStatus.Width = 100;

LoadUpdateStatus();



lblComments.ID =
"lblComments";

lblComments.Text = "Comments";

lblComments.Visible = false;

txtComments.ID = "txtComments";

txtComments.Width = 180;

txtComments.TextMode =
TextBoxMode.MultiLine;

txtComments.Visible = false;

hdnApprovalProcess.ID = "hdnApprovalProcess";

#region
javscript confirmation

string script;

//Confirm Approval for Leaves

script = "";

//script += "if (ddlUpdateStatus.SelectedItem.Text == 'Approved')";

//script += "{";

//script += "if(confirm('Are you sure Want to Approve the Leave?'))";

//script += "}";

//script += "else if (ddlUpdateStatus.SelectedItem.Text == 'Rejected')";

//script += "{";

//script += "}";

script += "if(confirm('Are you sure Want to Approve/Reject the Leave?'))";

script += "{";

script += "document.getElementById('" + base.ClientID + "_hdnApprovalProcess').value = 1;";

script += "}";

script += "else";

script += "{";

script += "document.getElementById('" + base.ClientID + "_hdnApprovalProcess').value = 0;";

script += "}";

btnSubmit.Attributes.Add("onclick", script);

#endregion


btnSubmit.Click += new EventHandler(btnSubmit_Click);

btnCancel.Click += new EventHandler(btnCancel_Click);

gvLeaveApproval.RowCreated += new System.Web.UI.WebControls.GridViewRowEventHandler(gvLeaveApproval_RowCreated);

gvLeaveApproval.RowEditing += new GridViewEditEventHandler(gvLeaveApproval_RowEditing);

// this.InitGridView(ref gvLeaveApproval, "GetAll");

InitGridView(gvLeaveApproval, "GetAll");

}







#endregion



#region

othermethods

void ddlUpdateStatus_SelectedIndexChanged(object sender, EventArgs e)

{



}

void gvLeaveApproval_RowCreated(object sender, GridViewRowEventArgs e)

{

e.Row.Cells[1].Visible =
true;

}

void gvLeaveApproval_RowEditing(object sender, GridViewEditEventArgs e)

{

try

{

string GetSolutionName = gvLeaveApproval.Rows[e.NewEditIndex].Cells[1].Text;

string GetCompanyName = gvLeaveApproval.Rows[e.NewEditIndex].Cells[2].Text;

string GetSolutionStatus = gvLeaveApproval.Rows[e.NewEditIndex].Cells[3].Text;

SqlConnection sqlcon = new SqlConnection(ConnectionString);

sqlcon.Open();

SqlDataAdapter da = new SqlDataAdapter("select * from PartnerSolution where SolutionName='" + GetSolutionName + "'and SolutionStatus='" + GetSolutionStatus + "' ", sqlcon);

DataTable dt = new DataTable();

da.Fill(dt);

string strContactEmail = dt.Rows[0]["ContactEmail"].ToString();

if (dt.Rows.Count > 0)

{





SmtpClient mailClient = new SmtpClient();

MailMessage email = new MailMessage("busadmin@kryptos.in", strContactEmail);

email.Bcc.Add("chitharan.s@kryptos.in");

email.Subject = "Your Solution Status has been Approved ";

email.IsBodyHtml = true;

email.Body = "<html><body><table><tr><td>Dear Partner,</td></tr><tr><td></td></tr><tr><td>Greetings!.</td></tr><tr><td>Please find the Solution Status below,<br/></td></tr><tr><td></td></tr><tr><td>CompanyName:" + GetCompanyName + "</td></tr><tr><td></td></tr><tr><td></td></tr><tr><td>SolutionName:" + GetSolutionName + "</td></tr><tr><td>Kindly acknowledge the receipt.</td></tr><tr><td></td></tr> <tr><td></td></tr> <tr><td></td></tr> <tr><td>Regards,</td></tr><tr><td></td></tr> <tr><td>VAR Administrator</td></tr></table><body></html>";

mailClient.Port = 25;

mailClient.DeliveryMethod =
SmtpDeliveryMethod.SpecifiedPickupDirectory;

mailClient.PickupDirectoryLocation = @"C:\Inetpub\mailroot\Pickup\";

mailClient.Send(email);

DisplayMessage(
"Approved Solution Status sent to Your MailID Successfully", MessageType.Information);



}

}

catch (Exception ex)

{

DisplayErroMessage(ex);

}

}

void gvUSage_RowCommand(object sender, GridViewCommandEventArgs e)

{

try

{

if (e.CommandName == "Edit")

{ }

}

catch (Exception ex)

{

DisplayErroMessage(ex);

}

}

#endregion

#region

Click_Events

void btnCancel_Click(object sender, EventArgs e)

{

try

{

ClearGridCheckBox();



}

catch (Exception ex)

{

DisplayErroMessage(ex);

}

}

void btnSubmit_Click(object sender, EventArgs e)

{

int selectedCount = 0;

try

{

if (ddlUpdateStatus.SelectedItem.Text == "Approved")

{

UpdatestatusinSiteList();

}

else

{

UpdaterejectedList();

}

for (int i = 0; i < gvLeaveApproval.Rows.Count; i++)

{

CheckBox chk = (CheckBox)gvLeaveApproval.Rows[i].Cells[0].Controls[0];

if (chk != null)

{

if (chk.Checked)

{

selectedCount++;

string LeaveEmpID = gvLeaveApproval.Rows[i].Cells[1].Text.ToString();

string LeaveRowID = gvLeaveApproval.Rows[i].Cells[9].Text.ToString();

if (hdnApprovalProcess.Value == "1")

{

if (ddlUpdateStatus.SelectedItem.Text == "Approved")

{



#region
Approved

SPSecurity.RunWithElevatedPrivileges(delegate()

{

using (SPSite site = new SPSite(" http://intranet.kryptos.in:8080/sites/KCS/HRM/Lists/"))

{

site.AllowUnsafeUpdates =
true;

using (SPWeb web = site.OpenWeb())

{

web.AllowUnsafeUpdates =
true;

SPList list = web.Lists["LeaveMasterData"];



SPList leavelist = web.Lists["LeaveData"];

SPListItem leaveitem = leavelist.GetItemById(Convert.ToInt16(gvLeaveApproval.Rows[i].Cells[9].Text.ToString()));

string RecentLType = leaveitem["LeaveType"].ToString();

//string RecentLDate = leaveitem["CreatedBy"].ToString();

string RecentLReason = leaveitem["Reason"].ToString();

string RecentLFromdate = Convert.ToDateTime(leaveitem["FromDate"].ToString()).ToShortDateString();

string RecentLTodate = Convert.ToDateTime(leaveitem["ToDate"].ToString()).ToShortDateString();

foreach (SPListItem item in list.Items)

{

string AID = item["ID"].ToString();

string empid = item["EmployeeID"].ToString();

string empName = item["EmployeeName"].ToString();

string empsex = item["EmployeeSex"].ToString();

string AvailCL = Convert.ToInt16(item["AvailableCasualLeave"]).ToString();

string AvailedCL = Convert.ToInt16(item["AvailedCasualLeave"]).ToString();

string AvailSL = Convert.ToInt16(item["AvailableSickLeave"]).ToString();

string AvailedSL = Convert.ToInt16(item["AvailedSickLeave"]).ToString();

string AvailWL = Convert.ToInt16(item["AvailableWeddingAnniversary"]).ToString();

string AvailedWL = Convert.ToInt16(item["AvailedWeddingAnniversary"]).ToString();

string AvailSBL = Convert.ToInt16(item["AvailableSpouseBdayLeave"]).ToString();

string AvailedSBL = Convert.ToInt16(item["AvailedSpouseBdayLeave"]).ToString();

string AvailPL = Convert.ToInt16(item["AvailablePaternityLeave"]).ToString();

string AvailedPL = Convert.ToInt16(item["AvailedPaternityLeave"]).ToString();

string AvailML = Convert.ToInt16(item["AvailableMaternityLeave"]).ToString();

string AvailedML = Convert.ToInt16(item["AvailedMaternityLeave"]).ToString();

string AvailWFM = Convert.ToInt16(item["WorkfromHome"]).ToString();

string AvailOPL = Convert.ToInt16(item["OptionalLeave"]).ToString();

Regex reg = new Regex("[;#0123456789\\\\/:*?\"<>|&']");

string Empname = reg.Replace(empName, "");

if (empid.ToString() == LeaveEmpID.ToString())

{

SPFieldUserValue Appempmailid = new SPFieldUserValue(web, item["EmployeeName"].ToString());

string AppEmpEmailAddresss = Appempmailid.User.Email;

SPFieldUserValue AppHODmailid = new SPFieldUserValue(web, item["DepartmentHead"].ToString());

string AppHODEmailAddresss = AppHODmailid.User.Email;

SmtpClient mailClient = new SmtpClient();

MailMessage email = new MailMessage(AppHODEmailAddresss, AppEmpEmailAddresss);

email.CC.Add("hr@kryptos.in");

email.CC.Add("vallimayel@kryptos.in");

email.Subject = "Your Leave has been Approved ";

email.IsBodyHtml = true;

if (empsex == "Male")

{

//email.Body = "<html><body><table><tr><td>Dear Employee,</td></tr><tr><td></td></tr><tr><td></td></tr><tr><td>Please visit your Approved Leave details http://intranet.kryptos.in:8080/sites/KCS/HRM/Lists/LeaveData/DispForm.aspx?ID=" + hdnrowid.Value.ToString() + " </td></tr><tr><td>Please find the Leave Master Details below,.<tr><td> <table bgcolor='#F0F0F0' border='1' class='style1' align='center'><tr> <td> Available Casual Leave:</td> <td>" + AvailCL.ToString() + "</td></tr><tr><td>Available Sick Leave:</td><td>" + AvailSL.ToString() + "</td> </tr> <tr> <td>Available Wedding Leave:</td><td>" + AvailWL.ToString() + "</td></tr><tr><td>Available Paternity Leave:</td><td>" + AvailPL.ToString() + "</td></tr><tr><td>Available Spouse BirthDay Leave:</td><td>" + AvailSBL.ToString() + "</td></tr><tr><td>Available Optional Leave:</td><td>" + AvailOPL.ToString() + "</td></tr></table><tr><td> Regards,</td></tr><tr><td>Head Of Department</td></tr></table><body></html>";

email.Body = "<html><body><table><tr><td>Dear Employee,</td></tr><tr><td></td></tr><tr><td></td></tr><tr><td>Please visit your Approved Leave details<td><tr><table bgcolor='#F0F0F0' border='1' class='style1' align='center'><tr><td>Leave Category:</td><td>" + RecentLType.ToString() + "</td></tr><tr><td>Reason:</td><td>" + RecentLReason.ToString() + "</td></tr><tr><td>From Date:</td><td>" + RecentLFromdate.ToString() + "</td></tr><tr><td>TO Date:</td><td>" + RecentLTodate.ToString() + "</td></tr></table><tr><td>Please find the Leave Master Details below,.<tr><td> <table bgcolor='#F0F0F0' border='1' class='style1' align='center'><tr> <td> Available Casual Leave:</td> <td>" + AvailCL.ToString() + "</td></tr><tr><td>Available Sick Leave:</td><td>" + AvailSL.ToString() + "</td> </tr> <tr> <td>Available Wedding Leave:</td><td>" + AvailWL.ToString() + "</td></tr><tr><td>Available Paternity Leave:</td><td>" + AvailPL.ToString() + "</td></tr><tr><td>Available Spouse BirthDay Leave:</td><td>" + AvailSBL.ToString() + "</td></tr><tr><td>Available Optional Leave:</td><td>" + AvailOPL.ToString() + "</td></tr></table><tr><td> Regards,</td></tr><tr><td>Head Of Department</td></tr></table><body></html>";

}

else if (empsex == "Female")

{

//email.Body = "<html><body><table><tr><td>Dear Employee,</td></tr><tr><td></td></tr><tr><td></td></tr><tr><td>Please visit your Approved Leave details http://intranet.kryptos.in:8080/sites/KCS/HRM/Lists/LeaveData/DispForm.aspx?ID=" + hdnrowid.Value.ToString() + " </td></tr><tr><td>Please find the Leave Master Details below,.<tr><td> <table bgcolor='#F0F0F0' border='1' class='style1' align='center'><tr> <td> Available Casual Leave:</td> <td>" + AvailCL.ToString() + "</td></tr><tr><td>Available Sick Leave:</td><td>" + AvailSL.ToString() + "</td> </tr> <tr> <td>Available Wedding Leave:</td><td>" + AvailWL.ToString() + "</td></tr><tr><td>Available Maternity Leave:</td><td>" + AvailML.ToString() + "</td></tr><tr><td>Available Spouse BirthDay Leave:</td><td>" + AvailSBL.ToString() + "</td></tr><tr><td>Available Optional Leave:</td><td>" + AvailOPL.ToString() + "</td></tr></table><tr><td> Regards,</td></tr><tr><td>Head Of Department</td></tr></table><body></html>";

email.Body = "<html><body><table><tr><td>Dear Employee,</td></tr><tr><td></td></tr><tr><td></td></tr><tr><td>Please visit your Approved Leave details<td><tr><table bgcolor='#F0F0F0' border='1' class='style1' align='center'><tr><td>Leave Category:</td><td>" + RecentLType.ToString() + "</td></tr><tr><td>Reason:</td><td>" + RecentLReason.ToString() + "</td></tr><tr><td>From Date:</td><td>" + RecentLFromdate.ToString() + "</td></tr><tr><td>TO Date:</td><td>" + RecentLTodate.ToString() + "</td></tr></table><tr><td>Please find the Leave Master Details below,.<tr><td> <table bgcolor='#F0F0F0' border='1' class='style1' align='center'><tr> <td> Available Casual Leave:</td> <td>" + AvailCL.ToString() + "</td></tr><tr><td>Available Sick Leave:</td><td>" + AvailSL.ToString() + "</td> </tr> <tr> <td>Available Wedding Leave:</td><td>" + AvailWL.ToString() + "</td></tr><tr><td>Available Maternity Leave:</td><td>" + AvailML.ToString() + "</td></tr><tr><td>Available Spouse BirthDay Leave:</td><td>" + AvailSBL.ToString() + "</td></tr><tr><td>Available Optional Leave:</td><td>" + AvailOPL.ToString() + "</td></tr></table><tr><td> Regards,</td></tr><tr><td>Head Of Department</td></tr></table><body></html>";

}

mailClient.Port = 25;

mailClient.Host =
"vsr00a008-03.kryptos.gcc";

mailClient.Send(email);

DisplayMessage(
"Approved Leave Status has been sent to " + Empname.ToString() + " MailID Successfully", MessageType.Information);

}

}

}

}

});





#endregion


}

else if (ddlUpdateStatus.SelectedItem.Text == "Rejected")

{



#region
Rejected

SPSecurity.RunWithElevatedPrivileges(delegate()

{

//using (SPSite site = new SPSite(" http://intranet.kryptos.in:8080/sites/KCS/HRM/Lists/LeaveMasterData/AllItems.aspx"))

using (SPSite site = new SPSite(" http://intranet.kryptos.in:8080/sites/KCS/HRM/Lists/"))

{

site.AllowUnsafeUpdates =
true;

using (SPWeb web = site.OpenWeb())

{

web.AllowUnsafeUpdates =
true;

SPList list = web.Lists["LeaveMasterData"];

SPList leavelist = web.Lists["LeaveData"];

//Page.Response.Write("beforeL=hdrowid" + gvLeaveApproval.Rows[i].Cells[9].Text.ToString());

//if (LeaveRowID == hdnrowid.Value)

//{

// Page.Response.Write("afterL=hdrowid");

SPListItem leaveitem = leavelist.GetItemById(Convert.ToInt16(gvLeaveApproval.Rows[i].Cells[9].Text.ToString()));

string RecentLType = leaveitem["LeaveType"].ToString();

//string RecentLDate = leaveitem["CreatedBy"].ToString();

string RecentLReason = leaveitem["Reason"].ToString();

string RecentLFromdate = Convert.ToDateTime(leaveitem["FromDate"].ToString()).ToShortDateString();

string RecentLTodate = Convert.ToDateTime(leaveitem["ToDate"].ToString()).ToShortDateString();

// Page.Response.Write("RecentLType");

//Page.Response.Write("RecentLDate");

// Page.Response.Write("RecentLReason");

// Page.Response.Write("RecentLFromdate");

//Page.Response.Write("RecentLTodate");

foreach (SPListItem item in list.Items)

{

string RID = item["ID"].ToString();

string EmpID = item["EmployeeID"].ToString();

string empName = item["EmployeeName"].ToString();

string empsex = item["EmployeeSex"].ToString();

string AvailCL = Convert.ToInt16(item["AvailableCasualLeave"]).ToString();

string AvailedCL = Convert.ToInt16(item["AvailedCasualLeave"]).ToString();

string AvailSL = Convert.ToInt16(item["AvailableSickLeave"]).ToString();

string AvailedSL = Convert.ToInt16(item["AvailedSickLeave"]).ToString();

string AvailWL = Convert.ToInt16(item["AvailableWeddingAnniversary"]).ToString();

string AvailedWL = Convert.ToInt16(item["AvailedWeddingAnniversary"]).ToString();

string AvailSBL = Convert.ToInt16(item["AvailableSpouseBdayLeave"]).ToString();

string AvailedSBL = Convert.ToInt16(item["AvailedSpouseBdayLeave"]).ToString();

string AvailPL = Convert.ToInt16(item["AvailablePaternityLeave"]).ToString();

string AvailedPL = Convert.ToInt16(item["AvailedPaternityLeave"]).ToString();

string AvailML = Convert.ToInt16(item["AvailableMaternityLeave"]).ToString();

string AvailedML = Convert.ToInt16(item["AvailedMaternityLeave"]).ToString();

string AvailWFM = Convert.ToInt16(item["WorkfromHome"]).ToString();

string AvailOPL = Convert.ToInt16(item["OptionalLeave"]).ToString();

Regex reg = new Regex("[;#0123456789\\\\/:*?\"<>|&']");

string Empname = reg.Replace(empName, "");

if (LeaveEmpID.ToString() == EmpID.ToString())

{



SPFieldUserValue Appempmailid = new SPFieldUserValue(web, item["EmployeeName"].ToString());

string AppEmpEmailAddresss = Appempmailid.User.Email;

SPFieldUserValue AppHODmailid = new SPFieldUserValue(web, item["DepartmentHead"].ToString());

string AppHODEmailAddresss = AppHODmailid.User.Email;

SmtpClient mailClient = new SmtpClient();

MailMessage email = new MailMessage(AppHODEmailAddresss, AppEmpEmailAddresss);

email.CC.Add("hr@kryptos.in");

email.CC.Add("vallimayel@kryptos.in");

email.Subject = "Your Leave has been Rejected ";

email.IsBodyHtml = true;

if (empsex == "Male")

{

// Page.Response.Write("beforeL=hdrowidMail");

email.Body = "<html><body><table><tr><td>Dear Employee,</td></tr><tr><td></td></tr><tr><td></td></tr><tr><td>Please visit your Rejected Leave details<td><tr><table bgcolor='#F0F0F0' border='1' class='style1' align='center'><tr><td>Leave Category:</td><td>" + RecentLType.ToString() + "</td></tr><tr><td>Reason:</td><td>" + RecentLReason.ToString() + "</td></tr><tr><td>From Date:</td><td>" + RecentLFromdate.ToString() + "</td></tr><tr><td>TO Date:</td><td>" + RecentLTodate.ToString() + "</td></tr></table><tr><td>Please find the Leave Master Details below,.<tr><td> <table bgcolor='#F0F0F0' border='1' class='style1' align='center'><tr> <td> Available Casual Leave:</td> <td>" + AvailCL.ToString() + "</td></tr><tr><td>Available Sick Leave:</td><td>" + AvailSL.ToString() + "</td> </tr> <tr> <td>Available Wedding Leave:</td><td>" + AvailWL.ToString() + "</td></tr><tr><td>Available Paternity Leave:</td><td>" + AvailPL.ToString() + "</td></tr><tr><td>Available Spouse BirthDay Leave:</td><td>" + AvailSBL.ToString() + "</td></tr><tr><td>Available Optional Leave:</td><td>" + AvailOPL.ToString() + "</td></tr></table><tr><td> Regards,</td></tr><tr><td>Head Of Department</td></tr></table><body></html>";

//email.Body = "<html><body><table><tr><td>Dear Employee,</td></tr><tr><td></td></tr><tr><td></td></tr><tr><td>Please visit your Rejected Leave details </td></tr><tr><td>Please find the Leave Master Details below,.<tr><td> <table bgcolor='#F0F0F0' border='1' class='style1' align='center'><tr> <td> Available Casual Leave:</td> <td>" + AvailCL.ToString() + "</td></tr><tr><td>Available Sick Leave:</td><td>" + AvailSL.ToString() + "</td> </tr> <tr> <td>Available Wedding Leave:</td><td>" + AvailWL.ToString() + "</td></tr><tr><td>Available Paternity Leave:</td><td>" + AvailPL.ToString() + "</td></tr><tr><td>Available Spouse BirthDay Leave:</td><td>" + AvailSBL.ToString() + "</td></tr><tr><td>Available Optional Leave:</td><td>" + AvailOPL.ToString() + "</td></tr></table><tr><td> Regards,</td></tr><tr><td>Head Of Department</td></tr></table><body></html>";

//Page.Response.Write("beforeL=hdrowidMail");

}

else if (empsex == "Female")

{

email.Body =
"<html><body><table><tr><td>Dear Employee,</td></tr><tr><td></td></tr><tr><td></td></tr><tr><td>Please visit your Rejected Leave details<td><tr><table bgcolor='#F0F0F0' border='1' class='style1' align='center'><tr><td>Leave Category:</td><td>" + RecentLType.ToString() + "</td></tr><tr><td>Reason:</td><td>" + RecentLReason.ToString() + "</td></tr><tr><td>From Date:</td><td>" + RecentLFromdate.ToString() + "</td></tr><tr><td>TO Date:</td><td>" + RecentLTodate.ToString() + "</td></tr></table><tr><td>Please find the Leave Master Details below,.<tr><td> <table bgcolor='#F0F0F0' border='1' class='style1' align='center'><tr> <td> Available Casual Leave:</td> <td>" + AvailCL.ToString() + "</td></tr><tr><td>Available Sick Leave:</td><td>" + AvailSL.ToString() + "</td> </tr> <tr> <td>Available Wedding Leave:</td><td>" + AvailWL.ToString() + "</td></tr><tr><td>Available Maternity Leave:</td><td>" + AvailML.ToString() + "</td></tr><tr><td>Available Spouse BirthDay Leave:</td><td>" + AvailSBL.ToString() + "</td></tr><tr><td>Available Optional Leave:</td><td>" + AvailOPL.ToString() + "</td></tr></table><tr><td> Regards,</td></tr><tr><td>Head Of Department</td></tr></table><body></html>";

//email.Body = "<html><body><table><tr><td>Dear Employee,</td></tr><tr><td></td></tr><tr><td></td></tr><tr><td>Please visit your Rejected Leave details </td></tr><tr><td>Please find the Leave Master Details below,.<tr><td> <table bgcolor='#F0F0F0' border='1' class='style1' align='center'><tr> <td> Available Casual Leave:</td> <td>" + AvailCL.ToString() + "</td></tr><tr><td>Available Sick Leave:</td><td>" + AvailSL.ToString() + "</td> </tr> <tr> <td>Available Wedding Leave:</td><td>" + AvailWL.ToString() + "</td></tr><tr><td>Available Maternity Leave:</td><td>" + AvailML.ToString() + "</td></tr><tr><td>Available Spouse BirthDay Leave:</td><td>" + AvailSBL.ToString() + "</td></tr><tr><td>Available Optional Leave:</td><td>" + AvailOPL.ToString() + "</td></tr></table><tr><td> Regards,</td></tr><tr><td>Head Of Department</td></tr></table><body></html>";

}

mailClient.Port = 25;

mailClient.Host =
"vsr00a008-03.kryptos.gcc";

mailClient.Send(email);

DisplayMessage(
" Leave has been Rejected details sent to " + Empname.ToString() + " MailID ", MessageType.Information);

}



}

// }

}

}

});





#endregion


}

}

}

}

if (selectedCount == 0)

{

DisplayMessage(
"Please select atleast one leave to Approve/Reject", MessageType.Warning);

}

}

hdnApprovalProcess.Value =
"0";

InitGridView(gvLeaveApproval, "GetAll");

}

catch (Exception ex)

{

DisplayErroMessage(ex);

}

}

#endregion



#region

Methods_References

private void UpdatestatusinSiteList()

{

try

{

int selectedCount = 0;

for (int i = 0; i < gvLeaveApproval.Rows.Count; i++)

{

CheckBox chk = (CheckBox)gvLeaveApproval.Rows[i].Cells[0].Controls[0];

if (chk != null)

{

if (chk.Checked)

{

selectedCount++;



string Name = gvLeaveApproval.Rows[i].Cells[1].Text.ToString();

string ROWID = gvLeaveApproval.Rows[i].Cells[9].Text.ToString();

SPSecurity.RunWithElevatedPrivileges(delegate()

{

using (SPSite site = new SPSite("http://intranet.kryptos.in:8080/sites/KCS/HRM/Lists/"))

{

site.AllowUnsafeUpdates =
true;

using (SPWeb web = site.OpenWeb())

{

web.AllowUnsafeUpdates =
true;

SPList pics = web.Lists["LeaveData"];

foreach (SPListItem item in pics.Items)

{

string RID = item["ID"].ToString();

string Empname = item["EmployeeID"].ToString();



if (ROWID == RID)

{

item[
"LeaveApprovalStatus"] = ddlUpdateStatus.SelectedItem.Text.ToString();

item.Update();

}



}

}

}

});



if (selectedCount == 0)

{

DisplayMessage(
"Please select atleast one record to Approve", MessageType.Warning);

}

else

{

DisplayMessage(
"Leave has been Apply Successfully ", MessageType.Information);

}



}

}



}

}

catch (Exception ex)

{

DisplayErroMessage(ex);

}

}

private void UpdaterejectedList()

{

int selectedCount = 0;

for (int i = 0; i < gvLeaveApproval.Rows.Count; i++)

{

CheckBox chk = (CheckBox)gvLeaveApproval.Rows[i].Cells[0].Controls[0];

if (chk != null)

{

if (chk.Checked)

{

selectedCount++;

string EMPID = gvLeaveApproval.Rows[i].Cells[1].Text.ToString();

string ROWID = gvLeaveApproval.Rows[i].Cells[9].Text.ToString();

hdnempid.Value = EMPID;

SPSecurity.RunWithElevatedPrivileges(delegate()

{

using (SPSite site = new SPSite("http://intranet.kryptos.in:8080/sites/KCS/HRM/Lists/"))

{

site.AllowUnsafeUpdates =
true;

using (SPWeb web = site.OpenWeb())

{

web.AllowUnsafeUpdates =
true;

SPList pics = web.Lists["LeaveData"];

foreach (SPListItem item in pics.Items)

{

string RowEid = item["ID"].ToString();

string Empid = item["EmployeeID"].ToString();

string LeaveCategory = item["LeaveType"].ToString();

hdnleavecaty.Value = LeaveCategory.ToString();

Regex re = new Regex("[float;#]");



string nofdays = re.Replace(item["NumberofDays"].ToString(), "");

//Page.Response.Write(nofdays.ToString());

hdnNofDays.Value = nofdays.ToString();



if (Empid == EMPID)

{

if (RowEid == ROWID)

{

//string RecentLType = item["LeaveType"].ToString();

//string RecentLDate = item["CreatedBy"].ToString();

//string RecentLReason = item["Reason"].ToString();

//string RecentLFromdate = Convert.ToDateTime(item["FromDate"].ToString()).ToShortDateString();

//string RecentLTodate = Convert.ToDateTime(item["ToDate"].ToString()).ToShortDateString();

//hdnRecentLType.Value = RecentLType;

//hdnRecentLDate.Value = RecentLDate;

//hdnRecentLReason.Value = RecentLReason;

//hdnRecentLFromdate.Value = RecentLFromdate;

//hdnRecentLTodate.Value = RecentLTodate;

item["LeaveApprovalStatus"] = ddlUpdateStatus.SelectedItem.Text.ToString();

item.Update();

SPSecurity.RunWithElevatedPrivileges(delegate()

{

using (SPSite ssite = new SPSite("http://intranet.kryptos.in:8080/sites/KCS/HRM/Lists/"))

{

ssite.AllowUnsafeUpdates =
true;

using (SPWeb sweb = ssite.OpenWeb())

{

web.AllowUnsafeUpdates =
true;

SPList spics = web.Lists["LeaveMasterData"];

foreach (SPListItem items in spics.Items)

{

string sEmpid = items["EmployeeID"].ToString();

string AvailCL = Convert.ToInt16(items["AvailableCasualLeave"]).ToString();

string AvailedCL = Convert.ToInt16(items["AvailedCasualLeave"]).ToString();

string AvailSL = Convert.ToInt16(items["AvailableSickLeave"]).ToString();

string AvailedSL = Convert.ToInt16(items["AvailedSickLeave"]).ToString();

string AvailWL = Convert.ToInt16(items["AvailableWeddingAnniversary"]).ToString();

string AvailedWL = Convert.ToInt16(items["AvailedWeddingAnniversary"]).ToString();

string AvailSBL = Convert.ToInt16(items["AvailableSpouseBdayLeave"]).ToString();

string AvailedSBL = Convert.ToInt16(items["AvailedSpouseBdayLeave"]).ToString();

string AvailPL = Convert.ToInt16(items["AvailablePaternityLeave"]).ToString();

string AvailedPL = Convert.ToInt16(items["AvailedPaternityLeave"]).ToString();

string AvailML = Convert.ToInt16(items["AvailableMaternityLeave"]).ToString();

string AvailedML = Convert.ToInt16(items["AvailedMaternityLeave"]).ToString();

string AvailWFM = Convert.ToInt16(items["WorkfromHome"]).ToString();

string AvailOPL = Convert.ToInt16(items["OptionalLeave"]).ToString();

if (sEmpid == EMPID)

{

Guid itemId = items.UniqueId;

SPListItem updateitem = web.Lists["LeaveMasterData"].Items[itemId];

decimal d = Convert.ToDecimal(hdnNofDays.Value.ToString());

int no = Convert.ToInt32(Math.Truncate(d));

//Page.Response.Write(no.ToString());

#region
leaveinfo

if (hdnleavecaty.Value.ToString() == "Casual Leave")

{

int acl = Int32.Parse(AvailCL);

int alcl = Int32.Parse(AvailedCL);

updateitem["AvailableCasualLeave"] = (no + acl);

updateitem["AvailedCasualLeave"] = ((alcl) - no);

updateitem.Update();



}

else if (hdnleavecaty.Value.ToString() == "Sick Leave")

{

int asl = Int32.Parse(AvailSL);

int alsl = Int32.Parse(AvailedSL);

updateitem["AvailableSickLeave"] = (no + asl);//(Convert.ToInt16(AvailSL) + (Convert.ToInt16(hdnNofDays.Value))).ToString();

updateitem["AvailedSickLeave"] = ((alsl) - no);//(Convert.ToInt16(hdnNofDays.Value) - Convert.ToInt16(AvailedSL)).ToString();

updateitem.Update();

}

else if (hdnleavecaty.Value.ToString() == "Wedding Anniversary")

{

int awl = Int32.Parse(AvailWL);

int alwl = Int32.Parse(AvailedWL);

updateitem["AvailableWeddingAnniversary"] = (no + awl);//(Convert.ToInt16(AvailWL) + (Convert.ToInt16(hdnNofDays.Value))).ToString();

updateitem["AvailedWeddingAnniversary"] = ((alwl) - no);//(Convert.ToInt16(hdnNofDays.Value) - Convert.ToInt16(AvailedWL)).ToString();

updateitem.Update();

}

else if (hdnleavecaty.Value.ToString() == "Spouse Birthday")

{

int asp = Int32.Parse(AvailSBL);

int alsp = Int32.Parse(AvailedSBL);

updateitem["AvailableSpouseBdayLeave"] = (no + asp);//(Convert.ToInt16(AvailSBL) + (Convert.ToInt16(hdnNofDays.Value))).ToString();

updateitem["AvailedSpouseBdayLeave"] = ((alsp) - no); //(Convert.ToInt16(hdnNofDays.Value) - Convert.ToInt16(AvailedSBL)).ToString();

updateitem.Update();

}

else if (hdnleavecaty.Value.ToString() == "Paternity Leave")

{

int apl = Int32.Parse(AvailPL);

int alpl = Int32.Parse(AvailedPL);

updateitem["AvailablePaternityLeave"] = (no + apl); //(Convert.ToInt16(AvailPL) + (Convert.ToInt16(hdnNofDays.Value))).ToString();

updateitem["AvailedPaternityLeave"] = ((alpl) - no); //(Convert.ToInt16(hdnNofDays.Value) - Convert.ToInt16(AvailedPL)).ToString();

updateitem.Update();



}

else if (hdnleavecaty.Value.ToString() == "Maternity Leave")

{

int aml = Int32.Parse(AvailML);

int alml = Int32.Parse(AvailedML);

updateitem["AvailableMaternityLeave"] = (no + aml);// (Convert.ToInt16(AvailML) + (Convert.ToInt16(hdnNofDays.Value))).ToString();

updateitem["AvailedMaternityLeave"] = ((alml) - no);// (Convert.ToInt16(hdnNofDays.Value) - Convert.ToInt16(AvailedML)).ToString();

updateitem.Update();

}

else if (hdnleavecaty.Value.ToString() == "Work from Home")

{

int awfh = Int32.Parse(AvailWFM);

updateitem["WorkfromHome"] = ((awfh) - no); //(Convert.ToInt16(hdnNofDays.Value) - Convert.ToInt16(AvailWFM)).ToString();

updateitem.Update();

}

else if (hdnleavecaty.Value.ToString() == "Optional Leave")

{

int aopl = Int32.Parse(AvailOPL);

updateitem["OptionalLeave"] = ((aopl) - no); //(Convert.ToInt16(hdnNofDays.Value) - Convert.ToInt16(AvailOPL)).ToString();

updateitem.Update();

}

#endregion


}

}

if (selectedCount == 0)

{

DisplayMessage(
"Please select atleast one record to Reject", MessageType.Warning);

}

else

{

DisplayMessage(
"Leave has been Rejected ", MessageType.Information);

}

}

}

});

}

}

}

if (selectedCount == 0)

{

DisplayMessage(
"Please select atleast one record to Reject", MessageType.Warning);

}

else

{

DisplayMessage(
"Leave has been Rejected ", MessageType.Information);

}

}

}

});





}

}

}



}

private void ClearGridCheckBox()

{

for (int i = 0; i < gvLeaveApproval.Rows.Count; i++)

{

CheckBox chkSelect = (CheckBox)gvLeaveApproval.Rows[i].Cells[1].FindControl("strCheckBoxName");

chkSelect.Checked = false;

}

}

private void LoadUpdateStatus()

{

try

{

ddlUpdateStatus.Items.Insert(0,
new ListItem("Select", "-1"));

ddlUpdateStatus.Items.Insert(1, new ListItem("Approved"));

ddlUpdateStatus.Items.Insert(2, new ListItem("Rejected"));

}

catch (Exception ex)

{

DisplayErroMessage(ex);

}

}

protected void CheckApprover()

{

try

{

#region
checkApprover

SPSecurity.RunWithElevatedPrivileges(delegate()

{

using (SPSite site = new SPSite("http://intranet.kryptos.in:8080/sites/KCS/HRM/Lists/"))

{

site.AllowUnsafeUpdates =
true;

using (SPWeb web = site.OpenWeb())

{

//web.AllowUnsafeUpdates = true;

//PrincipalContext ctx = new PrincipalContext(ContextType.Domain);

//UserPrincipal user = UserPrincipal.Current;

//string displayName = user.DisplayName;

SPWeb webloggedUser = SPControl.GetContextWeb(Context);

SPUser sUser = webloggedUser.CurrentUser;

hdnappdisplayname.Value = sUser.ToString();

web.AllowUnsafeUpdates =
true;

SPList list = web.Lists["LeaveData"];

foreach (SPListItem item in list.Items)

{

string approver = item["Approver"].ToString();

Regex re = new Regex("[;#0123456789\\\\/:*?\"<>|&']");

string approverName = re.Replace(approver, "");

hdnapprover.Value = approverName;

//Page.Response.Write(approverName.ToString());

}

}

}

});

#endregion


}

catch (Exception ex)

{

DisplayErroMessage(ex);

}

}

#endregion



#region

CreateChildControls

protected override void CreateChildControls()

{

TableCell tc;

//TableCell tc1;

TableRow tr;



base.CreateChildControls();

if (ScriptManager.GetCurrent(this.Page) == null)

{

ScriptManager scriptHandler = new ScriptManager();

scriptHandler.ID = "scriptHandler";

scriptHandler.EnablePartialRendering = true;

this.Controls.Add(scriptHandler);

}

#region
Ajax Update Panel

this.EnsureUpdatePanelFixups();

UpdatePanel up1 = new UpdatePanel();

up1.ID = "UpdatePanel1";

up1.ChildrenAsTriggers = true;

up1.UpdateMode = UpdatePanelUpdateMode.Conditional;

up1.Update();

UpdatePanel up2 = new UpdatePanel();

up2.ID = "UpdatePanel2";

up2.ChildrenAsTriggers = true;

up2.UpdateMode = UpdatePanelUpdateMode.Conditional;

up2.Update();

UpdatePanel up3 = new UpdatePanel();

up3.ID = "UpdatePanel3";

up3.ChildrenAsTriggers = true;

up3.UpdateMode = UpdatePanelUpdateMode.Conditional;

up3.Update();

#endregion

#region

View ApprovalFields

tr = new TableRow();

tc = new TableCell();

tc.HorizontalAlign = HorizontalAlign.Center;

pnlLeaveApproval.Controls.Add(hdnrowid);

tc.Controls.Add(pnlLeaveApproval);

tr.Cells.Add(tc);

tblPartnerView.Rows.Add(tr);



tr =
new TableRow();

tc = new TableCell();

tc.HorizontalAlign = HorizontalAlign.Center;

pnlLeaveApproval.Controls.Add(hdnempid);

tc.Controls.Add(pnlLeaveApproval);

tr.Cells.Add(tc);

tblPartnerView.Rows.Add(tr);



tr =
new TableRow();

tc = new TableCell();

tc.HorizontalAlign = HorizontalAlign.Center;

pnlLeaveApproval.Controls.Add(hdnapprover);

tc.Controls.Add(pnlLeaveApproval);

tr.Cells.Add(tc);

tblPartnerView.Rows.Add(tr);



tr =
new TableRow();

tc = new TableCell();

tc.HorizontalAlign = HorizontalAlign.Center;

pnlLeaveApproval.Controls.Add(hdnappdisplayname);

tc.Controls.Add(pnlLeaveApproval);

tr.Cells.Add(tc);

tblPartnerView.Rows.Add(tr);

tr =
new TableRow();

tc = new TableCell();

tc.HorizontalAlign = HorizontalAlign.Center;

pnlLeaveApproval.Controls.Add(hdnsoln);

tc.Controls.Add(pnlLeaveApproval);

tr.Cells.Add(tc);

tblPartnerView.Rows.Add(tr);



tr =
new TableRow();

tc = new TableCell();

tc.HorizontalAlign = HorizontalAlign.Center;

pnlLeaveApproval.Controls.Add(gvLeaveApproval);

tc.Controls.Add(pnlLeaveApproval);

tr.Cells.Add(tc);

tblPartnerView.Rows.Add(tr);

tr =
new TableRow();

tc = new TableCell();

tc.HorizontalAlign = HorizontalAlign.Center;

pnlLeaveApproval.Controls.Add(hdnleavecaty);

tc.Controls.Add(pnlLeaveApproval);

tr.Cells.Add(tc);

tblPartnerView.Rows.Add(tr);

tr =
new TableRow();

tc = new TableCell();

tc.HorizontalAlign = HorizontalAlign.Center;

pnlLeaveApproval.Controls.Add(hdnNofDays);

tc.Controls.Add(pnlLeaveApproval);

tr.Cells.Add(tc);

tblPartnerView.Rows.Add(tr);

tr =
new TableRow();

tc = new TableCell();

tc.HorizontalAlign = HorizontalAlign.Center;

pnlLeaveApproval.Controls.Add(hdnRecentLType);

tc.Controls.Add(pnlLeaveApproval);

tr.Cells.Add(tc);

tblPartnerView.Rows.Add(tr);

tr =
new TableRow();

tc = new TableCell();

tc.HorizontalAlign = HorizontalAlign.Center;

pnlLeaveApproval.Controls.Add(hdnRecentLDate);

tc.Controls.Add(pnlLeaveApproval);

tr.Cells.Add(tc);

tblPartnerView.Rows.Add(tr);

tr =
new TableRow();

tc = new TableCell();

tc.HorizontalAlign = HorizontalAlign.Center;

pnlLeaveApproval.Controls.Add(hdnRecentLReason);

tc.Controls.Add(pnlLeaveApproval);

tr.Cells.Add(tc);

tblPartnerView.Rows.Add(tr);

tr =
new TableRow();

tc = new TableCell();

tc.HorizontalAlign = HorizontalAlign.Center;

pnlLeaveApproval.Controls.Add(hdnRecentLTodate);

tc.Controls.Add(pnlLeaveApproval);

tr.Cells.Add(tc);

tblPartnerView.Rows.Add(tr);

tr =
new TableRow();

tc = new TableCell();

tc.HorizontalAlign = HorizontalAlign.Center;

pnlLeaveApproval.Controls.Add(hdnRecentLFromdate);

tc.Controls.Add(pnlLeaveApproval);

tr.Cells.Add(tc);

tblPartnerView.Rows.Add(tr);



tr =
new TableRow();

tc = new TableCell();

tc.ColumnSpan = 2;

tc.HorizontalAlign =
HorizontalAlign.Center;

Literal ltSpace = new Literal();

ltSpace.Text = "&nbsp;&nbsp;&nbsp;";

tc.Controls.Add(lblUpdateStatus);

tc.Controls.Add(ltSpace);

tc.Controls.Add(ddlUpdateStatus);

tc.Controls.Add(hdnsoln);

tr.Cells.Add(tc);

tblPartnerView.Rows.Add(tr);



tr =
new TableRow();

tc = new TableCell();

tc.ColumnSpan = 2;

tc.HorizontalAlign =
HorizontalAlign.Center;

Literal ltSpace1 = new Literal();

ltSpace1.Text = "&nbsp;&nbsp;&nbsp;";

tc.Controls.Add(lblComments);

tc.Controls.Add(ltSpace1);

tc.Controls.Add(txtComments);

tc.Controls.Add(hdnsoln);

tr.Cells.Add(tc);

tblPartnerView.Rows.Add(tr);



tr =
new TableRow();

tc = new TableCell();

tc.ColumnSpan = 2;

tc.HorizontalAlign =
HorizontalAlign.Center;

Literal ltSpace2 = new Literal();

ltSpace2.Text = "&nbsp;&nbsp;&nbsp;";

tc.Controls.Add(btnSubmit);

tc.Controls.Add(ltSpace2);

tc.Controls.Add(btnCancel);

tc.Controls.Add(hdnApprovalProcess);

tr.Cells.Add(tc);

tblPartnerView.Rows.Add(tr);

#endregion

#region

Add Controls to main table

tr = new TableRow();

tc = new TableCell();

tc.VerticalAlign = VerticalAlign.Top;

tc.HorizontalAlign = HorizontalAlign.Center;

tc.Controls.Add(tblPartnerView);

tr.Cells.Add(tc);

tblMain.Rows.Add(tr);

tr =
new TableRow();

tc = new TableCell();

tc.VerticalAlign = VerticalAlign.Top;

tc.HorizontalAlign = HorizontalAlign.Center;

tc.Controls.Add(tblLeaveApproval);

tr.Cells.Add(tc);

tblMain.Rows.Add(tr);

//Add Status Label

tr = new TableRow();

tc = new TableCell();

tc.HorizontalAlign = HorizontalAlign.Center;

tc.ColumnSpan = 2;

tc.Controls.Add(hdnNofDays);

tr.Cells.Add(tc);

tr.Cells.Add(tc);

tblMain.Rows.Add(tr);



tr =
new TableRow();

tc = new TableCell();

tc.HorizontalAlign = HorizontalAlign.Center;

tc.ColumnSpan = 2;

tc.Controls.Add(lblStatus);

tr.Cells.Add(tc);

tr.Cells.Add(tc);

tblMain.Rows.Add(tr);

this.Controls.Add(tblMain);

#endregion


}

#endregion



#region

InitiateGridView

private void InitGridView(GridView grdView, string oper)

{

try

{

#region
CheckApprover

SPWeb webCA = SPControl.GetContextWeb(Context);

SPUser sUser = webCA.CurrentUser;

string approverName = "";

string status = "";

hdnappdisplayname.Value = sUser.Name.ToString();

SPSecurity.RunWithElevatedPrivileges(delegate()

{

using (SPSite site = new SPSite("http://intranet.kryptos.in:8080/sites/KCS/HRM/Lists/"))

{

site.AllowUnsafeUpdates =
true;

using (SPWeb web = site.OpenWeb())

{

web.AllowUnsafeUpdates =
true;

SPList list = web.Lists["LeaveData"];

foreach (SPListItem item in list.Items)

{

string empleavedata = item["Approver"].ToString();

Regex reg = new Regex("[;#0123456789\\\\/:*?\"<>|&']");

string LeaveEmpName = reg.Replace(empleavedata, "");

if (sUser.Name.ToString() == LeaveEmpName)

{

string approver = item["Approver"].ToString();

status = item["LeaveApprovalStatus"].ToString();

Regex re = new Regex("[;#0123456789\\\\/:*?\"<>|&']");

approverName = re.Replace(approver, "");

hdnapprover.Value = approverName;

}

}

}

}

});

#endregion


grdView.DataSource = null;

grdView.AutoGenerateColumns = false;

grdView.DataBind();

grdView.Columns.Clear();

grdView.CellPadding = 0;

grdView.CellSpacing = 0;

grdView.BorderStyle =
BorderStyle.Solid;

grdView.BorderWidth = Unit.Pixel(1);

grdView.BorderColor = ColorTranslator.FromHtml("#869D6");

grdView.HeaderStyle.BackColor = ColorTranslator.FromHtml("#869D6");

grdView.HeaderStyle.ForeColor = ColorTranslator.FromHtml("#000000");

grdView.HeaderStyle.BackColor = ColorTranslator.FromHtml("#8CC3FF");

grdView.HeaderStyle.ForeColor = ColorTranslator.FromHtml("#ffffff");

grdView.Width = Unit.Percentage(100);

if (oper == "GetAll")

{

SPSecurity.RunWithElevatedPrivileges(delegate()

{

using (SPSite site = new SPSite("http://intranet.kryptos.in:8080/sites/KCS/HRM/Lists/"))

{

site.AllowUnsafeUpdates =
true;

using (SPWeb web = site.OpenWeb())

{

web.AllowUnsafeUpdates =
true;

SPList list = web.Lists["LeaveData"];

DataTable table = new DataTable();

table.Columns.Add("EmployeeID", typeof(string));

table.Columns.Add("EmployeeName", typeof(string));

table.Columns.Add("LeaveType", typeof(string));

table.Columns.Add("FromDate", typeof(string));

table.Columns.Add("ToDate", typeof(string));

table.Columns.Add("NumberofDays", typeof(string));

table.Columns.Add("Reason", typeof(string));

table.Columns.Add("LeaveApprovalStatus", typeof(string));

table.Columns.Add("ID", typeof(string));

DataRow row;

foreach (SPListItem item in list.Items)

{

string Empid = item["EmployeeID"].ToString();

int rowid = Convert.ToInt32(item["ID"]);

hdnrowid.Value = rowid.ToString();

}

SPList appList = web.Lists["LeaveData"];

SPQuery SPMyQuery = new SPQuery();

string camlquery = "<Where> <And> <Eq><FieldRef Name='LeaveApprovalStatus' /> <Value Type='Text'>Pending</Value> </Eq> <Eq><FieldRef Name='Approver' /> <Value Type='Text'>" + sUser.Name.ToString() + "</Value> </Eq> </And></Where>";

SPMyQuery.Query = camlquery;

SPListItemCollection applistitemcoll = appList.GetItems(SPMyQuery);

foreach (SPListItem applistitem in applistitemcoll)

{

row = table.Rows.Add();

row[
"EmployeeID"] = applistitem["EmployeeID"].ToString();

row["EmployeeName"] = applistitem["EmployeeName"].ToString();

row["LeaveType"] = applistitem["LeaveType"].ToString();

row["FromDate"] = Convert.ToDateTime(applistitem["FromDate"].ToString()).ToShortDateString();

row["ToDate"] = Convert.ToDateTime(applistitem["ToDate"].ToString()).ToShortDateString();

Regex re = new Regex("[float;#]");

row["NumberofDays"] = re.Replace(applistitem["NumberofDays"].ToString(), "");

row["Reason"] = applistitem["Reason"].ToString();

row["LeaveApprovalStatus"] = applistitem["LeaveApprovalStatus"].ToString();

row["ID"] = applistitem["ID"].ToString();



}

//hdnsoln.Value = status.ToString();

if (sUser.Name.ToString() == hdnapprover.Value.ToString())

{

btnSubmit.Visible =
true;

btnCancel.Visible = true;

lblUpdateStatus.Visible = true;

ddlUpdateStatus.Visible = true;

#region
LeaveData

BoundField bfield;

gvLeaveApproval.AllowSorting = true;

if (table.Rows.Count > 0)

{

TemplateField tmplCol = new TemplateField();

tmplCol.HeaderText = "Select";

tmplCol.ItemStyle.HorizontalAlign = HorizontalAlign.Center;

tmplCol.ItemTemplate = new CreateItemTemplateCheckBox("chkboxCustomer", false);

gvLeaveApproval.Columns.Add(tmplCol);

bfield =
new BoundField();

bfield.DataField = "EmployeeID";

bfield.HeaderText = "Employee ID";

gvLeaveApproval.Columns.Add(bfield);

bfield =
new BoundField();

bfield.DataField = "EmployeeName";

bfield.HeaderText = "Employee Name";

gvLeaveApproval.Columns.Add(bfield);

bfield =
new BoundField();

bfield.DataField = "LeaveType";

bfield.HeaderText = "Leave Type";

gvLeaveApproval.Columns.Add(bfield);



bfield =
new BoundField();

bfield.DataFormatString = "{0:MM-dd-yyyy }";

bfield.DataField = "FromDate";

bfield.HeaderText = "From Date";

bfield.HtmlEncode = false;

gvLeaveApproval.Columns.Add(bfield);

bfield =
new BoundField();

bfield.DataFormatString = "{0:MM-dd-yyyy }";

bfield.DataField = "ToDate";

bfield.HeaderText = "To Date";

bfield.HtmlEncode = false;

gvLeaveApproval.Columns.Add(bfield);

bfield =
new BoundField();

bfield.DataField = "NumberofDays";

bfield.HeaderText = "Number Of Days";

gvLeaveApproval.Columns.Add(bfield);

bfield =
new BoundField();

bfield.DataField = "Reason";

bfield.HeaderText = "Reason";

gvLeaveApproval.Columns.Add(bfield);



bfield =
new BoundField();

bfield.DataField = "LeaveApprovalStatus";

bfield.HeaderText = "LeaveApproval Status";

gvLeaveApproval.Columns.Add(bfield);

bfield =
new BoundField();

bfield.DataField = "ID";

bfield.HeaderText = "ItemID";

gvLeaveApproval.Columns.Add(bfield);



gvLeaveApproval.DataSource = table.DefaultView;

gvLeaveApproval.DataBind();

tblPartnerView.Visible =
true;

tblLeaveApproval.Visible = true;

pnlLeaveApproval.Visible = true;

gvLeaveApproval.Visible = true;

btnCancel.Visible = true;

}

// data table is empty here..!!

else

{

DisplayMessage(
"No Leave Request Pending for your Approval !!!", MessageType.Information);

pnlLeaveApproval.Visible = false;

gvLeaveApproval.Visible = false;

btnSubmit.Visible = false;

btnCancel.Visible = false;

tblLeaveApproval.Visible = false;

tblPartnerView.Visible = false;

}

#endregion


}

else

{

DisplayMessage(
"Only Head of Department shall can be able to Approve/Reject the Leave Request..!!", MessageType.Warning);

}

}

}

});

}

}

catch (Exception ex)

{

DisplayErroMessage(ex);

}

}

#endregion



#region

Error handling methods

private enum MessageType

{

Information,

Warning

}

private void DisplayErroMessage(Exception e)

{

// Display Error Message

this.lblStatus.ForeColor = Color.Red;

this.lblStatus.Text = "Application has encountered the problem. Report this message to your administrator. <br>" + e.Message + e.Source + e.StackTrace;

}

private void DisplayMessage(string Message, MessageType msgType)

{

// Display Warning Message

if (msgType == MessageType.Information)

this.lblStatus.ForeColor = Color.Blue;

else

this.lblStatus.ForeColor = Color.Red;

this.lblStatus.Text = Message;



}

#endregion



#region

Ajax Update Code

private void EnsureUpdatePanelFixups()

{

if (this.Page.Form != null)

{

string formOnSubmitAtt = this.Page.Form.Attributes["onsubmit"];

if (formOnSubmitAtt == "return _spFormOnSubmitWrapper();")

{

this.Page.Form.Attributes["onsubmit"] = "_spFormOnSubmitWrapper();";

}

}

ScriptManager.RegisterStartupScript(this, typeof(LeaveApprovalProcess), "UpdatePanelFixup", "_spOriginalFormAction = document.forms[0].action; _spSuppressFormOnSubmitWrapper=true;", true);

}

#endregion


}

}

No comments:

Post a Comment