枚举问题总是值如何?

发布于 2024-08-03 12:31:01 字数 3255 浏览 3 评论 0原文

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

但总是FrameStatus.NormalStatus怎么办?

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;
}

我的完整课程

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;
    }
}
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;
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦幻的心爱 2024-08-10 12:31:01

您没有为 LoadToList 中的 fc.Status 分配任何内容,并且 FrameCam 的“状态”字段的初始化为“FrameStatus.NormalStatus”。如果您更新 LoadToList 中的代码以分配给 fc.status(而不是 this.status,如此处所示),那么它应该按您的预期工作。

附带说明一下,LoadToList 应该是一个静态方法,这可以缓解这个问题。

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.

哽咽笑 2024-08-10 12:31:01

使用调试器。单步执行代码。

该代码没有走您认为它走的路。

如果您不知道如何在调试器中单步执行代码,您必须学习。

对于计算机程序员来说,这不是一项可选技能。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文