Created
June 20, 2019 13:00
-
-
Save rasoulian/5a4a1f62eff248c503994c3990f31e57 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Linq; | |
using System.Text; | |
using Microsoft.Data.Sqlite; | |
using Microsoft.EntityFrameworkCore; | |
namespace drkarami | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var DBs = System.IO.Directory.GetFiles(Environment.CurrentDirectory, "*.db").ToList(); | |
DBs.ForEach(dbFile => | |
{ | |
var stringBuilder = new StringBuilder(); | |
using (var db = new BloggingContext(dbFile)) | |
{ | |
db.Quiz.ToList().ForEach(q => | |
{ | |
var question = $@"<fieldset id='{q.ID}' data-answer='{q.Correct}'> | |
<legend><h4>{q.Soal}</h4></legend> | |
<ol> | |
<li id='q{q.ID}-1'><label><input type='radio' name='q{q.ID}'>{q.G_1}</label></li> | |
<li id='q{q.ID}-2'><label><input type='radio' name='q{q.ID}'>{q.G_2}</label></li> | |
<li id='q{q.ID}-3'><label><input type='radio' name='q{q.ID}'>{q.G_3}</label></li> | |
<li id='q{q.ID}-4'><label><input type='radio' name='q{q.ID}'>{q.G_4}</label></li> | |
</ol> | |
</fieldset>"; | |
stringBuilder.AppendLine(question); | |
}); | |
} | |
var html = $@"<html><head> | |
<meta charset='utf-8' /> | |
<meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=yes' /> | |
<meta http-equiv='content-type' content='text/html;charset=UTF-8' /> | |
<meta http-equiv='X-UA-Compatible' content='IE=edge'> | |
<style>body, html{{font - size: 8pt;font-family: Tahoma, Verdana, Arial, 'Helvetica Neue', Helvetica, Sans-Serif;}}</style> | |
</head> | |
<body dir='rtl'> | |
<main>{stringBuilder}</main> | |
<footer style='margin: 30pt'><button style='width:100%' onclick='show()'>OK</button></footer> | |
<script>function show(){{var qs = document.querySelectorAll('fieldset'); [].forEach.call(qs, function(q) {{ document.getElementById(`q${{q.id}}-${{q.dataset.answer}}`).style.backgroundColor = 'green' }})}}</script> | |
</body></html>"; | |
System.IO.File.WriteAllText(dbFile+".html", html); | |
}); | |
Console.WriteLine("Done!"); | |
} | |
} | |
public class BloggingContext : DbContext | |
{ | |
private string _dbName = string.Empty; | |
public BloggingContext(string dbName) | |
{ | |
_dbName = dbName; | |
} | |
public DbSet<Quiz> Quiz { get; set; } | |
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) | |
{ | |
var connectionStringBuilder = new SqliteConnectionStringBuilder { DataSource = _dbName }; | |
var connectionString = connectionStringBuilder.ToString(); | |
var connection = new SqliteConnection(connectionString); | |
optionsBuilder.UseSqlite(connection); | |
} | |
} | |
public class Quiz | |
{ | |
public int ID { get; set; } | |
public string Soal { get; set; } | |
public string G_1 { get; set; } | |
public string G_2 { get; set; } | |
public string G_3 { get; set; } | |
public string G_4 { get; set; } | |
public int Correct { get; set; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment