KDataOut.cs
上传用户:chizxy
上传日期:2014-11-29
资源大小:407k
文件大小:7k
源码类别:

其他行业

开发平台:

C#

  1. using System;
  2. using System.Drawing;
  3. using System.Collections;
  4. using System.ComponentModel;
  5. using System.Windows.Forms;
  6. using System.Data;
  7. using System.Data.SqlClient;
  8. using System.Threading;
  9. namespace MKIms3
  10. {
  11. /// <summary>
  12. /// KDataOut 的摘要说明。
  13. /// </summary>
  14. public class KDataOut : System.Windows.Forms.Form
  15. {
  16. private Excel._Application _myExcel;
  17. static Thread MyOutThread = null;
  18. private System.Windows.Forms.Label label1;
  19. private System.Windows.Forms.Label label2;
  20. private System.Windows.Forms.Label label3;
  21. private System.Windows.Forms.Button btn_out;
  22. private System.Windows.Forms.ProgressBar progressBar_now;
  23. private System.Windows.Forms.ProgressBar progressBar_all;
  24. private System.Windows.Forms.PictureBox pictureBox1;
  25. /// <summary>
  26. /// 必需的设计器变量。
  27. /// </summary>
  28. private System.ComponentModel.Container components = null;
  29. public KDataOut()
  30. {
  31. //
  32. // Windows 窗体设计器支持所必需的
  33. //
  34. InitializeComponent();
  35. //
  36. // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
  37. //
  38. }
  39. /// <summary>
  40. /// 清理所有正在使用的资源。
  41. /// </summary>
  42. protected override void Dispose( bool disposing )
  43. {
  44. if( disposing )
  45. {
  46. if(components != null)
  47. {
  48. components.Dispose();
  49. }
  50. }
  51. base.Dispose( disposing );
  52. }
  53. #region Windows 窗体设计器生成的代码
  54. /// <summary>
  55. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  56. /// 此方法的内容。
  57. /// </summary>
  58. private void InitializeComponent()
  59. {
  60. System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(KDataOut));
  61. this.label1 = new System.Windows.Forms.Label();
  62. this.label2 = new System.Windows.Forms.Label();
  63. this.progressBar_now = new System.Windows.Forms.ProgressBar();
  64. this.progressBar_all = new System.Windows.Forms.ProgressBar();
  65. this.label3 = new System.Windows.Forms.Label();
  66. this.btn_out = new System.Windows.Forms.Button();
  67. this.pictureBox1 = new System.Windows.Forms.PictureBox();
  68. this.SuspendLayout();
  69. // 
  70. // label1
  71. // 
  72. this.label1.Location = new System.Drawing.Point(128, 9);
  73. this.label1.Name = "label1";
  74. this.label1.Size = new System.Drawing.Size(72, 23);
  75. this.label1.TabIndex = 0;
  76. this.label1.Text = "当前进度:";
  77. this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
  78. // 
  79. // label2
  80. // 
  81. this.label2.Location = new System.Drawing.Point(125, 56);
  82. this.label2.Name = "label2";
  83. this.label2.Size = new System.Drawing.Size(61, 23);
  84. this.label2.TabIndex = 1;
  85. this.label2.Text = "总进度:";
  86. this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
  87. // 
  88. // progressBar_now
  89. // 
  90. this.progressBar_now.Location = new System.Drawing.Point(136, 32);
  91. this.progressBar_now.Name = "progressBar_now";
  92. this.progressBar_now.Size = new System.Drawing.Size(240, 21);
  93. this.progressBar_now.TabIndex = 2;
  94. // 
  95. // progressBar_all
  96. // 
  97. this.progressBar_all.Location = new System.Drawing.Point(136, 80);
  98. this.progressBar_all.Name = "progressBar_all";
  99. this.progressBar_all.Size = new System.Drawing.Size(240, 21);
  100. this.progressBar_all.TabIndex = 3;
  101. // 
  102. // label3
  103. // 
  104. this.label3.Location = new System.Drawing.Point(136, 120);
  105. this.label3.Name = "label3";
  106. this.label3.Size = new System.Drawing.Size(160, 48);
  107. this.label3.TabIndex = 4;
  108. this.label3.Text = "    说明:导出完毕,请按照提示保存导出的xsl文件。";
  109. // 
  110. // btn_out
  111. // 
  112. this.btn_out.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
  113. this.btn_out.Location = new System.Drawing.Point(310, 120);
  114. this.btn_out.Name = "btn_out";
  115. this.btn_out.Size = new System.Drawing.Size(56, 40);
  116. this.btn_out.TabIndex = 5;
  117. this.btn_out.Text = "数据     导出";
  118. this.btn_out.Click += new System.EventHandler(this.btn_out_Click);
  119. // 
  120. // pictureBox1
  121. // 
  122. this.pictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
  123. this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
  124. this.pictureBox1.Location = new System.Drawing.Point(-8, -24);
  125. this.pictureBox1.Name = "pictureBox1";
  126. this.pictureBox1.Size = new System.Drawing.Size(136, 200);
  127. this.pictureBox1.TabIndex = 6;
  128. this.pictureBox1.TabStop = false;
  129. // 
  130. // KDataOut
  131. // 
  132. this.AcceptButton = this.btn_out;
  133. this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
  134. this.ClientSize = new System.Drawing.Size(384, 178);
  135. this.Controls.Add(this.pictureBox1);
  136. this.Controls.Add(this.btn_out);
  137. this.Controls.Add(this.label3);
  138. this.Controls.Add(this.progressBar_all);
  139. this.Controls.Add(this.progressBar_now);
  140. this.Controls.Add(this.label2);
  141. this.Controls.Add(this.label1);
  142. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
  143. this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
  144. this.Name = "KDataOut";
  145. this.ShowInTaskbar = false;
  146. this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
  147. this.Text = "所有钻孔属性数据导出";
  148. this.Closing += new System.ComponentModel.CancelEventHandler(this.KDataOut_Closing);
  149. this.Load += new System.EventHandler(this.KDataOut_Load);
  150. this.ResumeLayout(false);
  151. }
  152. #endregion
  153.  
  154. private void import_excel()
  155. {
  156. DataBase myDB = new DataBase();
  157. DataSet myset;
  158. myset = myDB.RunProcedure("up_putout_all","all");
  159. if(myset!=null)
  160. {
  161. int n =myset.Tables["all"].Columns.Count;
  162. this.progressBar_now.Value = 0;
  163. this.progressBar_now.Maximum = n;
  164. this.progressBar_all.Value = 0;
  165. this.progressBar_all.Maximum = myset.Tables["all"].Rows.Count;
  166. int j=0;
  167. for(int m=0;m<n;m++)
  168. {
  169. this._myExcel.Cells[1,m+1]=myset.Tables[0].Columns[m].ColumnName.ToString();
  170. }
  171. for(j=0;j<myset.Tables["all"].Rows.Count;j++)
  172. {
  173. for(int i=1;i<=n;i++)
  174. {
  175. if(i==2)
  176. {
  177. this._myExcel.Cells[j+2,i]="'"+myset.Tables["all"].Rows[j][i-1].ToString().Trim(); //单独处理编号。使其为字符串
  178. }
  179. else
  180. {
  181. this._myExcel.Cells[j+2,i]=myset.Tables["all"].Rows[j][i-1].ToString().Trim();
  182. }
  183. this.progressBar_now.Value =i;
  184. }
  185. this.progressBar_all.Value = j;
  186. }
  187. }
  188. this.label3.Text = "数据成功导出,请关闭本窗体,按照提示保存数据";
  189. MessageBox.Show("数据成功导出,请关闭本窗体,按照提示保存数据","系统信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
  190. this.Close();
  191. }
  192. private void btn_out_Click(object sender, System.EventArgs e)
  193. {
  194. this.Cursor = Cursors.WaitCursor;
  195. this._myExcel.UserControl = false;
  196. this._myExcel.Application.Workbooks.Add(true);
  197. this._myExcel.Visible = false;
  198. this.Cursor = Cursors.Default;
  199. MyOutThread = new Thread(new ThreadStart(import_excel));
  200. MyOutThread.IsBackground = true;
  201. MyOutThread.ApartmentState = ApartmentState.MTA;
  202. MyOutThread.Start();
  203. }
  204. private void KDataOut_Closing(object sender, System.ComponentModel.CancelEventArgs e)
  205. {
  206. this._myExcel.Quit();
  207. this._myExcel=null;
  208. GC.Collect();
  209. }
  210. private void KDataOut_Load(object sender, System.EventArgs e)
  211. {
  212. this._myExcel = new Excel.ApplicationClass();
  213. }
  214. }
  215. }