protected void frmViewAdd_ItemUpdating(object sender, FormViewUpdateEventArgs e) { try { ModalPopupExtender2.Show(); DateTime startDate = DateTime.Parse(((TextBox)this.frmViewAdd.FindControl("txtStartDate")).Text); DateTime endDate = DateTime.Parse(((TextBox)this.frmViewAdd.FindControl("txtEndDate")).Text); int frequency = int.Parse(((DropDownList)this.frmViewAdd.FindControl("drpFrequency")).SelectedValue); TimeSpan ts = endDate.Subtract(startDate); DateTimeHelper.DateDifference findMonths = new DateTimeHelper.DateDifference(startDate, endDate); DateTime nextDate = startDate.AddMonths(frequency); if (DateTime.Compare(startDate, endDate) > 0) { e.Cancel = true; //ScriptManager.RegisterStartupScript(Page, Page.GetType(), Guid.NewGuid().ToString(), "alert('EndDate should not be less than StartDate and Try again.');", true); ((Label)this.frmViewAdd.FindControl("lblError")).Text = "EndDate should not be less than StartDate and Try again."; return; } if (DateTime.Compare(nextDate, endDate) > 0) { e.Cancel = true; //ScriptManager.RegisterStartupScript(Page, Page.GetType(), Guid.NewGuid().ToString(), "alert('Next visit date will exceede the EndDate. Please try again.');", true); ((Label)this.frmViewAdd.FindControl("lblError")).Text = "Next visit date will exceede the EndDate. Please try again."; return; } int reminder = findMonths.TotalMonths % frequency; if (reminder != 0) { e.Cancel = true; //ScriptManager.RegisterStartupScript(Page, Page.GetType(), Guid.NewGuid().ToString(), "alert('Invalid EndDate, Please check the EndDate and try again.');", true); ((Label)this.frmViewAdd.FindControl("lblError")).Text = "Invalid EndDate, Please check the EndDate and try again."; return; } } catch (Exception ex) { TroyLiteExceptionManager.HandleException(ex); } }
private double CalculateTotalLeaveDays(DateTime StartDate, string StartDateSession, DateTime EndDate, string EndDateSession) { double totalLeaveDays = 0; int dateDiffDays = new DateTimeHelper.DateDifference(StartDate, EndDate).Days; if (dateDiffDays.Equals(0)) { if (StartDateSession.Equals("FN") && EndDateSession.Equals("AN")) { totalLeaveDays = 1.0; } else if (StartDateSession.Equals("FN") && EndDateSession.Equals("FN")) { totalLeaveDays = 0.5; } else if (StartDateSession.Equals("AN") && EndDateSession.Equals("AN")) { totalLeaveDays = 0.5; } } else { if (StartDateSession.Equals("FN") && EndDateSession.Equals("AN")) { totalLeaveDays = dateDiffDays + 1; } else if (StartDateSession.Equals("FN") && EndDateSession.Equals("FN")) { totalLeaveDays = dateDiffDays + 0.5; } else if (StartDateSession.Equals("AN") && EndDateSession.Equals("AN")) { totalLeaveDays = dateDiffDays + 0.5; } else if (StartDateSession.Equals("AN") && EndDateSession.Equals("FN")) { totalLeaveDays = dateDiffDays; } } return(totalLeaveDays); }