Beispiel #1
0
 /// <summary>
 /// 获取所有用户
 /// </summary>
 /// <returns></returns>
 public async Task <List <Models.User> > GetAllAsync()
 {
     using (var db = new DAL.UserDAL())
     {
         return(await db.GetAll().ToListAsync());
     }
 }
 public ActionResult Login(UserLoginViewModel Um)
 {
     //Model Validation
     if (!ModelState.IsValid)
     {
         return(View(Um));
     }
     else
     {
         //login ko code yaha lekhna parcha
         DAL.UserDAL ud = new DAL.UserDAL();
         if (ud.IfUserExists(Um.UserName))
         {
             if (ud.Login(Um))
             {
                 //session initialize ko code here
                 Session.Add("Islogged", true);
                 Session.Add("UserName", Um.UserName);
                 return(RedirectToAction("Index", "Home"));
             }
             else
             {
                 ModelState.AddModelError("NotMatch", "Password Doesnot match");
                 return(View(Um));
             }
         }
         else
         {
             ModelState.AddModelError("DoesNotExists", "User doesnot exists");
             return(View(Um));
         }
     }
 }
Beispiel #3
0
 /// <summary>
 /// 查询:根据用户名获取相应的用户组信息
 /// </summary>
 /// <param name="userName"></param>
 /// <returns></returns>
 public static async Task <string> GetUserGroupForUserName(string userName)
 {
     using (var db = new DAL.UserDAL())
     {
         return((await db._db.Users.Include(s => s.UserGroup).FirstAsync(m => m.UserName == userName)).UserGroup.Name);
     }
 }
Beispiel #4
0
        /// <summary>
        /// 更新:根据用户名更新用户信息
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="model"></param>
        /// <returns></returns>
        public static async Task SetUserForUserName(string userName, Models.User model)
        {
            using (var db = new DAL.UserDAL())
            {
                var data = await db.GetAll().FirstAsync(s => s.UserName == userName);

                data.Approval             = model.Approval;
                data.Attention            = model.Attention;
                data.AttentionIdCard      = model.AttentionIdCard;
                data.BusinessLicense      = model.BusinessLicense;
                data.BusinessState        = model.BusinessState;
                data.Contact              = model.Contact;
                data.ContanctPhone        = model.ContanctPhone;
                data.EnglishName          = model.EnglishName;
                data.EntityName           = model.EntityName;
                data.EthnicMinoritiesName = model.EthnicMinoritiesName;
                data.IdNumber             = model.IdNumber;
                data.LegelPerson          = model.LegelPerson;
                data.Note        = model.Note;
                data.Phone       = model.Phone;
                data.TheZipCode  = model.TheZipCode;
                data.UnitAddress = model.UnitAddress;
                data.UnitCode    = model.UnitCode;
                await db.EditAsync(data);
            }
        }
Beispiel #5
0
        public ActionResult UserList()
        {
            var dal  = new DAL.UserDAL();
            var user = dal.UserList();

            return(View(user));
        }
Beispiel #6
0
 public async Task <Models.User> GetUserOne(string userName)
 {
     using (var db = new DAL.UserDAL())
     {
         return(await db.GetAll().FirstAsync(m => m.UserName == userName));
     }
 }
Beispiel #7
0
 /// <summary>
 /// 登录
 /// </summary>
 /// <param name="user"></param>
 /// <param name="pwd"></param>
 /// <returns></returns>
 public static async Task <bool> Login(string user, string pwd)
 {
     using (var db = new DAL.UserDAL())
     {
         return(await db.GetAll().AnyAsync(m => m.UserName == user && m.UserPwd == pwd));
     }
 }
Beispiel #8
0
        public ActionResult Details(int id)
        {
            var dal  = new DAL.UserDAL();
            var user = dal.Search(id);

            return(View(user));
        }
Beispiel #9
0
 public ActionResult Login(Models.Login model)
 {
     if (ModelState.IsValid)
     {
         var daluser = new DAL.UserDAL();
         var user    = daluser.Login(model);
         if (user != null)
         {
             Session["USER"] = user;
             var sestud  = (Entity.User)Session["USER"];
             int id      = sestud.User_id;
             var dalstud = new DAL.StudentDAL();
             var stud    = dalstud.Searchstud(id);
             if (stud != null)
             {
                 Session["Stud"] = stud;
             }
             var dalteac = new DAL.TeacherDAL();
             var teacher = dalteac.Searchteac(id);
             if (teacher != null)
             {
                 Session["Teacher"] = teacher;
             }
             return(RedirectToAction("Index", "User"));
         }
         else
         {
             Response.Write("<script> alert('ไม่พบผู้ใช้')</script>");
         }
     }
     return(View(model));
 }
Beispiel #10
0
 /// <summary>
 /// 根据Id删除用户
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public async Task RemoveAsync(int id)
 {
     using (var db = new DAL.UserDAL())
     {
         await db.RemoveAsync(id);
     }
 }
Beispiel #11
0
        public ActionResult Edit(int id)
        {
            var dal  = new DAL.UserDAL();
            var user = dal.Search(id);

            ViewBag.Image = user.Image;
            return(View(user));
        }
Beispiel #12
0
        /// <summary>
        /// 修改密码
        /// </summary>
        /// <param name="user"></param>
        /// <param name="oldPwd"></param>
        /// <param name="newPwd"></param>
        /// <returns></returns>
        public async Task EditAsync(string user, string oldPwd, string newPwd)
        {
            using (var db = new DAL.UserDAL())
            {
                var userData = await db.GetAll().FirstAsync(m => m.UserName == user);

                userData.UserPwd = newPwd;
                await db.EditAsync(userData);
            }
        }
Beispiel #13
0
 /// <summary>
 /// 增加用户
 /// </summary>
 /// <param name="user"></param>
 /// <param name="pwd"></param>
 /// <returns></returns>
 public async Task AddAsync(string user, string pwd, string entityName)
 {
     using (DAL.UserDAL db = new DAL.UserDAL())
     {
         await db.AddAsync(new Models.User()
         {
             UserName   = user,
             UserPwd    = pwd,
             EntityName = entityName
         });
     }
 }
Beispiel #14
0
 public Boolean LoginUser(Model.User Tmp)
 {
     try
     {
         DAL.UserDAL ObjectDAL = new DAL.UserDAL();
         return(ObjectDAL.LoginUser(Tmp) > 0 ? true : false);
     }
     catch (SqlException)
     {
         throw;
     }
 }
Beispiel #15
0
        public ActionResult Delete(int id)
        {
            var dal    = new DAL.UserDAL();
            var user   = dal.Search(id);
            var result = dal.Delete(user);

            if (result)
            {
                Response.Write("<script> alert('ลบข้อมูลเรียบร้อย')</script>");
            }
            return(RedirectToAction("UserList"));
        }
Beispiel #16
0
        public UserEntity Signin(UserEntity user)
        {
            Dictionary<string, string> condition = new Dictionary<string, string>();
            condition.Add("UserName", user.UserName);
            condition.Add("UserPwd", user.UserPwd);
            UserEntity userResult = new DAL.UserDAL().Signin(user, condition);

            if (userResult != null && userResult.UserState == 0)
            {
                throw new BllException("用户为停用状态,请联系管理员!");
            }

            return userResult;
        }
Beispiel #17
0
        public ActionResult Edit(Entity.User model, int id)
        {
            try
            {
                var dal  = new DAL.UserDAL();
                var user = dal.Search(id);

                user.Username = model.Username;
                user.Password = model.Password;
                user.Name     = model.Name;
                user.Usertype = model.Usertype;


                #region Upload Picture                             // จัดการบันทึกรูปภาพ
                HttpPostedFileBase Image = Request.Files["Image"]; //อ่านภาพต้นฉบับ

                if (Image != null)
                {
                    if (Image != null && Image.ContentLength > 0)
                    {
                        string filename = Path.GetFileName(Image.FileName);
                        string SavePath = Server.MapPath("~/UploadPicture");
                        if (!Directory.Exists(SavePath))
                        {
                            Directory.CreateDirectory(SavePath);
                        }

                        Image.SaveAs(SavePath + "/" + filename);  //บันทึกไฟล์ภาพ
                        user.Image = "UploadPicture/" + filename; //ชื่อไฟล์และพาท
                    }
                }

                #endregion


                var result = dal.EditeUser(user);
                if (result)
                {
                    Response.Write("<script> alert('แก้ไข้ข้อมูลสำเร็จ')</script>");
                }
                return(RedirectToAction("UserList"));
            }
            catch (Exception)
            {
                Response.Write("<scrip> aler('ไม่สำเร็จ')</scrip>");
            }
            return(View(model));
        }
Beispiel #18
0
        /// <summary>
        /// 用户登陆
        /// </summary>
        /// <param name="log">用户名</param>
        /// <param name="pwd">密码</param>
        /// <returns></returns>
        public Model.User Login(string log, string pwd)
        {
            pwd = Encryption(pwd);
            Model.User        user = new Model.User();
            List <Model.User> date = new DAL.UserDAL().GetUser();

            if (date.Count == 0)//获取List里面的元素
            {
                user.LoginInfo = "用户不存在";
                return(user);
            }
            if (date[0].pwd != pwd)
            {
                user.LoginInfo = "密码错误";
                return(user);
            }
            return(date[0]);
        }
Beispiel #19
0
 /// <summary>
 /// 登录并返回id
 /// </summary>
 /// <param name="user"></param>
 /// <param name="pwd"></param>
 /// <param name="id"></param>
 /// <returns></returns>
 public static bool Login(string user, string pwd, out int id)
 {
     using (var db = new DAL.UserDAL())
     {
         var emp = db.GetAll().FirstOrDefaultAsync(m => m.UserName == user && m.UserPwd == pwd);
         emp.Wait();
         if (emp.Result == null)
         {
             id = -1;
             return(false);
         }
         else
         {
             id = emp.Id;
             return(true);
         }
     }
 }
Beispiel #20
0
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="code"></param>
        /// <param name="pwd"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public bool LoginSys(string code, string pwd, out string msg)
        {
            msg = "登录成功";
            UserInfo user = new DAL.UserDAL().GetSingleUser(code);

            if (user == null)
            {
                msg = "用户信息不存在";
                return(false);
            }

            if (pwd != user.pwd)
            {
                msg = "用户密码输入有误";
                return(false);
            }
            GlobalVar.LoginUser = user;
            return(true);
        }
Beispiel #21
0
        public ActionResult Create(Entity.User model)
        {
            #region Upload Picture                             // จัดการบันทึกรูปภาพ
            HttpPostedFileBase Image = Request.Files["Image"]; //อ่านภาพต้นฉบับ

            if (Image != null && Image.ContentLength > 0)
            {
                string filename = Path.GetFileName(Image.FileName);
                string SavePath = Server.MapPath("~/UploadPicture");
                if (!Directory.Exists(SavePath))
                {
                    Directory.CreateDirectory(SavePath);
                }

                Image.SaveAs(SavePath + "/" + filename);   //บันทึกไฟล์ภาพ
                model.Image = "UploadPicture/" + filename; //ชื่อไฟล์และพาท
            }
            #endregion
            if (ModelState.IsValid)
            {
                var dal = new DAL.UserDAL();
                var chk = dal.Chkuser(model);
                if (chk != null)
                {
                    Response.Write("<script> alert('มีชื่อผู้ใช้นี้แล้ว')</script>");
                }
                else
                {
                    var result = dal.CreateUser(model);
                    if (result)
                    {
                        Response.Write("<script> alert('ลงทะเบียนสำเร็จ')</script>");
                    }
                    return(RedirectToAction("UserList", "User"));
                }
                return(View());
            }
            return(View(model));
        }
Beispiel #22
0
        // GET: APPAPI/Login 用户注册
        public IActionResult Index(string username, string password)
        {
            //前端判断后台也要判断用户名和密码是否为空等情况
            if (string.IsNullOrEmpty(username))
            {
                return Json(new { status = "n", info = "请输入用户名!" });
            }
            if (string.IsNullOrEmpty(password))
            {
                return Json(new { status = "n", info = "请输入密码!" });
            }

            //判断是否注册过
            DAL.UserDAL udal = new DAL.UserDAL();
            int x = udal.CalcCount("username=@username", new SqlParameter[] { new SqlParameter("@username", username) });

            if(x>0)
            {
                return Json(new { status = "n", info = "用户已被注册,请重新输入!" });
            }
            //否则就加入数据库
           int userid= udal.Add(new Model.User() { username = username, password = password });
            
            //语法糖 4.5以上才能用 ,原始的  info = "恭喜您(+username+)注册成功!" 

            return Json(
                new {
                    status = "y",
                    info = $"恭喜您({username})注册成功!",
                    userid = userid,
                    // face = Tool.GetHostUrl() + $"/{u.face}"  ,  //upload//aa.jpg -》http://mhqapp.net/upload/aa.jpg

                    face = "upload/face.jpg" ,
                    username = username,
                    usertype = "普通会员" 

                });

        }
Beispiel #23
0
        // GET: APPAPI/Login 用户登录
        public ActionResult Index(string username, string password)
        {
            //前端判断后台也要判断用户名和密码是否为空等情况
            if (string.IsNullOrEmpty(username))
            {
                return(Json(new { status = "n", info = "请输入用户名!" }));
            }
            if (string.IsNullOrEmpty(password))
            {
                return(Json(new { status = "n", info = "请输入密码!" }));
            }


            Model.User u = new DAL.UserDAL().GetModelByCond("username=@username and password=@password", new SqlParameter[] {
                new SqlParameter("@username", username),
                new SqlParameter("@password", password)
            });

            if (u != null)
            {
                //登录成功
                return(Json(new
                {
                    status = "y",
                    info = "恭喜你登录成功!",
                    userid = u.id,
                    // face = Tool.GetHostUrl() + $"/{u.face}"  ,  //upload//aa.jpg -》http://mhqapp.net/upload/aa.jpg

                    face = string.IsNullOrEmpty(u.face)?"upload/face.jpg":u.face,
                    username = u.username,
                    usertype = string.IsNullOrEmpty(u.usertype) ? "普通会员":u.usertype
                }));
            }
            else
            {
                //登录失败
                return(Json(new { status = "n", info = "登录失败!" }));
            }
        }
 public ActionResult Signup(UserRegistrationViewModel Um)
 {
     //Model Validation
     if (!ModelState.IsValid)
     {
         return(View(Um));
     }
     else
     {
         //Registration ko code yaha lekhna parcha
         DAL.UserDAL ud = new DAL.UserDAL();
         if (ud.IfUserExists(Um.UserName))
         {
             ModelState.AddModelError("Exists", "Username already Exists.");
             return(View(Um));
         }
         else
         {
             ud.CreateUser(Um);
             return(RedirectToAction("Index", "Home"));
         }
     }
 }
Beispiel #25
0
 /// <summary>
 /// Construtor padrão
 /// </summary>
 public UserService()
 {
     _userDAL = new DAL.UserDAL();
 }
Beispiel #26
0
 /// <summary>
 /// Construtor que utiliza um contexto já existente
 /// </summary>
 /// <param name="context"></param>
 public UserService(DAL.UserDAL context)
 {
     _userDAL = context;
 }
Beispiel #27
0
 public UserBAL(Connection connection, Setting setting)
 {
     UserDAL = new DAL.UserDAL(connection, setting);
 }
Beispiel #28
0
        private async void Button_Confim_Click(object sender, RoutedEventArgs e)
        {
            if (!CheckInputIsShitOrFuck())
            {
                return;
            }

            ChongGuanSafetySupervisionQZ.DAL.UserDAL userDAL = new DAL.UserDAL();
            var addUser_result = await userDAL.Add(new QZ_User
            {
                AreaCode                = _chinaCitiesViewModel.SelectedItem.AreaId,
                CreateTime              = DateTime.Now.ToString(),
                IsDeleteId              = 0,
                IsForbidden             = 0,
                LoginName               = this.TextBox_AdminUserName.Text,
                LoginPwd                = this.RadPasswordBox_AdminPassword.Password,
                ModifyTime              = DateTime.Now.ToString(),
                UserCode                = Guid.NewGuid().ToString("N"),
                UserName                = "******",
                UserAge                 = "0",
                UserCard                = "",
                UserEmail               = "",
                UserFingerImageFilePath = "",
                UserLawCard             = "",
                UserPhone               = "",
                UserPhotoFilePath       = "",
                UserSex                 = ""
            });

            if (!addUser_result.IsSuccessed)
            {
                RadWindow.Alert(new DialogParameters
                {
                    Header = new TextBlock {
                        Text = "添加管理员失败", FontFamily = new FontFamily("微软雅黑"), IsHitTestVisible = false, Foreground = new SolidColorBrush(Colors.White)
                    },
                    Content = new TextBlock {
                        Text = addUser_result.Message, FontFamily = new FontFamily("微软雅黑"), IsHitTestVisible = false
                    },

                    Owner = this,
                    Theme = new MaterialTheme()
                });

                return;
            }

            GlobalData.CurrentUser = addUser_result.Data;

            ChongGuanSafetySupervisionQZ.DAL.DeparmentDAL deparmentDAL = new DAL.DeparmentDAL();
            var addDeparment_result = await deparmentDAL.Add(new QZ_Deparment
            {
                AreaCode            = _chinaCitiesViewModel.SelectedItem.AreaId,
                DeparmentCode       = Guid.NewGuid().ToString("N"),
                DeparmentName       = this.TextBox_Department.Text,
                DeparmentParentCode = "",
                IsDeleteId          = 0
            });

            if (!addDeparment_result.IsSuccessed)
            {
                RadWindow.Alert(new DialogParameters
                {
                    Header = new TextBlock {
                        Text = "添加部门信息失败", FontFamily = new FontFamily("微软雅黑"), IsHitTestVisible = false, Foreground = new SolidColorBrush(Colors.White)
                    },
                    Content = new TextBlock {
                        Text = addDeparment_result.Message, FontFamily = new FontFamily("微软雅黑"), IsHitTestVisible = false
                    },


                    Owner = this,
                    Theme = new MaterialTheme()
                });

                return;
            }

            GlobalData.CurrentDeparment = addDeparment_result.Data;

            ChongGuanSafetySupervisionQZ.DAL.Deparment_UserDAL deparment_UserDAL = new DAL.Deparment_UserDAL();
            await deparment_UserDAL.Add(GlobalData.CurrentDeparment, GlobalData.CurrentUser);

            ChongGuanSafetySupervisionQZ.DAL.Role_UserDAL role_UserDAL = new DAL.Role_UserDAL();
            await role_UserDAL.Add(new QZ_Role { RoleId = 1 }, GlobalData.CurrentUser);

            GlobalData.CurrnetRole = new QZ_Role {
                RoleId = 1
            };

            //RegistryHelper.SetRegistryData(@"ChongGuan\ChongGuanSafetySupervisionQZ",
            //    "Registered", "1");

            CreateRegFile();

            checkingHardwareWindow.Show();
            //dXRibbonMainWindow.Show();
            this.Close();
        }
Beispiel #29
0
        private async void Button_Confim_Click(object sender, RoutedEventArgs e)
        {
            if (!CheckInputIsShitOrFuck())
            {
                return;
            }

            IsLoginningOrDone(true);

            //await Task.Delay(1000);

            ChongGuanSafetySupervisionQZ.DAL.UserDAL userDAL = new DAL.UserDAL();
            var loginResult = await userDAL.Login(new Model.QZ_User {
                LoginName = this.TextBox_UserName.Text, LoginPwd = this.RadPasswordBox_Password.Password
            });

            if (!loginResult.IsSuccessed)
            {
                IsLoginningOrDone(false);

                RadWindow.Alert(new DialogParameters
                {
                    Header = new TextBlock {
                        Text = "登录失败", FontFamily = new FontFamily("微软雅黑"), IsHitTestVisible = false, Foreground = new SolidColorBrush(Colors.White)
                    },
                    Content = new TextBlock {
                        Text = loginResult.Message, FontFamily = new FontFamily("微软雅黑"), IsHitTestVisible = false
                    },

                    Owner = this,
                    Theme = new MaterialTheme()
                });

                return;
            }

            GlobalData.CurrentUser = loginResult.Data;

            ChongGuanSafetySupervisionQZ.DAL.Role_UserDAL role_UserDAL = new DAL.Role_UserDAL();
            var role_UserResult = role_UserDAL.QueryRoleByUser(GlobalData.CurrentUser);

            if (!role_UserResult.IsSuccessed)
            {
                IsLoginningOrDone(false);

                RadWindow.Alert(new DialogParameters
                {
                    Header = new TextBlock {
                        Text = "登录失败", FontFamily = new FontFamily("微软雅黑"), IsHitTestVisible = false, Foreground = new SolidColorBrush(Colors.White)
                    },
                    Content = new TextBlock {
                        Text = role_UserResult.Message, FontFamily = new FontFamily("微软雅黑"), IsHitTestVisible = false
                    },

                    Owner = this,
                    Theme = new MaterialTheme()
                });

                return;
            }

            GlobalData.CurrnetRole = role_UserResult.Data;

            ChongGuanSafetySupervisionQZ.DAL.Deparment_UserDAL deparment_UserDAL = new DAL.Deparment_UserDAL();
            var deparment_UserResult = deparment_UserDAL.QueryDeparmentByUser(GlobalData.CurrentUser);

            if (!deparment_UserResult.IsSuccessed)
            {
                IsLoginningOrDone(false);

                RadWindow.Alert(new DialogParameters
                {
                    Header = new TextBlock {
                        Text = "登录失败", FontFamily = new FontFamily("微软雅黑"), IsHitTestVisible = false, Foreground = new SolidColorBrush(Colors.White)
                    },
                    Content = new TextBlock {
                        Text = deparment_UserResult.Message, FontFamily = new FontFamily("微软雅黑"), IsHitTestVisible = false
                    },

                    Owner = this,
                    Theme = new MaterialTheme()
                });

                return;
            }

            GlobalData.CurrentDeparment = deparment_UserResult.Data;

            //dXRibbonMainWindow.Show();
            checkingHardwareWindow.Show();
            //homeWindow.Show();
            this.Close();

            IsLoginningOrDone(false);

            //NavigationService..Navigate(new Uri("NavigateDemoPage.xaml", UriKind.Relative));
        }
Beispiel #30
0
 public UserBLL()
 {
     dal = new DAL.UserDAL();
 }