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);
     }
 }
Esempio n. 2
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;
                }
            }
        }
Esempio n. 3
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);
                }
            }
        }
Esempio n. 4
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);
                }
            }
        }
Esempio n. 5
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);
     }
 }
 /// <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);
     }
 }
        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);
            }
        }
Esempio n. 8
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);
         }
     }
 }
Esempio n. 9
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);
     }
 }
        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);
            }
        }