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(); }
}
}

最新文章

  1. 读书笔记 —— 《css秘密花园》
  2. [HDU 1114] Piggy-Bank (动态规划)
  3. 【笨嘴拙舌WINDOWS】窗体样式
  4. 【英语】Bingo口语笔记(39) - Get系列
  5. delete archivelog all 无法彻底删除归档日志?
  6. Android http协议实现文件下载
  7. puppet yum仓库
  8. Example of how to use both JDK 7 and JDK 8 in one build.--reference
  9. ios禁用多按钮同时点下的效果
  10. .net导出不规则Excel
  11. Kali学习笔记11:僵尸扫描案例
  12. Django REST framework 第四章 Authentication
  13. Intellij-插件安装-JRebel热部署插件安装
  14. Java编程思想 学习笔记12
  15. metroui
  16. NOIP2003加分二叉树
  17. Java相关工具下载、配置环境变量
  18. 【洛谷P1823】音乐会的等待 单调栈+二分
  19. Thinkpad X220 升级 Windows 10 后无线网卡消失问题
  20. Ajax的基础应用

热门文章

  1. 04.nginx使用
  2. JavaScript手绘风格的图形库RoughJS使用指南
  3. 月薪30-50K的大数据工程师们,他们背后是如何学习的
  4. TortoiseGit —— 配置密钥
  5. hadoop生态搭建(3节点)-12.rabbitmq配置
  6. 第5章 MapReduce操作
  7. 【NXP开发板应用—智能插排】4. PWM驱动
  8. centos7下使用n grok编译服务端和客户端穿透内网
  9. 流程控制之--if。
  10. 关于指针的笔记【1】【C语言程序设计-谭浩强】