Esempio n. 1
0
        protected override void BtnOK_Click(object sender, EventArgs e)
        {
            int    iFlag       = cbFlag.SelectedIndex - 1;
            string strUserName = txtUserName.Text.Trim();
            string strPassword = txtPassword.Text.Trim();
            string strMemo     = txtMemo.Text.Trim();

            if (iFlag == -1 || strUserName.Equals("") || strPassword.Equals(""))
            {
                CMessageBox.ShowError("角色、用户名和密码都必须输入!", Config.DialogTitle);
                return;
            }

            if (MessageBox.Show("确定要保存吗?", Config.DialogTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
            {
                return;
            }

            Model.UserInfo objModel = new Model.UserInfo()
            {
                Flag     = iFlag,
                ID       = this._CurrentID,
                UserName = strUserName,
                UserPwd  = (this._CurrentAction.Equals(EAction.Create)) ? Functions.Md5_32(strPassword) : ((strPassword.Equals(this._OriginalPassword) ? this._OriginalPassword : Functions.Md5_32(strPassword))),
                Memo     = strMemo
            };
            string strErrorInfo = "";

            IDAL.IUserInfo objDAL = DALFactory.DALFactory.UserInfo();
            if (this._CurrentAction.Equals(EAction.Create))
            {
                int iNewID = objDAL.Add(objModel, out strErrorInfo);
                if (iNewID <= 0)
                {
                    CMessageBox.ShowError(string.Format("创建用户失败,错误如下:\r\n{0}!", strErrorInfo), Config.DialogTitle);
                    return;
                }
            }
            else
            {
                bool bIfSucc = objDAL.Update(objModel, out strErrorInfo);
                if (!bIfSucc)
                {
                    CMessageBox.ShowError(string.Format("修改用户失败,错误如下:\r\n{0}!", strErrorInfo), Config.DialogTitle);
                    return;
                }
            }
            this.DialogResult = DialogResult.OK;
        }
Esempio n. 2
0
        /// <summary>
        /// 删除数据
        /// </summary>
        /// <param name="selectedItems)">当前选择的所有项</param>
        protected override void OnDelete(ListView.SelectedListViewItemCollection selectedItems)
        {
            if (MessageBox.Show("确定要删除当前选择的用户吗?", Config.DialogTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
            {
                return;
            }

            int iSuccNum  = 0;
            int iFaultNum = 0;

            foreach (ListViewItem selectedItem in selectedItems)
            {
                UserInfo       objModel = (UserInfo)selectedItem.Tag;
                IDAL.IUserInfo objDal   = DALFactory.DALFactory.UserInfo();
                if (objDal.Delete(objModel.ID))
                {
                    iSuccNum++;
                }
                else
                {
                    iFaultNum++;
                }
            }

            if (iSuccNum > 0)
            {
                //重新刷新列表
                BindLVData(0, this.CurrentSqlWhere);
            }
            if (iSuccNum == 0)
            {
                CMessageBox.ShowError("对不起,删除失败!", Config.DialogTitle);
            }
            else if (iFaultNum == 0)
            {
                CMessageBox.ShowSucc("恭喜您,删除成功!", Config.DialogTitle);
            }
            else
            {
                CMessageBox.ShowSucc(string.Format("{0}个删除成功,{1}个删除失败", iSuccNum, iFaultNum), Config.DialogTitle);
            }
        }
Esempio n. 3
0
        private void UserViewForm_Load(object sender, EventArgs e)
        {
            cbFlag.Items.Add("请选择角色");
            cbFlag.Items.Add("超级管理员");
            cbFlag.Items.Add("普通管理员");
            cbFlag.SelectedIndex = this._CurrentFlag + 1;

            //获得数据
            if (this._CurrentAction.Equals(EAction.Edit))
            {
                IDAL.IUserInfo objUser  = DALFactory.DALFactory.UserInfo();
                Model.UserInfo objModel = objUser.GetModel(this._CurrentID);
                if (objModel != null)
                {
                    cbFlag.SelectedIndex   = objModel.Flag + 1;
                    txtUserName.Text       = objModel.UserName;
                    this._OriginalPassword = objModel.UserPwd;
                    txtPassword.Text       = this._OriginalPassword;
                    txtMemo.Text           = objModel.Memo;
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// 绑定数据到列表
        /// </summary>
        /// <param name="selNum">数据条数</param>
        /// <param name="sqlWhereAndOrderBy">条件</param>
        protected override void BindLVData(int selNum = 0, string sqlWhereAndOrderBy = null)
        {
            this.lvContent.BeginUpdate();
            this.lvContent.Items.Clear();
            try
            {
                if (selNum <= 0)
                {
                    selNum = this.DefaultPageSize;
                }
                if (string.IsNullOrEmpty(sqlWhereAndOrderBy) || sqlWhereAndOrderBy.Equals(""))
                {
                    sqlWhereAndOrderBy = string.Format("ID <> 1 AND ID<>{0}", this.CurrentUserInfo.ID);
                }
                this.CurrentSqlWhere = sqlWhereAndOrderBy;

                IDAL.IUserInfo   objDal   = DALFactory.DALFactory.UserInfo();
                IList <UserInfo> listData = objDal.GetListByWhere(selNum, sqlWhereAndOrderBy);
                if (!(listData == null || listData.Count <= 0))
                {
                    foreach (UserInfo model in listData)
                    {
                        //序号,60|用户名,100|级别,180|备注,300
                        ListViewItem item = new ListViewItem(new string[] { Convert.ToString(this.lvContent.Items.Count + 1), model.UserName, model.FlagDesc, model.Memo })
                        {
                            Tag  = model,
                            Font = new Font("宋体", 9, FontStyle.Regular)
                        };
                        this.lvContent.Items.Add(item);
                    }
                }
            }
            catch (Exception)
            {
            }
            this.lvContent.EndUpdate();
        }