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+数据库+三层的更多相关文章

  1. Android开发数据库三层应用-DataSnap

    Android开发数据库三层应用-DataSnap http://www.2ccc.com/news/Html/?1517.html 核心提示:我觉得Delphi最强大的的功能之一就是开发数据库三层应 ...

  2. Wpf+数据库代码封装+策略模式封装

    运行界面: 数据库保存的题: 数据库封装代码: using System; using System.Collections.Generic; using System.Linq; using Sys ...

  3. WPF 数据库增删改查

    <Window x:Class="DataBindingExam.MainWindow"        xmlns="http://schemas.microsof ...

  4. Delphi数据库的三层架构的问题和解决方法

    Delphi数据库的三层架构的问题和解决方法 原创 2014年03月26日 16:26:03 标签: Delphi / 数据库三层架构 / DCOM / DCOMConnection 790 //-- ...

  5. MYSQL数据库性能调优之一:调优技术基础

    1.mysql数据库优化技术有哪些? 2.数据库三层结构? 3.数据库3NF

  6. Asp.Net之三层架构

    三层架构之理论: 通常意义上讲的三层架构就是将整个项目应用划分为:表现层(UI),业务逻辑层(BLL),数据访问层(DAL).与传统的二层架构的区别在于在用户界面(UI)和数据库服务器之间,添加中间层 ...

  7. delphi 三层架构简单例子(经测试成功)

    delphi 三层架构简单例子(经测试成功) 转载 2013年12月19日 09:48:57 1100 所谓三层: (1) 客户端 (2) 服务器端 (3) 数据库 在数据访问时,使得客户端必须通过服 ...

  8. 2014年7月份第2周51Aspx源码发布详情

      体育馆综合会员管理系统源码  2014-7-11 [VS2010]功能介绍:本系统适用于羽毛球馆,台球馆,乒乓球馆,棋牌室,篮球馆等综合体育馆,可同时使用.本系统功能非常强大,包含体育馆内餐厅,超 ...

  9. 框架应用:Spring framework (五) - Spring MVC技术

    软件开发中的MVC设计模式 软件开发的目标是减小耦合,让模块之前关系清晰. MVC模式在软件开发中经常和ORM模式一起应用,主要作用是将(数据抽象,数据实体传输和前台数据展示)分层,这样前台,后台,数 ...

随机推荐

  1. visual studio进程或线程自上一个步骤以来已更改

    1.自己的解决方案:visual studio在多进程执行,在配置页面(webconfig)里把UseCounterThread参数设置为0 2.公司其他人解决方案,自己试了,多进程执行的时候没起作用 ...

  2. 第九篇:S3C2400时钟体系

    S3C2400时钟体系 S3C2400时钟配置流程 该学习板使用了外部晶振12Mhz 晶振--->经过MPLL(锁相环) --->(倍频得到)FCLK--->(对FCLK分频得到)H ...

  3. Python2和Python3

    1. 字符编码 1.1. Python2默认为ACSII编码 1.2. Python3为Unicode 2. Unicode和UTF8和GBK编码的关系 utf8:中文3字节              ...

  4. Tips & Tricks Learned Releasing an Hybrid App Using Steroids.js

    http://marcgg.com/blog/2014/04/09/phonegap-steroids-hybrid-native-app-tips/

  5. MySQL 存储过程常用SQL语句收集

    1,select curdate() /*2016-10-08*/ 2,select date_sub(curdate(), INTERVAL 6 DAY) /*2016-10-02*/ 3,case ...

  6. 二进制描述子 BRIEF(ORB), BRISK, FREAK

    二进制描述子设计原则体现在三个部分: 采样pattern 方向orientation compensation 配对sampling pairs ORB基于BRIEF: BRISK是用于OKVIS的描 ...

  7. (转)Html邮件CSS指南

    转载地址:http://www.maildesign.cn/archives/937 分享来自Campaignmonitor非常实用的Html邮件中CSS的支持文档! 他们总结的Html邮件的CSS指 ...

  8. C# 简单工厂

    如下: public static IList<T> Create<T>(Type type) { if (type == typeof(List<T>)) { r ...

  9. InnoDB意向锁和插入意向锁

      Preface       Last night one buddy in tech wechat group asked "what's intention locks of Inno ...

  10. (Python爬虫02) 制定爬虫的学习计划了

    公司清退是件很让人郁闷的事情,精,气,神 都会受到影响.焦虑的心态,涣散的眼神, 无所适从的若无其事,人周茶凉的快速交接,各种担忧....平静的面孔波涛汹涌的心.... 认识聊天中满满的套路...还有 ...