383 lines
13 KiB
C#
383 lines
13 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.ComponentModel;
|
|||
|
using System.Data;
|
|||
|
using System.Drawing;
|
|||
|
using System.Text;
|
|||
|
using System.Windows.Forms;
|
|||
|
using DBFactory;
|
|||
|
namespace ControlSystem
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// Creator:Richard.liu
|
|||
|
/// <20>û<EFBFBD><C3BB><EFBFBD>Ȩ<EFBFBD><EFBFBD><DEB9><EFBFBD>
|
|||
|
/// </summary>
|
|||
|
public partial class FrmUsers : Form
|
|||
|
{
|
|||
|
bool _ifupdate=false ;
|
|||
|
DBOperator dbo= CStaticClass.dbo;
|
|||
|
|
|||
|
string CommomSql = "select f_userid as <20>û<EFBFBD>ID,f_username as <20>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>,f_purview as Ȩ<><C8A8> from t_base_users";
|
|||
|
private static FrmUsers _formInstance;
|
|||
|
public static FrmUsers FormInstance
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
if (_formInstance == null)
|
|||
|
{
|
|||
|
_formInstance = new FrmUsers();
|
|||
|
}
|
|||
|
return _formInstance;
|
|||
|
}
|
|||
|
set { _formInstance = value; }
|
|||
|
}
|
|||
|
public FrmUsers()
|
|||
|
{
|
|||
|
InitializeComponent();
|
|||
|
|
|||
|
foreach (ToolStripMenuItem tsmi in FrmMain.FormInstance.menuStrip1.Items)
|
|||
|
{
|
|||
|
this.treeView1.Nodes.Add(tsmi.Name, tsmi.Text);
|
|||
|
|
|||
|
|
|||
|
foreach (ToolStripItem tsi in tsmi.DropDown.Items)
|
|||
|
{
|
|||
|
if (tsi.Name.IndexOf("MI") >= 0)
|
|||
|
{
|
|||
|
this.treeView1.Nodes[tsmi.Name].Nodes.Add(tsi.Name, tsi.Text);
|
|||
|
//this.checkedListBox1.Items.Add(" "+tsi.Name + ":" + tsi.Text);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
_formInstance = this;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
private void button2_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
DataView dv = dbo.ExceSQL(CommomSql).Tables[0].DefaultView;
|
|||
|
this.dataGridView1.DataSource = dv;
|
|||
|
}
|
|||
|
|
|||
|
private void btQuery_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
string df, sql;
|
|||
|
if ((this.tbContent.Text.Trim() == "") || (this.cbField.Text.Trim() == "")) return;
|
|||
|
if (this.cbField.Text == "<22>û<EFBFBD>ID")
|
|||
|
{
|
|||
|
df = "F_UserID";
|
|||
|
}
|
|||
|
else if (this.cbField.Text == "<22><><EFBFBD><EFBFBD>")
|
|||
|
{
|
|||
|
df = "f_username";
|
|||
|
}
|
|||
|
else//
|
|||
|
{
|
|||
|
return ;
|
|||
|
}
|
|||
|
sql = CommomSql + " where " + df + "= '" + this.tbContent.Text + "'";
|
|||
|
DataSet ds = dbo.ExceSQL(sql);
|
|||
|
this.dataGridView1.DataSource = ds.Tables[0].DefaultView;
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
throw ex;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void btNull_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
for (int i = 0; i < this.treeView1.Nodes.Count; i++)
|
|||
|
{
|
|||
|
this.treeView1.Nodes[i].Checked=false ;
|
|||
|
for (int ii = 0; ii < this.treeView1.Nodes[i].Nodes.Count; ii++)
|
|||
|
{
|
|||
|
this.treeView1.Nodes[i].Nodes[ii].Checked = false;
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
private void btSave_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
string ts = string.Empty;
|
|||
|
if (this.checkBox1.Checked == true)
|
|||
|
{
|
|||
|
ts = "<22><><EFBFBD><EFBFBD>";
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
ts = "<22><EFBFBD>";
|
|||
|
}
|
|||
|
if (MessageBox.Show("<22><>ȷ<EFBFBD><C8B7>Ҫ"+ts+"<22>û<EFBFBD><C3BB><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD>", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE>", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
if (this.tbUserID.Text.Trim().Length == 0)
|
|||
|
{
|
|||
|
MessageBox.Show("<22>û<EFBFBD>ID<49><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE>", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|||
|
this.tbUserID.Focus();
|
|||
|
return;
|
|||
|
}
|
|||
|
if (this.tbPassword.Text.Trim().Length == 0)
|
|||
|
{
|
|||
|
MessageBox.Show("<22>û<EFBFBD><C3BB><EFBFBD><EFBFBD>벻<EFBFBD><EBB2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE>", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|||
|
this.tbPassword.Focus();
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
string pur=string.Empty ;
|
|||
|
for (int i = 0; i < this.treeView1.Nodes.Count;i++ )
|
|||
|
{
|
|||
|
int scount = 0;
|
|||
|
for (int ii = 0; ii < this.treeView1.Nodes[i].Nodes.Count; ii++)
|
|||
|
{
|
|||
|
if (this.treeView1.Nodes[i].Nodes[ii].Checked == true)
|
|||
|
{
|
|||
|
pur += ";" + treeView1.Nodes[i].Nodes[ii].Name;
|
|||
|
this.treeView1.Nodes[i].Checked = true;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
scount++;
|
|||
|
}
|
|||
|
}
|
|||
|
if ((this.treeView1.Nodes[i].Nodes.Count != scount) || ((scount == 0) && (this.treeView1.Nodes[i].Nodes.Count==0)))
|
|||
|
{
|
|||
|
if (this.treeView1.Nodes[i].Checked == true)
|
|||
|
{
|
|||
|
pur += ";" + treeView1.Nodes[i].Name;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
pur = pur.Substring(1);
|
|||
|
string sql = "";
|
|||
|
|
|||
|
try
|
|||
|
{
|
|||
|
if (_ifupdate == true)
|
|||
|
{
|
|||
|
sql = "UPDATE t_base_users SET f_username = '" + this.tbUserName.Text.Trim() + "',f_purview='" + pur + "',f_password='" + tbPassword.Text.Trim() + "' where f_userid= '" + this.tbUserID.Text + "'";
|
|||
|
dbo.ExceSQL(sql);
|
|||
|
MessageBox.Show("<22>û<EFBFBD><C3BB><EFBFBD>Ϣ<EFBFBD>ijɹ<C4B3><C9B9><EFBFBD>", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE>", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|||
|
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
DataView dc = dbo.ExceSQL("select f_userid from t_base_users where f_userid= '" + this.tbUserID.Text + "'").Tables[0].DefaultView;
|
|||
|
if (dc.Count > 0)
|
|||
|
{
|
|||
|
MessageBox.Show("<22>û<EFBFBD><C3BB><EFBFBD>Ϣ<EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD>ڣ<EFBFBD>", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE>", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|||
|
return;
|
|||
|
}
|
|||
|
sql = "insert into t_base_users(f_userid,f_username,f_purview,f_password) values('" + this.tbUserID.Text.Trim() + "','" + this.tbUserName.Text.Trim() + "','" + pur + "','" + tbPassword.Text.Trim() + "')";
|
|||
|
dbo.ExceSQL(sql);
|
|||
|
MessageBox.Show("<22>û<EFBFBD><C3BB><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD>ӳɹ<D3B3><C9B9><EFBFBD>", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE>", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|||
|
|
|||
|
}
|
|||
|
sql = CommomSql + " where f_userid= '" + this.tbUserID.Text + "'";
|
|||
|
DataSet ds = dbo.ExceSQL(sql);
|
|||
|
this.dataGridView1.DataSource = ds.Tables[0].DefaultView;
|
|||
|
_ifupdate = false;
|
|||
|
// CommonClassLib.CCarryConvert.WriteDarkCasket("Login", "UserID<49><44>" + CStaticClass.UserID + "<22>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD>־", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>桿<EFBFBD><E6A1BF>ť", "ϵͳ<CFB5>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>", "UserID<49><44>" + tbUserID.Text );
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
throw ex;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void tsmEdit_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
if (dataGridView1.RowCount <= 0)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
this.tabControl1.SelectTab("tabPage1");
|
|||
|
|
|||
|
this.tbUserID.Text = this.dataGridView1.CurrentRow.Cells[0].Value.ToString() + "";
|
|||
|
DataView dv = dbo.ExceSQL("select f_username as UserName,f_purview as Purview,f_password as password from t_base_users where f_userid='" + this.tbUserID.Text + "'").Tables[0].DefaultView;
|
|||
|
if (dv.Count > 0)
|
|||
|
{
|
|||
|
this.tbUserName.Text = dv[0]["UserName"].ToString() + "";
|
|||
|
this.tbPassword.Text = dv[0]["password"].ToString() + "";
|
|||
|
char[] cc = new char[1] { ':' };
|
|||
|
|
|||
|
for (int i = 0; i < this.treeView1.Nodes.Count; i++)
|
|||
|
{
|
|||
|
|
|||
|
if (dv[0]["Purview"].ToString().IndexOf(this.treeView1.Nodes[i].Name) >= 0)
|
|||
|
{
|
|||
|
|
|||
|
this.treeView1.Nodes[i].Checked = true;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
this.treeView1.Nodes[i].Checked = false;
|
|||
|
}
|
|||
|
for (int ii = 0; ii < this.treeView1.Nodes[i].Nodes.Count; ii++)
|
|||
|
{
|
|||
|
|
|||
|
if (dv[0]["Purview"].ToString().IndexOf(this.treeView1.Nodes[i].Nodes[ii].Name) >= 0)
|
|||
|
{
|
|||
|
|
|||
|
this.treeView1.Nodes[i].Nodes[ii].Checked = true;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
this.treeView1.Nodes[i].Nodes[ii].Checked = false;
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
_ifupdate =true ;
|
|||
|
this.checkBox1.Checked = false;
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
private void ToolStripMenuItem_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
if (MessageBox.Show("<22><>ȷ<EFBFBD><C8B7>Ҫɾ<D2AA><C9BE><EFBFBD>û<EFBFBD><C3BB><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD>", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE>", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
dbo.ExceSQL("delete from t_base_users where f_userid='" + this.dataGridView1.CurrentRow.Cells[0].Value.ToString() + "'");
|
|||
|
button2_Click(sender, e);
|
|||
|
//CommonClassLib.CCarryConvert.WriteDarkCasket("Login", "UserID<49><44>" + CStaticClass.UserID + "<22>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD>־", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɾ<EFBFBD><C9BE><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD>", "ϵͳ<CFB5>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҽ<EFBFBD><D2BC>˵<EFBFBD>", "UserID<49><44>" + tbUserID.Text);
|
|||
|
}
|
|||
|
|
|||
|
private void FrmUsers_Load(object sender, EventArgs e)
|
|||
|
{
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
private void btAll_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
for (int i = 0; i < this.treeView1.Nodes.Count; i++)
|
|||
|
{
|
|||
|
this.treeView1.Nodes[i].Checked = true;
|
|||
|
for (int ii = 0; ii < this.treeView1.Nodes[i].Nodes.Count; ii++)
|
|||
|
{
|
|||
|
this.treeView1.Nodes[i].Nodes[ii].Checked = true;
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void checkBox1_CheckedChanged(object sender, EventArgs e)
|
|||
|
{
|
|||
|
if (this.checkBox1.Checked == true)
|
|||
|
{
|
|||
|
_ifupdate = false;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
_ifupdate = true;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void cbField_SelectedIndexChanged(object sender, EventArgs e)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
string df, sql;
|
|||
|
if (this.cbField.Text == "<22>û<EFBFBD>ID")
|
|||
|
{
|
|||
|
df = "F_UserID";
|
|||
|
}
|
|||
|
else if (this.cbField.Text == "<22><><EFBFBD><EFBFBD>")
|
|||
|
{
|
|||
|
df = "f_username";
|
|||
|
}
|
|||
|
else//
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
sql = " select distinct " + df + " from t_base_users";
|
|||
|
DataView dv = dbo.ExceSQL(sql).Tables[0].DefaultView;
|
|||
|
tbContent.DataSource = null;
|
|||
|
tbContent.DisplayMember = df;
|
|||
|
tbContent.ValueMember = df;
|
|||
|
tbContent.DataSource = dv;
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
throw ex;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void dataGridView1_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
|
|||
|
{
|
|||
|
if ((e.RowIndex >= 0) && (e.Button == MouseButtons.Right))
|
|||
|
{
|
|||
|
dataGridView1.ClearSelection();
|
|||
|
dataGridView1.Rows[e.RowIndex].Selected = true;
|
|||
|
dataGridView1.CurrentCell = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
//private void treeView1_AfterCheck(object sender, TreeViewEventArgs e)
|
|||
|
//{
|
|||
|
// try
|
|||
|
// {
|
|||
|
// if (e.Node.Parent == null)
|
|||
|
// {
|
|||
|
// TreeNode tnc = e.Node;
|
|||
|
// if (tnc.Checked == false)
|
|||
|
// {
|
|||
|
// for (int i = 0; i < tnc.Nodes.Count; i++)
|
|||
|
// {
|
|||
|
// tnc.Nodes[i].Checked = false;
|
|||
|
// }
|
|||
|
// }
|
|||
|
// return;
|
|||
|
// }
|
|||
|
// TreeNode tn = e.Node.Parent;
|
|||
|
// if (tn.Nodes.Count > 0)
|
|||
|
// {
|
|||
|
// int icount = 0;
|
|||
|
// for (int i = 0; i < tn.Nodes.Count; i++)
|
|||
|
// {
|
|||
|
// if (tn.Nodes[i].Checked == true)
|
|||
|
// {
|
|||
|
// tn.Checked = true;
|
|||
|
// }
|
|||
|
// else
|
|||
|
// {
|
|||
|
// icount++;
|
|||
|
// }
|
|||
|
// }
|
|||
|
// //if (tn.Nodes.Count == icount)
|
|||
|
// //{
|
|||
|
// // tn.Checked = false;
|
|||
|
// //}
|
|||
|
// }
|
|||
|
// }
|
|||
|
// catch (Exception ex)
|
|||
|
// {
|
|||
|
// throw ex;
|
|||
|
// }
|
|||
|
//}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
}
|