Hello Guys,
I am working on a website which consist of webpage built in 24 hour format. In that user will be given 2 dropdown boxes in which he select Hour and minutes. The page is built using Javascript. Now my task is that i have to convert it into 12 hour format. Can you help me in that regard? Thanks.
I have made the following changes in my code :-
<%@ Page Language="C#" MasterPageFile="~/include/master/home_page.master" AutoEventWireup="true" CodeFile="email_schedule_status.aspx.cs" Inherits="email_email_schedule_status" %>
<asp:Content ID="ContentHead" ContentPlaceHolderID="ContentPlaceHolderHead" runat="server">
<link type="text/css" rel="stylesheet" href="/include/style/jquery-ui-1.8.5.custom.css" />
<script type="text/javascript" src="/include/script/jquery.ui.core.js"></script>
<script type="text/javascript" src="/include/script/jquery.ui.datepicker.js"></script>
</asp:Content>
<asp:Content ID="ContentBody" ContentPlaceHolderID="ContentPlaceHolderBody" runat="server">
<script language="javascript" type="text/javascript">
function func_check_schedule()
{
var objScheduleFor = eval("document.forms[0]." + "ctl00_ContentPlaceHolderBody_rbtnScheduleFor");
var objScheduleDate = eval("document.forms[0]." + "ctl00_ContentPlaceHolderBody_txtScheduleDate");
var objScheduleHours = document.getElementById("ctl00_ContentPlaceHolderBody_ddlHrs");
var objScheduleMinutes = document.getElementById("ctl00_ContentPlaceHolderBody_ddlMinutes");
var objTime = document.getElementById("ctl00_ContentPlaceHolderBody_ddlTime");
var objDate = document.getElementById("Date");
if(objScheduleFor && objScheduleFor.checked == true)
{
if(objScheduleDate)
{
objScheduleDate.disabled = false;
objScheduleHours.disabled = false;
objScheduleMinutes.disabled = false;
objTime.disabled = false;
objDate.disabled = false;
}
}
else
{
if(objScheduleDate)
{
objScheduleDate.disabled = true;
objScheduleHours.disabled = true;
objScheduleMinutes.disabled = true;
objTime.disabled = true;
}
if(objDate)
{
objDate.disabled = true;
}
}
}
function Validate_Date()
{
var bFlag = false;
var ScheduleDate = document.getElementById("ctl00_ContentPlaceHolderBody_txtScheduleDate").value;
var Hours = document.getElementById("ctl00_ContentPlaceHolderBody_ddlHrs").value;
var Minutes = document.getElementById("ctl00_ContentPlaceHolderBody_ddlMinutes").value;
var Time = document.getElementById("ctl00_ContentPlaceHolderBody_ddlTime").value;
var objRadio = eval("document.forms[0]." + "ctl00$ContentPlaceHolderBody$grpEmailStatus");
if(objRadio != null)
{
for(var iCtr = 0; iCtr < objRadio.length; iCtr++)
{
if(objRadio[iCtr].checked == true)
{
bFlag = true;
break;
}
}
if(bFlag == false)
{
alert("Please select any status");
return false;
}
}
if(!ScheduleDate.match(/^(?:([1-9]|0[1-9]|1[012])[\- \/.]([1-9]|0[1-9]|[12][0-9]|3[01])[\- \/.](19|20)[0-9]{2})$/))
{
alert("Please enter schedule date in valid format(mm/dd/yyyy).");
return false;
}
if(document.getElementById("ctl00_ContentPlaceHolderBody_rbtnScheduleFor").checked == true)
{
if(Hours == "----")
{
alert("Please select hours.");
return false;
}
if(Minutes == "----")
{
alert("Please select minutes.");
return false;
}
dtCurrent = new Date();
dtCurrentConstructedDate = new Date(dtCurrent.getYear(), dtCurrent.getMonth(), dtCurrent.getDate(), dtCurrent.getHours(), dtCurrent.getMinutes());
var sExistingDate = ScheduleDate + " :" + Hours + ":" + Minutes+ ":" + Time;
dtExistingDate = new Date(sExistingDate);
if (dtExistingDate <= dtCurrent)
{
alert("Schedule date and time should not be less than or equal to Current date & time!!!");
return false;
}
}
function Enable_Calendar()
{
var objScheduleFor = eval("document.forms[0]." + "ctl00_ContentPlaceHolderBody_rbtnScheduleFor");
var dDate = document.getElementById("Date");
if(objScheduleFor.checked == true)
{
dDate.disabled = false;
}
else
{
dDate.disabled = true;
}
}
}
</script>
<script type="text/javascript">
var sPrefixDateFrom = "#ctl00_ContentPlaceHolderBody_txtScheduleDate";
$(document).ready(function () {
$(sPrefixDateFrom).datepicker({
showOn: 'both',
buttonImage: '/images/cal.jpg',
showButtonPanel: true,
buttonImageOnly: true,
changeMonth: true,
changeYear: true,
minDate: 'today'
});
});
</script>
<div id="mid_undr_wrapp">
<div style="height: 23px;">
</div>
<div id="socialpage_tab_wrapp">
<div id="Progressbar_wrapp">
<ul id="progress">
<li class="blue"><a href="/admin/">Dashboard → </a></li>
<li class="blue"><a href="/admin/emailmarketing/schedule_list.aspx">Email →</a></li>
<li class="blue"><a id="aEditTemplate" runat="server">Change Template →</a></li>
<li class="blue"><a id="aEditContent" runat="server">Content →</a></li>
<li class="blue"><a id="aEmailSettings" runat="server" href="">Settings →</a></li>
<li class="blue"><a id="aUserList" runat="server" href="">Email List →</a></li>
<li class="orange disable-link"><a href="">Schedule →</a></li>
<li class="disable-link"><a href="">Confirmation</a></li>
</ul>
</div>
<div id="pge_heading_txt">
Email Schedule Status
</div>
<div style="width:80%; margin:0 auto;">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr height="10px">
<td>
</td>
</tr>
<tr>
<td class="text2" width="100%">
<b class="field-caption">Email Name:</b>
<%=m_sScheduleName%>
</td>
<td align="right">
<a onclick="mypopup('eschedulestatus')" href="#" title="Help">
<img src="images/help-icon.jpg" border="0" alt="" /></a>
</td>
</tr>
</table>
<div class="heading_margin"></div>
<table border="0" cellpadding="0" cellspacing="0" width="95%" align="center">
<tr>
<td>
<asp:Literal ID="ltrlMessage" runat="server"></asp:Literal>
</td>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<td>
<table border="0" cellpadding="0" cellspacing="0" width="100%" class="tbloutline">
<tr class="grid1">
<td>
</td>
<td width="50px" align="right">
<b class="field-caption">Select</b>
</td>
<td>
<b class="field-caption">Status</b>
</td>
</tr>
<%if (socialmediasms.Sessioncl.GetSessionResendScheduleId() == "0" && m_iScheduleIdRelated == 0)
{ %>
<tr>
<td class="tbloutlinerow">
</td>
<td class="tbloutlinerow" align="right">
<asp:RadioButton ID="rbtnDraft" runat="server" GroupName="grpEmailStatus" Checked="true"
onClick="func_check_schedule()" />
</td>
<td class="tbloutlinerow">
Draft
</td>
</tr>
<%} %>
<tr>
<td class="tbloutlinerow">
</td>
<td class="tbloutlinerow" align="right">
<asp:RadioButton ID="rbtnSendNow" runat="server" GroupName="grpEmailStatus" Checked="true" onclick="func_check_schedule()" />
</td>
<td class="tbloutlinerow">
Send Now
</td>
</tr>
<tr>
<td>
</td>
<td align="right">
<asp:RadioButton ID="rbtnScheduleFor" runat="server" GroupName="grpEmailStatus" onclick="func_check_schedule()" />
</td>
<td>
Schedule For
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
<td>
Date: <asp:TextBox ID="txtScheduleDate" runat="server"></asp:TextBox>
<asp:RangeValidator ID="rvDate" runat="server" ValidationGroup="message" Type="Date"
ControlToValidate="txtScheduleDate" ErrorMessage="Please choose valid date" Display="None"
Height="16px" MinimumValue="2009/06/01" MaximumValue="9999/12/31"></asp:RangeValidator>
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
<td>
Time: <asp:DropDownList ID="ddlHrs" runat="server" Width="50px">
</asp:DropDownList>
<asp:DropDownList ID="ddlMinutes" runat="server" Width="50px">
</asp:DropDownList>
<asp:DropDownList ID="ddlTime" runat="server" Width="50px">
<asp:ListItem>AM</asp:ListItem>
<asp:ListItem>PM</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
</table>
</td>
</tr>
<tr height="10px">
<td>
</td>
</tr>
<%if (socialmediasms.Sessioncl.GetSessionScheduleId() != "0")
{ %>
<tr>
<td>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr height="30px">
<td align="left">
<asp:ImageButton ID="btnFinishBottom" Text="Finish" runat="server" ImageUrl="~/images/save_continue.png"
OnClick="btnFinish_Click" OnClientClick="return Validate_Date();" />
</td>
</tr>
</table>
</td>
</tr>
<%} %>
<%if (socialmediasms.Sessioncl.GetSessionScheduleId() == "0")
{ %>
<tr>
<td>
<asp:ImageButton ID="btnSave" runat="server" ImageUrl="/images/save.png" Text="Save"
OnClick="btnSave_Click" OnClientClick="return Validate_Date();" />
<asp:ImageButton ID="btnCancel" runat="server" ImageUrl="/images/cancel.png" Text="Cancel"
OnClick="btnCancel_Click" />
</td>
</tr>
<%} %>
</table>
</div>
<div class="heading_margin"></div>
</div>
</div>
<script type="text/javascript">
func_check_schedule();
</script>
</asp:Content>
This is my CS File :-
using System;
using System.Data;
using System.Web.UI.WebControls;
using socialmediasms;
public partial class email_email_schedule_status : System.Web.UI.Page
{
private int m_iClientId = 0;
private int m_iUserId = 0;
private int m_iScheduleId = 0;
public string m_sEnable = "";
public string m_sScheduleName = "";
public int m_iScheduleIdRelated = 0;
protected void Page_Load(object sender, EventArgs e)
{
Sessioncl.CheckUserSession();
m_iClientId = Sessioncl.GetLoggedInClientId();
m_iUserId = Sessioncl.GetLoggedInClientId();
m_iScheduleId = Numericcl.GetIntValue(Request.QueryString["i"]);
if (!IsPostBack)
{
this.FillTime();
this.Form_Details(Applicationcl.eFormDetailType.eInitialize);
this.ManageBreadcrumb();
}
}
private void Form_Details(Applicationcl.eFormDetailType eType)
{
if (eType == Applicationcl.eFormDetailType.eInitialize)
{
EmailSchedulecl oEmailSchedulecl = new EmailSchedulecl();
DataTable dtSchedule = null;
if (Sessioncl.GetSessionResendScheduleId() == "0")
{
dtSchedule = oEmailSchedulecl.GetScheduleDetails(m_iClientId, m_iScheduleId);
}
else
{
dtSchedule = oEmailSchedulecl.GetScheduleFromTempSchedule(m_iClientId, Numericcl.GetIntValue(Sessioncl.GetSessionResendScheduleId()));
}
if (dtSchedule != null && dtSchedule.Rows.Count > 0)
{
m_sScheduleName = dtSchedule.Rows[0]["vc_schedule_name"].ToString();
m_iScheduleIdRelated = Numericcl.GetIntValue(dtSchedule.Rows[0]["in_schedule_id_related"].ToString());
}
if (m_iScheduleIdRelated == 0 && Sessioncl.GetSessionResendScheduleId() == "0")
{
ltrlMessage.Text = "Set your email status to "__^ a date and time to send it. If you're ready to send it now, select ^__b class="field-caption">Send Now.";
}
else
{
ltrlMessage.Text = "Set your email status to ^__b class="field-caption">Schedule a date and time to send it. If you're ready to send it now, select ^__b class="field-caption">Send Now.";
}
txtScheduleDate.Text = DateTime.Today.Date.ToShortDateString();
ddlHrs.SelectedValue = DateTime.Now.Hour.ToString();
ddlMinutes.SelectedValue = "00";
txtScheduleDate.Enabled = false;
ddlHrs.Enabled = false;
ddlMinutes.Enabled = false;
int iScheduleStatusTypeId = 0;
if (dtSchedule.Rows.Count > 0)
{
iScheduleStatusTypeId = Numericcl.GetIntValue(dtSchedule.Rows[0]["in_schedule_status_type_id"].ToString());
}
if (iScheduleStatusTypeId == 1)
{
rbtnDraft.Checked = true;
}
else if (iScheduleStatusTypeId == 2)
{
rbtnSendNow.Checked = true;
}
else if (iScheduleStatusTypeId == 3)
{
rbtnScheduleFor.Checked = true;
txtScheduleDate.Enabled = true;
ddlHrs.Enabled = true;
ddlMinutes.Enabled = true;
txtScheduleDate.Text = dtSchedule.Rows[0]["dt_schedule"].ToString();
ddlHrs.SelectedValue = dtSchedule.Rows[0]["vc_hour"].ToString();
ddlMinutes.SelectedValue = dtSchedule.Rows[0]["vc_minutes"].ToString();
}
if (rbtnScheduleFor.Checked == true)
{
m_sEnable = "Block";
}
else
{
m_sEnable = "None";
}
oEmailSchedulecl = null;
}
else if (eType == Applicationcl.eFormDetailType.eSave)
{
int iStatusId = 0;
string sScheduleDate = "";
EmailSchedulecl oEmailSchedulecl = new EmailSchedulecl();
if (rbtnDraft.Checked == true)
{
iStatusId = 1;
sScheduleDate = DateTime.Now.ToShortDateString();
}
else if (rbtnSendNow.Checked == true)
{
iStatusId = 3;
DateTime dDate = DateTime.Now;
DateTime dDateCurrent = DateTime.Now;
if (dDateCurrent.Minute == 0)
{
dDate = Convert.ToDateTime(dDateCurrent.Month + "/" + dDateCurrent.Day + "/" + dDateCurrent.Year + " " + dDateCurrent.Hour + ":" + "00" + ": 00");
}
else if (dDateCurrent.Minute >= 1 && dDateCurrent.Minute <= 15)
{
dDate = Convert.ToDateTime(dDateCurrent.Month + "/" + dDateCurrent.Day + "/" + dDateCurrent.Year + " " + dDateCurrent.Hour + ":" + "15" + ": 00");
}
else if (dDateCurrent.Minute >= 16 && dDateCurrent.Minute <= 30)
{
dDate = Convert.ToDateTime(dDateCurrent.Month + "/" + dDateCurrent.Day + "/" + dDateCurrent.Year + " " + dDateCurrent.Hour + ":" + "30" + ": 00");
}
else if (dDateCurrent.Minute >= 30 && dDateCurrent.Minute <= 45)
{
dDate = Convert.ToDateTime(dDateCurrent.Month + "/" + dDateCurrent.Day + "/" + dDateCurrent.Year + " " + dDateCurrent.Hour + ":" + "45" + ": 00");
}
else if (dDateCurrent.Minute >= 46 && dDateCurrent.Minute <= 59)
{
dDateCurrent = dDateCurrent.AddHours(1);
dDate = Convert.ToDateTime(dDateCurrent.Month + "/" + dDateCurrent.Day + "/" + dDateCurrent.Year + " " + dDateCurrent.Hour + ":" + "15" + ": 00");
}
sScheduleDate = dDate.ToString();
}
else if (rbtnScheduleFor.Checked == true)
{
iStatusId = 3;
sScheduleDate = txtScheduleDate.Text + " " + ddlHrs.SelectedValue + ":" + ddlMinutes.SelectedValue + ": 00";
}
oEmailSchedulecl.UpdateScheduleStatusIdInSchedule(m_iClientId, m_iScheduleId, iStatusId, sScheduleDate, m_iUserId);
oEmailSchedulecl = null;
}
}
protected void btnFinish_Click(object sender, EventArgs e)
{
if (Sessioncl.GetSessionResendScheduleId() == "0")
{
this.Form_Details(Applicationcl.eFormDetailType.eSave);
Response.Redirect("email_status.aspx?i=" + m_iScheduleId);
}
else
{
if (Sessioncl.GetSessionResendScheduleId() != "0")
{
int iScheduleId = 0;
if (Sessioncl.GetSessionSelectedResendOption() == "EnterEmailAddess")
{
string sSessionListId = Sessioncl.GetSessionListId();
string delimStr = ",";
char[] delimiter = delimStr.ToCharArray();
string[] sListId = sSessionListId.Split(delimiter);
EmailSchedulecl oEmailSchedulecl = new EmailSchedulecl();
EmailTemplatecl oEmailTemplatecl = new EmailTemplatecl(m_iClientId, Numericcl.GetIntValue(Sessioncl.GetSessionScheduleId()));
iScheduleId = oEmailSchedulecl.SaveDataFormTemporaryScheduleTable(m_iClientId, Numericcl.GetIntValue(Sessioncl.GetSessionResendScheduleId()), m_iUserId);
oEmailSchedulecl.UpdateScheduleIdRelated(m_iClientId, iScheduleId, Numericcl.GetIntValue(Sessioncl.GetSessionScheduleId()), m_iUserId);
oEmailTemplatecl.Save(m_iClientId, iScheduleId, oEmailTemplatecl.TemplateId, oEmailTemplatecl.TemplateTypeId, oEmailTemplatecl.TemplateName, oEmailTemplatecl.Template, m_iClientId);
EmailScheduleListcl oEmailScheduleListcl = new EmailScheduleListcl();
for (int iCtr = 0; iCtr < sListId.Length - 1; iCtr++)
{
int iListId = Numericcl.GetIntValue(sListId[iCtr]);
oEmailScheduleListcl.Save(m_iClientId, iScheduleId, iListId, m_iUserId);
}
DataTable dtScheduleList = oEmailScheduleListcl.GetScheduleList(m_iClientId, iScheduleId);
EmailListUsercl oEmailListUsercl = new EmailListUsercl();
EmailScheduleListUsercl oEmailScheduleListUsercl = new EmailScheduleListUsercl();
for (int iCtr = 0; iCtr < dtScheduleList.Rows.Count; iCtr++)
{
int iListId = Numericcl.GetIntValue(dtScheduleList.Rows[iCtr]["in_list_id"]);
DataTable dtListUser = oEmailListUsercl.GetUserList(m_iClientId, iListId);
for (int iListUser = 0; iListUser < dtListUser.Rows.Count; iListUser++)
{
int iUserId = Numericcl.GetIntValue(dtListUser.Rows[iListUser]["in_user_id"]);
oEmailScheduleListUsercl.Save(m_iClientId, iScheduleId, iListId, iUserId, m_iUserId);
}
dtListUser = null;
}
oEmailSchedulecl.DeleteFromTempSchedule(m_iClientId, Numericcl.GetIntValue(Sessioncl.GetSessionResendScheduleId()));
m_iScheduleId = iScheduleId;
this.Form_Details(Applicationcl.eFormDetailType.eSave);
iScheduleId = Numericcl.GetIntValue(Sessioncl.GetSessionScheduleId());
Sessioncl.SetSessionSelectedResendOption("");
Sessioncl.SetSessionListId("");
Sessioncl.SetSessionScheduleId(0);
Sessioncl.SetSessionResendScheduleId(0);
dtScheduleList = null;
oEmailSchedulecl = null;
oEmailListUsercl = null;
oEmailScheduleListcl = null;
oEmailScheduleListUsercl = null;
Response.Redirect("email_status.aspx?i=" + iScheduleId + "&ii=" + m_iScheduleId);
}
else if (Sessioncl.GetSessionSelectedResendOption() == "ExitingListContact")
{
int iListId = 0;
EmailSchedulecl oEmailSchedulecl = new EmailSchedulecl();
EmailTemplatecl oEmailTemplatecl = new EmailTemplatecl(m_iClientId, Numericcl.GetIntValue(Sessioncl.GetSessionScheduleId()));
iScheduleId = oEmailSchedulecl.SaveDataFormTemporaryScheduleTable(m_iClientId, Numericcl.GetIntValue(Sessioncl.GetSessionResendScheduleId()), m_iUserId);
oEmailSchedulecl.UpdateScheduleIdRelated(m_iClientId, iScheduleId, Numericcl.GetIntValue(Sessioncl.GetSessionScheduleId()), m_iUserId);
oEmailTemplatecl.Save(m_iClientId, oEmailTemplatecl.ScheduleId, oEmailTemplatecl.TemplateId, oEmailTemplatecl.TemplateTypeId, oEmailTemplatecl.TemplateName, oEmailTemplatecl.Template, m_iClientId);
EmailScheduleListcl oEmailScheduleListcl = new EmailScheduleListcl();
DataTable dtScheduleList = oEmailScheduleListcl.GetScheduleList(m_iClientId, Numericcl.GetIntValue(Sessioncl.GetSessionScheduleId()));
EmailListUsercl oEmailListUsercl = new EmailListUsercl();
EmailScheduleListUsercl oEmailScheduleListUsercl = new EmailScheduleListUsercl();
for (int iCtr = 0; iCtr < dtScheduleList.Rows.Count; iCtr++)
{
iListId = Numericcl.GetIntValue(dtScheduleList.Rows[iCtr]["in_list_id"]);
DataTable dtListUser = oEmailListUsercl.GetUserList(m_iClientId, iListId);
for (int iListUser = 0; iListUser < dtListUser.Rows.Count; iListUser++)
{
int iUserId = Numericcl.GetIntValue(dtListUser.Rows[iListUser]["in_user_id"]);
if (!oEmailScheduleListUsercl.CheckScheduleListUser(m_iClientId, Numericcl.GetIntValue(Sessioncl.GetSessionScheduleId()), iListId, iUserId))
{
oEmailScheduleListcl.Save(m_iClientId, iScheduleId, iListId, m_iUserId);
oEmailScheduleListUsercl.Save(m_iClientId, iScheduleId, iListId, iUserId, m_iUserId);
}
}
dtListUser = null;
}
Sessioncl.ClearTempData(m_iClientId);
m_iScheduleId = iScheduleId;
this.Form_Details(Applicationcl.eFormDetailType.eSave);
iScheduleId = Numericcl.GetIntValue(Sessioncl.GetSessionScheduleId());
Sessioncl.SetSessionSelectedResendOption("");
Sessioncl.SetSessionListId("");
Sessioncl.SetSessionScheduleId(0);
Sessioncl.SetSessionResendScheduleId(0);
dtScheduleList = null;
oEmailSchedulecl = null;
oEmailListUsercl = null;
oEmailScheduleListcl = null;
oEmailScheduleListUsercl = null;
Response.Redirect("email_status.aspx?i=" + iScheduleId + "&ii=" + m_iScheduleId);
}
}
}
}
protected void btnSave_Click(object sender, EventArgs e)
{
this.Form_Details(Applicationcl.eFormDetailType.eSave);
Response.Redirect("email_status.aspx?i=" + m_iScheduleId);
}
protected void btnCancel_Click(object sender, EventArgs e)
{
Response.Redirect("email_status.aspx?i=" + m_iScheduleId);
}
private void FillTime()
{
int iCtr = 1;
for (iCtr = 1; iCtr <= 12; iCtr++)
{
ddlHrs.Items.Add(new ListItem(iCtr.ToString(), iCtr.ToString()));
}
for (iCtr = 0; iCtr <= 45; iCtr += 15)
{
if (iCtr == 0)
{
ddlMinutes.Items.Add(new ListItem("00", iCtr.ToString()));
}
else
{
ddlMinutes.Items.Add(new ListItem(iCtr.ToString(), iCtr.ToString()));
}
}
}
private void ManageBreadcrumb()
{
EmailSchedulecl oEmailSchedulecl = new EmailSchedulecl(m_iClientId, m_iScheduleId);
aEditTemplate.HRef = "/admin/emailmarketing/edit_template.aspx?i=" + m_iScheduleId + "&ii=" + oEmailSchedulecl.TemplateId;
aEditContent.HRef = "/admin/emailmarketing/manage_content.aspx?i=" + m_iScheduleId + "&ii=" + oEmailSchedulecl.TemplateId;
aEmailSettings.HRef = "/admin/emailmarketing/email_schedule_extend.aspx?i=" + m_iScheduleId + "&ii=" + oEmailSchedulecl.TemplateId;
aUserList.HRef = "/admin/emailmarketing/email_list.aspx?i=" + m_iScheduleId;
}
}