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 ATM
{
public partial class ATM取款机_管理 : Form
{
DataSet ds = new DataSet();
SqlDataAdapter dataAdapter = null;
public ATM取款机_管理()
{
InitializeComponent();
}
private void button3_Click(object sender, EventArgs e)
{
a();
}
private void a()
{
if (validateInput())
{
MessageBox.Show("开户成功^-^!!!");
MessageBox.Show("卡号:103007916229009\t密码:123456");
ATM开户 stu = new ATM开户();
stu.Show();
string loginid = txtLoginId.Text.Trim();
string pwd = textBox2.Text.Trim();
string name = txtName.Text.Trim();
string stuNo = txtNum.Text.Trim();
string address = txtAddress.Text.Trim();
string phone = txtPhone.Text.Trim();
//string UserStateId =txtStateId.Text.Trim();
string sex = rdoSet1.Checked ? "活动" : "挂失";
// string state = rdoState1.Checked ? "1" : "0";
string state = rdoSet1.Checked ? rdoSet1.Tag.ToString() : rdoSet2.Tag.ToString();
string sql = string.Format(@"SELECT cardInfo.cardID, userInfo.customerName, userInfo.PID, userInfo.telephone, cardInfo.state
FROM cardInfo INNER JOIN
userInfo ON cardInfo.customerID = userInfo.customerID)values('{0}',{1}',{2},'{3}','{4}','{5}','{6})"
, loginid, pwd, name, stuNo, address, phone, sex);
int num = DBHelper.ExecuteNonQuery(sql);
if (num > 0)
{
MessageBox.Show("数据插入成功!", "操作提示");
ATM开户 st = new ATM开户();
st.Show();
}
else
{
MessageBox.Show("数据插入失败!", "操作提示");
}
}
}
private bool validateInput()
{
if (txtName.Text.Trim() == "")
{
MessageBox.Show("请输入开户名!", "输入提示");
txtName.Focus();
return false;
}
if (txtNum.Text.Trim() == "")
{
MessageBox.Show("请输入身份证号!", "输入提示");
txtNum.Focus();
return false;
}
if (txtNum.Text.Length != 18)
{
MessageBox.Show("身份证号长度必须等于15或18个字符!", "输入提示");
txtNum.Focus();
return false;
} long n = 0;
if (long.TryParse(txtNum.Text.Trim(), out n) == false)
{
MessageBox.Show("身份证号必须为数字字符!", "输入提示");
txtNum.Focus();
return false;
}
if (txtPhone.Text.Trim() == "")
{
MessageBox.Show("请输入电话!", "输入提示");
txtPhone.Focus();
return false;
}
if (txtPhone.Text.Length != 11)
{
MessageBox.Show("电话号码格式为xxxx-xxxxxxxx13位或手机号11位!", "输入提示");
txtPhone.Focus();
return false;
}
long phone = 0;
if (long.TryParse(txtPhone.Text.Trim(), out phone) == false)
{
MessageBox.Show("电话号码必须为数字字符和-组合!", "输入提示");
txtPhone.Focus();
return false;
}
if (txtAddress.Text.Trim() == "")
{
MessageBox.Show("请输入地址!可选输入", "输入提示");
}
if (this.txtLoginId.Text.Trim() == "")
{
MessageBox.Show("请输入开户名!", "输入提示");
txtLoginId.Focus();
return false;
}
if (textBox5.Text.Trim() == "")
{
MessageBox.Show("请输入金额!", "输入提示");
textBox5.Focus();
return false;
}
if (this.textBox4.Text.Trim() == "")
{
MessageBox.Show("请输入密码!", "输入提示");
textBox4.Focus();
return false;
}
if (textBox4.Text.Length != 6)
{
MessageBox.Show("密码长度必须等于6个字符!", "输入提示");
textBox4.Focus();
return false;
}
return true;
// this.Hide();
}
/*
string sql = @"SELECT cardInfo.cardID, userInfo.customerName, userInfo.PID, userInfo.telephone, cardInfo.state
FROM cardInfo INNER JOIN
userInfo ON cardInfo.customerID = userInfo.customerID";
this.listView1.Items.Clear();
string connStr = "Data Source=.;Initial Catalog=ATM;Persist Security Info=True;User ID=sa;Password=1234";
*/
string connStr = "Data Source=.;Initial Catalog=ATM;Persist Security Info=True;User ID=sa;Password=1234";
private void ATM取款机_管理_Load(object sender, EventArgs e)
{
string sql = @"SELECT userInfo.customerName, userInfo.PID, userInfo.telephone, userInfo.address, transInfo.cardID, transInfo.transMoney,
userInfo.customerID, transInfo.transDate, transInfo.transType, cardInfo.balance, transInfo.remark
FROM cardInfo INNER JOIN
transInfo ON cardInfo.cardID = transInfo.cardID INNER JOIN
userInfo ON cardInfo.customerID = userInfo.customerID";
SqlConnection connect = new SqlConnection(connStr);
dataAdapter = new SqlDataAdapter(sql, connect);
dataAdapter.Fill(ds);
this.dataGridView1.DataSource = ds.Tables[0];
this.dataGridView3.DataSource = ds.Tables[0];
string sqls = @"SELECT cardInfo.cardID, userInfo.customerName, userInfo.PID, userInfo.telephone,
cardInfo.state
FROM cardInfo INNER JOIN
userInfo ON cardInfo.customerID = userInfo.customerID";
NewMethod(sqls);
}
private void button1_Click_2(object sender, EventArgs e)
{
string sql = @"SELECT userInfo.PID,userInfo.customerName, userInfo.telephone, userInfo.address, transInfo.cardID, transInfo.transMoney
FROM cardInfo INNER JOIN
transInfo ON cardInfo.cardID = transInfo.cardID INNER JOIN
userInfo ON cardInfo.customerID = userInfo.customerID where 1=1";
if (textBox1.Text != "")
{
sql = sql + "and customerName like'%" + textBox1.Text + "%'";
}
if (textBox2.Text != "")
{
sql = sql + "and PID like'%" + textBox2.Text + "%'";
}
if (textBox3.Text != "")
{
sql = sql + "and transInfo.cardID like'%" + textBox3.Text + "%'";
}
dataAdapter.SelectCommand.CommandText = sql;
ds.Tables[0].Clear();
dataAdapter.Fill(ds);
}
private void NewMethod(string sqls)
{
this.listView1.Items.Clear();
string connStr = "Data Source=.;Initial Catalog=ATM;Persist Security Info=True;User ID=sa;Password=1234";
SqlConnection connection = new SqlConnection(connStr);
SqlCommand command = new SqlCommand(sqls, connection);
connection.Open();
SqlDataReader dataReader = command.ExecuteReader();
while (dataReader.Read())
{
string P = dataReader[4].ToString();
string BstuId = dataReader[1].ToString();
string NM = dataReader[0].ToString();
string BXM = dataReader[3].ToString();
string BstuName = dataReader[2].ToString();
ListViewItem lvStu = new ListViewItem(NM);
lvStu.Tag = NM;
this.listView1.Items.Add(lvStu);
string[] subs = new string[] { BstuId,BstuName ,BXM , P };
lvStu.SubItems.AddRange(subs);
}
dataReader.Close();
connection.Close();
}
private void 修改难度ToolStripMenuItem_Click(object sender, EventArgs e)
{
ATM开户 stu = new ATM开户();
stu.Show();
}
private void 删除ToolStripMenuItem_Click_1(object sender, EventArgs e)
{
string selsql = @"SELECT cardInfo.cardID, userInfo.customerName, userInfo.PID, userInfo.telephone, cardInfo.state
FROM cardInfo INNER JOIN
userInfo ON cardInfo.customerID = userInfo.customerID";
NewMethod(selsql);
}
private void 活动ToolStripMenuItem_Click(object sender, EventArgs e)
{
string selsql = @"SELECT cardInfo.cardID, userInfo.customerName, userInfo.PID, userInfo.telephone, cardInfo.state
FROM cardInfo INNER JOIN
userInfo ON cardInfo.customerID = userInfo.customerID";
NewMethod(selsql);
}
private void 刷新_Click(object sender, EventArgs e)
{
ds.Tables[0].Clear();
dataAdapter.Fill(ds);
}
private void button5_Click(object sender, EventArgs e)
{
this.Close();
}
private void toolStripButton4_Click(object sender, EventArgs e)
{
ATM开户 stu = new ATM开户();
stu.Show();
}
private void toolStripButton3_Click(object sender, EventArgs e)
{
Card stu = new Card();
stu.Show();
}
private void 修改状态ToolStripMenuItem_Click(object sender, EventArgs e)
{
ATM开户 stu = new ATM开户();
stu.Show();
}
private void 查看详情ToolStripMenuItem_Click(object sender, EventArgs e)
{
Form2 stu = new Form2();
stu.Show();
}
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void tabPage1_Click(object sender, EventArgs e)
{
}
private void contextMenuStrip1_Opening(object sender, CancelEventArgs e)
{
}
private void dataGridView3_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void ewrToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void tabPage3_Click(object sender, EventArgs e)
{
}
private void toolStripMenuItem2_Click(object sender, EventArgs e)
{
string i = listView1.SelectedItems[0].Tag.ToString();
string dy = "update cardinfo set state='活动' where cardid="+i;
int nu = DBHelper.ExecuteNonQuery(dy);
if (nu>0)
{
MessageBox.Show("成功");
}
}
private void toolStripMenuItem3_Click(object sender, EventArgs e)
{
string i = listView1.SelectedItems[0].Tag.ToString();
string dy = "update cardinfo set state='挂失' where cardid="+i;
int nu = DBHelper.ExecuteNonQuery(dy);
if (nu > 0)
{
MessageBox.Show("成功");
}
}
private void button6_Click(object sender, EventArgs e)
{
this.listView1.Items.Clear();
string sqls = @"SELECT cardInfo.cardID, userInfo.customerName, userInfo.PID, userInfo.telephone,
cardInfo.state
FROM cardInfo INNER JOIN
userInfo ON cardInfo.customerID = userInfo.customerID";
NewMethod(sqls);
}
private void button7_Click(object sender, EventArgs e)
{
this.Close();
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
}
}