Hi,
I would need to update a value and the label colour of the value accordingly, it should show red if the value does not match the value in the array, green otherwise.
This is my code, my code looks so messy, I seriously am not sure if I am using the Timer control properly. I need the interval set to 10, as the moment the data is updated in the database, it should automatically show on the page. However, the colour of the value must change accordingly.
<%@ Page Title="" Language="C#" MasterPageFile="~/Progress.Master" AutoEventWireup="true" CodeBehind="Progress-ManRoland1.aspx.cs" Inherits="WebApplication1.Progress_ManRoland1" %><asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"></asp:Content><asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"><asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager><asp:UpdatePanel ID="UpdatePanel1" runat="server"><ContentTemplate><asp:Timer runat="server" ID="Timer1" Interval="10" OnTick="IncreaseCount"></asp:Timer><div class="container"><asp:Label ID="Label0" runat="server" Text="Label" CssClass="font-size-progress"></asp:Label><asp:Label ID="lblslash" runat="server" Text="/" ForeColor="WindowFrame" CssClass="font-size-progress"></asp:Label><asp:Label ID="Label1" runat="server" Text="Label" CssClass ="font-size-progress" ForeColor="WhiteSmoke"></asp:Label><h1> <asp:Label ID="lblReasonCode" runat="server" Text="Label" ForeColor="White"></asp:Label></h1><p><asp:Label ID="lblTime" runat="server" /></p> </div><br /><%-- <asp:Timer ID="aTimer" runat="server" OnTick="IncreaseCount" Interval="3600000" />--%></ContentTemplate></asp:UpdatePanel></asp:Content>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Configuration;
using System.Data.OleDb;
using System.Web.UI.WebControls;
using System.Web.UI;
using System.Data.SqlClient;
using System.Drawing;
namespace WebApplication1
{
public partial class Progress_ManRoland1 : System.Web.UI.Page
{
DataSet DS = new DataSet();
int pallettqtybyshift = 0;
double[] morningshift = new double[13];
DateTime[] hourtable2 = new DateTime[13];
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
//during first Page Load
lblTime.Text = DateTime.Now.ToString("hh:mm:ss tt");
Label1.Text = GetCurrentShiftPalletteQuantity().ToString();
//Label0.Text = GetPalletteCount_dblcountingmachine().ToString();
}
else
{
//if Postback occurs
//Response.Write("Postback occurs");
}
}
private DataSet GetData(string SPName, SqlParameter SPParameter, SqlParameter SPParameter1)
{
string CS = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
SqlConnection con = new SqlConnection(CS);
SqlDataAdapter da = new SqlDataAdapter(SPName, con);
da.SelectCommand.CommandType = CommandType.StoredProcedure;
if (SPParameter != null)
{
da.SelectCommand.Parameters.Add(SPParameter);
da.SelectCommand.Parameters.Add(SPParameter1);
}
DataSet DS = new DataSet();
da.Fill(DS);
return DS;
}
private DataSet OMplanner(string SPName, SqlParameter SPParameter, SqlParameter SPParameter1)
{
string CS = ConfigurationManager.ConnectionStrings["OMplanner"].ConnectionString;
SqlConnection con1 = new SqlConnection(CS);
SqlDataAdapter da1 = new SqlDataAdapter(SPName, con1);
da1.SelectCommand.CommandType = CommandType.StoredProcedure;
if (SPParameter != null)
{
da1.SelectCommand.Parameters.Add(SPParameter);
da1.SelectCommand.Parameters.Add(SPParameter1);
}
DataSet DS1 = new DataSet();
da1.Fill(DS1);
return DS1;
}
protected void IncreaseCount(object sender, EventArgs e)
{
lblTime.Text = DateTime.Now.ToString("hh:mm:ss tt");
hourtable2 = FillupHourTable();
morningshift = ExpectedTable();
Label0.Text = GetPalletteCount_dblcountingmachine().ToString();
int everytickcount = Convert.ToInt32(Label0.Text);
int expectedtarget;
for (int i = 0; i < hourtable2.Length; i++)
{
expectedtarget = Convert.ToInt32(Math.Round(morningshift[i], 0));
if (DateTime.Now == hourtable2[i])
{
if (everytickcount >= expectedtarget)
{
Label0.ForeColor = Color.Green;
}
else
{
Label0.ForeColor = Color.Red;
}
}
}
}
private int GetCurrentShiftPalletteQuantity()
{
DateTime currenttime = DateTime.Now;
SqlParameter parameter0 = new SqlParameter("@currentdate", currenttime.ToShortDateString());
SqlParameter parameter1 = new SqlParameter("@currenttime", currenttime.ToString("hh:mm:ss tt"));
DataSet DS = GetData("GET_MAN1_CurrentShiftData", parameter0, parameter1);
string reasoncode = DS.Tables[0].Rows[0][1].ToString();
ReasonCode(reasoncode);
double tgt_palletteqtypershift = Convert.ToDouble(DS.Tables[0].Rows[0][0].ToString());
return Convert.ToInt32(Math.Round(tgt_palletteqtypershift, 0));
}
private int GetPalletteCount_dblcountingmachine()
{
DateTime currenttime = DateTime.Now;
SqlParameter machineid = new SqlParameter("@machineid", 3);
SqlParameter timestampdate = new SqlParameter("@currentdate", currenttime.ToString("yyyy-MM-dd"));
DataSet newds = OMplanner("TimeStampdetails", machineid, timestampdate);
int tickcount = Convert.ToInt32(newds.Tables[0].Rows[0][0].ToString());
return tickcount;
}
private void ReasonCode(string code)
{
if(code == "0")
{
lblReasonCode.Text = "Make Ready";
}
else if (code == "1")
{
lblReasonCode.Text = "Active";
}
else if (code == "2")
{
lblReasonCode.Text = "Breakdown";
}
else if (code == "3")
{
lblReasonCode.Text = "Maintenance";
}
else if (code == "4")
{
lblReasonCode.Text = "No Work";
}
else if (code == "5")
{
lblReasonCode.Text = "Plate Change";
}
else if (code == "6")
{
lblReasonCode.Text = "Cycle Service";
}
}
private DateTime[] FillupHourTable()
{
TimeSpan startime_firstshift = new TimeSpan(14, 54, 0);
TimeSpan addhour = new TimeSpan(0, 2, 0 );
DateTime[] hourtable = new DateTime[13];
for (int i = 0; i < hourtable.Length; i++)
{
hourtable[i] = DateTime.Today.Add(startime_firstshift);
//Response.Write(hourtable[i]);
//Response.Write('\n');
startime_firstshift = startime_firstshift + addhour;
}
return hourtable;
}
private double[] ExpectedTable()
{
pallettqtybyshift = GetCurrentShiftPalletteQuantity();
double averageplt_hourly = Math.Round(Convert.ToDouble(pallettqtybyshift) / 12,2);
//Response.Write(averageplt_hourly);
//morningshift = new double[13];
double[] morningshift = new double[13];
for (int i = 0; i < morningshift.Length; i++)
{
if(i == 0)
{
morningshift[i] = 0;
//Response.Write(morningshift[i]);
}
else
{
morningshift[i] = averageplt_hourly + morningshift[i - 1];
//Response.Write(morningshift[i]);
}
//Response.Write('\n');
}
return morningshift;
}
}
}