UserSTDDbData.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using OTSIncAReportApp.DataOperation.DataAccess;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace OTSIncAReportApp._2_CommonFunction.CommonClass
  9. {
  10. internal class UserSTDDbData
  11. {
  12. private SqlHelper dbHelper;
  13. public UserSTDDbData(string STDDbName, string resultpath)
  14. {
  15. NLog.Logger log = NLog.LogManager.GetCurrentClassLogger();
  16. if (!STDDbName.Contains(".db"))
  17. {
  18. STDDbName += ".db";
  19. }
  20. if (STDDbName.ToLower() == "nostddb.db")
  21. {
  22. dbHelper = null;
  23. log.Error("Failed to load user-defined library" + "!");
  24. }
  25. string fullPath = resultpath + STDDbName;
  26. string fullPath2 = System.IO.Directory.GetCurrentDirectory() + "\\Config\\SysData\\" + STDDbName;
  27. if (System.IO.File.Exists(fullPath))
  28. {
  29. dbHelper = new SqlHelper("data source='" + fullPath + "'");
  30. log.Warn("Loading the user standard library:" + fullPath + "!");
  31. }
  32. else if (System.IO.File.Exists(fullPath2))
  33. {
  34. dbHelper = new SqlHelper("data source='" + fullPath2 + "'");
  35. log.Warn("Loading the user standard library:" + fullPath2 + "!");
  36. }
  37. else
  38. {
  39. dbHelper = null;
  40. log.Error("Failed to load user-defined library" + "!");
  41. }
  42. }
  43. public DataTable GetSubAttributeFromDatabase()
  44. {
  45. string sqliteString = "select STDId,Hardness,Density,Electrical_conductivity from ClassifySTD";
  46. DataTable DT = new DataTable();
  47. DT = dbHelper.ExecuteQuery(sqliteString);
  48. return DT;
  49. }
  50. public SqlHelper GetSqlHelper() { return dbHelper; }
  51. }
  52. }