KDataOut.cs
上传用户:chizxy
上传日期:2014-11-29
资源大小:407k
文件大小:7k
- using System;
- using System.Drawing;
- using System.Collections;
- using System.ComponentModel;
- using System.Windows.Forms;
- using System.Data;
- using System.Data.SqlClient;
- using System.Threading;
- namespace MKIms3
- {
- /// <summary>
- /// KDataOut 的摘要说明。
- /// </summary>
- public class KDataOut : System.Windows.Forms.Form
- {
- private Excel._Application _myExcel;
- static Thread MyOutThread = null;
- private System.Windows.Forms.Label label1;
- private System.Windows.Forms.Label label2;
- private System.Windows.Forms.Label label3;
- private System.Windows.Forms.Button btn_out;
- private System.Windows.Forms.ProgressBar progressBar_now;
- private System.Windows.Forms.ProgressBar progressBar_all;
- private System.Windows.Forms.PictureBox pictureBox1;
- /// <summary>
- /// 必需的设计器变量。
- /// </summary>
- private System.ComponentModel.Container components = null;
- public KDataOut()
- {
- //
- // Windows 窗体设计器支持所必需的
- //
- InitializeComponent();
- //
- // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
- //
- }
- /// <summary>
- /// 清理所有正在使用的资源。
- /// </summary>
- protected override void Dispose( bool disposing )
- {
- if( disposing )
- {
- if(components != null)
- {
- components.Dispose();
- }
- }
- base.Dispose( disposing );
- }
- #region Windows 窗体设计器生成的代码
- /// <summary>
- /// 设计器支持所需的方法 - 不要使用代码编辑器修改
- /// 此方法的内容。
- /// </summary>
- private void InitializeComponent()
- {
- System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(KDataOut));
- this.label1 = new System.Windows.Forms.Label();
- this.label2 = new System.Windows.Forms.Label();
- this.progressBar_now = new System.Windows.Forms.ProgressBar();
- this.progressBar_all = new System.Windows.Forms.ProgressBar();
- this.label3 = new System.Windows.Forms.Label();
- this.btn_out = new System.Windows.Forms.Button();
- this.pictureBox1 = new System.Windows.Forms.PictureBox();
- this.SuspendLayout();
- //
- // label1
- //
- this.label1.Location = new System.Drawing.Point(128, 9);
- this.label1.Name = "label1";
- this.label1.Size = new System.Drawing.Size(72, 23);
- this.label1.TabIndex = 0;
- this.label1.Text = "当前进度:";
- this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
- //
- // label2
- //
- this.label2.Location = new System.Drawing.Point(125, 56);
- this.label2.Name = "label2";
- this.label2.Size = new System.Drawing.Size(61, 23);
- this.label2.TabIndex = 1;
- this.label2.Text = "总进度:";
- this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
- //
- // progressBar_now
- //
- this.progressBar_now.Location = new System.Drawing.Point(136, 32);
- this.progressBar_now.Name = "progressBar_now";
- this.progressBar_now.Size = new System.Drawing.Size(240, 21);
- this.progressBar_now.TabIndex = 2;
- //
- // progressBar_all
- //
- this.progressBar_all.Location = new System.Drawing.Point(136, 80);
- this.progressBar_all.Name = "progressBar_all";
- this.progressBar_all.Size = new System.Drawing.Size(240, 21);
- this.progressBar_all.TabIndex = 3;
- //
- // label3
- //
- this.label3.Location = new System.Drawing.Point(136, 120);
- this.label3.Name = "label3";
- this.label3.Size = new System.Drawing.Size(160, 48);
- this.label3.TabIndex = 4;
- this.label3.Text = " 说明:导出完毕,请按照提示保存导出的xsl文件。";
- //
- // btn_out
- //
- this.btn_out.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
- this.btn_out.Location = new System.Drawing.Point(310, 120);
- this.btn_out.Name = "btn_out";
- this.btn_out.Size = new System.Drawing.Size(56, 40);
- this.btn_out.TabIndex = 5;
- this.btn_out.Text = "数据 导出";
- this.btn_out.Click += new System.EventHandler(this.btn_out_Click);
- //
- // pictureBox1
- //
- this.pictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
- this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
- this.pictureBox1.Location = new System.Drawing.Point(-8, -24);
- this.pictureBox1.Name = "pictureBox1";
- this.pictureBox1.Size = new System.Drawing.Size(136, 200);
- this.pictureBox1.TabIndex = 6;
- this.pictureBox1.TabStop = false;
- //
- // KDataOut
- //
- this.AcceptButton = this.btn_out;
- this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
- this.ClientSize = new System.Drawing.Size(384, 178);
- this.Controls.Add(this.pictureBox1);
- this.Controls.Add(this.btn_out);
- this.Controls.Add(this.label3);
- this.Controls.Add(this.progressBar_all);
- this.Controls.Add(this.progressBar_now);
- this.Controls.Add(this.label2);
- this.Controls.Add(this.label1);
- this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
- this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
- this.Name = "KDataOut";
- this.ShowInTaskbar = false;
- this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
- this.Text = "所有钻孔属性数据导出";
- this.Closing += new System.ComponentModel.CancelEventHandler(this.KDataOut_Closing);
- this.Load += new System.EventHandler(this.KDataOut_Load);
- this.ResumeLayout(false);
- }
- #endregion
-
- private void import_excel()
- {
- DataBase myDB = new DataBase();
- DataSet myset;
- myset = myDB.RunProcedure("up_putout_all","all");
- if(myset!=null)
- {
- int n =myset.Tables["all"].Columns.Count;
- this.progressBar_now.Value = 0;
- this.progressBar_now.Maximum = n;
- this.progressBar_all.Value = 0;
- this.progressBar_all.Maximum = myset.Tables["all"].Rows.Count;
- int j=0;
- for(int m=0;m<n;m++)
- {
- this._myExcel.Cells[1,m+1]=myset.Tables[0].Columns[m].ColumnName.ToString();
- }
- for(j=0;j<myset.Tables["all"].Rows.Count;j++)
- {
- for(int i=1;i<=n;i++)
- {
- if(i==2)
- {
- this._myExcel.Cells[j+2,i]="'"+myset.Tables["all"].Rows[j][i-1].ToString().Trim(); //单独处理编号。使其为字符串
- }
- else
- {
- this._myExcel.Cells[j+2,i]=myset.Tables["all"].Rows[j][i-1].ToString().Trim();
- }
- this.progressBar_now.Value =i;
- }
- this.progressBar_all.Value = j;
- }
- }
- this.label3.Text = "数据成功导出,请关闭本窗体,按照提示保存数据";
- MessageBox.Show("数据成功导出,请关闭本窗体,按照提示保存数据","系统信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
- this.Close();
- }
- private void btn_out_Click(object sender, System.EventArgs e)
- {
- this.Cursor = Cursors.WaitCursor;
- this._myExcel.UserControl = false;
- this._myExcel.Application.Workbooks.Add(true);
- this._myExcel.Visible = false;
- this.Cursor = Cursors.Default;
- MyOutThread = new Thread(new ThreadStart(import_excel));
- MyOutThread.IsBackground = true;
- MyOutThread.ApartmentState = ApartmentState.MTA;
- MyOutThread.Start();
- }
- private void KDataOut_Closing(object sender, System.ComponentModel.CancelEventArgs e)
- {
- this._myExcel.Quit();
- this._myExcel=null;
- GC.Collect();
- }
- private void KDataOut_Load(object sender, System.EventArgs e)
- {
- this._myExcel = new Excel.ApplicationClass();
- }
- }
- }