tags:

views:

131

answers:

2
public enum FrameStatus
{
    NotReport = 0,
    NormalStatus = 1,
    NotNormalstatus = 2
}

but alway FrameStatus.NormalStatus how?

public FrameStatus FrameReportStatus(int Framid, string Timebet)
{
    foreach (FrameCam fc in al)
    {
        if (fc.Timebet == Timebet && fc.IdFrame == Framid)
        {
           if ((int)fc.status == 1) fc.status = FrameStatus.NormalStatus;
           else if ((int)fc.status == 2) fc.status = FrameStatus.NotNormalstatus;
           else fc.status = FrameStatus.NotReport;
           return fc.status;
        }
    }
    return FrameStatus.NotReport;
}

my complete classs

class FrameCam
{
    private ArrayList al = new ArrayList();
    public string strConnect;

    public FrameStatus status = FrameStatus.NormalStatus;
    public string Timebet;
    public int IdFrame;

    public FrameCam()
    {

    }
    public FrameCam(string st, string bt)
    {
        strConnect = st;
        Timebet = bt;
        LoadtoList();
    }

    public FrameStatus GetFramStatus(int Framid, string timebet)
    {
        foreach (FrameCam fc in al)
        {
            if (Framid == fc.IdFrame && timebet == fc.Timebet)
            {
                return fc.status;
            }
        }
        return FrameStatus.NotReport;
    }
    private void LoadtoList()
    {
        SqlConnection conn = null;
        SqlDataReader sr = null;
        try
        {
            string query =
                "SELECT * FROM FrameReport WHERE convert(varchar, GETDATE(), 101) = convert(varchar, DateTimeSign, 101) AND TimeSignBeetWeen='" +this.Timebet+"'";

            conn = new SqlConnection(this.strConnect);
            conn.Open();
            SqlCommand sc = new SqlCommand();
            sc.CommandText = query;
            sc.Connection = conn;
            sr = sc.ExecuteReader();
            while (sr.Read())
            {
                FrameCam fc = new FrameCam();
                fc.Timebet = sr["TimeSignBeetWeen"].ToString();
                fc.IdFrame = (int)sr["IdFrame"];
                if ((int)sr["Status"] == (int)FrameStatus.NormalStatus)
                {
                    status = FrameStatus.NormalStatus;
                }
                if ((int)sr["Status"] == (int)FrameStatus.NotNormalstatus)
                {
                    status = FrameStatus.NotNormalstatus;
                }
                else status = FrameStatus.NotReport;

                al.Add(fc);
            }
        }
        catch (Exception)
        {
        }
        finally
        {
            if (sr != null) sr.Close();
            if (conn != null) conn.Close();
        }
    }

    public FrameStatus FrameReportStatus(int Framid, string Timebet)
    {
        foreach (FrameCam fc in al)
        {
            if (fc.Timebet == Timebet && fc.IdFrame == Framid)
            {
                if ((int)fc.status == 1) fc.status = FrameStatus.NormalStatus;
                else if ((int)fc.status == 2) fc.status = FrameStatus.NotNormalstatus;
                else fc.status = FrameStatus.NotReport;
                return fc.status;
            }
        }
        return FrameStatus.NotReport;
    }
}
+1  A: 

You're not assigning anything to fc.Status within LoadToList and the initialize for FrameCam's 'status' field is "FrameStatus.NormalStatus". If you update the code in LoadToList to assign to fc.status (instead of this.status, as is shown here) then it should work as you expect.

As a side note, LoadToList should be a static method, which would have mitigated this problem.

Shaun Wilson
A: 

Use a debugger. Step through the code.

The code is not taking the path you think it is taking.

If you do not know how to step through code in a debugger, you MUST learn.

This is not an optional skill for a computer programmer.

abelenky