Esempio n. 1
0
        public string savehf(IFormCollection collection)
        {
            yjfk yjfk = new yjfk();

            try {
                if (ModelState.IsValid)
                {
                    var model = HttpContext.Session.Get("CurrentUser");                    //获取session
                    if (model == null)
                    {
                        return("nologin");
                    }
                    else
                    {
                        string hex          = System.Text.Encoding.Default.GetString(model);    //获取json数据
                        ry     sta          = JsonConvert.DeserializeObject <ry>(hex);          //转换成model数据
                        var    updateResult = TryUpdateModelAsync <yjfk>(yjfk);
                        yjfk.ry_id   = sta.id;
                        yjfk.status  = 0;
                        yjfk.hf_time = DateTime.Now;
                        yjfkRepository.AddData(yjfk);
                        return("success");
                    }
                }
                return("fail");
            }
            catch (Exception ex) {
                return("fail");
            }
        }
Esempio n. 2
0
		public string htlogin()
		{
			ry ry = new ry();
			var updateResult = TryUpdateModelAsync<ry>(ry);
			if (ModelState.IsValid)
			{
				//检查用户信息
				var user = ryRepository.Check(ry.yhm, ry.mm);
				if (user != null)
				{
					HttpContext.Session.Clear();
					//记录session
					HttpContext.Session.Set("CurrentUser", ByteConvertHelper.Object2Bytes(user));
					HttpContext.Session.Set("CurrentUserModel", ByteConvertHelper.Object2Bytes(ry));

					return "success";
				}
				else
				{
					return "用户名或密码错误需要修改";
				}
			}
			foreach (var key in ModelState.Keys)
			{
				if (ModelState[key].Errors.Count > 0)
				{
					ViewBag.ErrorInfo = JsonConvert.SerializeObject(new { Key = key, ErrorMessage = ModelState[key].Errors[0].ErrorMessage });
					break;
				}
			}
			return "fail";
		}
Esempio n. 3
0
        private void tsbRYSave_Click(object sender, EventArgs e)
        {
            if ((dgvRY.SelectedRows.Count < 1) || (txtID.Text == ""))
            {
                Dlg.ShowErrorInfoAndHelp("请先选择要保存的用户");
                return;
            }
            if (txtLoginName.Text.Trim() == string.Empty)
            {
                toolTip1.Show("登录名不能为空", txtLoginName, 0, txtLoginName.Height, 2000);
                return;
            }
            if (txtUserName.Text.Trim() == string.Empty)
            {
                toolTip1.Show("姓名不能为空", txtUserName, 0, txtUserName.Height, 2000);
                return;
            }
            ry ry = new ry();

            ry.ID        = Convert.ToInt64(txtID.Text);
            ry.LoginName = txtLoginName.Text;
            ry.UserName  = txtUserName.Text.Trim();

            ry.AreaCode        = txtAreaCode.Text.Trim();
            ry.IntDepartmentID = Convert.ToInt32(cmbDepart.SelectedValue);
            ry.IntRoleID       = Convert.ToInt32(cmbRole.SelectedValue);

            ry.DepartmentName = cmbDepart.Text.Trim(); //部门名称
            ry.OperRight      = cmbRole.Text.Trim();   //权限名称


            int ret = Convert.ToInt32(SqlHelper.ExecuteScalar(string.Format("select count(1) from t_users where loginName='{0}' and id <> {1}", ry.LoginName, ry.ID)));

            if (ret > 0)
            {
                toolTip1.Show("该登陆名已存在,请重新输入", txtLoginName, 0, txtLoginName.Height, 2000);
                txtLoginName.Focus();
                return;
            }


            if ((ry.LoginName.ToLower() == "admin"))
            {
                Dlg.ShowErrorInfoAndHelp("员工admin不允许修改!");
                return;
            }

            //string mSql = string.Format("update t_users set loginName='{0}',UserName='******',userChar='{2}',intdepartmentID='{3}',IntRoleID={4} where id='{5}'", ry.LoginName, ry.UserName, ry.AreaCode,ry.IntDepartmentID,ry.IntRoleID,ry.ID);

            //添加部门名称和权限名称字段
            string mSql = string.Format("update t_users set loginName='{0}',UserName='******',userChar='{2}',intdepartmentID='{3}',IntRoleID={4},DepartmentName='{6}',OperRight='{7}' where id='{5}'", ry.LoginName, ry.UserName, ry.AreaCode, ry.IntDepartmentID, ry.IntRoleID, ry.ID, ry.DepartmentName, ry.OperRight);

            ret = SqlHelper.ExecuteNonQuery(mSql);
            if (ret > 0)
            {
                InitRY();
                SelectRow(ry.ID);
                Dlg.ShowOKInfo("修改成功!");
            }
        }
Esempio n. 4
0
        public ActionResult SaveNews(IFormCollection collection)
        {
            tzb news = new tzb();
            Tuple <tzb, attach> Models = Tuple.Create(new tzb(), new attach());
            var model = HttpContext.Session.Get("CurrentUser");            //获取session

            if (model == null)
            {
                return(Success("/qian/USER/Login"));
            }
            try
            {
                if (ModelState.IsValid)
                {
                    var updateResult = TryUpdateModelAsync <Tuple <tzb, attach> >(Models);                   //将传递过来的对象转换
                    news = Models.Item1;
                    using (var db = tzbRepository.Connection)
                    {
                        string            hex      = System.Text.Encoding.Default.GetString(model); //获取json数据
                        ry                sta      = JsonConvert.DeserializeObject <ry>(hex);       //转换成model数据
                        string            userID   = sta.id;
                        string            userName = sta.yhm;
                        FTPHelper         ftps     = new FTPHelper(_FtpConnection.Value.FtpServerIP, _FtpConnection.Value.FtpRemotePath + "/" + news.id, _FtpConnection.Value.FtpUserID, _FtpConnection.Value.FtpPassword);
                        List <FileStruct> files    = ftps.GetFileAndDirectoryList(_FtpConnection.Value.FtpRemotePath + "/tbz/" + news.id + "/");

                        if (files != null)
                        {
                            foreach (var file in files)
                            {
                                attach attach = new attach();
                                attach.tp_name     = file.Name;
                                attach.yw_id       = news.id;
                                attach.create_time = DateTime.Now;
                                attach.tp_lj       = _FtpConnection.Value.FtpRemotePath + "/tbz/" + news.id;
                                attachRepository.AddFile(attach, userName, attach.tp_name);
                            }
                        }

                        tzbRepository.AddNews(news, userName);
                        if (news.TSTATUS == 0)
                        {
                            return(Success("保存成功。"));
                        }
                        else
                        {
                            return(Success("未插入成功。"));
                        }
                    }
                }
                else
                {
                    return(View());
                }
            }
            catch (Exception ex)
            {
                return(Error("保存数据库出错"));
            }
        }
Esempio n. 5
0
        private void tsbRYAdd_Click(object sender, EventArgs e)
        {
            TrimTextBox();
            if (txtLoginName.Text.Trim() == string.Empty)
            {
                toolTip1.Show("登录名不能为空", txtLoginName, 0, txtLoginName.Height, 2000);
                return;
            }
            if (txtUserName.Text.Trim() == string.Empty)
            {
                toolTip1.Show("姓名不能为空", txtUserName, 0, txtUserName.Height, 2000);
                return;
            }



            ry ry = new ry();

            ry.LoginName       = txtLoginName.Text.Trim();
            ry.UserName        = txtUserName.Text.Trim();
            ry.AreaCode        = txtAreaCode.Text.Trim();
            ry.IntDepartmentID = Convert.ToInt32(cmbDepart.SelectedValue);
            ry.IntRoleID       = Convert.ToInt32(cmbRole.SelectedValue);

            ry.DepartmentName = cmbDepart.Text.Trim(); //部门名称
            ry.OperRight      = cmbRole.Text.Trim();   //权限名称

            int ret = Convert.ToInt32(SqlHelper.ExecuteScalar(string.Format("select count(1) from t_users where loginName='{0}'", ry.LoginName)));

            if (ret > 0)
            {
                toolTip1.Show("该登陆名已存在,请重新输入", txtLoginName, 0, txtLoginName.Height, 2000);
                txtLoginName.Focus();
                return;
            }

            // string mSql = string.Format("insert into t_users(loginname,UserName,userChar,IntDepartmentID,IntRoleID,userstatus,PassWord) values ('{0}','{1}','{2}',{3},{4},'正常','{5}')", ry.LoginName, ry.UserName, ry.AreaCode, ry.IntDepartmentID, ry.IntRoleID, MD5.Md5Encrypt("1"));

            //添加部门名称和权限名称
            string mSql = string.Format("insert into t_users(loginname,UserName,userChar,IntDepartmentID,IntRoleID,userstatus,PassWord,DepartmentName,OperRight) values ('{0}','{1}','{2}',{3},{4},'正常','{5}','{6}','{7}')", ry.LoginName, ry.UserName, ry.AreaCode, ry.IntDepartmentID, ry.IntRoleID, MD5.Md5Encrypt("1"), ry.DepartmentName, ry.OperRight);



            ret = SqlHelper.ExecuteNonQuery(mSql);
            if (ret > 0)
            {
                InitRY();
                mSql       = string.Format("select id from t_users where loginname='{0}'", ry.LoginName);
                ry.ID      = Convert.ToInt64(SqlHelper.ExecuteScalar(mSql));
                txtID.Text = ry.ID.ToString();
                SelectRow(ry.ID);
                Dlg.ShowOKInfo("添加成功,初始密码1!");
            }
        }
Esempio n. 6
0
        public IViewComponentResult Invoke()
        {
            var model = HttpContext.Session.Get("CurrentUser");

            if (model == null)
            {            //未登录
                ViewData["yhm"] = null;
            }
            else
            {                                                               //已登录
                string hex = System.Text.Encoding.Default.GetString(model); //获取json数据
                ry     sta = JsonConvert.DeserializeObject <ry>(hex);       //转换成model数据

                ViewData["yhm"] = sta.yhm;
            }
            return(View());
        }
Esempio n. 7
0
        public string DORegister()
        {
            ry  ry           = new ry();
            var updateResult = TryUpdateModelAsync <ry>(ry);
            ry  tt           = ryRepository.jcsjh(ry.sjh);//查询手机号是否在人员表中出现

            if (tt != null)
            {
                return("手机号已存在");
            }            //如果tt为null,就代表没有这个手机号,可以接着注册
            ry.id          = Guid.NewGuid().ToString();
            ry.create_time = DateTime.Now;
            ry.rylx        = 1;
            bool t = this.ryRepository.insertry(ry);

            if (t)
            {
                return("用户未注册,可以正常登陆");
            }
            return("用户名已存在,请重新注册");
        }
Esempio n. 8
0
        private void tsbRYSave_Click(object sender, EventArgs e)
        {
            if (dgvRY.SelectedRows.Count < 1)
            {
                Dlg.ShowErrorInfoAndHelp("请先选择要保存的用户");
                return;
            }
            if (TBGH.Text.Trim() == string.Empty)
            {
                toolTip1.Show("工号不能为空", TBGH, 0, TBGH.Height, 2000);
                return;
            }
            if (TBXM.Text.Trim() == string.Empty)
            {
                toolTip1.Show("姓名不能为空", TBXM, 0, TBXM.Height, 2000);
                return;
            }
            ry ry = new ry();

            ry.GH  = Convert.ToInt32(TBGH.Text);
            ry.XM  = TBXM.Text.Trim();
            ry.XB  = "男";
            ry.DH  = TBDH.Text.Trim();
            ry.SH  = Convert.ToInt32(CBoxSH.SelectedValue);
            ry.RYZ = Convert.ToInt32(CBoxRole.SelectedValue);
            if (rbFemale.Checked == true)
            {
                ry.XB = "女";
            }
            int gh = Convert.ToInt32(dgvRY.SelectedRows[0].Cells["ColGH"].Value);
            int ret;

            if (gh != ry.GH)
            {
                Dlg.ShowErrorInfoAndHelp("已经创建的员工不允许修改其工号!");
                return;
                //if (gh == 1001)
                //{
                //    Dlg.ShowErrorInfoAndHelp("员工1001不允许修改工号!");
                //    return;
                //}
                //ret = Convert.ToInt32(SqlHelper.ExecuteScalar(string.Format("select count(1) from ptry where gh={0}", ry.GH)));
                //if (ret > 0)
                //{
                //    toolTip1.Show("该工号已存在,请重新输入", TBGH, 0, TBGH.Height, 2000);
                //    TBGH.Focus();
                //    return;
                //}
            }
            if ((gh == 1001) && (ry.RYZ != (int)dgvRY.SelectedRows[0].Cells["ColJB"].Value))
            {
                Dlg.ShowErrorInfoAndHelp("员工1001不允许修改权限!");
                return;
            }
            string mSql = string.Format("update ptry set gh='{0}',xm='{1}',xb='{2}',dh='{3}',sh={4},jb={5} where gh='{6}'", ry.GH, ry.XM, ry.XB, ry.DH, ry.SH, ry.RYZ, gh);

            ret = SqlHelper.ExecuteNonQuery(mSql);
            if (ret > 0)
            {
                InitRY();
                SelectRow(ry.GH);
                Dlg.ShowOKInfo("修改成功!");
            }
        }
Esempio n. 9
0
        private void tsbRYAdd_Click(object sender, EventArgs e)
        {
            TrimTextBox();
            if (TBGH.Text.Trim() == string.Empty)
            {
                toolTip1.Show("工号不能为空", TBGH, 0, TBGH.Height, 2000);
                return;
            }
            if (TBXM.Text.Trim() == string.Empty)
            {
                toolTip1.Show("姓名不能为空", TBXM, 0, TBXM.Height, 2000);
                return;
            }
            if (Utils.StrToIntDef(TBGH.Text, -1) == -1)
            {
                Dlg.ShowErrorInfoAndHelp("请输入四位数字工号,且不能与已有工号重复!");
                TBGH.SelectAll();
                TBGH.Focus();
                return;
            }
            if (TBDH.Text != "")
            {
                if (Utils.StrToIntDef(TBDH.Text, -1) == -1)
                {
                    Dlg.ShowErrorInfoAndHelp("请输入正确的电话号码数字!");
                    TBDH.SelectAll();
                    TBDH.Focus();
                    return;
                }
            }

            ry ry = new ry();

            ry.GH  = Convert.ToInt32(TBGH.Text);
            ry.XM  = TBXM.Text.Trim();
            ry.XB  = "男";
            ry.DH  = TBDH.Text.Trim();
            ry.SH  = Convert.ToInt32(CBoxSH.SelectedValue);
            ry.RYZ = Convert.ToInt32(CBoxRole.SelectedValue);
            if (rbFemale.Checked == true)
            {
                ry.XB = "女";
            }
            int ret = Convert.ToInt32(SqlHelper.ExecuteScalar(string.Format("select count(1) from ptry where gh='{0}'", ry.GH)));

            if (ret > 0)
            {
                toolTip1.Show("该工号已存在,请重新输入", TBGH, 0, TBGH.Height, 2000);
                TBGH.Focus();
                return;
            }

            string mSql = string.Format("insert into ptry(gh,xm,xb,dh,sh,jb,zt,mm) values ({0},'{1}','{2}','{3}',{4},{5},'0','{6}')", ry.GH, ry.XM, ry.XB, ry.DH, ry.SH, ry.RYZ, MD5.Md5Encrypt("1001"));

            ret = SqlHelper.ExecuteNonQuery(mSql);
            if (ret > 0)
            {
                InitRY();
                SelectRow(ry.GH);
                Dlg.ShowOKInfo("添加成功,初始密码1001!");
            }
        }