功能**
private void GetComboxItems(params int[] type)
{
try
{
/* DEPARTMENT CODE */
if (type[0] == 1)
{
cmbDept.Items.Clear();
using (SFCDataContext SFC = new SFCDataContext())
{
var Dept = (from i in SFC.Systems_SettingsDepartments
orderby i.Department_ID
select i);
foreach (var q in Dept)
{
cmbDept.Items.Add(q.Department_ID);
}
SFC.Connection.Close();
}
}
/* CORRECTIVE ACTION RECORD CODE */
if (type[1] == 1)
{
cmbCARNo.Items.Clear();
using (SFCDataContext SFC = new SFCDataContext())
{
var CarNo = (from i in SFC.Systems_CARLogSheets
orderby i.CARDocNo
where i.PostStatus == 0
select new
{
Code = i.CARDocNo
});
foreach (var w in CarNo)
{
cmbCARNo.Items.Add(w.Code);
}
SFC.Connection.Close();
}
}
/* MEASUREMENT CODE */
if (type[2] == 1)
{
cmbMeas.Items.Clear();
using (SFCDataContext SFC = new SFCDataContext())
{
var Measure = (from i in SFC.Systems_SettingsMeasurements
orderby i.Measurement_ID
where i.CategoryType == "Measurement"
select new
{
DESC = i.Measurement
});
foreach (var e in Measure)
{
cmbMeas.Items.Add(e.DESC);
}
SFC.Connection.Close();
}
}
/* SUB-MEASUREMENT CODE */
if (type[3] == 1)
{
cmbSubMeas.Items.Clear();
using (SFCDataContext SFC = new SFCDataContext())
{
var SubMeas = (from i in SFC.Systems_SettingsMeasurements
orderby i.Measurement_ID
where i.CategoryType == "Sub-Measurement"
select new
{
DESC = i.Measurement
});
foreach (var r in SubMeas)
{
cmbSubMeas.Items.Add(r.DESC);
}
SFC.Connection.Close();
}
}
}
catch (Exception ex)
{ MessageBox.Show(ex.Message.ToString()); }
}
* FORM LOAD **
private void frmSQMProductivityReports_Load(object sender, EventArgs e)
{
GetComboxItems(1, 0, 1, 0);
}
为什么在这个代码中...我的第一个if语句是“True”所以它在if语句中的代码之后执行,它确实如此。现在第二个if语句是“False”,它跳过它里面的函数。但是现在第3个if语句是“True”,它应该与第1个相同,但是我已经检查了几次它跳过if语句中的函数为什么呢?在我的代码中有什么问题我尝试看它对我来说似乎没问题。
答案 0 :(得分:1)
根据您的输入,符合条件的if
条件是第一个和第三个。请注意,如果抛出异常,某些语句可以被“跳过”,因此在那里放置断点或打印日志可能帮助您更好地了解正在发生的事情。
附注:
params
的使用似乎是多余的(它主要用于应该传递未知的#arguments),因为参数的数量是固定的。bool
类型而不是int for flags