所以我有 5 个按钮可以将可见性设置为 false。但是我不能在设计师的课堂上做,我需要在这个课堂上做。我不确定我是否应该通过按钮或者是否有更好的方法?但这是数据网格加载的地方
public static void CostSQL(string connstring, string passableQuery, IEdmVault7 vault, int ID, IEdmFolder5 Folder)
{
try
{
SqlConnection con = new SqlConnection(connstring);
con.Open();
//concat later to optimize code for universal use by passing variable quote
SqlCommand cmd = new SqlCommand(passableQuery, con);
DataTable rTbl = new DataTable();
rTbl.Load(cmd.ExecuteReader());
SQLResultSelector RSel = new SQLResultSelector(rTbl, vault, ID, "c", Folder);
RSel.ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show("Something happend during your connection to SQL error : " + ex.Message);
}
}
考虑一个事件,如果满足条件,则设置按钮的可见性。
一个概念性的例子,根据 if weekday 传递 true 或 false。
internal class SomeClass
{
public delegate void OnCondition(bool condition);
public static event OnCondition Condition;
public static void CostSql()
{
Condition?.Invoke(DateTime.Now.DayOfWeek is not
(DayOfWeek.Sunday or DayOfWeek.Saturday));
}
}
然后在表单中订阅事件,也许在表单加载中。
SomeClass.Condition += SomeClass_Condition;
事件中的代码,决定做什么...
private void SomeClass_Condition(bool condition)
{
// here is where you set visibility of buttons
if (condition)
{
}
else
{
}
}
问题是这个班级已经被称为
RSel
所以当我用全名打电话时它会抛出错误。我将 clearbutton
方法放在设计器类中,然后使用 rsel.clearbutton();
正确调用它并且它有效
public static void CostSQL(string connstring, string passableQuery, IEdmVault7 vault, int ID, IEdmFolder5 Folder)
{
try
{
SqlConnection con = new SqlConnection(connstring);
con.Open();
//concat later to optimize code for universal use by passing variable quote
SqlCommand cmd = new SqlCommand(passableQuery, con);
DataTable rTbl = new DataTable();
RSel.ClearButtons();
rTbl.Load(cmd.ExecuteReader());
SQLResultSelector RSel = new SQLResultSelector(rTbl, vault, ID, "c", Folder);
RSel.ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show("Something happend during your connection to SQL error : " + ex.Message);
}
}