WPF+数据库+三层
1.计算类
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace Zwt
{
class Class1
{
}
interface Iation//定义计算接口
{
double Calation(double a, double b);
}
class Add : Iation//加法
{
public double Calation(double a, double b)
{
return a + b;
}
}
class Sub : Iation//减法
{
public double Calation(double a, double b)
{
return a - b;
}
}
class Mul : Iation//乘法
{
public double Calation(double a, double b)
{
return a * b;
}
}
class Div : Iation//除法
{
public double Calation(double a, double b)
{
if (b == )
{
throw new Exception("除数不能为零!");
}
else
{
return a / b;
}
}
}
class Factionsss//实现策略模式!
{
private Iation clation;
public Factionsss(string operation)
{
switch (operation)
{
case "+":
clation = new Add();
break;
case "-":
clation = new Sub();
break;
case "*":
clation = new Mul();
break;
case "/":
clation = new Div();
break;
} }
public double cal(double a, double b)
{
return clation.Calation(a, b);
} }
}
2,实体类
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace Zwt
{
class TIModel
{
string number1;
string number2;
string operation;
public string Number1
{
get
{
return number1;
}
set
{
number1 = value;
}
}
public string Number2
{
get
{
return number2;
}
set
{
number2 = value;
}
}
public string Operation
{
get
{
return operation;
}
set
{
operation = value;
}
} }
}
3.DBhelper类
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient; namespace Zwt
{
class DBhelper
{
string constr = "Data Source=.;Initial Catalog=TIKU;Integrated Security=True";
SqlConnection conn = new SqlConnection();
SqlCommand cmd = new SqlCommand();
public void dbcon()
{
try
{
conn = new SqlConnection(constr);
}
finally
{ } }
public void OPen()
{
conn.Open();
}
public void Close()
{
conn.Close();
}
public int execSql(string safeSql, params SqlParameter[] values)//增删
{
int result;
conn = new SqlConnection(constr);
cmd = new SqlCommand(safeSql, conn);
OPen();
if (values != null)
{
cmd.Parameters.AddRange(values);
}
try
{
result = cmd.ExecuteNonQuery();
}
finally
{
Close(); }
return result; }
public DataSet execDataset(string safeSql, params SqlParameter[] values)//读
{
conn = new SqlConnection(constr);
cmd = new SqlCommand(safeSql, conn);
if (values != null)
{
cmd.Parameters.AddRange(values);
}
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);
return ds;
} }
}
4,数据访问层
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace Zwt
{
class TIDAL
{
public int InsterTI(TIModel Ti)
{
string sql = "insert into TI(number1,operation,number2) values (@number1,@operation,@number2)";
SqlParameter[] para = new SqlParameter[]
{
new SqlParameter("@number1",Ti.Number1),
new SqlParameter("@operation",Ti.Operation),
new SqlParameter("@number2",Ti.Number2),
};
DBhelper helper = new DBhelper();
return helper.execSql(sql, para);
}
public DataSet Read()
{
string sql = "select number1,operation,number2 from TI";
DBhelper helper = new DBhelper();
return helper.execDataset(sql); }
public int DeleteTI()
{
string sql = "delete from TI ";
SqlParameter[] para = new SqlParameter[] { };
DBhelper helper = new DBhelper();
return helper.execSql(sql, para); }
}
}
5,业务逻辑层
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient; namespace Zwt
{
class TIBLL
{
TIDAL TI1 = new TIDAL();
public int InsertTi(TIModel Ti1)
{
return TI1.InsterTI(Ti1);
}
public int Delect()
{
return TI1.DeleteTI();
}
public DataSet Read()
{
return TI1.Read();
}
}
}
UI层
Mainwidowd的代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes; namespace Zwt
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
TIBLL tib = new TIBLL(); private void button1_Click(object sender, RoutedEventArgs e)
{
TIModel Tim = new TIModel();
Tim.Number1 =textBox1.Text;
Tim.Number2 = textBox2.Text;
Tim.Operation = comboBox1.Text;
int a = tib.InsertTi(Tim);
if (a > )
{
MessageBox.Show("保存成功!");
}
else
{
MessageBox.Show("保存失败!");
}
textBox1.Clear();
textBox2.Clear();
} private void button2_Click(object sender, RoutedEventArgs e)
{
int b = tib.Delect();
if (b > )
{
MessageBox.Show("删除成功!");
}
else
{
MessageBox.Show("删除失败!");
}
} private void button3_Click(object sender, RoutedEventArgs e)
{
Window1 win = new Window1();
win.ShowDialog();
} private void Window_Loaded(object sender, RoutedEventArgs e)
{ }
}
}
window1的代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Data.SqlClient;
using System.Data; namespace Zwt
{
/// <summary>
/// Window1.xaml 的交互逻辑
/// </summary>
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
TIBLL TIll = new TIBLL();
int i = ;
private void Window_Loaded(object sender, RoutedEventArgs e)
{ DataSet ds= TIll.Read();
DataTable dt = ds.Tables[];
textBox1.Text = dt.Rows[][].ToString().Trim();
textBox2.Text = dt.Rows[][].ToString().Trim();
label1.Content = dt.Rows[][].ToString().Trim(); } private void textBox3_KeyDown(object sender, KeyEventArgs e)
{
double a=Convert.ToDouble(textBox1.Text);
double b=Convert.ToDouble(textBox2.Text);
Factionsss fas = new Factionsss(label1.Content.ToString());
double aswer = fas.cal(a, b);
if (aswer.ToString() == textBox3.Text)
{
MessageBox.Show("回答正确!");
}
else
{
MessageBox.Show("回答错误!");
}
textBox3.Clear();
read(); }
private void read()
{
DataSet ds = TIll.Read();
DataTable dt = ds.Tables[];
textBox1.Text = dt.Rows[i][].ToString().Trim();
textBox2.Text = dt.Rows[i][].ToString().Trim();
label1.Content = dt.Rows[i][].ToString().Trim(); }
}
}
WPF+数据库+三层的更多相关文章
- Android开发数据库三层应用-DataSnap
Android开发数据库三层应用-DataSnap http://www.2ccc.com/news/Html/?1517.html 核心提示:我觉得Delphi最强大的的功能之一就是开发数据库三层应 ...
- Wpf+数据库代码封装+策略模式封装
运行界面: 数据库保存的题: 数据库封装代码: using System; using System.Collections.Generic; using System.Linq; using Sys ...
- WPF 数据库增删改查
<Window x:Class="DataBindingExam.MainWindow" xmlns="http://schemas.microsof ...
- Delphi数据库的三层架构的问题和解决方法
Delphi数据库的三层架构的问题和解决方法 原创 2014年03月26日 16:26:03 标签: Delphi / 数据库三层架构 / DCOM / DCOMConnection 790 //-- ...
- MYSQL数据库性能调优之一:调优技术基础
1.mysql数据库优化技术有哪些? 2.数据库三层结构? 3.数据库3NF
- Asp.Net之三层架构
三层架构之理论: 通常意义上讲的三层架构就是将整个项目应用划分为:表现层(UI),业务逻辑层(BLL),数据访问层(DAL).与传统的二层架构的区别在于在用户界面(UI)和数据库服务器之间,添加中间层 ...
- delphi 三层架构简单例子(经测试成功)
delphi 三层架构简单例子(经测试成功) 转载 2013年12月19日 09:48:57 1100 所谓三层: (1) 客户端 (2) 服务器端 (3) 数据库 在数据访问时,使得客户端必须通过服 ...
- 2014年7月份第2周51Aspx源码发布详情
体育馆综合会员管理系统源码 2014-7-11 [VS2010]功能介绍:本系统适用于羽毛球馆,台球馆,乒乓球馆,棋牌室,篮球馆等综合体育馆,可同时使用.本系统功能非常强大,包含体育馆内餐厅,超 ...
- 框架应用:Spring framework (五) - Spring MVC技术
软件开发中的MVC设计模式 软件开发的目标是减小耦合,让模块之前关系清晰. MVC模式在软件开发中经常和ORM模式一起应用,主要作用是将(数据抽象,数据实体传输和前台数据展示)分层,这样前台,后台,数 ...
随机推荐
- windows service 2012:搭建FTP服务器
最近公司将服务器从线上移植到线下每次上传项目都要进入服务器感觉好麻烦, 所以就想搭建一个FTP的站点来管理项目,弄这个之前首先要关闭我们的windows service 2012 服务器的防火墙,只有 ...
- 『Python基础-7』for循环 & while循环
『Python基础-7』for循环 & while循环 目录: 循环语句 for循环 while循环 循环的控制语句: break,continue,pass for...else 和 whi ...
- python学习笔记:第19天 类的约束、异常、MD5和logging
目录 一.类的约束 二.异常处理: 三.MD5加密 四.日志(logging模块) 一.类的约束 真正写写项目的代码时都是多人协作的,所以有些地方需要约束程序的结构.也就是说,在分配任务之前就应该把功 ...
- HyperLedger Fabric 1.4 官方End-2-End运行(8)
8.1 End-2-End案例简介 Fabric官方提供了实现点对点的Fabric网络示例,该网络有两个组织(organizations),一个组织有两种节点(Peer),通过Kafka ...
- 北京Uber优步司机奖励政策(2月19日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
- 成都Uber优步司机奖励政策(1月17日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
- Unicode编码相关概念
1.Unicode是一种字符映射方案,这种映射并不是编码(即还没有到二进制机器码层面),而是像一个电话本一样,把全世界所有语言使用的字符,都映射成一个"u+"开头的数字(在JAVA ...
- WPF DataGridRow Event
CM(Caliburn.Micro)框架绑定DataGridRow事件 <DataGrid.ItemContainerStyle> <Style TargetType="D ...
- APP产品设计流程图
产品设计流程(toB) 工作有半个月了,遇到了很多问题,也在不断学习和充实自己,让自己的工作变得更加清晰和流程化,所以整理了这么个设计流程. 收集整理一切有用或则以后可能会用的文档. 从文档里面提炼用 ...
- git 操作几个命令
git clone ssh://lijianfeng@192.168.1.246:29418/GMGameSDK压栈:git stash查状态:git status切换到要修改的提交:git reb ...