123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Drawing;
- using System.Data;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using WWPipeLine.MapBasic.Conditions;
- using WeifenLuo.WinFormsUI.Docking;
- using WWPipeLine.MapBasic;
- using Sunny.UI;
- namespace WWPipeLine.MapTools.Conditions.XiTongGuanLi
- {
- public partial class UserManager : ConditionPanel
- {
- private int m_id = 0;
- public UserManager()
- {
- this.ConditionPanelName = "系统用户管理";
- InitializeComponent();
- this.IsShowPanelFooter = false;
- }
- protected override void OnLoad(EventArgs e)
- {
- DataTable dt = new NpgsqlHelper().ExecuteQuery("SELECT id,uname from usersys where urole_id=1").Tables[0];
- uiDGVjslkpz.DataSource = dt;
- foreach (DataGridViewColumn c in uiDGVjslkpz.Columns)
- {
- c.SortMode = DataGridViewColumnSortMode.NotSortable;
- switch (c.Name.ToLower())
- {
- case "id": c.HeaderText = "ID"; c.Visible = false; break;
- case "uname": c.HeaderText = "账号"; break;
- default: c.HeaderText = ""; break;
- }
- }
- uiDGVjslkpz.SelectedIndex = 0;
- uitbUsername.Text = ""; uitbPass.Text = "";
- }
- private void uiDGVjslkpz_SelectIndexChange(object sender, int index)
- {
- var selectRows = (sender as UIDataGridView).SelectedRows;
- if (selectRows == null || selectRows.Count != 1) return;
- m_id = ComsStatic.StringToInt(selectRows[0].Cells["id"].Value.ToString());
- uitbUsername.Text = selectRows[0].Cells["uname"].Value.ToString();
- }
- private void uiButton1_Click(object sender, EventArgs e)
- {
- if (string.IsNullOrEmpty(uitbUsername.Text) || string.IsNullOrEmpty(uitbPass.Text))
- { UIMessageTip.ShowError("请输入合法的用户名和密码"); return; }
- string sql = string.Format("select id from usersys where uname='{0}'", uitbUsername.Text);
- int r = new NpgsqlHelper().ExecuteQuery(sql).Tables[0].Rows.Count;
- if (r != 0)
- { UIMessageTip.ShowError("当前用户名已存在,请更换其他用户名"); return; }
- string pwdMd5 = ComsStatic.getMd5Hash(uitbPass.Text, "ww");
- sql = string.Format(" INSERT INTO usersys(uname,upassword,urole_id)VALUES('{0}','{1}',1) ", uitbUsername.Text, pwdMd5);
- r = new NpgsqlHelper().ExecuteNonQuery(sql);
- if (r == 1)
- ComsStatic.ShowOKLog("新增用户成功", uitbUsername.Text);
- else
- ComsStatic.ShowErrorLog("新增用户失败", uitbUsername.Text);
- OnLoad(e);
- }
- private void uiButton2_Click(object sender, EventArgs e)
- {
- if (string.IsNullOrEmpty(uitbPass.Text) || m_id == 0)
- { UIMessageTip.ShowError("请输入合法的用户名和密码"); return; }
- string pwdMd5 = ComsStatic.getMd5Hash(uitbPass.Text, "ww");
- string sql = string.Format("UPDATE usersys set upassword='{0}' where id ={1} ", pwdMd5, m_id);
- int r = new NpgsqlHelper().ExecuteNonQuery(sql);
- if (r == 1)
- ComsStatic.ShowOKLog("修改用户密码成功", m_id.ToString());
- else
- ComsStatic.ShowErrorLog("修改用户失败", m_id.ToString());
- OnLoad(e);
- }
- private void uiButton3_Click(object sender, EventArgs e)
- {
- if (m_id == 0)
- { UIMessageTip.ShowError("请选择需要删除的账号"); return; }
- string sql = string.Format("DELETE FROM usersys where id={0}", m_id);
- int r = new NpgsqlHelper().ExecuteNonQuery(sql);
- if (r == 1)
- ComsStatic.ShowOKLog("删除用户成功", m_id.ToString());
- else
- ComsStatic.ShowErrorLog("删除用户失败", m_id.ToString());
- OnLoad(e);
- }
- private void uitbPass_KeyPress(object sender, KeyPressEventArgs e)
- {
- e.Handled = true;
- if ((e.KeyChar >= 48 && e.KeyChar <= 57) || (e.KeyChar >= 65 && e.KeyChar <= 90) || (e.KeyChar >= 97 && e.KeyChar <= 122) || (e.KeyChar == 8))
- e.Handled = false;
- }
- }
- }
|