111,123
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: 这行代码将数据加载到表“dbDataSet.data”中。您可以根据需要移动或移除它。
this.dataTableAdapter.Fill(this.dbDataSet.data);
}
private void label12_Click(object sender, EventArgs e)
{
new Form4().ShowDialog();
}
private void label13_Click(object sender, EventArgs e)
{
new Form3().ShowDialog();
}
private void button2_Click(object sender, EventArgs e)
{
String mdd = comboBox1.Text; //目的地
int qj = 0;//起价
int xf = 0;//5公斤下续费
int kg_5 = 0;//超5公斤续费
int kg_50 = 0;//超50公斤续费
int kg_100 = 0;//超100公斤续费
int bjl = 0;//保价费率
int zfy = 0;//总邮费
Double zl1;//初始重量值
Double zl;//重量
//检测目的地
if (mdd == "选择目的地" || mdd == "")
{
MessageBox.Show("错误:还没选择发货目的地!", "没选择目的地");
return;
}
//检测重量
zl1 = System.Convert.ToDouble(numericUpDown1.Text);
zl = System.Math.Ceiling(zl1);//重量遇小数进1变整
int zl2 = System.Convert.ToInt32(zl);//把重量转换成int类型
if (zl <= 0)
{
MessageBox.Show("错误:没有输入重量!", "没有输入重量");
return;
}
//获取数据
string srtCon = @"provider=Microsoft.jet.OLEDB.4.0;Data source=db.mdb;jet OLEDB:Database password=godiqpl";
OleDbConnection con = new OleDbConnection(srtCon);
OleDbCommand com = new OleDbCommand(srtCon);
con.Open();
com.CommandText = "Select qj,xf,kg_5,kg_50,kg_100,bj from data where dq like '"+mdd+"'";
com.CommandType = CommandType.Text;
com.Connection = con;
OleDbDataReader reader = com.ExecuteReader();
if (reader.Read())
{
//分别获取数据库并赋值
qj = reader.GetInt32(0);
xf = reader.GetInt32(1);
kg_5 = reader.GetInt32(2);
kg_50 = reader.GetInt32(3);
kg_100 = reader.GetInt32(4);
bjl = reader.GetInt32(5);
//计算并输出数据
if (zl2 <= 5)
{
zfy = qj + (zl2 - 1) * xf;
}
else if (zl2 > 5 && zl2 <= 50)
{
zfy = qj + 4 * xf + (zl2 - 5) * kg_5;
}
else if (zl2 > 50 && zl2 <= 100)
{
zfy = qj + 4 * xf + 45 * kg_5 + (zl2 - 50) * kg_50;
}
else
{
zfy = qj + 4 * xf + 45 * kg_5 + 50 * kg_50 + (zl2 - 100) * kg_100;
}
//计算保价费用
int bj;
int bjf;
bj = System.Convert.ToInt32(numericUpDown2.Text);
if (bj > 0)
{
bjf = bj * bjl/100;
zfy += bjf;
}
//输出数据
label7.Text = "发往" + mdd + ",重" + zl1 + "公斤" + ",应付邮费:" + zfy + "元.";
}
else
{
MessageBox.Show("数据读取失败!请正确选择目的地","严重错误");
}
con.Close();
}
}
}