304 lines
11 KiB
C#
304 lines
11 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 System.Data.SqlClient;
|
|||
|
using ryCommon;
|
|||
|
using ryCommonDb;
|
|||
|
using ryConfig;
|
|||
|
using ryConfig.MSSQLTables;
|
|||
|
namespace Server
|
|||
|
{
|
|||
|
public partial class frmUserList : Form
|
|||
|
{
|
|||
|
Dictionary<string, string> groupDict = new Dictionary<string, string>();
|
|||
|
string splitChar = "|";
|
|||
|
public frmUserList()
|
|||
|
{
|
|||
|
InitializeComponent();
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 载入用户数据
|
|||
|
/// </summary>
|
|||
|
public void LoadDb(string whereSQL,string userList)
|
|||
|
{
|
|||
|
#region 重新载入数据
|
|||
|
this.userList = userList.Replace(",","|").Replace(";", "|");
|
|||
|
lvUsersView.Items.Clear();
|
|||
|
isProcUse = true;
|
|||
|
DataProvider mydb = new DataProvider();
|
|||
|
IDbInterface db =new SqlDataProvider();
|
|||
|
if (db.ConnDb(Config.clsPram.SQLConnStr) == 1)
|
|||
|
{
|
|||
|
DataSet ds = db.ReadData("select * from " + TableUsers.TableName + " where " + TableUsers.Enabled + "=1" + whereSQL);
|
|||
|
lvUsersView.Columns[0].Text = "用户名(正在读取)";
|
|||
|
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
|
|||
|
{
|
|||
|
DataRow reader = ds.Tables[0].Rows[i];
|
|||
|
ListViewItem item;
|
|||
|
string userId = reader[TableUsers.UserId].ToString();
|
|||
|
item = lvUsersView.Items.Add(userId);
|
|||
|
if ((splitChar + this.userList + splitChar).IndexOfEx(splitChar + userId + splitChar) >= 0)
|
|||
|
{
|
|||
|
item.Checked = true;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
item.Checked = false;
|
|||
|
}
|
|||
|
item.Tag = reader["id"].ToString();
|
|||
|
try
|
|||
|
{
|
|||
|
item.Name = "U" + userId;
|
|||
|
}
|
|||
|
catch { }
|
|||
|
string groupId = reader[TableUsers.DivisionDId].ToString();
|
|||
|
if (groupDict.ContainsKey(groupId))
|
|||
|
{
|
|||
|
item.Group = lvUsersView.Groups["M" + groupId];
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
DataSet ds_auth = db.ReadData("select " + TableDivision.Name + " from " + TableDivision.TableName
|
|||
|
+ " where " + TableDivision.dId + "=" + (groupId.Length==0 ? "0" : groupId));
|
|||
|
string groupName = "未知";
|
|||
|
if (mydb.HaveData(ds_auth)) { groupName = ds_auth.Tables[0].Rows[0][0].ToString(); }
|
|||
|
try
|
|||
|
{
|
|||
|
item.Group = lvUsersView.Groups.Add("M" + groupId, groupName);
|
|||
|
}
|
|||
|
catch { }
|
|||
|
groupDict.Add(groupId, groupName);
|
|||
|
}
|
|||
|
item.SubItems.Add(reader[TableUsers.NickName].ToString());
|
|||
|
item.SubItems.Add(reader[TableUsers.Des].ToString());
|
|||
|
string online = reader[TableUsers.Online].ToString();
|
|||
|
if (online == "0")
|
|||
|
{
|
|||
|
online = "不在线";
|
|||
|
item.ForeColor = Color.Gray;
|
|||
|
}
|
|||
|
else if (online == "1")
|
|||
|
{
|
|||
|
online = "在线";
|
|||
|
item.ForeColor = Color.Black;
|
|||
|
}
|
|||
|
else if (online == "2")
|
|||
|
{
|
|||
|
online = "离开";
|
|||
|
item.ForeColor = Color.Gray;
|
|||
|
}
|
|||
|
else if (online == "3")
|
|||
|
{
|
|||
|
online = "忙碌";
|
|||
|
item.ForeColor = Color.Gray;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
online = "";
|
|||
|
item.ForeColor = Color.Gray;
|
|||
|
}
|
|||
|
item.SubItems.Add(online);
|
|||
|
}
|
|||
|
}
|
|||
|
db.Free();
|
|||
|
lvUsersView.Columns[0].Text = "用户名(" + lvUsersView.Items.Count.ToString() + ")";
|
|||
|
isProcUse = false;
|
|||
|
#endregion
|
|||
|
}
|
|||
|
private bool SingleSelected=false;
|
|||
|
public void SetSingleSelected(bool isSingle)
|
|||
|
{
|
|||
|
lvUsersView.CheckBoxes = !isSingle;
|
|||
|
SingleSelected = isSingle;
|
|||
|
btnSelectAll.Visible = !isSingle;
|
|||
|
if (isSingle) { lvUsersView.ContextMenuStrip = null; }
|
|||
|
else { lvUsersView.ContextMenuStrip = ryContextMenuStrip1; }
|
|||
|
|
|||
|
}
|
|||
|
private void frmUserList_Load(object sender, EventArgs e)
|
|||
|
{
|
|||
|
//LoadDb("");
|
|||
|
}
|
|||
|
|
|||
|
private void 全选ToolStripMenuItem_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
for (int i = 0; i < lvUsersView.Items.Count; i++)
|
|||
|
{
|
|||
|
lvUsersView.Items[i].Checked = true;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void 反选ToolStripMenuItem_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
for (int i = 0; i < lvUsersView.Items.Count; i++)
|
|||
|
{
|
|||
|
lvUsersView.Items[i].Checked = !lvUsersView.Items[i].Checked;
|
|||
|
}
|
|||
|
}
|
|||
|
public string userList = "";
|
|||
|
public string userNickList = "";
|
|||
|
private void btnSelected_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
userList = "";
|
|||
|
userNickList = "";
|
|||
|
if (SingleSelected)
|
|||
|
{
|
|||
|
if (lvUsersView.SelectedItems.Count == 0) { return; }
|
|||
|
userList = lvUsersView.SelectedItems[0].Text;
|
|||
|
userNickList = lvUsersView.SelectedItems[0].SubItems[1].Text;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
for (int i = 0; i < lvUsersView.Items.Count; i++)
|
|||
|
{
|
|||
|
if (lvUsersView.Items[i].Checked)
|
|||
|
{
|
|||
|
if (userList.Length==0)
|
|||
|
{
|
|||
|
userList = lvUsersView.Items[i].Text;
|
|||
|
userNickList = lvUsersView.Items[i].SubItems[1].Text;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
userList += splitChar + lvUsersView.Items[i].Text;
|
|||
|
userNickList += splitChar + lvUsersView.Items[i].SubItems[1].Text;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
if (userList.Length==0)
|
|||
|
{
|
|||
|
MessageBox.Show("请至少选择一个用户!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
this.DialogResult = DialogResult.OK;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void chkwz_CheckedChanged(object sender, EventArgs e)
|
|||
|
{
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
private void btnSelectAll_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
全选ToolStripMenuItem.PerformClick();
|
|||
|
}
|
|||
|
private void chkwz_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
string whereSQL = "";
|
|||
|
if (chkwz.Checked)
|
|||
|
{
|
|||
|
whereSQL = TableUsers.Keys + " like '%|文章资讯|%'";
|
|||
|
}
|
|||
|
if (chkRes.Checked)
|
|||
|
{
|
|||
|
if (whereSQL.Length!=0) { whereSQL += " or "; }
|
|||
|
whereSQL += TableUsers.Keys + " like '%|资源|%'";
|
|||
|
}
|
|||
|
if (chkZT.Checked)
|
|||
|
{
|
|||
|
if (whereSQL.Length!=0) { whereSQL += " or "; }
|
|||
|
whereSQL += TableUsers.Keys + " like '%|专题|%'";
|
|||
|
}
|
|||
|
if (chkFB.Checked)
|
|||
|
{
|
|||
|
if (whereSQL.Length!=0) { whereSQL += " or "; }
|
|||
|
whereSQL += TableUsers.Keys + " like '%|封包|%'";
|
|||
|
}
|
|||
|
if (chkBD.Checked)
|
|||
|
{
|
|||
|
if (whereSQL.Length!=0) { whereSQL += " or "; }
|
|||
|
whereSQL += TableUsers.Keys + " like '%|补丁|%'";
|
|||
|
}
|
|||
|
if (chkSY.Checked)
|
|||
|
{
|
|||
|
if (whereSQL.Length!=0) { whereSQL += " or "; }
|
|||
|
whereSQL += TableUsers.Keys + " like '%|手游|%'";
|
|||
|
}
|
|||
|
if (chkReport.Checked)
|
|||
|
{
|
|||
|
if (whereSQL.Length!=0) { whereSQL += " or "; }
|
|||
|
whereSQL += TableUsers.Keys + " like '%|报表|%'";
|
|||
|
}
|
|||
|
if (whereSQL.Length!=0) { whereSQL = " and (" + whereSQL + ")"; }
|
|||
|
//MessageBox.Show(whereSQL);
|
|||
|
LoadDb(whereSQL,userList);
|
|||
|
}
|
|||
|
|
|||
|
private void lvUsersView_ItemCheck(object sender, ItemCheckEventArgs e)
|
|||
|
{
|
|||
|
|
|||
|
}
|
|||
|
bool isProcUse = false;
|
|||
|
private void lvUsersView_ItemChecked(object sender, ItemCheckedEventArgs e)
|
|||
|
{
|
|||
|
if (!isProcUse)
|
|||
|
{
|
|||
|
if (!e.Item.Checked)
|
|||
|
{
|
|||
|
userList = (splitChar + userList + splitChar).Replace(splitChar + e.Item.Text + splitChar, splitChar);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
if ((splitChar + userList + splitChar).IndexOfEx(splitChar + e.Item.Text + splitChar) < 0)
|
|||
|
{
|
|||
|
userList += splitChar + e.Item.Text;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void lvUsersView_KeyDown(object sender, KeyEventArgs e)
|
|||
|
{
|
|||
|
if (e.KeyCode == Keys.Enter)
|
|||
|
{
|
|||
|
btnSelected.PerformClick();
|
|||
|
}
|
|||
|
else if (e.KeyCode == Keys.Left)
|
|||
|
{
|
|||
|
if (lvUsersView.SelectedItems.Count != 0)
|
|||
|
{
|
|||
|
lvUsersView.SelectedItems[0].Checked = !lvUsersView.SelectedItems[0].Checked;
|
|||
|
}
|
|||
|
}
|
|||
|
else if (e.KeyCode == Keys.Escape)
|
|||
|
{
|
|||
|
Close();
|
|||
|
}
|
|||
|
else if (e.KeyCode == Keys.A && e.Control)
|
|||
|
{
|
|||
|
btnSelectAll.PerformClick();
|
|||
|
}
|
|||
|
else if (e.KeyCode == Keys.Z && e.Control)
|
|||
|
{
|
|||
|
btnSelected.PerformClick();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void chkReport_CheckedChanged(object sender, EventArgs e)
|
|||
|
{
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
private void 选择该组ToolStripMenuItem_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
if (lvUsersView.SelectedItems.Count == 0) { return; }
|
|||
|
string tag = lvUsersView.SelectedItems[0].Group.Name;
|
|||
|
try
|
|||
|
{
|
|||
|
for (int i = 0; i < lvUsersView.Items.Count; i++)
|
|||
|
{
|
|||
|
lvUsersView.Items[i].Checked = tag == lvUsersView.Items[i].Group.Name;
|
|||
|
}
|
|||
|
}
|
|||
|
catch { }
|
|||
|
}
|
|||
|
}
|
|||
|
}
|