Ejemplo n.º 1
0
        public static void InsertDataBDSQL(string baseName = "ConvertBinFile.db3", HeaderTradeRecord fileBinRead = new HeaderTradeRecord())
        {
            try
            {
                string fName = Path.GetFileNameWithoutExtension(baseName);

                string path = Path.GetDirectoryName(baseName);
                baseName = path + "\\" + fName + ".db3";

                WorkingBD.CreateBDSQL(baseName);
                baseNameLastSQL = baseName;

                using (SQLiteConnection connection = new SQLiteConnection(string.Format("Data Source={0};", baseName)))
                {
                    connection.Open();
                    using (SQLiteCommand command = new SQLiteCommand(connection))
                    {
                        command.CommandText = @"DELETE FROM [Header];";
                        command.CommandType = CommandType.Text;
                        command.ExecuteNonQuery();

                        command.CommandText = @"DELETE FROM [TradeRecord];";
                        command.CommandType = CommandType.Text;
                        command.ExecuteNonQuery();

                        command.CommandText = @"INSERT INTO [Header] ([version], [type]) VALUES (" + fileBinRead.version + ", '" + fileBinRead.type + "');";
                        command.CommandType = CommandType.Text;
                        command.ExecuteNonQuery();

                        foreach (Model.TradeRecord t in fileBinRead.trades)
                        {
                            command.CommandText = @"INSERT INTO [TradeRecord] ([id], [account], [volume], [comment]) VALUES ("
                                                  + t.id + ", " + t.account + ", '" + t.volume + "', '" + t.comment + "');";
                            command.CommandType = CommandType.Text;
                            command.ExecuteNonQuery();
                        }
                    }
                }

                SavePathFileConvert(baseName, "sql");
            }
            catch (Exception x)
            {
                Console.WriteLine("Error InsertDataBD SQL: " + x.Message);
                WorkingBD.SaveLog("Error InsertDataBD SQL: " + x.Message);
            }
        }