flowMeter/NGToolsPC/frmJdygl.cs

184 lines
5.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace NGToolsPC
{
public partial class frmJdygl : Form
{
public frmJdygl()
{
MySqlCon = new System.Data.OleDb.OleDbConnection(mldPublic.strConCNG);
InitializeComponent();
}
private void frmJdygl_Load(object sender, EventArgs e)
{
string strSQL = "";
if (mldPublic.strJdyXm == "") { return; }
if (mldPublic.strJdyXm == "admin")
{
strSQL = "select ID,检定员,密码 from 用户管理 order by ID";
dataGridView1.AllowUserToAddRows = true;
}
else
{
strSQL = "select ID,检定员,密码 from 用户管理 where 检定员='" + mldPublic.strJdyXm + "' order by ID";
Button1.Enabled = false;
Button3.Enabled = false;
dataGridView1.AllowUserToAddRows = false;
}
try
{
dtJdy = new DataTable();
JdyDap = new System.Data.OleDb.OleDbDataAdapter();
JdyDap.SelectCommand = new OleDbCommand(strSQL, MySqlCon);
JdyDap.Fill(dtJdy);
this.dataGridView1.DataSource = dtJdy;
this.dataGridView1.Columns[0].Visible = false;
this.dataGridView1.Columns[2].Visible = false;
Jdycb = new OleDbCommandBuilder(JdyDap);
JdyDap.UpdateCommand = Jdycb.GetUpdateCommand();
JdyDap.InsertCommand = Jdycb.GetInsertCommand();
JdyDap.DeleteCommand = Jdycb.GetDeleteCommand();
}
catch (Exception ex)
{
//string aaa = ex.Message;
}
}
public System.Data.OleDb.OleDbConnection MySqlCon; // VBConversions Note: Initial value cannot be assigned here since it is non-static. Assignment has been moved to the class constructors.
DataTable dtJdy;
OleDbCommandBuilder Jdycb;
System.Data.OleDb.OleDbDataAdapter JdyDap;
int strJdyCheck;
string strJdyName;
private void dataGridView1_Click(object sender, EventArgs e)
{
if (dataGridView1.SelectedRows.Count == 0)
{
return;
}
int intJdyID = 0;
try
{
intJdyID = System.Convert.ToInt32(dataGridView1.SelectedRows[0].Cells[0].Value.ToString());
strJdyName = (dataGridView1.SelectedRows[0].Cells[1].Value.ToString());
if (intJdyID == 0)
{
return;
}
strJdyCheck = intJdyID;
}
catch (Exception)
{
}
}
private void Button1_Click(object sender, EventArgs e)
{
JdyDap.Update(dtJdy);
dtJdy.Clear();
JdyDap.Fill(dtJdy);
}
private void Button3_Click(object sender, EventArgs e)
{
//消息框中需要显示哪些按钮,此处显示“确定”和“取消”
string yhxm = dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
if (yhxm == "admin")
{
return;
}
MessageBoxButtons messButton = MessageBoxButtons.OKCancel;
//"确定要退出吗?"是对话框的显示信息,"退出系统"是对话框的标题
//默认情况下如MessageBox.Show("确定要退出吗?")只显示一个“确定”按钮。
DialogResult dr = MessageBox.Show("确定要删除吗?", "删除检定员", messButton);
if (dr == DialogResult.OK)//如果点击“确定”按钮
{
dataGridView1.Rows.Remove(dataGridView1.SelectedRows[0]);
}
JdyDap.Update(dtJdy);
dtJdy.Clear();
JdyDap.Fill(dtJdy);
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
if (strJdyCheck == 0)
{
MessageBox.Show("请先选择用户!");
dataGridView1.Focus();
return;
}
DataRow[] dr = dtJdy.Select("ID=" + strJdyCheck);
string oldPsw = dr[0]["密码"].ToString();
if (oldPsw == textBox1.Text)
{
if (textBox2.Text == textBox3.Text)
{
dr[0]["密码"] = textBox3.Text;
JdyDap.Update(dtJdy);
dtJdy.Clear();
JdyDap.Fill(dtJdy);
MessageBox.Show("修改成功,请记好密码!");
textBox1.Focus();
return;
}
else
{
MessageBox.Show("新密码和确认密码不对,请重新输入!");
textBox2.Focus();
return;
}
}
else
{
MessageBox.Show("旧密码不对,请重新输入!");
textBox1.Focus();
return;
}
}
}
}