简单的物流项目实战,WPF的MVVM设计模式(四)
接下来写ViewModels
创建运单的ViewModel类
public class CreateExpressWindowViewModel: NotificationObject
{
private string province; public string Province
{
get
{
return province;
}
set
{
province = value;
this.RaisePropertyChanged("Province");
}
} private string city; public string City
{
get
{
return city;
}
set
{
city = value;
this.RaisePropertyChanged("City");
}
} private string area; public string Area
{
get
{
return area;
}
set
{
area = value;
this.RaisePropertyChanged("Area");
}
} private string street; public string Street
{
get
{
return street;
}
set
{
street = value;
this.RaisePropertyChanged("Street");
}
} private string username; public string Username
{
get
{
return username;
}
set
{
username = value;
this.RaisePropertyChanged("Username");
}
} private string phonenumber; public string Phonenumber
{
get
{
return phonenumber;
}
set
{
phonenumber = value;
this.RaisePropertyChanged("Phonenumber");
}
} private string createtime; public string Createtime
{
get
{
return createtime;
}
set
{
createtime = value;
this.RaisePropertyChanged("Createtime");
}
} public DelegateCommand CreateExpressCommand { get; set; } public CreateExpressWindowViewModel()
{
Createtime = DateTime.Now.ToShortDateString();
CreateExpressCommand = new DelegateCommand(new Action(InsertExpress));
} private void InsertExpress()
{
//Random rd = new Random();
//int num = rd.Next(10000000, 99999999); InsertExpressService insertExpressService = new InsertExpressService();
Express express = new Express();
insertExpressService.InsertExpress(Province,City,Area,Street,Username,Phonenumber,Createtime);
MessageBox.Show("成功下单!");
ExpressWindow expressWindow = new ExpressWindow(); ReadExpressWindow readExpressWindow = new ReadExpressWindow();
readExpressWindow.Show();
expressWindow.Close();
}
}
public class GetExpressWindow : NotificationObject
{
private string province; public string Province
{
get
{
return province;
}
set
{
province = value;
this.RaisePropertyChanged("Province");
}
} private string city; public string City
{
get
{
return city;
}
set
{
city = value;
this.RaisePropertyChanged("City");
}
} private string area; public string Area
{
get
{
return area;
}
set
{
area = value;
this.RaisePropertyChanged("Area");
}
} private string street; public string Street
{
get
{
return street;
}
set
{
street = value;
this.RaisePropertyChanged("Street");
}
} private string username; public string Username
{
get
{
return username;
}
set
{
username = value;
this.RaisePropertyChanged("Username");
}
} private string phonenumber; public string Phonenumber
{
get
{
return phonenumber;
}
set
{
phonenumber = value;
this.RaisePropertyChanged("Phonenumber");
}
} private string createtime; public string Createtime
{
get
{
return createtime;
}
set
{
createtime = value;
this.RaisePropertyChanged("Createtime");
}
}
public DelegateCommand GetExpressCommand { get; set; }
public GetExpressWindow()
{
GetExpressCommand = new DelegateCommand(new Action(GetExpress));
} private void GetExpress()
{
GetExpressService getExpressService = new GetExpressService();
Express express = new Express();
express = getExpressService.GetExpressData();
Province = express.Province;
City = express.City;
Area = express.Area;
Street = express.Street;
Username = express.UserName;
Phonenumber = express.PhoneNumber;
Createtime = express.CteateTime;
}
}
public class RegisteredWindowViewModel : NotificationObject
{ private string userAccount; public string UserAccount
{
get
{
return userAccount;
}
set
{
userAccount = value;
this.RaisePropertyChanged("UserAccount");
}
} private string password; public string Password
{
get
{
return password;
}
set
{
password = value;
this.RaisePropertyChanged("Password");
}
} public DelegateCommand InsertCommand { get; set; }
public RegisteredWindowViewModel()
{
InsertCommand = new DelegateCommand(new Action(InsertUserData));
} private void InsertUserData()
{
InsertRegisteredService insertRegisteredService = new InsertRegisteredService();
User user = new User();
user.UserAccount = UserAccount;
user.Password = Password;
user = insertRegisteredService.InsertUser(UserAccount, Password);
MessageBox.Show("注册成功!");
}
}
public class UserViewModel: NotificationObject
{
/// <summary>
/// 判断登录用户是否存在
/// </summary>
private bool exist; public bool Exist
{
get
{
return exist;
}
set
{
exist = value;
this.RaisePropertyChanged("Exist");
}
} }
public class UserWindowViewModel : NotificationObject
{ //var logger = NLog.LogManager.GetCurrentClassLogger();
//logger.Info("Hello World"); //var a = LogManager.GetCurrentClassLogger();
private string username; public string Username
{
get
{
return username;
}
set
{
username = value;
this.RaisePropertyChanged("Username");
}
} private string userpassword; public string Userpassword
{
get
{
return userpassword;
}
set
{
userpassword = value;
this.RaisePropertyChanged("Userpassword");
}
} public DelegateCommand GetCommand { get; set; } public UserWindowViewModel()
{
GetCommand = new DelegateCommand(new Action(GetUser));
}
private void GetUser()
{
GetUserService getUserServicelist = new GetUserService();
List<User> userslist = getUserServicelist.GetAllUser(); List<User> usernamecount = userslist.Where(x=>x.UserAccount==Username).ToList();
List<User> passwordcount = userslist.Where(x=>x.Password==Userpassword).ToList(); ///方法二
for (int i = ; i < usernamecount.Count; i++)
{
if (usernamecount[i].UserAccount==Username&&usernamecount[i].Password==Userpassword)
{
MessageBox.Show("登录成功!");
ExpressWindow expressWindow = new ExpressWindow();
expressWindow.ShowDialog();
return;
}
else
{
MessageBox.Show("账号不存在或密码错误!");
return;
}
} ///方法一
//if (usernamecount.Count > 0 && passwordcount.Count > 0)
//{
// MessageBox.Show("登录成功!");
// return;
//}
//else
//{
// MessageBox.Show("登录失败!");
// return;
//} }
}
以上分别为创建运单,查看运单,以及注册,以及登录的ViewModels,作为Views和Models之间的连接器
简单的物流项目实战,WPF的MVVM设计模式(四)的更多相关文章
- 简单的物流项目实战,WPF的MVVM设计模式(一)
新建一个WPF项目,命名为WMS 然后分别新建文件夹,Data,Models,Views,ViewModels,Services,如下图所示 然后通过NuGet安装连个Nuget包,分别为SQLite ...
- 简单的物流项目实战,WPF的MVVM设计模式(五)
开始界面 <Grid> <Grid.RowDefinitions> <RowDefinition/> <RowDefinition/> <RowD ...
- 简单的物流项目实战,WPF的MVVM设计模式(三)
往Services文件里面添加接口以及实现接口 IUserService接口 List<User> GetAllUser(); GetUserService类 ConnectToDatab ...
- 简单的物流项目实战,WPF的MVVM设计模式(二)
往Models文件添加一个类,ConnectObject /// <summary> /// 链接数据库字符串 /// </summary ...
- 使用MVVM设计模式构建WPF应用程序
使用MVVM设计模式构建WPF应用程序 本文是翻译大牛Josh Smith的文章,WPF Apps With The Model-View-ViewModel Design Pattern,译者水平有 ...
- WPF系列教程——(二)使用Prism实现MVVM设计模式 - 简书
原文:WPF系列教程--(二)使用Prism实现MVVM设计模式 - 简书 本文假设你已经知道MVVM设计模式是什么,所以直接进入正题,今天我们就用Prism来实现WPF的MVVM设计模式,百度上关于 ...
- CleanAOP实战系列--WPF中MVVM自动更新
CleanAOP实战系列--WPF中MVVM自动更新 作者: 立地 邮箱: jarvin_g@126.com QQ: 511363759 CleanAOP介绍:https://github.com/J ...
- 从0到1:使用Caliburn.Micro(WPF和MVVM)开发简单的计算器
从0到1:使用Caliburn.Micro(WPF和MVVM)开发简单的计算器 之前时间一直在使用Caliburn.Micro这种应用了MVVM模式的WPF框架做开发,是时候总结一下了. Calibu ...
- 企业项目实战 .Net Core + Vue/Angular 分库分表日志系统 | 简单的分库分表设计
前言 项目涉及到了一些设计模式,如果你看的不是很明白,没有关系坚持下来,写完之后去思考去品,你就会有一种突拨开云雾的感觉,所以请不要在半途感觉自己看不懂选择放弃,如果我哪里写的详细,或者需要修正请联系 ...
随机推荐
- TTTTTTTTTTTTTT POJ 3678 与或异或 2-SAT+强连通 模板题
Katu Puzzle Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9129 Accepted: 3391 Descripti ...
- hdu 1754 线段树 水题 单点更新 区间查询
I Hate It Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- 计蒜客 A1607 UVALive 8512 [ACM-ICPC 2017 Asia Xi'an]XOR
ICPC官网题面假的,要下载PDF,点了提交还找不到结果在哪看(我没找到),用VJ交还直接return 0;也能AC 计蒜客题面 这个好 Time limit 3000 ms OS Linux 题目来 ...
- WTL拖拽文件
1.对话框属性中把:Accept Files设置为TRUE,或者ModifyStyleEx(0, WS_EX_ACCEPTFILES); 2.在对话框中添加一个ListBox控件,并关联成员变量:m_ ...
- 用flask进行web开发
经理管理一个餐厅,推出每天都有特色菜的营销模式.他想根据一周中的每一天有一种特色菜. 客人想知道当天的特色菜是什么.另外再添加一个介绍页面.bios路径下,显示餐厅主人,厨师,服务生的简介. pyth ...
- Thymeleaf 2-基础语法
三.基础语法 1.创建HTML 由上文也可以知道需要在html中添加: <html xmlns:th="http://www.thymeleaf.org"> 这样,下文 ...
- Jprofiler远程监控JVM
一.下载并安装 本地和远程服务器分别安装Jprofiler,下载地址 二.Windows远程连接JVM配置 1.打开Windows客户端Jprofiler 2.点Cancel 3.创建远程会话 4.添 ...
- mini dc(选做)
一.题目要求 提交测试截图和码云练习项目链接,实现Linux下dc的功能,计算后缀表达式的值 二.源代码 1.MyDC类 import java.util.StringTokenizer; impor ...
- Gridview中显示的值根据数据库中带出的值作更改
前台页面对Gridview增加事件 OnRowDataBound="GridView1_RowDataBound"protected void GridView1_RowDataB ...
- 后盾网lavarel视频项目---lavarel中间件(使用中间件拦截没登录的用户)
后盾网lavarel视频项目---lavarel中间件(使用中间件拦截没登录的用户) 一.总结 一句话总结: 1.中间件中验证用户是否登录:if(!Auth::guard('admin')->c ...