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.SqlClient;
namespace 游戏点卡管理
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
SqlConnection conn = new SqlConnection();
SqlCommand cmd = new SqlCommand();
SqlDataAdapter DataAdapter = new SqlDataAdapter();
DataSet ds = new DataSet();
public void ff ()
{
try
{
dataGridView1.Columns.Clear();
conn.Open();
string str = string.Format("select cardid as 卡号,gamename as 游戏名称,company as 发行公司,lastday as 最后有效期,price as 售价 from cardinfo");
cmd = new SqlCommand(str, conn);
DataAdapter = new SqlDataAdapter();
DataAdapter.SelectCommand = cmd;
ds = new DataSet();
DataAdapter.Fill(ds, "点卡");
dataGridView1.DataSource = ds.Tables["点卡"];
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
conn.Close();
}
}
private void Form1_Load(object sender, EventArgs e)
{
conn = new SqlConnection("server=.;pwd=sa;uid=sa;database=GameCardDB;");
ff();
}
private void button3_Click(object sender, EventArgs e)
{
string id = this.textBox1.Text.Trim();
string gs = this.textBox2.Text.Trim();
int sj = int.Parse(this.textBox3.Text.Trim());
string mc = this.textBox4.Text.Trim();
string time = this.dateTimePicker1.Text.Trim();
conn.Open();
string str = String.Format("insert into cardinfo values('{0}','{1}',{2},'{3}')", mc, gs, time, sj);
cmd = new SqlCommand(str, conn);
try
{
int numSQLCount = cmd.ExecuteNonQuery();
if (numSQLCount > 0)
{
MessageBox.Show("添加成功!");
}
else
{
MessageBox.Show("添加失败");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
conn.Close();
}
ff();
}
private void button2_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
}
}
}