我有一个能够生成大量文本文件的程序,当程序执行生成文本文件的线程时,我希望在表单上加载动画。这就是为什么我决定在谷歌下载.gif加载图像并在程序执行命令之前显示它。但它没有表现出来。你能帮忙解决这个问题吗?它只是最小的但我无法解决它。提前谢谢
private void btn_Generate_Click(object sender, EventArgs e)
{
pic_Loading.Visible = true;
if ((dt_To.Value - dt_From.Value).TotalDays >= 0)
{
for (var day = dt_From.Value; day <= dt_To.Value; day = day.AddDays(1))
{
string path = txt_path.Text + @"\" + day.ToString("yyyy");
BLL.CreateFolder.CreateNewFolder(path);
if (chk_txtFile.Checked == true)
{
BLL.InsertData.InsertDailySales(txt_Server.Text, cbo_Databasename.Text, txt_Uname.Text, txt_Password.Text, day.ToString("yyyy/MM/dd"), txt_texttenant.Text, txt_StoreKey.Text, "p_Aya_insert_daily");
BLL.InsertData.InsertDailySales(txt_Server.Text, cbo_Databasename.Text, txt_Uname.Text, txt_Password.Text, day.ToString("yyyy/MM/dd"), txt_texttenant.Text, txt_StoreKey.Text, "p_AYA_insert_hourly_First");
BLL.InsertData.InsertDailySales(txt_Server.Text, cbo_Databasename.Text, txt_Uname.Text, txt_Password.Text, day.ToString("yyyy/MM/dd"), txt_texttenant.Text, txt_StoreKey.Text, "p_AYA_insert_hourly_Sec");
BLL.PopulateData.LoadToDatagrid(txt_Server.Text, cbo_Databasename.Text, txt_Uname.Text, txt_Password.Text, "Select * from DAILY", dg_DailySales);
BLL.PopulateData.LoadToDatagrid(txt_Server.Text, cbo_Databasename.Text, txt_Uname.Text, txt_Password.Text, "Select * from HOURLY", dg_Hourly);
BLL.ExportData.ExportDaiySales(dg_DailySales, path + @"\" + txt_textContract.Text + day.ToString("MMdd"));
BLL.ExportData.ExportHourlySales(dg_Hourly, path + @"\" + txt_textContract.Text + day.ToString("MMdd"));
}
if (chk_DBF.Checked == true)
{
BLL.InsertData.InsertDailySales(txt_Server.Text, cbo_Databasename.Text, txt_Uname.Text, txt_Password.Text, day.ToString("yyyy/MM/dd"), txt_DBFTenantName.Text, txt_StoreKey.Text, "p_AYA_insertintodailydbf");
BLL.PopulateData.LoadToDatagrid(txt_Server.Text, cbo_Databasename.Text, txt_Uname.Text, txt_Password.Text, "Select * from DailyDBF", dg_DBFDaily);
BLL.InsertData.InsertDailySales(txt_Server.Text, cbo_Databasename.Text, txt_Uname.Text, txt_Password.Text, day.ToString("yyyy/MM/dd"), txt_DBFTenantName.Text, txt_StoreKey.Text, "p_AYA_InsertHourly_DBF1");
BLL.InsertData.InsertDailySales(txt_Server.Text, cbo_Databasename.Text, txt_Uname.Text, txt_Password.Text, day.ToString("yyyy/MM/dd"), txt_DBFTenantName.Text, txt_StoreKey.Text, "p_AYA_InsertHourly_DBF2");
BLL.PopulateData.LoadToDatagrid(txt_Server.Text, cbo_Databasename.Text, txt_Uname.Text, txt_Password.Text, "Select * from HourlyDBF", dg_DBFHourly);
string Fields = "TRANDATE D, OLDGT N(15,2), NEWGT N(15,2), DLYSALE N(15,2), TOTDISC N(15,2), TOTREF N(15,2), TOTCAN N(15,2), VAT N(15,2), TENTNAME C(50), BEGINV I, " +
" ENDINV N(11), BEGOR N(11), ENDOR N(11), TRANCNT N(11), LOCALTX N(15,2), SERVCHARGE N(15,2), NOTAXSALE N(15,2), RAWGROSS N(15,2), DLYLOCTAX N(15,2), OTHERS N(11), TERMNUM C(50)";
BLL.CreateDBF.CreateDBFile(path, txt_DBFTenantCode.Text + day.ToString("MMdd"), Fields);
string Hourly = "TRANDATE D, HOUR C(50), SALES N(15,2), TRANCNT N(11), TENTNAME C(50), TERMNUM C(50)";
BLL.CreateDBF.CreateDBFile(path, txt_DBFTenantCode.Text + day.ToString("MMdd") + "H", Hourly);
BLL.InsertToDBF.InsertData(path, dg_DBFDaily, txt_DBFTenantCode.Text + day.ToString("MMdd"));
BLL.InsertToDBF.Hourly(path, dg_DBFHourly, txt_DBFTenantCode.Text + day.ToString("MMdd") + "H");
}
}
MessageBox.Show("Success!");
pic_Loading.Visible = false;
}
else
{
MessageBox.Show("Invalid Date");
}
}
答案 0 :(得分:0)
我终于做到了。我用过BackgroudWorker。谢谢你的帮助。