水贴~

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace MakeSql
{
    class Program
    {
        static void Main(string[] args)
        {
            bool boolFlag=true ;
            while (boolFlag)
            {
                Console.WriteLine("请输入你的sql文件路径:(Please input ur SQL or TXT filepath:)");
                string strPath= Console.ReadLine();
                if ("EXIT" == strPath.ToUpper())
                {
                    boolFlag = false;
                    continue;
                }
                if (!File.Exists(strPath))
                {
                    Console.WriteLine("该文件路径错误,请重新输入.(This  filepath is error,please repeat input.)");
                    continue;
                }
               
                string strExpand = strPath.Substring(strPath.LastIndexOf("."));

                if (!(".sql" == strExpand ) && !(".txt" == strExpand))
                {
                    Console.WriteLine("该文件类型不支持,请重新输入.(This  fileType is error,please repeat input.)");
                    continue;
                }

                using (FileStream fs = File.Open(strPath, FileMode.Open))
                {
                    using (StreamReader sr = new StreamReader(fs))
                    {
                        try
                        {
                            FileStream newfs = new FileStream("D:/TempSQL.txt", FileMode.Append ,FileAccess.Write);
                            StreamWriter sw = new StreamWriter(newfs);
                            string date = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:ms");

                            sw.WriteLine();
                            sw.WriteLine("#####################################" + date + "  BEGIN########################################");
                            while (sr.Peek() >= 0)
                            {
                                string strTemp = sr.ReadLine();
                                if (strTemp.StartsWith("-"))
                                {
                                    sw.WriteLine("'" + strTemp);
                                }
                                else if (!string.IsNullOrEmpty(strTemp))
                                {
                                    sw.WriteLine("sql.AppendLine(/"" + strTemp + "/")");
                                }
                            }
                            sw.WriteLine("#####################################" + date + "  END############################################");
                            sw.WriteLine();
                            sw.Flush();
                            sw.Close();
                            newfs.Close();
                            Console.WriteLine(date + " 处理成功:(Successfully done.)");
                            Console.WriteLine("生成文件路径 D:/TempSQL.txt");
                        }
                        catch(Exception ex)
                            {
                                Console.WriteLine("处理失败:(Process failed:)");
                                Console.WriteLine(ex.Message );
                            }
                    }
                }
            }
        }
    }
}


本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/raineo/archive/2009/06/25/4298411.aspx

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值