枚举问题总是值如何?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您没有为 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.
使用调试器。单步执行代码。
该代码没有走您认为它走的路。
如果您不知道如何在调试器中单步执行代码,您必须学习。
对于计算机程序员来说,这不是一项可选技能。
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.