Upload to server

uploading
This commit is contained in:
2025-08-02 05:20:17 +07:00
commit a5eccbd452
984 changed files with 3031800 additions and 0 deletions

View File

@@ -0,0 +1,165 @@
using System;
using System.Management;
using System.Security.Cryptography;
using System.Security;
using System.Collections;
using System.Text;
namespace Omega
{
/// <summary>
/// Generates a 16 byte Unique Identification code of a computer
/// Example: 4876-8DB5-EE85-69D3-FE52-8CF7-395D-2EA9
/// </summary>
public class FingerPrint
{
private static string fingerPrint = string.Empty;
public static string Value()
{
if (string.IsNullOrEmpty(fingerPrint))
{
fingerPrint = GetHash("CPU >> " + cpuId() + "\nBIOS >> " + biosId() + "\nBASE >> " + baseId()
//+"\nDISK >> "+ diskId() + "\nVIDEO >> " + videoId() +"\nMAC >> "+ macId()
);
}
return fingerPrint;
}
private static string GetHash(string s)
{
MD5 sec = new MD5CryptoServiceProvider();
ASCIIEncoding enc = new ASCIIEncoding();
byte[] bt = enc.GetBytes(s);
return GetHexString(sec.ComputeHash(bt));
}
private static string GetHexString(byte[] bt)
{
string s = string.Empty;
for (int i = 0; i < bt.Length; i++)
{
byte b = bt[i];
int n, n1, n2;
n = (int)b;
n1 = n & 15;
n2 = (n >> 4) & 15;
if (n2 > 9)
s += ((char)(n2 - 10 + (int)'A')).ToString();
else
s += n2.ToString();
if (n1 > 9)
s += ((char)(n1 - 10 + (int)'A')).ToString();
else
s += n1.ToString();
if ((i + 1) != bt.Length && (i + 1) % 2 == 0) s += "-";
}
return s;
}
#region Original Device ID Getting Code
//Return a hardware identifier
private static string identifier(string wmiClass, string wmiProperty, string wmiMustBeTrue)
{
string result = "";
System.Management.ManagementClass mc = new System.Management.ManagementClass(wmiClass);
System.Management.ManagementObjectCollection moc = mc.GetInstances();
foreach (System.Management.ManagementObject mo in moc)
{
if (mo[wmiMustBeTrue].ToString() == "True")
{
//Only get the first one
if (result == "")
{
try
{
result = mo[wmiProperty].ToString();
break;
}
catch
{
}
}
}
}
return result;
}
//Return a hardware identifier
private static string identifier(string wmiClass, string wmiProperty)
{
string result = "";
System.Management.ManagementClass mc = new System.Management.ManagementClass(wmiClass);
System.Management.ManagementObjectCollection moc = mc.GetInstances();
foreach (System.Management.ManagementObject mo in moc)
{
//Only get the first one
if (result == "")
{
try
{
result = mo[wmiProperty].ToString();
break;
}
catch
{
}
}
}
return result;
}
private static string cpuId()
{
//Uses first CPU identifier available in order of preference
//Don't get all identifiers, as very time consuming
string retVal = identifier("Win32_Processor", "UniqueId");
if (retVal == "") //If no UniqueID, use ProcessorID
{
retVal = identifier("Win32_Processor", "ProcessorId");
if (retVal == "") //If no ProcessorId, use Name
{
retVal = identifier("Win32_Processor", "Name");
if (retVal == "") //If no Name, use Manufacturer
{
retVal = identifier("Win32_Processor", "Manufacturer");
}
//Add clock speed for extra security
retVal += identifier("Win32_Processor", "MaxClockSpeed");
}
}
return retVal;
}
//BIOS Identifier
private static string biosId()
{
return identifier("Win32_BIOS", "Manufacturer")
+ identifier("Win32_BIOS", "SMBIOSBIOSVersion")
+ identifier("Win32_BIOS", "IdentificationCode")
+ identifier("Win32_BIOS", "SerialNumber")
+ identifier("Win32_BIOS", "ReleaseDate")
+ identifier("Win32_BIOS", "Version");
}
//Main physical hard drive ID
private static string diskId()
{
return identifier("Win32_DiskDrive", "Model")
+ identifier("Win32_DiskDrive", "Manufacturer")
+ identifier("Win32_DiskDrive", "Signature")
+ identifier("Win32_DiskDrive", "TotalHeads");
}
//Motherboard ID
private static string baseId()
{
return identifier("Win32_BaseBoard", "Model")
+ identifier("Win32_BaseBoard", "Manufacturer")
+ identifier("Win32_BaseBoard", "Name")
+ identifier("Win32_BaseBoard", "SerialNumber");
}
//Primary video controller ID
private static string videoId()
{
return identifier("Win32_VideoController", "DriverVersion")
+ identifier("Win32_VideoController", "Name");
}
//First enabled network card ID
private static string macId()
{
return identifier("Win32_NetworkAdapterConfiguration", "MACAddress", "IPEnabled");
}
#endregion
}
}

View File

@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Omega
{
class Quiz
{
public string QuestionId { get; set; }
public int Order { get; set; }
}
}

View File

@@ -0,0 +1,209 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Word = Microsoft.Office.Interop.Word;
using Microsoft.Office.Interop.Word;
using Datalib.EntityClasses;
using Datalib.FactoryClasses;
using Datalib.HelperClasses;
using Datalib.Linq;
using Datalib.DatabaseSpecific;
using SD.LLBLGen.Pro.ORMSupportClasses;
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using Power= OpenXmlPowerTools;
using Sys=System.Windows.Forms;
using System.Xml.Linq;
using System.Xml;
using System.IO;
namespace Omega
{
class Utilities
{
public static void ConverttoPdf(string input, string output)
{
// Create an instance of Word.exe
Word._Application oWord = new Word.Application();
// Make this instance of word invisible (Can still see it in the taskmgr).
oWord.Visible = false;
// Interop requires objects.
object oMissing = System.Reflection.Missing.Value;
object isVisible = true;
object readOnly = false;
object oInput = input;
object oOutput = output;
object oFormat = WdSaveFormat.wdFormatPDF;
// Load a document into our instance of word.exe
Word._Document oDoc = oWord.Documents.Open(ref oInput, ref oMissing, ref readOnly, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref isVisible, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
// Make this document the active document.
oDoc.Activate();
// Save this document in Word 2003 format.
oDoc.SaveAs(ref oOutput, ref oFormat, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
// Always close Word.exe.
oWord.Quit(ref oMissing, ref oMissing, ref oMissing);
}
public static void PrintQuiz(TblQuizEntity CurrQuiz)
{
List <Power.Source> sources = new List<Power.Source>();
string SubjectId = "xxxx";
string FieldId = "xxxx";
int QuestionNum = 1;
Boolean Renumering = false;
string prefix = "";
LinqMetaData meta = new LinqMetaData(new DataAccessAdapter());
byte[] header = Convert.FromBase64String(meta.TblQuizTemplate.Where(m => m.QuizTemplateId == CurrQuiz.QuizTemplateId).FirstOrDefault().HeaderDes);
Power.WmlDocument headercon = new Power.WmlDocument(Guid.NewGuid().ToString("N"), header);
Power.OpenXmlMemoryStreamDocument modifystream = new Power.OpenXmlMemoryStreamDocument(headercon);
WordprocessingDocument modifywDoc =modifystream.GetWordprocessingDocument();
Power.TextReplacer.SearchAndReplace(modifywDoc, "{year}", CurrQuiz.QuizYear.ToString(), false);
Power.TextReplacer.SearchAndReplace(modifywDoc, "{QuizCode}", CurrQuiz.QuizCode, false);
Power.TextReplacer.SearchAndReplace(modifywDoc, "{QuizTime}", CurrQuiz.QuizTime.ToString(), false);
sources.Add(new Power.Source(modifystream.GetModifiedWmlDocument(), false));
byte[] footer = Convert.FromBase64String(meta.TblQuizTemplate.Where(m => m.QuizTemplateId == CurrQuiz.QuizTemplateId).FirstOrDefault().FooterDes);
Renumering = meta.TblQuizTemplate.Where(m => m.QuizTemplateId == CurrQuiz.QuizTemplateId).FirstOrDefault().Renumering;
var result = (from q in meta.TblQuestion join m in meta.TblQuizQuestion.Where(m => m.QuizId == CurrQuiz.QuizId) on q.QuestionId equals m.QuestionId select new { SubjectId = q.SubjectId, FieldID = q.FieldId, con = q.Content }).ToList().OrderBy(m => m.SubjectId).ThenBy(m => m.FieldID).ToList();
foreach (var q in result)
{
if(q.SubjectId!=SubjectId)
{
SubjectId = q.SubjectId;
QuestionNum = 1;
byte[] SubjectDes = Convert.FromBase64String(meta.TblSubject.Where(m => m.SubjectId == q.SubjectId).FirstOrDefault().SubjectDes);
sources.Add(new Power.Source(new Power.WmlDocument(Guid.NewGuid().ToString("N"), SubjectDes), false));
}
if (q.FieldID != FieldId)
{
try
{
FieldId = q.FieldID;
if (Renumering) QuestionNum = 1;
prefix = meta.TblField.Where(m => m.SubjectId == q.SubjectId).Where(m => m.FieldId == FieldId).FirstOrDefault().Prefix;
byte[] FieldDes = Convert.FromBase64String(meta.TblField.Where(m => m.SubjectId == q.SubjectId).Where(m => m.FieldId == q.FieldID).FirstOrDefault().Description);
sources.Add(new Power.Source(new Power.WmlDocument(Guid.NewGuid().ToString("N"), FieldDes), false));
}
catch (Exception err)
{
Sys.MessageBox.Show(q.SubjectId + " " + q.FieldID);
}
}
byte[] buf = Convert.FromBase64String(q.con);
Power.WmlDocument con = new Power.WmlDocument(Guid.NewGuid().ToString("N"), buf);
modifystream = new Power.OpenXmlMemoryStreamDocument(con);
modifywDoc = modifystream.GetWordprocessingDocument();
Power.TextReplacer.SearchAndReplace(modifywDoc, "{$}", prefix + (QuestionNum++).ToString() , false);
sources.Add(new Power.Source(modifystream.GetModifiedWmlDocument(), false));
}
sources.Add(new Power.Source(new Power.WmlDocument(CurrQuiz.QuizTemplateId, footer), false));
Power.WmlDocument FinalDoc = Power.DocumentBuilder.BuildDocument(sources);
string OutDocFile = SettingInfo.OutputFolder + @"\"+ CurrQuiz.QuizCode.ToString() + ".docx";
string OutPdfFile = SettingInfo.OutputFolder + @"\"+ CurrQuiz.QuizCode.ToString() + ".pdf";
FinalDoc.SaveAs(OutDocFile);
Utilities.ConverttoPdf(OutDocFile, OutPdfFile);
Forms.frmPDFViewer frm = new Forms.frmPDFViewer();
frm.pdffile = OutPdfFile;
frm.LoadData();
frm.Show();
}
public static void PrintQuizAnswer(TblQuizEntity CurrQuiz)
{
List<Power.Source> sources = new List<Power.Source>();
string SubjectId = "xxxx";
string FieldId = "xxxx";
int QuestionNum = 1;
Boolean Renumering = false;
string prefix = "";
LinqMetaData meta = new LinqMetaData(new DataAccessAdapter());
byte[] header = Convert.FromBase64String(meta.TblQuizTemplate.Where(m => m.QuizTemplateId == CurrQuiz.QuizTemplateId).FirstOrDefault().HeaderDes);
Power.WmlDocument headercon = new Power.WmlDocument(Guid.NewGuid().ToString("N"), header);
Power.OpenXmlMemoryStreamDocument modifystream = new Power.OpenXmlMemoryStreamDocument(headercon);
WordprocessingDocument modifywDoc = modifystream.GetWordprocessingDocument();
Power.TextReplacer.SearchAndReplace(modifywDoc, "{year}", CurrQuiz.QuizYear.ToString(), false);
Power.TextReplacer.SearchAndReplace(modifywDoc, "{QuizCode}", CurrQuiz.QuizCode, false);
Power.TextReplacer.SearchAndReplace(modifywDoc, "{QuizTime}", CurrQuiz.QuizTime.ToString(), false);
sources.Add(new Power.Source(modifystream.GetModifiedWmlDocument(), false));
byte[] footer = Convert.FromBase64String(meta.TblQuizTemplate.Where(m => m.QuizTemplateId == CurrQuiz.QuizTemplateId).FirstOrDefault().FooterDes);
Renumering = meta.TblQuizTemplate.Where(m => m.QuizTemplateId == CurrQuiz.QuizTemplateId).FirstOrDefault().Renumering;
var result = (from q in meta.TblQuestion join m in meta.TblQuizQuestion.Where(m => m.QuizId == CurrQuiz.QuizId) on q.QuestionId equals m.QuestionId select new { SubjectId = q.SubjectId, FieldID = q.FieldId, con = q.Answer}).ToList().OrderBy(m => m.SubjectId).ThenBy(m => m.FieldID).ToList();
foreach (var q in result)
{
if (q.SubjectId != SubjectId)
{
SubjectId = q.SubjectId;
QuestionNum = 1;
byte[] SubjectDes = Convert.FromBase64String(meta.TblSubject.Where(m => m.SubjectId == q.SubjectId).FirstOrDefault().SubjectDes);
sources.Add(new Power.Source(new Power.WmlDocument(Guid.NewGuid().ToString("N"), SubjectDes), false));
}
if (q.FieldID != FieldId)
{
FieldId = q.FieldID;
if (Renumering) QuestionNum = 1;
prefix = meta.TblField.Where(m => m.SubjectId == q.SubjectId).Where(m => m.FieldId == FieldId).FirstOrDefault().Prefix;
byte[] FieldDes = Convert.FromBase64String(meta.TblField.Where(m => m.SubjectId == q.SubjectId).Where(m => m.FieldId == q.FieldID).FirstOrDefault().Description);
sources.Add(new Power.Source(new Power.WmlDocument(Guid.NewGuid().ToString("N"), FieldDes), false));
}
string prefixTemplate = Sys.Application.StartupPath + @"/templates/prefix.docx";
Power.WmlDocument con = new Power.WmlDocument(prefixTemplate);
modifystream = new Power.OpenXmlMemoryStreamDocument(con);
modifywDoc = modifystream.GetWordprocessingDocument();
Power.TextReplacer.SearchAndReplace(modifywDoc, "question", prefix + (QuestionNum++).ToString(), false);
sources.Add(new Power.Source(modifystream.GetModifiedWmlDocument(), false));
byte[] buf = Convert.FromBase64String(q.con);
Power.WmlDocument ans = new Power.WmlDocument(Guid.NewGuid().ToString("N"), buf);
sources.Add(new Power.Source(ans, false));
}
//sources.Add(new Power.Source(new Power.WmlDocument(CurrQuiz.QuizTemplateId, footer), false));
Power.WmlDocument FinalDoc = Power.DocumentBuilder.BuildDocument(sources);
string OutDocFile = SettingInfo.OutputFolder + @"\A" + CurrQuiz.QuizCode.ToString() + ".docx";
string OutPdfFile = SettingInfo.OutputFolder + @"\A" + CurrQuiz.QuizCode.ToString() + ".pdf";
FinalDoc.SaveAs(OutDocFile);
Utilities.ConverttoPdf(OutDocFile, OutPdfFile);
Forms.frmPDFViewer frm = new Forms.frmPDFViewer();
frm.pdffile = OutPdfFile;
frm.LoadData();
frm.Show();
}
}
}

View File

@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
namespace Omega
{
internal static class common
{
public static DateTime testdate { get; set; }
public static DateTime visitdate { get; set; }
public static DateTime MaxDate(DateTime a, DateTime b)
{
return a > b ? a : b;
}
public static DateTime MinDate(DateTime a, DateTime b)
{
return a > b ? b : a;
}
public static string MD5Hash(string text)
{
MD5 md5 = new MD5CryptoServiceProvider();
//compute hash from the bytes of text
md5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(text));
//get hash result after compute it
byte[] result = md5.Hash;
StringBuilder strBuilder = new StringBuilder();
for (int i = 0; i < result.Length; i++)
{
//change it into 2 hexadecimal digits
//for each byte
strBuilder.Append(result[i].ToString("x2"));
}
return strBuilder.ToString();
}
}
}

View File

@@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Windows.Forms;
using System.Configuration;
using System.Collections;
namespace Omega
{
public class SettingInfo
{
private static XmlDocument doc = new XmlDocument();
public static string OutputFolder { get; set; }
public static string BackupFolder { get; set; }
public static string Password { get; set; }
public static string DatabaseFile { get; set; }
public static string UserName { get; set; }
public static string Exclusive {get;set;}
public static string InstallId { get; set; }
public static string RegisterNo {get;set;}
public static Boolean Registered { get; set; }
public static int MinQuestionNum { get; set; }
public static void InitInfo()
{
getValues();
}
public static void getValues()
{
try
{
var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
string value = config.AppSettings.Settings["ConnectionString.MS Access (OleDb)"].Value;
string[] values = value.Split(new char[] { ';' });
string DataSource = values[1];
DatabaseFile = DataSource.Split(new char[] { '=' })[1];
OutputFolder = config.AppSettings.Settings["OutputFolder"].Value;
BackupFolder = config.AppSettings.Settings["BackupFolder"].Value;
Exclusive = config.AppSettings.Settings["Exclusive"].Value;
InstallId = Omega.FingerPrint.Value().Trim();
RegisterNo = config.AppSettings.Settings["RegisterNo"].Value;
Registered = (common.MD5Hash(InstallId.Trim().ToString()).ToUpper() == RegisterNo);
MinQuestionNum = Convert.ToInt32(config.AppSettings.Settings["MinQuestionNum"].Value);
}
catch
{
}
}
}
}