Exemplo n.º 1
0
        /// <summary>
        /// 加载除su外的角色.
        /// </summary>
        public static void LoadRoles(ComboBox cmb)
        {
            List <Role> list = Role.Query("");

            try
            {
                foreach (Role item in list)
                {
                    string roleName = item.Name;
                    if (item.Id > 1)
                    {
                        cmb.Items.Add(item.Name);
                    }
                }
            }
            catch (Exception ex)
            {
                LogMan.Log2File(null, ex);
            }
            finally
            {
                if (cmb.Items.Count > 0)
                {
                    cmb.SelectedIndex = 0;
                }
            }
        }
Exemplo n.º 2
0
        //下拉框选择逻辑
        private void cmbRole_SelectedIndexChanged(object sender, EventArgs e)
        {
            int              roleId   = cmbRole.SelectedIndex + 2;
            string           roleName = cmbRole.Text;
            string           oldName  = string.Empty;
            DataGridViewCell cell     = dgvAuth.CurrentCell;

            if (cell != null)
            {
                try
                {
                    oldName    = cell.Value.ToString();
                    cell.Value = roleName;
                    int row = cell.RowIndex;
                    dgvAuth.Rows[row].Cells[2].Value = roleId;
                    Db.Authority auth = new Db.Authority();
                    auth.Id   = Convert.ToInt32(dtAuth.Rows[row]["id"]);
                    auth.Name = dtAuth.Rows[row]["name"].ToString();
                    Role role = new Role(roleId, roleName);
                    auth.Role = role;
                    if (auth.Update())
                    {
                        LogMan.Log2Sqlite(new Log(LogLevel.Info, EventType.权限管理, "修改权限:" + dtAuth.Rows[row]["name"].ToString() + "(" + oldName + "->" + roleName + ")", DateTime.Now));
                    }
                }
                catch (Exception ex)
                {
                    LogMan.Log2File(null, ex);
                }
            }
        }
Exemplo n.º 3
0
 private void LoadUsers(string where)
 {
     try
     {
         List <User> list = User.Query(where);
         dtUsers.Rows.Clear();
         foreach (User item in list)
         {
             string roleName = item.Role.Name;
             dtUsers.Rows.Add(item.UserName, roleName, "删除", "编辑");
         }
         dgvUser.DataSource            = dtUsers;
         dgvUser.Columns[0].HeaderText = "用户名";
         dgvUser.Columns[1].HeaderText = "角色名";
         dgvUser.Columns[2].HeaderText = "删除";
         dgvUser.Columns[3].HeaderText = "编辑";
         Font font = new Font("宋体", 9f, (System.Drawing.FontStyle)System.Drawing.FontStyle.Underline);
         dgvUser.Columns[2].DefaultCellStyle.Font      = dgvUser.Columns[3].DefaultCellStyle.Font = font;
         dgvUser.Columns[2].DefaultCellStyle.ForeColor = dgvUser.Columns[3].DefaultCellStyle.ForeColor = Color.Blue;
         //dgvUser.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
         //动态列宽
         dgvUser.Columns[2].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
         dgvUser.Columns[3].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
         dgvUser.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
         dgvUser.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
     }
     catch (Exception ex)
     {
         LogMan.Log2File(null, ex);
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Creates and runs a <seealso cref="Server"/>.
        /// </summary>
        /// <param name="_maxPlayers">The maximum number of clients that can connect to the server.</param>
        /// <param name="_port">The port to run on.</param>
        public static void Start(int _maxPlayers, int _port)
        {
            maxPlayers = _maxPlayers;
            port       = _port;

            LogMan.Initialize();
            LogMan.Info($"Copyright (c) {DateTime.Now.Year} Gideon Grinberg. Subject to the terms of the Mozilla PublicLicense, v. 2.0.");
            LogMan.Info($"Starting server.");

            try
            {
                tcpListener = new TcpListener(IPAddress.Any, port);

                tcpListener.Start();
                tcpListener.BeginAcceptTcpClient(new AsyncCallback(TCPConnectCallback), null);

                LogMan.Info($"Listening for connections on port {port}. Max players is currently set to {_maxPlayers}");
            }
            catch (Exception ex)
            {
                LogMan.Info($"ERROR: Failed to start TCP server. Exception: \n {ex}");
            }

            InitializeServerData();
            LogMan.Info("Finished initializing server!");
        }
Exemplo n.º 5
0
        /// <summary>
        /// 初始化主界面控件.
        /// </summary>
        private void IniUC()
        {
            //ribbon菜单初始化
            ucPanelFile   panelFile   = new ucPanelFile();
            ucPanelPrepro panelCloud  = new ucPanelPrepro();
            ucPanelUpdate panelUpdate = new ucPanelUpdate();
            ucPanelSys    panelSys    = new ucPanelSys();

            this.tpFile.Controls.Add(panelFile);
            this.tpPreprocess.Controls.Add(panelCloud);
            this.tpUpdate.Controls.Add(panelUpdate);
            this.tpSys.Controls.Add(panelSys);
            panelFile.Anchor = panelCloud.Anchor = panelUpdate.Anchor = panelSys.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right;

            //gis控件初始化
            this.axTOCControl.Dock = DockStyle.Fill;
            this.axMapControl.Dock = DockStyle.Fill;
            axMapControl.Map.Name  = "图层";

            //修改状态栏用户信息
            if (ConstDef.curUser != null)
            {
                this.tsslUser.Text = "当前用户:" + ConstDef.curUser.UserName + "-" + ConstDef.curUser.Role.Name;
            }

            //主界面大小位置初始化
            string sizeStr = ConfigurationManager.AppSettings["Size"].Trim();

            if (!string.IsNullOrEmpty(sizeStr))
            {
                try
                {
                    string[] size = sizeStr.Split(',');
                    if (size.Length == 5)
                    {
                        int width = int.Parse(size[2]);
                        if (width == 1920 || width == 1366)
                        {
                            this.Size = new Size(1024, 768);
                            this.CenterToScreen();
                        }
                        else
                        {
                            this.Location = new System.Drawing.Point(int.Parse(size[0]), int.Parse(size[1]));
                            this.Size     = new Size(int.Parse(size[2]), int.Parse(size[3]));
                            this.splitContainer.SplitterDistance = int.Parse(size[4]);
                        }
                    }
                    else
                    {
                        this.CenterToScreen();
                    }
                }
                catch (Exception ex)
                {
                    LogMan.Log2File(null, ex);
                }
            }
        }
Exemplo n.º 6
0
 //
 //获取鼠标位置坐标
 //
 private void GetStatusXY(double mapX, double mapY)
 {
     try
     {
         ISpatialReference spatialReference = this.axMapControl.SpatialReference;
         if (spatialReference != null)
         {
             if (spatialReference is IProjectedCoordinateSystem)
             {
                 IProjectedCoordinateSystem projectedCoordinateSystem = spatialReference as IProjectedCoordinateSystem;
                 IPoint point = new PointClass();
                 point.SpatialReference = spatialReference;
                 point.X = mapX;
                 point.Y = mapY;
                 point.Project(projectedCoordinateSystem.GeographicCoordinateSystem);
                 double lon        = point.X;
                 double lat        = point.Y;
                 int    lon_degree = (int)Math.Floor(Convert.ToDecimal(lon));
                 int    lat_degree = (int)Math.Floor(Convert.ToDecimal(lat));
                 lon = (lon - lon_degree) * 60;
                 lat = (lat - lat_degree) * 60;
                 int lon_m = (int)Math.Floor(Convert.ToDecimal(lon));
                 int lat_m = (int)Math.Floor(Convert.ToDecimal(lat));
                 lon = (lon - lon_m) * 60;
                 lat = (lat - lat_m) * 60;
                 int    lon_s  = (int)Math.Floor(Convert.ToDecimal(lon));
                 int    lat_s  = (int)Math.Floor(Convert.ToDecimal(lat));
                 string strLon = "";
                 string strLat = "";
                 if (lon_degree > 0)
                 {
                     strLon = lon_degree + "° " + lon_m + "′ " + lon_s + "″ E";
                 }
                 else
                 {
                     strLon = lon_degree + "° " + lon_m + "′ " + lon_s + "″ E";
                 }
                 if (lat_degree > 0)
                 {
                     strLat = lat_degree + "° " + lat_m + "′ " + lat_s + "″ N";
                 }
                 else
                 {
                     strLat = lat_degree + "° " + lat_m + "′ " + lat_s + "″ N";
                 }
                 this.tsslXY.Text = string.Format("坐标:{0},{1}", strLon, strLat);
             }
         }
         else
         {
             this.tsslXY.Text = string.Format("坐标:{0},{1}", mapX, mapY);
         }
     }
     catch (Exception ex)
     {
         LogMan.Log2File(null, ex);
     }
 }
        public AliveControlService()
        {
            InitializeComponent();
            string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);

            RegMan.SetProgramBase("AliveControl");
            LogMan.LogDirectory = path.Replace("file:\\", "");
            LogMan.StartLogging(LogMan.LogDirectory, "AliveControl");
            LogMan.AddLog("HUEAHOEIUHAEOIU");
            RegMan.Write("Path", path.Replace("file:\\", ""));
            LogMan.debugmode = true;
        }
Exemplo n.º 8
0
 /// <summary>
 /// Handles the Click event of the mrbAdd control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
 private void mrbAdd_Click(object sender, EventArgs e)
 {
     try
     {
         string name    = this.msltUser.Text.Trim();
         string pwd     = this.msltPwd.Text.Trim();
         string confirm = this.msltConfirm.Text.Trim();
         int    roleId  = cmbRole.SelectedIndex + 2;
         if (string.IsNullOrEmpty(name))
         {
             MessageBox.Show("用户名不能为空!", ConstMsg.Msg00, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
         }
         else if (string.IsNullOrEmpty(pwd) || string.IsNullOrEmpty(confirm))
         {
             MessageBox.Show("密码不能为空!", ConstMsg.Msg00, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
         }
         else if (pwd != confirm)
         {
             MessageBox.Show("两次输入密码不一致!", ConstMsg.Msg00, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
         }
         else
         {
             User user = User.Find(name);
             if (user != null)
             {
                 MessageBox.Show("用户已存在!", ConstMsg.Msg00, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
             }
             else
             {
                 user          = new User();
                 user.UserName = name;
                 user.Password = SunGolden.Encryption.DEncrypt.Encrypt(pwd);
                 user.RoleId   = roleId;
                 if (!user.Insert())
                 {
                     MessageBox.Show("添加用户失败!", ConstMsg.Msg00, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                 }
                 else
                 {
                     MessageBox.Show("添加用户成功!", ConstMsg.Msg00, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                     LogMan.Log2Sqlite(new Log(LogLevel.Info, EventType.用户管理, "添加用户:" + name, DateTime.Now));
                     this.DialogResult = DialogResult.OK;
                 }
             }
         }
     }
     catch (Exception ex)
     {
         LogMan.Log2File(null, ex);
     }
 }
        protected override void OnStart(string[] args)
        {
            LoadConfig();
            if (SessionKey == null)
            {
                LogMan.AddLog("No session key! Configure with ACConfig");
                this.Stop();
                return;
            }
            LogMan.AddLog("Started Service.");
            LogMan.AddLog("Interval: " + Interval.ToString());

            mTimer          = new System.Timers.Timer(Interval);
            mTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
            mTimer.Enabled  = true;
        }
Exemplo n.º 10
0
        public void SendQueueMessage(string message = "Hi Guys")
        {
            Stopwatch   sw           = new Stopwatch();
            QueueClient _queueClient = QueueClient.CreateFromConnectionString(_connectionString, _queueName);

            sw.Start();
            _queueClient.Send(new BrokeredMessage(new AzureMessage
            {
                Id   = 1,
                Body = "Deneme"
            }));
            sw.Stop();

            LogMan lm = new LogMan();

            lm.AzureLogToFile(1, sw.Elapsed);
        }
Exemplo n.º 11
0
        private void mrbOK_Click(object sender, EventArgs e)
        {
            int newRoleId = cmbRole.SelectedIndex + 2;

            try
            {
                if (newRoleId != selectedUser.RoleId)
                {
                    selectedUser.RoleId = newRoleId;
                    selectedUser.Update(true);
                    LogMan.Log2Sqlite(new Log(LogLevel.Info, EventType.用户管理, "修改用户角色:" + selectedUser.UserName + "(" + selectedUser.Role.Name + "->" + cmbRole.Text + ")", DateTime.Now));
                    this.DialogResult = DialogResult.OK;
                }
            }
            catch (Exception ex)
            {
                LogMan.Log2File(null, ex);
            }
        }
        private void OnTimedEvent(object source, ElapsedEventArgs e)
        {
            mTimer.Stop();
            MachineData mdata = new MachineData();

            LogMan.AddLog("Fetching Smart");
            mdata.disks = tvstools.ReadSmart();
            GC.KeepAlive(mTimer);
            LogMan.AddLog("Fetching Network Devices");
            mdata.ethernets = tvstools.GetNetworkDevices();
            GC.KeepAlive(mTimer);
            LogMan.AddLog("Fetching Mount Points");
            mdata.mounts = tvstools.GetMountPoints();
            GC.KeepAlive(mTimer);
            mdata.UUID        = MachineUUID;
            mdata.UpTime      = tvstools.GetUpTime();
            mdata.Processor   = tvstools.GetProcessorName();
            mdata.OS          = tvstools.GetOSName();
            mdata.FreeMemory  = tvstools.GetFreeMemory();
            mdata.FreeSwap    = tvstools.GetFreeSwapMemory();
            mdata.TotalMemory = tvstools.GetTotalMemory();
            mdata.TotalSwap   = tvstools.GetTotalSwapMemory();
            mdata.Name        = Name;
            LogMan.AddDebug(mdata.ToJSON());

            GC.KeepAlive(mTimer);
            LogMan.AddLog("Sending data");
            if (API.SendMachine(mdata))
            {
                if (MachineUUID == null)
                {
                    MachineUUID = API.MachineUUID;
                    LogMan.AddLog("First time of this machine! Now the UUID is: " + MachineUUID);
                    RegMan.Write("MachineUUID", MachineUUID);
                }
                LogMan.AddLog("Data sent successfully!");
            }
            else
            {
                LogMan.AddLog("Fail sending machine data!");
            }
            mTimer.Start();
        }
Exemplo n.º 13
0
        public void GetQueueMessage()
        {
            int messageCount = 0;

            LogMan      lm           = new LogMan();
            Stopwatch   sw           = new Stopwatch();
            QueueClient _queueClient = QueueClient.CreateFromConnectionString(_connectionString, _queueName);

            sw.Start();
            //
            _queueClient.OnMessage(message =>
            {
                Console.WriteLine(String.Format("Message body: {0}", message.GetBody <AzureMessage>().Id));
                messageCount++;
            });
            //
            sw.Stop();
            lm.AzureLogToFile(messageCount, sw.Elapsed);
        }
Exemplo n.º 14
0
 private void mrbLogin_Click(object sender, EventArgs e)
 {
     if (!Login())
     {
         return;
     }
     if (this.mcbRember.Checked)
     {
         //打开配置文件
         Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
         config.AppSettings.Settings["User"].Value     = this.msltUser.Text;
         config.AppSettings.Settings["Password"].Value = SunGolden.Encryption.DEncrypt.Encrypt(this.msltPwd.Text);
         //保存配置
         config.Save();
         ConfigurationManager.RefreshSection("AppSettings");
     }
     LogMan.Log2Sqlite(new Log(LogLevel.Info, EventType.用户管理, "用户登陆:" + this.msltUser.Text, DateTime.Now));
     this.DialogResult = DialogResult.OK;
 }
Exemplo n.º 15
0
        /// <summary>
        /// Connects a new client to the server.
        /// </summary>
        private static void TCPConnectCallback(IAsyncResult _result)
        {
            TcpClient _client = tcpListener.EndAcceptTcpClient(_result);

            tcpListener.BeginAcceptTcpClient(new AsyncCallback(TCPConnectCallback), null);

            LogMan.Info($"Incoming connection from {_client.Client.RemoteEndPoint}");
            for (int i = 1; i <= maxPlayers; i++)
            {
                if (clients[i].tcp.socket == null)
                {
                    clients[i].tcp.Connect(_client);
                    LogMan.Info($"Connected client {clients[i].tcp.socket.Client.RemoteEndPoint}. Client ID: {i}");
                    return;
                }
            }

            LogMan.Info($"Failed to connect client. Server is full. (Players: {maxPlayers}/{maxPlayers} connections used).");
        }
Exemplo n.º 16
0
    async void WebSocket()
    {
        try
        {
            m_uri      = new Uri(uri);
            m_clientws = new ClientWebSocket();
            await m_clientws.ConnectAsync(m_uri, new CancellationToken());

            Send = m_clientws.SendAsync;

            if (m_logMan == null)
            {
                m_logMan = new LogMan();
            }
            var data = JsonUtility.ToJson(m_logMan, false);
            await Send(new ArraySegment <byte>(Encoding.UTF8.GetBytes(data)), WebSocketMessageType.Binary, true, new CancellationToken());
        }
        catch (Exception ex)
        {
        }
    }
Exemplo n.º 17
0
 private bool Login()
 {
     if (string.IsNullOrEmpty(msltUser.Text))
     {
         MessageBox.Show("用户名不能为空!", ConstMsg.Msg00, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
         return(false);
     }
     else if (string.IsNullOrEmpty(this.msltPwd.Text))
     {
         MessageBox.Show("密码不能为空!", ConstMsg.Msg00, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
         return(false);
     }
     else
     {
         Db.User user = null;
         try
         {
             user = Db.User.Find(msltUser.Text.Trim());
         }
         catch (Exception ex)
         {
             LogMan.Log2File(null, ex);
         }
         if (user == null)
         {
             MessageBox.Show("用户不存在!", ConstMsg.Msg00, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
             return(false);
         }
         else if (user.Password != SunGolden.Encryption.DEncrypt.Encrypt(msltPwd.Text))
         {
             MessageBox.Show("密码错误!", ConstMsg.Msg00, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
             return(false);
         }
         else
         {
             ConstDef.curUser = user;
             return(true);
         }
     }
 }
Exemplo n.º 18
0
        public void AzureLoadTestSend()
        {
            var status = LogStatus.Stop;
            int count  = 0;

            Stopwatch   sw           = new Stopwatch();
            LogMan      lm           = new LogMan();
            QueueClient _queueClient = QueueClient.CreateFromConnectionString(_connectionString, _queueName);

            lm.WriteAzureLogStatus(LogStatus.Start);
            sw.Start();
            //
            try
            {
                for (int a = 1; a <= 50000; a++)
                {
                    _queueClient.Send(new BrokeredMessage(new AzureMessage
                    {
                        Id   = a,
                        Body = string.Format("{0} numarali mesaj.", a)
                    }));

                    Console.WriteLine(string.Format("{0} id numarali mesaj gonderildi. ", a));
                    lm.AzureLoadTestLog(a);
                    count = a;
                }
            }
            catch (Exception e)
            {
                lm.AzureLogException(e.InnerException.Message);
                status = LogStatus.Abondoned;
            }
            //
            sw.Stop();

            lm.AzureLogToFile(count, sw.Elapsed);
            lm.WriteAzureLogStatus(status);
        }
Exemplo n.º 19
0
 private void mrbAdd_Click(object sender, EventArgs e)
 {
     if (DialogResult.OK == MessageBox.Show("确定要修改密码吗?", ConstMsg.Msg00, MessageBoxButtons.OKCancel, MessageBoxIcon.Question))
     {
         string oldPwd    = this.msltOldPwd.Text;
         string newPwd    = this.msltNewPwd.Text;
         string confimPwd = this.msltConfimPwd.Text;
         if (string.IsNullOrEmpty(oldPwd) || SunGolden.Encryption.DEncrypt.Encrypt(oldPwd) != ConstDef.curUser.Password)
         {
             MessageBox.Show("原密码错误,请重新输入!", ConstMsg.Msg00, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
         }
         else if (string.IsNullOrEmpty(newPwd) || string.IsNullOrEmpty(confimPwd) || newPwd != confimPwd)
         {
             MessageBox.Show("新密码为空或不一致,请重新输入!", ConstMsg.Msg00, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
         }
         else
         {
             ConstDef.curUser.Password = SunGolden.Encryption.DEncrypt.Encrypt(newPwd);
             try
             {
                 if (ConstDef.curUser.Update(true))
                 {
                     //消息提示
                     MessageBox.Show("修改成功,下次登陆请使用新密码。", ConstMsg.Msg00, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                     //记录操作日志
                     LogMan.Log2Sqlite(new Log(LogLevel.Info, EventType.用户管理, "修改密码", DateTime.Now));
                 }
             }
             catch (Exception ex)
             {
                 //提示错误信息
                 MessageBox.Show("修改失败:" + ex.Message, ConstMsg.Msg00, MessageBoxButtons.OK, MessageBoxIcon.Error);
                 //记录错误日志
                 Db.LogMan.Log2File(null, ex);
             }
         }
     }
 }
Exemplo n.º 20
0
 private void frmLogin_Load(object sender, EventArgs e)
 {
     //加载本地记录用户
     try
     {
         string user = ConfigurationManager.AppSettings["User"];
         if (string.IsNullOrEmpty(user))
         {
             return;
         }
         this.msltUser.Text = user;
         string password = SunGolden.Encryption.DEncrypt.Decrypt(ConfigurationManager.AppSettings["Password"]);
         if (string.IsNullOrEmpty(password))
         {
             return;
         }
         this.msltPwd.Text = password;
     }
     catch (Exception ex)
     {
         LogMan.Log2File(null, ex);
     }
 }
Exemplo n.º 21
0
            /// <summary>
            /// Read TCP data from stream.
            /// </summary>
            private void ReceiveCallback(IAsyncResult _result)
            {
                try
                {
                    int _byteLength = stream.EndRead(_result);

                    if (_byteLength <= 0)
                    {
                        // TODO: disconnect client.
                        LogMan.Info("Received 0 bytes of data from client.");
                    }

                    byte[] _data = new byte[_byteLength];
                    Array.Copy(receiveBuffer, _data, dataBufferSize);

                    // TODO: handle data

                    stream.BeginRead(receiveBuffer, 0, dataBufferSize, ReceiveCallback, null);
                }
                catch (Exception ex)
                {
                    LogMan.Info($"\u001b[31m Error receiving TCP data: \u001b[0m {ex}");
                }
            }
 protected override void OnStop()
 {
     mTimer.Stop();
     mTimer.Dispose();
     LogMan.AddLog("Service Stopped");
 }
Exemplo n.º 23
0
        private void dgvUser_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            try
            {
                DataGridViewCell selectedCell = dgvUser.SelectedCells[0];
                string           text         = selectedCell.Value.ToString();
                string           uName        = dgvUser.Rows[selectedCell.RowIndex].Cells[0].Value.ToString();
                User             user         = User.Find(uName);
                if (user != null)
                {
                    EditUser(user, text);
                }
                //    if (text == "删除")
                //    {
                //        string uName = dgvUser.Rows[selectedCell.RowIndex].Cells[0].Value.ToString();
                //        string uRole = dgvUser.Rows[selectedCell.RowIndex].Cells[1].Value.ToString();
                //        if (uRole == "超级管理员")
                //        {
                //            MessageBox.Show("不能删除超级管理员账户", ConstMsg.Msg00, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                //        }
                //        else if (uRole == "管理员")
                //        {
                //            if (ConstDef.curUser.RoleId == 1)
                //            {
                //                if (DialogResult.OK == MessageBox.Show(string.Format("删除账户:{0} ?", uName), ConstMsg.Msg00, MessageBoxButtons.OKCancel, MessageBoxIcon.Question))
                //                {
                //                    User user = User.Find(uName);
                //                    user.Delete();
                //                    LogMan.Log2Sqlite(new Log(LogLevel.Info, EventType.用户管理, "删除用户:" + uName, DateTime.Now));
                //                    LoadUsers("");
                //                }
                //            }
                //            else
                //            {
                //                if (uName != ConstDef.curUser.UserName)
                //                {
                //                    MessageBox.Show("权限不足:删除其他管理员账户请使用超级管理员登陆!", ConstMsg.Msg00, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                //                }
                //                else
                //                {
                //                    if (DialogResult.OK == MessageBox.Show("已使用所选账户登陆,是否删除?", ConstMsg.Msg00, MessageBoxButtons.OKCancel, MessageBoxIcon.Question))
                //                    {
                //                        ConstDef.curUser.Delete();
                //                        LogMan.Log2Sqlite(new Log(LogLevel.Info, EventType.用户管理, "删除用户:" + uName, DateTime.Now));
                //                        Application.Restart();
                //                    }
                //                }
                //            }
                //        }
                //        else
                //        {
                //            if (DialogResult.OK == MessageBox.Show(string.Format("删除账户:{0} ?",uName), ConstMsg.Msg00, MessageBoxButtons.OKCancel, MessageBoxIcon.Question))
                //            {
                //                User user = User.Find(uName);
                //                user.Delete();
                //                LogMan.Log2Sqlite(new Log(LogLevel.Info, EventType.用户管理, "删除用户:" + uName, DateTime.Now));
                //                LoadUsers("");
                //            }
                //        }

                //    }
                //    else if(text)
            }
            catch (Exception ex)
            {
                LogMan.Log2File(null, ex);
            }
        }
Exemplo n.º 24
0
 private void EditUser(User user, string opration)
 {
     if (opration == "删除")
     {
         if (user.RoleId == 1)
         {
             MessageBox.Show("不能删除超级管理员账户", ConstMsg.Msg00, MessageBoxButtons.OK, MessageBoxIcon.Warning);
         }
         else if (user.RoleId == 2)
         {
             if (ConstDef.curUser.RoleId == 1)
             {
                 if (DialogResult.OK == MessageBox.Show(string.Format("删除账户:{0} ?", user.UserName), ConstMsg.Msg00, MessageBoxButtons.OKCancel, MessageBoxIcon.Question))
                 {
                     user.Delete();
                     LogMan.Log2Sqlite(new Log(LogLevel.Info, EventType.用户管理, "删除用户:" + user.UserName, DateTime.Now));
                     LoadUsers("");
                 }
             }
             else
             {
                 if (user.UserName != ConstDef.curUser.UserName)
                 {
                     MessageBox.Show("权限不足:删除其他管理员账户请使用超级管理员登陆!", ConstMsg.Msg00, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                 }
                 else
                 {
                     if (DialogResult.OK == MessageBox.Show("已使用所选账户登陆,是否删除?", ConstMsg.Msg00, MessageBoxButtons.OKCancel, MessageBoxIcon.Question))
                     {
                         ConstDef.curUser.Delete();
                         LogMan.Log2Sqlite(new Log(LogLevel.Info, EventType.用户管理, "删除用户:" + user.UserName, DateTime.Now));
                         Application.Restart();
                     }
                 }
             }
         }
         else
         {
             if (DialogResult.OK == MessageBox.Show(string.Format("删除账户:{0} ?", user.UserName), ConstMsg.Msg00, MessageBoxButtons.OKCancel, MessageBoxIcon.Question))
             {
                 user.Delete();
                 LogMan.Log2Sqlite(new Log(LogLevel.Info, EventType.用户管理, "删除用户:" + user.UserName, DateTime.Now));
                 LoadUsers("");
             }
         }
     }
     else if (opration == "编辑")
     {
         if (user.RoleId == 1)
         {
             MessageBox.Show("不能编辑超级管理员账户", ConstMsg.Msg00, MessageBoxButtons.OK, MessageBoxIcon.Warning);
         }
         else if (user.RoleId == 2)
         {
             if (ConstDef.curUser.RoleId == 1)
             {
                 //su编辑管理员角色
                 if (DialogResult.OK == new frmEditUser(user).ShowDialog())
                 {
                     LoadUsers("");
                 }
             }
             else
             {
                 if (user.UserName != ConstDef.curUser.UserName)
                 {
                     MessageBox.Show("权限不足:编辑其他管理员账户请使用超级管理员登陆!", ConstMsg.Msg00, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                 }
                 else
                 {
                     //管理员用户编辑自己角色
                     if (DialogResult.OK == new frmEditUser(user).ShowDialog())
                     {
                         if (user.UserName == ConstDef.curUser.UserName)
                         {
                             ConstDef.curUser = User.Find(user.UserName);
                         }
                         if (ConstDef.curUser.RoleId > 2)
                         {
                             this.Close();
                         }
                         else
                         {
                             LoadUsers("");
                         }
                     }
                 }
             }
         }
         //管理员编辑普通用户
         else
         {
             if (DialogResult.OK == new frmEditUser(user).ShowDialog())
             {
                 LoadUsers("");
             }
         }
     }
 }