📄 frmcydy.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace SMS.Forms
{
public partial class frmCydy : Form
{
public string Stype;
public string Scontent;
public string Sid;
private static frmCydy cydy;//声明一个私有变量,用来保存唯一的窗体实例
public frmCydy()
{
InitializeComponent();
}
//提供一个静态方法,此方法是用来判断何时实例化窗体
public static frmCydy Instance()
{
if (cydy == null)
cydy = new frmCydy();
return cydy;
}
private void frmCydy_FormClosing(object sender, FormClosingEventArgs e)
{
cydy.Dispose(true);
cydy = null;
}
private void pbDelete_Click(object sender, EventArgs e)
{
if (MessageBox.Show("确定要删除吗?", "警告", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
{
string id = dgvShow.SelectedCells[0].Value.ToString();//获取编号
OleDbConnection conn = BaseClass.ConnClass.DataConn();//连接数据库
conn.Open();//打开数据库
OleDbCommand cmd = new OleDbCommand("delete from tb_note where ID = " + id, conn);
cmd.ExecuteNonQuery();
conn.Close();
MessageBox.Show("删除成功!", "提示");
string str = "select * from tb_note where type = '" + tvDy.SelectedNode.Text + "'";
BindData(str);
}
}
private void pbClose_Click(object sender, EventArgs e)
{
cydy.Dispose(true);
cydy = null;
this.Close();
}
private void frmCydy_Load(object sender, EventArgs e)
{
//SqlConnection con = new SqlConnection("server = (local);uid=sa;pwd=;database=db_ls");
//con.Open();
//DataSet ds = new DataSet();
//SqlDataAdapter da = new SqlDataAdapter("select *from tb_01",con);
//da.Fill(ds);
//dgvShow.DataSource = ds.Tables[0].DefaultView;
}
private void tvDy_AfterSelect(object sender, TreeViewEventArgs e)
{
string str = "select * from tb_note where type = '" + tvDy.SelectedNode.Text + "'";//SQL语句
BindData(str);
}
//自定义的方法用于根据指定的SQL语句绑定数据控件
public void BindData(string strsql)
{
OleDbConnection conn = BaseClass.ConnClass.DataConn();
OleDbDataAdapter oda = new OleDbDataAdapter(strsql, conn);
DataSet ds = new DataSet();
oda.Fill(ds);
dgvShow.DataSource = ds.Tables[0];//绑定控件
}
private void dgvShow_CellDoubleClick(object sender, DataGridViewCellEventArgs e)//当双击某天常用短语时,将弹出显示详细信息以及修改信息的窗口
{
string id = dgvShow.SelectedCells[0].Value.ToString();
string content = dgvShow.SelectedCells[2].Value.ToString();
string type = tvDy.SelectedNode.Text;
frmDyChange dychange = new frmDyChange();
dychange.Scontent = content;
dychange.Sid = id;
dychange.Stype = type;
dychange.ShowDialog();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -