Exemple #1
0
        private void SerializeBinary()
        {
            DataTable     data         = new DataTable();
            List <string> chapter_test = new List <string>();
            //List<string> chapter = new List<string>();
            List <string> component = new List <string>();
            List <string> graph     = new List <string>();

            OleDbConnection exconn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties='Excel 12.0 Xml;HDR=YES;IMEX=1'");
            DataTable       table  = opene_excel(path);

            exconn.Open();

            foreach (DataRow row in table.Rows)
            {
                OleDbCommand    command = new OleDbCommand("Select * from [" + row["TABLE_NAME"].ToString() + "]", exconn);
                OleDbDataReader reader  = command.ExecuteReader();
                data.Load(reader);
                switch (row["TABLE_NAME"].ToString())
                {
                case "chapter_test$":
                    foreach (DataColumn col in data.Columns)
                    {
                        chapter_test.Add(col.ToString());
                    }
                    break;

                //case "chapter$":
                //    foreach (DataColumn col in data.Columns)
                //        chapter.Add(col.ToString());
                //    break;
                case "component$":
                    foreach (DataColumn col in data.Columns)
                    {
                        component.Add(col.ToString());
                    }
                    break;

                case "graph$":
                    foreach (DataColumn col in data.Columns)
                    {
                        graph.Add(col.ToString());
                    }
                    break;
                }
                data.Clear();
                data.Columns.Clear();
            }
            DataColumnName  columname = new DataColumnName(chapter_test, component, graph);
            FileStream      fs        = new FileStream("Config", FileMode.Create, FileAccess.Write);
            BinaryFormatter formatter = new BinaryFormatter();

            formatter.Serialize(fs, columname);
            fs.Close();
            fs.Dispose();
            columname.Dispose();
        }
Exemple #2
0
        private DataColumnName DeserializeBinary()
        {
            FileStream      fileStream = new FileStream("Config", FileMode.Open);
            BinaryFormatter formatter  = new BinaryFormatter();
            DataColumnName  name       = (DataColumnName)formatter.Deserialize(fileStream);

            fileStream.Close();
            fileStream.Dispose();
            return(name);
        }
Exemple #3
0
        public DataBaseProcess(DataColumnName name, string path)
        {
            data   = name;
            expath = path;
            OleDbConnection exconn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties='Excel 12.0 Xml;HDR=YES;IMEX=1'");
            DataTable       table  = OpenExcel(path);

            exconn.Open();

            foreach (DataRow row in table.Rows)
            {
                OleDbCommand    command = new OleDbCommand("SELECT * FROM [" + row["TABLE_NAME"].ToString() + "]", exconn);
                OleDbDataReader reader  = command.ExecuteReader();
                dataconent.Load(reader);
                if (row["TABLE_NAME"].ToString().Contains("chapter"))
                {
                    if (row["TABLE_NAME"].ToString().Contains("test"))
                    {
                        CommandQuery.CreateTable(row["TABLE_NAME"].ToString().TrimEnd('$'), data.Chapter_test);
                        CommandQuery.InsertChapterTest(row["TABLE_NAME"].ToString().TrimEnd('$'), CommandQuery.DataTableToList(dataconent));
                    }
                    else
                    {
                        CommandQuery.CreateTable(row["TABLE_NAME"].ToString().TrimEnd('$'), dataconent.Columns);
                        CommandQuery.InsertChapter(row["TABLE_NAME"].ToString().TrimEnd('$'), dataconent);
                    }
                }

                dataconent.Clear();
                dataconent.Columns.Clear();
            }

            CommandQuery.CreateTable("component", data.Component);
            //CommandQuery.CreateTable("graph", data.Graph);
            //CommandQuery.InsertGraph();

            exconn.Close();
            CommandQuery.CloseConnect();
        }