Thursday, September 13, 2012

LeaveManagement

using
System;

using
System.Collections.Generic;

using
System.Linq;

using
System.Text;

using
System.Drawing;

using
System.Data;

using
System.DirectoryServices.AccountManagement;

using
System.Data.SqlClient;

using
System.Xml.Serialization;

using
System.IO;

using
System.Web;

using
System.Net;

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
Microsoft.SharePoint;

using
Microsoft.SharePoint.WebControls;

using
Microsoft.SharePoint.WebPartPages;

using
System.Runtime.InteropServices;

using
System.Data.Sql;

using
System.Data.SqlTypes;

using
System.Net.Mail;

using
System.Reflection;

using
System.Security.Principal;

using
System.Text.RegularExpressions;

using
Microsoft.SharePoint.Utilities;



namespace
LeaveRequisition

{

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

{

#region
ConnectionString

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

#endregion



#region

Declaration_Controls

Label lblStatus = new Label();

Label lblEmpName = new Label();

Label lblEmpID = new Label();

Label lblDept = new Label();

Label lblDeptHead = new Label();

Label lblEmpStatus = new Label();

Label lblEmpSex = new Label();

Label lblFromDate = new Label();

Label lblToDate = new Label();

Label lblReason = new Label();

Label lblLeaveType = new Label();

Label lblNote = new Label();

Label lblAppover = new Label();

#region
LeaveInformationProcess

Label lblTotalNoofLeave = new Label();

Label lblNoofLeaveAvail = new Label();

Label lblNoofLeaveTaken = new Label();

Label lblNoofBalLeave = new Label();

#endregion




Label txtEmpName = new Label();

Label txtEmpID = new Label();

Label txtDept = new Label();

Label txtDeptHead = new Label();

Label txtEmpStatus = new Label();

Label txtEmpSex = new Label();

DropDownList ddlDept = new DropDownList();

TextBox txtNoofDays = new TextBox();

DateTimeControl dtFromDate = new DateTimeControl();

DateTimeControl dtToDate = new DateTimeControl();

TextBox txtReason = new TextBox();

DropDownList ddlLeaveType = new DropDownList();

DropDownList ddlApprover = new DropDownList();

PeopleEditor ctrlpplPicker = new PeopleEditor();



Label txtTotalNoofLeave = new Label();

Label txtNoofLeaveAvail = new Label();

Label txtNoofLeaveTaken = new Label();

Label txtNoofBalLeave = new Label();



HiddenField hdnEmpid = new HiddenField();

HiddenField hdnMasterEmpid = new HiddenField();

HiddenField hdnEmpname = new HiddenField();

HiddenField hdndisplayemail = new HiddenField();

HiddenField hdnapprover = new HiddenField();

HiddenField hdnhodEmailID = new HiddenField();

HiddenField hdnTS = new HiddenField();

HiddenField hdnLeaveCategory = new HiddenField();

HiddenField hdnLeaveRequisition = new HiddenField();

HiddenField hdnAvailCL = new HiddenField();

HiddenField hdnAvailSL = new HiddenField();

HiddenField hdnAvailSB = new HiddenField();

HiddenField hdnAvailWL = new HiddenField();

HiddenField hdnAvailML = new HiddenField();

HiddenField hdnAvailPL = new HiddenField();

HiddenField hdnAvailWFH = new HiddenField();

HiddenField hdnAvailOPL = new HiddenField();





Button btnClear = new Button();

Button btnApply = new Button();



Table tblStatic = new Table();

Table tblUserInputs = new Table();

Table tblLeaveInfo = new Table();

Table tblMain = new Table();

#endregion



#region

OnInitiate_Method

protected override void OnInit(EventArgs e)

{

try

{

base.OnInit(e);

this.InitiliseComponenet();

LoadEmpData();

}

catch (Exception ex)

{

DisplayErroMessage(ex);

}

}

#endregion



#region

Initialize_Component

private void InitiliseComponenet()

{

try

{

lblStatus.ID =
"lblStatus";

hdnapprover.ID = "hdnapprover";

hdnLeaveRequisition.ID = "hdnLeaveCategory";

hdnLeaveRequisition.ID = "hdnLeaveRequisition";

hdnTS.ID = "hdnTS";

hdnEmpid.ID = "hdnEmpid";

hdnEmpname.ID = "hdnEmpname";

hdndisplayemail.ID = "hdndisplayemail";

hdnAvailCL.ID = "hdnAvailCL";

hdnAvailSL.ID = "hdnAvailSL";

hdnAvailWL.ID = "hdnAvailWL";

hdnAvailML.ID = "hdnAvailML";

hdnAvailPL.ID = "hdnAvailPL";

hdnAvailWFH.ID = "hdnAvailWFH";

hdnAvailOPL.ID = "hdnAvailOPL";

hdnAvailSB.ID = "hdnAvailSB";

hdnMasterEmpid.ID = "hdnMasterEmpid";

hdnhodEmailID.ID = "hdnhodEmailID";



lblEmpName.ID =
"lblEmpName";

lblEmpName.Text = "Employee Name:";

lblEmpName.Font.Size = new FontUnit(10);

lblEmpName.Width = Unit.Percentage(100);

txtEmpName.ID = "txtEmpName";

txtEmpName.Font.Size = new FontUnit(10);

txtEmpName.Width = Unit.Percentage(100);







lblEmpID.ID =
"lblEmpID";

lblEmpID.Text = "Employee ID:";

lblEmpID.Font.Size = new FontUnit(10);

lblEmpID.Width = Unit.Percentage(100);

txtEmpID.ID = "txtEmpID";

txtEmpID.Font.Size = new FontUnit(10);

txtEmpID.Width = Unit.Percentage(100);



lblDept.ID =
"lblDept";

lblDept.Text = "Department:";

lblDept.Font.Size = new FontUnit(10);

lblDept.Width = Unit.Percentage(100);

txtDept.ID = "txtDept";

txtDept.Font.Size = new FontUnit(10);

txtDept.Width = Unit.Percentage(100);



lblDeptHead.ID =
"lblDeptHead";

lblDeptHead.Font.Size = new FontUnit(10);

lblDeptHead.Width = Unit.Percentage(100);

lblDeptHead.Text = "Department Head:";

txtDeptHead.ID = "txtDeptHead";

txtDeptHead.Font.Size = new FontUnit(10);

txtDeptHead.Width = Unit.Percentage(100);





lblEmpStatus.ID =
"lblEmpStatus";

lblEmpStatus.Font.Size = new FontUnit(10);

lblEmpStatus.Width = Unit.Percentage(100);

lblEmpStatus.Text = "Status:";

txtEmpStatus.ID = "txtEmpStatus";

txtEmpStatus.Font.Size = new FontUnit(10);

txtEmpStatus.Width = Unit.Percentage(100);





lblEmpSex.ID =
"lblEmpSex";

lblEmpSex.Font.Size = new FontUnit(10);

lblEmpSex.Width = Unit.Percentage(100);

lblEmpSex.Text = "Sex:";

txtEmpSex.ID = "txtEmpSex";

txtEmpSex.Font.Size = new FontUnit(10);

txtEmpSex.Width = Unit.Percentage(100);

lblFromDate.ID = "lblFromDate";

lblFromDate.Text = "From Date";

lblFromDate.Font.Size = new FontUnit(10);

lblFromDate.Width = Unit.Percentage(100);

dtFromDate.ID = "dtFromDate";

//dtFromDate.AutoPostBack = true;

//dtFromDate.MinDate = Convert.ToDateTime(DateTime.Today.ToLongDateString());

dtFromDate.IsRequiredField = true;

dtFromDate.DateOnly = true;



lblToDate.ID =
"lblToDate";

lblToDate.Text = "To Date";

lblToDate.Font.Size = new FontUnit(10);

lblToDate.Width = Unit.Percentage(100);

dtToDate.ID = "dtToDate";

dtToDate.AutoPostBack = true;

//dtToDate.MinDate = Convert.ToDateTime(DateTime.Today.ToLongDateString());

dtToDate.IsRequiredField = true;

dtToDate.DateOnly = true;

dtToDate.DateChanged += new EventHandler(dtToDate_DateChanged);



lblLeaveType.ID =
"lblLeaveType";

lblLeaveType.Text = "Leave Type";

lblLeaveType.Font.Size = new FontUnit(10);

ddlLeaveType.ID = "ddlLeaveType";

ddlLeaveType.Width = 160;

ddlLeaveType.SelectedIndexChanged +=
new EventHandler(ddlLeaveType_SelectedIndexChanged);

ddlLeaveType.AutoPostBack = true;

ddlLeaveType.EnableViewState = true;





#region
LeaveInfo

lblTotalNoofLeave.ID = "lblTotalNoofLeave";

lblTotalNoofLeave.Text = "Total No.of Leave";

lblTotalNoofLeave.Font.Size = new FontUnit(10);

lblTotalNoofLeave.ForeColor = System.Drawing.Color.Blue;

lblTotalNoofLeave.Width = 160;

txtTotalNoofLeave.ID =
"txtTotalNoofLeave";

//txtTotalNoofLeave.Width = 160;






lblNoofLeaveAvail.ID = "lblNoofLeaveAvail";

lblNoofLeaveAvail.Text = "No.of Leave Available";

lblNoofLeaveAvail.Font.Size = new FontUnit(10);

lblNoofLeaveAvail.ForeColor = System.Drawing.Color.Blue;

lblNoofLeaveAvail.Width = 160;

txtNoofLeaveAvail.ID =
"txtNoofLeaveAvail";

txtNoofLeaveAvail.Width = 160;



lblNoofLeaveTaken.ID =
"lblNoofLeaveTaken";

lblNoofLeaveTaken.Text = "No.of Leave Taken";

lblNoofLeaveTaken.Font.Size = new FontUnit(10);

lblNoofLeaveTaken.ForeColor = System.Drawing.Color.Blue;

lblNoofLeaveTaken.Width = 160;

txtNoofLeaveTaken.ID =
"txtNoofLeaveTaken";

txtNoofLeaveTaken.Width = 160;



lblNoofBalLeave.ID =
"lblNoofBalLeave";

lblNoofBalLeave.Text = "No.of Leave Balance";

lblNoofBalLeave.Font.Size = new FontUnit(10);

lblNoofBalLeave.ForeColor = System.Drawing.Color.Blue;

lblNoofBalLeave.Width = 160;

txtNoofBalLeave.ID =
"txtNoofBalLeave";

txtNoofBalLeave.Width = 160;

lblNoofBalLeave.Visible =
false;

txtNoofBalLeave.Visible = false;

#endregion




lblNote.ID = "lblNote";

lblNote.Text = "Note: Available only Sick Leave ONE day per month in case of Emergency";

lblNote.ForeColor = System.Drawing.Color.Red;

lblNote.Visible = false;





lblReason.ID =
"lblReason";

lblReason.Font.Size = new FontUnit(10);

lblReason.Text = "Reason";

txtReason.ID = "txtReason";

txtReason.TextMode = TextBoxMode.MultiLine;

txtReason.Width = 160;



lblAppover.ID =
"lblAppover";

lblAppover.Font.Size = new FontUnit(10);

lblAppover.Text = "Approver";

ddlApprover.ID = "ddlApprover";

ddlApprover.Width = 160;

LoadApprovers();

ctrlpplPicker.AutoPostBack =
false;

ctrlpplPicker.PlaceButtonsUnderEntityEditor = true;

ctrlpplPicker.ID = "pplEditor";

ctrlpplPicker.AllowEmpty = false;

ctrlpplPicker.SelectionSet = "User, DL, SecGroup, SPGroup";

ctrlpplPicker.MultiSelect = true;

// ctrlpplPicker.MaximumEntities = 5;

ctrlpplPicker.Width = 160;

ctrlpplPicker.BorderWidth =
Unit.Pixel(1);











btnApply.ID =
"btnApply";

btnApply.Text = "Apply";

btnApply.CausesValidation = true;

btnApply.BorderStyle = BorderStyle.Groove;

btnApply.Visible = true;

btnApply.Click += new EventHandler(btnApply_Click);





btnClear.ID =
"btnClear";

btnClear.Text = "Clear";

btnClear.CausesValidation = true;

btnClear.BorderStyle = BorderStyle.Groove;

btnClear.Visible = true;

btnClear.Click += new EventHandler(btnClear_Click);

#region
javscript confirmation

string script;

//Confirmation Approval for Leaves

script = "";

script += "if(confirm('Are you sure with your applied Leave details?'))";

script += "{";

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

script += "}";

script += "else";

script += "{";

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

script += "}";

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

#endregion

#region

validation

//rfvMainCategory.ID = "rfvMainCategory";

//rfvMainCategory.ControlToValidate = "ddlMainCategory";

//rfvMainCategory.ErrorMessage = "*";

//rfvMainCategory.ForeColor = Color.Red;




//rfvSubCategory.ID = "rfvSubCategory";

//rfvSubCategory.ControlToValidate = "ddlSubCategory";

//rfvSubCategory.ErrorMessage = "*";

//rfvSubCategory.ForeColor = Color.Red;




//rfvSolutionName.ID = "rfvSolutionName";

//rfvSolutionName.ControlToValidate = "txtSolutionName";

//rfvSolutionName.ErrorMessage = "*";

//rfvSolutionName.ForeColor = Color.Red;






//rfvSolutionDescription.ID = "rfvSolutionDescription";

//rfvSolutionDescription.ControlToValidate = "txtSolutionDescription";

//rfvSolutionDescription.ErrorMessage = "*";

//rfvSolutionDescription.ForeColor = Color.Red;






//rfvPriceDetails.ID = "rfvPriceDetails";

//rfvPriceDetails.ControlToValidate = "txtPriceDetails";

//rfvPriceDetails.ErrorMessage = "*";

//rfvPriceDetails.ForeColor = Color.Red;




//rfvLicenseDetails.ID = "rfvLicenseDetails";

//rfvLicenseDetails.ControlToValidate = "txtLicenseDetails";

//rfvLicenseDetails.ErrorMessage = "*";

//rfvLicenseDetails.ForeColor = Color.Red;




////// rfvImageUpload.ID = "rfvImageUpload";

////// rfvImageUpload.ControlToValidate = "ImageUpload";

////// rfvImageUpload.ErrorMessage = "*";

//////rfvImageUpload.ForeColor = Color.Red;






//rfvContactEmailID.ID = "rfvContactEmailID";

//rfvContactEmailID.ControlToValidate = "txtContactEmailID";

//rfvContactEmailID.ErrorMessage = "*";

//rfvContactEmailID.ForeColor = Color.Red;

//revContactEmailID.ID = "revContactEmailID";

//revContactEmailID.ErrorMessage = "Enter valid mail ID Eg: a@abc.com";

//revContactEmailID.ForeColor = Color.Red;

//revContactEmailID.ControlToValidate = "txtContactEmailID";

//revContactEmailID.ValidationExpression = @"^[a-z][a-z|0-9|]*([_][a-z|0-9]+)*([.][a-z|" + @"0-9]+([_][a-z|0-9]+)*)?@.[a-z|0-9|]*([-][a-z|0-9]+)*\.([a-z]" + @"[a-z|0-9]*(\.[a-z][a-z|0-9]*)?)$";

#endregion




tblStatic.ID = "tblStatic";

tblStatic.Width = Unit.Percentage(100);

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

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

tblStatic.BorderStyle = BorderStyle.Solid;

tblStatic.BorderWidth = Unit.Pixel(2);

tblStatic.CellPadding = 5;

tblStatic.HorizontalAlign =
HorizontalAlign.Center;



tblUserInputs.ID =
"tblUserInputs";

tblUserInputs.Width = Unit.Percentage(100);

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

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

tblUserInputs.BorderStyle = BorderStyle.Solid;

tblUserInputs.BorderWidth = Unit.Pixel(1);

tblUserInputs.CellPadding = 2;

tblUserInputs.HorizontalAlign =
HorizontalAlign.Center;



tblLeaveInfo.ID =
"tblLeaveInfo";

tblLeaveInfo.Width = Unit.Percentage(100);

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

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

tblLeaveInfo.BorderStyle = BorderStyle.Solid;

tblLeaveInfo.BorderWidth = Unit.Pixel(2);

tblLeaveInfo.CellPadding = 2;

tblLeaveInfo.HorizontalAlign =
HorizontalAlign.Center;

tblLeaveInfo.Visible = false;

tblMain.ID = "tblMain";

tblMain.Width = Unit.Percentage(100);

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

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

tblMain.BorderStyle = BorderStyle.Solid;

tblMain.BorderWidth = Unit.Pixel(1);

tblMain.CellPadding = 2;

tblMain.HorizontalAlign =
HorizontalAlign.Center;









}

catch (Exception ex)

{

DisplayErroMessage(ex);

}

}



















#endregion

#region

CreateChildControls

protected override void CreateChildControls()

{

try

{

TableCell tc;

TableCell tc1;

TableCell tc2;

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


tr = new TableRow();

tc = new TableCell();

tc1 = new TableCell();

tc2 = new TableCell();

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

tc.ForeColor = ColorTranslator.FromHtml("#ffffff");

tc.Font.Bold = true;

tc.Font.Size = FontUnit.Medium;

tc.ColumnSpan = 2;

tc.HorizontalAlign =
HorizontalAlign.Center;

tc.Text = "LEAVE APPLICATION";

tr.Cells.Add(tc);

tblMain.Rows.Add(tr);











tr =
new TableRow();

tc = new TableCell();

tc1 = new TableCell();

tc2 = new TableCell();

Literal ltspacestatic = new Literal();

Literal ltspacestatic1 = new Literal();

Literal ltspacestatic2 = new Literal();

ltspacestatic.Text = " ";

ltspacestatic1.Text = " ";

ltspacestatic2.Text = " ";

tc.HorizontalAlign = HorizontalAlign.Left;

tc.Font.Bold = true;

tc1.Font.Bold = true;

tc2.Font.Bold = true;

tc.Controls.Add(lblEmpName);

tc.Controls.Add(ltspacestatic);

tc.Controls.Add(txtEmpName);

tc1.Controls.Add(lblEmpID);

tc1.Controls.Add(ltspacestatic1);

tc1.Controls.Add(txtEmpID);

tc2.Controls.Add(lblEmpSex);

tc2.Controls.Add(ltspacestatic2);

tc2.Controls.Add(txtEmpSex);

tr.Cells.Add(tc);

tr.Cells.Add(tc1);

tr.Cells.Add(tc2);

tblStatic.Rows.Add(tr);





tr =
new TableRow();

tc = new TableCell();

tc1 = new TableCell();

tc2 = new TableCell();

tc.HorizontalAlign = HorizontalAlign.Left;

Literal ltspaces = new Literal();

Literal ltspaces1 = new Literal();

Literal ltspaces2 = new Literal();

ltspacestatic.Text = " ";

ltspacestatic1.Text = " ";

ltspacestatic2.Text = " ";

tc.Controls.Add(ltspaces);

tc1.Controls.Add(ltspaces1);

tc2.Controls.Add(ltspaces2);

tr.Cells.Add(tc);

tr.Cells.Add(tc1);

tr.Cells.Add(tc2);

tblStatic.Rows.Add(tr);



tr =
new TableRow();

tc = new TableCell();

tc1 = new TableCell();

tc2 = new TableCell();

Literal ltspacestatic3 = new Literal();

Literal ltspacestatic4 = new Literal();

Literal ltspacestatic5 = new Literal();

ltspacestatic3.Text = " ";

ltspacestatic4.Text = " ";

ltspacestatic5.Text = " ";

tc.HorizontalAlign = HorizontalAlign.Left;

tc.Font.Bold = true;

tc1.Font.Bold = true;

tc2.Font.Bold = true;

tc.Controls.Add(lblDept);

tc.Controls.Add(ltspacestatic3);

tc.Controls.Add(txtDept);

tc1.Controls.Add(lblDeptHead);

tc1.Controls.Add(ltspacestatic4);

tc1.Controls.Add(txtDeptHead);

tc2.Controls.Add(lblEmpStatus);

tc2.Controls.Add(ltspacestatic5);

tc2.Controls.Add(txtEmpStatus);

tr.Cells.Add(tc);

tr.Cells.Add(tc1);

tr.Cells.Add(tc2);

tblStatic.Rows.Add(tr);







tr =
new TableRow();

tc = new TableCell();

tc1 = new TableCell();

tc2 = new TableCell();

tc.HorizontalAlign = HorizontalAlign.Left;

tc.Controls.Add(lblNote);

tr.Cells.Add(tc);

tr.Cells.Add(tc1);

tr.Cells.Add(tc2);

tblUserInputs.Rows.Add(tr);







tr =
new TableRow();

tc = new TableCell();

tc1 = new TableCell();

tc2 = new TableCell();

tc.HorizontalAlign = HorizontalAlign.Left;

tc.Controls.Add(lblLeaveType);

tc1.Controls.Add(ddlLeaveType);

tr.Cells.Add(tc);

tr.Cells.Add(tc1);

tr.Cells.Add(tc2);

tblUserInputs.Rows.Add(tr);



#region
LeaveInfo

tr = new TableRow();

tc = new TableCell();

tc1 = new TableCell();

tc2 = new TableCell();

tc.HorizontalAlign = HorizontalAlign.Left;

tc.Controls.Add(lblTotalNoofLeave);

tc1.Controls.Add(txtTotalNoofLeave);

tr.Cells.Add(tc);

tr.Cells.Add(tc1);

tr.Cells.Add(tc2);

tblLeaveInfo.Rows.Add(tr);

tr =
new TableRow();

tc = new TableCell();

tc1 = new TableCell();

tc2 = new TableCell();

Literal ltspaceInfo = new Literal();

Literal ltspaceInfo1 = new Literal();

Literal ltspaceInfo2 = new Literal();

ltspaceInfo.Text = " ";

ltspaceInfo1.Text = " ";

ltspaceInfo2.Text = " ";

tc.HorizontalAlign = HorizontalAlign.Left;

tc.Font.Bold = true;

tc1.Font.Bold = true;

tc2.Font.Bold = true;

tc.Font.Size = FontUnit.Small;

tc1.Font.Size = FontUnit.Small;

tc2.Font.Size = FontUnit.Small;

tc.Controls.Add(lblTotalNoofLeave);

tc.Controls.Add(ltspaceInfo);

tc.Controls.Add(txtTotalNoofLeave);

tc1.Controls.Add(lblNoofLeaveAvail);

tc1.Controls.Add(ltspaceInfo1);

tc1.Controls.Add(txtNoofLeaveAvail);

tc2.Controls.Add(lblNoofLeaveTaken);

tc2.Controls.Add(ltspaceInfo2);

tc2.Controls.Add(txtNoofLeaveTaken);

tr.Cells.Add(tc);

tr.Cells.Add(tc1);

tr.Cells.Add(tc2);

tblLeaveInfo.Rows.Add(tr);

#endregion










tr = new TableRow();

tc = new TableCell();

tc1 = new TableCell();

tc2 = new TableCell();

tc.HorizontalAlign = HorizontalAlign.Left;

tc1.HorizontalAlign = HorizontalAlign.Center;

tc.Controls.Add(lblFromDate);

tc1.Controls.Add(dtFromDate);

tr.Cells.Add(tc);

tr.Cells.Add(tc1);

tr.Cells.Add(tc2);

tblUserInputs.Rows.Add(tr);





tr =
new TableRow();

tc = new TableCell();

tc1 = new TableCell();

tc2 = new TableCell();

tc.HorizontalAlign = HorizontalAlign.Left;

tc1.HorizontalAlign = HorizontalAlign.Center;

tc.Controls.Add(lblToDate);

tc1.Controls.Add(dtToDate);

tr.Cells.Add(tc);

tr.Cells.Add(tc1);

tr.Cells.Add(tc2);

tblUserInputs.Rows.Add(tr);









tr =
new TableRow();

tc = new TableCell();

tc1 = new TableCell();

tc2 = new TableCell();

tc.HorizontalAlign = HorizontalAlign.Left;

tc.Controls.Add(lblReason);

tc1.Controls.Add(txtReason);

tr.Cells.Add(tc);

tr.Cells.Add(tc1);

tr.Cells.Add(tc2);

tblUserInputs.Rows.Add(tr);











tr =
new TableRow();

tc = new TableCell();

tc1 = new TableCell();

tc2 = new TableCell();

tc.HorizontalAlign = HorizontalAlign.Left;

tc.Controls.Add(lblAppover);

tc1.Controls.Add(ctrlpplPicker);

tr.Cells.Add(tc);

tr.Cells.Add(tc1);

tr.Cells.Add(tc2);

tblUserInputs.Rows.Add(tr);







tr =
new TableRow();

tc = new TableCell();

tc.HorizontalAlign = HorizontalAlign.Left;

tc.Controls.Add(lblStatus);

tr.Cells.Add(tc);

tblMain.Rows.Add(tr);





tr =
new TableRow();

tc = new TableCell();

tc.HorizontalAlign = HorizontalAlign.Center;

tc.Controls.Add(tblStatic);

tr.Controls.Add(tc);

tblMain.Controls.Add(tr);



tr =
new TableRow();

tc1 = new TableCell();

tc1.HorizontalAlign = HorizontalAlign.Center;

tc1.Controls.Add(tblLeaveInfo);

tr.Controls.Add(tc1);

tblMain.Controls.Add(tr);

tr =
new TableRow();

tc = new TableCell();

tc.Controls.Add(hdnEmpid);

tr.Cells.Add(tc);

tblUserInputs.Rows.Add(tr);

tr =
new TableRow();

tc = new TableCell();

tc.Controls.Add(hdnLeaveRequisition);

tr.Cells.Add(tc);

tblUserInputs.Rows.Add(tr);



tr =
new TableRow();

tc = new TableCell();

tc.Controls.Add(hdnMasterEmpid);

tr.Cells.Add(tc);

tblUserInputs.Rows.Add(tr);



tr =
new TableRow();

tc = new TableCell();

tc.Controls.Add(hdnEmpname);

tr.Cells.Add(tc);

tblUserInputs.Rows.Add(tr);

tr =
new TableRow();

tc = new TableCell();

tc.Controls.Add(hdndisplayemail);

tr.Cells.Add(tc);

tblUserInputs.Rows.Add(tr);

tr =
new TableRow();

tc = new TableCell();

tc.Controls.Add(hdnhodEmailID);

tr.Cells.Add(tc);

tblUserInputs.Rows.Add(tr);



tr =
new TableRow();

tc = new TableCell();

tc.Controls.Add(hdnAvailCL);

tr.Cells.Add(tc);

tblUserInputs.Rows.Add(tr);

tr =
new TableRow();

tc = new TableCell();

tc.Controls.Add(hdnAvailSL);

tr.Cells.Add(tc);

tblUserInputs.Rows.Add(tr);



tr =
new TableRow();

tc = new TableCell();

tc.Controls.Add(hdnAvailWL);

tr.Cells.Add(tc);

tblUserInputs.Rows.Add(tr);



tr =
new TableRow();

tc = new TableCell();

tc.Controls.Add(hdnAvailSB);

tr.Cells.Add(tc);

tblUserInputs.Rows.Add(tr);



tr =
new TableRow();

tc = new TableCell();

tc.Controls.Add(hdnAvailML);

tr.Cells.Add(tc);

tblUserInputs.Rows.Add(tr);



tr =
new TableRow();

tc = new TableCell();

tc.Controls.Add(hdnAvailPL);

tr.Cells.Add(tc);

tblUserInputs.Rows.Add(tr);



tr =
new TableRow();

tc = new TableCell();

tc.Controls.Add(hdnAvailWFH);

tr.Cells.Add(tc);

tblUserInputs.Rows.Add(tr);

tr =
new TableRow();

tc = new TableCell();

tc.Controls.Add(hdnAvailOPL);

tr.Cells.Add(tc);

tblUserInputs.Rows.Add(tr);



tr =
new TableRow();

tc = new TableCell();

tc.Controls.Add(hdnTS);

tr.Cells.Add(tc);

tblUserInputs.Rows.Add(tr);



tr =
new TableRow();

tc = new TableCell();

tc.HorizontalAlign = HorizontalAlign.Center;

tc.Controls.Add(tblUserInputs);

tr.Controls.Add(tc);

tblMain.Controls.Add(tr);











tr =
new TableRow();

tc = new TableCell();

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

tc.ForeColor = ColorTranslator.FromHtml("#ffffff");

tc.Font.Bold = true;

Literal ltspace2 = new Literal();

ltspace2.Text = "  ";

tc.HorizontalAlign = HorizontalAlign.Center;

tc.Controls.Add(btnApply);

tc.Controls.Add(ltspace2);

tc.Controls.Add(btnClear);

tr.Controls.Add(tc);

tblMain.Controls.Add(tr);

this.Controls.Add(tblMain);

}

catch (Exception ex)

{

DisplayErroMessage(ex);

}

}

#endregion



#region

Click_Events

public void btnClear_Click(object sender, EventArgs e)

{

try

{

ClearData();

}

catch (Exception ex)

{

DisplayErroMessage(ex);

}

}

public void EmpApplyLeave()

{

try

{

#region
ApplyLeave

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;

btnApply.Enabled = true;

#region
SameLeaveNotAllwed

SPWeb webloggeduser = SPControl.GetContextWeb(Context);

SPUser sUser = webloggeduser.CurrentUser;

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

SPQuery SPMyQuery = new SPQuery();

DateTime start = Convert.ToDateTime(dtFromDate.SelectedDate);

DateTime end = Convert.ToDateTime(dtToDate.SelectedDate);

//string camlquery = "<Where> <And> <Or> <Eq><FieldRef Name='EmployeeName' /> <Value Type='Text'>" + sUser.Name.ToString() + "</Value> </Eq> <And> <Eq><FieldRef Name='FromDate' /> <Value Type='DateTime' IncludeTimeValue='FALSE'>" + SPUtility.CreateISO8601DateTimeFromSystemDateTime(start) + "</Value> </Eq> <Eq><FieldRef Name='ToDate' /> <Value Type='DateTime' IncludeTimeValue='FALSE'>" + SPUtility.CreateISO8601DateTimeFromSystemDateTime(end) + "</Value> </Eq></And> <And> <Or> <Eq><FieldRef Name='LeaveApprovalStatus' /><Value Type='Text'>Pending</Value></Eq> <Eq><FieldRef Name='LeaveApprovalStatus' /><Value Type='Text'>Approved</Value></Eq></Or></And> </Or> </And></Where>"; // <Eq><FieldRef Name='LeaveApprovalStatus'/><Value Type='Text'>Approved</Value></Eq></Or></And> <Eq><FieldRef Name='ToDate' /> <Value Type='DateTime'>" + dtToDate.SelectedDate + "</Value> </Eq> </And></Where>";

string camlquery = "<Where> <And><Or> <Eq><FieldRef Name='LeaveApprovalStatus' /><Value Type='Text'>Pending</Value></Eq> <Eq><FieldRef Name='LeaveApprovalStatus' /><Value Type='Text'>Approved</Value></Eq></Or> <And> <Eq><FieldRef Name='EmployeeName' /> <Value Type='Text'>" + sUser.Name.ToString() + "</Value> </Eq> <And> <Eq><FieldRef Name='FromDate' /> <Value Type='DateTime' IncludeTimeValue='FALSE'>" + SPUtility.CreateISO8601DateTimeFromSystemDateTime(start) + "</Value> </Eq> <Eq><FieldRef Name='ToDate' /> <Value Type='DateTime' IncludeTimeValue='FALSE'>" + SPUtility.CreateISO8601DateTimeFromSystemDateTime(end) + "</Value> </Eq> </And> </And> </And></Where>";

SPMyQuery.Query = camlquery;

SPListItemCollection CheckDatelistitem = appList.GetItems(SPMyQuery);

//Page.Response.Write("Final COunt= "+CheckDatelistitem.Count);



#endregion


if (CheckDatelistitem.Count < 1)

{

#region
Apply_Leave

SPListItemCollection listItems = web.Lists["LeaveData"].Items;

SPListItem Item = listItems.Add();

Item["EmployeeID"] = txtEmpID.Text.ToString();

Item["EmployeeName"] = txtEmpName.Text.ToString();

Item["LeaveType"] = ddlLeaveType.SelectedItem.Text.ToString();

Item["FromDate"] = Convert.ToDateTime(dtFromDate.SelectedDate).ToShortDateString();

Item["ToDate"] = Convert.ToDateTime(dtToDate.SelectedDate).ToShortDateString();

Item["Reason"] = txtReason.Text.ToString();









#region
referUpdateleaves

string AppEmailAddresss = string.Empty;

string EmpEmailAddresss = string.Empty;

string strEmpid = txtEmpID.Text.ToString();

string strLeaveType = ddlLeaveType.SelectedItem.Text.ToString();

DateTime fromdate = dtFromDate.SelectedDate;

DateTime todate = dtToDate.SelectedDate;

TimeSpan ns = todate.Subtract(fromdate);

hdnEmpid.Value = strEmpid.ToString();

hdnEmpname.Value = txtEmpName.Text.ToString();

hdnLeaveRequisition.Value = strLeaveType.ToString();

hdnTS.Value = (ns.Days.ToString());

#endregion


//int u = 0;

string employees = ctrlpplPicker.CommaSeparatedAccounts;

char[] splitter = { ',' };

string[] splitPPData = employees.Split(splitter);

SPFieldUserValueCollection values = new SPFieldUserValueCollection();

for (int i = 0; i < splitPPData.Length; i++)

{

string loginname = splitPPData[i];

if (!string.IsNullOrEmpty(loginname))

{

SPUser user = web.SiteUsers[loginname];

SPFieldUserValue spfielduser = new SPFieldUserValue(web, user.ID, user.LoginName);

values.Add(spfielduser);

//Page.Response.Write(user);

}

}

Item[
"Approver"] = values;

UpdateLeaves();





Item.Update();

lblStatus.Visible =
true;

DisplayMessage("Your Leave data has been Submitted Successfully for Approval.", MessageType.Information);

#region
EmailToApprover

string appemail = Item["Approver"].ToString();

string empemail = Item["EmployeeName"].ToString();

SPFieldUserValue userValue = new SPFieldUserValue(web, appemail.ToString());

SPUser spappemail = userValue.User;

AppEmailAddresss = spappemail.Email;

SPWeb emploggeduser = SPControl.GetContextWeb(Context);

SPUser empsUser = emploggeduser.CurrentUser;

EmpEmailAddresss = empsUser.Email;



SmtpClient mailClient = new SmtpClient();

MailMessage email = new MailMessage(EmpEmailAddresss.ToString(), AppEmailAddresss.ToString());

email.CC.Add("rama.r@kryptos.in");

email.Subject = "Leave Approval Request ..!!";

email.IsBodyHtml = true;

email.Body = "<html><body><table><tr><td>Dear Approver,</td></tr><tr><td></td></tr><tr><td></td></tr><tr><td>Please visit your Leave Approval Request Link: http://intranet.kryptos.in:8080/sites/KCS/HRM/LeaveApproval/default.aspx </td></tr><tr><td><tr><td><tr><td> Thanks & Regards,</td></tr><tr><td>" + txtEmpName.Text.ToString() + "</td></tr></table><body></html>";

mailClient.Port = 25;

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

mailClient.Send(email);

#endregion

#endregion


}

else

{

btnApply.Enabled =
false;

lblStatus.Visible = true;

DisplayMessage("Already a leave has been availed for Selected dates, Please select some other Dates.",MessageType.Warning);

}

}

}

});

#endregion


}

catch (Exception ex)

{

DisplayErroMessage(ex);

}

}

public void btnApply_Click(object sender, EventArgs e)

{

try

{

#region
EmployeeLeave_Apply

if (hdnLeaveRequisition.Value == "1")

{

//int add = 1;

if (ddlLeaveType.SelectedValue != "-1")

{

if (dtFromDate.SelectedDate != null)

{

if (dtToDate.SelectedDate != null)

{

if (txtReason.Text != string.Empty)

{

#region
leavecategorycheck

int l = 0;

int add = 1;

if (ddlLeaveType.SelectedItem.Text == "Casual Leave")

{

if (Convert.ToInt16(hdnAvailCL.Value) > l)//&& ((Convert.ToInt16(hdnTS.Value) + add) <= Convert.ToInt16(hdnAvailCL.Value)))

{

EmpApplyLeave();

}

else

{

DisplayMessage(
"You are not apply for this Leave beco'z all leaves taken Already!!!", MessageType.Warning);

}

}

else if (ddlLeaveType.SelectedItem.Text == "Sick Leave")

{

if (Convert.ToInt16(hdnAvailSL.Value) > l) //&& ((Convert.ToInt16(hdnTS.Value) + add) <= Convert.ToInt16(hdnAvailSL.Value)))

{

EmpApplyLeave();

}

else

{

DisplayMessage(
"You are not apply for this Leave beco'z all leaves taken Already!!!", MessageType.Warning);

}

}

else if (ddlLeaveType.SelectedItem.Text == "Wedding Anniversary")

{

if (Convert.ToInt16(hdnAvailWL.Value) > l)//&& ((Convert.ToInt16(hdnTS.Value) + add) <= Convert.ToInt16(hdnAvailWL.Value)))

{



EmpApplyLeave();

}

else

{

DisplayMessage(
"You are not apply for this Leave beco'z all leaves taken Already!!!", MessageType.Warning);

}

}

else if (ddlLeaveType.SelectedItem.Text == "Spouse Birthday")

{

if (Convert.ToInt16(hdnAvailSB.Value) > l)//&& ((Convert.ToInt16(hdnTS.Value) + add) <= Convert.ToInt16(hdnAvailSB.Value)))

{

EmpApplyLeave();

}

else

{

DisplayMessage(
"You are not apply for this Leave beco'z all leaves taken Already!!!", MessageType.Warning);

}

}

else if (ddlLeaveType.SelectedItem.Text == "Maternity Leave")

{

if (Convert.ToInt16(hdnAvailML.Value) > l)//&& ((Convert.ToInt16(hdnTS.Value) + add) <= Convert.ToInt16(hdnAvailML.Value)))

{

EmpApplyLeave();

}

else

{

DisplayMessage(
"You are not apply for this Leave beco'z all leaves taken Already!!!", MessageType.Warning);

}

}

else if (ddlLeaveType.SelectedItem.Text == "Paternity Leave")

{

if (Convert.ToInt16(hdnAvailPL.Value) > l)//&& ((Convert.ToInt16(hdnTS.Value) + add) <= Convert.ToInt16(hdnAvailPL.Value)))

{

EmpApplyLeave();

}

else

{

DisplayMessage(
"You are not apply for this Leave beco'z all leaves taken Already!!!", MessageType.Warning);

}

}

else if (ddlLeaveType.SelectedItem.Text == "Work from Home")

{

EmpApplyLeave();

}

else if (ddlLeaveType.SelectedItem.Text == "Optional Leave")

{

EmpApplyLeave();

}

#endregion


}

else

{

DisplayMessage(
"Please give Reason for Leave.", MessageType.Warning);

}

}

else

{

DisplayMessage(
"Please Choose Proper ToDate.", MessageType.Warning);

}

}

else

{

DisplayMessage(
"Please Choose Proper FromDate.", MessageType.Warning);

}

}

}

else

{

DisplayMessage(
"Please select LeaveCategory.", MessageType.Warning);

}

// ClearData();

#endregion


hdnLeaveRequisition.Value = "0";

ClearData();

tblLeaveInfo.Visible =
false;

}

catch (Exception ex)

{

DisplayErroMessage(ex);

}

}

protected void ddlDept_SelectedIndexChanged(object sender, EventArgs e)

{

try

{

}

catch (Exception ex)

{

DisplayErroMessage(ex);

}

}

public void ddlLeaveType_SelectedIndexChanged(object sender, EventArgs e)

{

try

{

#region
SeletedItem

tblLeaveInfo.Visible = true;

lblStatus.Text = "";

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"];

foreach (SPListItem item in list.Items)

{

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

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

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

string MasEmpName = re.Replace(MasterEmpname, "");

if (item["EmployeeName"].ToString() == MasterEmpname)

{

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();

hdnAvailCL.Value = Convert.ToInt16(AvailCL).ToString();

hdnAvailSL.Value = Convert.ToInt16(AvailSL).ToString();

hdnAvailSB.Value = Convert.ToInt16(AvailSBL).ToString();

hdnAvailML.Value = Convert.ToInt16(AvailML).ToString();

hdnAvailPL.Value = Convert.ToInt16(AvailPL).ToString();

hdnAvailWFH.Value = Convert.ToInt16(AvailWFM).ToString();

hdnAvailWL.Value = Convert.ToInt16(AvailWL).ToString();

hdnAvailOPL.Value = Convert.ToInt16(AvailOPL).ToString();

SPWeb WEB = SPControl.GetContextWeb(Context);

SPUser sUser = WEB.CurrentUser;

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

{

#region
LeaveInfo

txtNoofLeaveAvail.Visible = false;

int TotalLeave = 12;

if (ddlLeaveType.SelectedItem.Text == "Casual Leave")

{

txtNoofLeaveAvail.Visible =
true;

txtTotalNoofLeave.Text = TotalLeave.ToString();

txtNoofLeaveTaken.Text = AvailedCL;

//lblNoofBalLeave.Text =(AvailCL "-" AvailedCL);

txtNoofLeaveAvail.Text = AvailCL;

}

else if (ddlLeaveType.SelectedItem.Text == "Sick Leave")

{

txtNoofLeaveAvail.Visible =
true;

txtTotalNoofLeave.Text = "12";

txtNoofLeaveTaken.Text = AvailedSL;

txtNoofLeaveAvail.Text = AvailSL;

}

else if (ddlLeaveType.SelectedItem.Text == "Wedding Anniversary")

{

txtNoofLeaveAvail.Visible =
true;

txtTotalNoofLeave.Text = "1";

txtNoofLeaveTaken.Text = AvailedWL;

txtNoofLeaveAvail.Text = AvailWL;

}

else if (ddlLeaveType.SelectedItem.Text == "Spouse Birthday")

{

txtNoofLeaveAvail.Visible =
true;

txtTotalNoofLeave.Text = "1";

txtNoofLeaveTaken.Text = AvailedSBL;

txtNoofLeaveAvail.Text = AvailSBL;

}

else if (ddlLeaveType.SelectedItem.Text == "Paternity Leave")

{

txtNoofLeaveAvail.Visible =
true;

txtTotalNoofLeave.Text = "2";

txtNoofLeaveTaken.Text = AvailedPL;

txtNoofLeaveAvail.Text = AvailPL;

}

else if (ddlLeaveType.SelectedItem.Text == "Maternity Leave")

{

txtNoofLeaveAvail.Visible =
true;

txtTotalNoofLeave.Text = "90";

txtNoofLeaveTaken.Text = AvailedML;

txtNoofLeaveAvail.Text = AvailML;

}

else if (ddlLeaveType.SelectedItem.Text == "Work from Home")

{



txtTotalNoofLeave.Text =
"Nil";

txtNoofLeaveAvail.Text = "1";

txtNoofLeaveTaken.Text = AvailWFM;

txtNoofBalLeave.Text =
"Nil";



}

else if (ddlLeaveType.SelectedItem.Text == "Optional Leave")

{



txtTotalNoofLeave.Text =
"Nil";

txtNoofLeaveAvail.Text = "1";

txtNoofLeaveTaken.Text = AvailOPL;

txtNoofBalLeave.Text =
"Nil";



}



#endregion


}

}

}

}

}

});

#endregion


int btn = 0;

int textvalue = Convert.ToInt16(txtNoofLeaveAvail.Text);

if ((textvalue == btn))

{

btnApply.Visible =
false;

}

else

{

btnApply.Visible =
true;

}

}

catch (Exception ex)

{

DisplayErroMessage(ex);

}

}

public void dtToDate_DateChanged(object sender, EventArgs e)

{

try

{

btnApply.Enabled =
true;

lblStatus.Visible = false;

if (dtToDate.SelectedDate < dtFromDate.SelectedDate)

{

btnApply.Enabled =
false;

lblStatus.Visible = true;

DisplayMessage("To Date cannot be lesser than From Date.", MessageType.Warning);

}

}

catch (Exception ex)

{

DisplayErroMessage(ex);

}

}

#endregion





#region

Method_References

public void UpdateLeaves()

{

try

{

#region
UpdateLeaveDatailsMaster





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"];

//Page.Response.Write("webloginu-F");

SPWeb webloggeduser = SPControl.GetContextWeb(Context);

SPUser sUser = webloggeduser.CurrentUser;

//Page.Response.Write("webloginu-S");

foreach (SPListItem items in list.Items)

{

string id = Convert.ToInt16(items["ID"]).ToString();

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

string MasterEmpname = items["EmployeeName"].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();

#region
SP_Query

SPQuery SPMyQuery = new SPQuery();

SPMyQuery.Query = string.Format("< Where > < Eq > < FieldRef Name='EmployeeID' / > < Value Type='EmployeeID' > {0} < /Value > < /Eq > < /Where > ", 1);

SPListItemCollection common = list.GetItems(SPMyQuery);

#endregion


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

string EmpName = re.Replace(MasterEmpname, "");

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

{

//Page.Response.Write("masNAME=suser");

int add = 1;

if (items["EmployeeID"].ToString() == Convert.ToString(hdnEmpid.Value))

{

//Page.Response.Write("masid=hdid");

Guid itemId = items.UniqueId;

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

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

#region
leaveinfo

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

{

if (Convert.ToInt16(AvailCL) > 0 && (Convert.ToInt16(hdnTS.Value) + add) <= Convert.ToInt16(AvailCL))

{

updateitem[
"AvailableCasualLeave"] = Convert.ToString(Convert.ToInt16(AvailCL) - (Convert.ToInt16(hdnTS.Value) + add));

updateitem["AvailedCasualLeave"] = Convert.ToString((Convert.ToInt16(hdnTS.Value) + add) + Convert.ToInt16(AvailedCL)).ToString();

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

updateitem.Update();

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

}

else

{

DisplayMessage(
"All leaves are already Taken", MessageType.Warning);

}

}

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

{

if (Convert.ToInt16(AvailSL) > 0)

{

updateitem[
"AvailableSickLeave"] = (Convert.ToInt16(AvailSL) - (Convert.ToInt16(hdnTS.Value) + add)).ToString();

updateitem["AvailedSickLeave"] = ((Convert.ToInt16(hdnTS.Value) + add) + Convert.ToInt16(AvailedSL)).ToString();

updateitem.Update();

}

else

{

DisplayMessage(
"All leaves are already Taken.", MessageType.Warning);

}

}

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

{

if (Convert.ToInt16(AvailWL) > 0 && ((Convert.ToInt16(hdnTS.Value) + add) <= Convert.ToInt16(AvailWL)))

{

updateitem[
"AvailableWeddingAnniversary"] = Convert.ToString(Convert.ToInt16(AvailWL) - (Convert.ToInt16(hdnTS.Value) + add));

updateitem["AvailedWeddingAnniversary"] = Convert.ToString((Convert.ToInt16(hdnTS.Value) + add) + Convert.ToInt16(AvailedWL));

updateitem.Update();

}

else

{

DisplayMessage(
"All leaves are already Taken", MessageType.Warning);

}

}

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

{

if (Convert.ToInt16(AvailSBL) > 0)

{

updateitem[
"AvailableSpouseBdayLeave"] = Convert.ToString(Convert.ToInt16(AvailSBL) - (Convert.ToInt16(hdnTS.Value) + add));

updateitem["AvailedSpouseBdayLeave"] = Convert.ToString((Convert.ToInt16(hdnTS.Value) + add) + Convert.ToInt16(AvailedSBL));

updateitem.Update();

}

else

{

DisplayMessage(
"All leaves are already Taken", MessageType.Warning);

}

}

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

{

if (Convert.ToInt16(AvailPL) > 0)

{

updateitem[
"AvailablePaternityLeave"] = (Convert.ToInt16(AvailPL) - (Convert.ToInt16(hdnTS.Value) + add)).ToString();

updateitem["AvailedPaternityLeave"] = ((Convert.ToInt16(hdnTS.Value) + add) + Convert.ToInt16(AvailedPL)).ToString();

updateitem.Update();

}

else

{

DisplayMessage(
"All leaves are already Taken", MessageType.Warning);

}

}

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

{

if (Convert.ToInt16(AvailML) > 0)

{

updateitem[
"AvailableMaternityLeave"] = (Convert.ToInt16(AvailML) - (Convert.ToInt16(hdnTS.Value) + add)).ToString();

updateitem["AvailedMaternityLeave"] = ((Convert.ToInt16(hdnTS.Value) + add) + Convert.ToInt16(AvailedML)).ToString();

updateitem.Update();

}

else

{

DisplayMessage(
"All leaves are already Taken", MessageType.Warning);

}

}

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

{

updateitem[
"WorkfromHome"] = ((Convert.ToInt16(hdnTS.Value) + add) + Convert.ToInt16(AvailWFM)).ToString();

updateitem.Update();

}

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

{

updateitem[
"OptionalLeave"] = ((Convert.ToInt16(hdnTS.Value) + add) + Convert.ToInt16(AvailOPL)).ToString();

updateitem.Update();

}

#endregion


}

}

else

{

DisplayMessage(hdnEmpid.Value.ToString() +
" " + "EmployeeID does not exist with Master Database", MessageType.Warning);

}

}

}

}

});



#endregion


}

catch (Exception ex)

{

DisplayErroMessage(ex);

}

}

private void LoadDepartment()

{

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

ddlDept.Items.Insert(1, new ListItem("PCS"));

ddlDept.Items.Insert(2, new ListItem("MSO"));

ddlDept.Items.Insert(3, new ListItem("Sales"));

ddlDept.Items.Insert(4, new ListItem("Marketing"));

ddlDept.Items.Insert(5, new ListItem("AMS"));

ddlDept.Items.Insert(6, new ListItem("Finance"));

ddlDept.Items.Insert(7, new ListItem("Management"));

}

private void LoadPermanentEmpLeaveType()

{

try

{

if (txtEmpSex.Text == "Male")

{

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

ddlLeaveType.Items.Insert(1, new ListItem("Casual Leave"));

ddlLeaveType.Items.Insert(2, new ListItem("Sick Leave"));

ddlLeaveType.Items.Insert(3, new ListItem("Wedding Anniversary"));

ddlLeaveType.Items.Insert(4, new ListItem("Spouse Birthday"));

ddlLeaveType.Items.Insert(5, new ListItem("Paternity Leave"));

ddlLeaveType.Items.Insert(6, new ListItem("Work from Home"));

ddlLeaveType.Items.Insert(7, new ListItem("Optional Leave"));

}

else if (txtEmpSex.Text == "Female")

{

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

ddlLeaveType.Items.Insert(1, new ListItem("Casual Leave"));

ddlLeaveType.Items.Insert(2, new ListItem("Sick Leave"));

ddlLeaveType.Items.Insert(3, new ListItem("Wedding Anniversary"));

ddlLeaveType.Items.Insert(4, new ListItem("Spouse Birthday"));

ddlLeaveType.Items.Insert(5, new ListItem("Maternity Leave"));

ddlLeaveType.Items.Insert(6, new ListItem("Work from Home"));

ddlLeaveType.Items.Insert(7, new ListItem("Optional Leave"));

}

}

catch (Exception ex)

{

DisplayErroMessage(ex);

}



}

private void LoadProbationEmpLeaveType()

{

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

ddlLeaveType.Items.Insert(1, new ListItem("Sick Leave"));



}

private void LoadApprovers()

{

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

ddlApprover.Items.Insert(1, new ListItem("Approver1"));

ddlApprover.Items.Insert(2, new ListItem("Approver2"));

ddlApprover.Items.Insert(3, new ListItem("Approver3*"));

ddlApprover.Items.Insert(4, new ListItem("Approver4"));

ddlApprover.Items.Insert(5, new ListItem("Approver5*"));

}

private void LoadEmpData()

{

try

{

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;

#region
emploaddata

SPWeb webloggeduser = SPControl.GetContextWeb(Context);

SPUser sUser = webloggeduser.CurrentUser;

string displayemail = sUser.Email;

hdndisplayemail.Value = displayemail;

web.AllowUnsafeUpdates =
true;

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

foreach (SPListItem item in list.Items)

{

lblStatus.Text =
"";

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

string depthead = item["DepartmentHead"].ToString();

string empstatus = item["EmployeeStatus"].ToString();

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

string outputStringEmpName = re.Replace(empname, "");

string outputStringDeptHead = re.Replace(depthead, "");

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

{

txtEmpName.Text = outputStringEmpName;

txtEmpID.Text = item[
"EmployeeID"].ToString();

txtDept.Text = item["EmployeeDepartment"].ToString();

txtDeptHead.Text = outputStringDeptHead;

txtEmpStatus.Text = item[
"EmployeeStatus"].ToString();

txtEmpSex.Text = item["EmployeeSex"].ToString();

hdnMasterEmpid.Value = item["EmployeeID"].ToString();

if (empstatus == "Permanent")

{

LoadPermanentEmpLeaveType();

}

else if (empstatus == "Probation")

{

lblNote.Visible =
true;

LoadProbationEmpLeaveType();

}

#region
people_picker



if (item["DepartmentHead"] != null)

{

char[] to_splitter = { ';' };

string to_list = item["DepartmentHead"].ToString();

string[] arr = to_list.Split(to_splitter);

string users = string.Empty;

System.Collections.ArrayList entityArrayList = new System.Collections.ArrayList();

for (int i = 1; i < arr.Length; i++)

{

if ((i % 2) != 0)

{

users = arr[i].Substring(arr[i].IndexOf(
"#") + 1);

PickerEntity entity = new PickerEntity();

entity.Key = users;

entity = ctrlpplPicker.ValidateEntity(entity);

entityArrayList.Add(entity);

}

}

ctrlpplPicker.UpdateEntities(entityArrayList);

SPFieldUserValueCollection values = new SPFieldUserValueCollection();

foreach (PickerEntity entity in ctrlpplPicker.ResolvedEntities)

{

SPFieldUserValue hodEmailID = new SPFieldUserValue(SPContext.Current.Web, Convert.ToInt16(entity.EntityData[PeopleEditorEntityDataKeys.UserId]), entity.Description);

values.Add(hodEmailID);

hdnapprover.Value = values.ToString();

}

}

#endregion












}

else

{

//User does not exist our Database..!!!

DisplayMessage("", MessageType.Warning);

web.AllowUnsafeUpdates = false;

}



}

#endregion


}

}

});

}

catch (Exception ex)

{

DisplayErroMessage(ex);

}

}

public void ClearData()

{

// Emailcheck();

// ddlLeaveType.Items.Insert(0, new ListItem("Select LeaveCategory", "-1"));

//dtFromDate.SelectedDate = DateTime.Today;

//dtToDate.SelectedDate = DateTime.Today;

txtReason.Text = "";

}





#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(LeaveRequisition), "UpdatePanelFixup", "_spOriginalFormAction = document.forms[0].action; _spSuppressFormOnSubmitWrapper=true;", true);

}

#endregion


}

}

No comments:

Post a Comment