程序代码:
using System;
using System.Collections.Generic;
using using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class authorityForm : Form
{
private string use_Account = string.Empty;
private string use_Password = string.Empty;
private string use_name = string.Empty;
private bool lesson_Query;
private bool lesson_Add;
private bool lesson_Del;
private bool score_Query;
private bool score_Add;
private bool score_Del;
private bool score_Edit;
private string use_Message = string.Empty;
private bool save_Sign = false;
public authorityForm()
{
InitializeComponent();
}
private void authorityForm_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the '权限管理DataSet.权限管理' table. You can move, or remove it, as needed.
this.权限管理TableAdapter.Fill(this.权限管理DataSet.权限管理);
}
private void update_DataSet()
{
this.权限管理TableAdapter.UpdateQuery(
use_name,
lesson_Query,
lesson_Add,
lesson_Del,
score_Query,
score_Add,
score_Del,
score_Edit,
use_Message,
use_Account);
save_Sign = false;
}
private void saveBtn_Click(object sender, EventArgs e)
{
update_DataSet();
DialogResult result = MessageBox.Show("是否保存?", "保存提示", MessageBoxButtons.OK);
if (result == DialogResult.OK)
{
DataRow[] drSelect = this.权限管理DataSet.权限管理.Select("用户账号=" + "01"); 这里时form1,搜索得到
DataRow editDr = drSelect[0];
this.权限管理TableAdapter.Update(this.权限管理DataSet.权限管理);
save_Sign = true;
this.权限管理TableAdapter.Fill(this.权限管理DataSet.权限管理);
}
}
private void closeBtn_Click(object sender, EventArgs e)
{
DialogResult result = MessageBox.Show("是否退出?", "退出提示", MessageBoxButtons.OKCancel);
if (result == DialogResult.OK)
{
if (save_Sign == false)
{
this.权限管理BindingSource.CancelEdit();
}
this.Close();
}
else
{
this.权限管理TableAdapter.Fill(this.权限管理DataSet.权限管理);
}
}
private void delBtn_Click(object sender, EventArgs e)
{
this.权限管理BindingSource.RemoveCurrent();
}
private void accountTextBox_TextChanged(object sender, EventArgs e)
{
use_Account = accountTextBox.Text.ToString();
}
private void passwordTextBox_TextChanged(object sender, EventArgs e)
{
use_Password = passwordTextBox.Text.ToString();
}
private void nameTextBox_TextChanged(object sender, EventArgs e)
{
use_name = nameTextBox.Text.ToString();
}
private void messageTextBox_TextChanged(object sender, EventArgs e)
{
use_Message = messageTextBox.Text.ToString();
}
private void lessonQueryCheckBox_CheckedChanged(object sender, EventArgs e)
{
lesson_Query = lessonQueryCheckBox.Checked;
lessonCheckBox_State();
}
private void lessonAddCheckBox_CheckedChanged(object sender, EventArgs e)
{
lesson_Add = lessonAddCheckBox.Checked;
lessonCheckBox_State();
}
private void lessonDelCheckBox_CheckedChanged(object sender, EventArgs e)
{
lesson_Del = lessonDelCheckBox.Checked;
lessonCheckBox_State();
}
private void scoreQueryCheckBox_CheckedChanged(object sender, EventArgs e)
{
score_Query = scoreQueryCheckBox.Checked;
scoreCheckBox_State();
}
private void scoreAddCheckBox_CheckedChanged(object sender, EventArgs e)
{
score_Add = scoreAddCheckBox.Checked;
scoreCheckBox_State();
}
private void scoreDelCheckBox_CheckedChanged(object sender, EventArgs e)
{
score_Del = scoreDelCheckBox.Checked;
scoreCheckBox_State();
}
private void scoreEditCheckBox_CheckedChanged(object sender, EventArgs e)
{
score_Edit = scoreEditCheckBox.Checked;
scoreCheckBox_State();
}
private void lessonCheckBox_State()
{
if (lesson_Query == lesson_Add)
{
if (lesson_Add == lesson_Del)
{
if (lesson_Query)
{
lessonCheckBox.CheckState = CheckState.Checked;
}
else
{
lessonCheckBox.CheckState = CheckState.Unchecked;
}
}
else
{
lessonCheckBox.CheckState = CheckState.Indeterminate;
}
}
else
{
lessonCheckBox.CheckState = CheckState.Indeterminate;
}
}
private void lessonCheckBox_CheckedChanged(object sender, EventArgs e)
{
if (lessonCheckBox.CheckState == CheckState.Checked)
{
lessonQueryCheckBox.Checked = true;
lessonAddCheckBox.Checked = true;
lessonDelCheckBox.Checked = true;
}
else if (lessonCheckBox.CheckState == CheckState.Unchecked)
{
lessonQueryCheckBox.Checked = false;
lessonAddCheckBox.Checked = false;
lessonDelCheckBox.Checked = false;
}
//lessonCheckBox_State();
//MessageBox.Show(lessonQueryCheckBox.Checked.ToString() + lessonAddCheckBox.Checked.ToString() + lessonDelCheckBox.Checked.ToString());
}
private void scoreCheckBox_State()
{
if (score_Query == score_Add)
{
if (score_Add == score_Del)
{
if( score_Del==score_Edit)
{
if (score_Query)
{
scoreCheckBox.CheckState = CheckState.Checked;
}
else
{
scoreCheckBox.CheckState = CheckState.Unchecked;
}
}
else
{
scoreCheckBox.CheckState = CheckState.Indeterminate;
}
}
else
{
scoreCheckBox.CheckState = CheckState.Indeterminate;
}
}
else
{
scoreCheckBox.CheckState = CheckState.Indeterminate;
}
}
private void scoreCheckBox_CheckedChanged(object sender, EventArgs e)
{
if (scoreCheckBox.CheckState == CheckState.Checked)
{
scoreQueryCheckBox.Checked = true;
scoreAddCheckBox.Checked = true;
scoreDelCheckBox.Checked = true;
scoreEditCheckBox.Checked = true;
}
else if (scoreCheckBox.CheckState == CheckState.Unchecked)
{
scoreQueryCheckBox.Checked = false;
scoreAddCheckBox.Checked = false;
scoreDelCheckBox.Checked = false;
scoreEditCheckBox.Checked = false;
}
}
private void useListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
update_DataSet();
}
private void passwordEditBtn_Click(object sender, EventArgs e)
{
PasswordForm passwordFrom = new PasswordForm(use_Account);
passwordFrom.Tag = this;
this.Hide();
passwordFrom.Show();
}
private void AddBtn_Click(object sender, EventArgs e)
{
}
}
}