UserDataRecorder.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using Aitex.Core.RT.DBCore;
  2. using Aitex.Sorter.Common;
  3. using DocumentFormat.OpenXml.Drawing.Charts;
  4. using DocumentFormat.OpenXml.Spreadsheet;
  5. using MECF.Framework.Common.ControlDataContext;
  6. using MECF.Framework.Common.Equipment;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Data;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using Venus_Core;
  14. namespace MECF.Framework.Common.DBCore
  15. {
  16. public class UserDataRecorder
  17. {
  18. public static void InserUser(UserItem userItem)
  19. {
  20. string sql = string.Format(
  21. "INSERT INTO \"user\" (" +
  22. "\"UserName\"," +
  23. "\"Role\"," +
  24. "\"Password\"," +
  25. "\"Notes\"" +
  26. ") VALUES (" +
  27. $"'{userItem.Name}'," +
  28. $"'{userItem.Role}'," +
  29. $"'{userItem.Password}'," +
  30. $"'{userItem.Notes}'" +
  31. ");");
  32. DB.Insert(sql);
  33. }
  34. public static void DeleteUser(string userName)
  35. {
  36. string sql = string.Format(
  37. "DELETE FROM \"user\" where \"UserName\"=" +
  38. $"'{userName}'" +
  39. ";");
  40. DB.Insert(sql);
  41. }
  42. public static List<UserItem> GetUserItems()
  43. {
  44. List<UserItem> result = new List<UserItem>();
  45. string sql = string.Format($"SELECT * FROM \"user\"");
  46. DataSet ds = DB.ExecuteDataset(sql);
  47. for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
  48. {
  49. result.Add(new UserItem()
  50. {
  51. No =Convert.ToInt32( ds.Tables[0].Rows[i]["No"]),
  52. Name= ds.Tables[0].Rows[i]["UserName"].ToString(),
  53. Role = ds.Tables[0].Rows[i]["Role"].ToString(),
  54. Password= ds.Tables[0].Rows[i]["Password"].ToString(),
  55. Notes= ds.Tables[0].Rows[i]["Notes"].ToString()
  56. });
  57. }
  58. ds.Clear();
  59. return result;
  60. }
  61. }
  62. }