我有一个名为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
的新成员答案 0 :(得分:1)
您需要将WpfsoftwareMonitoring.views
命名空间添加到您的类文件
示例:
using WpfsoftwareMonitoring.views
namespace WpfsoftwareMonitoring
{
class SoftwareRosterClass
{
..............