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模式一起应用,主要作用是将(数据抽象,数据实体传输和前台数据展示)分层,这样前台,后台,数 ...
随机推荐
- webpack新建项目
记录如何搭建一个最简单的能跑的项目! 1.首先,需要下载安装nodejs环境,可以直接百度搜索nodejs去官网下载符合你操作系统的环境. 安装完nodejs后,在控制台输入命令: npm -vers ...
- mongodb C++ Driver安装
前言 mongocxx官网地址 http://mongocxx.org/?jmp=docs 本文的安装版本是:mongocxx-r3.2.0.tar.gz . 参考文档安装过程http://mongo ...
- 【JVM】上帝视角看JVM内存模型,分而治之论各模块详情
1. 上帝视角 [树看JVM] [图看JVM] 2. 分而治之 2.1 堆区 构成:堆区由新生代和老年代组成,新生代中包含伊甸区(Eden).幸存者区(survivor from .survivor ...
- python应用:爬虫框架Scrapy系统学习第二篇——windows下安装scrapy
windows下安装scrapy 依次执行下列操作: pip install wheel pip install lxml pip install PyOpenssl 安装Microsoft visu ...
- django的response-8
视图函数在处理请求后,必须返回一个 HttpResponse 对象,或者 HttpResponse对象的子对象. 1. HttpResponse 可以通过 django.http.HttpRespon ...
- Linux计划任务crontab设置详解
crontab文件的格式: minute hour day month weekday username command minute:分,值为0-59 hour:小时,值为1-23 day:天,值为 ...
- linux普通用户su root切换提示没有文件或目录
1. 首先进入单用户模式: 1). ubuntu : 上述情况可以在grub界面选择第二项修复,但没有grub可以参考: 1.重启ubuntu,随即长按shirft进入grub菜单: 2.选择reco ...
- Jedis+Redis+spring缓存
Redis程序使用它?Jedis 访问redis java api Redis-server & //后台运行防火墙要关闭 ts-parent的pom.xml加上jedis依赖 <dep ...
- 北京Uber司机7月13日奖励政策更新
各位司机朋友: 从7月13日(周一)起,奖励政策将进行调整,具体如下: 滴滴快车单单2.5倍,注册地址:http://www.udache.com/如何注册Uber司机(全国版最新最详细注册流程)/月 ...
- 机器学习实战:KNN代码报错“AttributeError: 'dict' object has no attribute 'iteritems'”
报错代码: sortedClassCount = sorted(classCount.iteritems(), key=operator.itemgetter(1), reverse=True) 解决 ...