c#大文件读取和写入数据库(带进度条的源代码)

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

protected int state = 0; //表示进度条当前处理的事件类型,1表读取word,2表写入word,3表doc转pdf,4表txt转pdf

private System.Windows.Forms.Form getDialog(string strFormName,System. Drawing.Icon ico,string strShowContent)

{

System.Windows.Forms.Form frm = new Form();

//初始化窗体

frm.Text = strFormName;

frm.Icon = ico;

frm.MaximizeBox = false;

frm.MinimizeBox = false;

frm.TopMost = true;

frm.ShowInTaskbar = false;

frm.Height = 168;

frm.Width = 544;

frm.StartPosition = System.Windows.Forms.FormStartPosition.CenterScree n;

//添加控件

bel lblContent = new Label();

lblContent.Text = strShowContent;

lblContent.Left = 30;

lblContent.Top = 20;

lblContent.Text = strShowContent;

frm.Controls.Add(lblContent);

System.Windows.Forms.ProgressBar prgLoader = new ProgressBar(); prgLoader.Left=30;

prgLoader.Top = lblContent.Top + lblContent.Height + 5;

prgLoader.Width = frm.Width - 2 * 30;

frm.Controls.Add(prgLoader);

bel lblShowPercent = new Label();

lblShowPercent.TextAlign = System.Drawing.ContentAlignment.MiddleRight; lblShowPercent.Left = prgLoader.Width + 30 - lblShowPercent.Width;

lblShowPercent.Top = prgLoader.Height + prgLoader.Top + 5;

lblShowPercent.Text = prgLoader.Value.ToString() + "%";

= "lblShowPercent";

frm.Controls.Add(lblShowPercent);

System.Windows.Forms.Button btnOK = new Button();

btnOK.Text = "取消";

btnOK.Left = prgLoader.Width + 30 - btnOK.Width;

btnOK.T op = frm.Height - 30 - btnOK.Height;

btnOK.Click +=new EventHandler(btnOk_Click);

frm.Controls.Add(btnOK);

return frm;

}

private void btnOk_Click(object sender,System.EventArgs e)

{

//获取控件信息

System.Windows.Forms.Button btnOk = (System.Windows.Forms.Button)se nder;

System.Windows.Forms.Form frm = (System.Windows.Forms.Form)btnOk .Parent;

System.Windows.Forms.ProgressBar prgLoader = null;

foreach(System.Windows.Forms.Control control in frm.Controls)

{

if(control.GetType().ToString() == "System.Windows.Forms.ProgressBar") {

prgLoader = (System.Windows.Forms.ProgressBar)control;

}

}

//判断当前的完成情况

if(prgLoader.Value == 100)

{

frm.Close();

}

else

{

System.Windows.Forms.DialogResult dr = MessageBox.Show(frm,"是否停止当前操作?","提示",System.Windows.Forms.MessageBoxButtons.YesNo,

System.Windows.Forms.MessageBoxIcon.Warning);

if(dr == System.Windows.Forms.DialogResult.Yes)

{

state = 0;

frm.Close();

}

}

}

///

///写入word到数据库

///

///sql连接类

///直接将目标内容写入数据库的sql,

相关文档
最新文档