在我的 MVC 应用程序中,我有一个启动按钮,单击时会触发计时器。如果我复制该页面并再次单击开始按钮,计时器将重新开始。如何修改代码以显示一个弹出窗口,指示计时器已在运行?
@if ((Model.ISetupStatus != 3 && !Model.BIsJobFinished) && (BLSession.BIsProductionAccess || Model.objPageAccessInfo.BIsStatusUpdate)) {
设置部分
@if(模型.ISetupStatus == 0) { 开始 结束 } 否则如果(模型.ISetupStatus == 1) { 停止 结束 } 否则如果(模型.ISetupStatus == 2) { 开始 结束 }@if ((Model.ISetupStatus != 3 && !Model.BIsJobFinished) && (BLSession.BIsProductionAccess || Model.objPageAccessInfo.BIsStatusUpdate))
{
<div style="border: 1px solid rgb( 224, 228, 228 );border-left: 3.9px solid #d2d2d2;padding: 20px 30px;border-radius: 7px;padding-top: 12px;float:left;">
<p>Setup Section</p>
<div class="inner" style="border-radius:4px;display:inline-block;">
@if (Model.ISetupStatus == 0)
{
<button class="btn production-btn" type="button" style="width:135px;background-color:green;" onclick="javascript: UpdateProductionStatus(@Model.IJobID,1,true,false);">Start</button>
<button class="btn production-btn" type="button" style="width:135px;background-color:#ff000052;" onclick="javascript: UpdateProductionStatus(@Model.IJobID,3,true,true);" disabled>Finish</button>
}
else if (Model.ISetupStatus == 1)
{
<button class="btn production-btn" type="button" style="width:135px;background-color:red;" onclick="javascript: UpdateProductionStatus(@Model.IJobID,2,true,true);">Stop</button>
<button class="btn production-btn" type="button" style="width:135px;background-color:red;" onclick="javascript: UpdateProductionStatus(@Model.IJobID,3,true,true);">Finish</button>
}
else if (Model.ISetupStatus == 2)
{
<button class="btn production-btn" type="button" style="width:135px;background-color:green;" onclick="javascript: UpdateProductionStatus(@Model.IJobID,1,true,false);">Start</button>
<button class="btn production-btn" type="button" style="width:135px;background-color:red;" onclick="javascript: UpdateProductionStatus(@Model.IJobID,3,true,true);">Finish</button>
}
</div>
<br /><br />
<div>
@if(Model.BIsSetupRunning)
{
<b id="@Model.IOrderID" style="font-size: 18px;">@Model.STotalSetupRunningTime</b>
}
else if (Model.BIsSetupStopped)
{
<b style="font-size: 18px;" class="blinking">@Model.STotalSetupTime</b>
}
else if (Model.BIsSetupCompleted)
{
<b style="font-size: 18px;">@Model.STotalSetupTime</b>
}
</div>
<p class="preview_updatebutton" style="margin-top:10px;display:none;" id="divSetupStopComments">
<textarea id="txtSetupStopComments" class="popup-description" rows="2" cols="32" placeholder="Note misprints and or any problems for this Job"></textarea><br /><br />
<button class="btn production-btn" type="button" style="width:135px;float:right;" onclick="javascript: UpdateProductionStatus(@Model.IJobID,2,true,false);">Submit</button>
</p>
</div>
}
添加 JavaScript 函数来显示弹出窗口:
<script>
function displayTimerRunningPopup() {
alert('The timer is already running. Please wait until it finishes.');
}
</script>
修改开始按钮的onclick事件,在启动之前检查定时器是否已经在运行:
<button class="btn production-btn" type="button" style="width:135px;background-color:green;" onclick="javascript: if([email protected]) UpdateProductionStatus(@Model.IJobID,1,true,false); else displayTimerRunningPopup();">Start</button>
在此修改中,我们使用 Razor 语法 @Model.BIsSetupRunning 来检查计时器是否已在运行。如果它正在运行(BIsSetupRunning 为 true),将调用 displayTimerRunningPopup() JavaScript 函数来显示弹出窗口。否则,将调用 UpdateProductionStatus 函数来启动计时器。
我希望这会有所帮助 谢谢