public ActionResult LoginUser(Table_User _userName) { if (ModelState.IsValid) { if (manager.IsUserName(_userName.UserName)) { var pass = manager.GetPassword(_userName.UserName); if (_userName.UserPassword == pass) { FormsAuthentication.SetAuthCookie(_userName.UserName, false); int idUser = ManagerLogin.GetId(_userName.UserName); using (var db = new QuanLyKhoEntities()) { Session["name"] = db.UserProfiles.Find(idUser).Name; } return(RedirectToAction("Index", "Kho_Chua")); } else { ModelState.AddModelError("ErrDN", "Mật khẩu chưa đúng"); } } else { ModelState.AddModelError("ErrDN", "Không tồn tại tài khoản này"); } } return(View("LoginUser", _userName)); }
static void TestDataSetAndOQL(object para) { string sql = "select top 10 * from Table_User"; Table_User user = new Table_User(); user.MapNewTableName("Table_User"); //user.MapNewTableName("Table_User"); OQL qt = new OQL(user); qt.Select().Where(qt.Condition.IN(user.Name, new object[] { "a", "b", "c" })).OrderBy(user.Name); //qt.Select().Where(cmp => cmp.Comparer(user.Name, "in", new string[] { "a", "b", "c" })); //OQL qt = OQL.From(user).Select().END; //qt.TopCount = 10; qt.Limit(10, 10); qt.PageWithAllRecordCount = 0; AdoHelper db = MyDB.GetDBHelper(); //测试下面2种方式对连接数量的影响,经测试,发现 MyDB.Instance 跟 MyDB.GetDBHelper() 没有区别。 //List<Table_User> list = EntityQuery<Table_User>.QueryList(qt); //DataSet ds = MyDB.Instance.ExecuteDataSet(sql); //测试连接会话,下面db的连接会在using 结束后关闭 using (db.OpenSession()) { List <Table_User> list = EntityQuery <Table_User> .QueryList(qt, db); DataSet ds = db.ExecuteDataSet(sql); } }
public bool CreateTablesAndInitialData() { try { int countTableCreationSuccess = 0; var resultTappuser = db.GetTableInfo("Table_User"); if (resultTappuser.Count == 0) { db.CreateTable <Table_User>(); Table_User table_User = new Table_User { Username = "", Password = "" }; var resultDB = db.Insert(table_User); if (resultDB == 1) { countTableCreationSuccess += 1; } } else { countTableCreationSuccess += 1; } var resultTconfig = db.GetTableInfo("Table_Config"); if (resultTconfig.Count == 0) { db.CreateTable <Table_Config>(); Table_Config table_Config = new Table_Config { UrlDomain = "", UrlPrefix = "", FingerPrintAllow = false }; var resultDB = db.Insert(table_Config); if (resultDB == 1) { countTableCreationSuccess += 1; } } else { countTableCreationSuccess += 1; } if (countTableCreationSuccess == 2) { return(true); } else { return(false); } } catch (Exception) { return(false); } }
public ActionResult EditProfileUser(Table_User data) { if (ModelState.IsValid) { Session["U_NAME"] = data.U_Name + data.U_LastName; db.Entry(data).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index", "UserWellcome")); } return(View(data)); }
public ActionResult register(Table_User data) { data.U_TypeID = 1; if (ModelState.IsValid) { db.Table_User.Add(data); db.SaveChanges(); return(RedirectToAction(nameof(Login))); } return(View(data)); }
public UsuarioAM(Table_User usuario) { InitializeComponent(); usuarioDAL = new ManejoUsuarios(); cboPerfiles.DataSource = usuarioDAL.listaPerfiles(); cboPerfiles.DisplayMember = "name"; cboPerfiles.ValueMember = "id"; txtUsuario.Text = usuario.User_Name; txtContrasenia.Text = usuario.User_Password; idUsuario = usuario.ID_User; modificar = true; }
public ActionResult SignUp(Table_User _userName) { if (ModelState.IsValid) { ManagerLogin manager = new ManagerLogin(); manager.AddUser(_userName); return(RedirectToAction("Index", "HangHoa")); } else { return(View()); } }
public async Task <bool> CreateAsyncTablesAndInitialData() { try { int countTableCreationSuccess = 0; var resultTappuser = await dbAsync.GetTableInfoAsync("Table_User"); if (resultTappuser.Count == 0) { await dbAsync.CreateTableAsync <Table_User>(); Table_User table_User = new Table_User { Username = "", Password = "" }; var resultDB = await dbAsync.InsertAsync(table_User); if (resultDB == 1) { countTableCreationSuccess += 1; } } var resultTconfig = await dbAsync.GetTableInfoAsync("Table_Config"); if (resultTconfig.Count == 0) { await dbAsync.CreateTableAsync <Table_Config>(); Table_Config table_Config = new Table_Config { UrlDomain = "", UrlPrefix = "", FingerPrintAllow = false }; var resultDB = await dbAsync.InsertAsync(table_Config); if (resultDB == 1) { countTableCreationSuccess += 1; } } if (countTableCreationSuccess == 2) { return(true); } else { return(false); } } catch (Exception) { return(false); } }
public ActionResult Register(Table_User user) { if (db.Table_User.Any(x => x.UserName == user.UserName)) { ViewBag.Notification = "This User is already existed"; return(View()); } else { TempData["RegisterMessage"] = "<script>alert('User Register successfully')</script>"; db.Table_User.Add(user); db.SaveChanges(); return(RedirectToAction("Signin", "User")); } }
public static Table_User init(List <Object> data) { Table_User table = new Table_User(); table.id = (int)data[0]; table.account = data[1].ToString(); table.password = data[2].ToString(); table.phone = data[3].ToString(); table.zhanshilevel = (int)data[4]; table.fashilevel = (int)data[5]; table.huanshilevel = (int)data[6]; table.createtime = data[7].ToString(); return(table); }
static void OQLAvgTest() { Table_User user = new Table_User(); OQL q = OQL.From(user) .Select().Avg(user.Height, "AvgHeight") .GroupBy(user.Sex) .END; EntityContainer ec = new EntityContainer(q); var result = ec.MapToList(() => new { //获取聚合函数的值,用下面一行代码的方式 AvgHeight = ec.GetItemValue <double>("AvgHeight"), Sex = user.Sex ?"男":"女" }); Console.WriteLine("get AVG record count:" + result.Count); }
public bool AgregarUsuario(string userName, string userPassword, string userPasswordComprobar) { if (userPassword.Equals(userPasswordComprobar)) { var table_User = new Table_User(); table_User.User_Name = userName; table_User.User_Password = userPassword; var resultado = db.Table_User.Add(table_User); db.SaveChanges(); return true; } else return false; }
public ActionResult Create(Table_User user) { if (ModelState.IsValid == true) { db.Table_User.Add(user); int a = db.SaveChanges(); if (a > 0) { TempData["InsertMessage"] = "<script>alert('Data Inserted successfully!!')</script>"; return(RedirectToAction("Index")); } else { TempData["InsertMessage"] = "<script>alert(' Not Inserted!!')</script>"; } } return(View()); }
public ActionResult Signin(Table_User user) { var checklogin = db.Table_User.Where(x => x.UserName.Equals(user.UserName) && x.Password.Equals(user.Password)).FirstOrDefault(); if (checklogin != null) { Session["UId"] = user.UserId.ToString(); Session["UName"] = user.UserName.ToString(); TempData["SigninMessage"] = "<script>alert('User Signin successfully')</script>"; return(RedirectToAction("Seat_Menu", "Seats")); } else { ViewBag.Notification = "Incorrect Username or Password"; } return(View()); }
public ActionResult Register(Table_User user) { if (ModelState.IsValid) { if (manager.IsExitstUserName(user.UserName)) { ModelState.AddModelError(user.UserName, "Tên tài khoản đã tồn tại"); } else { if (manager.AddUser(user)) { FormsAuthentication.SetAuthCookie(user.UserName, false); return(RedirectToAction("Index", "Dienthoais")); } } } return(View(user)); }
public ActionResult CreateUserByAdmin(User _user) { using (var db = new QuanLyKhoEntities()) { ViewBag.Role = db.Table_Role.ToList(); ManagerLogin managerLogin = new ManagerLogin(); if (ModelState.IsValid) { if (managerLogin.IsExitsUserToSignUp(_user.UserName)) { Response.Write("<script>alert('Đã tồn tại tài khoản')</script>"); } else { try { var tbl_user = new Table_User(); tbl_user.UserName = _user.UserName; tbl_user.UserPassword = _user.UserPassword; db.Table_User.Add(tbl_user); db.SaveChanges(); var userRole = new UserRole(); userRole.UserId = tbl_user.UserId; userRole.RoleId = _user.Role; userRole.IsActive = true; db.UserRoles.Add(userRole); db.SaveChanges(); var userProfile = new UserProfile(); userProfile.UserId = tbl_user.UserId; userProfile.Name = _user.Name; // db.UserProfiles.Add(userProfile); db.SaveChanges(); } catch { Response.Write("<script>alert('Lỗi submit')</script>"); } } } } return(View()); }
public async Task <bool> PullAsyncProbatchCredentials(Table_User table_User) { try { var result = await dbAsync.UpdateAsync(table_User); if (result == 1) { return(true); } else { return(false); } } catch (Exception) { return(false); } }
public bool AddUser(Table_User user) { using (DienThoaiDBEntities db = new DienThoaiDBEntities()) { using (var trans = db.Database.BeginTransaction()) { try { db.Table_User.Add(user); db.SaveChanges(); trans.Commit(); return(true); } catch { trans.Rollback(); return(false); } } } }
public void AddUser(Table_User _user) { if (_user.UserName.Length > 0 && _user.UserPassword.Length > 0) { using (QuanLyKhoEntities db = new QuanLyKhoEntities()) { using (var dbTran = db.Database.BeginTransaction()) { try { db.Table_User.Add(_user); db.SaveChanges(); dbTran.Commit(); } catch (Exception) { dbTran.Rollback(); } } } } }
public ActionResult UpdateUser([Bind(Exclude = "last_update_date")] Table_User user) { try { if (ModelState.IsValid) { using (var context = new ResumeModel()) { context.Entry(user).State = EntityState.Modified; user.last_update_date = DateTime.Now; context.SaveChanges(); } ViewBag.Message = "Profile updated successfully/ 賬號修改成功"; } } catch (Exception ex) { ViewBag.Message = "Error in updating profile"; } return(View("Home")); }
public ActionResult Login(Table_User data) { var CKMAILL = db.Table_User.Where(a => a.U_EmailID == data.U_EmailID).FirstOrDefault(); var CKPASS = db.Table_User.Where(a => a.U_Password == data.U_Password).FirstOrDefault(); Session["typeid"] = 111; if (CKMAILL == null) { ModelState.AddModelError("U_EmailID", "ไม่พบข้อมูลอีเมลล์ของคุณ"); } else if (CKMAILL != null) { if (CKPASS == null) { ModelState.AddModelError("U_Password", "รหัสผ่านของคุณผิด"); } else { if (CKMAILL.U_TypeID == 1) { Session["U_EMAIL"] = CKMAILL.U_EmailID; Session["U_NAME"] = CKMAILL.U_Name + CKMAILL.U_LastName; Session["typeid"] = 1; AddOrder(CKMAILL.U_EmailID, CKMAILL.U_TypeID); return(RedirectToAction("Index", "UserWellcome")); } else { Session["U_EMAIL"] = CKMAILL.U_EmailID; Session["typeid"] = 2; Session["U_NAME"] = CKMAILL.U_Name + CKMAILL.U_LastName; return(RedirectToAction("Index", "Movie")); } } } return(View(data)); }
public ActionResult Index(Table_User user) { if (manager.IsExitstUserName(user.UserName)) { if (user.UserPassword == manager.GetPassword(user.UserName)) { FormsAuthentication.SetAuthCookie(user.UserName, false); return(RedirectToAction("Index", "Dienthoais")); } else { ModelState.AddModelError("errorPass", "Nhập sai Password"); } } else { ModelState.AddModelError("errorPass", "Không tồn tại tài khoản"); } return(View(user)); }
static void Main(string[] args) { Console.WriteLine("====**************** PDF.NET SOD 控制台测试程序 **************===="); Assembly coreAss = Assembly.GetAssembly(typeof(AdoHelper));//获得引用程序集 Console.WriteLine("框架核心程序集 PWMIS.Core Version:{0}", coreAss.GetName().Version.ToString()); Console.WriteLine(); Console.WriteLine(" 应用程序配置文件默认的数据库配置信息:\r\n 当前使用的数据库类型是:{0}\r\n 连接字符串为:{1}\r\n 请确保数据库服务器和数据库是否有效且已经初始化过建表脚本(项目下的2个sql脚本文件),\r\n继续请回车,退出请输入字母 Q ." , MyDB.Instance.CurrentDBMSType.ToString(), MyDB.Instance.ConnectionString); Console.WriteLine("=====Power by Bluedoctor,2015.2.8 http://www.pwmis.com/sqlmap ===="); string read = Console.ReadLine(); if (read.ToUpper() == "Q") { return; } Console.WriteLine("当前机器的分布式ID:{0}", CommonUtil.CurrentMachineID()); Console.WriteLine("测试分布式ID:秒级有序"); for (int i = 0; i < 50; i++) { Console.Write(CommonUtil.NewSequenceGUID()); Console.Write(","); } Console.WriteLine(); Console.WriteLine("测试分布式ID:唯一且有序"); for (int i = 0; i < 20000; i++) { long seq = CommonUtil.NewUniqueSequenceGUID(); if (i <= 50) { Console.Write(CommonUtil.NewUniqueSequenceGUID()); Console.Write(","); } } Console.WriteLine(); IDataParameter[] paraArr = new IDataParameter[] { MyDB.Instance.GetParameter("P1", 111), MyDB.Instance.GetParameter("P2", "abc'ee<edde/>e"), MyDB.Instance.GetParameter("P3", DBNull.Value), }; string str = DbParameterSerialize.Serialize(paraArr); Console.WriteLine("测试参数序列化:{0}", str); IDataParameter[] paraArr2 = DbParameterSerialize.DeSerialize(str, MyDB.Instance); Console.WriteLine("测试反序列化成功!"); LocalDbContext localDb = new LocalDbContext(); var entitys = localDb.ResolveAllEntitys(); localDb.CurrentDataBase.RegisterCommandHandle(new TransactionLogHandle()); Table_User user = new Table_User(); user.Name = "zhang san"; user.Height = 1.8f; user.Birthday = new DateTime(1980, 1, 1); user.Sex = true; localDb.Add(user); user.Name = "lisi"; user.Height = 1.6f; user.Birthday = new DateTime(1982, 3, 1); user.Sex = false; localDb.Add(user); Console.WriteLine("测试 生成事务日志 成功!(此操作将写入事务日志信息到数据库中。)"); //var logList = localDb.QueryList<MyCommandLogEntity>(OQL.From(new MyCommandLogEntity()).Select().END); AdoHelper db = MyDB.GetDBHelperByConnectionName("local"); var logList = OQL.From <MyCommandLogEntity>().Select().END.ToList(db); foreach (MyCommandLogEntity log in logList) { var paras = DbParameterSerialize.DeSerialize(log.ParameterInfo, db); int count = db.ExecuteNonQuery(log.CommandText, log.CommandType, paras); Console.WriteLine("执行语句:{0} \r\n 受影响行数:{1}", log.CommandText, count); } Console.WriteLine("测试 运行事务日志 成功!(此操作将事务日志的操作信息回放执行。)"); //写入10000条日志,有缓存,可能不会写完 Console.WriteLine("测试日志写入10000 条信息..."); CommandLog loger = new CommandLog(); for (int t = 0; t <= 1; t++) { System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(WriteLog)); thread.Name = "thread" + t; thread.Start(loger); } loger.Flush(); Console.WriteLine("按任意键继续"); Console.ReadLine(); EntityUser etu = new EntityUser(); ITable_User itu = etu.AsEntity(); DateTime dtt = itu.Birthday; //测试 AdoHelper的并发能力 //for (int i = 0; i < 100; i++) //{ // System.Threading.Thread t = new System.Threading.Thread( // new System.Threading.ParameterizedThreadStart(TestDataSetAndOQL)); // t.Name = "thread "+i; // t.Start(); //} //测试生成列的脚本 EntityCommand ecmd = new EntityCommand(new Table_User(), new SqlServer()); string table_script = ecmd.CreateTableCommand; Console.Write("1,测试 OpenSession 长连接数据库访问..."); TestDataSetAndOQL(null); Console.WriteLine("OK"); // Console.WriteLine("2,测试OQL 转SQL..."); RoadTeam.Model.CS.TbCsEvent CsEvent = new RoadTeam.Model.CS.TbCsEvent(); CsEvent.EventID = 1; OQL oql = OQL.From(CsEvent) .Select(CsEvent.EventCheck, CsEvent.EventCheckInfo, CsEvent.EventCheckor, CsEvent.EventCheckTime) .Where(CsEvent.EventID) .END; Console.WriteLine(oql.ToString()); Console.WriteLine("-----------------------"); RoadTeam.Model.CS.TbCsEvent CsEvent2 = new RoadTeam.Model.CS.TbCsEvent(); CsEvent.EventID = 1; OQL oql2 = OQL.From(CsEvent2) .Select(true, CsEvent2.EventCheck, CsEvent2.EventCheckInfo, CsEvent2.EventCheckor, CsEvent2.EventCheckTime) .Where(CsEvent2.EventID) .END; Console.WriteLine(oql2.ToString()); Console.WriteLine("-----------------------"); Console.WriteLine("OK"); // Console.Write("3,测试实体类动态增加虚拟属性..."); UserModels um1 = new UserModels(); um1.AddPropertyName("TestName"); um1["TestName"] = 123; int testi = (int)um1["TestName"]; um1["TestName"] = "abc"; string teststr = (string)um1["TestName"]; Console.WriteLine("OK"); // Console.Write("4,测试缓存..."); var cache = PWMIS.Core.MemoryCache <EntityBase> .Default; cache.Add("UserModels", um1); var cacheData = cache.Get("UserModels"); cache.Remove("UserModels"); Console.WriteLine("OK"); // Console.Write("5,测试自动创建实体类数据库表..."); AutoCreateEntityTable <LT_Users>(); AutoCreateEntityTable <LT_UserRoles>(); Console.WriteLine("OK"); Console.WriteLine("------------测试暂时停止,回车继续运行------"); Console.ReadLine(); //return; Console.Write("6,测试实体类的外键查询..."); TestEntityFK(); Console.WriteLine("OK"); Console.Write("7,测试实体类批量插入..."); OqlInTest(); Console.WriteLine("OK"); Console.WriteLine("8,测试SOD POCO实体类性能..."); Console.WriteLine("SELECT top 100000 UID,Sex,Height,Birthday,Name FROM Table_User"); for (int i = 0; i < 10; i++) { Console.WriteLine("-------------Testt No.{0}----------------", i + 1); TestPocoQuery(); } Console.WriteLine("--------OK---------------"); Console.Write("9,测试OQL IN 子查询..."); TestInChild(); Console.WriteLine("OK"); //TestFun(1, 2, 3); Console.WriteLine("10,测试泛型 OQL --GOQL"); TestGOQL(); Console.WriteLine("OK"); Console.WriteLine("11,测试OQL 批量更新(带条件更新)..."); UpdateTest(); Console.WriteLine("OK"); Console.WriteLine("12,测试批量数据插入性能...."); //InsertTest(); Console.WriteLine("13,OQL 自连接..."); OqlJoinTest(); // Console.Write("14,根据接口类型,自动创建实体类测试..."); TestDynamicEntity(); Console.WriteLine("OK"); // Console.WriteLine("15,Sql 格式化查询测试( SOD 微型ORM功能)..."); AdoHelper dbLocal = new SqlServer(); dbLocal.ConnectionString = MyDB.Instance.ConnectionString; //DataSet ds = dbLocal.ExecuteDataSet("SELECT * FROM Table_User WHERE UID={0} AND Height>={1:5.2}", 1, 1.80M); /* * 下面的写法过时 * var dataList = dbLocal.GetList(reader => * { * return new * { * UID=reader.GetInt32(0), * Name=reader.GetString(1) * }; * }, "SELECT UID,Name FROM Table_User WHERE Sex={0} And Height>={0:5.2}",1, 1.60); */ var dataList = dbLocal.ExecuteMapper("SELECT UID,Name FROM Table_User WHERE Sex={0} And Height>={1:5.2}", 1, 1.60) .MapToList(reader => new { UID = reader.GetInt32(0), Name = reader.GetString(1) }); Console.WriteLine("OK"); // Console.Write("16,测试属性拷贝..."); V_UserModels vum = new V_UserModels(); vum.BIGTEAM_ID = 123;//可空属性,如果目标对象不是的话,无法拷贝 vum.REGION_ID = 456; vum.SMALLTEAM_ID = 789; UserModels um = vum.CopyTo <UserModels>(); Console.WriteLine("OK"); // Console.Write("17,测试【自定义查询】的实体类..."); UserPropertyView up = new UserPropertyView(); OQL q11 = new OQL(up); OQLOrder order = new OQLOrder(q11); q11.Select() .Where(q11.Condition.AND(up.PropertyName, "=", "总成绩").AND(up.PropertyValue, ">", 1000)) .OrderBy(order.Asc(up.UID)); AdoHelper db11 = MyDB.GetDBHelperByConnectionName("local"); var result = EntityQuery <UserPropertyView> .QueryList(q11, db11); //下面2行不是必须 q11.Dispose(); Console.WriteLine("OK"); //EntityContainer ec = new EntityContainer(q11); //var ecResult = ec.MapToList(() => { // return new { AAA = ec.GetItemValue<int>(0), BBB = ec.GetItemValue<string>(1) }; //}); ///////////////////////////////////////////////////// Console.WriteLine("18,测试实体类【自动保存】数据..."); TestAutoSave(); Console.WriteLine("19,测试OQL上使用聚合函数..."); OQLAvgTest(); /////////////////测试事务//////////////////////////////////// Console.WriteLine("20,测试测试事务..."); TestTransaction(); TestTransaction2(); Console.WriteLine("事务测试完成!"); Console.WriteLine("-------PDF.NET SOD 测试全部完成-------"); Console.ReadLine(); }
private async void FingerPrint() { try { ApiSrv = new Services.ApiService(ApiConsult.ApiAuth); RefreshAppConfig(); var request = new AuthenticationRequestConfiguration("Autenticación Biométrica", "ProBatch Mobile 2.0"); var result = await CrossFingerprint.Current.AuthenticateAsync(request); if (!result.Authenticated) { return; } UserDialogs.Instance.ShowLoading("Iniciando sesión...", MaskType.Black); Table_User tableUserFingerPrint = await DBHelper.GetAsyncProbatchCredentials(); if (tableUserFingerPrint == null) { UserDialogs.Instance.HideLoading(); Toast.ShowError("No se pudo obtener las credenciales de ProBatch"); return; } try { Response resultApiIsAvailable = await ApiSrv.ApiIsAvailable(); if (!resultApiIsAvailable.IsSuccess) { UserDialogs.Instance.HideLoading(); Toast.ShowError(resultApiIsAvailable.Message); return; } Response resultToken = await ApiSrv.GetToken(); if (!resultToken.IsSuccess) { UserDialogs.Instance.HideLoading(); Toast.ShowError(resultToken.Message); return; } else { Token token = JsonConvert.DeserializeObject <Token>(Crypto.DecodeString(resultToken.Data)); LoginPb loginPb = new LoginPb { Username = Crypto.DecodeString(tableUserFingerPrint.Username), Password = Crypto.DecodeString(tableUserFingerPrint.Password) }; Response resultLoginProbatch = await ApiSrv.AuthenticateProbath(token.Key, loginPb); if (!resultLoginProbatch.IsSuccess) { UserDialogs.Instance.HideLoading(); Toast.ShowError(resultLoginProbatch.Message); return; } else { PbUser = JsonConvert.DeserializeObject <PbUser>(Crypto.DecodeString(resultLoginProbatch.Data)); if (!PbUser.IsValid) { UserDialogs.Instance.HideLoading(); bool deleteFingerPrintRegister = await UserDialogs.Instance.ConfirmAsync("Credenciales inválidas, deseas eliminar el registro biométrico?", "AST●ProBatch®", "Si", "No"); if (deleteFingerPrintRegister) { IsChecked = false; Table_Config table_Config = new Table_Config { Id = 1, UrlDomain = this.UrlDomain, UrlPrefix = this.UrlPrefix, FingerPrintAllow = IsChecked }; if (!await DBHelper.PullAsyncAppConfig(table_Config)) { Toast.ShowError("No se pudo actualizar la configuración."); return; } else { Table_User table_User = new Table_User { Id = 1, Username = string.Empty, Password = string.Empty }; if (!await DBHelper.PullAsyncProbatchCredentials(table_User)) { Toast.ShowError("No se pudo actualizar la configuración."); return; } else { IsVisibleLogin = true; IsVisibleFingerPrint = false; } } return; } } else { if (!IsChecked) { Table_Config table_Config = new Table_Config { Id = 1, UrlDomain = this.UrlDomain, UrlPrefix = this.UrlPrefix, FingerPrintAllow = this.IsChecked }; if (!await DBHelper.PullAsyncAppConfig(table_Config)) { Toast.ShowError("No se pudo actualizar la configuración."); return; } else { Table_User table_User = new Table_User { Id = 1, Username = string.Empty, Password = string.Empty }; if (!await DBHelper.PullAsyncProbatchCredentials(table_User)) { Toast.ShowError("No se pudo actualizar la configuración."); return; } else { IsVisibleLogin = true; IsVisibleFingerPrint = false; } } } UserDialogs.Instance.HideLoading(); this.Username = string.Empty; this.Password = string.Empty; MainViewModel.GetInstance().Home = new HomeViewModel(); Application.Current.MainPage = new NavigationPage(new HomePage()); Alert.Show("Bienvenido: " + PbUser.FisrtName.Trim() + ", " + PbUser.LastName.Trim() + "!", "Continuar"); } } } } catch //(Exception ex) { UserDialogs.Instance.HideLoading(); Toast.ShowError("Ocurrió un error."); return; } } catch //(Exception ex) { Toast.ShowError("Ocurrió un error datos locales."); return; } }
private async void Login() { if (string.IsNullOrEmpty(this.Username)) { Alert.Show("Debe ingresar un usuario"); return; } if (string.IsNullOrEmpty(this.Password)) { Alert.Show("Debe ingresar una contraseña"); return; } if (IsChecked) { if (!IsFingerPrintAvailable) { Alert.Show("Sensor de huella no disponible o no configurado."); IsChecked = false; return; } else { var request = new AuthenticationRequestConfiguration("Autenticación Biométrica", "ProBatch Mobile 2.0"); var result = await CrossFingerprint.Current.AuthenticateAsync(request); if (!result.Authenticated) { this.Username = string.Empty; this.Password = string.Empty; IsChecked = false; return; } } } ApiSrv = new Services.ApiService(ApiConsult.ApiAuth); RefreshAppConfig(); try { UserDialogs.Instance.ShowLoading("Iniciando sesión...", MaskType.Black); Response resultApiIsAvailable = await ApiSrv.ApiIsAvailable(); if (!resultApiIsAvailable.IsSuccess) { UserDialogs.Instance.HideLoading(); Toast.ShowError(resultApiIsAvailable.Message); return; } Response resultToken = await ApiSrv.GetToken(); if (!resultToken.IsSuccess) { UserDialogs.Instance.HideLoading(); Toast.ShowError(resultToken.Message); return; } else { Token token = JsonConvert.DeserializeObject <Token>(Crypto.DecodeString(resultToken.Data)); LoginPb loginPb = new LoginPb { Username = this.Username, Password = this.Password }; Response resultLoginProbatch = await ApiSrv.AuthenticateProbath(token.Key, loginPb); if (!resultLoginProbatch.IsSuccess) { UserDialogs.Instance.HideLoading(); Toast.ShowError(resultLoginProbatch.Message); return; } else { PbUser = JsonConvert.DeserializeObject <PbUser>(Crypto.DecodeString(resultLoginProbatch.Data)); if (!PbUser.IsValid) { UserDialogs.Instance.HideLoading(); //Alert.Show("Usuario y/o Password incorrectos"); this.IsEnabled = false; this.IsEnabled = true; return; } else { if (IsChecked) { Table_Config table_Config = new Table_Config { Id = 1, UrlDomain = this.UrlDomain, UrlPrefix = this.UrlPrefix, FingerPrintAllow = this.IsChecked }; if (!await DBHelper.PullAsyncAppConfig(table_Config)) { UserDialogs.Instance.HideLoading(); Toast.ShowError("No se pudo actualizar la configuración."); return; } else { Table_User table_User = new Table_User { Id = 1, Username = Crypto.EncryptString(this.Username), Password = Crypto.EncryptString(this.Password) }; if (!await DBHelper.PullAsyncProbatchCredentials(table_User)) { UserDialogs.Instance.HideLoading(); Toast.ShowError("No se pudo actualizar la configuración."); return; } else { IsVisibleLogin = false; IsVisibleFingerPrint = true; } } } UserDialogs.Instance.HideLoading(); this.Username = string.Empty; this.Password = string.Empty; MainViewModel.GetInstance().Home = new HomeViewModel(); Application.Current.MainPage = new NavigationPage(new HomePage()); Alert.Show("Bienvenido: " + PbUser.FisrtName.Trim() + ", " + PbUser.LastName.Trim() + "!", "Continuar"); } } } } catch //(Exception ex) { UserDialogs.Instance.HideLoading(); Toast.ShowError("Ocurrió un error."); return; } }
public static void Do(ClientInfo clientInfo, string data) { S2C_Register s2c = new S2C_Register(); s2c.Tag = CSParam.NetTag.Register.ToString(); s2c.Code = (int)CSParam.CodeType.Ok; try { C2S_Register c2s = JsonConvert.DeserializeObject <C2S_Register>(data); string account = c2s.Account; string password = c2s.Password; // 先查询这个账号是否存在 List <KeyData> keylist = new List <KeyData>() { new KeyData("account", account) }; MySqlUtil.getInstance().addCommand(CmdType.query, "user", keylist, null, (CmdReturnData cmdReturnData) => { if (cmdReturnData.result == CmdResult.OK) { List <Object> list = cmdReturnData.listData; // 已存在,注册失败 if (list != null && list.Count > 0) { s2c.Code = (int)CSParam.CodeType.RegisterFail_Exist; Socket_S.getInstance().Send(clientInfo, s2c); } // 不存在,先插入数据 else { List <KeyData> keylist2 = new List <KeyData>() { new KeyData("account", account), new KeyData("password", password) }; MySqlUtil.getInstance().addCommand(CmdType.insert, "user", null, keylist2, (CmdReturnData cmdReturnData2) => { if (cmdReturnData2.result == CmdResult.OK) { // 插完数据后再查询该账号,返回userId MySqlUtil.getInstance().addCommand(CmdType.query, "user", keylist, null, (CmdReturnData cmdReturnData3) => { if (cmdReturnData3.result == CmdResult.OK) { List <Object> list3 = cmdReturnData3.listData; if (list3 != null && list3.Count > 0) { Table_User table_User = Table_User.init(list3); s2c.Code = (int)CSParam.CodeType.Ok; s2c.UserId = table_User.id; Socket_S.getInstance().Send(clientInfo, s2c); } else { CommonUtil.Log("插入新用户数据后查询不到:account=" + account); s2c.Code = (int)CSParam.CodeType.ServerError; Socket_S.getInstance().Send(clientInfo, s2c); } } else { s2c.Code = (int)CSParam.CodeType.ServerError; Socket_S.getInstance().Send(clientInfo, s2c); } }); } // 插入新用户数据失败 else { CommonUtil.Log("插入新用户数据失败:account=" + account); s2c.Code = (int)CSParam.CodeType.ServerError; Socket_S.getInstance().Send(clientInfo, s2c); } }); } } else { s2c.Code = (int)CSParam.CodeType.ServerError; Socket_S.getInstance().Send(clientInfo, s2c); return; } }); } catch (Exception ex) { s2c.Code = (int)CSParam.CodeType.ParamError; Socket_S.getInstance().Send(clientInfo, s2c); } }