Ejemplo n.º 1
0
    private void loadData()
    {
        SqlDataSource sds = new SqlDataSource();

        sds.ConnectionString  = connectionString;
        sds.SelectCommand     = "dbo.getUser";
        sds.SelectCommandType = SqlDataSourceCommandType.StoredProcedure;
        DataView dv = sds.Select(DataSourceSelectArguments.Empty) as DataView;

        if (dv.Count > 0)
        {
            for (int i = 0; i < dv.Count; i++)
            {
                CUsers user = new CUsers();
                user.id       = (int)dv.Table.Rows[i]["id"];
                user.account  = dv.Table.Rows[i]["account"].ToString();
                user.password = dv.Table.Rows[i]["password"].ToString();
                user.name     = dv.Table.Rows[i]["name"].ToString();
                user.phone    = dv.Table.Rows[i]["phone"].ToString();
                user.email    = dv.Table.Rows[i]["email"].ToString();
                user.address  = dv.Table.Rows[i]["address"].ToString();
                userList.Add(user);
            }
        }
    }
Ejemplo n.º 2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            List <CShoppingCart> cartList    = Session["cart"] as List <CShoppingCart>;
            CUsersFactory        userFactory = new CUsersFactory();
            double dblPay = 0;
            int    count  = 0;
            foreach (CShoppingCart c in cartList)
            {
                dblPay += Convert.ToDouble(c.小計);
                count  += Convert.ToInt32(c.數量);
            }
            dblPay           += 100;
            lblTotal.Text     = dblPay.ToString() + "元(含運費100)";
            lblTotalCont.Text = count.ToString() + "本";

            string account = Session["loginName"].ToString();
            CUsers user    = userFactory.getByAccount(account);
            tboxName1.Text    = user.name;
            tboxPhone1.Text   = user.phone;
            tboxEmail1.Text   = user.email;
            tboxAddress1.Text = user.address;
            tboxName2.Text    = user.name;
            tboxPhone2.Text   = user.phone;
            tboxEmail2.Text   = user.email;
            tboxAddress2.Text = user.address;
        }
    }
Ejemplo n.º 3
0
        public ActionResult DoLogin()
        {
            string res = JsonStringResult.VerifyFail();

            try
            {
                if (GeetestValidate.Validate())
                {
                    CUsers user = UsersBll.Instance.Login(Request["LoginName"].TryParseString(), Request["Password"].TryParseString());
                    if (user != null)
                    {
                        string userJson = JsonConvert.SerializeObject(user, new JsonSerializerSettings
                        {
                            DateFormatString = "yyyy-MM-dd HH:mm:ss"
                        });
                        CookieHelper.SetCookie("User", userJson, DateTime.Now.AddDays(30));
                        res = JsonStringResult.SuccessResult();
                    }
                    else
                    {
                        res = JsonStringResult.Error(OperateResCodeEnum.用户名或密码错误);
                    }
                }
                else
                {
                    res = JsonStringResult.Error(OperateResCodeEnum.验证码错误);
                }
            }
            catch (Exception ex)
            {
                res = JsonStringResult.Error(OperateResCodeEnum.内部错误);
            }
            return(Content(res));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Create([Bind("Id,UserName,Password,IsActive,RegisterDate")] CUsers users)
        {
            if (ModelState.IsValid)
            {
                string result = await _userRep.AnyUser‍Insert(users);

                if (result != "True")
                {
                    users.RegisterDate = DateTime.Now;

                    //Hash Password
                    users.Password = HashPassword.ToHashPassword(users.Password);

                    await _userRep.InsertUser(users);

                    await _userRep.Save();

                    Success();
                    return(RedirectToAction(nameof(Index)));
                }

                ModelState.AddModelError("UserName", " اين نام كاربري قبلاً در سيستم ثبت شده است");
            }
            RegisterViewModel viewModelUser = new RegisterViewModel();

            viewModelUser.UserName = users.UserName;
            viewModelUser.IsActive = users.IsActive;
            viewModelUser.Password = users.Password;
            return(View(viewModelUser));
        }
Ejemplo n.º 5
0
        public async Task ChangePasswordUser(CUsers user)
        {
            var dbModel = await GetByUserName(user.UserName);

            dbModel.Password         = user.Password;
            _db.Entry(dbModel).State = EntityState.Modified;
        }
Ejemplo n.º 6
0
        public static void addUser(CUsers cu)
        {
            Users u = Mapper.convertToUsers(cu);

            using (NDBEntities db = new NDBEntities())
            {
                Users u2 = (from x in db.Users
                            where x.IdUser.Equals(u.IdUser) && x.Permission != u.Permission && x.Permission != 4
                            select x).FirstOrDefault();
                if (u2 != null)
                {
                    db.Users.Find(u2.IdUser).Permission = 4;
                    db.SaveChanges();
                }
                else
                {
                    try
                    {
                        db.Users.Add(u);
                        db.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        throw e;
                    }
                }
            }
        }
Ejemplo n.º 7
0
        public async Task UpdateUser(CUsers user)
        {
            var dbModel = await GetUserById(user.Id);

            dbModel.UserName         = user.UserName;
            dbModel.IsActive         = user.IsActive;
            _db.Entry(dbModel).State = EntityState.Modified;
        }
Ejemplo n.º 8
0
        //public static void updateUser(CUsers cu)
        //{
        //    if (selectUserById(cu.Id) != null)
        //    {
        //        removeUser(cu.Id);
        //    }
        //    addUser(cu);
        //}
        public static void updateUser(CUsers cu)
        {
            Users u = Mapper.convertToUsers(selectUserById(cu.Id));

            using (NDBEntities db = new NDBEntities())
            {
                db.Users.Find(cu.Id).Address     = cu.Address;
                db.Users.Find(cu.Id).PhoneNum    = cu.PhoneNum;
                db.Users.Find(cu.Id).MailAddress = cu.mailAddress;
                db.SaveChanges();
            }
        }
Ejemplo n.º 9
0
 public int updateUser([FromBody] CUsers user)
 {
     try
     {
         BUserManager.updateUser(user);
         return(1);
     }
     catch (Exception)
     {
         throw;
     }
 }
Ejemplo n.º 10
0
        private void btnAddU_Click(object sender, EventArgs e)
        {
            CUsers u = new CUsers(txtIdU.Text, txtNameU.Text, txtAddressU.Text, txtPhoneU.Text, int.Parse(txtCodeKinderU.Text), int.Parse(txtPremissionU.Text), txtMail.Text);

            BUserManager.addUser(u);
            txtIdU.Text         = "";
            txtNameU.Text       = "";
            txtAddressU.Text    = "";
            txtPhoneU.Text      = "";
            txtCodeKinderU.Text = "";
            txtPremissionU.Text = "";
            txtMail.Text        = "";
        }
Ejemplo n.º 11
0
        public static CUsers convertToCUsers(Users u)
        {
            CUsers cu = new CUsers();

            cu.Id        = u.IdUser;
            cu.FirstName = u.FirstName;
            cu.LastName  = u.LastName;
            cu.Address   = u.Address;
            cu.PhoneNum  = u.PhoneNum;
            //  cu.KinderGardenCode = u.KinderGardenCode;
            cu.Permission  = u.Permission;
            cu.mailAddress = u.MailAddress;
            //  cu.Active = u.Active;
            return(cu);
        }
Ejemplo n.º 12
0
        private void btn_Login_Click(object sender, EventArgs e)
        {
            CUsers cUsers = new CUsers();
            var    users  = cUsers.findAll();
            var    user   = users.Where(u => u.Username == txt_Username.Text.Trim()).SingleOrDefault();

            if (!(user is null) && user.Password == txt_Password.Text.Trim())
            {
                var isAdmin = user.isAdmin;
                var name    = user.Name;
                MessageBox.Show("Đăng nhập thành công");
                this.Hide();
                Form1 frm = new Form1(isAdmin, name);
                frm.Show();
            }
Ejemplo n.º 13
0
        public static Users convertToUsers(CUsers cu)
        {
            Users u = new Users();

            u.IdUser    = cu.Id;
            u.FirstName = cu.FirstName;
            u.LastName  = cu.LastName;
            u.Address   = cu.Address;
            u.PhoneNum  = cu.PhoneNum;
            // u.KinderGardenCode = cu.KinderGardenCode;
            u.MailAddress = cu.mailAddress;
            u.Permission  = cu.Permission;
            //  u.Active = cu.Active;
            return(u);
        }
Ejemplo n.º 14
0
        public int addUser([FromBody] CUsers user)
        {
            try
            {
                BUserManager.addUser(user);
                return(1);
            }
            catch (Exception e)
            {
                if (e.InnerException.InnerException.Message.Equals("Violation of PRIMARY KEY constraint 'PK__Users__B7C9263840CFC3C0'. Cannot insert duplicate key in object 'dbo.Users'. The duplicate key value is (319100160).\r\nThe statement has been terminated."))
                {
                    allreadyExist ex = new allreadyExist();
                    throw ex;
                }

                throw e;
            }
        }
Ejemplo n.º 15
0
        private void btnTransfer_Click(object sender, EventArgs e)
        {
            CUsers cuser    = new CUsers();
            string userstng = Interaction.InputBox("please, insert the user's code that you want to transfer.", "insert code:");
            double amount   = Convert.ToDouble(Interaction.InputBox("please, insert the amount that you want to transfer.", "insert amount:"));

            if (userstng != null & amount != 0)
            {
                Users receptor = cuser.getUserByCode(userstng);
                Users emisor   = SUsers.getInstance();
                cuser.transfer(emisor, receptor, amount);
                Menu_Load(sender, e);
            }
            else
            {
                MessageBox.Show("please, insert a code count or amount to process", "there is an error:");
            }
        }
Ejemplo n.º 16
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,UserName,IsActive")] CUsers users)
        {
            if (id != users.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    string result = await _userRep.AnyUser‍Update(users);

                    if (result != "True")
                    {
                        await _userRep.UpdateUser(users);

                        await _userRep.Save();

                        Success();
                    }
                    else
                    {
                        ModelState.AddModelError("UserName", " اين نام كاربري قبلاً در سيستم ثبت شده است");
                        return(View(users));
                    }
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CUsersExists(users.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(users));
        }
Ejemplo n.º 17
0
        //public static int addChildren(CChildren cc)
        //{
        //    Children c = Mapper.convertToChildren(cc);
        //    using (NDBEntities db = new NDBEntities())
        //    {
        //        try
        //        {
        //            db.Children.Add(c);
        //            db.SaveChanges();
        //            return 1;
        //        }
        //        catch (Exception e)
        //        {

        //            throw;
        //        }
        //    }
        //}

        public static int addChildren(CChildParent cc)
        {
            CUsers    u  = new CUsers(cc.ParentId, cc.ParentFirstName, cc.ParentLastName, cc.Address, cc.Phone, 1, cc.mailAddress, cc.Active);
            Users     u1 = Mapper.convertToUsers(u);
            CChildren c  = new CChildren(cc.ChildId, cc.ChildFirstName, cc.ChildLastName, cc.Address, cc.Phone, cc.ParentCode, cc.KinderGardenCode, cc.Active, cc.picture);
            Children  c1 = Mapper.convertToChildren(c);

            using (NDBEntities db = new NDBEntities())
            {
                try
                {
                    var idParent = (from x in db.Users
                                    where u1.IdUser == x.IdUser
                                    select x.IdUser).FirstOrDefault();
                    if (idParent == null)
                    {
                        db.Users.Add(u1);
                    }
                    Children child = (from x in db.Children
                                      where x.IdChild.Equals(cc.ChildId) && x.Active == 0
                                      select x).FirstOrDefault();
                    if (child != null)
                    {
                        Children ch = db.Children.First(d => d.IdChild.Equals(child.IdChild));
                        ch.Active = 1;
                    }
                    else
                    {
                        db.Children.Add(c1);
                        db.SaveChanges();
                    }

                    return(1);
                }
                catch (Exception e)
                {
                    throw;
                }
            }
        }
Ejemplo n.º 18
0
        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            string controllerName = filterContext.RouteData.Values["controller"].ToString().ToLower();
            string actionName     = filterContext.RouteData.Values["action"].ToString().ToLower();
            string returnUrl      = "/" + controllerName + "/" + actionName + filterContext.RequestContext.HttpContext.Request.Url.Query;

            string userJson = CookieHelper.GetCookieValue("User");

            //Log.Default.Debug(userJson);
            if (!userJson.IsNullOrEmpty())
            {
                CUsers user = null;
                try
                {
                    user = JsonConvert.DeserializeObject <CUsers>(userJson);
                    FF_User hs_user = UsersBll.Instance.GetUserByAdmin(user.UserCode);
                    filterContext.Controller.ViewBag.User = hs_user;
                    DateTime now        = DateTime.Now;
                    string   SecretCode = hs_user.SecretCode;
                    filterContext.Controller.ViewBag.ConfusionStringToHTML = SignUtil.CreateConfusionStringToHTML(SecretCode, now);
                }
                catch (Exception ex)
                {
                    Log.Default.Error(ex);
                }
                if (user == null || UsersBll.Instance.IsUserCodeRepeat(user.UserCode) == false)
                {
                    SetContextResult(filterContext, returnUrl);
                    return;
                }
            }
            else
            {
                SetContextResult(filterContext, returnUrl);
                return;
            }
        }
Ejemplo n.º 19
0
 public async Task InsertUser(CUsers user)
 {
     await _db.CUsers.AddAsync(user);
 }
Ejemplo n.º 20
0
 public static void updateUser(CUsers cu)
 {
     DUsersManager.updateUser(cu);
 }
Ejemplo n.º 21
0
 public static void addUser(CUsers cu)
 {
     DUsersManager.addUser(cu);
 }
Ejemplo n.º 22
0
 public async Task <string> AnyUser‍Insert(CUsers user)
 {
     return(Convert.ToString(await _db.CUsers.AnyAsync(u => u.UserName == user.UserName)));
 }
Ejemplo n.º 23
0
 public async Task <string> AnyUser‍Update(CUsers user)
 {
     return(Convert.ToString(await _db.CUsers.AnyAsync(u => u.UserName == user.UserName && u.Id != user.Id)));
 }