Hanu Design 寒灯一笑的丝米空间
丝米空间,我的地盘,我做主

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using System.Diagnostics;

using Jinrm.Data;
using Jinrm.Function;
using System.IO;

namespace donghai_s
{
 /// <summary>
 /// Form1 的摘要说明。
 /// </summary>
 public class Form1 : System.Windows.Forms.Form
 {
  private System.Windows.Forms.Button button1;
  private System.Windows.Forms.MainMenu 文件;
  private System.Windows.Forms.MainMenu 打开;
  private System.Windows.Forms.MenuItem 打开文件;
  private System.Windows.Forms.MenuItem 版本信息;

  private DoSqlServer connZ = new DoSqlServer("(local)","sa","sa","netcnb_dhx");
  private DoSqlServer connY = new DoSqlServer("(local)","sa","sa","Lyg_dhx");
  private FuncSecurity FS = new FuncSecurity();
  private System.Windows.Forms.TextBox Excel_Text;
  private System.Windows.Forms.TextBox textBox1;

  /// <summary>
  /// 必需的设计器变量。
  /// </summary>
  private System.ComponentModel.Container components = null;

  public Form1()
  {
   //
   // 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()
  {
   this.button1 = new System.Windows.Forms.Button();
   this.文件 = new System.Windows.Forms.MainMenu();
   this.打开文件 = new System.Windows.Forms.MenuItem();
   this.版本信息 = new System.Windows.Forms.MenuItem();
   this.打开 = new System.Windows.Forms.MainMenu();
   this.Excel_Text = new System.Windows.Forms.TextBox();
   this.textBox1 = new System.Windows.Forms.TextBox();
   this.SuspendLayout();
   //
   // button1
   //
   this.button1.Location = new System.Drawing.Point(104, 32);
   this.button1.Name = "button1";
   this.button1.Size = new System.Drawing.Size(136, 23);
   this.button1.TabIndex = 0;
   this.button1.Text = "导出加密数据到Execl";
   this.button1.Click += new System.EventHandler(this.button1_Click);
   //
   // 文件
   //
   this.文件.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
                      this.打开文件,
                      this.版本信息});
   //
   // 打开文件
   //
   this.打开文件.Index = 0;
   this.打开文件.Text = "";
   this.打开文件.Click += new System.EventHandler(this.menuItem1_Click);
   //
   // 版本信息
   //
   this.版本信息.Index = 1;
   this.版本信息.Text = "";
   //
   // Excel_Text
   //
   this.Excel_Text.Location = new System.Drawing.Point(120, 112);
   this.Excel_Text.Name = "Excel_Text";
   this.Excel_Text.TabIndex = 1;
   this.Excel_Text.Text = "";
   //
   // textBox1
   //
   this.textBox1.Location = new System.Drawing.Point(72, 160);
   this.textBox1.Name = "textBox1";
   this.textBox1.Size = new System.Drawing.Size(208, 21);
   this.textBox1.TabIndex = 2;
   this.textBox1.Text = "textBox1";
   //
   // Form1
   //
   this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
   this.ClientSize = new System.Drawing.Size(360, 221);
   this.Controls.Add(this.textBox1);
   this.Controls.Add(this.Excel_Text);
   this.Controls.Add(this.button1);
   this.Menu = this.文件;
   this.Name = "Form1";
   this.Text = "数据导入程序";
   this.ResumeLayout(false);

  }
  #endregion

  /// <summary>
  /// 应用程序的主入口点。
  /// </summary>
  [STAThread]
  static void Main()
  {
   Application.Run(new Form1());
  }

  private void menuItem1_Click(object sender, System.EventArgs e)
  {
  
  }

  private static string CmdPing(string IsoName)
  {
   Process p = new Process();
   p.StartInfo.FileName = "cmd.exe";
   p.StartInfo.UseShellExecute = false;
   p.StartInfo.RedirectStandardInput = true;
   p.StartInfo.RedirectStandardOutput = true;
   p.StartInfo.RedirectStandardError = true;
   p.StartInfo.CreateNoWindow = true;
   string pingrst;
   p.Start();
   string tempstr = "F:\\CDIMAGE.EXE -l连云港 -t12/31/2002,12:00:00 -h -j1 -m -bF:\\xpboot.img F:\\ISO F:\\" + IsoName + ".iso";
   p.StandardInput.WriteLine(tempstr);
   //p.StandardInput.WriteLine("ping -n 1 "+strIp);
   p.StandardInput.WriteLine("exit");

   string strRst = p.StandardOutput.ReadToEnd();
   if(strRst.IndexOf("(0% loss)")!=-1)
    pingrst = "连接";
   else if( strRst.IndexOf("Done.")!=-1)
    pingrst = "无法到达目的主机";
   else if(strRst.IndexOf("Request timed out.")!=-1)
    pingrst = "超时";
   else if(strRst.IndexOf("Unknown host")!=-1)
    pingrst = "无法解析主机";
   else
    pingrst = strRst;
   p.Close();
   return pingrst;
  }
  
  private void button1_Click(object sender, System.EventArgs e)
  {
   #region 导出Excel

   //*********数据************//
   DataSet ds = connY.GetDs("*","xzjg","fid=101000 or fid=101001","");

   COM.Excel.cExcelFile excel = new COM.Excel.cExcelFile();
   excel.CreateFile("C:\\111.xls");

   COM.Excel.cExcelFile.ValueTypes vt = COM.Excel.cExcelFile.ValueTypes.xlsText;
   COM.Excel.cExcelFile.CellFont cf = COM.Excel.cExcelFile.CellFont.xlsFont0;
   COM.Excel.cExcelFile.CellAlignment ca = COM.Excel.cExcelFile.CellAlignment.xlsLeftAlign;
   COM.Excel.cExcelFile.CellHiddenLocked chl = COM.Excel.cExcelFile.CellHiddenLocked.xlsNormal;
  
   object title = "";
   int row=0,col=0,cellformat=0,excelrow=0;

   #region excel表头
   row=1;col=1;title = "UserID";
   excel.WriteValue(ref vt, ref cf, ref ca, ref chl,ref row,ref col,ref title,ref cellformat);
   row=1;col=2;title = "UserPwd";
   excel.WriteValue(ref vt, ref cf, ref ca, ref chl,ref row,ref col,ref title,ref cellformat);
   row=1;col=3;title = "UserName";
   excel.WriteValue(ref vt, ref cf, ref ca, ref chl,ref row,ref col,ref title,ref cellformat);
   row=1;col=4;title = "UserDes";
   excel.WriteValue(ref vt, ref cf, ref ca, ref chl,ref row,ref col,ref title,ref cellformat);
   row=1;col=5;title = "IsUse";
   excel.WriteValue(ref vt, ref cf, ref ca, ref chl,ref row,ref col,ref title,ref cellformat);
   #endregion
   Excel_Text.Text = ds.Tables[0].Rows.Count.ToString();
   #region 表内容
   for(row=0;row<ds.Tables[0].Rows.Count;row++)
   {
    excelrow = row + 2;
    col=1;title = ds.Tables[0].Rows[row]["fid"].ToString();excel.WriteValue(ref vt, ref cf, ref ca, ref chl,ref excelrow,ref col,ref title,ref cellformat);
    col=2;title = "";excel.WriteValue(ref vt, ref cf, ref ca, ref chl,ref excelrow,ref col,ref title,ref cellformat);
    col=3;title = ds.Tables[0].Rows[row]["mc"].ToString();excel.WriteValue(ref vt, ref cf, ref ca, ref chl,ref excelrow,ref col,ref title,ref cellformat);
    col=4;
    title = Base32.Encode(FS.EncryptText(ds.Tables[0].Rows[row]["fid"].ToString()));excel.WriteValue(ref vt, ref cf, ref ca, ref chl,ref excelrow,ref col,ref title,ref cellformat);
    
    string str;
    str= Base32.Encode(FS.EncryptText(ds.Tables[0].Rows[row]["fid"].ToString())) ;

    StreamWriter SW;
    SW=File.CreateText("F:\\ISO\\MyTextFile.txt");
    SW.WriteLine(row+1 +"  "+str);
    SW.Close();
    string ip = "测试";
    string strRst = CmdPing(ip + row+1);
    textBox1.Text = strRst;

    col=5;title = "1";excel.WriteValue(ref vt, ref cf, ref ca, ref chl,ref excelrow,ref col,ref title,ref cellformat);
   }
   #endregion
   int ret = excel.CloseFile();
   if(ret!=0)//错误
   {}

   #endregion
  }
 }
}

posted on 2006-05-30 13:54  寒灯一笑  阅读(412)  评论(0编辑  收藏  举报