WPF中如何简单的使用CommunityToolkit.Mvvm创建一个项目并进行 增删改查

news2024/12/26 9:22:27

目录

开始前准备的数据库dbblog如下:

第一步:创建项目后下载四个NuGet程序包

第二步:删除原本的MainWindow.XAML文件 并创建如下的目录结构 然后在View文件夹下面创建Login.XAML和Main.XAML          并且在App.XAML中将启动项改为Login.XAML

1.View文件夹下面创建Login.XAML和Main.XAML 

2.在App.XAML中将启动项改为Login.XAML

第三步:在Model文件夹中创建BlogTypeInfo类,CommentInfo类,PostInfo类,UserInfo类 并在Model文件夹下的View文件夹中创建BlogTypeInfoView类,CommentInfoView类,PostInfoView类,UserInfoView类

BlogTypeInfo类如下:

CommentInfo类如下:

PostInfo类如下:

UserInfo类如下:

BlogTypeInfoView类如下:

CommentInfoView类如下:

PostInfoView类如下:

UserInfoView类如下:

第四步:在View文件夹中的UserControls文件夹中创建BlogType.XAML、Comment.XAML、Post.XAML、User.XAML

User.XAML如下:

Post.XAML如下:

Comment.XAML如下:

BlogType.XAML如下:

第五步:在Service文件夹下创建IBase 、IBlogTypeInfo、ICommentInfo、IPostInfo、IUserInfo

IBase如下:

IBlogTypeInfo如下:

ICommentInfo如下:

IPostInfo如下:

IUserInfo如下:

第六步:先配置好在APP.config中的connectionStrings并在Help文件夹中创建ConstHelper类中把connectionStrings放在里面 然后实现Service中的所有接口BlogTypeInfoService、CommentInfoService、PostInfoService、UserInfoService 

配置connectionStrings

ConstHelper如下:

BlogTypeInfoService如下:

CommentInfoService如下:

PostInfoService如下:

UserInfoService如下:

第七步:在App.cs文件中放入想要放入Ioc容器的对象

第八步:在Helper文件夹中创建LoginInfoHelper类存放登录的用户 并在ViewModel创建LoginViewModel类和MainViewModel类

LoginViewModel如下:

MainViewModel如下:

第九步:在Login.XAML和Main.XAML中写对应的前端代码

1.在Dict文件夹中创建LoginDictionary.xaml存放登录窗口的样式

 LoginDictionary.xaml如下:

2.App.XAML文件中存在共同的样式以及存放LoginDictionary.xaml的引用

3.在Login.XAML文件中创建上下文并创建基本样式 

4.在Main.XAML文件中创建上下文并创建基本样式 

效果如下:


开始前准备的数据库dbblog如下:

USE [dbblog]
GO
/****** Object:  Table [dbo].[UserInfo]    Script Date: 2024/11/5 17:42:36 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[UserInfo](
	[UserId] [int] IDENTITY(1,1) NOT NULL,
	[UserName] [varchar](20) NOT NULL,
	[UserPwd] [varchar](50) NOT NULL,
	[Phone] [varchar](20) NOT NULL,
	[NickName] [varchar](20) NOT NULL,
	[Logo] [image] NULL,
	[RealName] [varchar](20) NULL,
	[Sex] [bit] NULL,
	[Birthday] [datetime] NULL,
	[DataStatus] [int] NOT NULL,
	[CreateUserId] [int] NOT NULL,
	[CreateTime] [datetime] NOT NULL,
	[LastUpdateUserId] [int] NULL,
	[LastUpdateTime] [datetime] NULL,
 CONSTRAINT [PK_UserInfo] PRIMARY KEY CLUSTERED 
(
	[UserId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  View [dbo].[UserInfoView]    Script Date: 2024/11/5 17:42:36 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create view [dbo].[UserInfoView]
as
select ui1.[UserId]
      ,ui1.[UserName]
      ,ui1.[UserPwd]
      ,ui1.[Phone]
      ,ui1.[NickName]
      ,ui1.[Logo]
      ,ui1.[RealName]
      ,ui1.[Sex]
      ,ui1.[Birthday]
      ,ui1.[DataStatus]
	  ,case ui1.[DataStatus] when 0 then '正常' when 1 then '禁用' else '未知' end as DataStatusText
      ,ui1.[CreateUserId]
	  ,ui2.[UserName] as CreateUserName
      ,ui1.[CreateTime]
      ,ui1.[LastUpdateUserId]
	  ,ui3.[UserName] as LastUpdateUserName
      ,ui1.[LastUpdateTime] from UserInfo as ui1
left join UserInfo as ui2 on ui1.CreateUserId = ui2.UserId
left join UserInfo as ui3 on ui1.LastUpdateUserId = ui2.UserId
GO
/****** Object:  Table [dbo].[BlogTypeInfo]    Script Date: 2024/11/5 17:42:36 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[BlogTypeInfo](
	[BlogTypeId] [int] IDENTITY(1,1) NOT NULL,
	[TypeName] [varchar](50) NOT NULL,
	[ParentBlogTypeId] [int] NOT NULL,
	[DataStatus] [int] NOT NULL,
	[CreateUserId] [int] NOT NULL,
	[CreateTime] [datetime] NOT NULL,
	[LastUpdateUserId] [int] NULL,
	[LastUpdateTime] [datetime] NULL,
 CONSTRAINT [PK_BlogTypeInfo] PRIMARY KEY CLUSTERED 
(
	[BlogTypeId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  View [dbo].[BlogTypeInfoView]    Script Date: 2024/11/5 17:42:36 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create view [dbo].[BlogTypeInfoView]
as
select bti.[BlogTypeId]
      ,bti.[TypeName]
      ,bti.[ParentBlogTypeId]
	  ,bti2.[TypeName] as ParentBlogTypeName
      ,bti.[DataStatus]
	  ,case bti.[DataStatus] when 0 then '正常' when 1 then '禁用' else '未知' end as DataStatusText
      ,bti.[CreateUserId]
	  ,ui1.[UserName] as CreateUserName
      ,bti.[CreateTime]
      ,bti.[LastUpdateUserId]
	  ,ui2.[UserName] as LastUpdateUserName
      ,bti.[LastUpdateTime] from blogtypeinfo as bti
left join blogtypeinfo as bti2 on bti.parentblogtypeid=bti2.blogtypeid
left join userinfo as ui1 on bti.createuserid=ui1.userid
left join userinfo as ui2 on bti.lastupdateuserid=ui2.userid
GO
/****** Object:  Table [dbo].[CommentInfo]    Script Date: 2024/11/5 17:42:36 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[CommentInfo](
	[CommentId] [int] IDENTITY(1,1) NOT NULL,
	[CommentContent] [varchar](250) NOT NULL,
	[DataStatus] [int] NOT NULL,
	[CreateUserId] [int] NOT NULL,
	[CreateTime] [datetime] NOT NULL,
	[LastUpdateUserId] [int] NULL,
	[LastUpdateTime] [datetime] NULL,
 CONSTRAINT [PK_CommentInfo] PRIMARY KEY CLUSTERED 
(
	[CommentId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  View [dbo].[CommentInfoView]    Script Date: 2024/11/5 17:42:36 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create view [dbo].[CommentInfoView]
as
SELECT ci.[CommentId]
      ,ci.[CommentContent]
      ,ci.[DataStatus]
	  ,case ci.[DataStatus] when 0 then '正常' when 1 then '禁用' else '未知' end as DataStatusText
      ,ci.[CreateUserId]
	   ,ui1.[UserName] as CreateUserName
      ,ci.[CreateTime]
      ,ci.[LastUpdateUserId]
	  ,ui2.[UserName] as LastUpdateUserName
      ,ci.[LastUpdateTime]
  FROM [dbo].[CommentInfo] as ci
  left join userinfo as ui1 on ci.createuserid=ui1.userid
left join userinfo as ui2 on ci.lastupdateuserid=ui2.userid




GO
/****** Object:  Table [dbo].[PostInfo]    Script Date: 2024/11/5 17:42:36 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[PostInfo](
	[PostId] [int] IDENTITY(1,1) NOT NULL,
	[Title] [varchar](50) NOT NULL,
	[PostContent] [text] NOT NULL,
	[BlogTypeId] [int] NOT NULL,
	[LikeCount] [int] NOT NULL,
	[HateCount] [int] NOT NULL,
	[ReadCount] [int] NOT NULL,
	[CommentCount] [int] NOT NULL,
	[DataStatus] [int] NOT NULL,
	[CreateUserId] [int] NOT NULL,
	[CreateTime] [datetime] NOT NULL,
	[LastUpdateUserId] [int] NULL,
	[LastUpdateTime] [datetime] NULL,
 CONSTRAINT [PK_PostInfo] PRIMARY KEY CLUSTERED 
(
	[PostId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  View [dbo].[PostInfoView]    Script Date: 2024/11/5 17:42:36 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

create view [dbo].[PostInfoView]
as
SELECT poi.[PostId]
      ,poi.[Title]
      ,poi.[PostContent]
      ,poi.[BlogTypeId]
      ,bti.[TypeName] as BlogTypeName
      ,poi.[LikeCount]
      ,poi.[HateCount]
      ,poi.[ReadCount]
      ,poi.[CommentCount]
      ,poi.[DataStatus]
	   ,case poi.[DataStatus] when 0 then '正常' when 1 then '禁用' else '未知' end as DataStatusText
      ,poi.[CreateUserId]
	   ,ui1.[UserName] as CreateUserName
      ,poi.[CreateTime]
      ,poi.[LastUpdateUserId]
	   ,ui2.[UserName] as LastUpdateUserName
      ,poi.[LastUpdateTime]
  FROM [dbo].[PostInfo] as poi
  left join blogtypeinfo as bti on poi.blogtypeid=bti.blogtypeId
    left join userinfo as ui1 on poi.createuserid=ui1.userid
left join userinfo as ui2 on poi.lastupdateuserid=ui2.userid



GO
ALTER TABLE [dbo].[BlogTypeInfo] ADD  CONSTRAINT [DF_BlogTypeInfo_DataStatus]  DEFAULT ((0)) FOR [DataStatus]
GO
ALTER TABLE [dbo].[BlogTypeInfo] ADD  CONSTRAINT [DF_BlogTypeInfo_CreateTime]  DEFAULT (getdate()) FOR [CreateTime]
GO
ALTER TABLE [dbo].[CommentInfo] ADD  CONSTRAINT [DF_CommentInfo_DataStatus]  DEFAULT ((0)) FOR [DataStatus]
GO
ALTER TABLE [dbo].[CommentInfo] ADD  CONSTRAINT [DF_CommentInfo_CreateTime]  DEFAULT (getdate()) FOR [CreateTime]
GO
ALTER TABLE [dbo].[PostInfo] ADD  CONSTRAINT [DF_PostInfo_LikeCount]  DEFAULT ((0)) FOR [LikeCount]
GO
ALTER TABLE [dbo].[PostInfo] ADD  CONSTRAINT [DF_PostInfo_HateCount]  DEFAULT ((0)) FOR [HateCount]
GO
ALTER TABLE [dbo].[PostInfo] ADD  CONSTRAINT [DF_PostInfo_ReadCount]  DEFAULT ((0)) FOR [ReadCount]
GO
ALTER TABLE [dbo].[PostInfo] ADD  CONSTRAINT [DF_PostInfo_CommentCount]  DEFAULT ((0)) FOR [CommentCount]
GO
ALTER TABLE [dbo].[PostInfo] ADD  CONSTRAINT [DF_PostInfo_DataStatus]  DEFAULT ((0)) FOR [DataStatus]
GO
ALTER TABLE [dbo].[PostInfo] ADD  CONSTRAINT [DF_PostInfo_CreateTime]  DEFAULT (getdate()) FOR [CreateTime]
GO
ALTER TABLE [dbo].[UserInfo] ADD  CONSTRAINT [DF_UserInfo_DataStatus]  DEFAULT ((0)) FOR [DataStatus]
GO
ALTER TABLE [dbo].[UserInfo] ADD  CONSTRAINT [DF_UserInfo_CreateTime]  DEFAULT (getdate()) FOR [CreateTime]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'主键' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'BlogTypeInfo', @level2type=N'COLUMN',@level2name=N'BlogTypeId'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'博客类型名称' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'BlogTypeInfo', @level2type=N'COLUMN',@level2name=N'TypeName'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'父级类型名称' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'BlogTypeInfo', @level2type=N'COLUMN',@level2name=N'ParentBlogTypeId'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'数据状态(0正常,1禁用)' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'BlogTypeInfo', @level2type=N'COLUMN',@level2name=N'DataStatus'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'创建人(外键)' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'BlogTypeInfo', @level2type=N'COLUMN',@level2name=N'CreateUserId'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'创建日期' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'BlogTypeInfo', @level2type=N'COLUMN',@level2name=N'CreateTime'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'最后一次修改人(外键)' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'BlogTypeInfo', @level2type=N'COLUMN',@level2name=N'LastUpdateUserId'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'最后一次修改日期' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'BlogTypeInfo', @level2type=N'COLUMN',@level2name=N'LastUpdateTime'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'主键' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'CommentInfo', @level2type=N'COLUMN',@level2name=N'CommentId'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'评论内容' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'CommentInfo', @level2type=N'COLUMN',@level2name=N'CommentContent'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'数据状态(0正常,1禁用)' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'CommentInfo', @level2type=N'COLUMN',@level2name=N'DataStatus'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'创建人(外键)' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'CommentInfo', @level2type=N'COLUMN',@level2name=N'CreateUserId'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'创建日期' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'CommentInfo', @level2type=N'COLUMN',@level2name=N'CreateTime'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'最后一次修改人(外键)' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'CommentInfo', @level2type=N'COLUMN',@level2name=N'LastUpdateUserId'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'最后一次修改日期' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'CommentInfo', @level2type=N'COLUMN',@level2name=N'LastUpdateTime'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'主键' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'PostInfo', @level2type=N'COLUMN',@level2name=N'PostId'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'标题' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'PostInfo', @level2type=N'COLUMN',@level2name=N'Title'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'内容' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'PostInfo', @level2type=N'COLUMN',@level2name=N'PostContent'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'类型' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'PostInfo', @level2type=N'COLUMN',@level2name=N'BlogTypeId'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'点赞数量' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'PostInfo', @level2type=N'COLUMN',@level2name=N'LikeCount'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'踩数量' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'PostInfo', @level2type=N'COLUMN',@level2name=N'HateCount'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'阅读数量' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'PostInfo', @level2type=N'COLUMN',@level2name=N'ReadCount'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'评论数量' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'PostInfo', @level2type=N'COLUMN',@level2name=N'CommentCount'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'数据状态(0正常,1禁用)' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'PostInfo', @level2type=N'COLUMN',@level2name=N'DataStatus'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'创建人(外键)' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'PostInfo', @level2type=N'COLUMN',@level2name=N'CreateUserId'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'创建日期' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'PostInfo', @level2type=N'COLUMN',@level2name=N'CreateTime'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'最后一次修改人(外键)' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'PostInfo', @level2type=N'COLUMN',@level2name=N'LastUpdateUserId'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'最后一次修改日期' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'PostInfo', @level2type=N'COLUMN',@level2name=N'LastUpdateTime'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'主键' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'UserInfo', @level2type=N'COLUMN',@level2name=N'UserId'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'用户名' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'UserInfo', @level2type=N'COLUMN',@level2name=N'UserName'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'密码' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'UserInfo', @level2type=N'COLUMN',@level2name=N'UserPwd'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'手机号' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'UserInfo', @level2type=N'COLUMN',@level2name=N'Phone'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'昵称' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'UserInfo', @level2type=N'COLUMN',@level2name=N'NickName'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'姓名' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'UserInfo', @level2type=N'COLUMN',@level2name=N'RealName'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'性别' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'UserInfo', @level2type=N'COLUMN',@level2name=N'Sex'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'生日' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'UserInfo', @level2type=N'COLUMN',@level2name=N'Birthday'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'数据状态(0正常,1禁用)' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'UserInfo', @level2type=N'COLUMN',@level2name=N'DataStatus'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'创建人(外键)' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'UserInfo', @level2type=N'COLUMN',@level2name=N'CreateUserId'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'创建日期' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'UserInfo', @level2type=N'COLUMN',@level2name=N'CreateTime'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'最后一次修改人(外键)' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'UserInfo', @level2type=N'COLUMN',@level2name=N'LastUpdateUserId'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'最后一次修改日期' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'UserInfo', @level2type=N'COLUMN',@level2name=N'LastUpdateTime'
GO

第一步:创建项目后下载四个NuGet程序包

第二步:删除原本的MainWindow.XAML文件 并创建如下的目录结构 然后在View文件夹下面创建Login.XAML和Main.XAML          并且在App.XAML中将启动项改为Login.XAML

1.View文件夹下面创建Login.XAML和Main.XAML 

2.在App.XAML中将启动项改为Login.XAML

第三步:在Model文件夹中创建BlogTypeInfo类,CommentInfo类,PostInfo类,UserInfo类 并在Model文件夹下的View文件夹中创建BlogTypeInfoView类,CommentInfoView类,PostInfoView类,UserInfoView类

BlogTypeInfo类如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WPF练习13简单的项目.Model
{
    public class BlogTypeInfo
    {
        public int BlogTypeId { get; set; }
        public string TypeName { get; set; }
        public int ParentBlogTypeId { get; set; }
        public int DataStatus { get; set; } = 0;
        public int CreateUserId { get; set; }
        public DateTime CreateTime { get; set; } = DateTime.Now;
        public int LastUpdateUserId { get; set; }
        public DateTime LastUpdateTime { get; set; }
    }
}

CommentInfo类如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WPF练习13简单的项目.Model
{
    public class CommentInfo
    {
        public int CommentId { get; set; }
        public string CommentContent { get; set; }
        public int DataStatus { get; set; } = 0;
        public int CreateUserId { get; set; }
        public DateTime CreateTime { get; set; } = DateTime.Now;
        public int LastUpdateUserId { get; set; }
        public DateTime LastUpdateTime { get; set; }
    }
}

PostInfo类如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WPF练习13简单的项目.Model
{
    public class PostInfo
    {
        public int PostId { get; set; }
        public string Title { get; set; }
        public string PostContent { get; set; }
        public int BlogTypeId { get; set; }
        public int LikeCount { get; set; } = 0;
        public int HateCount { get; set; } = 0;
        public int ReadCount { get; set; } = 0;
        public int CommentCount { get; set; } = 0;
        public int DataStatus { get; set; } = 0;
        public int CreateUserId { get; set; }
        public DateTime CreateTime { get; set; } = DateTime.Now;
        public int LastUpdateUserId { get; set; }
        public DateTime LastUpdateTime { get; set; }
    }
}

UserInfo类如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WPF练习13简单的项目.Model
{
    public class UserInfo
    {
        public int UserId { get; set; }
        public string UserName { get; set; }
        public string UserPwd { get; set; }
        public string Phone { get; set; }
        public string NickName { get; set; }
        public byte[] Logo { get; set; }
        public string RealName { get; set; }
        public bool Sex { get; set; }
        public DateTime Birthday { get; set; }
        public int DataStatus { get; set; } = 0;
        public int CreateUserId { get; set; }
        public DateTime CreateTime { get; set; } = DateTime.Now;
        public int LastUpdateUserId { get; set; }
        public DateTime LastUpdateTime { get; set; }
    }
}

BlogTypeInfoView类如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WPF练习13简单的项目.Model.View
{
    public class BlogTypeInfoView : BlogTypeInfo
    {
        public string ParentBlogTypeName { get; set; }
        public string DataStatusText { get; set; }
        public string CreateUserName { get; set; }
        public int LastUpdateUserName { get; set; }
    }
}

CommentInfoView类如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WPF练习13简单的项目.Model.View
{
    public class CommentInfoView : CommentInfo
    {
        public string DataStatusText { get; set; }
        public string CreateUserName { get; set; }
        public int LastUpdateUserName { get; set; }
    }
}

PostInfoView类如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WPF练习13简单的项目.Model.View
{
    public class PostInfoView : PostInfo
    {
        public string BlogTypeName { get; set; }
        public string DataStatusText { get; set; }
        public string CreateUserName { get; set; }
        public int LastUpdateUserName { get; set; }
    }
}

UserInfoView类如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WPF练习13简单的项目.Model.View
{
    public class UserInfoView : UserInfo
    {
        public string DataStatusText { get; set; }
        public string CreateUserName { get; set; }
        public int LastUpdateUserName { get; set; }
    }
}

第四步:在View文件夹中的UserControls文件夹中创建BlogType.XAML、Comment.XAML、Post.XAML、User.XAML

User.XAML如下:

<UserControl x:Class="WPF练习13简单的项目.View.UserControls.User"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:WPF练习13简单的项目.View.UserControls"
             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="800">
    <Grid>
        <TextBlock Text="1" />
    </Grid>
</UserControl>

Post.XAML如下:

<UserControl x:Class="WPF练习13简单的项目.View.UserControls.Post"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:WPF练习13简单的项目.View.UserControls"
             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="800">
    <Grid>
        <TextBlock Text="2" />
    </Grid>
</UserControl>

Comment.XAML如下:

<UserControl x:Class="WPF练习13简单的项目.View.UserControls.Comment"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:WPF练习13简单的项目.View.UserControls"
             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="800">
    <Grid>
        <TextBlock Text="3" />
    </Grid>
</UserControl>

BlogType.XAML如下:

<UserControl x:Class="WPF练习13简单的项目.View.UserControls.BlogType"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:WPF练习13简单的项目.View.UserControls"
             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="800">
    <Grid>
        <TextBlock Text="4" />
    </Grid>
</UserControl>

第五步:在Service文件夹下创建IBase 、IBlogTypeInfo、ICommentInfo、IPostInfo、IUserInfo

IBase如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WPF练习13简单的项目.Service
{
    public interface IBase<T,K>
    {
        /// <summary>
        /// 添加数据
        /// </summary>
        /// <param name="model">模型</param>
        /// <returns>布尔</returns>
        bool Add(T model);

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id">主键</param>
        /// <returns>布尔</returns>
        bool Delete(int id);

        /// <summary>
        /// 分页获取数据
        /// </summary>
        /// <param name="strWhere">查询条件</param>
        /// <param name="orderBy">排序字段</param>
        /// <param name="startIndex">起始索引</param>
        /// <param name="endIndex">结束索引</param>
        /// <returns>列表,关联视图模型K</returns>
        List<K> GetListByPage(string strWhere, string orderBy, int startIndex, int endIndex);

        /// <summary>
        /// 获取单个模型
        /// </summary>
        /// <param name="id">主键</param>
        /// <returns>泛型T</returns>
        T GetModel(int id);

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="model">模型</param>
        /// <returns>布尔</returns>
        bool Update(T model);
    }
}

IBlogTypeInfo如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WPF练习13简单的项目.Model.View;
using WPF练习13简单的项目.Model;

namespace WPF练习13简单的项目.Service
{
    public interface IBlogTypeInfo : IBase<BlogTypeInfo, BlogTypeInfoView>
    {

    }
}

ICommentInfo如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WPF练习13简单的项目.Model.View;
using WPF练习13简单的项目.Model;

namespace WPF练习13简单的项目.Service
{
    public interface ICommentInfo : IBase<CommentInfo, CommentInfoView>
    {
    }
}

IPostInfo如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WPF练习13简单的项目.Model.View;
using WPF练习13简单的项目.Model;

namespace WPF练习13简单的项目.Service
{
    public interface IPostInfo : IBase<PostInfo, PostInfoView>
    {
    }
}

IUserInfo如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WPF练习13简单的项目.Model;
using WPF练习13简单的项目.Model.View;

namespace WPF练习13简单的项目.Service
{
    public interface IUserInfo : IBase<UserInfo, UserInfoView>
    {
        UserInfo Login(string userName, string userPwd);
    }
}

第六步:先配置好在APP.config中的connectionStrings并在Help文件夹中创建ConstHelper类中把connectionStrings放在里面 然后实现Service中的所有接口BlogTypeInfoService、CommentInfoService、PostInfoService、UserInfoService 

配置connectionStrings

ConstHelper如下:

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WPF练习13简单的项目.Helper
{
    public static class ConstHelper
    {
        public static string ConnString { get; } = ConfigurationManager.ConnectionStrings["connString"].ConnectionString;
    }
}

BlogTypeInfoService如下:

using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WPF练习13简单的项目.Model.View;
using WPF练习13简单的项目.Model;
using WPF练习13简单的项目.Service;
using Dapper;
using WPF练习13简单的项目.Helper;

namespace WPF练习13简单的项目.ServiceImpl
{
    public class BlogTypeInfoService : IBlogTypeInfo
    {
        public bool Add(BlogTypeInfo model)
        {
            using (var conn = new SqlConnection(ConstHelper.ConnString))
            {
                conn.Open();
                var sql = "INSERT INTO BlogTypeInfo(TypeName,ParentBlogTypeId,DataStatus,CreateUserId,CreateTime,LastUpdateUserId,LastUpdateTime) VALUES (@TypeName,@ParentBlogTypeId,@DataStatus,@CreateUserId,@CreateTime,@LastUpdateUserId,@LastUpdateTime)";
                return conn.Execute(sql, model) > 0;
            }
        }

        public bool Delete(int id)
        {
            using (var conn = new SqlConnection(ConstHelper.ConnString))
            {
                conn.Open();
                var sql = "UPDATE BlogTypeInfo Set DataStatus=1 WHERE BlogTypeId=@BlogTypeId";
                var param = new { BlogTypeId = id };
                return conn.Execute(sql, param) > 0;
            }
        }

        public List<BlogTypeInfoView> GetListByPage(string strWhere, string orderBy, int startIndex, int endIndex)
        {
            using (var conn = new SqlConnection(ConstHelper.ConnString))
            {
                conn.Open();
                StringBuilder sql = new StringBuilder();
                sql.Append("SELECT * FROM ( ");
                sql.Append(" SELECT ROW_NUMBER() OVER (");

                if (!string.IsNullOrEmpty(orderBy.Trim()))
                    sql.Append("ORDER BY T." + orderBy);
                else
                    sql.Append("ORDER BY T.UserId DESC");

                sql.Append(")AS Row, T.*  FROM BlogTypeInfoView T ");
                if (!string.IsNullOrEmpty(strWhere.Trim()))
                {
                    sql.Append(" WHERE " + strWhere);
                }
                sql.Append(" ) TT");
                sql.AppendFormat(" WHERE TT.Row BETWEEN {0} AND {1}", startIndex, endIndex);

                return conn.Query<BlogTypeInfoView>(sql.ToString()).ToList();
            }
        }

        public BlogTypeInfo GetModel(int id)
        {
            using (var conn = new SqlConnection(ConstHelper.ConnString))
            {
                conn.Open();
                var sql = "SELECT * FROM BlogTypeInfo WHERE BlogTypeId=@BlogTypeId";
                var param = new { BlogTypeId = id };
                return conn.QueryFirstOrDefault<BlogTypeInfo>(sql, param);
            }
        }

        public bool Update(BlogTypeInfo model)
        {
            using (var conn = new SqlConnection(ConstHelper.ConnString))
            {
                conn.Open();
                var sql = "UPDATE BlogTypeInfo SET TypeName=@TypeName,ParentBlogTypeId=@ParentBlogTypeId,DataStatus=@DataStatus,CreateUserId=@CreateUserId,CreateTime=@CreateTime,LastUpdateUserId=@LastUpdateUserId,LastUpdateTime=@LastUpdateTime WHERE BlogTypeId=@BlogTypeId";
                return conn.Execute(sql, model) > 0;
            }
        }
    }
}

CommentInfoService如下:

using Dapper;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WPF练习13简单的项目.Helper;
using WPF练习13简单的项目.Model;
using WPF练习13简单的项目.Model.View;
using WPF练习13简单的项目.Service;

namespace WPF练习13简单的项目.ServiceImpl
{
    public class CommentInfoService : ICommentInfo
    {
        public bool Add(CommentInfo model)
        {
            using (var conn = new SqlConnection(ConstHelper.ConnString))
            {
                conn.Open();
                var sql = "INSERT INTO CommentInfo(CommentContent,DataStatus,CreateUserId,CreateTime,LastUpdateUserId,LastUpdateTime) VALUES (@CommentContent,@DataStatus,@CreateUserId,@CreateTime,@LastUpdateUserId,@LastUpdateTime)";
                return conn.Execute(sql, model) > 0;
            }
        }

        public bool Delete(int id)
        {
            using (var conn = new SqlConnection(ConstHelper.ConnString))
            {
                conn.Open();
                var sql = "UPDATE CommentInfo Set DataStatus=1 WHERE CommentId=@CommentId";
                var param = new { CommentId = id };
                return conn.Execute(sql, param) > 0;
            }
        }

        public List<CommentInfoView> GetListByPage(string strWhere, string orderBy, int startIndex, int endIndex)
        {
            using (var conn = new SqlConnection(ConstHelper.ConnString))
            {
                conn.Open();
                StringBuilder sql = new StringBuilder();
                sql.Append("SELECT * FROM ( ");
                sql.Append(" SELECT ROW_NUMBER() OVER (");

                if (!string.IsNullOrEmpty(orderBy.Trim()))
                    sql.Append("ORDER BY T." + orderBy);
                else
                    sql.Append("ORDER BY T.UserId DESC");

                sql.Append(")AS Row, T.*  FROM CommentInfoView T ");
                if (!string.IsNullOrEmpty(strWhere.Trim()))
                {
                    sql.Append(" WHERE " + strWhere);
                }
                sql.Append(" ) TT");
                sql.AppendFormat(" WHERE TT.Row BETWEEN {0} AND {1}", startIndex, endIndex);

                return conn.Query<CommentInfoView>(sql.ToString()).ToList();
            }
        }

        public CommentInfo GetModel(int id)
        {
            using (var conn = new SqlConnection(ConstHelper.ConnString))
            {
                conn.Open();
                var sql = "SELECT * FROM CommentInfo WHERE CommentId=@CommentId";
                var param = new { CommentId = id };
                return conn.QueryFirstOrDefault<CommentInfo>(sql, param);
            }
        }

        public bool Update(CommentInfo model)
        {
            using (var conn = new SqlConnection(ConstHelper.ConnString))
            {
                conn.Open();
                var sql = "UPDATE CommentInfo SET CommentContent=@CommentContent,DataStatus=@DataStatus,CreateUserId=@CreateUserId,CreateTime=@CreateTime,LastUpdateUserId=@LastUpdateUserId,LastUpdateTime=@LastUpdateTime WHERE CommentId=@CommentId";
                return conn.Execute(sql, model) > 0;
            }
        }
    }
}

PostInfoService如下:

using Dapper;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WPF练习13简单的项目.Helper;
using WPF练习13简单的项目.Model;
using WPF练习13简单的项目.Model.View;
using WPF练习13简单的项目.Service;

namespace WPF练习13简单的项目.ServiceImpl
{
    public class PostInfoService: IPostInfo
    {
        public bool Add(PostInfo model)
        {
            using (var conn = new SqlConnection(ConstHelper.ConnString))
            {
                conn.Open();
                var sql = "INSERT INTO PostInfo(Title,PostContent,BlogTypeId,LikeCount,HateCount,ReadCount,CommentCount,DataStatus,CreateUserId,CreateTime,LastUpdateUserId,LastUpdateTime) VALUES (@Title,@PostContent,@BlogTypeId,@LikeCount,@HateCount,@ReadCount,@CommentCount,@DataStatus,@CreateUserId,@CreateTime,@LastUpdateUserId,@LastUpdateTime)";
                return conn.Execute(sql, model) > 0;
            }
        }

        public bool Delete(int id)
        {
            using (var conn = new SqlConnection(ConstHelper.ConnString))
            {
                conn.Open();
                var sql = "UPDATE PostInfo Set DataStatus=1 WHERE PostId=@PostId";
                var param = new { PostId = id };
                return conn.Execute(sql, param) > 0;
            }
        }

        public List<PostInfoView> GetListByPage(string strWhere, string orderBy, int startIndex, int endIndex)
        {
            using (var conn = new SqlConnection(ConstHelper.ConnString))
            {
                conn.Open();
                StringBuilder sql = new StringBuilder();
                sql.Append("SELECT * FROM ( ");
                sql.Append(" SELECT ROW_NUMBER() OVER (");

                if (!string.IsNullOrEmpty(orderBy.Trim()))
                    sql.Append("ORDER BY T." + orderBy);
                else
                    sql.Append("ORDER BY T.UserId DESC");

                sql.Append(")AS Row, T.*  FROM PostInfoView T ");
                if (!string.IsNullOrEmpty(strWhere.Trim()))
                {
                    sql.Append(" WHERE " + strWhere);
                }
                sql.Append(" ) TT");
                sql.AppendFormat(" WHERE TT.Row BETWEEN {0} AND {1}", startIndex, endIndex);

                return conn.Query<PostInfoView>(sql.ToString()).ToList();
            }
        }

        public PostInfo GetModel(int id)
        {
            using (var conn = new SqlConnection(ConstHelper.ConnString))
            {
                conn.Open();
                var sql = "SELECT * FROM PostInfo WHERE PostId=@PostId";
                var param = new { PostId = id };
                return conn.QueryFirstOrDefault<PostInfo>(sql, param);
            }
        }

        public bool Update(PostInfo model)
        {
            using (var conn = new SqlConnection(ConstHelper.ConnString))
            {
                conn.Open();
                var sql = "UPDATE PostInfo SET Title=@Title,PostContent=@PostContent,BlogTypeId=@BlogTypeId,LikeCount=@LikeCount,HateCount=@HateCount,ReadCount=@ReadCount,CommentCount=@CommentCount,DataStatus=@DataStatus,CreateUserId=@CreateUserId,CreateTime=@CreateTime,LastUpdateUserId=@LastUpdateUserId,LastUpdateTime=@LastUpdateTime WHERE PostId=@PostId";
                return conn.Execute(sql, model) > 0;
            }
        }
    }
}

UserInfoService如下:

using Dapper;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WPF练习13简单的项目.Helper;
using WPF练习13简单的项目.Model;
using WPF练习13简单的项目.Model.View;
using WPF练习13简单的项目.Service;

namespace WPF练习13简单的项目.ServiceImpl
{
    public class UserInfoService: IUserInfo
    {
        public bool Add(UserInfo model)
        {
            using (var conn = new SqlConnection(ConstHelper.ConnString))
            {
                conn.Open();
                var sql = "INSERT INTO UserInfo(UserName,UserPwd,Phone,NickName,Logo,RealName,Sex,Birthday,DataStatus,CreateUserId,CreateTime,LastUpdateUserId,LastUpdateTime) VALUES (@UserName,@UserPwd,@Phone,@NickName,@Logo,@RealName,@Sex,@Birthday,@DataStatus,@CreateUserId,@CreateTime,@LastUpdateUserId,@LastUpdateTime)";
                return conn.Execute(sql, model) > 0;
            }
        }

        public bool Delete(int id)
        {
            using (var conn = new SqlConnection(ConstHelper.ConnString))
            {
                conn.Open();
                var sql = "UPDATE UserInfo Set DataStatus=1 WHERE UserId=@UserId";
                var param = new { UserId = id };
                return conn.Execute(sql, param) > 0;
            }
        }

        public List<UserInfoView> GetListByPage(string strWhere, string orderBy, int startIndex, int endIndex)
        {
            using (var conn = new SqlConnection(ConstHelper.ConnString))
            {
                conn.Open();
                StringBuilder sql = new StringBuilder();
                sql.Append("SELECT * FROM ( ");
                sql.Append(" SELECT ROW_NUMBER() OVER (");

                if (!string.IsNullOrEmpty(orderBy.Trim()))
                    sql.Append("ORDER BY T." + orderBy);
                else
                    sql.Append("ORDER BY T.UserId DESC");

                sql.Append(")AS Row, T.*  FROM UserInfoView T ");
                if (!string.IsNullOrEmpty(strWhere.Trim()))
                {
                    sql.Append(" WHERE " + strWhere);
                }
                sql.Append(" ) TT");
                sql.AppendFormat(" WHERE TT.Row BETWEEN {0} AND {1}", startIndex, endIndex);

                return conn.Query<UserInfoView>(sql.ToString()).ToList();
            }

        }

        public UserInfo GetModel(int id)
        {
            using (var conn = new SqlConnection(ConstHelper.ConnString))
            {
                conn.Open();
                var sql = "SELECT * FROM UserInfo WHERE UserId=@UserId";
                var param = new { UserId = id };
                return conn.QueryFirstOrDefault<UserInfo>(sql, param);
            }
        }

        public UserInfo Login(string userName, string userPwd)
        {
            using (var conn = new SqlConnection(ConstHelper.ConnString))
            {
                conn.Open();
                var sql = "SELECT * FROM UserInfo WHERE UserName=@UserName AND UserPwd=@UserPwd";
                var param = new { UserName = userName, UserPwd = userPwd };
                return conn.QueryFirstOrDefault<UserInfo>(sql, param);
            }
        }

        public bool Update(UserInfo model)
        {
            using (var conn = new SqlConnection(ConstHelper.ConnString))
            {
                conn.Open();
                var sql = "UPDATE UserInfo SET UserName=@UserName,UserPwd=@UserPwd,Phone=@Phone,NickName=@NickName,Logo=@Logo,RealName=@RealName,Sex=@Sex,Birthday=@Birthday,DataStatus=@DataStatus,CreateUserId=@CreateUserId,CreateTime=@CreateTime,LastUpdateUserId=@LastUpdateUserId,LastUpdateTime=@LastUpdateTime WHERE UserId=@UserId";
                return conn.Execute(sql, model) > 0;
            }
        }
    }
}

第七步:在App.cs文件中放入想要放入Ioc容器的对象

using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using WPF练习13简单的项目.Service;
using WPF练习13简单的项目.ServiceImpl;
using WPF练习13简单的项目.View;
using WPF练习13简单的项目.View.UserControls;

namespace WPF练习13简单的项目
{
    /// <summary>
    /// App.xaml 的交互逻辑
    /// </summary>
    public partial class App : Application
    {
        public IServiceProvider Services { get; }
        public App()
        {
            Services = ConfigurationServices();
        }

        public static new App Current { get { return (App)Application.Current; } }

        private IServiceProvider ConfigurationServices()
        {
            ServiceCollection services = new ServiceCollection();

            // 放窗体
            services.AddSingleton<Main>();

            // 放用户控件
            services.AddSingleton<BlogType>();
            services.AddSingleton<Comment>();
            services.AddSingleton<Post>();
            services.AddSingleton<User>();

            // 放服务
            services.AddSingleton<IBlogTypeInfo, BlogTypeInfoService>();
            services.AddSingleton<ICommentInfo, CommentInfoService>();
            services.AddSingleton<IPostInfo, PostInfoService>();
            services.AddSingleton<IUserInfo, UserInfoService>();

            return services.BuildServiceProvider();
        }
    }
}

第八步:在Helper文件夹中创建LoginInfoHelper类存放登录的用户 并在ViewModel创建LoginViewModel类和MainViewModel类

 

using CTMVVMDemo.Model;

namespace CTMVVMDemo.Helper
{
    public static class LoginInfoHelper
    {
        public static UserInfo CurrentUser { get; set; }
    }
}

LoginViewModel如下:

using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using WPF练习13简单的项目.Helper;
using WPF练习13简单的项目.Model;
using WPF练习13简单的项目.Service;
using WPF练习13简单的项目.View;


namespace WPF练习13简单的项目.ViewModel
{
    public class LoginViewModel : ObservableObject
    {
        private readonly IUserInfo userService;
        public LoginViewModel()
        {
            userService = App.Current.Services.GetService<IUserInfo>();
        }

        private string userName;
        public string UserName
        {
            get => userName;
            set => SetProperty(ref userName, value);
        }

        private SecureString password;
        public SecureString Password
        {
            get => password;
            set => SetProperty(ref password, value);
        }

        public RelayCommand<Login> LoginCommand
        {
            get
            {
                return new RelayCommand<Login>((loginWin) =>
                {
                    Button btnLogin = loginWin.FindName("btnLogin") as Button;
                    if (btnLogin != null) btnLogin.Focus();
                    UserInfo userInfo = userService.Login(UserName, SecureStringToString(Password));
                    if (userInfo == null)
                    {
                        MessageBox.Show("登录失败,请检查账号或密码是否正确!", "错误", System.Windows.MessageBoxButton.OK, MessageBoxImage.Error);
                        return;
                    }
                    LoginInfoHelper.CurrentUser = userInfo;
                    loginWin.Hide();
                    var mainWin = App.Current.Services.GetService<Main>();
                    mainWin.Show();
                });
            }
        }

        public RelayCommand<object> PasswordChangedCommand
        {
            get
            {
                return new RelayCommand<object>((obj) =>
                {
                    var passwordBox = obj as PasswordBox;
                    if (passwordBox != null) Password = passwordBox.SecurePassword;
                });
            }
        }

        /// <summary>
        /// 将 SecureString 类型的数据转换为普通的字符串类型。 https://www.cnblogs.com/CDRPS/p/18156533
        /// </summary>
        /// <param name="secureString">要转换的 SecureString 对象。</param>
        /// <returns>转换后的字符串,如果转换失败则返回空字符串。</returns>
        private string SecureStringToString(SecureString secureString)
        {
            // 初始化指针
            IntPtr ptr = IntPtr.Zero;
            try
            {
                // 将 SecureString 转换为指针
                ptr = Marshal.SecureStringToGlobalAllocUnicode(secureString);
                if (ptr != IntPtr.Zero)
                {
                    // 将指针中的数据复制到一个普通的字符串
                    return Marshal.PtrToStringUni(ptr);
                }
                else
                {
                    return string.Empty;
                }
            }
            catch (Exception ex)
            {
                // 处理异常
                Console.WriteLine($"转换 SecureString 出错:{ex.Message}");
                return string.Empty;
            }
            finally
            {
                // 清除内存中的敏感数据
                if (ptr != IntPtr.Zero)
                {
                    Marshal.ZeroFreeGlobalAllocUnicode(ptr);
                }
            }
        }
    }
}

MainViewModel如下:

using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using WPF练习13简单的项目.Helper;
using WPF练习13简单的项目.Model;
using WPF练习13简单的项目.Service;
using WPF练习13简单的项目.View.UserControls;

namespace WPF练习13简单的项目.ViewModel
{
    public class MainViewModel: ObservableObject
    {
        private readonly IUserInfo userService;
        public MainViewModel()
        {
            userService = App.Current.Services.GetService<IUserInfo>();
            CurrentUser = LoginInfoHelper.CurrentUser;
            WhichUserControl = App.Current.Services.GetService<User>();
        }

        private UserInfo currentUser;
        public UserInfo CurrentUser
        {
            get => currentUser;
            set => SetProperty(ref currentUser, value);
        }

        private UserControl whichUserControl;
        public UserControl WhichUserControl
        {
            get => whichUserControl;
            set => SetProperty(ref whichUserControl, value);
        }

        public RelayCommand<string> ToggleCommand
        {
            get
            {
                return new RelayCommand<string>((str) =>
                {
                    switch (str)
                    {
                        case "用户管理":
                            WhichUserControl = App.Current.Services.GetService<User>();
                            break;
                        case "博客类型":
                            WhichUserControl = App.Current.Services.GetService<BlogType>();
                            break;
                        case "博客管理":
                            WhichUserControl = App.Current.Services.GetService<Post>();
                            break;
                        case "评论管理":
                            WhichUserControl = App.Current.Services.GetService<Comment>();
                            break;
                        default:
                            WhichUserControl = App.Current.Services.GetService<User>();
                            break;
                    }
                });
            }
        }

        public RelayCommand ClosedCommand
        {
            get
            {
                return new RelayCommand(() =>
                {
                    App.Current.Shutdown();
                });
            }
        }
    }
}

第九步:在Login.XAML和Main.XAML中写对应的前端代码

1.在Dict文件夹中创建LoginDictionary.xaml存放登录窗口的样式

 LoginDictionary.xaml如下:
<Application x:Class="WPF练习13简单的项目.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:local="clr-namespace:WPF练习13简单的项目"
             StartupUri="View/Login.xaml">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Dict/LoginDictionary.xaml" />
            </ResourceDictionary.MergedDictionaries>

            <Style x:Key="ButtonDefault"
                   TargetType="Button">
                <Setter Property="FocusVisualStyle"
                        Value="{x:Null}" />
                <Setter Property="Width"
                        Value="80" />
                <Setter Property="Height"
                        Value="30" />
                <Setter Property="Foreground"
                        Value="#ffffff" />
                <Setter Property="Background"
                        Value="#9e6f55" />
                <Setter Property="BorderThickness"
                        Value="0" />
            </Style>
            <Style x:Key="TextBoxDefault"
                   TargetType="TextBox">
                <Setter Property="Width"
                        Value="150" />
                <Setter Property="Height"
                        Value="30" />
                <Setter Property="VerticalContentAlignment"
                        Value="Center" />
                <Setter Property="Padding"
                        Value="10,0,0,0" />
                <Setter Property="BorderBrush"
                        Value="#9e6f55" />
            </Style>
            <Style x:Key="PasswordBoxDefault"
                   TargetType="PasswordBox">
                <Setter Property="Width"
                        Value="150" />
                <Setter Property="Height"
                        Value="30" />
                <Setter Property="VerticalContentAlignment"
                        Value="Center" />
                <Setter Property="Padding"
                        Value="10,0,0,0" />
                <Setter Property="BorderBrush"
                        Value="#9e6f55" />
            </Style>

        </ResourceDictionary>
    </Application.Resources>
</Application>

2.App.XAML文件中存在共同的样式以及存放LoginDictionary.xaml的引用

 <Application.Resources>
     <ResourceDictionary>
         <ResourceDictionary.MergedDictionaries>
             <ResourceDictionary Source="Dict/LoginDictionary.xaml" />
         </ResourceDictionary.MergedDictionaries>

         <Style x:Key="ButtonDefault"
                TargetType="Button">
             <Setter Property="FocusVisualStyle"
                     Value="{x:Null}" />
             <Setter Property="Width"
                     Value="80" />
             <Setter Property="Height"
                     Value="30" />
             <Setter Property="Foreground"
                     Value="#ffffff" />
             <Setter Property="Background"
                     Value="#9e6f55" />
             <Setter Property="BorderThickness"
                     Value="0" />
         </Style>
         <Style x:Key="TextBoxDefault"
                TargetType="TextBox">
             <Setter Property="Width"
                     Value="150" />
             <Setter Property="Height"
                     Value="30" />
             <Setter Property="VerticalContentAlignment"
                     Value="Center" />
             <Setter Property="Padding"
                     Value="10,0,0,0" />
             <Setter Property="BorderBrush"
                     Value="#9e6f55" />
         </Style>
         <Style x:Key="PasswordBoxDefault"
                TargetType="PasswordBox">
             <Setter Property="Width"
                     Value="150" />
             <Setter Property="Height"
                     Value="30" />
             <Setter Property="VerticalContentAlignment"
                     Value="Center" />
             <Setter Property="Padding"
                     Value="10,0,0,0" />
             <Setter Property="BorderBrush"
                     Value="#9e6f55" />
         </Style>

     </ResourceDictionary>

3.在Login.XAML文件中创建上下文并创建基本样式 

<Window x:Class="WPF练习13简单的项目.View.Login"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WPF练习13简单的项目.View"
        xmlns:vm="clr-namespace:WPF练习13简单的项目.ViewModel"
        xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
        d:DataContext="{d:DesignInstance Type=vm:LoginViewModel}"
        FocusManager.FocusedElement="{Binding ElementName=txtUserName}"
        mc:Ignorable="d"
        Title="Login"
        Height="450"
        Width="800">
    <Window.DataContext>
        <vm:LoginViewModel />
    </Window.DataContext>
    <Grid HorizontalAlignment="Center"
          VerticalAlignment="Center">
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition />
            <RowDefinition />
        </Grid.RowDefinitions>

        <WrapPanel>
            <Label Content="账号:" />
            <TextBox Name="txtUserName"
                     Style="{StaticResource TextBoxDefault}"
                     Template="{DynamicResource TextBoxTemplate}"
                     Text="{Binding UserName}" />
        </WrapPanel>

        <WrapPanel Grid.Row="1"
                   Margin="0,10,0,0">
            <Label Content="密码:" />
            <PasswordBox Name="PasswordBox"
                         Style="{StaticResource PasswordBoxDefault}"
                         Template="{DynamicResource PasswordBoxTemplate}">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="PasswordChanged">
                        <i:InvokeCommandAction Command="{Binding PasswordChangedCommand}"
                                               CommandParameter="{Binding ElementName=PasswordBox}" />
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </PasswordBox>
        </WrapPanel>

        <WrapPanel Grid.Row="2"
                   Margin="0,10,0,0"
                   HorizontalAlignment="Center">
            <Button Name="btnLogin"
                    Command="{Binding LoginCommand}"
                    CommandParameter="{Binding RelativeSource={RelativeSource AncestorType=Window}}"
                    Content="登录"
                    IsDefault="True"
                    Style="{StaticResource ButtonDefault}"
                    Template="{DynamicResource ButtonTemplate}" />
        </WrapPanel>
    </Grid>
</Window>

4.在Main.XAML文件中创建上下文并创建基本样式 

<Window x:Class="WPF练习13简单的项目.View.Main"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WPF练习13简单的项目.View"
        xmlns:vm="clr-namespace:WPF练习13简单的项目.ViewModel"
        xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
        d:DataContext="{d:DesignInstance Type=vm:MainViewModel}"
        WindowStartupLocation="CenterScreen"
        mc:Ignorable="d"
        Title="Main"
        Height="450"
        Width="800">
    <Window.DataContext>
        <vm:MainViewModel />
    </Window.DataContext>

    <i:Interaction.Triggers>
        <i:EventTrigger EventName="Closed">
            <i:InvokeCommandAction Command="{Binding ClosedCommand}" />
        </i:EventTrigger>
    </i:Interaction.Triggers>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="60" />
            <RowDefinition />
        </Grid.RowDefinitions>

        <Grid Background="#f4eeee">
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition Width="200" />
            </Grid.ColumnDefinitions>

            <WrapPanel VerticalAlignment="Center">
                <TextBlock Padding="10,0,0,0"
                           FontSize="20"
                           Text="博客后台管理系统" />
            </WrapPanel>

            <WrapPanel Grid.Column="1"
                       HorizontalAlignment="Right"
                       VerticalAlignment="Center">
                <TextBlock VerticalAlignment="Center"
                           Text="当前用户:" />
                <TextBlock VerticalAlignment="Center"
                           Text="{Binding CurrentUser.UserName}" />
                <Button Margin="10,0"
                        Command="{Binding ClosedCommand}"
                        Content="退出"
                        Style="{StaticResource ButtonDefault}"
                        Template="{DynamicResource ButtonTemplate}" />
            </WrapPanel>
        </Grid>


        <Grid Grid.Row="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="160" />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>

            <StackPanel Background="#9e6f55">

                <Button Width="160"
                        Margin="0,10,0,10"
                        Command="{Binding ToggleCommand}"
                        CommandParameter="用户管理"
                        Content="用户管理"
                        Style="{StaticResource ButtonDefault}"
                        Template="{DynamicResource ButtonTemplate}" />
                <Button Width="160"
                        Margin="0,0,0,10"
                        Command="{Binding ToggleCommand}"
                        CommandParameter="博客类型"
                        Content="博客类型"
                        Style="{StaticResource ButtonDefault}"
                        Template="{DynamicResource ButtonTemplate}" />
                <Button Width="160"
                        Margin="0,0,0,10"
                        Command="{Binding ToggleCommand}"
                        CommandParameter="博客管理"
                        Content="博客管理"
                        Style="{StaticResource ButtonDefault}"
                        Template="{DynamicResource ButtonTemplate}" />
                <Button Width="160"
                        Margin="0,0,0,10"
                        Command="{Binding ToggleCommand}"
                        CommandParameter="评论管理"
                        Content="评论管理"
                        Style="{StaticResource ButtonDefault}"
                        Template="{DynamicResource ButtonTemplate}" />
            </StackPanel>

            <ContentControl Grid.Column="1"
                            Margin="10"
                            Content="{Binding WhichUserControl}" />

        </Grid>
    </Grid>
</Window>

效果如下:

 

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2234775.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

【51蛋骗鸡一共八个灯 按顺序依次12。34。56。78。两个灯同时亮灭的代码】2022-1-19

缘由proteus流水灯-嵌入式-CSDN问答 仿真51单片机流水灯代码-编程语言-CSDN问答 protues仿真单片机控制led流水灯-嵌入式-CSDN问答 #include<reg52.h>//头文件 void main() //主函数 {unsigned char y23;unsigned int ys0;while(1){if(!ys){P0y2;if(!(y2*4))y23…

数据结构:跳表实现(C++)

个人主页 &#xff1a; 个人主页 个人专栏 &#xff1a; 《数据结构》 《C语言》《C》《Linux》《网络》 《redis学习笔记》 文章目录 前言跳表跳表的优化思路skiplist&#xff0c;平衡搜索树&#xff0c;哈希表的对比 实现思路SkiplistNodesearch 搜索add 增加earse 删除 整体…

ssm基于Web的汽车客运订票系统的设计与实现+vue

系统包含&#xff1a;源码论文 所用技术&#xff1a;SpringBootVueSSMMybatisMysql 免费提供给大家参考或者学习&#xff0c;获取源码看文章最下面 需要定制看文章最下面 目 录 目 录 I 摘 要 III ABSTRACT IV 1 绪论 1 1.1 课题背景 1 1.2 研究现状 1 1.3 研究内容…

SSM中maven

一&#xff1a;maven的分模块开发 maven分模块就是在多人操作一个项目时将maven模块导入依赖&#xff0c;注意仓库里面没有资源坐标&#xff0c;需要使用install操作下载。 二&#xff1a;maven的依赖管理 pom文件中直接写的依赖叫做直接依赖&#xff0c;直接依赖中用到的依…

如何找到养生生活视频素材?推荐几个优秀网站

今天&#xff0c;我们来聊一个实用的话题&#xff0c;那就是如何找到优质的养生视频素材。作为自媒体创作者&#xff0c;高质量的视频素材对内容制作至关重要。不论你是刚入行的新手&#xff0c;还是已经积累了一定粉丝的大V&#xff0c;找到合适的养生视频素材都能帮助你更好地…

vscode的一些使用心得

问题1&#xff1a;/home目录空间有限 连接wsl或者remote的时候&#xff0c;会在另一端下载一个.vscode-server&#xff0c;vscode的插件都会安装进去&#xff0c;导致空间增加很多&#xff0c;可以选择更换这个文件的位置 参考&#xff1a;https://blog.csdn.net/weixin_4389…

画动态爱心(Python-matplotlib)

介绍 氵而已 由于用的是 AI&#xff0c;注释得非常清楚&#xff0c;自己改改也可以用 代码 # -*- coding: utf-8 -*- # Environment PyCharm # File_name 尝试1 |User Pfolg # 2024/11/05 22:45 import numpy as np import matplotlib.pyplot as plt import matplot…

13-鸿蒙开发中的综合实战:华为登录界面

大家好&#xff0c;欢迎来到鸿蒙开发系列教程&#xff01;今天&#xff0c;我们将通过一个综合实战项目来实现一个华为登录界面。这个项目将涵盖输入框组件、按钮组件、文本组件和布局容器的使用&#xff0c;帮助你更好地理解和应用这些组件。无论你是初学者还是有一定经验的开…

LCL三相并网逆变器simulink仿真+说明文档

背景描述&#xff1a; 详细解析了LCL三相并网逆变器的工作原理&#xff0c;强调了准PR比例谐振控制的重要性&#xff0c;讨论了电感、电容参数选择及保护电路设计。通过仿真结果展示了逆变器性能优化的方法&#xff0c;以提升系统效率和稳定性。 模型介绍&#xff1a; 整体模…

突破1200°C高温性能极限!北京科技大学用机器学习合成24种耐火高熵合金,室温延展性极佳

在工程应用中&#xff0c;如燃气轮机、核反应堆和航空推进系统&#xff0c;对具备优异高温机械性能的金属合金需求十分旺盛。由于材料熔点的固有限制&#xff0c;传统镍基 (Ni) 高温合金的耐温能力已接近极限。为满足开发高温结构材料的需求&#xff0c;耐火高熵合金 (RHEAs) 于…

使用GPT-SoVITS训练语音模型

1.项目演示 阅读单句话 1725352713141 读古诗 1725353700203 2.项目环境 开发环境&#xff1a;linux 机器配置如下&#xff1a;实际使用率百分之二十几&#xff0c; 3.开发步骤 1.首先是准备数据集&#xff0c;要求是wav格式&#xff0c;一到两个小时即可&#xff0c; 2.…

react18中redux-promise搭配redux-thunk完美简化异步数据操作

用过redux-thunk的应该知道&#xff0c;操作相对繁琐一点&#xff0c;dispatch本只可以出发plain object。redux-thunk让dispatch可以返回一个函数。而redux-promise在此基础上大大简化了操作。 实现效果 关键逻辑代码 store/index.js import { createStore, applyMiddlewar…

【JS学习】10. web API-BOM

文章目录 Web APIs - 第5天笔记js组成window对象定时器-延迟函数location对象navigator对象histroy对象本地存储&#xff08;今日重点&#xff09;localStorage&#xff08;重点&#xff09;sessionStorage&#xff08;了解&#xff09;localStorage 存储复杂数据类型 综合案例…

The First项目报告:MANTRA如何实现世界金融区块链化?

RWA&#xff08;现实世界资产&#xff09;代币化被视为加密领域的下一个财富增长点&#xff0c;它作为桥梁连接传统金融与加密世界&#xff0c;潜力覆盖数十万亿美元资产市场。尽管面临技术、监管及市场挑战&#xff0c;RWA项目正逐步获得广泛关注。MANTRA是一个Cosmos SDK基L1…

DAY21|二叉树Part08|LeetCode: 669. 修剪二叉搜索树、108.将有序数组转换为二叉搜索树、538.把二叉搜索树转换为累加树

目录 LeetCode: 669. 修剪二叉搜索树 基本思路 C代码 LeetCode: 108.将有序数组转换为二叉搜索树 基本思路 C代码 LeetCode: 538.把二叉搜索树转换为累加树 基本思路 C代码 LeetCode: 669. 修剪二叉搜索树 力扣代码链接 文字讲解&#xff1a;LeetCode: 669. 修剪二叉搜…

大模型LLama3!!!Ollama下载、部署和应用(保姆级详细教程)

首先呢&#xff0c;大家在网站先下载ollama软件 这就和anaconda和python是一样的 废话不多说 直接上链接&#xff1a;Download Ollama on Windows 三个系统都支持 注意&#xff1a; 这里的Models&#xff0c;就是在上面&#xff0c;大家点开之后&#xff0c;里面有很多模型…

C++转义序列

\b \b是一个退格符&#xff08;backspace character&#xff09;&#xff0c;它的作用是将光标向左移动一个位置&#xff0c;但并不会删除光标位置上的字符。这个行为在某些情况下可能会导致视觉上的字符“消失”&#xff0c;但实际上这些字符仍然存在于输出缓冲区中&#xf…

[渲染层网络层错误] net::ERR_CONTENT_LENGTH_MISMATCH 问题解决

问题描述 问题背景 微信小程序访问后端img资源的时候&#xff0c;偶尔出现这个感叹号&#xff0c;图片加载不出来&#xff0c;但是对应的url贴出来在浏览器中访问&#xff0c;或者重新加载是可以访问的。 错误描述 经查询前端报错 [渲染层网络层错误] net::ERR_CONTENT_LE…

初始JavaEE篇 —— 网络编程(1):基础的网络知识

找往期文章包括但不限于本期文章中不懂的知识点&#xff1a; 个人主页&#xff1a;我要学编程程(ಥ_ಥ)-CSDN博客 所属专栏&#xff1a;JavaEE 目录 前言&#xff1a; 网络的发展历程 网络通信基础 IP地址 端口号 网络协议 网络通信的流程 前言&#xff1a; 我们现在所…

基于SSM+小程序的高校寻物平台管理系统(失物1)

&#x1f449;文末查看项目功能视频演示获取源码sql脚本视频导入教程视频 1、项目介绍 本基于微信小程序的高校寻物平台有管理员&#xff0c;用户以及失主三个角色。 1、管理员功能有个人中心&#xff0c;用户管理&#xff0c;失主管理&#xff0c;寻物启示管理&#xff0c;拾…