我有一个名为 SoftwareRosterForm 的表单:
namespace WpfsoftwareMonitoring.views
{
public partial class SoftwareRosterForm : Window
{
public SoftwareRosterForm()
{
InitializeComponent();
}
}
}
和一个 SoftwareRosterClass:
namespace WpfsoftwareMonitoring
{
class SoftwareRosterClass
{
ConnectionManager DatabaseConnect = new ConnectionManager();
DataSet SoftwareData = new DataSet();
public void AddSoftwareFunction(SoftwareRosterForm SoftwareRosterPage)
{
if (SoftwareRosterPage.SoftName_txtbox.Text == "" || SoftwareRosterPage.SoftType_cmbbox.Text == "")
{
MessageBox.Show("Complete all the fields.");
}
else
{
DatabaseConnect.StringQuery = "SELECT * FROM SoftwareList_tbl WHERE Software_name = '" + SoftwareRosterPage.SoftName_txtbox.Text + "'";
DatabaseConnect.GetData();
if (DatabaseConnect.SQLDR.HasRows == true)
{
DatabaseConnect.SQLDR.Close();
SoftwareRosterPage.SoftName_txtbox.SelectAll();
MessageBox.Show("Software already exist.");
}
else
{
DatabaseConnect.SQLDR.Close();
DatabaseConnect.StringQuery = "INSERT INTO SoftwareList_tbl (Software_name, Software_type) VALUES ('" + SoftwareRosterPage.SoftName_txtbox.Text + "', '" + SoftwareRosterPage.SoftType_cmbbox.Text + "')";
DatabaseConnect.InsertData();
MessageBox.Show("Software added.");
DatabaseConnect.SQLDR.Close();
ClearFormFields(SoftwareRosterPage);
FilterSoftwareList(SoftwareRosterPage);
SoftwareRosterPage.SoftName_txtbox.Focus();
}
}
}
public void FilterSoftwareList(SoftwareRosterForm SoftwareRosterPage)
{
//SoftList_lstview.Items.Clear();
DatabaseConnect.StringQuery = "SELECT Software_name, Software_type FROM SoftwareList_tbl";
DatabaseConnect.GetData();
DatabaseConnect.SQLDR.Close();
//Fills the temporary table with the selected data and fills the list view
DatabaseConnect.SQLDA.Fill(SoftwareData);
SoftwareRosterPage.SoftList_lstview.DataContext = SoftwareData.Tables[0].DefaultView;
DatabaseConnect.SQLDR.Close();
}
public void ClearFormFields(SoftwareRosterForm SoftwareRosterPage)
{
SoftwareRosterPage.SoftName_txtbox.Clear();
SoftwareRosterPage.SoftType_cmbbox.SelectedIndex = -1;
}
}
}
我尝试在 public void AddSoftwareFunction(SoftwareRosterForm SoftwareRosterPage)
方法中传递 SoftwareRosterForm 但出现错误:
找不到类型或命名空间名称“SoftwareRosterForm”(您是否缺少 using 指令或程序集引用?)
但是当我在命名空间中删除“视图”时WpfsoftwareMonitoring.Views
,错误不会发生,而是出现了另一个错误:
当前上下文中不存在名称“InitializeComponent”
任何想法?我将表单放在 Views 文件夹中,我尝试删除文件夹中的表单,效果很好,但我需要将表单放在文件夹中以保持整洁
我只是一名大学生,是 c# 和 wpf 的新手