Exemple #1
0
        public HttpResponseMessage Get(dynamic param)
        {
            ResponseMessage responseMsg = new ResponseMessage(0);

            try
            {
                Dictionary <string, object> dictParams = GetDictionary(param);
                string userName = GetDictValue(dictParams, "userName");
                if (string.IsNullOrEmpty(userName))
                {
                    return(GenernateErrorMsg("用户名不能为空!"));
                }


                #region

                ST_USER_DAL dal   = new ST_USER_DAL();
                ST_USER     model = dal.getEntity(userName);
                responseMsg.message = model;

                #endregion
            }
            catch (Exception ex)
            {
                responseMsg.status  = -1;
                responseMsg.message = ex.Message;
                LogHelper.LogErrorMsg(ex, MethodBase.GetCurrentMethod().Name);
            }

            return(ToJson(responseMsg));
        }
Exemple #2
0
        public HttpResponseMessage Add(dynamic param)
        {
            ResponseMessage responseMsg = new ResponseMessage(0);

            if (null == param)
            {
                return(GenernateErrorMsg("请求参数不能为空!"));
            }

            try
            {
                Dictionary <string, object> dictParams = GetDictionary(param);

                //TODO  必填字段判断,其他字段略
                string userName = GetDictValueNotEmpty(dictParams, "userName");

                //系统用户信息
                ST_USER model = JsonHelper.Json2Object <ST_USER>(JsonHelper.Object2Json(dictParams));

                ST_USER_DAL dal = new ST_USER_DAL();

                //查询是否已经有对应名称的用户
                //注意,此处userName为主键,因此直接使用getEntity
                ST_USER oldEntity = dal.getEntity(userName.Trim());
                if (null != oldEntity)
                {
                    return(GenernateErrorMsg("该用户名已存在!"));
                }

                //TODO  其他信息校验

                #region

                //添加用户信息,返回影响的行数
                int cnt = dal.add(model);
                responseMsg.message = cnt;

                #region  添加日志记录

                //TODO  添加操作日志

                #endregion

                #endregion
            }
            catch (Exception ex)
            {
                responseMsg.status  = -1;
                responseMsg.message = ex.Message;
                LogHelper.LogErrorMsg(ex, MethodBase.GetCurrentMethod().Name);
            }

            return(ToJson(responseMsg));
        }
Exemple #3
0
        private void btn_login_Click(object sender, EventArgs e)
        {
            string str = string.Empty;

            foreach (ST_USER user_temp in list_user)
            {
                if (tb_pw.Text == user_temp.password && cb_user.Text == user_temp.name)
                {
                    cur_user = user_temp;
                    switch (cur_user.pms)
                    {
                    case PERMISSION.SuperAdmin:
                        str = "超级管理员";
                        break;

                    case PERMISSION.Admin:
                        str = "管理员";
                        break;

                    case PERMISSION.Engineer:
                        str = "工程师";
                        break;

                    case PERMISSION.Operator:
                        str = "作业员";
                        break;

                    case PERMISSION.None:
                        str = "无权限";
                        break;

                    default:
                        str = "无权限";
                        break;
                    }
                    cur_user.bUpdate  = true;
                    lb_log_inf.Text   = cur_user.name + "登陆成功";
                    lb_grade_inf.Text = "用户级别为:" + str;
                    //更新界面
                    if (Width == pnl_log.Width + pnl_log.Margin.Left * 2 + pnl_manager.Width + pnl_manager.Margin.Left * 2)
                    {
                        Width = pnl_log.Width + pnl_log.Margin.Left * 2;
                        Width = pnl_log.Width + pnl_log.Margin.Left * 2 + pnl_manager.Width + pnl_manager.Margin.Left * 2;
                    }
                    LoadFromFile();
                    return;
                }
            }
            Width             = pnl_log.Width + pnl_log.Margin.Left * 2;
            lb_log_inf.Text   = cb_user.Text + "登陆失败,密码错误!";
            lb_grade_inf.Text = String.Empty;
        }
Exemple #4
0
        private void FillTable(ST_USER user, int row = -2)
        {
            if (user.name.Length < 3 || user.password.Length < 3)
            {
                return;
            }
            //if empty or add mode then add
            if (dgv.Rows.Count == 0 || row == -2)
            {
                row = dgv.Rows.Add();
            }
            //the last row
            else if (row < 0)
            {
                row = dgv.Rows.Count - 1;
            }

            dgv.Rows[row].Cells[0].Value = row + 1;
            dgv.Rows[row].Cells[1].Value = user.name;
            dgv.Rows[row].Cells[2].Value = user.password;

            string str = "无权限";

            switch (user.pms)
            {
            case PERMISSION.SuperAdmin:
                str = "超级管理员";
                break;

            case PERMISSION.Admin:
                str = "管理员";
                break;

            case PERMISSION.Engineer:
                str = "工程师";
                break;

            case PERMISSION.Operator:
                str = "作业员";
                break;

            case PERMISSION.None:
                str = "无权限";
                break;

            default:
                str = "无权限";
                break;
            }
            dgv.Rows[row].Cells[3].Value = str;
        }
Exemple #5
0
        public HttpResponseMessage Update(dynamic param)
        {
            ResponseMessage responseMsg = new ResponseMessage(0);

            if (null == param)
            {
                return(GenernateErrorMsg("请求参数不能为空!"));
            }

            try
            {
                Dictionary <string, object> dictParams = GetDictionary(param);
                //用户信息
                ST_USER model = JsonHelper.Json2Object <ST_USER>(JsonHelper.Object2Json(param));

                //TODO  必填字段判断,其他字段略
                string userName = GetDictValueNotEmpty(dictParams, "userName");

                ST_USER_DAL dal       = new ST_USER_DAL();
                ST_USER     oldEntity = dal.getEntity(userName);

                if (null == oldEntity)
                {
                    return(GenernateErrorMsg("要更新的记录不存在!"));
                }

                //TODO 其他字段校验

                //更新用户信息,返回影响的行数
                responseMsg.message = dal.update(model);

                #region

                #region 添加日志记录

                //TODO  添加操作日志

                #endregion

                #endregion
            }
            catch (Exception ex)
            {
                responseMsg.status  = -1;
                responseMsg.message = ex.Message;
                LogHelper.LogErrorMsg(ex, MethodBase.GetCurrentMethod().Name);
            }
            return(ToJson(responseMsg));
        }
Exemple #6
0
        public HttpResponseMessage Delete(dynamic param)
        {
            ResponseMessage responseMsg = new ResponseMessage(0);

            if (null == param)
            {
                return(GenernateErrorMsg("请求参数不能为空!"));
            }

            try
            {
                Dictionary <string, object> dictParams = GetDictionary(param);
                string userName = GetDictValueNotEmpty(dictParams, "userName");

                ST_USER_DAL dal       = new ST_USER_DAL();
                ST_USER     oldEntity = dal.getEntity(userName);

                if (null == oldEntity)
                {
                    return(GenernateErrorMsg("要删除的记录不存在!"));
                }

                //TODO  根据实际需要删除,一般做假删除操作,如果是真删除,需要删除与之相应的其他关联信息(此时需要使用事物操作)

                //删除用户信息,返回影响的行数
                responseMsg.message = dal.delete(userName);

                #region

                #region 添加日志记录

                //TODO  添加操作日志

                #endregion

                #endregion
            }
            catch (Exception ex)
            {
                responseMsg.status  = -1;
                responseMsg.message = ex.Message;
                LogHelper.LogErrorMsg(ex, MethodBase.GetCurrentMethod().Name);
            }

            return(ToJson(responseMsg));
        }
Exemple #7
0
        public bool SaveToFile(string filename = "\\syscfg\\user.bin")
        {
            filename = Path.GetFullPath("..") + filename;
            List <ST_USER> list_temp = new List <ST_USER>();

            list_temp.Clear();
            //检查表格内是否有重复用户名
            foreach (DataGridViewRow v in dgv.Rows)
            {
                if (v.Cells[1].Value != null)
                {
                    var count = 0;
                    foreach (DataGridViewRow v2 in dgv.Rows)
                    {
                        if (v2.Cells[1].Value != null)
                        {
                            if (v.Cells[1].Value.ToString().Equals(v2.Cells[1].Value.ToString()))
                            {
                                count++;
                            }
                        }
                    }
                    if (count > 1)
                    {
                        MessageBox.Show("用户名有重复,重复的内容是:【" + v.Cells[1].Value + "】!");
                        return(false);
                    }
                }
            }

            //检查表格是否有两个超级管理员
            foreach (DataGridViewRow v in dgv.Rows)
            {
                if (v.Cells[3].Value.ToString().Equals("超级管理员"))
                {
                    if (v.Index != 0)
                    {
                        MessageBox.Show("第一个用户为超级管理员,其它超级管理员降级为管理员!");
                        v.Cells[3].Value = "管理员";
                    }
                }
            }

            foreach (DataGridViewRow row in dgv.Rows)
            {
                if (row.Cells[1].Value.ToString().Length < 3 || row.Cells[2].Value.ToString().Length < 3)
                {
                    continue;
                }
                ST_USER user = new ST_USER();
                user.name     = row.Cells[1].Value.ToString();
                user.password = row.Cells[2].Value.ToString();
                switch (row.Cells[3].Value.ToString())
                {
                case "超级管理员":
                    user.pms = PERMISSION.SuperAdmin;
                    break;

                case "管理员":
                    user.pms = PERMISSION.Admin;
                    break;

                case "工程师":
                    user.pms = PERMISSION.Engineer;
                    break;

                case "作业员":
                    user.pms = PERMISSION.Operator;
                    break;

                case "无权限":
                default:
                    user.pms = PERMISSION.None;
                    break;
                }
                list_temp.Add(user);
            }
            if (list_temp.Count == 0)
            {
                return(false);
            }

            //save
            list_user = list_temp;
            StreamWriter writer1 = new StreamWriter(filename, false, System.Text.Encoding.GetEncoding("UTF-8"));

            foreach (ST_USER user in list_temp)
            {
                writer1.WriteLine(user.ToString());
            }
            writer1.Close();
            writer1.Dispose();
            return(true);
        }
Exemple #8
0
        public bool LoadFromFile(string filename = "\\syscfg\\user.bin")
        {
            List <ST_USER> list_temp = new List <ST_USER>();

            list_temp.Clear();
            //read
            filename = Path.GetFullPath("..") + filename;
            if (File.Exists(filename))
            {
                StreamReader reader1 = new StreamReader(filename, System.Text.Encoding.GetEncoding("UTF-8"));
                while (true)
                {
                    string str = reader1.ReadLine();
                    if (str == null)
                    {
                        break;
                    }
                    ST_USER user = new ST_USER();
                    if (user.FromString(str))
                    {
                        list_temp.Add(user);
                    }
                }
                reader1.Close();
                reader1.Dispose();
            }
            else
            {
                ST_USER user = new ST_USER();
                user.FromString("超级管理员,12345678,SuperAdmin");
                list_temp.Add(user);

                user = new ST_USER();
                user.FromString("管理员,1234567,Admin");
                list_temp.Add(user);

                user = new ST_USER();
                user.FromString("工程师,123456,Engineer");
                list_temp.Add(user);

                user = new ST_USER();
                user.FromString("作业员,123456,Operator");
                list_temp.Add(user);
            }

            if (list_temp.Count == 0)
            {
                return(false);
            }
            list_user = list_temp;
            string cb_user_text = cb_user.Text;

            cb_user_text = cb_user.Text;
            cb_user.Items.Clear();
            foreach (ST_USER user_temp in list_user)
            {
                cb_user.Items.Add(user_temp.name);
                if (cb_user_text == user_temp.name)
                {
                    cb_user.Text = cb_user_text;
                }
            }
            if (cur_user.name == "超级管理员" && cur_user.pms == PERMISSION.SuperAdmin)
            {
                btn_add.Visible  = true;
                btn_dele.Visible = true;
                btn_add.Enabled  = true;
                btn_dele.Enabled = true;
            }
            else
            {
                btn_add.Visible  = false;
                btn_dele.Visible = false;
                btn_add.Enabled  = false;
                btn_dele.Enabled = false;
            }
            UpdateShow();
            return(true);
        }