Form1.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using SqlSugar;
  11. using HXX.Scanner.Database;
  12. namespace test_db
  13. {
  14. public partial class Form1 : Form
  15. {
  16. public Form1()
  17. {
  18. InitializeComponent();
  19. }
  20. SqlSugarClient db;
  21. private void Form1_Load(object sender, EventArgs e)
  22. {
  23. try
  24. {
  25. db = SqlSugarHelper.GetClient();
  26. }
  27. catch (Exception ee)
  28. {
  29. MessageBox.Show(ee.Message);
  30. }
  31. }
  32. private void button1_Click(object sender, EventArgs e)
  33. {
  34. try
  35. {
  36. create_entity("tb_file_info");
  37. }
  38. catch (Exception ee)
  39. {
  40. MessageBox.Show(ee.Message);
  41. }
  42. }
  43. private string create_entity(string entityName)
  44. {
  45. try
  46. {
  47. if (entityName == null)
  48. {
  49. return "参数不能为空!";
  50. }
  51. else
  52. {
  53. string filePath = Application.StartupPath;
  54. db.DbFirst.IsCreateAttribute().IsCreateDefaultValue().Where(entityName).CreateClassFile(filePath, "HXX.Scanner.Database");
  55. return "操作成功!";
  56. }
  57. }
  58. catch (Exception ee)
  59. {
  60. return "请求失败!";
  61. }
  62. }
  63. private void button2_Click(object sender, EventArgs e)
  64. {
  65. try
  66. {
  67. var list = db.Queryable<tb_file_info>().ToList();
  68. }
  69. catch (Exception ee)
  70. {
  71. MessageBox.Show(ee.Message);
  72. }
  73. }
  74. }
  75. }