【发布时间】:2014-06-27 07:35:50
【问题描述】:
所以我的应用程序中有两个页面。 我还有一个 MySQL 类,其中包含要执行的连接参数和查询。 问题是,我需要两个页面在类中使用相同的方法并将数据返回到触发它的表单。
这种方式一页就够用了,就是不知道怎么用两页或多页。
//MySQL Library
using MySql.Data.MySqlClient;
using MySql.Data;
namespace Masca.users.MySQL
{
public class registrationSQL
{
// The SQL class now knows about the registration page
public users.RegistrationPages.registrationForm Registration;
// The SQL class now knows about the registration Form and datagrid page
public users.RegistrationPages.registrationFormGrid RegistrationFormGrid;
这是我希望全局访问的方法。
// I guess this part is what I cant figure out
// This is where you set where it's supposed to ruturn the strings right?
// Well What I don't get is how you add another page to return strings to if it calls the method.
public void foward (users.RegistrationPages.registrationForm RegistrationForm)
{
//Declarations
string datasource = "localhost";
string port = "3306";
string username = "root";
string password = "Password";
//Connection
string sqlcon = "datasource = " + datasource + ";" + "port=" + port + ";" + "username=" + username + ";" + "password=" + password + ";";
//Query
string query = "select * from temp.signup where tag = (select min(tag) from temp.signup where tag > '" + RegistrationForm.tag.Text + "' );";
//MySQL declarations
MySqlConnection con = new MySqlConnection(sqlcon);
MySqlCommand cmd = new MySqlCommand(query, con);
MySqlDataReader rdr;
//Excecution
try
{
//If the connection is Open
con.Open();
{
rdr = cmd.ExecuteReader();
while (rdr.Read())
{
//String population
// GetString & GetColumnValueAsString are predefined functions
// They check if a field is null or an integer before returning it as a string
string sid = GetString(rdr, "id");
string smember = GetColumnValueAsString(rdr, "member");
string stag = GetColumnValueAsString(rdr, "tag");
string sfirst = GetString(rdr, "first");
string ssecond = GetString(rdr, "second");
string sthird = GetString(rdr, "third");
string sfourth = GetString(rdr, "surname");
string sdob = rdr.GetString("dob");
string ssex = rdr.GetString("sex");
string susername = GetString(rdr, "username");
string spassword = GetString(rdr, "password");
string ssecurity = GetString(rdr, "question");
string sanswer = GetString(rdr, "answer");
string spemail = GetString(rdr, "pemail");
string swemail = GetString(rdr, "wemail");
string sdoc = rdr.GetString("doc");
string scell = GetString(rdr, "cell");
string shome = GetString(rdr, "home");
string sext = GetColumnValueAsString(rdr, "ext");
string sstreet = GetString(rdr, "street");
string ssurbub = GetString(rdr, "surbub");
string scity = GetString(rdr, "city");
string sregion = GetString(rdr, "region");
string sdept = rdr.GetString("dept");
string sbank = GetString(rdr, "bank");
string sbranch = GetString(rdr, "branch");
string saccount = GetString(rdr, "account");
// Bindings
// This is another thing
// If another page calls this method besides the 'RegistrationForm'
// How am I to direct the strings to that one instead of 'RegistrationForm'
RegistrationForm.id.Text = sid;
RegistrationForm.member.Text = smember;
RegistrationForm.tag.Text = stag;
RegistrationForm.first.Text = sfirst;
RegistrationForm.second.Text = ssecond;
RegistrationForm.third.Text = sthird;
RegistrationForm.surname.Text = sfourth;
RegistrationForm.dob.Text = sdob;
RegistrationForm.sex.Text = ssex;
RegistrationForm.username.Text = susername;
RegistrationForm.password.Text = spassword;
RegistrationForm.question.Text = ssecurity;
RegistrationForm.answer.Text = sanswer;
RegistrationForm.pemail.Text = spemail;
RegistrationForm.wemail.Text = swemail;
RegistrationForm.doc.Text = sdoc;
RegistrationForm.cell.Text = scell;
RegistrationForm.home.Text = shome;
RegistrationForm.ext.Text = sext;
RegistrationForm.street.Text = sstreet;
RegistrationForm.surbub.Text = ssurbub;
RegistrationForm.city.Text = scity;
RegistrationForm.region.Text = sregion;
RegistrationForm.dept.Text = sdept;
RegistrationForm.bank.Text = sbank;
RegistrationForm.branch.Text = sbranch;
RegistrationForm.account.Text = saccount;
}
// Close the connection
con.Close();
}
}
catch (Exception ex)
{
ModernDialog.ShowMessage(ex.Message , "SQL related error", MessageBoxButton.OK);
}
}
这就是我在“registrationForm”中调用此方法的方式
private void next_Click(object sender, RoutedEventArgs e)
{
RegistratonSql.foward(this);
}
这基本上是为了允许使用页面中的文本框浏览记录。 有什么线索可以解决这个问题吗?
【问题讨论】: