public LeaveENT SelectTotalDaysByLeaveTypeIDUserID(SqlInt32 LeaveTypeID, SqlInt32 UserID) { using (SqlConnection objConn = new SqlConnection(ConnectionString)) { objConn.Open(); using (SqlCommand objCmd = objConn.CreateCommand()) { try { #region Prepare Command objCmd.CommandType = CommandType.StoredProcedure; objCmd.CommandText = "PR_Leave_SelectLeaveTotalDaysByLeaveTypeIDUserID"; objCmd.Parameters.Add("@LeaveTypeID", SqlDbType.Int).Value = LeaveTypeID; objCmd.Parameters.Add("@UserID", SqlDbType.Int).Value = UserID; #endregion Prepare Command #region Read Data and Set Controls LeaveENT entLeave = new LeaveENT(); using (SqlDataReader objSDR = objCmd.ExecuteReader()) { while (objSDR.Read()) { if (!objSDR["TotalDays"].Equals(DBNull.Value)) { entLeave.TotalDays = Convert.ToInt32(objSDR["TotalDays"]); } } } return(entLeave); #endregion Read Data and Set Controls } catch (SqlException ex) { Message = ex.Message; return(null); } catch (Exception ex) { Message = ex.Message; return(null); } finally { if (objConn.State == ConnectionState.Open) { objConn.Close(); } } } } }
public Boolean UpdateLeaveStatusInLeave(LeaveENT entLeave, SqlInt32 LeaveID) { LeaveDAL dalLeave = new LeaveDAL(); if (dalLeave.UpdateLeaveStatusInLeave(entLeave, LeaveID)) { return(true); } else { Message = dalLeave.Message; return(false); } }
public Boolean Insert(LeaveENT entLeave, SqlInt32 UserID) { LeaveDAL dalLeave = new LeaveDAL(); if (dalLeave.Insert(entLeave, UserID)) { return(true); } else { Message = dalLeave.Message; return(false); } }
public Boolean Insert(LeaveENT entLeave, SqlInt32 UserID) { using (SqlConnection objConn = new SqlConnection(ConnectionString)) { objConn.Open(); using (SqlCommand objCmd = objConn.CreateCommand()) { try { #region Prepare Command objCmd.CommandType = CommandType.StoredProcedure; objCmd.CommandText = "PR_Leave_InsertByUserID"; objCmd.Parameters.Add("@LeaveID", SqlDbType.Int, 4).Direction = ParameterDirection.Output; objCmd.Parameters.Add("@LeaveTypeID", SqlDbType.Int).Value = entLeave.LeaveTypeID; objCmd.Parameters.Add("@LeaveReason", SqlDbType.VarChar).Value = entLeave.LeaveReason; objCmd.Parameters.Add("@LeaveStartDate", SqlDbType.VarChar).Value = entLeave.LeaveStartDate; objCmd.Parameters.Add("@LeaveEndDate", SqlDbType.VarChar).Value = entLeave.LeaveEndDate; objCmd.Parameters.Add("@LeaveDuration", SqlDbType.VarChar).Value = entLeave.LeaveDuration; objCmd.Parameters.Add("@UserID", SqlDbType.Int).Value = UserID; #endregion Prepare Command objCmd.ExecuteNonQuery(); if (objCmd.Parameters["@LeaveID"] != null) { entLeave.LeaveID = Convert.ToInt32(objCmd.Parameters["@LeaveID"].Value); } return(true); } catch (SqlException ex) { Message = ex.Message; return(false); } catch (Exception ex) { Message = ex.Message; return(false); } finally { if (objConn.State == ConnectionState.Open) { objConn.Close(); } } } } }
private void fillControls(SqlInt32 LeaveID, SqlInt32 UserID) { LeaveBAL balLeave = new LeaveBAL(); LeaveENT entLeave = new LeaveENT(); entLeave = balLeave.SelectByPK(LeaveID, UserID); if (!entLeave.LeaveTypeID.IsNull) { ddlLeaveType.SelectedValue = entLeave.LeaveTypeID.Value.ToString(); Session["LeaveTypeID"] = entLeave.LeaveTypeID.Value.ToString(); } if (!entLeave.LeaveReason.IsNull) { txtLeaveReason.Text = entLeave.LeaveReason.Value.ToString(); } if (!entLeave.LeaveDuration.IsNull) { if (entLeave.LeaveDuration == "HalfLeave") { rbHalfLeave.Checked = true; lblLeaveStartDate.Text = "Leave Date"; txtLeaveEndDate.Text = ""; panelLeaveEndDate.Visible = false; } if (entLeave.LeaveDuration == "FullLeave") { rbFullLeave.Checked = true; lblLeaveStartDate.Text = "Leave StartDate"; txtLeaveEndDate.Text = ""; panelLeaveEndDate.Visible = true; } } if (!entLeave.LeaveStartDate.IsNull) { txtLeaveStartDate.Text = entLeave.LeaveStartDate.Value.ToString(); } if (!entLeave.LeaveEndDate.IsNull) { txtLeaveEndDate.Text = entLeave.LeaveEndDate.Value.ToString(); } }
protected void gvLeaveStatus_RowCommand(object sender, GridViewCommandEventArgs e) { LeaveBAL balLeave = new LeaveBAL(); LeaveENT entLeave = new LeaveENT(); LeaveStatusBAL balLeaveStatus = new LeaveStatusBAL(); UserENT entUser = new UserENT(); UserBAL balUser = new UserBAL(); entUser = balUser.SelectUserName(Convert.ToInt32(Session["UserID"].ToString().Trim())); if (e.CommandName == "Approved") { if (e.CommandArgument != null) { #region Collect Data entLeave.LeaveStatus = e.CommandName.ToString().Trim(); entLeave.LeaveResponseBy = entUser.UserName; #endregion Collect Data if (!balLeave.UpdateLeaveStatusInLeave(entLeave, Convert.ToInt32(e.CommandArgument))) { PanelErrorMesseage.Visible = true; lblErrorMesseage.Text = balLeave.Message; } } } else if (e.CommandName == "Rejected") { if (e.CommandArgument != null) { #region Collect Data entLeave.LeaveStatus = e.CommandName.ToString().Trim(); entLeave.LeaveResponseBy = entUser.UserName; #endregion Collect Data if (!balLeave.UpdateLeaveStatusInLeave(entLeave, Convert.ToInt32(e.CommandArgument))) { PanelErrorMesseage.Visible = true; lblErrorMesseage.Text = balLeave.Message; } } } balLeaveStatus.Delete(Convert.ToInt32(e.CommandArgument)); FillGridViewLeave(); }
public Boolean UpdateLeaveStatusInLeave(LeaveENT entLeave, SqlInt32 LeaveID) { using (SqlConnection objConn = new SqlConnection(ConnectionString)) { objConn.Open(); using (SqlCommand objCmd = objConn.CreateCommand()) { try { #region Prepare Command objCmd.CommandType = CommandType.StoredProcedure; objCmd.CommandText = "PR_Leave_UpdateLeaveStatusByPK"; objCmd.Parameters.Add("@LeaveResponseBy", SqlDbType.VarChar).Value = entLeave.LeaveResponseBy; objCmd.Parameters.Add("@LeaveStatus", SqlDbType.VarChar).Value = entLeave.LeaveStatus; objCmd.Parameters.Add("@LeaveID", SqlDbType.Int).Value = LeaveID; #endregion Prepare Command objCmd.ExecuteNonQuery(); return(true); } catch (SqlException ex) { Message = ex.Message; return(false); } catch (Exception ex) { Message = ex.Message; return(false); } finally { if (objConn.State == ConnectionState.Open) { objConn.Close(); } } } } }
protected void gvLeave_RowCommand(object sender, GridViewCommandEventArgs e) { LeaveBAL balLeave = new LeaveBAL(); LeaveENT entLeave = new LeaveENT(); LeaveENT entLeaveforRemainingLeave = new LeaveENT(); LeaveStatusBAL balLeaveStatus = new LeaveStatusBAL(); LeaveTypeENT entLeaveType = new LeaveTypeENT(); LeaveTypeBAL balLeaveType = new LeaveTypeBAL(); entLeave = balLeave.SelectLeaveStatusByPK(Convert.ToInt32(e.CommandArgument.ToString().Trim())); if (e.CommandName == "DeleteRecord") { if (e.CommandArgument != null) { entLeaveforRemainingLeave = balLeave.SelectByPK(Convert.ToInt32(e.CommandArgument.ToString().Trim()), Convert.ToInt32(Session["UserID"].ToString())); if (balLeaveStatus.Delete(Convert.ToInt32(e.CommandArgument.ToString().Trim()))) { if (!balLeave.Delete(Convert.ToInt32(e.CommandArgument.ToString().Trim()), Convert.ToInt32(Session["UserID"].ToString().Trim()))) { lblErrorMesseage.Text = balLeave.Message; } FillGridViewLeave(); displayRemainingLeave(); } else { PanelErrorMesseage.Visible = true; lblErrorMesseage.Text = balLeaveStatus.Message; } if (entLeave.LeaveResponseBy == "Pending" && entLeave.LeaveStatus == "Pending") { if (entLeaveforRemainingLeave.LeaveEndDate != "") { string strStartDate = entLeaveforRemainingLeave.LeaveStartDate.ToString(); string[] StartDateString = strStartDate.Split('-'); DateTime startdate = Convert.ToDateTime(StartDateString[0] + "-" + StartDateString[1] + "-" + StartDateString[2]); string strEndDate = entLeaveforRemainingLeave.LeaveEndDate.ToString(); string[] EndDateString = strEndDate.Split('-'); DateTime enddate = Convert.ToDateTime(EndDateString[0] + "-" + EndDateString[1] + "-" + EndDateString[2]); entLeaveType = balLeaveType.SelectByPK(entLeave.LeaveTypeID); if (entLeaveType.LeaveType == "Casual Leave") { entLeaveType.TotalDays = entLeaveType.TotalDays + Convert.ToInt32((enddate - startdate).TotalDays) + 1; } else if (entLeaveType.LeaveType == "Medical Leave") { entLeaveType.TotalDays = entLeaveType.TotalDays + Convert.ToInt32((enddate - startdate).TotalDays) + 1; } else if (entLeaveType.LeaveType == "LOP") { entLeaveType.TotalDays = entLeaveType.TotalDays + Convert.ToInt32((enddate - startdate).TotalDays) + 1; } else if (entLeaveType.LeaveType == "Other Leave") { entLeaveType.TotalDays = entLeaveType.TotalDays + Convert.ToInt32((enddate - startdate).TotalDays) + 1; } } else { entLeaveType = balLeaveType.SelectByPK(entLeave.LeaveTypeID); if (entLeaveType.LeaveType == "Casual Leave") { entLeaveType.TotalDays = entLeaveType.TotalDays + 1; } else if (entLeaveType.LeaveType == "Medical Leave") { entLeaveType.TotalDays = entLeaveType.TotalDays + 1; } else if (entLeaveType.LeaveType == "LOP") { entLeaveType.TotalDays = entLeaveType.TotalDays + 1; } else if (entLeaveType.LeaveType == "Other Leave") { entLeaveType.TotalDays = entLeaveType.TotalDays + 1; } } entLeaveType.UserID = Convert.ToInt32(Session["UserID"].ToString().Trim()); if (balLeaveType.UpdateTotalDaysByLeaveType(entLeaveType)) { displayRemainingLeave(); } else { PanelErrorMesseage.Visible = true; lblErrorMesseage.Text = balLeaveType.Message; } } } } else if (e.CommandName == "EditRecord") { if (entLeave.LeaveResponseBy != "Pending" && entLeave.LeaveStatus != "Pending") { PanelErrorMesseage.Visible = true; lblErrorMesseage.Text = "You can not edit leave after Responsed"; } else { if (e.CommandArgument != null) { Response.Redirect("~/Content/Leave/LeaveAddEdit.aspx?LeaveID=" + e.CommandArgument.ToString().Trim()); } } } }
private void addLeave() { LeaveBAL balLeave = new LeaveBAL(); LeaveENT entLeave = new LeaveENT(); LeaveTypeENT entLeaveType = new LeaveTypeENT(); LeaveTypeBAL balLeaveType = new LeaveTypeBAL(); entLeave = balLeave.SelectByPK(Convert.ToInt32(Request.QueryString["LeaveID"]), Convert.ToInt32(Session["UserID"].ToString().Trim())); if (Request.QueryString["LeaveID"] != null) { if (entLeave.LeaveEndDate != "") { string strStartDate = entLeave.LeaveStartDate.ToString(); string[] StartDateString = strStartDate.Split('-'); DateTime startdate = Convert.ToDateTime(StartDateString[0] + "-" + StartDateString[1] + "-" + StartDateString[2]); string strEndDate = entLeave.LeaveEndDate.ToString(); string[] EndDateString = strEndDate.Split('-'); DateTime enddate = Convert.ToDateTime(EndDateString[0] + "-" + EndDateString[1] + "-" + EndDateString[2]); entLeaveType = balLeaveType.SelectByPK(entLeave.LeaveTypeID); if (entLeaveType.LeaveType == "Casual Leave") { entLeaveType.TotalDays = entLeaveType.TotalDays + Convert.ToInt32((enddate - startdate).TotalDays) + 1; Session["Casual Leave"] = entLeaveType.TotalDays; } else if (entLeaveType.LeaveType == "Medical Leave") { entLeaveType.TotalDays = entLeaveType.TotalDays + Convert.ToInt32((enddate - startdate).TotalDays) + 1; Session["Medical Leave"] = entLeaveType.TotalDays; } else if (entLeaveType.LeaveType == "LOP") { entLeaveType.TotalDays = entLeaveType.TotalDays + Convert.ToInt32((enddate - startdate).TotalDays) + 1; Session["LOP"] = entLeaveType.TotalDays; } else if (entLeaveType.LeaveType == "Other Leave") { entLeaveType.TotalDays = entLeaveType.TotalDays + Convert.ToInt32((enddate - startdate).TotalDays) + 1; Session["Other Leave"] = entLeaveType.TotalDays; } } else { entLeaveType = balLeaveType.SelectByPK(entLeave.LeaveTypeID); if (entLeaveType.LeaveType == "Casual Leave") { entLeaveType.TotalDays = entLeaveType.TotalDays + 1; } else if (entLeaveType.LeaveType == "Medical Leave") { entLeaveType.TotalDays = entLeaveType.TotalDays + 1; } else if (entLeaveType.LeaveType == "LOP") { entLeaveType.TotalDays = entLeaveType.TotalDays + 1; } else if (entLeaveType.LeaveType == "Other Leave") { entLeaveType.TotalDays = entLeaveType.TotalDays + 1; } } entLeaveType.UserID = Convert.ToInt32(Session["UserID"].ToString().Trim()); if (!balLeaveType.UpdateTotalDaysByLeaveType(entLeaveType)) { PanelErrorMesseage.Visible = true; lblErrorMessage.Text = balLeaveType.Message; } } }
protected void btnCancel_Click(object sender, EventArgs e) { LeaveENT entLeave = new LeaveENT(); LeaveBAL balLeave = new LeaveBAL(); LeaveTypeENT entLeaveType = new LeaveTypeENT(); LeaveTypeBAL balLeaveType = new LeaveTypeBAL(); if (Request.QueryString["LeaveID"] != null) { entLeave = balLeave.SelectByPK(Convert.ToInt32(Request.QueryString["LeaveID"]), Convert.ToInt32(Session["UserID"].ToString().Trim())); entLeaveType = balLeaveType.SelectByPK(entLeave.LeaveTypeID); if (entLeave.LeaveEndDate != "") { if (entLeaveType.LeaveType == "Casual Leave") { entLeaveType.TotalDays = entLeaveType.TotalDays - Convert.ToInt32(Session["Casual Leave"].ToString().Trim()) - 2; Session["Casual Leave"] = null; } else if (entLeaveType.LeaveType == "Medical Leave") { entLeaveType.TotalDays = entLeaveType.TotalDays - Convert.ToInt32(Session["Medical Leave"].ToString().Trim()) - 2; Session["Medical Leave"] = null; } else if (entLeaveType.LeaveType == "LOP") { entLeaveType.TotalDays = entLeaveType.TotalDays - Convert.ToInt32(Session["LOP"].ToString().Trim()) - 2; Session["LOP"] = null; } else if (entLeaveType.LeaveType == "Other Leave") { entLeaveType.TotalDays = entLeaveType.TotalDays - Convert.ToInt32(Session["Other Leave"].ToString().Trim()) - 2; Session["Other Leave"] = null; } } else { if (entLeaveType.LeaveType == "Casual Leave") { entLeaveType.TotalDays = entLeaveType.TotalDays - 1; } else if (entLeaveType.LeaveType == "Medical Leave") { entLeaveType.TotalDays = entLeaveType.TotalDays - 1; } else if (entLeaveType.LeaveType == "LOP") { entLeaveType.TotalDays = entLeaveType.TotalDays - 1; } else if (entLeaveType.LeaveType == "Other Leave") { entLeaveType.TotalDays = entLeaveType.TotalDays - 1; } } entLeaveType.UserID = Convert.ToInt32(Session["UserID"].ToString().Trim()); if (!balLeaveType.UpdateTotalDaysByLeaveType(entLeaveType)) { PanelErrorMesseage.Visible = true; lblErrorMessage.Text = balLeaveType.Message; } } Response.Redirect("~/Content/Leave/LeaveList.aspx"); }
protected void btnSave_Click(object sender, EventArgs e) { #region Collect Data LeaveENT entLeave = new LeaveENT(); LeaveBAL balLeave = new LeaveBAL(); LeaveStatusENT entLeaveStatus = new LeaveStatusENT(); LeaveStatusBAL balLeaveStatus = new LeaveStatusBAL(); LeaveTypeENT entLeaveType = new LeaveTypeENT(); LeaveTypeBAL balLeaveType = new LeaveTypeBAL(); if (ddlLeaveType.SelectedIndex > 0) { entLeave.LeaveTypeID = Convert.ToInt32(ddlLeaveType.SelectedValue); entLeaveStatus.LeaveTypeID = Convert.ToInt32(ddlLeaveType.SelectedValue); entLeaveType.LeaveTypeID = Convert.ToInt32(ddlLeaveType.SelectedValue); } entLeaveType = balLeaveType.SelectByPK(entLeaveType.LeaveTypeID); if (entLeave.LeaveID > 0) { entLeaveStatus.LeaveID = entLeave.LeaveID; } if (txtLeaveReason.Text.Trim() != "") { entLeave.LeaveReason = txtLeaveReason.Text.Trim(); } if (rbHalfLeave.Checked != false) { entLeave.LeaveDuration = rbHalfLeave.Text.Trim(); } if (rbFullLeave.Checked != false) { entLeave.LeaveDuration = rbFullLeave.Text.Trim(); } if (txtLeaveStartDate.Text.Trim() != "") { DateTime today = DateTime.Today; string strDate = txtLeaveStartDate.Text.Trim(); string[] dateString = strDate.Split('-'); DateTime startdate = Convert.ToDateTime(dateString[0] + "-" + dateString[1] + "-" + dateString[2]); if (startdate < today) { PanelErrorMesseage.Visible = true; lblErrorMessage.Text = "Leavedate must not be in past"; txtLeaveStartDate.Focus(); return; } else { PanelErrorMesseage.Visible = false; entLeave.LeaveStartDate = txtLeaveStartDate.Text.Trim(); } } if (txtLeaveEndDate.Text.Trim() != "") { entLeave.LeaveEndDate = txtLeaveEndDate.Text.Trim(); } #endregion Collect Data if (Request.QueryString["LeaveID"] == null) { string strStartDate = txtLeaveStartDate.Text.Trim(); string[] StartDateString = strStartDate.Split('-'); DateTime startdate = Convert.ToDateTime(StartDateString[0] + "-" + StartDateString[1] + "-" + StartDateString[2]); if (entLeaveType.LeaveType == "Casual Leave") { entLeaveType.UserID = Convert.ToInt32(Session["UserID"].ToString().Trim()); if (rbHalfLeave.Checked == true) { entLeaveType.TotalDays = entLeaveType.TotalDays - 1; } else if (rbFullLeave.Checked == true) { string strEndDate = txtLeaveEndDate.Text.Trim(); string[] EndDateString = strEndDate.Split('-'); DateTime enddate = Convert.ToDateTime(EndDateString[0] + "-" + EndDateString[1] + "-" + EndDateString[2]); entLeaveType.TotalDays = entLeaveType.TotalDays - Convert.ToInt32((enddate - startdate).TotalDays) - 1; } if (entLeaveType.TotalDays < 0) { PanelErrorMesseage.Visible = true; lblErrorMessage.Text = "You Can't Add More Casual Leave Because You Had Already Use It"; return; } else { if (balLeave.Insert(entLeave, Convert.ToInt32(Session["UserID"].ToString().Trim()))) { if (entLeave.LeaveID > 0) { entLeaveStatus.LeaveID = entLeave.LeaveID; } if (!balLeaveType.UpdateTotalDaysByLeaveType(entLeaveType)) { PanelErrorMesseage.Visible = true; lblErrorMessage.Text = balLeaveType.Message; } clearSelection(); PanelSuccess.Visible = true; lblSuccess.Text = "Data Inserted Successfully"; } else { PanelErrorMesseage.Visible = true; lblErrorMessage.Text = balLeave.Message; } if (!balLeaveStatus.Insert(entLeaveStatus, Convert.ToInt32(Session["UserID"].ToString().Trim()))) { PanelErrorMesseage.Visible = true; lblErrorMessage.Text = balLeaveStatus.Message; } } } else if (entLeaveType.LeaveType == "Medical Leave") { entLeaveType.UserID = Convert.ToInt32(Session["UserID"].ToString().Trim()); if (rbHalfLeave.Checked == true) { entLeaveType.TotalDays = entLeaveType.TotalDays - 1; } else if (rbFullLeave.Checked == true) { string strEndDate = txtLeaveEndDate.Text.Trim(); string[] EndDateString = strEndDate.Split('-'); DateTime enddate = Convert.ToDateTime(EndDateString[0] + "-" + EndDateString[1] + "-" + EndDateString[2]); entLeaveType.TotalDays = entLeaveType.TotalDays - Convert.ToInt32((enddate - startdate).TotalDays) - 1; } if (entLeaveType.TotalDays < 0) { PanelErrorMesseage.Visible = true; lblErrorMessage.Text = "You Can't Add More Medical Leave Because You Had Already Use It"; return; } else { if (balLeave.Insert(entLeave, Convert.ToInt32(Session["UserID"].ToString().Trim()))) { if (entLeave.LeaveID > 0) { entLeaveStatus.LeaveID = entLeave.LeaveID; } if (!balLeaveType.UpdateTotalDaysByLeaveType(entLeaveType)) { PanelErrorMesseage.Visible = true; lblErrorMessage.Text = balLeaveType.Message; } clearSelection(); PanelSuccess.Visible = true; lblSuccess.Text = "Data Inserted Successfully"; } else { PanelErrorMesseage.Visible = true; lblErrorMessage.Text = balLeave.Message; } if (!balLeaveStatus.Insert(entLeaveStatus, Convert.ToInt32(Session["UserID"].ToString().Trim()))) { PanelErrorMesseage.Visible = true; lblErrorMessage.Text = balLeaveStatus.Message; } } } else if (entLeaveType.LeaveType == "LOP") { entLeaveType.UserID = Convert.ToInt32(Session["UserID"].ToString().Trim()); if (rbHalfLeave.Checked == true) { entLeaveType.TotalDays = entLeaveType.TotalDays - 1; } else if (rbFullLeave.Checked == true) { string strEndDate = txtLeaveEndDate.Text.Trim(); string[] EndDateString = strEndDate.Split('-'); DateTime enddate = Convert.ToDateTime(EndDateString[0] + "-" + EndDateString[1] + "-" + EndDateString[2]); entLeaveType.TotalDays = entLeaveType.TotalDays - Convert.ToInt32((enddate - startdate).TotalDays) - 1; } if (entLeaveType.TotalDays < 0) { PanelErrorMesseage.Visible = true; lblErrorMessage.Text = "You Can't Add More LOP Because You Had Already Use It"; return; } else { if (balLeave.Insert(entLeave, Convert.ToInt32(Session["UserID"].ToString().Trim()))) { if (entLeave.LeaveID > 0) { entLeaveStatus.LeaveID = entLeave.LeaveID; } if (!balLeaveType.UpdateTotalDaysByLeaveType(entLeaveType)) { PanelErrorMesseage.Visible = true; lblErrorMessage.Text = balLeaveType.Message; } clearSelection(); PanelSuccess.Visible = true; lblSuccess.Text = "Data Inserted Successfully"; } else { PanelErrorMesseage.Visible = true; lblErrorMessage.Text = balLeave.Message; } if (!balLeaveStatus.Insert(entLeaveStatus, Convert.ToInt32(Session["UserID"].ToString().Trim()))) { PanelErrorMesseage.Visible = true; lblErrorMessage.Text = balLeaveStatus.Message; } } } else if (entLeaveType.LeaveType == "Other Leave") { entLeaveType.UserID = Convert.ToInt32(Session["UserID"].ToString().Trim()); if (rbHalfLeave.Checked == true) { entLeaveType.TotalDays = entLeaveType.TotalDays - 1; } else if (rbFullLeave.Checked == true) { string strEndDate = txtLeaveEndDate.Text.Trim(); string[] EndDateString = strEndDate.Split('-'); DateTime enddate = Convert.ToDateTime(EndDateString[0] + "-" + EndDateString[1] + "-" + EndDateString[2]); entLeaveType.TotalDays = entLeaveType.TotalDays - Convert.ToInt32((enddate - startdate).TotalDays) - 1; } if (entLeaveType.TotalDays < 0) { PanelErrorMesseage.Visible = true; lblErrorMessage.Text = "You Can't Add More Other Leave Because You Had Already Use It"; return; } else { if (balLeave.Insert(entLeave, Convert.ToInt32(Session["UserID"].ToString().Trim()))) { if (entLeave.LeaveID > 0) { entLeaveStatus.LeaveID = entLeave.LeaveID; } if (!balLeaveType.UpdateTotalDaysByLeaveType(entLeaveType)) { PanelErrorMesseage.Visible = true; lblErrorMessage.Text = balLeaveType.Message; } clearSelection(); PanelSuccess.Visible = true; lblSuccess.Text = "Data Inserted Successfully"; } else { PanelErrorMesseage.Visible = true; lblErrorMessage.Text = balLeave.Message; } if (!balLeaveStatus.Insert(entLeaveStatus, Convert.ToInt32(Session["UserID"].ToString().Trim()))) { PanelErrorMesseage.Visible = true; lblErrorMessage.Text = balLeaveStatus.Message; } } } } else { entLeave.LeaveID = Convert.ToInt32(Request.QueryString["LeaveID"].ToString().Trim()); entLeaveStatus.LeaveID = Convert.ToInt32(Request.QueryString["LeaveID"].ToString().Trim()); string strStartDate = txtLeaveStartDate.Text.Trim(); string[] StartDateString = strStartDate.Split('-'); DateTime startdate = Convert.ToDateTime(StartDateString[0] + "-" + StartDateString[1] + "-" + StartDateString[2]); if (entLeaveType.LeaveType == "Casual Leave") { entLeaveType.UserID = Convert.ToInt32(Session["UserID"].ToString().Trim()); if (rbHalfLeave.Checked == true) { entLeaveType.TotalDays = entLeaveType.TotalDays - 1; } else if (rbFullLeave.Checked == true) { string strEndDate = txtLeaveEndDate.Text.Trim(); string[] EndDateString = strEndDate.Split('-'); DateTime enddate = Convert.ToDateTime(EndDateString[0] + "-" + EndDateString[1] + "-" + EndDateString[2]); entLeaveType.TotalDays = entLeaveType.TotalDays - Convert.ToInt32((enddate - startdate).TotalDays) - 1; } if (entLeaveType.TotalDays < 0) { PanelErrorMesseage.Visible = true; lblErrorMessage.Text = "You Can't Add More Casual Leave Because You Had Already Use It"; return; } } else if (entLeaveType.LeaveType == "Medical Leave") { entLeaveType.UserID = Convert.ToInt32(Session["UserID"].ToString().Trim()); if (rbHalfLeave.Checked == true) { entLeaveType.TotalDays = entLeaveType.TotalDays - 1; } else if (rbFullLeave.Checked == true) { string strEndDate = txtLeaveEndDate.Text.Trim(); string[] EndDateString = strEndDate.Split('-'); DateTime enddate = Convert.ToDateTime(EndDateString[0] + "-" + EndDateString[1] + "-" + EndDateString[2]); entLeaveType.TotalDays = entLeaveType.TotalDays - Convert.ToInt32((enddate - startdate).TotalDays) - 1; } if (entLeaveType.TotalDays < 0) { PanelErrorMesseage.Visible = true; lblErrorMessage.Text = "You Can't Add More Medical Leave Because You Had Already Use It"; return; } } else if (entLeaveType.LeaveType == "LOP") { entLeaveType.UserID = Convert.ToInt32(Session["UserID"].ToString().Trim()); if (rbHalfLeave.Checked == true) { entLeaveType.TotalDays = entLeaveType.TotalDays - 1; } else if (rbFullLeave.Checked == true) { string strEndDate = txtLeaveEndDate.Text.Trim(); string[] EndDateString = strEndDate.Split('-'); DateTime enddate = Convert.ToDateTime(EndDateString[0] + "-" + EndDateString[1] + "-" + EndDateString[2]); entLeaveType.TotalDays = entLeaveType.TotalDays - Convert.ToInt32((enddate - startdate).TotalDays) - 1; } if (entLeaveType.TotalDays < 0) { PanelErrorMesseage.Visible = true; lblErrorMessage.Text = "You Can't Add More LOP Leave Because You Had Already Use It"; return; } } else if (entLeaveType.LeaveType == "Other Leave") { entLeaveType.UserID = Convert.ToInt32(Session["UserID"].ToString().Trim()); if (rbHalfLeave.Checked == true) { entLeaveType.TotalDays = entLeaveType.TotalDays - 1; } else if (rbFullLeave.Checked == true) { string strEndDate = txtLeaveEndDate.Text.Trim(); string[] EndDateString = strEndDate.Split('-'); DateTime enddate = Convert.ToDateTime(EndDateString[0] + "-" + EndDateString[1] + "-" + EndDateString[2]); entLeaveType.TotalDays = entLeaveType.TotalDays - Convert.ToInt32((enddate - startdate).TotalDays) - 1; } if (entLeaveType.TotalDays < 0) { PanelErrorMesseage.Visible = true; lblErrorMessage.Text = "You Can't Add More Other Leave Because You Had Already Use It"; return; } } entLeaveType.UserID = Convert.ToInt32(Session["UserID"].ToString().Trim()); if (!balLeaveType.UpdateTotalDaysByLeaveType(entLeaveType)) { PanelErrorMesseage.Visible = true; lblErrorMessage.Text = balLeaveType.Message; } if (!balLeave.Update(entLeave, Convert.ToInt32(Session["UserID"].ToString().Trim()))) { PanelErrorMesseage.Visible = true; lblErrorMessage.Text = balLeave.Message; } if (balLeaveStatus.UpdateLeaveStatus(entLeaveStatus)) { Response.Redirect("~/Content/Leave/LeaveList.aspx"); } else { PanelErrorMesseage.Visible = true; lblErrorMessage.Text = balLeaveStatus.Message; } } }