[英]Refreshing one form on close of another or via a button click on another form
My program allows the user to edit the data in a database. 我的程序允许用户编辑数据库中的数据。 This works by showing the user the "product" on one form and then asks them to insert the correct amount of stock on another.
这通过在一种形式上向用户显示“产品”,然后要求他们在另一种形式上插入正确数量的库存来起作用。
I am trying to make it so that the first form with the "product" is refreshed to show the amended numbers from the second form with either the closure of the second or via a button click on the second. 我正在尝试使带有“产品”的第一个表格刷新,以显示第二个表格的修改数字,或者关闭第二个表格或通过单击第二个按钮。
I unfortunately have no knowledge of how to do this. 不幸的是,我不知道如何执行此操作。
I know that it's not: 我知道不是:
frm1 f1 = new frm1(this);
f1.Show();
Code for amend form: 修改形式代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace InventoryManager
{
public partial class frmAdjustment : Form
{
frmAmendStock _main;
public string enteredSKU { get; set; }
public frmAdjustment(frmAmendStock main)
{
InitializeComponent();
_main = main;
}
private void frmAdjustment_Load(object sender, EventArgs e)
{
this.AcceptButton = btnSubmit;
}
private void btnCancel_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnSubmit_Click(object sender, EventArgs e)
{
using (OleDbConnection connect = new OleDbConnection())
{
connect.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Other\Documents\University Work\USB\Individual Project\Artefact\InventoryManager\InventoryManager\stock.mdb";
connect.Open();
OleDbCommand cmd = new OleDbCommand("UPDATE items SET Stock = @stock, Stock_Counted = @counted WHERE SKU LIKE '" +enteredSKU+"'", connect);
string units = txtAmount.Text;
if (connect.State == ConnectionState.Open)
{
if (string.IsNullOrEmpty(units))
{
MessageBox.Show("Please enter the correct amount of units.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
cmd.Parameters.Add("@stock", OleDbType.Integer, 5).Value = txtAmount.Text;
cmd.Parameters.Add("@counted", OleDbType.Integer, 5).Value = txtAmount.Text;
try
{
cmd.ExecuteNonQuery();
MessageBox.Show("Stock Adjusted", "Saved", MessageBoxButtons.OK, MessageBoxIcon.Information);
txtAmount.Clear();
connect.Close();
this.Close();
}
catch (Exception expe)
{
MessageBox.Show(expe.ToString());
connect.Close();
}
}
}
else
{
MessageBox.Show("Connection Failed");
}
}
}
}
}
Example :` 例子:
if (f1.ShowDialog(this) == DialogResult.OK){
var stock = f1.Stock;
}
Makes sense ? 说得通 ?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.