⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.cs

📁 c#开发的批量图片入库oracle的程序
💻 CS
📖 第 1 页 / 共 2 页
字号:
using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
//using System.Data.OracleClient;
using System.IO;

using Oracle.DataAccess.Client;
using Oracle.DataAccess.Types;

using System.Threading;

namespace DataInput
{
    public partial class Form1 : Form
    {
        public static OracleConnection cn;
        public static string UserName = "";
        public static string Password = "";
        public static string DataSource = "";

        public static string TablePath = "";
        public static string TableName = "";
        public static string TableSpace = "";

        public static int lastLocation, extendLocation;
        public static string tableName;
        public static string[] partitionName = { };
        public static int partitionNumber = 0;
        public static string fnNumber;
        public static long id = 0, maxLength = 0;
        public static string strPartition = "";

        static string ID = "ID";
        static string NAME = "NAME";
        static string IMAGE = "SHAPE";
        static string JAVA = "JAVA";
        static string TABLE2 = "TABLE2";

        static long index;
        static long filesSum = 0;

        public static DataSet dsJAVA;
        public static DataTable dtTemp;
        public static DataRow drCurrent;
        public static OracleCommandBuilder objCommandBuilder;

        public static string strSql = "";
        public static OracleDataAdapter ada;
        static long timeOut = 0;
        int iii = 10;
        public Form1()
        {
            
            InitializeComponent();
            Control.CheckForIllegalCrossThreadCalls = false;
        }

        public static Byte[] Rtf(string fileName)
        {
            using (FileStream fsIn = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                int size = Convert.ToInt32(fsIn.Length);
                Byte[] rtf = new Byte[size];
                fsIn.Position = 0;
                fsIn.Read(rtf, 0, size);
                return rtf;
            }
        }


        private void 连接数据库ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Connection newConnection = new Connection();
            newConnection.Show();
        }

        private void 建表ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            
            if (fbdFindData.ShowDialog() == DialogResult.OK)
             {
                 lastLocation = fbdFindData.SelectedPath.LastIndexOf("\\");
                 TABLE2 = fbdFindData.SelectedPath.Substring(lastLocation + 1);

            foreach (string ChildDirectory in Directory.GetDirectories(fbdFindData.SelectedPath))
            //foreach (string ChildDirectory in Directory.GetDirectories("D:\\beijing"))
            {
                lastLocation = ChildDirectory.LastIndexOf("\\");
                tableName = TABLE2 + ChildDirectory.Substring(lastLocation + 1);

                foreach (string ChildDirectoryNext in Directory.GetDirectories(ChildDirectory))
                {

                    lastLocation = ChildDirectoryNext.LastIndexOf("\\");
                    Array.Resize(ref partitionName, partitionName.Length + 1);
                    partitionName[partitionNumber] = ChildDirectoryNext.Substring(lastLocation + 1);

                    DirectoryInfo di = new DirectoryInfo(ChildDirectoryNext);

                    filesSum += di.GetFiles().Length;

                    if (di.GetFiles().Length != 0)
                    {
                        
                        foreach (FileInfo fi in di.GetFiles())
                        {
                            extendLocation = fi.Name.LastIndexOf(".");
                            lastLocation = fi.Name.LastIndexOf("_");
                            if (lastLocation != -1)
                            {
                                fnNumber = "1" + fi.Name.Substring(0, lastLocation) + fi.Name.Substring(lastLocation + 1, extendLocation - lastLocation - 1);
                                id = Convert.ToInt64(fnNumber);
                                maxLength = di.GetFiles().Length + id;
                                
                                break;
                            }
                            
                        }
                        strPartition = strPartition + "PARTITION " + "p" + partitionName[partitionNumber] + " VALUES LESS THAN  (" + maxLength + ")TABLESPACE " + TableSpace + ",";
                        
                    }
                    
                    partitionNumber++;
                }
                string createTable = "CREATE TABLE " + UserName + "." + tableName + " (" +
ID + " Decimal (15) NOT NULL, " +
NAME + " VARCHAR2(64), " +
IMAGE + " BLOB) TABLESPACE " + TableSpace +
" PARTITION BY RANGE (" + ID + ") (";
                createTable = createTable + strPartition.Substring(0, strPartition.Length - 1) + ")";
                OracleCommand command = new OracleCommand(createTable, cn);
                command.ExecuteNonQuery();
                createTable = "";
                strPartition = "";
            }
            }
        }

/*        static void ThreadProc(Object stateInfo)
        {

            timeOut = Environment.TickCount;
            if (fbdFindData.ShowDialog() == DialogResult.OK)
            {
                lastLocation = fbdFindData.SelectedPath.LastIndexOf("\\");
                TABLE2 = fbdFindData.SelectedPath.Substring(lastLocation + 1);
                foreach (string ChildDirectory in Directory.GetDirectories(fbdFindData.SelectedPath))
                //foreach (string ChildDirectory in Directory.GetDirectories("D:\\beijing"))
                {
                    lastLocation = ChildDirectory.LastIndexOf("\\");
                    tableName = TABLE2 + ChildDirectory.Substring(lastLocation + 1);

                    ///////////////////////////////////////////////////////////////////////////////////////////////
                    strSql = "SELECT * from ";
                    strSql = strSql + tableName + " WHERE ID = -1";
                    ada = new OracleDataAdapter(strSql, cn);
                    dsJAVA = new DataSet("JAVA");
                    ada.Fill(dsJAVA, tableName);
                    dtTemp = dsJAVA.Tables[tableName];

                    ///////////////////////////////////////////////////////////////////////////////////////////////
                    foreach (string ChildDirectoryNext in Directory.GetDirectories(ChildDirectory))
                    {

                        lastLocation = ChildDirectoryNext.LastIndexOf("\\");
                        Array.Resize(ref partitionName, partitionName.Length + 1);
                        partitionName[partitionNumber] = ChildDirectoryNext.Substring(lastLocation + 1);

                        DirectoryInfo di = new DirectoryInfo(ChildDirectoryNext);
                        if (di.GetFiles().Length != 0)
                        {
                            int i = 0;
                            foreach (FileInfo fi in di.GetFiles())
                            {
                                i++;
                                extendLocation = fi.Name.LastIndexOf(".");
                                lastLocation = fi.Name.LastIndexOf("_");
                                if (lastLocation != -1)
                                {
                                    fnNumber = "1" + fi.Name.Substring(0, lastLocation) + fi.Name.Substring(lastLocation + 1, extendLocation - lastLocation - 1);
                                    //id = Convert.ToInt32(fnNumber);
                                    //maxLength = di.GetFiles().Length + id - 1;

                                    ///////////////////////////////////////////////////////////////////////////////////////////////
                                    drCurrent = dtTemp.NewRow();
                                    drCurrent["ID"] = fnNumber;
                                    drCurrent["NAME"] = fi.Name.Substring(0, fi.Name.Length);
                                    drCurrent["SHAPE"] = Rtf(fi.FullName);
                                    dtTemp.Rows.Add(drCurrent);
                                    drCurrent = dtTemp.NewRow();

                                    if (i == di.GetFiles().Length - 1 && Math.IEEERemainder(i, 10) != 0)
                                    {
                                        objCommandBuilder = new OracleCommandBuilder(ada);
                                        ada.Update(dsJAVA, tableName);

                                        dsJAVA.Clear();
                                    }
                                    else if (Math.IEEERemainder(i, 10) == 0)
                                    {
                                        i++;
                                        objCommandBuilder = new OracleCommandBuilder(ada);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -