public static ProfilePhone ToProfilePhone(ProfileLocal profile) { return(new ProfilePhone { Name = profile.ProfileName, Number = profile.value, Exist = profile.Exist, ProfilePhoneId = profile.ProfileId, UserId = profile.UserId }); }
public static ProfileWhatsapp ToProfileWhatsapp(ProfileLocal profile) { return(new ProfileWhatsapp { Exist = profile.Exist, Number = profile.value, Name = profile.ProfileName, ProfileWhatsappId = profile.ProfileId, UserId = profile.UserId }); }
public static ProfileEmail ToProfileEmail(ProfileLocal profile) { return(new ProfileEmail { Name = profile.ProfileName, Email = profile.value, Exist = profile.Exist, ProfileEmailId = profile.ProfileId, UserId = profile.UserId }); }
public static ProfileSM ToProfileSM(ProfileLocal profile) { return(new ProfileSM { Exist = profile.Exist, link = profile.value, ProfileMSId = profile.ProfileId, ProfileName = profile.ProfileName, RedSocialId = profile.RedSocialId, UserId = profile.UserId }); }
public void removeProfilePhone(ProfilePhone _profilePhone) { ProfileLocal P = Converter.ToProfileLocalP(_profilePhone); ProfileLocal Aux = new ProfileLocal(); foreach (ProfileLocal PLocal in ProfilePerfiles) { if (P.ProfileName == PLocal.ProfileName && P.value == PLocal.value) { Aux = PLocal; } } ProfilePerfiles.Remove(Aux); var A = ProfilePerfiles.Count; }
public void removeProfileEmail(ProfileEmail _profileEmail) { ProfileLocal E = Converter.ToProfileLocalE(_profileEmail); ProfileLocal Aux = new ProfileLocal(); foreach (ProfileLocal PLocal in ProfilePerfiles) { if (E.ProfileName == PLocal.ProfileName && E.value == PLocal.value) { Aux = PLocal; } } ProfilePerfiles.Remove(Aux); var A = ProfilePerfiles.Count; }
public void removeProfileW(ProfileWhatsapp _profileW) { ProfileLocal W = Converter.ToProfileLocalW(_profileW); ProfileLocal Aux = new ProfileLocal(); foreach (ProfileLocal PLocal in ProfilePerfiles) { if (W.ProfileName == PLocal.ProfileName && W.value == PLocal.value) { Aux = PLocal; } } ProfilePerfiles.Remove(Aux); var A = ProfilePerfiles.Count; }
public void removeProfileSM(ProfileSM _profileSM) { ProfileLocal SM = Converter.ToProfileLocalSM(_profileSM); ProfileLocal Aux = new ProfileLocal(); foreach (ProfileLocal PLocal in ProfilePerfiles) { if (SM.ProfileName == PLocal.ProfileName && SM.value == PLocal.value) { Aux = PLocal; } } ProfilePerfiles.Remove(Aux); var A = ProfilePerfiles.Count; }
public void updateProfileEmail(ProfileEmail _profileEmail) { ProfileLocal E = Converter.ToProfileLocalE(_profileEmail); ProfileLocal Aux = new ProfileLocal(); int newIndex = 0; foreach (ProfileLocal PLocal in ProfilePerfiles) { if (E.ProfileName == PLocal.ProfileName && E.value == PLocal.value) { Aux = PLocal; newIndex = ProfilePerfiles.IndexOf(PLocal); } } ProfilePerfiles.Remove(Aux); ProfilePerfiles.Insert(newIndex, E); }
public void updateProfileWhatsapp(ProfileWhatsapp _profileW) { ProfileLocal W = Converter.ToProfileLocalW(_profileW); ProfileLocal Aux = new ProfileLocal(); int newIndex = 0; foreach (ProfileLocal PLocal in ProfilePerfiles) { if (W.ProfileName == PLocal.ProfileName && W.value == PLocal.value) { Aux = PLocal; newIndex = ProfilePerfiles.IndexOf(PLocal); } } ProfilePerfiles.Remove(Aux); ProfilePerfiles.Insert(newIndex, W); }
public void updateProfileSM(ProfileSM _profileSM) { ProfileLocal SM = Converter.ToProfileLocalSM(_profileSM); ProfileLocal Aux = new ProfileLocal(); int newIndex = 0; foreach (ProfileLocal PLocal in ProfilePerfiles) { if (SM.ProfileName == PLocal.ProfileName && SM.value == PLocal.value) { Aux = PLocal; newIndex = ProfilePerfiles.IndexOf(PLocal); } } ProfilePerfiles.Remove(Aux); ProfilePerfiles.Insert(newIndex, SM); }
public void updateProfilePhone(ProfilePhone _profileP) { ProfileLocal P = Converter.ToProfileLocalP(_profileP); ProfileLocal Aux = new ProfileLocal(); int newIndex = 0; foreach (ProfileLocal PLocal in ProfilePerfiles) { if (P.ProfileName == PLocal.ProfileName && P.value == PLocal.value) { Aux = PLocal; newIndex = ProfilePerfiles.IndexOf(PLocal); } } ProfilePerfiles.Remove(Aux); ProfilePerfiles.Insert(newIndex, P); }
public void addProfile(ProfileLocal _profileSelected) { ProfilesSelected.Add(_profileSelected); }
public ObservableCollection <ProfileLocal> DataFill(ForeingBox _foreingBox) { ProfilesF = new ObservableCollection <ProfileLocal>(); List <ForeingProfile> foreingProfileList; using (var conn = new SQLite.SQLiteConnection(App.root_db)) { foreingProfileList = conn.Query <ForeingProfile>("Select * from ForeingProfile where ForeingProfile.BoxId = ?", _foreingBox.BoxId); } foreach (ForeingProfile Pro in foreingProfileList) { string Image = string.Empty; if (_foreingBox.UserRecivedId == MainViewModel.GetInstance().User.UserId) { switch (Pro.ProfileType) { case "Email": Image = "mail2"; break; case "Phone": Image = "tel2"; break; case "Facebook": Image = "facebook2"; break; case "Instagram": Image = "instagramlogo2"; break; case "Twitter": Image = "twitterlogo2"; break; case "Snapchat": Image = "snapchat2"; break; case "LinkedIn": Image = "linkedin2"; break; case "TikTok": Image = "tiktok2"; break; case "Youtube": Image = "youtube2"; break; case "Spotify": Image = "spotify2"; break; case "Twitch": Image = "twitch2"; break; case "WebPage": Image = "gmail2"; break; case "Whatsapp": Image = "whatsapp2"; break; case "Telegram": Image = "telegram2"; break; default: break; } ProfileLocal Local = new ProfileLocal { IdBox = Pro.BoxId, UserId = Pro.UserId, ProfileName = Pro.ProfileName, value = Pro.value, ProfileType = Pro.ProfileType, Logo = Image, }; ProfilesF.Add(Local); } } return(ProfilesF); }
void OnListViewItemSelected(object sender, SelectedItemChangedEventArgs e) { selectedItemProfile = e.SelectedItem as ProfileLocal; }
void OnListViewItemTapped(object sender, ItemTappedEventArgs e) { ProfileLocal tappedItemProfile = e.Item as ProfileLocal; switch (tappedItemProfile.Logo) { case "mail2": ProfileEmail E = Converter.ToProfileEmail(tappedItemProfile); if (E.Exist == false) { PostProfileEmail(Box.BoxId, E.ProfileEmailId); E.Exist = true; MainViewModel.GetInstance().ListOfNetworks.updateProfileEmail(E); MainViewModel.GetInstance().DetailsBox.addProfileEmail(E); } else { DeleteProfileEmail(Box.BoxId, E.ProfileEmailId); E.Exist = false; MainViewModel.GetInstance().ListOfNetworks.updateProfileEmail(E); MainViewModel.GetInstance().DetailsBox.removeProfileEmail(E); } break; case "tel2": ProfilePhone P = Converter.ToProfilePhone(tappedItemProfile); if (P.Exist == false) { PostProfilePhone(Box.BoxId, P.ProfilePhoneId); P.Exist = true; MainViewModel.GetInstance().ListOfNetworks.updateProfilePhone(P); MainViewModel.GetInstance().DetailsBox.addProfilePhone(P); } else { DeleteProfilePhone(Box.BoxId, P.ProfilePhoneId); P.Exist = false; MainViewModel.GetInstance().ListOfNetworks.updateProfilePhone(P); MainViewModel.GetInstance().DetailsBox.removeProfilePhone(P); } break; case "facebook2": ProfileSM SMfb = Converter.ToProfileSM(tappedItemProfile); if (SMfb.Exist == false) { PostProfileSM(Box.BoxId, SMfb.ProfileMSId); SMfb.Exist = true; MainViewModel.GetInstance().ListOfNetworks.updateProfileSM(SMfb); MainViewModel.GetInstance().DetailsBox.addProfileSM(SMfb); } else { DeleteProfileSM(Box.BoxId, SMfb.ProfileMSId); SMfb.Exist = false; MainViewModel.GetInstance().ListOfNetworks.updateProfileSM(SMfb); MainViewModel.GetInstance().DetailsBox.removeProfileSM(SMfb); } break; case "twitterlogo2": ProfileSM SMtwtt = Converter.ToProfileSM(tappedItemProfile); if (SMtwtt.Exist == false) { PostProfileSM(Box.BoxId, SMtwtt.ProfileMSId); SMtwtt.Exist = true; MainViewModel.GetInstance().ListOfNetworks.updateProfileSM(SMtwtt); MainViewModel.GetInstance().DetailsBox.addProfileSM(SMtwtt); } else { DeleteProfileSM(Box.BoxId, SMtwtt.ProfileMSId); SMtwtt.Exist = false; MainViewModel.GetInstance().ListOfNetworks.updateProfileSM(SMtwtt); MainViewModel.GetInstance().DetailsBox.removeProfileSM(SMtwtt); } break; case "instagramlogo2": ProfileSM SMIns = Converter.ToProfileSM(tappedItemProfile); if (SMIns.Exist == false) { PostProfileSM(Box.BoxId, SMIns.ProfileMSId); SMIns.Exist = true; MainViewModel.GetInstance().ListOfNetworks.updateProfileSM(SMIns); MainViewModel.GetInstance().DetailsBox.addProfileSM(SMIns); } else { DeleteProfileSM(Box.BoxId, SMIns.ProfileMSId); SMIns.Exist = false; MainViewModel.GetInstance().ListOfNetworks.updateProfileSM(SMIns); MainViewModel.GetInstance().DetailsBox.removeProfileSM(SMIns); } break; case "snapchat2": ProfileSM SMSnap = Converter.ToProfileSM(tappedItemProfile); if (SMSnap.Exist == false) { PostProfileSM(Box.BoxId, SMSnap.ProfileMSId); SMSnap.Exist = true; MainViewModel.GetInstance().ListOfNetworks.updateProfileSM(SMSnap); MainViewModel.GetInstance().DetailsBox.addProfileSM(SMSnap); } else { DeleteProfileSM(Box.BoxId, SMSnap.ProfileMSId); SMSnap.Exist = false; MainViewModel.GetInstance().ListOfNetworks.updateProfileSM(SMSnap); MainViewModel.GetInstance().DetailsBox.removeProfileSM(SMSnap); } break; case "linkedin2": ProfileSM SMSLink = Converter.ToProfileSM(tappedItemProfile); if (SMSLink.Exist == false) { PostProfileSM(Box.BoxId, SMSLink.ProfileMSId); SMSLink.Exist = true; MainViewModel.GetInstance().ListOfNetworks.updateProfileSM(SMSLink); MainViewModel.GetInstance().DetailsBox.addProfileSM(SMSLink); } else { DeleteProfileSM(Box.BoxId, SMSLink.ProfileMSId); SMSLink.Exist = false; MainViewModel.GetInstance().ListOfNetworks.updateProfileSM(SMSLink); MainViewModel.GetInstance().DetailsBox.removeProfileSM(SMSLink); } break; case "tiktok2": ProfileSM SMSTik = Converter.ToProfileSM(tappedItemProfile); if (SMSTik.Exist == false) { PostProfileSM(Box.BoxId, SMSTik.ProfileMSId); SMSTik.Exist = true; MainViewModel.GetInstance().ListOfNetworks.updateProfileSM(SMSTik); MainViewModel.GetInstance().DetailsBox.addProfileSM(SMSTik); } else { DeleteProfileSM(Box.BoxId, SMSTik.ProfileMSId); SMSTik.Exist = false; MainViewModel.GetInstance().ListOfNetworks.updateProfileSM(SMSTik); MainViewModel.GetInstance().DetailsBox.removeProfileSM(SMSTik); } break; case "youtube2": ProfileSM SMYou = Converter.ToProfileSM(tappedItemProfile); if (SMYou.Exist == false) { PostProfileSM(Box.BoxId, SMYou.ProfileMSId); SMYou.Exist = true; MainViewModel.GetInstance().ListOfNetworks.updateProfileSM(SMYou); MainViewModel.GetInstance().DetailsBox.addProfileSM(SMYou); } else { DeleteProfileSM(Box.BoxId, SMYou.ProfileMSId); SMYou.Exist = false; MainViewModel.GetInstance().ListOfNetworks.updateProfileSM(SMYou); MainViewModel.GetInstance().DetailsBox.removeProfileSM(SMYou); } break; case "spotify2": ProfileSM SMSP = Converter.ToProfileSM(tappedItemProfile); if (SMSP.Exist == false) { PostProfileSM(Box.BoxId, SMSP.ProfileMSId); SMSP.Exist = true; MainViewModel.GetInstance().ListOfNetworks.updateProfileSM(SMSP); MainViewModel.GetInstance().DetailsBox.addProfileSM(SMSP); } else { DeleteProfileSM(Box.BoxId, SMSP.ProfileMSId); SMSP.Exist = false; MainViewModel.GetInstance().ListOfNetworks.updateProfileSM(SMSP); MainViewModel.GetInstance().DetailsBox.removeProfileSM(SMSP); } break; case "twitch2": ProfileSM SMTwc = Converter.ToProfileSM(tappedItemProfile); if (SMTwc.Exist == false) { PostProfileSM(Box.BoxId, SMTwc.ProfileMSId); SMTwc.Exist = true; MainViewModel.GetInstance().ListOfNetworks.updateProfileSM(SMTwc); MainViewModel.GetInstance().DetailsBox.addProfileSM(SMTwc); } else { DeleteProfileSM(Box.BoxId, SMTwc.ProfileMSId); SMTwc.Exist = false; MainViewModel.GetInstance().ListOfNetworks.updateProfileSM(SMTwc); MainViewModel.GetInstance().DetailsBox.removeProfileSM(SMTwc); } break; case "gmail2": ProfileSM SMWeb = Converter.ToProfileSM(tappedItemProfile); if (SMWeb.Exist == false) { PostProfileSM(Box.BoxId, SMWeb.ProfileMSId); SMWeb.Exist = true; MainViewModel.GetInstance().ListOfNetworks.updateProfileSM(SMWeb); MainViewModel.GetInstance().DetailsBox.addProfileSM(SMWeb); } else { DeleteProfileSM(Box.BoxId, SMWeb.ProfileMSId); SMWeb.Exist = false; MainViewModel.GetInstance().ListOfNetworks.updateProfileSM(SMWeb); MainViewModel.GetInstance().DetailsBox.removeProfileSM(SMWeb); } break; case "whatsapp2": ProfileWhatsapp W = Converter.ToProfileWhatsapp(tappedItemProfile); if (W.Exist == false) { PostProfileWhatsapp(Box.BoxId, W.ProfileWhatsappId); W.Exist = true; MainViewModel.GetInstance().ListOfNetworks.updateProfileWhatsapp(W); MainViewModel.GetInstance().DetailsBox.addProfileW(W); } else { DeleteProfileWhatsapp(Box.BoxId, W.ProfileWhatsappId); W.Exist = false; MainViewModel.GetInstance().ListOfNetworks.updateProfileWhatsapp(W); MainViewModel.GetInstance().DetailsBox.removeProfileW(W); } break; case "telegram2": ProfileSM SMT = Converter.ToProfileSM(tappedItemProfile); if (SMT.Exist == false) { PostProfileSM(Box.BoxId, SMT.ProfileMSId); SMT.Exist = true; MainViewModel.GetInstance().ListOfNetworks.updateProfileSM(SMT); MainViewModel.GetInstance().DetailsBox.addProfileSM(SMT); } else { DeleteProfileSM(Box.BoxId, SMT.ProfileMSId); SMT.Exist = false; MainViewModel.GetInstance().ListOfNetworks.updateProfileSM(SMT); MainViewModel.GetInstance().DetailsBox.removeProfileSM(SMT); } break; default: break; } }
public static string get_box() { string json = null; string message2 = null; try { json = null; var Profile = new ProfileLocal(); var Profile_1 = new ProfileLocal(); var Box_Local = new BoxLocal(); using (var conn = new SQLite.SQLiteConnection(App.root_db)) { Profile_1 = conn.Table <ProfileLocal>().FirstOrDefault(); Box_Local = conn.Table <BoxLocal>().FirstOrDefault(); int coun = conn.Table <ProfileLocal>().Count(); string json_header = null; string json_body = null; string json_value = null; string json_fantasma = null; //11/30/2020 6:09:07 p. m. json_header = "Box recibida correctamente!\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + "¡"; json_value = "{" + @"""BoxId"":""" + Box_Local.BoxId + @""", ""Name"":""" + Box_Local.Name + @""", ""BoxDefault"":""" + Box_Local.BoxDefault + @""", ""UserId"":""" + Box_Local.UserId + @""", ""Time"":""" + Box_Local.Time + @""", ""ImagePath"":""" + Box_Local.ImagePath + @""", ""UserTypeId"":""" + Box_Local.UserTypeId + @""", ""FirstName"":""" + Box_Local.FirstName + @""", ""LastName"":""" + Box_Local.LastName + @""", ""ImageFullPath"":""" + Box_Local.ImageFullPath + @""", ""FullName"":""" + Box_Local.FullName + @""", ""ProfileLocalId"":""" + Profile_1.ProfileLocalId + @""", ""IdBox"":""" + Profile_1.IdBox + @""", ""UserId_p"":""" + Profile_1.UserId + @""", ""ProfileName"":""" + Profile_1.ProfileName + @""", ""value"":""" + Profile_1.value + @""", ""ProfileType"":""" + Profile_1.ProfileType + @""" }"; message2 = Box_Local.UserId.ToString(); //quitar //name bxl //BoxDefault //time //UserTypeId //ImageFullPath //FullName json_fantasma = "{" + @"""BoxId"":""-"", ""Name"":""" + Box_Local.Name + @""", ""BoxDefault"":""" + Box_Local.BoxDefault + @""", ""UserId"":""" + Box_Local.UserId + @""", ""Time"":""" + Box_Local.Time + @""", ""ImagePath"":""" + Box_Local.ImagePath + @""", ""UserTypeId"":""" + Box_Local.UserTypeId + @""", ""FirstName"":""" + Box_Local.FirstName + @""", ""LastName"":""" + Box_Local.LastName + @""", ""ImageFullPath"":""" + Box_Local.ImageFullPath + @""", ""FullName"":""" + Box_Local.FullName + @""", ""ProfileLocalId"":""" + Profile_1.ProfileLocalId + @""", ""IdBox"":""" + Profile_1.IdBox + @""", ""UserId_p"":""" + Profile_1.UserId + @""", ""ProfileName"":""" + Profile_1.ProfileName + @""", ""value"":""" + Profile_1.value + @""", ""ProfileType"":""" + Profile_1.ProfileType + @""" }"; if (coun > 1) { for (int i = 1; i < coun; i++) { Profile = conn.Table <ProfileLocal>().ElementAt(i); json_body = "{" + @"""BoxId"":""" + Box_Local.BoxId + @""", ""Name"":""" + Box_Local.Name + @""", ""BoxDefault"":""" + Box_Local.BoxDefault + @""", ""UserId"":""" + Box_Local.UserId + @""", ""Time"":""" + Box_Local.Time + @""", ""ImagePath"":""" + Box_Local.ImagePath + @""", ""UserTypeId"":""" + Box_Local.UserTypeId + @""", ""FirstName"":""" + Box_Local.FirstName + @""", ""LastName"":""" + Box_Local.LastName + @""", ""ImageFullPath"":""" + Box_Local.ImageFullPath + @""", ""FullName"":""" + Box_Local.FullName + @""", ""ProfileLocalId"":""" + Profile.ProfileLocalId + @""", ""IdBox"":""" + Profile.IdBox + @""", ""UserId_p"":""" + Profile.UserId + @""", ""ProfileName"":""" + Profile.ProfileName + @""", ""value"":""" + Profile.value + @""", ""ProfileType"":""" + Profile.ProfileType + @""" }"; json_value = json_value + ",\n" + json_body; } json_value = "[" + json_value + "]"; } else { json_value = "[" + json_value + ",\n" + json_fantasma + "]"; } json = "¬" + json_value; } } catch (Exception exx) { Console.Write(exx); json = null; } var message = json; return(message2); }
private void CheckLocalBox() { BoxLocal boxLocal = new BoxLocal(); bool valBoxLocal = false; bool valProfileLocal = false; using (var conn = new SQLite.SQLiteConnection(App.root_db)) { string cadenaConexion = @"data source=serverappmynfo.database.windows.net;initial catalog=mynfo;user id=adminmynfo;password=4dmiNFC*Atx2020;Connect Timeout=60"; //string cadenaConexion = @"data source=serverappmynfo.database.windows.net;initial catalog=mynfo;user id=adminmynfo;password=4dmiNFC*Atx2020;Connect Timeout=60"; string queryToGetBoxDefault = "select * from dbo.Boxes where dbo.boxes.UserId = " + MainViewModel.GetInstance().User.UserId + " and dbo.Boxes.BoxDefault = 1"; StringBuilder sb; var resultBoxLocal = conn.GetTableInfo("BoxLocal"); var resulForeingBox = conn.GetTableInfo("ForeingBox"); var resultForeingProfiles = conn.GetTableInfo("ForeingProfile"); if (resulForeingBox.Count == 0) { conn.CreateTable <ForeingBox>(); if (resultForeingProfiles.Count == 0) { conn.CreateTable <ForeingProfile>(); } } //Si no existe la tabla de las boxes locales... if (resultBoxLocal.Count == 0) { //Validamos si existe la tabla de perfiles locales var resultProfileLocal = conn.GetTableInfo("ProfileLocal"); //Crear tabla de box local conn.CreateTable <BoxLocal>(); //Si no existe la tabla de perfiles... if (resultProfileLocal.Count == 0) { //Creamos la tabla de perfiles local conn.CreateTable <ProfileLocal>(); } else { //Eliminamos los datos de la tabla de perfiles locales conn.DeleteAll <ProfileLocal>(); } //Buscar registros, y si existen, replicarlos a la box local using (SqlConnection connection = new SqlConnection(cadenaConexion)) { sb = new System.Text.StringBuilder(); sb.Append(queryToGetBoxDefault); string sql = sb.ToString(); using (SqlCommand command = new SqlCommand(sql, connection)) { connection.Open(); using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { boxLocal = new BoxLocal { BoxId = (int)reader["BoxId"], BoxDefault = true, Name = (string)reader["Name"], UserId = MainViewModel.GetInstance().User.UserId, Time = (DateTime)reader["Time"], FirstName = MainViewModel.GetInstance().User.FirstName, LastName = MainViewModel.GetInstance().User.LastName, ImagePath = MainViewModel.GetInstance().User.ImagePath, UserTypeId = MainViewModel.GetInstance().User.UserTypeId }; conn.Insert(boxLocal); valBoxLocal = true; } } connection.Close(); } } //Si existe la box en la nube if (boxLocal.BoxId != 0) { //Creación de perfiles locales de box local string queryGetBoxEmail = "select * from dbo.ProfileEmails " + "join dbo.Box_ProfileEmail on" + "(dbo.ProfileEmails.ProfileEmailId = dbo.Box_ProfileEmail.ProfileEmailId) " + "where dbo.Box_ProfileEmail.BoxId = " + boxLocal.BoxId; string queryGetBoxPhone = "select * from dbo.ProfilePhones " + "join dbo.Box_ProfilePhone on" + "(dbo.ProfilePhones.ProfilePhoneId = dbo.Box_ProfilePhone.ProfilePhoneId) " + "where dbo.Box_ProfilePhone.BoxId = " + boxLocal.BoxId; string queryGetBoxSMProfiles = "select * from dbo.ProfileSMs " + "join dbo.Box_ProfileSM on" + "(dbo.ProfileSMs.ProfileMSId = dbo.Box_ProfileSM.ProfileMSId) " + "join dbo.RedSocials on(dbo.ProfileSMs.RedSocialId = dbo.RedSocials.RedSocialId) " + "where dbo.Box_ProfileSM.BoxId = " + boxLocal.BoxId; //Consulta para obtener perfiles email using (SqlConnection conn1 = new SqlConnection(cadenaConexion)) { sb = new System.Text.StringBuilder(); sb.Append(queryGetBoxEmail); string sql = sb.ToString(); using (SqlCommand command = new SqlCommand(sql, conn1)) { conn1.Open(); using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { ProfileLocal emailProfile = new ProfileLocal { IdBox = boxLocal.BoxId, UserId = (int)reader["UserId"], ProfileName = (string)reader["Name"], value = (string)reader["Email"], ProfileType = "Email" }; //Crear perfil de correo de box local predeterminada using (var connSQLite = new SQLite.SQLiteConnection(App.root_db)) { connSQLite.Insert(emailProfile); } } } conn1.Close(); } } //Consulta para obtener perfiles teléfono using (SqlConnection conn1 = new SqlConnection(cadenaConexion)) { sb = new System.Text.StringBuilder(); sb.Append(queryGetBoxPhone); string sql = sb.ToString(); using (SqlCommand command = new SqlCommand(sql, conn1)) { conn1.Open(); using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { ProfileLocal phoneProfile = new ProfileLocal { IdBox = boxLocal.BoxId, UserId = (int)reader["UserId"], ProfileName = (string)reader["Name"], value = (string)reader["Number"], ProfileType = "Phone" }; //Crear perfil de teléfono de box local predeterminada using (var connSQLite = new SQLite.SQLiteConnection(App.root_db)) { connSQLite.Insert(phoneProfile); } } } conn1.Close(); } } //Consulta para obtener perfiles de redes sociales using (SqlConnection conn1 = new SqlConnection(cadenaConexion)) { sb = new System.Text.StringBuilder(); sb.Append(queryGetBoxSMProfiles); string sql = sb.ToString(); using (SqlCommand command = new SqlCommand(sql, conn1)) { conn1.Open(); using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { ProfileLocal smProfile = new ProfileLocal { IdBox = boxLocal.BoxId, UserId = (int)reader["UserId"], ProfileName = (string)reader["ProfileName"], value = (string)reader["link"], ProfileType = (string)reader["Name"] }; //Crear perfil de teléfono de box local predeterminada using (var connSQLite = new SQLite.SQLiteConnection(App.root_db)) { connSQLite.Insert(smProfile); } } } conn1.Close(); } } //Validamos que se haya insertado al menos un perfil if (conn.Table <ProfileLocal>().Count() > 0) { valProfileLocal = true; } } if (valBoxLocal == true && valProfileLocal == true) { //this.get_box(); } } else { //********************************************* //Si la tabla de box local si existe //La vacíamos para colocar los nuevos valores conn.DeleteAll <BoxLocal>(); conn.DeleteAll <ProfileLocal>(); //Validamos que esté vacía int a = conn.Table <BoxLocal>().Count(); //Buscar registros, y si existen, replicarlos a la box local using (SqlConnection connection = new SqlConnection(cadenaConexion)) { sb = new System.Text.StringBuilder(); sb.Append(queryToGetBoxDefault); string sql = sb.ToString(); using (SqlCommand command = new SqlCommand(sql, connection)) { connection.Open(); using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { boxLocal = new BoxLocal { BoxId = (int)reader["BoxId"], BoxDefault = true, Name = (string)reader["Name"], UserId = MainViewModel.GetInstance().User.UserId, Time = (DateTime)reader["Time"], FirstName = MainViewModel.GetInstance().User.FirstName, LastName = MainViewModel.GetInstance().User.LastName, ImagePath = MainViewModel.GetInstance().User.ImagePath, UserTypeId = MainViewModel.GetInstance().User.UserTypeId }; conn.Insert(boxLocal); valBoxLocal = true; } } connection.Close(); } } a = conn.Table <BoxLocal>().Count(); //Validamos que exista una box if (boxLocal.BoxId != 0) { //Creación de perfiles locales de box local string queryGetBoxEmail = "select * from dbo.ProfileEmails " + "join dbo.Box_ProfileEmail on" + "(dbo.ProfileEmails.ProfileEmailId = dbo.Box_ProfileEmail.ProfileEmailId) " + "where dbo.Box_ProfileEmail.BoxId = " + boxLocal.BoxId; string queryGetBoxPhone = "select * from dbo.ProfilePhones " + "join dbo.Box_ProfilePhone on" + "(dbo.ProfilePhones.ProfilePhoneId = dbo.Box_ProfilePhone.ProfilePhoneId) " + "where dbo.Box_ProfilePhone.BoxId = " + boxLocal.BoxId; string queryGetBoxSMProfiles = "select * from dbo.ProfileSMs " + "join dbo.Box_ProfileSM on" + "(dbo.ProfileSMs.ProfileMSId = dbo.Box_ProfileSM.ProfileMSId) " + "join dbo.RedSocials on(dbo.ProfileSMs.RedSocialId = dbo.RedSocials.RedSocialId) " + "where dbo.Box_ProfileSM.BoxId = " + boxLocal.BoxId; //Consulta para obtener perfiles email using (SqlConnection conn1 = new SqlConnection(cadenaConexion)) { sb = new System.Text.StringBuilder(); sb.Append(queryGetBoxEmail); string sql = sb.ToString(); using (SqlCommand command = new SqlCommand(sql, conn1)) { conn1.Open(); using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { ProfileLocal emailProfile = new ProfileLocal { IdBox = boxLocal.BoxId, UserId = (int)reader["UserId"], ProfileName = (string)reader["Name"], value = (string)reader["Email"], ProfileType = "Email" }; //Crear perfil de correo de box local predeterminada using (var connSQLite = new SQLite.SQLiteConnection(App.root_db)) { connSQLite.Insert(emailProfile); } } } conn1.Close(); } } //Consulta para obtener perfiles teléfono using (SqlConnection conn1 = new SqlConnection(cadenaConexion)) { sb = new System.Text.StringBuilder(); sb.Append(queryGetBoxPhone); string sql = sb.ToString(); using (SqlCommand command = new SqlCommand(sql, conn1)) { conn1.Open(); using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { ProfileLocal phoneProfile = new ProfileLocal { IdBox = boxLocal.BoxId, UserId = (int)reader["UserId"], ProfileName = (string)reader["Name"], value = (string)reader["Number"], ProfileType = "Phone" }; //Crear perfil de teléfono de box local predeterminada using (var connSQLite = new SQLite.SQLiteConnection(App.root_db)) { connSQLite.Insert(phoneProfile); } } } conn1.Close(); } } //Consulta para obtener perfiles de redes sociales using (SqlConnection conn1 = new SqlConnection(cadenaConexion)) { sb = new System.Text.StringBuilder(); sb.Append(queryGetBoxSMProfiles); string sql = sb.ToString(); using (SqlCommand command = new SqlCommand(sql, conn1)) { conn1.Open(); using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { ProfileLocal smProfile = new ProfileLocal { IdBox = boxLocal.BoxId, UserId = (int)reader["UserId"], ProfileName = (string)reader["ProfileName"], value = (string)reader["link"], ProfileType = (string)reader["Name"] }; //Crear perfil de teléfono de box local predeterminada using (var connSQLite = new SQLite.SQLiteConnection(App.root_db)) { connSQLite.Insert(smProfile); } } } conn1.Close(); } } //Validamos que se haya insertado al menos un perfil if (conn.Table <ProfileLocal>().Count() > 0) { valProfileLocal = true; } if (valBoxLocal == true && valProfileLocal == true) { //this.get_box(); } } } } }
async void OnCollectionViewSelectionChanged(object sender, SelectionChangedEventArgs e) { selectedItem = e.CurrentSelection.FirstOrDefault() as ProfileLocal; if (selectedItem == null) { return; } switch (selectedItem.ProfileType) { case "Email": await Launcher.OpenAsync(new Uri("mailto:" + selectedItem.value)); break; case "Instagram": await Launcher.OpenAsync(new Uri(selectedItem.value)); break; case "Facebook": await Launcher.OpenAsync(new Uri(selectedItem.value)); break; case "LinkedIn": await Launcher.OpenAsync(new Uri(selectedItem.value)); break; case "Phone": PhoneDialer.Open(selectedItem.value); break; case "Snapchat": await Launcher.OpenAsync(new Uri(selectedItem.value)); break; case "Spotify": await Launcher.OpenAsync(new Uri(selectedItem.value)); break; case "TikTok": await Launcher.OpenAsync(new Uri(selectedItem.value)); break; case "Twitch": await Launcher.OpenAsync(new Uri(selectedItem.value)); break; case "Twitter": await Launcher.OpenAsync(new Uri(selectedItem.value)); break; case "WebPage": await Launcher.OpenAsync(new Uri(selectedItem.value)); break; case "Whatsapp": try { string language = CultureInfo.CurrentUICulture.TwoLetterISOLanguageName; switch (language) { case "en": Chat.Open("52" + selectedItem.value, "Hi%20from%20mynfo!"); break; case "es": Chat.Open("52" + selectedItem.value, "Hola%20desde%20mynfo!"); break; case "pt": Chat.Open("52" + selectedItem.value, "Olá%20de%20mynfo!"); break; default: Chat.Open("52" + selectedItem.value, "Hi%20from%20mynfo!"); break; } //Chat.Open("52" + selectedItem.value, Languages.MessageWhatsApp + " " + MainViewModel.GetInstance().User.FirstName); } catch (Exception ex) { await DisplayAlert(Languages.Error, ex.Message, Languages.Accept); } break; case "Youtube": await Launcher.OpenAsync(new Uri(selectedItem.value)); break; default: break; } ((CollectionView)sender).SelectedItem = null; }
async void OnCollectionViewSelectionChanged(object sender, SelectionChangedEventArgs e) { selectedItem = e.CurrentSelection.FirstOrDefault() as ProfileLocal; if (selectedItem == null) { return; } switch (selectedItem.ProfileType) { case "Email": await Launcher.OpenAsync(new Uri("mailto:" + selectedItem.value)); break; case "Instagram": await Launcher.OpenAsync(new Uri(selectedItem.value)); break; case "Facebook": await Launcher.OpenAsync(new Uri(selectedItem.value)); break; case "Linkedin": await Launcher.OpenAsync(new Uri(selectedItem.value)); break; case "Phone": PhoneDialer.Open(selectedItem.value); break; case "Snapchat": await Launcher.OpenAsync(new Uri(selectedItem.value)); break; case "Spotify": await Launcher.OpenAsync(new Uri(selectedItem.value)); break; case "Telegram": await Launcher.OpenAsync(new Uri("https://telegram.me/" + selectedItem.value)); break; case "Tiktok": await Launcher.OpenAsync(new Uri(selectedItem.value)); break; case "Twitch": await Launcher.OpenAsync(new Uri(selectedItem.value)); break; case "Twitter": await Launcher.OpenAsync(new Uri(selectedItem.value)); break; case "WebPage": await Launcher.OpenAsync(new Uri(selectedItem.value)); break; case "Whatsapp": try { Chat.Open("+52" + selectedItem.value, Languages.MessageWhatsApp + MainViewModel.GetInstance().User.FirstName); } catch (Exception ex) { await DisplayAlert(Languages.Error, ex.Message, Languages.Accept); } break; case "Youtube": await Launcher.OpenAsync(new Uri(selectedItem.value)); break; default: break; } ((CollectionView)sender).SelectedItem = null; }
async void deleteBox(object sender, EventArgs e, int _BoxId, int _UserId, bool _BoxDefault) { string sqlDeleteEmails = "delete from dbo.Box_ProfileEmail where dbo.Box_ProfileEmail.BoxId = " + _BoxId, sqlDeletePhones = "delete from dbo.Box_ProfilePhone where dbo.Box_ProfilePhone.BoxId = " + _BoxId, sqlDeleteSMProfiles = "delete from dbo.Box_ProfileSM where dbo.Box_ProfileSM.BoxId = " + _BoxId, sqlDeleteWhatsappProfiles = "delete from dbo.Box_ProfileWhatsapp where dbo.Box_ProfileWhatsapp.BoxId = " + _BoxId, sqlDeleteBox = "delete from dbo.Boxes where dbo.boxes.BoxId = " + _BoxId; string cadenaConexion = @"data source=serverappmynfo.database.windows.net;initial catalog=mynfo;user id=adminmynfo;password=4dmiNFC*Atx2020;Connect Timeout=60"; //string cadenaConexion = @"data source=serverappmynfo.database.windows.net;initial catalog=mynfo;user id=adminmynfo;password=4dmiNFC*Atx2020;Connect Timeout=60"; StringBuilder sb; string sql; bool answer = await DisplayAlert(Resource.Warning, Resource.DeleteBoxNotification, Resource.Yes, Resource.No); #region If if (answer == true) { using (SqlConnection connection = new SqlConnection(cadenaConexion)) { //Borrar emails de la box sb = new System.Text.StringBuilder(); sb.Append(sqlDeleteEmails); sql = sb.ToString(); using (SqlCommand command = new SqlCommand(sql, connection)) { connection.Open(); command.ExecuteNonQuery(); connection.Close(); } //Borrar teléfonos de la box sb = new System.Text.StringBuilder(); sb.Append(sqlDeletePhones); sql = sb.ToString(); using (SqlCommand command = new SqlCommand(sql, connection)) { connection.Open(); command.ExecuteNonQuery(); connection.Close(); } //Borrar perfiles de redes sociales de la box sb = new System.Text.StringBuilder(); sb.Append(sqlDeleteSMProfiles); sql = sb.ToString(); using (SqlCommand command = new SqlCommand(sql, connection)) { connection.Open(); command.ExecuteNonQuery(); connection.Close(); } //Borrar perfiles de whatsapp de la box sb = new System.Text.StringBuilder(); sb.Append(sqlDeleteWhatsappProfiles); sql = sb.ToString(); using (SqlCommand command = new SqlCommand(sql, connection)) { connection.Open(); command.ExecuteNonQuery(); connection.Close(); } //Borrar box sb = new System.Text.StringBuilder(); sb.Append(sqlDeleteBox); sql = sb.ToString(); var apiSecurity = Application.Current.Resources["APISecurity"].ToString(); var Box = await this.apiService.GetBox( apiSecurity, "/api", "/Boxes", _BoxId); MainViewModel.GetInstance().Home.RemoveList(Box); using (SqlCommand command = new SqlCommand(sql, connection)) { connection.Open(); command.ExecuteNonQuery(); connection.Close(); } //Si la box era predeterminada if (_BoxDefault == true) { //Borrar box predeterminada anterior using (var conn = new SQLite.SQLiteConnection(App.root_db)) { conn.DeleteAll <BoxLocal>(); } //Borrar perfiles de box predeterminada anteriores using (var conn = new SQLite.SQLiteConnection(App.root_db)) { conn.DeleteAll <ProfileLocal>(); } string sqlUpdateBoxDefault = "update top (1) dbo.Boxes set BoxDefault = 1 where dbo.Boxes.UserId = " + _UserId; BoxLocal boxLocal; bool boxLocalExists = false; int boxIdLocal = 0; //Definir nueva box default sb = new System.Text.StringBuilder(); sb.Append(sqlUpdateBoxDefault); sql = sb.ToString(); using (SqlCommand command = new SqlCommand(sql, connection)) { connection.Open(); command.ExecuteNonQuery(); connection.Close(); } string sqlGetNewDefault = "select * from dbo.Boxes " + "where dbo.Boxes.UserId = " + _UserId + "and dbo.Boxes.BoxDefault = 1"; //Definir nueva box default sb = new System.Text.StringBuilder(); sb.Append(sqlGetNewDefault); sql = sb.ToString(); //Creación de nueva box local using (SqlCommand command = new SqlCommand(sql, connection)) { connection.Open(); using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { boxLocal = new BoxLocal { BoxId = (int)reader["BoxId"], BoxDefault = true, Name = (String)reader["Name"], UserId = MainViewModel.GetInstance().User.UserId, Time = (DateTime)reader["Time"], FirstName = MainViewModel.GetInstance().User.FirstName, LastName = MainViewModel.GetInstance().User.LastName, ImagePath = MainViewModel.GetInstance().User.ImagePath, UserTypeId = MainViewModel.GetInstance().User.UserTypeId }; //Crear box local predeterminada using (var conn = new SQLite.SQLiteConnection(App.root_db)) { conn.CreateTable <BoxLocal>(); conn.Insert(boxLocal); } //Crear tabla de perfiles de box local predeterminada using (var conn = new SQLite.SQLiteConnection(App.root_db)) { conn.CreateTable <ProfileLocal>(); } boxLocalExists = true; boxIdLocal = (int)reader["BoxId"]; } } connection.Close(); } //Si se creo la box local, procedo a crear los perfiles locales if (boxLocalExists == true) { //Creación de perfiles locales de box local string queryGetBoxEmail = "select * from dbo.ProfileEmails " + "join dbo.Box_ProfileEmail on" + "(dbo.ProfileEmails.ProfileEmailId = dbo.Box_ProfileEmail.ProfileEmailId) " + "where dbo.Box_ProfileEmail.BoxId = " + boxIdLocal; string queryGetBoxPhone = "select * from dbo.ProfilePhones " + "join dbo.Box_ProfilePhone on" + "(dbo.ProfilePhones.ProfilePhoneId = dbo.Box_ProfilePhone.ProfilePhoneId) " + "where dbo.Box_ProfilePhone.BoxId = " + boxIdLocal; string queryGetBoxSMProfiles = "select * from dbo.ProfileSMs " + "join dbo.Box_ProfileSM on" + "(dbo.ProfileSMs.ProfileMSId = dbo.Box_ProfileSM.ProfileMSId) " + "join dbo.RedSocials on(dbo.ProfileSMs.RedSocialId = dbo.RedSocials.RedSocialId) " + "where dbo.Box_ProfileSM.BoxId = " + boxIdLocal; string queryGetBoxWhatsappProfiles = "select * from dbo.ProfileWhatsapps join dbo.Box_ProfileWhatsapp on " + "(dbo.ProfileWhatsapps.ProfileWhatsappId = dbo.Box_ProfileWhatsapp.ProfileWhatsappId) " + "where dbo.Box_ProfileWhatsapp.BoxId = " + boxIdLocal; //Consulta para obtener perfiles email using (SqlConnection conn = new SqlConnection(cadenaConexion)) { sb = new System.Text.StringBuilder(); sb.Append(queryGetBoxEmail); sql = sb.ToString(); using (SqlCommand command = new SqlCommand(sql, conn)) { conn.Open(); using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { ProfileLocal emailProfile = new ProfileLocal { IdBox = boxIdLocal, UserId = (int)reader["UserId"], ProfileName = (string)reader["Name"], value = (string)reader["Email"], ProfileType = "Email" }; //Crear perfil de correo de box local predeterminada using (var connSQLite = new SQLite.SQLiteConnection(App.root_db)) { connSQLite.Insert(emailProfile); } } } conn.Close(); } } //Consulta para obtener perfiles teléfono using (SqlConnection conn = new SqlConnection(cadenaConexion)) { sb = new System.Text.StringBuilder(); sb.Append(queryGetBoxPhone); sql = sb.ToString(); using (SqlCommand command = new SqlCommand(sql, conn)) { conn.Open(); using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { ProfileLocal phoneProfile = new ProfileLocal { IdBox = boxIdLocal, UserId = (int)reader["UserId"], ProfileName = (string)reader["Name"], value = (string)reader["Number"], ProfileType = "Phone" }; //Crear perfil de teléfono de box local predeterminada using (var connSQLite = new SQLite.SQLiteConnection(App.root_db)) { connSQLite.Insert(phoneProfile); } } } conn.Close(); } } //Consulta para obtener perfiles de redes sociales using (SqlConnection conn = new SqlConnection(cadenaConexion)) { sb = new System.Text.StringBuilder(); sb.Append(queryGetBoxSMProfiles); sql = sb.ToString(); using (SqlCommand command = new SqlCommand(sql, conn)) { conn.Open(); using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { ProfileLocal smProfile = new ProfileLocal { IdBox = boxIdLocal, UserId = (int)reader["UserId"], ProfileName = (string)reader["ProfileName"], value = (string)reader["link"], ProfileType = (string)reader["Name"] }; //Crear perfil de teléfono de box local predeterminada using (var connSQLite = new SQLite.SQLiteConnection(App.root_db)) { connSQLite.Insert(smProfile); } } } conn.Close(); } } //Consulta para obtener perfiles whatsapp using (SqlConnection conn = new SqlConnection(cadenaConexion)) { sb = new System.Text.StringBuilder(); sb.Append(queryGetBoxWhatsappProfiles); sql = sb.ToString(); using (SqlCommand command = new SqlCommand(sql, conn)) { conn.Open(); using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { ProfileLocal whatsappProfile = new ProfileLocal { IdBox = boxIdLocal, UserId = (int)reader["UserId"], ProfileName = (string)reader["Name"], value = (string)reader["Number"], ProfileType = "Whatsapp" }; //Crear perfil de whatsapp de box local predeterminada using (var connSQLite = new SQLite.SQLiteConnection(App.root_db)) { connSQLite.Insert(whatsappProfile); } } } conn.Close(); } } } } } //Regresar a home MainViewModel.GetInstance().Home = new HomeViewModel(); Application.Current.MainPage = new MasterPage(); await PopupNavigation.Instance.PopAllAsync(); } #endregion //if(answer == true) //{ // MainViewModel.GetInstance().DetailsBoxEdith.DeleteBox(_BoxId); //} //else //{ // return; //} }
public DetailBoxPopUpPage(Box _Box) { InitializeComponent(); apiService = new ApiService(); NavigationPage.SetHasNavigationBar(this, false); OSAppTheme currentTheme = Application.Current.RequestedTheme; FrameB.CloseWhenBackgroundIsClicked = true; #region Lastcode int BoxId = _Box.BoxId; var boxLocal = new BoxLocal(); int UserID = MainViewModel.GetInstance().User.UserId; string consultaDefault; string queryLastBoxCreated = "SELECT TOP 1 * FROM dbo.Boxes where dbo.Boxes.UserId = " + UserID + " ORDER BY BoxId DESC"; string queryUpdatesetDefault; string queryUpdateTakeOffDefault; string queryGetPhones; string queryGetEmails; string queryGetSMProfiles; string queryGetWhatsapp; string cadenaConexion = @"data source=serverappmynfo.database.windows.net;initial catalog=mynfo;user id=adminmynfo;password=4dmiNFC*Atx2020;Connect Timeout=60"; //string cadenaConexion = @"data source=serverappmynfo.database.windows.net;initial catalog=mynfo;user id=adminmynfo;password=4dmiNFC*Atx2020;Connect Timeout=60"; System.Text.StringBuilder sb; BoxName = ""; bool BoxDefault = _Box.BoxDefault; int UserId = 0; DateTime boxcreation = DateTime.Now; var BxSaveName = new ImageButton(); var BxBtnDelete = new ImageButton(); var bxBtnHome = new ImageButton(); var BxDefaultCheckBox = new CheckBox(); int listProfileNum = 0; //Asignación de querys consultaDefault = "select * from dbo.Boxes where dbo.Boxes.BoxId = " + BoxId; queryUpdatesetDefault = "update dbo.Boxes set BoxDefault = 1 where dbo.Boxes.UserId =" + UserID + " and dbo.Boxes.BoxId =" + BoxId; queryUpdateTakeOffDefault = "update dbo.Boxes set BoxDefault = 0 where dbo.Boxes.UserId =" + UserID + " and dbo.Boxes.BoxDefault = 1 and dbo.Boxes.BoxId !=" + BoxId; queryGetPhones = "select dbo.Boxes.BoxId, dbo.ProfilePhones.ProfilePhoneId, dbo.ProfilePhones.Name, " + "dbo.ProfilePhones.Number from dbo.Box_ProfilePhone Join dbo.Boxes " + "on(dbo.Boxes.BoxId = dbo.Box_ProfilePhone.BoxId) " + "Join dbo.ProfilePhones on(dbo.ProfilePhones.ProfilePhoneId = dbo.Box_ProfilePhone.ProfilePhoneId) " + "where dbo.Boxes.BoxId = " + BoxId; queryGetEmails = "select dbo.Boxes.BoxId, dbo.ProfileEmails.ProfileEmailId, dbo.ProfileEmails.Name, " + "dbo.ProfileEmails.Email from dbo.Box_ProfileEmail " + "Join dbo.Boxes on(dbo.Boxes.BoxId = dbo.Box_ProfileEmail.BoxId) " + "Join dbo.ProfileEmails on(dbo.ProfileEmails.ProfileEmailId = dbo.Box_ProfileEmail.ProfileEmailId) " + "where dbo.Boxes.BoxId = " + BoxId; queryGetSMProfiles = "select * from dbo.Box_ProfileSM " + "join dbo.ProfileSMs on(dbo.ProfileSMs.ProfileMSId = dbo.Box_ProfileSM.ProfileMSId) " + "join dbo.RedSocials on(dbo.ProfileSMs.RedSocialId = dbo.RedSocials.RedSocialId) " + "where dbo.Box_ProfileSM.BoxId = " + _Box.BoxId; queryGetWhatsapp = "select dbo.Boxes.BoxId, dbo.ProfileWhatsapps.ProfileWhatsappId, dbo.ProfileWhatsapps.Name, " + "dbo.ProfileWhatsapps.Number from dbo.Box_ProfileWhatsapp Join dbo.Boxes " + "on(dbo.Boxes.BoxId = dbo.Box_ProfileWhatsapp.BoxId) " + "Join dbo.ProfileWhatsapps on(dbo.ProfileWhatsapps.ProfileWhatsappId = dbo.Box_ProfileWhatsapp.ProfileWhatsappId) " + "where dbo.Boxes.BoxId =" + _Box.BoxId; ////Consulta para obtener Box //using (SqlConnection connection = new SqlConnection(cadenaConexion)) //{ // sb = new System.Text.StringBuilder(); // sb.Append(consultaDefault); // string sql = sb.ToString(); // using (SqlCommand command = new SqlCommand(sql, connection)) // { // connection.Open(); // using (SqlDataReader reader = command.ExecuteReader()) // { // while (reader.Read()) // { // BoxName = (string)reader["Name"]; // BoxDefault = (bool)reader["BoxDefault"]; // UserId = (int)reader["UserId"]; // boxcreation = (DateTime)reader["Time"]; // } // } // connection.Close(); // } //} //boxLocal.BoxId = _Box.BoxId; //boxLocal.Name = BoxName; //boxLocal.BoxDefault = BoxDefault; //boxLocal.UserId = UserId; //boxLocal.Time = boxcreation; //boxLocal.FirstName = MainViewModel.GetInstance().User.FirstName; //boxLocal.LastName = MainViewModel.GetInstance().User.LastName; //boxLocal.ImagePath = MainViewModel.GetInstance().User.ImagePath; //boxLocal.UserTypeId = MainViewModel.GetInstance().User.UserTypeId; //Definir color de fondo con respecto a si la box es predeterminada if (currentTheme == OSAppTheme.Light) { if (_Box.ColorBox != null) { FrameB.BackgroundColor = Color.FromHex(_Box.ColorBox); } else { FrameB.BackgroundColor = Color.FromHex("#c6c6c6"); } BackG.BackgroundColor = Color.FromHex("#FFFFFF"); bxBtnHome.BackgroundColor = Color.FromHex("#FFFFFF"); BxSaveName.BackgroundColor = Color.FromHex("#FFFFFF"); BxBtnDelete.BackgroundColor = Color.FromHex("#FFFFFF"); } else { if (_Box.ColorBox != null) { FrameB.BackgroundColor = Color.FromHex(_Box.ColorBox); } else { FrameB.BackgroundColor = Color.FromHex("#a4a4a4"); } BackG.BackgroundColor = Color.FromHex("#222b3a"); bxBtnHome.BackgroundColor = Color.FromHex("#222b3a"); BxSaveName.BackgroundColor = Color.FromHex("#222b3a"); BxBtnDelete.BackgroundColor = Color.FromHex("#222b3a"); } //Tamaño de etiqueta de box predeterminada if (Xamarin.Forms.Device.RuntimePlatform == Xamarin.Forms.Device.iOS) { defaultLabel.FontSize = 13; } //Navegación a ventana de perfiles BoxProfiles.Clicked += new EventHandler((sender, e) => BoxDetails_Clicked(sender, e, BoxId, BoxDefault, BoxName)); //Botón de Editar EdithButton.Clicked += new EventHandler((sender, e) => edithBox(sender, e, _Box, UserID, BoxDefault)); //Creación del checkbox de box predeterminada BxDefaultCheckBox.IsChecked = BoxDefault; BxDefaultCheckBox.VerticalOptions = LayoutOptions.Start; if (Xamarin.Forms.Device.RuntimePlatform == Xamarin.Forms.Device.iOS) { Thickness thick = new Thickness(20, -6, 0, 0); BoxDefaultCheckBox.Margin = thick; } else if (Xamarin.Forms.Device.RuntimePlatform == Xamarin.Forms.Device.Android) { Thickness thick = new Thickness(20, 0, 0, 0); BoxDefaultCheckBox.Margin = thick; } if (BoxDefault == true) { BxDefaultCheckBox.IsEnabled = false; if (currentTheme == OSAppTheme.Dark) { BxDefaultCheckBox.Color = Color.White; EdithButton.Source = "edit3"; BoxProfiles.Source = "plusb"; } else { BxDefaultCheckBox.Color = Color.FromHex("FF5521"); EdithButton.Source = "edit2"; BoxProfiles.Source = "Plus"; } } else { if (currentTheme == OSAppTheme.Dark) { BxDefaultCheckBox.IsEnabled = true; BxDefaultCheckBox.Color = Color.FromHex("FFFFFF"); EdithButton.Source = "edit3"; BoxProfiles.Source = "plusb"; } else { BxDefaultCheckBox.IsEnabled = true; BxDefaultCheckBox.Color = Color.FromHex("FF5521"); EdithButton.Source = "edit2"; BoxProfiles.Source = "Plus"; } } BxDefaultCheckBox.CheckedChanged += CheckDefaultBox; BoxDefaultCheckBox.Children.Add(BxDefaultCheckBox); //Marcar o desmarcar la box predeterminada void CheckDefaultBox(object sender, EventArgs e) { string queryGetBoxEmail = "select * from dbo.ProfileEmails " + "join dbo.Box_ProfileEmail on" + "(dbo.ProfileEmails.ProfileEmailId = dbo.Box_ProfileEmail.ProfileEmailId) " + "where dbo.Box_ProfileEmail.BoxId = " + _Box.BoxId; string queryGetBoxPhone = "select * from dbo.ProfilePhones " + "join dbo.Box_ProfilePhone on" + "(dbo.ProfilePhones.ProfilePhoneId = dbo.Box_ProfilePhone.ProfilePhoneId) " + "where dbo.Box_ProfilePhone.BoxId = " + _Box.BoxId; string queryGetBoxSMProfiles = "select * from dbo.ProfileSMs " + "join dbo.Box_ProfileSM on" + "(dbo.ProfileSMs.ProfileMSId = dbo.Box_ProfileSM.ProfileMSId) " + "join dbo.RedSocials on(dbo.ProfileSMs.RedSocialId = dbo.RedSocials.RedSocialId) " + "where dbo.Box_ProfileSM.BoxId = " + _Box.BoxId; string queryGetBoxWhatsapp = "select * from dbo.ProfileWhatsapps join dbo.Box_ProfileWhatsapp on " + "(dbo.ProfileWhatsapps.ProfileWhatsappId = dbo.Box_ProfileWhatsapp.ProfileWhatsappId) " + "where dbo.Box_ProfileWhatsapp.BoxId = " + _Box.BoxId; //Borrar box predeterminada anterior using (var conn = new SQLite.SQLiteConnection(App.root_db)) { conn.DeleteAll <BoxLocal>(); } //Borrar perfiles de box predeterminada anteriores using (var conn = new SQLite.SQLiteConnection(App.root_db)) { conn.DeleteAll <ProfileLocal>(); } //Crear box local predeterminada using (var conn = new SQLite.SQLiteConnection(App.root_db)) { conn.CreateTable <BoxLocal>(); conn.Insert(boxLocal); } //Crear tabla de perfiles de box local predeterminada using (var conn = new SQLite.SQLiteConnection(App.root_db)) { conn.CreateTable <ProfileLocal>(); } //Consulta para obtener perfiles email using (SqlConnection connection = new SqlConnection(cadenaConexion)) { sb = new System.Text.StringBuilder(); sb.Append(queryGetBoxEmail); string sql = sb.ToString(); using (SqlCommand command = new SqlCommand(sql, connection)) { connection.Open(); using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { ProfileLocal emailProfile = new ProfileLocal { IdBox = _Box.BoxId, UserId = (int)reader["UserId"], ProfileName = (string)reader["Name"], value = (string)reader["Email"], ProfileType = "Email" }; //Crear perfil de correo de box local predeterminada using (var conn = new SQLite.SQLiteConnection(App.root_db)) { conn.Insert(emailProfile); } } } connection.Close(); } } //Consulta para obtener perfiles teléfono using (SqlConnection connection = new SqlConnection(cadenaConexion)) { sb = new System.Text.StringBuilder(); sb.Append(queryGetBoxPhone); string sql = sb.ToString(); using (SqlCommand command = new SqlCommand(sql, connection)) { connection.Open(); using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { ProfileLocal phoneProfile = new ProfileLocal { IdBox = _Box.BoxId, UserId = (int)reader["UserId"], ProfileName = (string)reader["Name"], value = (string)reader["Number"], ProfileType = "Phone" }; //Crear perfil de teléfono de box local predeterminada using (var conn = new SQLite.SQLiteConnection(App.root_db)) { conn.Insert(phoneProfile); } } } connection.Close(); } } //Consulta para obtener perfiles de redes sociales using (SqlConnection connection = new SqlConnection(cadenaConexion)) { sb = new System.Text.StringBuilder(); sb.Append(queryGetBoxSMProfiles); string sql = sb.ToString(); using (SqlCommand command = new SqlCommand(sql, connection)) { connection.Open(); using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { ProfileLocal smProfile = new ProfileLocal { IdBox = _Box.BoxId, UserId = (int)reader["UserId"], ProfileName = (string)reader["ProfileName"], value = (string)reader["link"], ProfileType = (string)reader["Name"] }; //Crear perfil de teléfono de box local predeterminada using (var conn = new SQLite.SQLiteConnection(App.root_db)) { conn.Insert(smProfile); } } } connection.Close(); } } //Consulta para obtener perfiles de whatsapp using (SqlConnection connection = new SqlConnection(cadenaConexion)) { sb = new System.Text.StringBuilder(); sb.Append(queryGetBoxWhatsapp); string sql = sb.ToString(); using (SqlCommand command = new SqlCommand(sql, connection)) { connection.Open(); using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { ProfileLocal whatsappProfile = new ProfileLocal { IdBox = _Box.BoxId, UserId = (int)reader["UserId"], ProfileName = (string)reader["Name"], value = (string)reader["Number"], ProfileType = "Whatsapp" }; //Crear perfil de teléfono de box local predeterminada using (var conn = new SQLite.SQLiteConnection(App.root_db)) { conn.Insert(whatsappProfile); } } } connection.Close(); } } //Consulta para predeterminar la box actual using (SqlConnection connection = new SqlConnection(cadenaConexion)) { sb = new System.Text.StringBuilder(); sb.Append(queryUpdatesetDefault); string sql = sb.ToString(); using (SqlCommand command = new SqlCommand(sql, connection)) { connection.Open(); command.ExecuteNonQuery(); connection.Close(); } } //Consulta para quitar predeterminado de la box default anterior using (SqlConnection connection = new SqlConnection(cadenaConexion)) { sb = new System.Text.StringBuilder(); sb.Append(queryUpdateTakeOffDefault); string sql = sb.ToString(); using (SqlCommand command = new SqlCommand(sql, connection)) { connection.Open(); command.ExecuteNonQuery(); connection.Close(); } } MainViewModel.GetInstance().Home.GetBoxDefault(); BxDefaultCheckBox.IsEnabled = false; MainViewModel.GetInstance().Home.GetBoxNoDefault(); } #endregion }