📄 frmtel.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace SMS.Forms
{
public partial class frmTel : Form
{
private static frmTel tel;//生命一个私有变量,用来保存唯一的窗体变量
public frmTel()
{
InitializeComponent();
}
//提供一个静态方法,此方法是用来判断何时实例化窗体
public static frmTel Instance()
{
if (tel == null)
tel = new frmTel();
return tel;
}
private void frmTel_FormClosing(object sender, FormClosingEventArgs e)
{
tel.Dispose(true);
tel = null;
}
private void pbDelete_Click(object sender, EventArgs e)
{
if (MessageBox.Show("确定要删除吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
{
string id = dgvAllUser.SelectedCells[0].Value.ToString();//获取列编号
OleDbConnection conn = BaseClass.ConnClass.DataConn(); //连接数据库
conn.Open();
OleDbCommand cmd = new OleDbCommand("delete from tb_tel where ID = " + id, conn);
cmd.ExecuteNonQuery();
conn.Close();
MessageBox.Show("删除联系人成功", "提示");
SetTelData();
}
}
private void pbClose_Click(object sender, EventArgs e)
{
tel.Dispose(true);
tel = null;
this.Close();
}
private void frmTel_Load(object sender, EventArgs e)
{
SetTelData();
}
private void SetTelData()
{
OleDbConnection conn = BaseClass.ConnClass.DataConn();//连接数据库
OleDbDataAdapter da = new OleDbDataAdapter("select * from tb_tel order by ID desc", conn);
DataSet ds = new DataSet();
da.Fill(ds);
dgvAllUser.DataSource = ds.Tables[0];
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -