using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data .SqlClient;
using System.Data ;
namespace car
{
///
/// frmCarInsurance 的摘要说明。
///
public class frmCarInsurance : System.Windows.Forms.Form
{
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.ComboBox comboBox2;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.TextBox textBox4;
private System.Windows.Forms.TextBox textBox5;
private System.Windows.Forms.TextBox textBox9;
private System.Windows.Forms.Label label11;
private System.Windows.Forms.TextBox textBox6;
private System.Windows.Forms.Label label8;
private System.Windows.Forms.TextBox textBox7;
private System.Windows.Forms.Label label9;
private System.Windows.Forms.TextBox textBox8;
private System.Windows.Forms.Label label10;
private System.Windows.Forms.TextBox textBox10;
private System.Windows.Forms.Label label12;
private System.Windows.Forms.TextBox textBox11;
private System.Windows.Forms.Label label13;
private System.Windows.Forms.TextBox textBox12;
private System.Windows.Forms.Label label14;
private System.Windows.Forms.TextBox textBox13;
private System.Windows.Forms.Label label15;
private System.Windows.Forms.Label label16;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
///
/// 必需的设计器变量。
///
private System.ComponentModel.Container components = null;
private SqlCommand cmd;
private SqlConnection con = new SqlConnection ("server=.;uid=sa;pwd=sa;database=car");
private SqlDataReader dr;
private System.Windows.Forms.Label lblE;
private DataSet ds;
public frmCarInsurance()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
///
/// 清理所有正在使用的资源。
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
///
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
///
private void InitializeComponent()
{
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.comboBox2 = new System.Windows.Forms.ComboBox();
this.label4 = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.label6 = new System.Windows.Forms.Label();
this.label7 = new System.Windows.Forms.Label();
this.textBox2 = new System.Windows.Forms.TextBox();
this.textBox3 = new System.Windows.Forms.TextBox();
this.textBox4 = new System.Windows.Forms.TextBox();
this.textBox5 = new System.Windows.Forms.TextBox();
this.textBox9 = new System.Windows.Forms.TextBox();
this.label11 = new System.Windows.Forms.Label();
this.textBox6 = new System.Windows.Forms.TextBox();
this.label8 = new System.Windows.Forms.Label();
this.textBox7 = new System.Windows.Forms.TextBox();
this.label9 = new System.Windows.Forms.Label();
this.textBox8 = new System.Windows.Forms.TextBox();
this.label10 = new System.Windows.Forms.Label();
this.textBox10 = new System.Windows.Forms.TextBox();
this.label12 = new System.Windows.Forms.Label();
this.textBox11 = new System.Windows.Forms.TextBox();
this.label13 = new System.Windows.Forms.Label();
this.textBox12 = new System.Windows.Forms.TextBox();
this.label14 = new System.Windows.Forms.Label();
this.textBox13 = new System.Windows.Forms.TextBox();
this.label15 = new System.Windows.Forms.Label();
this.label16 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.lblE = new System.Windows.Forms.Label();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Controls.Add(this.label3);
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.Controls.Add(this.comboBox2);
this.groupBox1.Controls.Add(this.comboBox1);
this.groupBox1.Controls.Add(this.textBox1);
this.groupBox1.Location = new System.Drawing.Point(40, 24);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(648, 96);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "车辆信息";
//
// groupBox2
//
this.groupBox2.Controls.Add(this.textBox13);
this.groupBox2.Controls.Add(this.label15);
this.groupBox2.Controls.Add(this.textBox12);
this.groupBox2.Controls.Add(this.label14);
this.groupBox2.Controls.Add(this.textBox11);
this.groupBox2.Controls.Add(this.label13);
this.groupBox2.Controls.Add(this.textBox10);
this.groupBox2.Controls.Add(this.label12);
this.groupBox2.Controls.Add(this.textBox8);
this.groupBox2.Controls.Add(this.label10);
this.groupBox2.Controls.Add(this.textBox7);
this.groupBox2.Controls.Add(this.label9);
this.groupBox2.Controls.Add(this.textBox6);
this.groupBox2.Controls.Add(this.label8);
this.groupBox2.Controls.Add(this.textBox9);
this.groupBox2.Controls.Add(this.label11);
this.groupBox2.Controls.Add(this.textBox5);
this.groupBox2.Controls.Add(this.textBox4);
this.groupBox2.Controls.Add(this.textBox3);
this.groupBox2.Controls.Add(this.textBox2);
this.groupBox2.Controls.Add(this.label7);
this.groupBox2.Controls.Add(this.label6);
this.groupBox2.Controls.Add(this.label5);
this.groupBox2.Controls.Add(this.label4);
this.groupBox2.Location = new System.Drawing.Point(40, 152);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(648, 160);
this.groupBox2.TabIndex = 1;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "保单信息";
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(24, 40);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(54, 17);
this.label1.TabIndex = 0;
this.label1.Text = "汽车牌照";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(216, 40);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(54, 17);
this.label2.TabIndex = 1;
this.label2.Text = "生效日期";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(432, 40);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(54, 17);
this.label3.TabIndex = 2;
this.label3.Text = "终止日期";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(88, 36);
this.textBox1.Name = "textBox1";
this.textBox1.TabIndex = 2;
this.textBox1.Text = "";
//
// comboBox1
//
this.comboBox1.Location = new System.Drawing.Point(280, 37);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(121, 20);
this.comboBox1.TabIndex = 3;
//
// comboBox2
//
this.comboBox2.Location = new System.Drawing.Point(504, 37);
this.comboBox2.Name = "comboBox2";
this.comboBox2.Size = new System.Drawing.Size(121, 20);
this.comboBox2.TabIndex = 4;
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(24, 24);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(42, 17);
this.label4.TabIndex = 0;
this.label4.Text = "交强险";
//
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(24, 56);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(42, 17);
this.label5.TabIndex = 1;
this.label5.Text = "盗抢险";
//
// label6
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(24, 88);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(42, 17);
this.label6.TabIndex = 2;
this.label6.Text = "车损险";
//
// label7
//
this.label7.AutoSize = true;
this.label7.Location = new System.Drawing.Point(24, 120);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(42, 17);
this.label7.TabIndex = 3;
this.label7.Text = "三者险";
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(88, 16);
this.textBox2.Name = "textBox2";
this.textBox2.TabIndex = 4;
this.textBox2.Text = "";
//
// textBox3
//
this.textBox3.Location = new System.Drawing.Point(88, 56);
this.textBox3.Name = "textBox3";
this.textBox3.TabIndex = 5;
this.textBox3.Text = "";
//
// textBox4
//
this.textBox4.Location = new System.Drawing.Point(88, 88);
this.textBox4.Name = "textBox4";
this.textBox4.TabIndex = 6;
this.textBox4.Text = "";
//
// textBox5
//
this.textBox5.Location = new System.Drawing.Point(88, 120);
this.textBox5.Name = "textBox5";
this.textBox5.TabIndex = 7;
this.textBox5.Text = "";
//
// textBox9
//
this.textBox9.Location = new System.Drawing.Point(306, 14);
this.textBox9.Name = "textBox9";
this.textBox9.TabIndex = 12;
this.textBox9.Text = "";
//
// label11
//
this.label11.AutoSize = true;
this.label11.Location = new System.Drawing.Point(232, 24);
this.label11.Name = "label11";
this.label11.Size = new System.Drawing.Size(54, 17);
this.label11.TabIndex = 8;
this.label11.Text = "保费浮动";
//
// textBox6
//
this.textBox6.Location = new System.Drawing.Point(306, 48);
this.textBox6.Name = "textBox6";
this.textBox6.TabIndex = 14;
this.textBox6.Text = "";
//
// label8
//
this.label8.AutoSize = true;
this.label8.Location = new System.Drawing.Point(232, 56);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(54, 17);
this.label8.TabIndex = 13;
this.label8.Text = "保费浮动";
//
// textBox7
//
this.textBox7.Location = new System.Drawing.Point(306, 88);
this.textBox7.Name = "textBox7";
this.textBox7.TabIndex = 16;
this.textBox7.Text = "";
//
// label9
//
this.label9.AutoSize = true;
this.label9.Location = new System.Drawing.Point(232, 88);
this.label9.Name = "label9";
this.label9.Size = new System.Drawing.Size(54, 17);
this.label9.TabIndex = 15;
this.label9.Text = "保费浮动";
//
// textBox8
//
this.textBox8.Location = new System.Drawing.Point(306, 120);
this.textBox8.Name = "textBox8";
this.textBox8.TabIndex = 18;
this.textBox8.Text = "";
//
// label10
//
this.label10.AutoSize = true;
this.label10.Location = new System.Drawing.Point(232, 120);
this.label10.Name = "label10";
this.label10.Size = new System.Drawing.Size(54, 17);
this.label10.TabIndex = 17;
this.label10.Text = "保费浮动";
//
// textBox10
//
this.textBox10.Location = new System.Drawing.Point(512, 16);
this.textBox10.Name = "textBox10";
this.textBox10.TabIndex = 20;
this.textBox10.Text = "";
//
// label12
//
this.label12.AutoSize = true;
this.label12.Location = new System.Drawing.Point(440, 24);
this.label12.Name = "label12";
this.label12.Size = new System.Drawing.Size(54, 17);
this.label12.TabIndex = 19;
this.label12.Text = "保费金额";
//
// textBox11
//
this.textBox11.Location = new System.Drawing.Point(512, 48);
this.textBox11.Name = "textBox11";
this.textBox11.TabIndex = 22;
this.textBox11.Text = "";
//
// label13
//
this.label13.AutoSize = true;
this.label13.Location = new System.Drawing.Point(440, 56);
this.label13.Name = "label13";
this.label13.Size = new System.Drawing.Size(54, 17);
this.label13.TabIndex = 21;
this.label13.Text = "保费金额";
//
// textBox12
//
this.textBox12.Location = new System.Drawing.Point(512, 80);
this.textBox12.Name = "textBox12";
this.textBox12.TabIndex = 24;
this.textBox12.Text = "";
//
// label14
//
this.label14.AutoSize = true;
this.label14.Location = new System.Drawing.Point(440, 88);
this.label14.Name = "label14";
this.label14.Size = new System.Drawing.Size(54, 17);
this.label14.TabIndex = 23;
this.label14.Text = "保费金额";
//
// textBox13
//
this.textBox13.Location = new System.Drawing.Point(512, 112);
this.textBox13.Name = "textBox13";
this.textBox13.TabIndex = 26;
this.textBox13.Text = "";
//
// label15
//
this.label15.AutoSize = true;
this.label15.Location = new System.Drawing.Point(440, 120);
this.label15.Name = "label15";
this.label15.Size = new System.Drawing.Size(54, 17);
this.label15.TabIndex = 25;
this.label15.Text = "保费金额";
//
// label16
//
this.label16.Location = new System.Drawing.Point(40, 312);
this.label16.Name = "label16";
this.label16.TabIndex = 2;
this.label16.Text = "保费金额";
//
// button1
//
this.button1.Location = new System.Drawing.Point(392, 328);
this.button1.Name = "button1";
this.button1.TabIndex = 3;
this.button1.Text = "计算";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(488, 328);
this.button2.Name = "button2";
this.button2.TabIndex = 4;
this.button2.Text = "保存";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button3
//
this.button3.Location = new System.Drawing.Point(592, 328);
this.button3.Name = "button3";
this.button3.TabIndex = 5;
this.button3.Text = "退出";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// lblE
//
this.lblE.Location = new System.Drawing.Point(120, 312);
this.lblE.Name = "lblE";
this.lblE.TabIndex = 6;
//
// frmCarInsurance
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(720, 362);
this.Controls.Add(this.lblE);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.label16);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.Name = "frmCarInsurance";
this.Text = "frmCarInsurance";
this.Load += new System.EventHandler(this.frmCarInsurance_Load);
this.groupBox1.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private void button3_Click(object sender, System.EventArgs e)
{
this.Close();
}
private void frmCarInsurance_Load(object sender, System.EventArgs e)
{
//取系统当前时间
this.comboBox1.Text =DateTime.Now.ToShortDateString ();
//取系统时间下一年的同一天的前一天
DateTime obj = DateTime.Now .AddYears (1);
DateTime obj1= obj.Date.AddDays (-1);
this.comboBox2.Text =obj1.ToShortDateString();
}
private void button1_Click(object sender, System.EventArgs e)
{
if(this.textBox1.Text =="")
{
MessageBox.Show ("请输入汽车牌照","系统提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
return;
}
con.Open ();
string sel ="select datediff(year,purchaseDate,getdate()),datediff(year,DriverLisence,getdate()) ,CarPrice from carInformation where RegistMark='"+this.textBox1.Text +"'";
cmd = new SqlCommand (sel,con);
dr =cmd.ExecuteReader();
if(dr.Read ())
{
double CarPrice = double.Parse (dr.GetValue (2).ToString ());//新车价格
double CarAge = double.Parse (dr.GetValue (0).ToString ());
double DriverAge = double.Parse (dr.GetValue(1).ToString ());
this.textBox2 .Text =""+1050;
this.textBox6.Text=""+1050*(-10)/100;
this.textBox10.Text =""+(1050*(-10)/100+1050);
this.textBox3.Text=""+CarPrice*2/100;
this.textBox7.Text="-"+(CarPrice*2/100*(DriverAge/100+CarAge/100));
this.textBox11.Text=""+(CarPrice*2/100-CarPrice*2/100*(DriverAge/100+CarAge/100));
this.textBox4.Text = ""+CarPrice*3/100;
this.textBox8.Text="-"+(CarPrice*3/100*(DriverAge/100+CarAge/100));
this.textBox12.Text=""+(CarPrice*3/100-CarPrice*2/100*(DriverAge/100+CarAge/100));
this.textBox5.Text=""+CarPrice*1/100;
this.textBox9.Text="-"+CarPrice*1/100*DriverAge/100;
this.textBox13.Text=""+(CarPrice/100-CarPrice*1/100*DriverAge/100);
this.lblE.Text=""+((CarPrice/100-CarPrice*1/100*DriverAge/100)+CarPrice*3/100-CarPrice*2/100*(DriverAge/100+CarAge/100)+CarPrice*2/100-CarPrice*2/100*(DriverAge/100+CarAge/100)+1050*(-10)/100+1050);
this.button2.Enabled = true;
this.button1.Enabled = false;
con.Close();
}
else
{
MessageBox.Show("无该车辆信息!","系统提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
con.Close();
return;
}
}
private void button2_Click(object sender, System.EventArgs e)
{
string nowTime = DateTime.Now .ToShortDateString ();
con.Open();
//初始化对象
cmd = new SqlCommand ("insert into CarInsurance values('"+this.textBox1.Text +"','"+this.comboBox1.Text +"','"+this.comboBox2.Text +"','"+nowTime +"',"+double.Parse (this.lblE .Text)+")",con);
cmd.ExecuteNonQuery();
MessageBox.Show ("保存成功","系统提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
this.button1.Enabled =false;
this.button2.Enabled =true;
con.Close ();
}
}
}