【发布时间】:2014-01-30 17:22:00
【问题描述】:
我正在开发库存软件。在此软件中,当用户按下 Ctrl+Space 按钮时,系统将打开一个显示所有产品列表的表单 (frmProducts.cs)。在此表单上,用户可以按名称搜索产品,从该表单中选择产品,然后按“选择”按钮。所选产品将与产品代码一起显示在销售发票产品名称文本框中。
现在,当用户选择产品程序打开一个新的销售发票表单并且不将数据加载到旧表单中时,就会出现问题。程序应该显示已经打开的表格并填写了数据。
我写的打开产品信息的代码是:
private void txtProductCode1_KeyDown(object sender, KeyEventArgs e)
{
if (e.Control && e.KeyCode == Keys.Space)
{
// frm4.Instance.Show();
frmProducts cs = new frmProducts();
cs.Show();
}
}
我在 frmProducts 选择按钮上写的代码是:
int ItemNo;
string sql;
if (lvProducts.SelectedItems.Count == 0)
{
MessageBox.Show("Please Select Atleast one Column", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
ItemNo = Convert.ToInt32(lvProducts.SelectedItems[0].Text.ToString());
sql = "";
sql += "SELECT * FROM ProductLog WHERE ProductLog.ItemNo = " + ItemNo + "";
SqlConnection cn = new SqlConnection();
SqlCommand rs = new SqlCommand();
SqlDataReader sdr = null;
clsConnection clsCon = new clsConnection();
clsCon.fnc_ConnectToDB(ref cn);
rs.Connection = cn;
rs.CommandText = sql;
sdr = rs.ExecuteReader();
this.Close();
frmSaleInvoice frm = new frmSaleInvoice(ref sdr);
frm.ShowDialog();
sdr.Close();
rs = null;
cn.Close();
}
frminvoice 中捕获数据的代码是:
public frmSaleInvoice(ref SqlDataReader sdr)
{
InitializeComponent();
while (sdr.Read())
{
txtProductCode1.Text = Convert.ToString(sdr["ProductCode"]);
}
}
我也在“选择”按钮上尝试了此代码,但它只是没有将任何内容加载到销售发票中:
frmSaleInvoice frm = new frmSaleInvoice(ref sdr);
if (frm.Visible)
{
frm.BringToFront();
}
也试过了
frmSaleInvoice frm = new frmSaleInvoice(ref sdr);
frmSaleInvoice.Instance.Show();
我也尝试用frmSaleInvoice.Instance.Show(); 传递值,但它不允许我传递像frmSaleInvoice.Instance.Show(ref sdr); 这样的数据
请帮帮我,我真的被困在里面了。
- 要么告诉我如何通过实例传递值
- 或任何其他方式来做到这一点?
任何建议将不胜感激。!
【问题讨论】:
标签: c# mysql .net winforms reference