コード例 #1
0
ファイル: AdminService.cs プロジェクト: lev2048/C_Sharp
 /// <summary>
 /// 根据用户名或密码登录
 /// </summary>
 /// <param name="objAdmin"></param>
 /// <returns></returns>
 public Admin AdminLogin(Admin objAdmin)
 {
     string sql = "select AdminName from Admins where LoginId={0} and LoginPwd='{1}'";
     sql = string.Format(sql, objAdmin.LoginId, objAdmin.LoginPwd);
     //查询
     try
     {
         SqlDataReader objReader = SQLHelper.GetReader(sql);
         if (objReader.Read())
         {
             objAdmin.AdminName = objReader["AdminName"].ToString();
         }
         //如果没找到,清空objAdmin
         else
         {
             objAdmin = null;
         }
         objReader.Close();
         return objAdmin;
     }
     catch (Exception ex)
     {
         throw new Exception("数据访问发生异常:" + ex.Message);
     }
 }
コード例 #2
0
		public void COMP87_Valid()
		{
			Admin admin = new Admin();
			admin.Password = "******";
			admin.PasswordConfirmation = "test";

			Assert.IsTrue(runner.IsValid(admin));
		}
コード例 #3
0
 public ActionResult Edit(int id, Admin admin)
 {
     AdminControl adminControl = new AdminControl();
     TryUpdateModel(admin);
     if (ModelState.IsValid)
     {
         adminControl.paramQuery("edit_admin", adminControl.paramEditAdmin(admin, id));
         return RedirectToAction("Index", "AdminAccount");
     }
     return View();
 }
コード例 #4
0
 public static int EditAdmin(Admin ad)
 {
     int upt = 0;
     try
     {
         upt = DataAccessLayer.AdminDA.EditAdmin(ad);
     }
     catch (Exception)
     {
         return 0;
     }
     return upt;
 }
コード例 #5
0
        public static int AddAdmin(Admin ad)
        {
            int ins = 0;
            try
            {
                ins = DataAccessLayer.AdminDA.AddAdmin(ad);
            }
            catch (Exception)
            {
                return 0;
            }

            return ins;
        }
コード例 #6
0
ファイル: FrmUserLogin.cs プロジェクト: lev2048/C_Sharp
 //登录
 private void btnLogin_Click(object sender, EventArgs e)
 {
     //数据验证
     if (this.txtLoginId.Text.Trim().Length == 0)
     {
         MessageBox.Show("请输入登录账号!", "登录提示");
         this.txtLoginId.Focus();
         return;
     }
     if (!DataValidate.IsInteger(this.txtLoginId.Text.Trim()))
     {
         MessageBox.Show("登录账号必须是正整数!", "登录提示");
         this.txtLoginId.Focus();
         this.txtLoginId.SelectAll();
         return;
     }
     if (this.txtLoginPwd.Text.Trim().Length == 0)
     {
         MessageBox.Show("请输入登录密码!", "登录提示");
         this.txtLoginPwd.Focus();
         return;
     }
     //封装用户信息到用户对象
     Admin objAdmin = new Admin()
     {
         LoginId = Convert.ToInt32(this.txtLoginId.Text.Trim()),
         LoginPwd = this.txtLoginPwd.Text.Trim()
     };
     try
     {
         //提交用户信息
         objAdmin = objAdminService.AdminLogin(objAdmin);
         if (objAdmin == null)
         {
             MessageBox.Show("登录账号或密码错误!", "登录提示");
         }
         else
         {
             Program.currentAdmin = objAdmin; //保存用户对象
             this.DialogResult = DialogResult.OK;//设置登录成功信息提示
             this.Close();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "登录失败!");
     }
 }
コード例 #7
0
		public void COMP87_Invalid()
		{
			Admin admin = new Admin();
			admin.Password = string.Empty;
			admin.PasswordConfirmation = "test";

			Assert.IsFalse(runner.IsValid(admin));
			Assert.AreEqual(2, runner.GetErrorSummary(admin).ErrorsCount);
			Assert.AreEqual(1, runner.GetErrorSummary(admin).GetErrorsForProperty("Password").Length);
			Assert.AreEqual(1, runner.GetErrorSummary(admin).GetErrorsForProperty("PasswordConfirmation").Length);

			admin.Password = "******";
			admin.PasswordConfirmation = string.Empty;

			Assert.IsFalse(runner.IsValid(admin));
			Assert.AreEqual(1, runner.GetErrorSummary(admin).ErrorsCount);
			Assert.AreEqual(1, runner.GetErrorSummary(admin).GetErrorsForProperty("PasswordConfirmation").Length);
		}
コード例 #8
0
        public ActionResult LoginProcess(FormCollection frm)
        {
            int check = 0;
            string user = frm["UserName"];
            string pass = frm["Password"];

            List<Models.Admin> ls = AdminBusiness.CheckLogin(user, pass);

            if (ls.Count > 0)
            {
                Session["mvc_user"] = ls[0];

                HttpCookie c = new HttpCookie("mvc_login");
                c.Values["user"] = user;
                c.Values["pass"] = pass;

                if (frm["cbRemember"].ToString().Contains("rmb"))
                {
                    c.Expires = DateTime.Now.AddDays(10);
                }
                else
                {
                    c.Expires = DateTime.Now.AddDays(-1);
                }
                Response.Cookies.Add(c);
                check = 1;

            }

            if (check == 1) return RedirectToAction("Index", "HomeAdmin");
            else
            {
                Models.Admin ad = new Models.Admin() { UserName=user,Password=pass};
                Session["draftAcc"] = ad;
                return RedirectToAction("Login", "Admin", new { error = "-1" });
            }
        }
コード例 #9
0
        public ActionResult EditProcess(FormCollection frm)
        {
            int kt = 0;
            try
            {
                bool actived = false;
                if (frm["cbIsActived"].ToString().Contains("rmb"))
                {
                    actived = true;
                }
                // TODO: Add insert logic here
                Models.Admin ad = new Models.Admin()
                {
                    Id = int.Parse(frm["Id"]),
                    UserName = frm["UserName"],
                    FullName = frm["FullName"],
                    Gender = frm["Gender"],
                    Phone = frm["Phone"],
                    Address = frm["Address"],
                    Email = frm["Email"],
                    IsActived = actived,
                };

                kt = AdminBusiness.EditAdmin(ad);

            }
            catch
            {
                kt = 0;
            }

            if (kt > 0)
            {
                return RedirectToAction("ListAdmin", "Admin", new { update = "success" });
            }
            else
            {
                return RedirectToAction("ListAdmin", "Admin", new { update = "error" });
            }
        }
コード例 #10
0
        public ActionResult CreateProcess(FormCollection frm)
        {
            int kt = 0;
            try
            {
                bool actived = false;
                if (frm["cbIsActived"].ToString().Contains("rmb"))
                {
                    actived = true;
                }
                // TODO: Add insert logic here
                Models.Admin ad = new Models.Admin()
                {
                    UserName=frm["UserName"],
                    Password = "******",
                    FullName = frm["FullName"],
                    Gender = frm["Gender"],
                    Phone = frm["Phone"],
                    Address = frm["Address"],
                    Email = frm["Email"],
                    IsActived = actived,
                    IsSuperAdmin=false
                };

                kt=AdminBusiness.AddAdmin(ad);

            }
            catch
            {
                kt = 0;
            }

            if (kt > 0)
            {
                return RedirectToAction("ListAdmin", "Admin", new {add="success"});
            }
            else
            {
                return RedirectToAction("ListAdmin", "Admin", new { add = "error" });
            }
        }
コード例 #11
0
        protected override void Seed(VechicleRegistration.Context.VRContext context)
        {
            //  This method will be called after migrating to the latest version.

            //  You can use the DbSet<T>.AddOrUpdate() helper extension method
            //  to avoid creating duplicate seed data. E.g.
            //
            //    context.People.AddOrUpdate(
            //      p => p.FullName,
            //      new Person { FullName = "Andrew Peters" },
            //      new Person { FullName = "Brice Lambson" },
            //      new Person { FullName = "Rowan Miller" }
            //    );
            //


            Image profileimage     = Image.FromFile(@"D:\profile.jpg");
            Image frontviewimage   = Image.FromFile(@"D:\frontview.jpg");
            Image driverslicense   = Image.FromFile(@"D:\driverslicense.jpg");
            Image proofofownership = Image.FromFile(@"D:\proofofownership.jpg");



            //  This method will be called after migrating to the latest version.

            //  You can use the DbSet<T>.AddOrUpdate() helper extension method
            //  to avoid creating duplicate seed data. E.g.
            //
            Student student = new Student()
            {
                name         = "Iyanda Oladapo Olalekan",
                MatricNumber = 120003,
                Department   = "Mechanical Engineering",
                Email        = "*****@*****.**",
                StudentImage = Helper.imageToByteArray(profileimage),
                Faculty      = "Faculty of Engineering",

                date_created  = DateTime.Now,
                last_modified = DateTime.Now,
            };


            QRCodeGenerator qrGenerator = new QRCodeGenerator();
            QRCodeData      qrCodeData  = qrGenerator.CreateQrCode(student.ToString(), QRCodeGenerator.ECCLevel.Q);

            QRCoder.QRCode qrCode      = new QRCoder.QRCode(qrCodeData);
            Bitmap         qrCodeImage = qrCode.GetGraphic(10);//Set higher to get larger image

            QRCode qrcode = new QRCode()
            {
                QRImage       = Helper.imageToByteArray(qrCodeImage),
                date_created  = DateTime.Now,
                last_modified = DateTime.Now,
                Student       = student
            };



            Vehicle Vehicle = new Vehicle()
            {
                Student         = student,
                Plate_number    = "LAG-0003",
                Drivers_License = Helper.imageToByteArray(driverslicense),
                vehicle_front   = Helper.imageToByteArray(frontviewimage),
                vehicle_back    = Helper.imageToByteArray(frontviewimage),
                vehicle_side    = Helper.imageToByteArray(frontviewimage),
                Make            = "Toyota",
                Color           = "Green",

                date_created       = DateTime.Now,
                last_modified      = DateTime.Now,
                proof_of_ownership = Helper.imageToByteArray(proofofownership),
                Model         = "2017",
                Chasis_number = "MKV 3000 33A 8UJ",
                Year          = "2017"
            };

            Models.Admin admin = new Models.Admin()
            {
                Username = "******",
                Password = "******"
            };

            context.Vehicles.AddOrUpdate(Vehicle);
            context.Students.AddOrUpdate(student);
            context.QRCodes.AddOrUpdate(qrcode);
            context.Admins.AddOrUpdate(admin);
            context.SaveChanges();
        }
コード例 #12
0
        private static List<Admin> AddAdminToList(DataTable dt)
        {
            List<Admin> ls = new List<Admin>();
            try
            {

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    Admin ad = new Admin()
                    {
                        Id = int.Parse(dt.Rows[i]["Id"].ToString()),
                        UserName = dt.Rows[i]["UserName"].ToString(),
                        Password = dt.Rows[i]["Password"].ToString(),
                        FullName = dt.Rows[i]["FullName"].ToString(),
                        Gender = dt.Rows[i]["Gender"].ToString(),
                        Phone = dt.Rows[i]["Phone"].ToString(),
                        Address = dt.Rows[i]["Address"].ToString(),
                        Email = dt.Rows[i]["Email"].ToString(),
                        IsActived = bool.Parse(dt.Rows[i]["IsActived"].ToString()),
                        IsSuperAdmin = bool.Parse(dt.Rows[i]["IsSuperAdmin"].ToString()),

                    };

                    ls.Add(ad);

                }
            }
            catch (Exception)
            {
                return new List<Admin>();
            }
            return ls;
        }