-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaspnetcore.txt
6761 lines (5554 loc) · 265 KB
/
aspnetcore.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1、https://github.com/dotnet/aspnetcore
https://github.com/dotnet/blazor-samples
https://github.com/microsoft/fluentui-blazor
https://learn.microsoft.com/zh-cn/ef/core/modeling/
https://www.nuget.org/
github Yuan1877008@
fastgithub_win-x64
2、使用 Blazor 利用 ASP.NET Core 生成第一个 Web 应用
2.1、centos8 安装.NET8 SDK
在CentOS 8上安装.NET 8 SDK,您可以按照以下步骤操作:
启用.NET 8的官方Microsoft密钥和存储库。
安装.NET 8 SDK。
以下是具体的命令:
# 1. 设置Microsoft密钥和存储库
sudo rpm -Uvh https://packages.microsoft.com/config/centos/8/packages-microsoft-prod.rpm
# 2. 安装.NET SDK
sudo dnf install dotnet-sdk-8.0
sudo dnf install dotnet-sdk-9.0
执行上述命令后,.NET 8 SDK将在CentOS 8系统上安装。您可以通过运行dotnet --version来验证安装是否成功。
2.2、创建应用
在终端中,运行以下命令来创建应用:
Command prompt
dotnet new blazor -o BlazorApp
此命令创建新 Blazor Web 应用项目,并将其放置在当前位置内名为 BlazorApp 的新目录中。
导航到由上一条命令创建的新 BlazorApp 目录:
Command prompt
cd BlazorApp
快速查看 BlazorApp 目录的内容。
ls
BlazorApp 目录中已经创建了多个文件,为你提供一个可以运行的简单的 Blazor 应用。
Program.cs 是启动服务器以及在其中配置应用服务和中间件的应用的入口点。
在 Components 目录中:
App.razor 为应用的根组件。
Routes.razor 配置 Blazor 路由器。
Pages 目录包含应用的一些示例网页。
BlazorApp.csproj 定义应用项目及其依赖项。
Properties 目录中的 launchSettings.json 文件为本地开发环境定义不同的配置文件设置。创建项目时会自动分配端口号并将其保存在此文件上。
请记下 BlazorApp 目录路径,因为教程后面会用到。
如果一切正常,请选择下面的 继续 按钮以转到下一步。
2.3、开放5246端口,并修改Properties 目录中的 launchSettings.json 文件里的http://localhost:5246为http://1.26:5246
[root@cpzljc BlazorApp]# firewall-cmd --list-port
[root@cpzljc BlazorApp]# firewall-cmd --zone=public --add-port=5246/tcp --permanent
[root@cpzljc BlazorApp]# systemctl restart firewalld
[root@cpzljc BlazorApp]# firewall-cmd --list-port
2.4、 运行应用
在终端中,运行以下命令:
Command prompt
dotnet watch
dotnet watch 命令将生成并启动应用,然后在每次更改代码时更新应用。可以选择Ctrl+C,以随时停止应用。
等待应用显示正在侦听 http://localhost:<port number> 然后打开浏览器并导航到该地址。
转到以下页面后,你已成功运行了第一个 Blazor 应用!
站点主页包含一些文本,并在左侧显示了多个选项卡,供你点击和浏览。
显示的页面由位于 Components/Pages 目录内的 Home.razor 文件定义。其内容如下所示:
Components/Pages/Home.razor
@page "/"
<PageTitle>Home</PageTitle>
<h1>Hello, world!</h1>
Welcome to your new app.
它已包含将它设置为主页的代码,并显示文本Hello, world! 和 Welcome to your new app。PageTitle 组件会设置当前页面的标题,使其显示在浏览器选项卡中。
2.5、 ant-design-blazor
https://github.com/ant-design-blazor/ant-design-blazor
https://github.com/MudBlazor/MudBlazor
https://mudblazor.com/
https://github.com/MudBlazor/Templates
https://github.com/CodeBeamOrg/CodeBeam.MudBlazor.Extensions
https://mudextensions.codebeam.org/
2.6、 Blazor for ASP.NET Web Forms开发人员电子书: https://learn.microsoft.com/zh-cn/dotnet/architecture/blazor-for-web-forms-developers/
2.7、 在centos8上安装visual studio code
在CentOS 8上安装Visual Studio Code可以通过以下步骤进行:
更新系统软件包列表:
sudo dnf update
安装必要的依赖:
sudo dnf install -y yum-utils
设置微软的软件仓库:
sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
sudo dnf config-manager --add-repo https://packages.microsoft.com/yumrepos/vscode
安装Visual Studio Code:
sudo dnf install -y code
安装完成后,你可以通过命令行启动Visual Studio Code,或者通过桌面环境的应用菜单查找并启动它。
3、 centos8 查询端口运行进程,关闭进程
在CentOS 8上,您可以使用ss或netstat命令来查找端口运行的进程,并使用kill命令来关闭进程。以下是具体的命令示例:
查询端口运行的进程:
# 使用ss命令查找特定端口(例如:8080)的进程
ss -ltnp | grep ':8080'
# 或者使用netstat命令
netstat -ltnp | grep ':8080'
关闭端口运行的进程:
# 假设查询结果显示进程ID为1234
kill 1234
# 如果进程不响应,可以使用强制选项
kill -9 1234
请确保您有足够的权限执行这些操作,通常需要root权限。如果没有,请使用sudo前缀来提升权限。
4、 /opt/aspnetcore/BlazorApp/DatabaseUtility.cs(1,17): error CS0234: 命名空间“Microsoft”中不存在类型或命名空间名“EntityFrameworkCore”(是否缺少程序集引用?) [/opt/aspnetcore/BlazorApp/BlazorApp.csproj]
-》 centos8 安装EntityFrameworkCore
在CentOS 8上安装EntityFrameworkCore,你需要使用.NET Core SDK。以下是安装EntityFrameworkCore的步骤:
安装.NET Core SDK:
访问官方.NET Core下载页面(https://dotnet.microsoft.com/download),选择CentOS 8的适当包进行安装。
安装完成后,打开终端并运行以下命令以安装EntityFrameworkCore包:
dotnet tool install --global dotnet-ef
使用以下命令来更新EntityFrameworkCore工具:
dotnet tool update --global dotnet-ef
在你的.NET Core项目中,使用以下命令来安装EntityFrameworkCore:
dotnet add package Microsoft.EntityFrameworkCore
如果你需要安装特定的数据库提供程序,比如Pomelo EntityFrameworkCore MySQL提供程序,你可以使用以下命令:
dotnet add package Pomelo.EntityFrameworkCore.MySql
请确保你的CentOS 8系统已经开启了网络连接,并且能够访问.NET Core的包管理服务。如果遇到任何依赖问题,请确保你的包管理器(如NuGet)是最新版本,并且已经正确配置。
5、 EntityFrameworkCore 连接mysql数据库的方法
在使用EntityFrameworkCore连接MySQL数据库时,你需要安装相应的数据库提供程序包。以下是安装和配置的步骤:
安装Pomelo.EntityFrameworkCore.MySql或MySql.Data.EntityFrameworkCore。
# 使用Pomelo提供程序
dotnet add package Pomelo.EntityFrameworkCore.MySql
# 或者使用官方MySQL提供程序
dotnet add package MySql.Data.EntityFrameworkCore
在你的appsettings.json或配置文件中添加数据库连接字符串。
{
"ConnectionStrings": {
"DefaultConnection": "server=localhost;port=3306;database=mydb;user=root;password=mypassword;"
}
}
配置Startup.cs或你的配置类以使用MySQL提供程序。
public void ConfigureServices(IServiceCollection services)
{
// 使用Pomelo提供程序
services.AddDbContext<YourDbContext>(options =>
options.UseMySql(Configuration.GetConnectionString("DefaultConnection")));
// 或者使用官方MySQL提供程序
services.AddDbContext<YourDbContext>(options =>
options.UseMySql(Configuration.GetConnectionString("DefaultConnection"), new MySqlServerVersion(new Version(8, 0, 27))));
}
定义你的数据模型和DbContext。
public class YourDbContext : DbContext
{
public YourDbContext(DbContextOptions<YourDbContext> options) : base(options)
{
}
public DbSet<YourEntity> YourEntities { get; set; }
// 其他DbSet定义...
}
public class YourEntity
{
public int Id { get; set; }
// 其他属性...
}
使用YourDbContext进行数据库操作。
public class YourRepository
{
private readonly YourDbContext _context;
public YourRepository(YourDbContext context)
{
_context = context;
}
public List<YourEntity> GetAll()
{
return _context.YourEntities.ToList();
}
// 其他方法...
}
以上步骤展示了如何使用EntityFrameworkCore连接MySQL数据库。记得替换示例代码中的YourDbContext, YourEntity, YourRepository和数据库连接字符串为你自己的上下文、实体和配置。
7、
PS D:\> dotnet new install Microsoft.FluentUI.AspNetCore.Templates
PS D:\> dotnet new fluentblazor --name jtpjsapp -au Individual
已成功创建模板“Fluent Blazor Web 应用”。
此模板包含除 Microsoft 以外其他方的技术,请参阅 https://aka.ms/aspnetcore/8.0-third-party-notices 以获取详细信息。
正在处理创建后操作...
正在还原 D:\jtpjsapp\jtpjsapp.csproj:
正在确定要还原的项目…
已还原 D:\jtpjsapp\jtpjsapp.csproj (用时 35.6 秒)。
已成功还原。
PS D:\jtpjsapp> dotnet add package Microsoft.FluentUI.AspNetCore.Components.Icons
PS D:\jtpjsapp> dotnet add package Microsoft.FluentUI.AspNetCore.Components.Emoji
添加组件提供程序
在MainLayout.razor文件末尾添加以下组件。 关联服务使用这些提供程序来正确显示 Toast、对话框、工具提示或消息栏。
<FluentToastProvider />
<FluentDialogProvider />
<FluentTooltipProvider />
<FluentMessageBarProvider />
<FluentMenuProvider />
将 DataGrid 组件与 EF Core 结合使用
如果要将 与 EF Core 提供的数据一起使用,则需要安装一个额外的包,以便网格知道如何异步解析查询以提高效率。.<FluentDataGrid>
安装
通过运行以下命令安装包:
dotnet add package Microsoft.FluentUI.AspNetCore.Components.DataGrid.EntityFrameworkAdapter
用法
在您的Program.cs文件中,您需要在builder.Services.AddFluentUIComponents(...);行后添加以下内容:
builder.Services.AddDataGridEntityFrameworkAdapter();
PS D:\jtpjsapp\Components\Layout> vim .\MainLayout.razor
[root@cpzljc Layout]# cat MainLayout.razor
@inherits LayoutComponentBase
@inject IWebHostEnvironment Environment
<FluentLayout>
@if (Environment.IsDevelopment()) {
<FluentHeader>
票据系统(开发环境)
<FluentSpacer />
<AuthorizeView>
<Authorized>
<FluentNavLink Href="Account/Manage">@context.User.Identity?.Name</FluentNavLink>
<form action="Account/Logout" method="post">
<AntiforgeryToken />
@* <input type="hidden" name="ReturnUrl" value="@currentUrl" /> *@
<input type="hidden" name="ReturnUrl" value="Account/Login" />
<FluentButton Type="ButtonType.Submit" Style="width: 100%;">注销</FluentButton>
</form>
</Authorized>
</AuthorizeView>
</FluentHeader>
} else {
<FluentHeader>
票据系统
<FluentSpacer />
<AuthorizeView>
<Authorized>
<FluentNavLink Href="Account/Manage">@context.User.Identity?.Name</FluentNavLink>
<form action="Account/Logout" method="post">
<AntiforgeryToken />
@* <input type="hidden" name="ReturnUrl" value="@currentUrl" /> *@
<input type="hidden" name="ReturnUrl" value="Account/Login" />
<FluentButton Type="ButtonType.Submit" Style="width: 100%;">注销</FluentButton>
</form>
</Authorized>
</AuthorizeView>
</FluentHeader>
}
<FluentStack Class="main" Orientation="Orientation.Horizontal" Width="100%">
<AuthorizeView>
<Authorized>
<NavMenu />
</Authorized>
<NotAuthorized>
</NotAuthorized>
</AuthorizeView>
<FluentBodyContent Class="body-content">
<div class="content">
@Body
</div>
</FluentBodyContent>
</FluentStack>
<FluentFooter>
<p> 江特电机 </p>
@* <a href="https://www.fluentui-blazor.net" target="_blank">Documentation and demos</a> *@
<FluentSpacer />
@* <a href="https://learn.microsoft.com/en-us/aspnet/core/blazor" target="_blank">About Blazor</a>*@
</FluentFooter>
<FluentToastProvider />
<FluentDialogProvider @rendermode="RenderMode.InteractiveServer" />
<FluentTooltipProvider />
<FluentMessageBarProvider />
<FluentMenuProvider />
</FluentLayout>
<div id="blazor-error-ui">
An unhandled error has occurred.
<a href="" class="reload">Reload</a>
<a class="dismiss">??</a>
</div>
PS D:\jtpjsapp\Components\Layout> vim .\NavMenu.razor
[root@cpzljc Layout]# cat NavMenu.razor
@implements IDisposable
@inject NavigationManager NavigationManager
<div class="navmenu">
<input type="checkbox" title="Menu expand/collapse toggle" id="navmenu-toggle" class="navmenu-icon" />
<label for="navmenu-toggle" class="navmenu-icon"><FluentIcon Value="@(new Icons.Regular.Size20.Navigation())" Color="Color.Fill" /></label>
<nav class="sitenav" aria-labelledby="main-menu">
<FluentNavMenu Id="main-menu" Collapsible="true" Width="250" Title="Navigation menu" @bind-Expanded="expanded" CustomToggle="true">
@* <FluentNavLink Href="/" Match="NavLinkMatch.All" Icon="@(new Icons.Regular.Size20.Home())" IconColor="Color.Accent">首页</FluentNavLink>
<FluentNavLink Href="counter" Icon="@(new Icons.Regular.Size20.NumberSymbolSquare())" IconColor="Color.Accent">Counter</FluentNavLink>
<FluentNavLink Href="weather" Icon="@(new Icons.Regular.Size20.WeatherPartlyCloudyDay())" IconColor="Color.Accent">Weather</FluentNavLink> *@
@* <FluentNavLink Href="auth" Icon="@(new Icons.Regular.Size20.LockClosedKey())" IconColor="Color.Accent">授权登录</FluentNavLink> *@
<AuthorizeView>
<Authorized>
@*
<FluentNavLink Href="Account/Manage">@context.User.Identity?.Name</FluentNavLink>
<form action="Account/Logout" method="post">
<AntiforgeryToken />
<input type="hidden" name="ReturnUrl" value="@currentUrl" />
<input type="hidden" name="ReturnUrl" value="Account/Login" />
<FluentButton Type="ButtonType.Submit" Style="width: 100%;">注销</FluentButton>
</form>
*@
<FluentNavLink Href="recbill" Icon="@(new Icons.Regular.Size20.Money())" IconColor="Color.Accent">应收票据</FluentNavLink>
<FluentNavLink Href="motherRecbilllist" Icon="@(new Icons.Regular.Size20.List())" IconColor="Color.Accent">应收票据母票列表</FluentNavLink>
<FluentNavLink Href="childRecbilllist" Icon="@(new Icons.Regular.Size20.TicketHorizontal())" IconColor="Color.Accent">应收票据子票列表</FluentNavLink>
</Authorized>
<NotAuthorized>
<FluentNavLink Href="Account/Register">注册</FluentNavLink>
<FluentNavLink Href="Account/Login">登录</FluentNavLink>
</NotAuthorized>
</AuthorizeView>
</FluentNavMenu>
</nav>
</div>
@code {
private bool expanded = true;
private string? currentUrl;
protected override void OnInitialized()
{
currentUrl = NavigationManager.ToBaseRelativePath(NavigationManager.Uri);
NavigationManager.LocationChanged += OnLocationChanged;
}
private void OnLocationChanged(object? sender, LocationChangedEventArgs e)
{
currentUrl = NavigationManager.ToBaseRelativePath(e.Location);
StateHasChanged();
}
public void Dispose()
{
NavigationManager.LocationChanged -= OnLocationChanged;
}
}
[root@cpzljc Components]# cat App.razor
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<base href="/" />
<link rel="stylesheet" href="app.css" />
<link rel="stylesheet" href="jtpjsapp.styles.css" />
<link rel="icon" type="image/x-icon" href="favicon.ico" />
<HeadOutlet />
</head>
<body>
<Routes @rendermode="RenderModeForPage" />
<script src="_framework/blazor.web.js"></script>
<script>
window.downloadFileFromStream = async (fileName, contentStreamReference) => {
const arrayBuffer = await contentStreamReference.arrayBuffer();
const blob = new Blob([arrayBuffer]);
const url = URL.createObjectURL(blob);
const anchorElement = document.createElement('a');
anchorElement.href = url;
anchorElement.download = fileName ?? '';
anchorElement.click();
anchorElement.remove();
URL.revokeObjectURL(url);
}
</script>
</body>
</html>
@code {
[CascadingParameter]
private HttpContext HttpContext { get; set; } = default!;
private IComponentRenderMode? RenderModeForPage =>
HttpContext.Request.Path.StartsWithSegments("/Account")
? null
: InteractiveServer;
}
[root@cpzljc Components]# cat Routes.razor
@using jtpjsapp.Components.Account.Shared
@inject NavigationManager NavigationManager
<Router AppAssembly="typeof(Program).Assembly">
<Found Context="routeData">
@if (NavigationManager.Uri.Contains("/Account/Login") || NavigationManager.Uri.Contains("/Account/Register") ) {
<RouteView RouteData="routeData" DefaultLayout="typeof(Layout.MainLayout)" />
<FocusOnNavigate RouteData="routeData" Selector="h1" />
} else {
<AuthorizeRouteView RouteData="routeData" DefaultLayout="typeof(Layout.MainLayout)">
<NotAuthorized>
<RedirectToLogin />
</NotAuthorized>
</AuthorizeRouteView>
<FocusOnNavigate RouteData="routeData" Selector="h1" />
}
</Found>
</Router>
[root@cpzljc Data]# cat RecBillModel.cs
using System.ComponentModel.DataAnnotations;
using Microsoft.EntityFrameworkCore;
namespace jtpjsapp.Data ;
//[Table("RecBillModels")]
[Index(nameof(TicketNumber), nameof(SubTicketNumber), IsUnique = true)]
public class RecBillModel
{
public RecBillModel() {}
public RecBillModel(DateTime dt, DateTime td, DateTime dd , DateTime addtime , DateTime modifytime) {
this.RecDate = dt;
this.TicketIssueDate = td;
this.DueDate = dd;
this.AddTime = addtime;
this.ModifyTime = modifytime;
}
public int Id { get; set; }
[Required]
[Comment("收票日期")]
public DateTime RecDate { get; set; }
[Required]
[StringLength(16,
ErrorMessage = "Identifier too long (16 character limit).")]
public string RecVoucher { get; set; }
[Required]
[MaxLength(100)]
public string EntryName { get; set; }
[Required]
[StringLength(50,
ErrorMessage = "Identifier too long (50 character limit).")]
public string RecBillCategory { get; set; }
[Required]
[StringLength(50,
ErrorMessage = "Identifier too long (50 character limit).")]
public string FrontRela { get; set; }
[Required]
[StringLength(10,
ErrorMessage = "Identifier too long (10 character limit).")]
public string NewGeneration { get; set; }
[Required]
[StringLength(50,
ErrorMessage = "Identifier too long (50 character limit).")]
public string TicketNumber { get; set; }
[Required]
[StringLength(50,
ErrorMessage = "Identifier too long (50 character limit).")]
public string SubTicketNumber { get; set; }
[Required]
[StringLength(50,
ErrorMessage = "Identifier too long (50 character limit).")]
public string IssuingUnit { get; set; }
[Required]
[StringLength(50,
ErrorMessage = "Identifier too long (50 character limit).")]
public string AcceptorName { get; set; }
[Required]
[StringLength(10,
ErrorMessage = "Identifier too long (10 character limit).")]
public string Is69 { get; set; }
[Required]
// [Column(TypeName = "decimal(10, 2)")]
[Precision(14, 2)]
// [Range(0.00001, 999999999999, ErrorMessage = "承兑金额要大于0。")]
public decimal AcceptAmount { get; set; }
[Required]
public DateTime TicketIssueDate { get; set; }
[Required]
public DateTime DueDate { get; set; }
public bool Selected { get; set; }
// user ID from AspNetUser table.
public string OwnerID { get; set; }
[Required]
public RecbillStatus Status { get; set; }
[Required]
public RecbillCompany Company { get; set; }
public string? Endorser { get; set; }
[Required]
[Precision(14, 2)]
public decimal Balance { get; set; }
[Precision(14, 2)]
public decimal? TransferAmount { get; set; }
[Required]
public DateTime AddTime { get; set; }
public DateTime? ModifyTime { get; set; }
[StringLength(10,
ErrorMessage = "Identifier too long (10 character limit).")]
public string IsMotherTicket { get; set; }
/*
[Range(1, 100000,
ErrorMessage = "Accommodation invalid (1-100000).")]
public int MaximumAccommodation { get; set; }
[Required]
[Range(typeof(bool), "true", "true",
ErrorMessage = "This form disallows unapproved ships.")]
public bool IsValidatedDesign { get; set; }
[Required]
public DateTime ProductionDate { get; set; }
*/
}
public enum RecbillStatus
{
Submitted,
Approved,
Rejected
}
public enum RecbillCompany
{
江特电机,
江西江特,
银锂新能源,
杭州米格,
天津华兴,
宜丰锂业,
泰昌矿业,
江特电动车,
江特客车厂,
江特节能公司,
江特高新装备公司,
江特高新武汉分公司
}
[root@cpzljc Data]# cat RecBillDbContext.cs
using Microsoft.EntityFrameworkCore;
namespace jtpjsapp.Data;
public class RecBillDbContext : DbContext
{
public DbSet<RecBillModel> RecBillModels { get; set; }
//public DbSet<Post> Posts { get; set; }
public RecBillDbContext(DbContextOptions<RecBillDbContext> options)
: base(options)
{
}
}
[root@cpzljc Data]# cat ApplicationDbContext.cs
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
namespace jtpjsapp.Data;
public class ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : IdentityDbContext<ApplicationUser>(options)
{
public DbSet<RecBillModel> RecBillModels { get; set; }
}
PS D:\jtpjsapp\Components\Pages> cp Counter.razor Recbill.razor
PS D:\jtpjsapp\Components> vim .\_Imports.razor
@using System.Net.Http
@using System.Net.Http.Json
@using Microsoft.AspNetCore.Components.Authorization
@using Microsoft.AspNetCore.Components.Forms
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.AspNetCore.Components.Web
@using static Microsoft.AspNetCore.Components.Web.RenderMode
@using Microsoft.AspNetCore.Components.Web.Virtualization
@using Microsoft.FluentUI.AspNetCore.Components
@using Microsoft.JSInterop
@using jtpjsapp
@using jtpjsapp.Components
@using System.ComponentModel.DataAnnotations
@using System.ComponentModel.DataAnnotations.Schema
@using Microsoft.EntityFrameworkCore
@using jtpjsapp.Data
@using jtpjsapp.Authorization
@using Microsoft.AspNetCore.Identity
@using Microsoft.AspNetCore.Authorization
@using ClosedXML.Excel
@using System.IO
PS D:\jtpjsapp\Components\Pages> vim .\Recbill.razor
@page "/recbill"
@rendermode InteractiveServer
@attribute [Authorize]
@implements IDisposable
@inject ILogger<RecBillModel> Logger
@inject IDbContextFactory<ApplicationDbContext> DbFactory
@inject IDialogService DialogService
@inject IAuthorizationService AuthorizationService
@inject UserManager<ApplicationUser> UserManager
@inject AuthenticationStateProvider AuthenticationStateProvider
<PageTitle>应收票据</PageTitle>
<FluentStack>
<FluentButton Type="ButtonType.Button" Appearance="Appearance.Accent" Disabled="@adddisabled" OnClick="@addRecbillAsync" >新增母票</FluentButton>
<FluentTextField @bind-Value="ticketNumberOption" Required="true" Label="票号:" Minlength="1" Maxlength="50"> </FluentTextField>
<FluentTextField @bind-Value="subTicketNumberOption" Required="true" Label="子票号:" Minlength="1" Maxlength="50"> </FluentTextField>
<FluentButton Type="ButtonType.Button" Appearance="Appearance.Accent" Disabled="@finddisabled" OnClick="@FindRecBillByTicketNumberAndSubTicketNumber" >查询母票/子票</FluentButton>
<FluentButton Type="ButtonType.Button" Appearance="Appearance.Accent" Disabled="@modifydisabled" OnClick="@modifyRecbllByTicketNumberAndSubTicketNumberAndId">修改</FluentButton>
<FluentButton Type="ButtonType.Button" Appearance="Appearance.Accent" Disabled="@deletedisabled" OnClick="@deleteRecbllByTicketNumberAndSubTicketNumberAndId" >删除</FluentButton>
</FluentStack>
<h1 style="text-align: center">应收票据</h1>
<EditForm Model="recbill" OnValidSubmit="Submit" FormName="Recbill1">
<DataAnnotationsValidator />
<ValidationSummary />
<FluentGrid Spacing="1" >
<FluentGridItem lg="4">
<FluentSelect TOption="RecbillCompany"
Items=@(Enum.GetValues<RecbillCompany>() )
Placeholder="选择单位..."
OptionText="@(i => Enum.GetName(i))"
OptionValue="@(i => ((int)(i)).ToString() )"
@bind-Value="@recbillCompany"
@bind-SelectedOption="@recbill.Company"
Label="所属单位:"
Disabled="@formdisabled"
Required="false" />
</FluentGridItem>
<FluentGridItem lg="4">
<FluentLabel>
收票日期:
<br/>
@* <FluentDatePicker @bind-Value="recbill.RecDate" @bind-PickerMonth="recbill.RecDate" /> *@
<InputDate @bind-Value="recbill.RecDate" Disabled="@formdisabled" />
</FluentLabel>
</FluentGridItem>
<FluentGridItem lg="4">
<FluentTextField @bind-Value="recbill.RecVoucher" Required="true" Label="收票凭证号:" Minlength="1" Maxlength="16" Disabled="@formdisabled" >
</FluentTextField>
</FluentGridItem>
<FluentGridItem lg="4">
<FluentTextField @bind-Value="recbill.EntryName" Required="true" Label="项目名称(即前手单位):" Minlength="1" Maxlength="50" Disabled="@formdisabled" >
</FluentTextField>
</FluentGridItem>
<FluentGridItem lg="4">
<FluentSelect Items=@recBillCategoryOptions
OptionText="@(i => i.Text)"
OptionValue="@(i => i.Value)"
OptionSelected="@(i => i.Selected)"
@bind-Value="@recbill.RecBillCategory"
Label="应收票据类别:"
Disabled="@formdisabled"
Required="false" />
</FluentGridItem>
<FluentGridItem lg="4">
<FluentTextField @bind-Value="recbill.FrontRela" Required="true" Label="与前手的关系:" Minlength="1" Maxlength="16" Disabled="@formdisabled" > </FluentTextField>
</FluentGridItem>
<FluentGridItem lg="4">
<FluentSelect Items=@newGenerationOptions
OptionText="@(i => i.Text)"
OptionValue="@(i => i.Value)"
OptionSelected="@(i => i.Selected)"
@bind-Value="@recbill.NewGeneration"
Label="新一代:"
Disabled="@formdisabled"
Required="false" />
</FluentGridItem>
<FluentGridItem lg="4">
<FluentTextField @bind-Value="recbill.TicketNumber" Required="true" Label="票号:" Minlength="1" Maxlength="50" Disabled="@formdisabled" > </FluentTextField>
</FluentGridItem>
<FluentGridItem lg="4">
<FluentTextField @bind-Value="recbill.SubTicketNumber" Required="true" Label="子票号:" Minlength="1" Maxlength="50" Disabled="@formdisabled" > </FluentTextField>
</FluentGridItem>
<FluentGridItem lg="4">
<FluentTextField @bind-Value="recbill.IssuingUnit" Required="true" Label="出票单位:" Minlength="1" Maxlength="50" Disabled="@formdisabled" > </FluentTextField>
</FluentGridItem>
<FluentGridItem lg="4">
<FluentTextField @bind-Value="recbill.AcceptorName" Required="true" Label="承兑人名称:" Minlength="1" Maxlength="50" Disabled="@formdisabled" > </FluentTextField>
</FluentGridItem>
<FluentGridItem lg="4">
<FluentSelect Items=@is69Options
OptionText="@(i => i.Text)"
OptionValue="@(i => i.Value)"
OptionSelected="@(i => i.Selected)"
@bind-Value="@recbill.Is69"
Label="是否为6+9:"
Disabled="@formdisabled"
Required="false" />
</FluentGridItem>
<FluentGridItem lg="4">
<FluentLabel>
承兑金额:
<br/>
<InputNumber @bind-Value="recbill.AcceptAmount" Disabled="@formdisabled" />
</FluentLabel>
</FluentGridItem>
<FluentGridItem lg="4">
<FluentLabel>
余额:
<br/>
<InputNumber @bind-Value="recbill.Balance" Disabled="@childdisabled" />
</FluentLabel>
</FluentGridItem>
<FluentGridItem lg="4">
<FluentLabel>
转出金额:
<br/>
<InputNumber @bind-Value="recbill.TransferAmount" Disabled="@childdisabled" />
</FluentLabel>
</FluentGridItem>
<FluentGridItem lg="4">
<FluentLabel>
出票日:
<br/>
@* <FluentDatePicker @bind-Value="recbill.RecDate" @bind-PickerMonth="recbill.RecDate" /> *@
<InputDate @bind-Value="recbill.TicketIssueDate" Disabled="@formdisabled" />
</FluentLabel>
</FluentGridItem>
<FluentGridItem lg="4">
<FluentLabel>
到期日:
<br/>
@* <FluentDatePicker @bind-Value="recbill.RecDate" @bind-PickerMonth="recbill.RecDate" /> *@
<InputDate @bind-Value="recbill.DueDate" Disabled="@formdisabled" />
</FluentLabel>
</FluentGridItem>
<FluentGridItem lg="4">
<FluentTextField @bind-Value="recbill.Endorser" Label="背书人:" Maxlength="100" Disabled="@childdisabled" >
</FluentTextField>
</FluentGridItem>
<FluentGridItem lg="4">
<FluentLabel>
新建时间:
<br/>
@* <FluentDatePicker @bind-Value="recbill.RecDate" @bind-PickerMonth="recbill.RecDate" /> *@
<InputDate @bind-Value="recbill.AddTime" Disabled="@foreverdisabled" />
</FluentLabel>
</FluentGridItem>
<FluentGridItem lg="4">
<FluentLabel>
修改时间:
<br/>
@* <FluentDatePicker @bind-Value="recbill.RecDate" @bind-PickerMonth="recbill.RecDate" /> *@
<InputDate @bind-Value="recbill.ModifyTime" Disabled="@foreverdisabled" />
</FluentLabel>
</FluentGridItem>
<FluentGridItem lg="4">
<FluentSelect Items=@isMotherTicketOptions
OptionText="@(i => i.Text)"
OptionValue="@(i => i.Value)"
OptionSelected="@(i => i.Selected)"
@bind-Value="@recbill.IsMotherTicket"
Label="母票/子票:"
Disabled="@foreverdisabled"
Required="true" />
</FluentGridItem>
</FluentGrid>
<br/>
@* <button type="submit">提交</button> *@
<FluentButton Type="ButtonType.Submit" Disabled="@submitdisabled" Appearance="Appearance.Accent">保存</FluentButton>
<FluentButton Type="ButtonType.Button" Appearance="Appearance.Accent" Disabled="@cansledisabled" OnClick="@cansleSubmit" >取消</FluentButton>
</EditForm>
@*
<div role="status" style="padding-bottom: 1em;">
Current count: <FluentBadge Appearance="Appearance.Neutral">@currentCount</FluentBadge>
</div>
<FluentButton Appearance="Appearance.Accent" @onclick="IncrementCount">Click me</FluentButton>
*@
@code {
private ApplicationDbContext? Context { get; set; }
private bool Busy;
private int currentCount = 0;
private bool adddisabled = false;
private bool finddisabled = false;
private bool modifydisabled = true;
private bool deletedisabled = true;
private bool submitdisabled = true;
private bool cansledisabled = true;
private bool formdisabled = true;
private bool ismodifybutton = false;
private bool foreverdisabled = true;
private bool motherdisabled = true;
private bool childdisabled = true;
private string ticketNumberOption;
private string subTicketNumberOption;
private string recbillCompany;
// [SupplyParameterFromForm]
private RecBillModel recbill = new RecBillModel(DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now);
static List<Option<string>> recBillCategoryOptions = new()
{
{ new Option<string> { Value = "电子银行承兑汇票", Text = "电子银行承兑汇票" } },
{ new Option<string> { Value = "其他", Text = "其他" } }
};
static List<Option<string>> newGenerationOptions = new()
{
{ new Option<string> { Value = "是", Text = "是" } },
{ new Option<string> { Value = "否", Text = "否" } }
};
static List<Option<string>> is69Options = new()
{
{ new Option<string> { Value = "是", Text = "是" } },
{ new Option<string> { Value = "否", Text = "否" } }
};
/*
static List<Option<string>> companyOptions = new()
{
{ new Option<string> { Value = "1", Text = "江特电机" } },
{ new Option<string> { Value = "2", Text = "江西江特" } },
{ new Option<string> { Value = "3", Text = "银锂新能源" } },
{ new Option<string> { Value = "4", Text = "杭州米格" } },
{ new Option<string> { Value = "5", Text = "天津华兴" } },
{ new Option<string> { Value = "6", Text = "宜丰锂业" } },
{ new Option<string> { Value = "7", Text = "泰昌矿业" } },
{ new Option<string> { Value = "8", Text = "江特电动车" } },
{ new Option<string> { Value = "9", Text = "江特客车厂" } },
{ new Option<string> { Value = "10", Text = "江特节能公司" } },
{ new Option<string> { Value = "11", Text = "江特高新装备公司" } },
{ new Option<string> { Value = "12", Text = "江特高新武汉分公司" } }
};
*/
static List<Option<string>> isMotherTicketOptions = new()
{
{ new Option<string> { Value = "母票", Text = "母票" } },
{ new Option<string> { Value = "子票", Text = "子票" } }
};
private void IncrementCount()
{
currentCount++;
}
protected override async Task OnInitializedAsync()
{
Busy = true;
Context = DbFactory.CreateDbContext();
Busy = false;
await base.OnInitializedAsync();
// ... 其他初始化代码
recbillCompany = "1";
recbill.Company = RecbillCompany.江西江特;
recbill.RecBillCategory = "电子银行承兑汇票";
recbill.NewGeneration = "是";
recbill.Is69 = "是";
}
private async Task addRecbillAsync(){
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
var user = authState.User;
recbill.OwnerID = UserManager.GetUserId(user);
var isAuthorized = await AuthorizationService.AuthorizeAsync(
user, recbill,
RecbillOperations.Create);
if (!isAuthorized.Succeeded)
{
//return Forbid();
var dialog = await DialogService.ShowErrorAsync("当前用户没有新建权限。" );
var result = await dialog.Result;
} else {
formdisabled = false;
submitdisabled = false;
cansledisabled = false;
ismodifybutton = false;
modifydisabled = true;
deletedisabled = true;
finddisabled = true;
recbill = new RecBillModel(DateTime.Now, DateTime.Now, DateTime.Now , DateTime.Now, DateTime.Now );
recbillCompany = "1";
recbill.Company = RecbillCompany.江西江特;
recbill.RecBillCategory = "电子银行承兑汇票";
recbill.NewGeneration = "是";
recbill.Is69 = "是";
}
}
private void cansleSubmit(){
if (ismodifybutton == false ) {
formdisabled = true;
submitdisabled = true;
cansledisabled = true;
modifydisabled = true;
deletedisabled = true;
finddisabled = false;
recbill = new RecBillModel(DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now);
}
if (ismodifybutton == true ) {
formdisabled = true;
submitdisabled = true;
cansledisabled = true;
modifydisabled = false;
deletedisabled = false;
finddisabled = false;
}
}
private async Task modifyRecbllByTicketNumberAndSubTicketNumberAndId(){
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
var user = authState.User;