public void Covert(Sqlite2CsConfig config)
        {
            CleanupOutput(config.outputPath);
            SQLiteConnectionStringBuilder sqlitestring = new SQLiteConnectionStringBuilder();

            sqlitestring.DataSource = config.databaseFilePath;
            mSqliteConn             = new SQLiteConnection(sqlitestring.ToString());
            mSqliteConn.Open();
            //mSqliteConn.StateChange += MSqliteConn_StateChange;
            Dictionary <string, string> tableInfoMap = GetTableInfo(config.databaseName, config.filterName);

            foreach (KeyValuePair <string, string> tableInfo in tableInfoMap)
            {
                CSFileWriter csFile = ConvertTable(config.databaseName, tableInfo.Key, tableInfo.Value, config.CSdataClassImpledInterface);

                string filePath = config.outputPath + "/" + tableInfo.Key + ".cs";
                if (File.Exists(filePath))
                {
                    Console.WriteLine("{0} already exists.", filePath);
                    return;
                }
                using (StreamWriter sw = File.CreateText(filePath))
                {
                    sw.Write(csFile.GenerateFilsString());
                    sw.Close();
                }
            }
            mSqliteConn.Close();
            System.Windows.Forms.MessageBox.Show("写入完毕!!!");
        }
示例#2
0
        private void InitWithConfig()
        {
            string configPath = Directory.GetCurrentDirectory() + "/config.xml";

            XmlSerializer     configSerializer = new XmlSerializer(typeof(Sqlite2CsConfig));
            XmlReaderSettings setting          = new XmlReaderSettings();

            if (!File.Exists(configPath))
            {
                FileStream fs = File.Create(configPath);
                fs.Close();
                fs.Dispose();
            }

            using (XmlReader fs = XmlReader.Create(configPath))
            {
                try
                {
                    config = configSerializer.Deserialize(fs) as Sqlite2CsConfig;
                }
                catch
                {
                    //whatever happend ,create a new config
                    config = new Sqlite2CsConfig();
                }
            }

            if (!string.IsNullOrEmpty(config.databaseFilePath))
            {
                databasePath.Text = config.databaseFilePath;
            }

            if (!string.IsNullOrEmpty(config.outputPath))
            {
                outputPath.Text = config.outputPath;
            }

            if (!string.IsNullOrEmpty(config.databaseName))
            {
                dbNameBox.Text = config.databaseName;
            }

            if (!string.IsNullOrEmpty(config.filterName))
            {
                filterNameBox.Text = config.filterName;
            }

            if (config.CSdataClassImpledInterface != null)
            {
                for (int i = 0; i < config.CSdataClassImpledInterface.Length; ++i)
                {
                    DataGridViewRow row = new DataGridViewRow();
                    row.CreateCells(dataGridView1);
                    row.Cells[0].Value = config.CSdataClassImpledInterface[i];
                    dataGridView1.Rows.Add(row);
                }
            }
        }