我想通过使两个方法公开,然后从另一个类调用方法(请参阅我的代码示例下面)中的WinForm工作进度条。但没有运气,酒吧不动。c#从另一个类的进度条调用方法
这里有两类:
namespace GP_Avantis_Integration
{
//Class B
public partial class GP_Avantis_Integration_Window : Form
{
public GP_Avantis_Integration_Window()
{
InitializeComponent();
}
DataSet ds = new DataSet();
SqlDataAdapter sqlda = new SqlDataAdapter();
SqlCommand sqlcomm = new SqlCommand();
public static int recno;
public void button1_Click(object sender, EventArgs e)
{
try
{
//Fetch data into memory
//Fill in Header table
//Fill in Line table
//Cleaning open connection
//Creating relationship in the Dataset between Header and Line table
// Instantiating and Crearintg Header and Line source
//Binding the Header source to the Header table
//Binding the Line source to the relationship
}
catch (ApplicationException ae)
{
}
finally
{
}
}
public void button2_Click(object sender, EventArgs e)
{
try
{
//Calling CreateJE Class
//Class Method ProcessData
CreateJE JE = new CreateJE(); --------> Calls the Class B
JE.ProcessData(ds);
MessageBox.Show("Complete!");
}
catch (ApplicationException ae)
{
}
finally
{
}
}
public void progress_Bar_setup()
{
progressBar1.Minimum = 0;
progressBar1.Maximum = CreateJE.max;
}
public void progressBar_updates(int recno)
{
progressBar1.Value = recno;
progressBar1.Update();
}
}
// Class B
class CreateJE
{
static public int max;
public void ProcessData (DataSet ds)
{
//Create an eConnect Trx type object
//POPTransactionType po = new POPTransactionType();
// ***** PO Header and Line
int ln;
ln = 0;
//Setting up ProgressBar
int recno = 1;
max = ds.Tables[0].Rows.Count;
GP_Avantis_Integration_Window w = new GP_Avantis_Integration_Window();
w.progress_Bar_setup();
// Create an eConnect PO Header node object
// Create an array for lineitems
foreach (DataRow dtrHDR in ds.Tables["Header"].Rows)
{
//ProgressBar Updates
w.progressBar_updates(recno);
//Instantiating GetJE object
//Retrieves the next JE from GP
//Create an eConnect PO Header node object
//Add the header node to the trx type object
ln = 0;
foreach (DataRow dtrLine in dtrHDR.GetChildRows("HdrLine"))
{
// Populate the elements of the taPoLIne_ItemsTaPOLine XML node
//Avantis Inv Trx Key
// Avantis GL Trx Type
//Add POLine to an Array
ln ++;
}
// Add the header node to the trx type object
// Add the lineitem node to the trx type object
// ***** Process information only
// Create an eConnect document object
// Create a file on the HD
// Serialize using the XmlTextWriter to the file
// Call the eConnectMethods
// Separate Class
// Instantiating the object for eConnectMethods class
// Passing last JRNENTRY retreived using the GetJE class
// so if there is an error on the eConnectEntry Method of eConnectMethods Class
// I can pass the last JE number back to GP
recno++;
}
}
}
}
出了什么问题? progessbar1.value是否在调试时更改?如果是这样,你可能需要在后台线程中启动foreach循环。 – IanGilham
您将无法通过使用对进度栏的引用来调用连接到B类的属性或方法。发布实际的代码,您的示例代码,甚至不是有效的代码。此时,除非您发布实际可编译的代码,否则您无法获得帮助,请详细解释哪些内容无效。 –
我在设置min = 0,max = 2。将1和2的值传递给progressbar1.update()方法,并在类B中使用foreach循环。调试时,我可以看到要传递的值。进度条(可视化)不移动。 – Shazam