当前位置:   article > 正文

使用VisualStudio软件,SQLServer数据库,powerdesigner软件设计,后端语言c#,从数据库字段到写数据库表到数据接口到页面展示完整流程_visual stadio开发工具,sql做后台数据库,前端用html+css

visual stadio开发工具,sql做后台数据库,前端用html+css

1.使用powerdesigner软件设计数据库字段

    1)powerdesigner软件的General是编写表中英文名的,想清楚要设计服务状态表需要的字段,在Columns中编写字段;

      2)设计子服务状态表需要的字段(同上),并且两者需要有关联,比如这两个表是通过ServiceId这个字段来进行联系;

      3)在Preview下方可以获取服务状态表的SQL语句,可以直接拿到SQL Server中建表;     4)获取子服务状态表的SQL语句(同上);

   5)两个表建成以后的样子;

2. 在数据库中执行,创建表

     1)将Preview下获取服务状态表的SQL语句复制到SQLServe数据库中,创建服务状态表;

  1. drop table if exists s_servicestatustable;
  2. /*==============================================================*/
  3. /* Table: s_servicestatustable */
  4. /*==============================================================*/
  5. create table s_servicestatustable
  6. (
  7. ServiceId varchar(36) not null,
  8. ServiceName varchar(50),
  9. ServiceStatus int,
  10. ServiceOperation varchar(50),
  11. ServiceProcessTime varchar(20),
  12. ServiceRefreshTime varchar(20),
  13. primary key (ServiceId)
  14. );

    2)选中建好的表,右键---设计,编写服务器状态表内容;

    3)创建子服务状态表(获取人员表d_futuresaccount中的一些内容,并使用as修改列名,条件是status为1的);

  1. SELECT
  2. '03358964-b6e9-42a6-b807-27b5b7846f2c' as ServiceId ,
  3. NewID() as SonServeId ,
  4. (investorid+'-'+brokerid) as SonServeName,
  5. 0 as SonServeStatus,
  6. '0' as SonServeOperation,
  7. '2022-11-08 14:02:10' as SonServeProcessTime,
  8. '2022-11-08 09:02:10' as SonServeRefreshTime,
  9. investorid as accountnumber,
  10. brokerid as brokerid
  11. INTO [dbo].[s_sonservicestatustable]
  12. FROM [d_futuresaccount] where [status] = 1;

    4)或者创建子表也可以使用另一种方式:

 先创建子服务状态表

  1. drop table if exists s_sonservicestatustable;
  2. /*==============================================================*/
  3. /* Table: s_sonservicestatustable */
  4. /*==============================================================*/
  5. create table s_sonservicestatustable
  6. (
  7. ServiceId varchar(36),
  8. SonServeId int not null,
  9. SonServeName varchar(50),
  10. SonServeStatus int,
  11. SonServeOperation varchar(50),
  12. SonServeProcessTime varchar(20),
  13. SonServeRefreshTime varchar(20),
  14. accountnumber varchar(20),
  15. brokerid varchar(20),
  16. primary key (SonServeId)
  17. );

在往子服务状态表里插入信息;

  1. insert into [dbo].[s_sonservicestatustable]([ServiceId],[SonServeId],[SonServeName],[SonServeStatus],[SonServeOperation],[SonServeProcessTime],[SonServeRefreshTime],[accountnumber],[brokerid])
  2. (select '03355564-b6e9-42a6-b807-27b5b7846f2c',
  3. NEWID(),
  4. (select [dictname]+'-'+[investorid] from [dbo].[s_dictionary] where [dictcode]=[brokerid]),
  5. 0,
  6. 0,
  7. '20221109 9:48:57',
  8. '20221109 14:24:25',
  9. [investorid],
  10. [brokerid]
  11. from [dbo].[d_futuresaccount])

将sa建立权限给mark,右键属性---权限--搜索--浏览---选择mark

 

 

 选择权限,除了接管所有权和控制,其他都勾上;

 

3.使用视图对子服务表进行关联,d_futuresaccount为主表,

将b_employees表中的worknumber与d_futuresaccount表中的worknumber进行关联;并显示b_employees表中的name,d_futuresaccount表中的worknumber;

将d_futuresaccount表中的investorid与s_sonservicestatustable表中的accountnumber进行关联;

将d_futuresaccount表中的brokerid与s_sonservicestatustable表中的brokerid进行关联;

并显示s_sonservicestatustable表中的所有信息;

d_futuresaccount表中的信息来自s_sonservicestatustable表;

将s_dictionary表中的dictcode与s_sonservicestatustable表中的brokerid进行关联;并显示dictname;

s_dictionary表中的信息来自s_sonservicestatustable表;

将dicttype筛选器设置为=期货公司;

 视图关联后形成的SQL语句;

  1. SELECT dbo.s_sonservicestatustable.ServiceId, dbo.s_sonservicestatustable.SonServeId,
  2. dbo.s_sonservicestatustable.SonServeName, dbo.s_sonservicestatustable.SonServeStatus,
  3. dbo.s_sonservicestatustable.SonServeOperation, dbo.s_sonservicestatustable.SonServeProcessTime,
  4. dbo.s_sonservicestatustable.SonServeRefreshTime, dbo.s_sonservicestatustable.accountnumber,
  5. dbo.s_sonservicestatustable.brokerid, dbo.d_futuresaccount.worknumber, dbo.b_employees.name,
  6. dbo.s_dictionary.dictname
  7. FROM dbo.s_dictionary RIGHT OUTER JOIN
  8. dbo.s_sonservicestatustable ON dbo.s_dictionary.dictcode = dbo.s_sonservicestatustable.brokerid LEFT OUTER JOIN
  9. dbo.b_employees INNER JOIN
  10. dbo.d_futuresaccount ON dbo.b_employees.worknumber = dbo.d_futuresaccount.worknumber ON
  11. dbo.s_sonservicestatustable.accountnumber = dbo.d_futuresaccount.investorid AND
  12. dbo.s_sonservicestatustable.brokerid = dbo.d_futuresaccount.brokerid
  13. WHERE (dbo.s_dictionary.dicttype = '期货公司')

整体格式如下:

 到此数据库设计完成;

将sa的视图权限给mark,右键属性---权限--搜索--浏览---选择mark后,勾选如下选项:查看定义、选择、引用;

 

 

5.使用VisualStudio软件进行如下操作,

     1)IYHLHService.cs文件中声明一个方法;

  1. /// <summary>
  2. /// 获取服务器所有信息
  3. /// </summary>
  4. /// <returns></returns>
  5. [OperationContract]
  6. DataTable AccountStatus();
  7. /// <summary>
  8. /// 获取子服务器所有信息
  9. /// </summary>
  10. /// <returns></returns>
  11. [OperationContract]
  12. DataTable SonAccountStatus();

    2)在YHLHService.cs中使用,获取服务器所有信息,需要右键--生成网站进行编译;

  1. / <summary>
  2. / 获取服务器所有信息
  3. / 声明一个ds实体集,用于存放SQL语句查询到的数据
  4. / dh声明 引用DataHelper中的方法
  5. / dt声明 因为是DataTable类型的所以需要声明一下
  6. / 对ds获取到的信息进行非空判断
  7. / </summary>
  8. / <returns></returns>
  9. public DataTable AccountStatus()
  10. {
  11. DataSet ds = new DataSet();
  12. DataHelper dh = new DataHelper();
  13. DataTable dt = new DataTable();
  14. string sqlstring = @"SELECT * FROM [dbo].[s_servicestatustable]";
  15. ds = dh.GetDataSet(sqlstring);
  16. if (ds != null && ds.Tables != null)
  17. {
  18. dt = ds.Tables[0];
  19. }
  20. return dt;
  21. }
  22. / <summary>
  23. / 获取子服务器所有信息
  24. / </summary>
  25. / <returns></returns>
  26. public DataTable SonAccountStatus()
  27. {
  28. DataSet ds = new DataSet();
  29. DataHelper dh = new DataHelper();
  30. DataTable dt = new DataTable();
  31. string sqlstring = @"select * from [dbo].[s_sonservicestatustable]";
  32. ds = dh.GetDataSet(sqlstring);
  33. if (ds != null && ds.Tables != null)
  34. {
  35. dt = ds.Tables[0];
  36. }
  37. return dt;
  38. }

    3)在Entity.cs中声明变量名,

  1. /// <summary>
  2. /// 服务器信息
  3. /// </summary>
  4. public class ServeAccount
  5. {
  6. public string ServiceId;
  7. public string ServiceName;
  8. public int ServiceStatus;
  9. public string ServiceOperation;
  10. public string ServiceProcessTime;
  11. public string ServiceRefreshTime;
  12. }
  13. /// <summary>
  14. /// 子服务器信息
  15. /// </summary>
  16. public class SonServeAccount
  17. {
  18. public string ServiceId;
  19. public string SonServeId;
  20. public string SonServeName;
  21. public int SonServeStatus;
  22. public string SonServeOperation;
  23. public string SonServeProcessTime;
  24. public string SonServeRefreshTime;
  25. public string accountnumber;
  26. public string brokerid;
  27. }

对该文件进行更新服务引用;

    4) 在LocalService中获取变量,进行操作,做完之后,进行右键--发布网站编译;

  1. /// <summary>
  2. /// 服务器所有信息
  3. /// </summary>
  4. /// <returns></returns>
  5. [WebMethod]
  6. public string AccountStatus()
  7. {
  8. DataTable dt = service.AccountStatus();
  9. List<ServeAccount> accountstatuslist = new List<ServeAccount>();
  10. if (dt != null && dt.Rows.Count > 0)
  11. {
  12. for(int i = 0; i < dt.Rows.Count; i++)
  13. {
  14. ServeAccount accountstatus = new ServeAccount();
  15. accountstatus.ServiceId = dt.Rows[i]["ServiceId"].ToString();
  16. accountstatus.ServiceName = dt.Rows[i]["ServiceName"].ToString();
  17. accountstatus.ServiceStatus = int.Parse(dt.Rows[i]["ServiceStatus"].ToString());
  18. accountstatus.ServiceOperation = dt.Rows[i]["ServiceOperation"].ToString();
  19. accountstatus.ServiceProcessTime = dt.Rows[i]["ServiceProcessTime"].ToString();
  20. accountstatus.ServiceRefreshTime = dt.Rows[i]["ServiceRefreshTime"].ToString();
  21. accountstatuslist.Add(accountstatus);
  22. }
  23. }
  24. string strjson = JsonConvert.SerializeObject(accountstatuslist);
  25. return strjson;
  26. }
  27. /// <summary>
  28. /// 子服务器所有信息
  29. /// </summary>
  30. /// <returns></returns>
  31. [WebMethod]
  32. public string SonAccountStatus()
  33. {
  34. DataTable dt = service.SonAccountStatus();
  35. List<SonServeAccount> sonaccountstatuslist = new List<SonServeAccount>();
  36. if (dt != null && dt.Rows.Count > 0)
  37. {
  38. for (int i = 0; i < dt.Rows.Count; i++)
  39. {
  40. SonServeAccount sonaccountstatus = new SonServeAccount();
  41. sonaccountstatus.ServiceId = dt.Rows[i]["ServiceId"].ToString();
  42. sonaccountstatus.SonServeId = dt.Rows[i]["SonServeId"].ToString();
  43. sonaccountstatus.SonServeName = dt.Rows[i]["SonServeName"].ToString();
  44. sonaccountstatus.SonServeStatus = int.Parse(dt.Rows[i]["SonServeStatus"].ToString());
  45. sonaccountstatus.SonServeOperation = dt.Rows[i]["SonServeOperation"].ToString();
  46. sonaccountstatus.SonServeProcessTime = dt.Rows[i]["SonServeProcessTime"].ToString();
  47. sonaccountstatus.SonServeRefreshTime = dt.Rows[i]["SonServeRefreshTime"].ToString();
  48. sonaccountstatus.accountnumber = dt.Rows[i]["accountnumber"].ToString();
  49. sonaccountstatus.brokerid = dt.Rows[i]["brokerid"].ToString();
  50. sonaccountstatuslist.Add(sonaccountstatus);
  51. }
  52. }
  53. string strjson = JsonConvert.SerializeObject(sonaccountstatuslist);
  54. return strjson;
  55. }

    5)html编写页面

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8" />
  5. <title></title>
  6. <link href="../../css/basic.css" rel="stylesheet" />
  7. <link rel="stylesheet" href="../../lib/bootstrap/css/bootstrap.css" media="all" />
  8. <script type="text/javascript" src="../../js/jquery-1.8.3.js" charset="utf-8"></script>
  9. <script type="text/javascript" src="../../js/jquery-jtemplates.js" charset="utf-8"></script>
  10. <script type="text/javascript" src="../../js/jquery.min.js" charset="utf-8"></script>
  11. <link href="../../lib/layui-v2.6.8/layui/css/layui.css" rel="stylesheet" />
  12. <script src="../../lib/layui-v2.6.8/layui/layui.js"></script>
  13. <script src="../../js/sysinfo.js"></script>
  14. <link href="../../css/AccountStatus/AccountStatus.css" rel="stylesheet" />
  15. <script src="../../js/AccountStatus/AccountStatus.js"></script>
  16. </head>
  17. <body>
  18. <div id="mangerdiv">
  19. <h3>我管理的账户</h3>
  20. <hr />
  21. <div id="accout">
  22. <ul>
  23. <li><h3>服务器状态</h3></li>
  24. <li><h3 class="layui-btn" id="servestatus">在线</h3></li>
  25. <li><h3 class="layui-btn layui-btn-primary layui-border-black">离线</h3></li>
  26. <li><h3 class="layui-btn layui-btn-primary layui-border-black">重启</h3></li>
  27. </ul>
  28. <ul>
  29. <li>所有账户</li>
  30. <li>在线账户数</li>
  31. <li>离线账户数</li>
  32. <li>添加新账户</li>
  33. </ul>
  34. <ul>
  35. <li><h2>10</h2></li>
  36. <li><h2>8</h2></li>
  37. <li><h2>2</h2></li>
  38. <li>
  39. <div class="layui-btn-group">
  40. <button type="button" class="layui-btn layui-btn-primary layui-btn-sm">
  41. <i class="layui-icon">&#xe654;</i>
  42. </button>
  43. </div>
  44. </li>
  45. </ul>
  46. </div>
  47. </div>
  48. <div id="tablediv">
  49. <table class="layui-table col-sm-4">
  50. <colgroup>
  51. <col width="150">
  52. <col width="200">
  53. <col>
  54. </colgroup>
  55. <thead id="thead">
  56. <tr>
  57. <th>账户id</th>
  58. <th>姓名</th>
  59. <th>状态</th>
  60. </tr>
  61. </thead>
  62. <tbody>
  63. <tr>
  64. <td>123456</td>
  65. <td></td>
  66. <td id="status">
  67. <ul>
  68. <li><button class="layui-btn layui-btn-radius">在线</button></li>
  69. <li><button class="layui-btn layui-btn-radius layui-btn-primary">离线</button></li>
  70. <li><button class="layui-btn layui-btn-radius layui-btn-primary">重新连接</button></li>
  71. </ul>
  72. </td>
  73. </tr>
  74. <tr>
  75. <td>123</td>
  76. <td>钱1</td>
  77. <td id="status">
  78. <ul>
  79. <li><button class="layui-btn layui-btn-radius layui-btn-primary">在线</button></li>
  80. <li><button class="layui-btn layui-btn-radius layui-btn-danger">离线</button></li>
  81. <li><button class="layui-btn layui-btn-radius layui-btn-normal">重新连接</button></li>
  82. </ul>
  83. </td>
  84. </tr>
  85. <tr>
  86. <td>12323</td>
  87. <td>钱2</td>
  88. <td id="status">
  89. <ul>
  90. <li><button class="layui-btn layui-btn-radius">在线</button></li>
  91. <li><button class="layui-btn layui-btn-radius layui-btn-primary">离线</button></li>
  92. <li><button class="layui-btn layui-btn-radius layui-btn-primary">重新连接</button></li>
  93. </ul>
  94. </td>
  95. </tr>
  96. <tr>
  97. <td>12367</td>
  98. <td>钱3</td>
  99. <td id="status">
  100. <ul>
  101. <li><button class="layui-btn layui-btn-radius">在线</button></li>
  102. <li><button class="layui-btn layui-btn-radius layui-btn-primary">离线</button></li>
  103. <li><button class="layui-btn layui-btn-radius layui-btn-primary">重新连接</button></li>
  104. </ul>
  105. </td>
  106. </tr>
  107. </tbody>
  108. </table>
  109. </div>
  110. </body>
  111. </html>

   6)css中编写样式

  1. #thead tr th {
  2. vertical-align: middle;
  3. text-align: center;
  4. }
  5. #tablediv {
  6. width: 50%;
  7. text-align: center;
  8. }
  9. #mangerdiv {
  10. width: 50%;
  11. text-align: center;
  12. }
  13. #mangerdiv h3 {
  14. margin-top: 10px;
  15. }
  16. #accout ul {
  17. margin: 10px;
  18. display: flex;
  19. }
  20. #accout ul li {
  21. float: left;
  22. flex: 1;
  23. }
  24. #accout ul:nth-child(2) {
  25. margin-top: 10px;
  26. }
  27. #status ul {
  28. display: flex;
  29. }
  30. #status ul li {
  31. float: left;
  32. flex: 1;
  33. /*text-align: center;*/
  34. }
  35. #status li:first-child {
  36. color: green;
  37. }
  38. #status li:nth-child(2) {
  39. color: #ccc;
  40. }
  41. #status li:nth-child(3) {
  42. color: red;
  43. }

      7)在js使用ajax进行接收文件;

  1. jQuery.extend({
  2. serveload: function () {
  3. var jsonObj;//接收数据
  4. $.ajax({
  5. type: 'POST',
  6. dataType: 'JSON',
  7. contentType: 'application/json; charset=utf-8',
  8. async: false,
  9. cache: false,
  10. url: urlstr + "View/LocalService/LocalService.asmx/AccountStatus",
  11. //传递的参数
  12. data: JSON.stringify({
  13. }),
  14. success: function (data) {
  15. jsonObj = JSON.parse(data.d);
  16. console.log(jsonObj);
  17. },
  18. error: function (XMLHttpRequest, textStatus, errorThrown) {
  19. alert("一般性网络问题,请求数据错误。");
  20. //alert(XMLHttpRequest.status);
  21. //alert(XMLHttpRequest.readyState);
  22. //alert(textStatus);
  23. }
  24. });
  25. },
  26. sonserveload: function () {
  27. var jsonObj;//接收数据
  28. $.ajax({
  29. type: 'POST',
  30. dataType: 'JSON',
  31. contentType: 'application/json; charset=utf-8',
  32. async: false,
  33. cache: false,
  34. url: urlstr + "View/LocalService/LocalService.asmx/SonAccountStatus",
  35. //传递的参数
  36. data: JSON.stringify({
  37. }),
  38. success: function (data) {
  39. jsonObj = JSON.parse(data.d);
  40. console.log("子服务器信息:",jsonObj);
  41. },
  42. error: function (XMLHttpRequest, textStatus, errorThrown) {
  43. alert("一般性网络问题,请求数据错误。");
  44. //alert(XMLHttpRequest.status);
  45. //alert(XMLHttpRequest.readyState);
  46. //alert(textStatus);
  47. }
  48. });
  49. }
  50. });
  51. //事件
  52. $(document).ready(function () {
  53. })
  54. $(function () {
  55. $.serveload();
  56. $.sonserveload();
  57. });

就可以获取到数据了

最终展示效果

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/668847
推荐阅读
相关标签
  

闽ICP备14008679号