Пример #1
0
        /// <summary>
        /// 初始化列表框
        /// </summary>
        private void InitialForm()
        {
            Exception outError = null;                 //异常

            SysCommon.DataBase.SysTable pSysDB = null; //连接数据库类
            //连接数据库
            ModDBOperate.ConnectDB(out pSysDB, out outError);
            if (outError != null)
            {
                SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", outError.Message);
                return;
            }
            string str = "";              //查询字符串

            if (m_BeRole)
            {
                //查询角色基本信息表
                // str = "select * from rolebaseinfo";  //定义查询字符串  3为系统管理员
                str = "select * from rolebaseinfo r join (select roletypeid from roletypeinfo ) t on (r.roletypeid=t.roletypeid) where t.roletypeid<> 3";
            }
            else
            {
                //查询用户基本信息表
                // str = "select * from userbaseinfo";//定义查询字符串  3为系统管理员
                str = "select * from userbaseinfo u join  userrolerelationinfo r on (u.userid=r.userid) join (select roleid,roletypeid from rolebaseinfo) b on (r.roleid=b.roleid) where b.roletypeid<>3";
            }
            //查询角色信息表
            DataTable pTable = pSysDB.GetSQLTable(str, out outError);

            if (outError != null || pTable == null)
            {
                SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "获取角色信息表失败");
                pSysDB.CloseDbConnection();
                m_beSuccedd = false;
                return;
            }
            for (int i = 0; i < pTable.Rows.Count; i++)
            {
                int          pRoleID   = Convert.ToInt32(pTable.Rows[i][0].ToString().Trim()); //角色ID
                string       pRoleName = pTable.Rows[i][1].ToString().Trim();                  //角色名称
                ListViewItem pItem     = new ListViewItem();
                pItem.Text    = pRoleName;
                pItem.Tag     = pRoleID;
                pItem.Checked = false;
                if (!LstViewRole.Items.Contains(pItem))
                {
                    LstViewRole.Items.Add(pItem);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// guozheng 2011-3-24 added 判断是不是第一次登陆(第一次登陆只有系统管理员,将系统管理员账号显示在界面上)
        /// </summary>
        private void JudgeInitialize()
        {
            Exception outError = null;

            SysCommon.DataBase.SysTable pSysDB = null;
            //连接数据库
            ModDBOperate.ConnectDB(out pSysDB, out outError);
            if (outError != null)
            {
                SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "连接Oracle数据库异常:" + outError.Message + "请检查Oracle数据库运行状态");
                return;
            }
            /////读取用户表,若只有一条记录则认为是系统管理员/////
            string    sSQL         = "SELECT * FROM userbaseinfo";
            DataTable GetUserTable = pSysDB.GetTable("userbaseinfo", out outError);

            if (GetUserTable.Rows.Count == 1)
            {
                ////////将系统管理员的信息显示在界面上////////
                this.txtUser.Text     = GetUserTable.Rows[0]["USERNAME"].ToString();
                this.txtPassword.Text = GetUserTable.Rows[0]["PASSWORD"].ToString();
            }
        }
Пример #3
0
        private void btnAddUser_Click(object sender, EventArgs e)
        {
            Exception exError = null;

            try
            {
                #region 进行界面控制
                if (txtComment.Text.Length > 200)
                {
                    ErrorHandle.ShowInform("提示", "备注内容太长!");
                    txtComment.Focus();
                    return;
                }
                if (txtTrueName.Text.IndexOf(" ") != -1)
                {
                    errorProvider.SetError(txtTrueName, "用户名不能有空格");
                    return;
                }
                //验证
                if (string.IsNullOrEmpty(this.txtTrueName.Text))
                {
                    errorProvider.SetError(txtTrueName, "用户真实名不能为空!");
                    return;
                }
                else if (string.IsNullOrEmpty(this.txtPassword.Text))
                {
                    errorProvider.SetError(txtPassword, "密码不能为空!");
                    return;
                }
                else if (this.comboSex.Text == "")
                {
                    errorProvider.SetError(comboSex, "请选择用户角色!");
                    return;
                }
                else if (this.comboSex.Text == "请选择")
                {
                    errorProvider.SetError(comboSex, "请选择性别!");
                    return;
                }
                else if (string.IsNullOrEmpty(this.txtPosition.Text))
                {
                    errorProvider.SetError(txtPosition, "姓名不能为空!");
                    return;
                }
                if (txtTrueName.Text == "Admin")
                {
                    ErrorHandle.ShowInform("提示", "此用户已存在,请重新输入!");
                    txtTrueName.Focus();
                    return;
                }
                #endregion

                //l连接系统维护库
                SysCommon.DataBase.SysTable pSysDB = null;
                ModDBOperate.ConnectDB(out pSysDB, out exError);
                if (exError != null)
                {
                    SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", exError.Message);
                    return;
                }

                #region 首先要判断用户名不能重复

                //用户名不能与超级管理员同名
                string[] arr = ModuleData.v_AppConnStr.Split(';');
                if (arr.Length != 3)
                {
                    SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "连接字符串不正确!");
                    return;
                }

                if (txtTrueName.Text.Trim() == arr[1].Substring(arr[1].IndexOf('=') + 1))
                {
                    SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "存在同名的用户!");
                    pSysDB.CloseDbConnection();
                    return;
                }

                //不能与数据库中的用户同名
                string    str        = "select * from userbaseinfo where USERNAME='******'";
                DataTable pUserTable = pSysDB.GetSQLTable(str, out exError);
                if (exError != null || pUserTable == null)
                {
                    SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "查询用户基本信息表失败!");
                    pSysDB.CloseDbConnection();
                    return;
                }

                #endregion

                //判断是更新还是添加
                if (_user != null)
                {
                    // (修改用户) 判断是否存在同名用户
                    if (pUserTable.Rows.Count > 1)
                    {
                        SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "存在同名的用户!");
                        pSysDB.CloseDbConnection();
                        return;
                    }

                    #region 用户修改,1、需要修改用户基本信息表,2、需要修改用户角色关系表,3、更新用户登录信息
                    pSysDB.StartTransaction();
                    //更新用户信息

                    #region 更新用户信息表
                    //若用户的基本信息发生了变更,则更新用户基本信息表
                    int    pUserID     = _user.ID; //用户ID
                    int    pRoleTypeID = _user.RoleTypeID;
                    string updateStr   = "";
                    if (m_UserName != txtTrueName.Text.Trim() || m_Password != txtPassword.Text.Trim() || comboSex.Text.Trim() != m_Sex || txtPosition.Text.Trim() != m_Position || txtComment.Text.Trim() != m_Remark)
                    {
                        //只要其中有一项基本信息发生了变化,就更injiben信息表
                        updateStr = "update userbaseinfo set UserName='******', Password='******', Sex='" + comboSex.Text.Trim() + "', Job='" + txtPosition.Text.Trim() + "', Remark='" + txtComment.Text.Trim() + "' where UserID=" + pUserID;
                        pSysDB.UpdateTable(updateStr, out exError);
                        if (exError != null)
                        {
                            SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "更新用户信息表失败!");
                            pSysDB.EndTransaction(false);
                            pSysDB.CloseDbConnection();
                            return;
                        }
                    }
                    #endregion
                    if (cmbRole.Text.Trim() != m_OldRoleName)
                    {
                        //说明用户对应的角色也进行了更新
                        #region 更新用户角色关系表
                        if ((cmbRole.SelectedItem as ComboBoxItem).Value == null || (cmbRole.SelectedItem as ComboBoxItem).Value.ToString().Trim() == "")
                        {
                            SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "获取角色ID失败!");
                            pSysDB.EndTransaction(false);
                            pSysDB.CloseDbConnection();
                            return;
                        }
                        int       pRoleID = -1; //角色ID  Convert.ToInt32((cmbRole.SelectedItem as ComboBoxItem).Value.ToString().Trim());
                        string    mStr    = "select * from rolebaseinfo where ROLENAME='" + cmbRole.Text.Trim() + "'";
                        DataTable tTable  = pSysDB.GetSQLTable(mStr, out exError);
                        if (exError != null || tTable == null)
                        {
                            SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "查询角色信息表失败!");
                            pSysDB.EndTransaction(false);
                            pSysDB.CloseDbConnection();
                            return;
                        }
                        if (tTable.Rows.Count == 0)
                        {
                            SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "获取角色ID失败!");
                            pSysDB.EndTransaction(false);
                            pSysDB.CloseDbConnection();
                            return;
                        }
                        pRoleID = Convert.ToInt32(tTable.Rows[0][0].ToString().Trim());
                        //首先查询用户角色关系表,看是否存在这个记录
                        //******************************************************************
                        //guozheng added 2011-3-24
                        string    sSQL     = "SELECT ROLEID FROM rolebaseinfo WHERE ROLETYPEID=" + _user.RoleTypeID;
                        DataTable GetTable = pSysDB.GetSQLTable(sSQL, out exError);
                        if (exError != null || GetTable == null)
                        {
                            SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "查询用户角色关系表失败!");
                            pSysDB.EndTransaction(false);
                            pSysDB.CloseDbConnection();
                            return;
                        }
                        if (GetTable.Rows.Count < 0)
                        {
                            SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "没有找到该用户对应的角色信息"); return;
                        }
                        //******************************************************************
                        string    tempStr  = "select * from userrolerelationinfo where ROLEID=" + GetTable.Rows[0][0].ToString() + " and USERID=" + pUserID;
                        DataTable temTable = pSysDB.GetSQLTable(tempStr, out exError);
                        if (exError != null || temTable == null)
                        {
                            SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "查询用户角色关系表失败!");
                            pSysDB.EndTransaction(false);
                            pSysDB.CloseDbConnection();
                            return;
                        }
                        if (temTable.Rows.Count == 0)
                        {
                            //若不存在,则插入关系记录
                            updateStr = "insert into userrolerelationinfo(USERID,ROLEID) values (" + pUserID + "," + pRoleID + ")";
                        }
                        else
                        {
                            //若存在,则更新关系记录
                            updateStr = "update userrolerelationinfo set ROLEID=" + pRoleID + " where USERID=" + pUserID;
                        }

                        pSysDB.UpdateTable(updateStr, out exError);
                        if (exError != null)
                        {
                            SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "更新用户角色关系表失败!");
                            pSysDB.EndTransaction(false);
                            pSysDB.CloseDbConnection();
                            return;
                        }
                        #endregion

                        //获得角色类型
                        tempStr  = "select * from rolebaseinfo where ROLEID=" + pRoleID;
                        temTable = pSysDB.GetSQLTable(tempStr, out exError);
                        if (exError != null || temTable == null)
                        {
                            SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "查询角色基本信息表失败!");
                            pSysDB.EndTransaction(false);
                            pSysDB.CloseDbConnection();
                            return;
                        }
                        if (temTable.Rows.Count == 0)
                        {
                            SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "不存在该角色");
                            pSysDB.EndTransaction(false);
                            pSysDB.CloseDbConnection();
                            return;
                        }
                        pRoleTypeID = Convert.ToInt32(temTable.Rows[0][2].ToString().Trim());
                    }

                    pSysDB.EndTransaction(true);
                    pSysDB.CloseDbConnection();
                    #region 更新用户登录信息
                    ModuleData.m_User            = new User();
                    ModuleData.m_User.ID         = pUserID;
                    ModuleData.m_User.Name       = txtTrueName.Text.Trim();
                    ModuleData.m_User.Password   = txtPassword.Text.Trim();
                    ModuleData.m_User.Sex        = comboSex.Text.Trim();
                    ModuleData.m_User.Position   = txtPosition.Text.Trim();
                    ModuleData.m_User.Remark     = txtComment.Text.Trim();
                    ModuleData.m_User.Role       = cmbRole.Text.Trim();
                    ModuleData.m_User.RoleTypeID = pRoleTypeID;
                    #endregion
                    SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "修改用户信息成功!");
                    #endregion
                }
                else
                {
                    //(新增用户)判断是否存在同名用户
                    if (pUserTable.Rows.Count > 0)
                    {
                        SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "存在同名的用户!");
                        pSysDB.CloseDbConnection();
                        return;
                    }
                    //添加用户信息
                    #region 添加用户,1、需要添加用户基本信息表,2、需要添加用户角色关系表
                    pSysDB.StartTransaction();

                    #region 获得用户ID
                    int       pUserID   = -1;
                    string    seleStr   = "select Max(UserID) from userbaseinfo";
                    DataTable tempTable = pSysDB.GetSQLTable(seleStr, out exError);
                    if (exError != null || tempTable == null)
                    {
                        SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "查询用户信息表失败!");
                        pSysDB.CloseDbConnection();
                        return;
                    }
                    if (tempTable.Rows.Count == 0)
                    {
                        pUserID = 1;
                    }
                    else
                    {
                        if (tempTable.Rows[0][0].ToString().Trim() == "")
                        {
                            pUserID = 1;
                        }
                        else
                        {
                            pUserID = Convert.ToInt32(tempTable.Rows[0][0].ToString().Trim()) + 1;
                        }
                    }
                    if (pUserID == -1)
                    {
                        SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "获取用户ID失败!");
                        return;
                    }
                    #endregion

                    #region 更新用户基本信息表
                    string insertStr = "insert into userbaseinfo(UserID,UserName,Password,Sex,Job,Remark) values(" + pUserID + ",'" + txtTrueName.Text.Trim() + "','" + txtPassword.Text.Trim() + "','" + comboSex.Text.Trim() + "','" + txtPosition.Text.Trim() + "','" + txtComment.Text.Trim() + "')";

                    pSysDB.UpdateTable(insertStr, out exError);
                    if (exError != null)
                    {
                        SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "更新用户表信息失败!");
                        pSysDB.EndTransaction(false);
                        pSysDB.CloseDbConnection();
                        return;
                    }
                    #endregion
                    #region 更新用户角色表

                    //获得角色ID
                    int pRoleID = -1;   //角色ID
                    if ((cmbRole.SelectedItem as ComboBoxItem).Value == null || (cmbRole.SelectedItem as ComboBoxItem).Value.ToString().Trim() == "")
                    {
                        SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "获取角色ID失败!");
                        pSysDB.EndTransaction(false);
                        pSysDB.CloseDbConnection();
                        return;
                    }
                    pRoleID = Convert.ToInt32((cmbRole.SelectedItem as ComboBoxItem).Value.ToString().Trim());

                    //插入数据到角色关系表里面
                    string inseStr = "insert into userrolerelationinfo(UserID,RoleID) values(" + pUserID + "," + pRoleID + ")";
                    pSysDB.UpdateTable(inseStr, out exError);
                    if (exError != null)
                    {
                        SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "更新用户角色关系表失败!");
                        pSysDB.EndTransaction(false);
                        pSysDB.CloseDbConnection();
                        return;
                    }
                    #endregion
                    pSysDB.EndTransaction(true);
                    pSysDB.CloseDbConnection();

                    SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示 ", "添加用户信息成功!");

                    #endregion
                }

                this.DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                exError = ex;
            }
        }
Пример #4
0
        /// <summary>
        /// chenyafei 20110311 add content:初始化界面
        /// </summary>
        private void InitilComboBox()
        {
            Exception outError = null;

            #region 初始化性别列表框
            ComboBoxItem item = new ComboBoxItem("男", 0);
            this.comboSex.Items.Add(item);
            item = new ComboBoxItem("女", 1);
            this.comboSex.Items.Add(item);
            this.comboSex.SelectedIndex = 0;
            #endregion

            #region 初始化角色列表框
            //连接系统维护库
            SysCommon.DataBase.SysTable pSysDB = null;
            ModDBOperate.ConnectDB(out pSysDB, out outError);
            if (outError != null)
            {
                SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", outError.Message);
                m_BeSuccedd = false;
                return;
            }
            //查询角色基本信息表
            string selStr = string.Empty;
            if (this._user == null)
            {
                selStr = "select * from rolebaseinfo WHERE rolebaseinfo.ROLETYPEID<>3";   //查询角色字符串,3为系统管理员角色,系统管理员角色不能添加
            }
            else
            {
                //cyf 20110602 delete
                //if (this._user.RoleTypeID==EnumRoleType.系统管理员.GetHashCode())
                //    selStr = "select * from rolebaseinfo";
                //else
                //    selStr = "select * from rolebaseinfo WHERE rolebaseinfo.ROLETYPEID<>3";
                //end
            }
            DataTable pTable = pSysDB.GetSQLTable(selStr, out outError);
            if (outError != null)
            {
                SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "查询角色基本信息表失败,原因:" + outError.Message);
                m_BeSuccedd = false;
                pSysDB.CloseDbConnection();
                return;
            }
            pSysDB.CloseDbConnection();
            //遍历表格记录,将角色信息加载到ComboBox中
            for (int i = 0; i < pTable.Rows.Count; i++)
            {
                string roleID   = "";   //角色ID
                string roleName = "";   //角色名称
                roleID   = pTable.Rows[i][0].ToString().Trim();
                roleName = pTable.Rows[i][1].ToString().Trim();
                ComboBoxItem pItem = new ComboBoxItem(roleName, roleID);
                cmbRole.Items.Add(pItem);
            }
            if (cmbRole.Items.Count > 0)
            {
                cmbRole.SelectedIndex = 0;
            }
            #endregion
        }
Пример #5
0
        // 登录系统
        private void btnOK_Click(object sender, EventArgs e)
        {
            Exception outError = null;

            //界面控制
            if (txtUser.Text.Trim() == "")
            {
                SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "用户名不能为空");
                return;
            }
            else if (txtPassword.Text.Trim() == "")
            {
                SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "密码不能为空");
                return;
            }

            if (ModuleData.v_AppConnStr.Trim() == "")
            {
                SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "连接字符串为空!");
                return;
            }
            string[] arr = ModuleData.v_AppConnStr.Split(';');
            if (arr.Length != 3)
            {
                SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "连接字符串不正确!");
                return;
            }
            ///////////////////////获取登陆的用户信息///////////////////
            #region 连接数据库
            SysCommon.DataBase.SysTable pSysDB = null;
            //连接数据库
            ModDBOperate.ConnectDB(out pSysDB, out outError);
            if (outError != null)
            {
                SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", outError.Message);
                return;
            }
            #endregion

            #region 查询用户基本信息表,用户和密码判断
            string    selStr    = "select * from userbaseinfo where UserName='******' and PASSWORD='******'";
            DataTable UserTable = pSysDB.GetSQLTable(selStr, out outError);
            if (outError != null || UserTable == null)
            {
                SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "查询用户基本信息表失败!");
                pSysDB.CloseDbConnection();
                return;
            }
            if (UserTable.Rows.Count == 0)
            {
                SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "无效的用户或者密码!");
                pSysDB.CloseDbConnection();
                return;
            }
            #endregion
            int    pUserID     = -1; //用户ID
            string pSex        = ""; //性别
            string pJob        = ""; //职称
            string pRemark     = ""; //备注
            string pRoleName   = ""; //角色名称
            int    pRoleTypeID = -1; //角色类型:1管理员、2作业员

            pUserID = Convert.ToInt32(UserTable.Rows[0][0].ToString().Trim());
            pSex    = UserTable.Rows[0][3].ToString().Trim();
            pJob    = UserTable.Rows[0][4].ToString().Trim();
            pRemark = UserTable.Rows[0][5].ToString().Trim();

            #region 查询用户角色
            string str = "select * from userrolerelationinfo inner join rolebaseinfo on UserID=" + pUserID + " and userrolerelationinfo.RoleID=rolebaseinfo.RoleID";
            //string str = "select * from userrolerelationinfo a inner join (select * from rolebaseinfo inner join roletypeinfo on rolebaseinfo.roletypeid=roletypeinfo.roletypeid) b on a.UserID=" + pUserID + "and a.RoleID=b.RoleID";

            DataTable pRoleRelTable = pSysDB.GetSQLTable(str, out outError);
            if (outError != null || pRoleRelTable == null)
            {
                SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "查询用户角色关系表失败!");
                pSysDB.CloseDbConnection();
                return;
            }
            if (pRoleRelTable.Rows.Count == 0)
            {
                pRoleName   = "";
                pRoleTypeID = -1;
            }
            else
            {
                pRoleName   = pRoleRelTable.Rows[0]["ROLENAME"].ToString().Trim();
                pRoleTypeID = Convert.ToInt32(pRoleRelTable.Rows[0]["ROLETYPEID"].ToString().Trim());  //角色类型ID
            }

            #endregion

            pSysDB.CloseDbConnection();

            //若用户和密码正确,则登录系统,保存用户相关信息

            m_User            = new SysCommon.Authorize.User();
            m_User.ID         = pUserID;
            m_User.Name       = this.txtUser.Text.Trim();
            m_User.Password   = this.txtPassword.Text.Trim();
            m_User.Sex        = pSex;
            m_User.Position   = pJob;
            m_User.Remark     = pRemark;
            m_User.Role       = pRoleName;
            m_User.RoleTypeID = pRoleTypeID;
            /////////////////////////////////////////////////////////////
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
Пример #6
0
        private void btnDelSel_Click(object sender, EventArgs e)
        {
            if (LstViewRole.CheckedItems.Count == 0)
            {
                return;
            }
            if (m_BeRole)
            {
                #region  除角色及其相关信息,1、删除角色用户关系表,2、删除角色表
                if (SysCommon.Error.ErrorHandle.ShowFrmInformation("是", "否", "是否删除选中角色及其对应的所有用户?"))
                {
                    //删除
                    SysCommon.DataBase.SysTable pSysDB = null;
                    Exception outError = null;
                    //连接数据库
                    ModDBOperate.ConnectDB(out pSysDB, out outError);
                    if (outError != null)
                    {
                        SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", outError.Message);
                        return;
                    }

                    //开启事物
                    pSysDB.StartTransaction();
                    //遍历列表框,执行删除操作
                    for (int i = 0; i < LstViewRole.Items.Count; i++)
                    {
                        int pRoleID = -1;//角色ID
                        //***********************************//
                        //guozheng added
                        if (pRoleID == 3)
                        {
                            SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "系统管理员角色:" + LstViewRole.Items[i].Text + " 不能删除"); continue;
                        }
                        ListViewItem pItem = new ListViewItem();
                        pItem = LstViewRole.Items[i];
                        if (!pItem.Checked)
                        {
                            continue;
                        }
                        pRoleID = Convert.ToInt32(pItem.Tag.ToString());
                        string delStr = "";   //删除字符串

                        //删除角色用户关系表
                        delStr = "delete from userrolerelationinfo where ROLEID=" + pRoleID;
                        pSysDB.UpdateTable(delStr, out outError);
                        if (outError != null)
                        {
                            SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "删除用户角色关系表失败!");
                            pSysDB.EndTransaction(false);
                            pSysDB.CloseDbConnection();
                            return;
                        }

                        //删除角色信息表
                        delStr = "delete from rolebaseinfo where ROLEID=" + pRoleID;
                        pSysDB.UpdateTable(delStr, out outError);
                        if (outError != null)
                        {
                            SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "删除角色信息表失败!");
                            pSysDB.EndTransaction(false);
                            pSysDB.CloseDbConnection();
                            return;
                        }
                    }

                    pSysDB.EndTransaction(true);
                    pSysDB.CloseDbConnection();

                    SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "删除成功!");
                }
                #endregion
            }
            else
            {
                #region  除用户及其相关信息,1、删除角色用户关系表,2、删除用户基本信息表
                if (SysCommon.Error.ErrorHandle.ShowFrmInformation("是", "否", "是否删除选中用户?"))
                {
                    //删除
                    SysCommon.DataBase.SysTable pSysDB = null;
                    Exception outError = null;
                    //连接数据库
                    ModDBOperate.ConnectDB(out pSysDB, out outError);
                    if (outError != null)
                    {
                        SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", outError.Message);
                        return;
                    }

                    //开启事物
                    pSysDB.StartTransaction();
                    //遍历列表框,执行删除操作
                    for (int i = 0; i < LstViewRole.Items.Count; i++)
                    {
                        int          pUserID = -1;//角色ID
                        ListViewItem pItem   = new ListViewItem();
                        pItem = LstViewRole.Items[i];
                        if (!pItem.Checked)
                        {
                            continue;
                        }
                        pUserID = Convert.ToInt32(pItem.Tag.ToString());
                        string delStr = "";   //删除字符串

                        //删除角色用户关系表
                        delStr = "delete from userrolerelationinfo where USERID=" + pUserID;
                        pSysDB.UpdateTable(delStr, out outError);
                        if (outError != null)
                        {
                            SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "删除用户角色关系表失败!");
                            pSysDB.EndTransaction(false);
                            pSysDB.CloseDbConnection();
                            return;
                        }
                        //删除该用户的作业分配区域
                        delStr = "delete from UPDATEINFO where USERID=" + pUserID;
                        pSysDB.UpdateTable(delStr, out outError);
                        if (outError != null)
                        {
                            SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "删除用户角色关系表失败!");
                            pSysDB.EndTransaction(false);
                            pSysDB.CloseDbConnection();
                            return;
                        }

                        //删除角色信息表
                        delStr = "delete from userbaseinfo where USERID=" + pUserID;
                        pSysDB.UpdateTable(delStr, out outError);
                        if (outError != null)
                        {
                            SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "删除角色信息表失败!");
                            pSysDB.EndTransaction(false);
                            pSysDB.CloseDbConnection();
                            return;
                        }
                    }

                    pSysDB.EndTransaction(true);
                    pSysDB.CloseDbConnection();
                    SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "删除成功!");
                }
                #endregion
            }

            this.Close();
        }
Пример #7
0
        /// <summary>
        /// 初始化角色类型列表框
        /// </summary>
        private void intialForm()
        {
            SysCommon.DataBase.SysTable pSysDB = null;
            Exception outError = null;

            //连接数据库
            ModDBOperate.ConnectDB(out pSysDB, out outError);
            if (outError != null)
            {
                SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", outError.Message);
                m_beSucced = false;
                return;
            }
            #region 初始化角色类型列表
            string selStr = "";                                         //初始化角色类型列表的字符串
            selStr = "select * from roletypeinfo WHERE ROLETYPEID<> 3"; //查询角色类型表,3为系统管理员
            DataTable pTable = pSysDB.GetSQLTable(selStr, out outError);
            if (outError != null)
            {
                SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "查询角色基本信息表失败,原因:" + outError.Message);
                pSysDB.CloseDbConnection();
                m_beSucced = false;
                return;
            }

            //遍历表格记录,将角色类型信息加载到ComboBox中
            for (int j = 0; j < pTable.Rows.Count; j++)
            {
                string roleID   = "";   //角色ID
                string roleName = "";   //角色类型名称
                roleID   = pTable.Rows[j][0].ToString().Trim();
                roleName = pTable.Rows[j][2].ToString().Trim();
                ComboBoxItem pItem = new ComboBoxItem(roleName, roleID);
                cmbGroupType.Items.Add(pItem);
            }
            if (cmbGroupType.Items.Count > 0)
            {
                cmbGroupType.SelectedIndex = 0;
            }
            #endregion

            if (m_BeUpdate)
            {
                #region 修改,初始化角色名列表框
                string    str       = "select * from rolebaseinfo where roletypeid<>3"; //查询角色类型表 3为系统管理员,不能修改
                DataTable RoleTable = pSysDB.GetSQLTable(str, out outError);
                if (outError != null || RoleTable == null)
                {
                    SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "查询角色基本信息表失败!");
                    pSysDB.CloseDbConnection();
                    m_beSucced = false;
                    return;
                }
                if (RoleTable.Rows.Count == 0)
                {
                    SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "还未添加过角色,请检查");
                    pSysDB.CloseDbConnection();
                    m_beSucced = false;
                    return;
                }
                for (int i = 0; i < RoleTable.Rows.Count; i++)
                {
                    int    pRoleID     = -1; //角色ID
                    string pRoleName   = ""; //角色名称
                    int    pRoleTypeID = -1; //角色类型ID
                    pRoleID     = Convert.ToInt32(RoleTable.Rows[i][0].ToString().Trim());
                    pRoleName   = RoleTable.Rows[i][1].ToString().Trim();
                    pRoleTypeID = Convert.ToInt32(RoleTable.Rows[i][2].ToString().Trim());
                    ComboBoxItem pItem = new ComboBoxItem(pRoleName, pRoleID);
                    cmbRoleName.Items.Add(pItem);
                }
                if (cmbRoleName.Items.Count > 0)
                {
                    cmbRoleName.SelectedIndex = 0;
                }
                #endregion
            }
            //else
            //{

            //}
            pSysDB.CloseDbConnection();
        }
Пример #8
0
        private void cmbRoleName_SelectedIndexChanged(object sender, EventArgs e)
        {
            //根据角色名称初始化角色类型

            txtRole.Text = cmbRoleName.Text.Trim();
            SysCommon.DataBase.SysTable pSysDB = null;
            Exception outError = null;

            //连接数据库
            ModDBOperate.ConnectDB(out pSysDB, out outError);
            if (outError != null)
            {
                SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", outError.Message);
                return;
            }

            string selStr = "";                                                                                                                                                                                                       //初始化角色类型列表的字符串

            selStr = "select * from roletypeinfo inner join rolebaseinfo on rolebaseinfo.ROLETYPEID=roletypeinfo.ROLETYPEID and rolebaseinfo.ROLEID=" + Convert.ToInt32((cmbRoleName.SelectedItem as ComboBoxItem).Value.ToString()); //查询角色类型表
            DataTable pTable = pSysDB.GetSQLTable(selStr, out outError);

            if (outError != null || pTable == null)
            {
                SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "查询角色类型表失败,原因:" + outError.Message);
                pSysDB.CloseDbConnection();
                return;
            }
            if (pTable.Rows.Count == 0)
            {
                SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "查询角色类型表失败,原因:" + outError.Message);
                pSysDB.CloseDbConnection();
                return;
            }
            //遍历表格记录,将角色类型信息加载到ComboBox中
            //for (int j = 0; j < pTable.Rows.Count; j++)
            //{
            string roleTypeID   = "";       //角色类型ID
            string roleTypeName = "";       //角色类型

            roleTypeID   = pTable.Rows[0]["ROLETYPEID"].ToString().Trim();
            roleTypeName = pTable.Rows[0]["ROLEREMARK"].ToString().Trim();
            //ComboBoxItem pItem = new ComboBoxItem(roleTypeName, roleTypeID);
            //cmbGroupType.SelectedItem = pItem;
            cmbGroupType.Text = roleTypeName;
            //cmbGroupType.Items.Add(pItem);
            //}
            //if (cmbGroupType.Items.Count > 0)
            //{
            //    cmbGroupType.SelectedIndex = 0;
            //}

            //初始化备注列表框
            selStr = "select * from rolebaseinfo where ROLEID=" + Convert.ToInt32((cmbRoleName.SelectedItem as ComboBoxItem).Value.ToString().Trim());
            pTable = pSysDB.GetSQLTable(selStr, out outError);
            if (outError != null || pTable == null)
            {
                SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "查询角色类型表失败,原因:" + outError.Message);
                pSysDB.CloseDbConnection();
                return;
            }
            if (pTable.Rows.Count == 0)
            {
                SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "该用户不存在!");
                pSysDB.CloseDbConnection();
                return;
            }
            txtComment.Text = pTable.Rows[0][3].ToString().Trim();

            pSysDB.CloseDbConnection();
        }
Пример #9
0
        private void btnAddRole_Click(object sender, EventArgs e)
        {
            Exception pError = null;

            try
            {
                #region 对界面进行控制
                if (txtComment.Text.Length >= 200)
                {
                    ErrorHandle.ShowFrmErrorHandle("提示", "备注内容太长!");
                    return;
                }
                if (string.IsNullOrEmpty(this.txtRole.Text.Trim()))
                {
                    ErrorHandle.ShowFrmErrorHandle("提示", "用户组名不能为空!");
                    return;
                }
                if (txtRole.Text.IndexOf(" ") != -1)
                {
                    errorProvider1.SetError(txtRole, "组名不能有空格");
                    return;
                }

                #endregion

                SysCommon.DataBase.SysTable pSysDB = null;
                //连接系统维护库
                ModDBOperate.ConnectDB(out pSysDB, out pError);
                if (pError != null)
                {
                    SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", pError.Message);
                    return;
                }
                int pRoleID     = -1;   //角色ID
                int pRoleTypeID = -1;   //角色类型ID
                pRoleTypeID = Convert.ToInt32((cmbGroupType.SelectedItem as ComboBoxItem).Value.ToString());
                if (pRoleTypeID == -1)
                {
                    SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "获取角色类型ID失败!");
                    pSysDB.CloseDbConnection();
                    return;
                }

                //判断是否存在同名的角色
                string    tempStr = "select * from rolebaseinfo where ROLENAME='" + txtRole.Text.Trim() + "'";
                DataTable mTable  = pSysDB.GetSQLTable(tempStr, out pError);
                if (pError != null || mTable == null)
                {
                    SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "查询角色基本信息表失败");
                    pSysDB.CloseDbConnection();
                    return;
                }


                if (m_BeUpdate)
                {
                    //判断是否存在同名角色
                    if (mTable.Rows.Count > 1)
                    {
                        SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "存在同名的角色!");
                        pSysDB.CloseDbConnection();
                        return;
                    }
                    #region 对界面进行控制,角色名称保护
                    if (string.IsNullOrEmpty(cmbRoleName.Text.Trim()))
                    {
                        ErrorHandle.ShowFrmErrorHandle("提示", "用户组名不能为空!");
                        return;
                    }
                    if (cmbRoleName.Text.Trim().IndexOf(" ") != -1)
                    {
                        errorProvider1.SetError(txtRole, "组名不能有空格");
                        return;
                    }

                    #endregion

                    //判断是否存在同名的角色
                    //if (cmbRoleName.Items.Contains(txtRole.Text.Trim()))
                    //{
                    //    SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "存在同名的角色!");
                    //    pSysDB.CloseDbConnection();
                    //    return;
                    //}

                    #region 修改角色信息,更新角色基本信息表

                    pRoleID = Convert.ToInt32((cmbRoleName.SelectedItem as ComboBoxItem).Value.ToString().Trim());
                    string updateStr = "update rolebaseinfo set ROLENAME='" + txtRole.Text.Trim() + "', ROLETYPEID=" + pRoleTypeID + ", REMARK='" + txtComment.Text.Trim() + "' where ROLEID=" + pRoleID;
                    pSysDB.UpdateTable(updateStr, out pError);
                    if (pError != null)
                    {
                        SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "修改角色基本信息表失败!");
                        pSysDB.CloseDbConnection();
                        return;
                    }
                    pSysDB.CloseDbConnection();

                    SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "修改角色信息成功!");
                    #endregion
                }
                else
                {
                    //判断是否存在同名角色
                    if (mTable.Rows.Count > 0)
                    {
                        SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "存在同名的角色!");
                        pSysDB.CloseDbConnection();
                        return;
                    }
                    #region 添加角色信息,往角色表里面插入记录

                    //查询角色ID的最大值
                    string    selStr    = "select Max(ROLEID) from rolebaseinfo";
                    DataTable tempTable = pSysDB.GetSQLTable(selStr, out pError);
                    if (pError != null || tempTable == null)
                    {
                        SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "查询角色基本信息表失败");
                        pSysDB.CloseDbConnection();
                        return;
                    }
                    if (tempTable.Rows.Count == 0)
                    {
                        pRoleID = 1;
                    }
                    else
                    {
                        if (tempTable.Rows[0][0].ToString().Trim() == "")
                        {
                            //SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "获取角色类型ID失败!");
                            //pSysDB.CloseDbConnection();
                            //return;
                            pRoleID = 1;
                        }
                        else
                        {
                            pRoleID = Convert.ToInt32(tempTable.Rows[0][0].ToString()) + 1;
                        }
                    }
                    if (pRoleID == -1)
                    {
                        SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "获取角色ID失败!");
                        return;
                    }
                    string str = "insert into rolebaseinfo(ROLEID,ROLENAME,ROLETYPEID,REMARK) values (";
                    str += pRoleID + ",'" + txtRole.Text.Trim() + "'," + pRoleTypeID + ",'" + txtComment.Text.Trim() + "')";
                    //更新数据库
                    pSysDB.UpdateTable(str, out pError);
                    if (pError != null)
                    {
                        SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "更新角色基本信息表失败!");
                        pSysDB.CloseDbConnection();
                        return;
                    }
                    pSysDB.CloseDbConnection();

                    SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "添加角色成功!");
                    #endregion
                }
                this.DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
            }
        }