简单的物流项目实战,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 分库分表日志系统 | 简单的分库分表设计
前言 项目涉及到了一些设计模式,如果你看的不是很明白,没有关系坚持下来,写完之后去思考去品,你就会有一种突拨开云雾的感觉,所以请不要在半途感觉自己看不懂选择放弃,如果我哪里写的详细,或者需要修正请联系 ...
随机推荐
- [BZOJ2987]Earthquake:类欧几里得算法
分析 类欧的式子到底是谁推的啊怎么这么神仙啊orz! 简单说一下这道题,题目中的约束条件可以转化为: \[ y \leq \frac{c-ax}{b} \] 有负数怎么办啊?转化一下: \[ y \l ...
- C# walls
在学习C#的阶段中,我们一点一点的往前爬, 此代码需要添加selenium ,和 获取 引用. using Ivony.Html.Parser; using Ivony.Html; using Ope ...
- 取值函数(getter)和存值函数(setter)
todo get和set关键字
- 大哥带我们的mysql注入 基于时间的盲注
?id= and ,,sleep()) ?id= and ,,sleep()) if语句/if()函数 在基于时间型SQL盲注中,我们经常使用条件语句来判断我们的操作是否正确: ?id= and = ...
- [CSP-S模拟测试]:123567(莫比乌斯函数+杜教筛+数论分块)
题目传送门(内部题92) 输入格式 一个整数$n$. 输出格式 一个答案$ans$. 样例 样例输入: 样例输出: 数据范围与提示 对于$20\%$的数据,$n\leqslant 10^6$. 对于$ ...
- MUI注
1.调试模式: 边改边看:左侧显示代码,右侧实时观看修改效果.可以调出“浏览器控制台”观测数据变化效果. 真机运行:电脑和手机都安装“360手机助手”,手机安装“F:\Program Files\HB ...
- 如何让你的JS代码写的更漂亮
感觉这篇文章总结的js的规范写法不错,拿来收藏.转自:https://mp.weixin.qq.com/s/AtR94IL9BW9EXOTnKOilmA 1. 按强类型风格写代码 JS是弱类型的,但是 ...
- vue树状结构(tree)
<!DOCTYPE html> <html> <head> <title></title> <style> body { fon ...
- kubernets部署微服务电商平台
一.准备条件 1) 确保kubernetes可以访问:reg.yunwei.edu镜像库(vim /etc/hosts) [root@cicd yml]# cat /etc/hosts 127.0.0 ...
- JDK7新特性
二进制字面量 数字字面量可以出现下划线 switch语句可以用字符串 泛型简化 异常的多个catch合并 try..with...resource语句 import java.io.FileReade ...