void OnListViewItemTapped(object sender, ItemTappedEventArgs e)
        {
            ForeingBox tappedItem = e.Item as ForeingBox;

            MainViewModel.GetInstance().ForeingBox = new ForeingBoxViewModel(tappedItem);
            PopupNavigation.Instance.PushAsync(new ForeingBoxPage(tappedItem));
        }
        public ForeingBoxPage(ForeingBox _foreingBox, bool isAfterReceiving = false)
        {
            InitializeComponent();
            NavigationPage.SetHasNavigationBar(this, false);
            OSAppTheme currentTheme = Application.Current.RequestedTheme;

            BackG.CloseWhenBackgroundIsClicked = true;

            #region DataFill
            ForeingBox foreing = _foreingBox;

            ForeignUserImage.Source = foreing.ImageFullPath;
            ForeignUserName.Text    = foreing.FullName;
            if (foreing.Edad != 0)
            {
                ForeignAge.Text = foreing.Edad + Languages.Anios;
            }
            if (foreing.Ubicacion != "")
            {
                ForeignLocation.Text = foreing.Ubicacion;
            }
            if (foreing.Ubicacion != "")
            {
                ForeignJob.Text = foreing.Ocupacion;
            }
            ForeignConnection.Text = Languages.ViewsLabel + foreing.Conexiones;
            #endregion
        }
        public void UpdateList(int _UserId)
        {
            List <ForeingBox> list = new List <ForeingBox>();

            using (var connSQLite = new SQLite.SQLiteConnection(App.root_db))
            {
                list = connSQLite.Query <ForeingBox>("select * from ForeingBox where ForeingBox.UserId = " + _UserId + " and ForeingBox.UserRecivedId = " + MainViewModel.GetInstance().User.UserId);
            }

            foreach (ForeingBox foreing in list)
            {
                int findValue = foreing.BoxId;
                int newIndex  = 0;
                for (int i = 0; i < ForeingBox.Count; i++)
                {
                    if (ForeingBox[i].BoxId == findValue && ForeingBox[i].UserRecivedId == MainViewModel.GetInstance().User.UserId)
                    {
                        newIndex = i;
                    }
                }

                ForeingBox.RemoveAt(newIndex);

                ForeingBox.Insert(newIndex, foreing);
            }
        }
        public void DeleteList(int a)
        {
            var F = new ForeingBox();

            foreach (ForeingBox BoxF in ForeingBox)
            {
                if (BoxF.BoxId == a && BoxF.UserRecivedId == MainViewModel.GetInstance().User.UserId)
                {
                    F = BoxF;
                }
            }
            ForeingBox.Remove(F);
        }
        public void UpdateList(ForeingBox _foreingBoxOld, ForeingBox _foreingBoxNew)
        {
            int findValue = _foreingBoxOld.BoxId;
            int newIndex  = 0;

            for (int i = 0; i < ForeingBox.Count; i++)
            {
                if (ForeingBox[i].BoxId == findValue && ForeingBox[i].UserRecivedId == MainViewModel.GetInstance().User.UserId)
                {
                    newIndex = i;
                }
            }

            ForeingBox.RemoveAt(newIndex);

            ForeingBox.Insert(newIndex, _foreingBoxNew);
        }
Пример #6
0
        public void UpdateList(ForeingBox _foreingBoxOld, ForeingBox _foreingBoxNew)
        {
            int findValue = _foreingBoxOld.BoxId;
            int newIndex  = 0;

            for (int i = 0; i < ForeingBox.Count; i++)
            {
                if (ForeingBox[i].BoxId == findValue)
                {
                    newIndex = i;
                }
            }

            ForeingBox.RemoveAt(newIndex);

            ForeingBox.Insert(newIndex, _foreingBoxNew);
        }
Пример #7
0
        public async void InsertForeignData(int user_id, int box_id)
        {
            try
            {
                var apiSecurity = Application.Current.Resources["APISecurity"].ToString();
                AddViewToUser(user_id);
                var ForeingUser = await apiService.GetUserId(apiSecurity,
                                                             "/api",
                                                             "/Users",
                                                             user_id);

                using (var connSQLite = new SQLite.SQLiteConnection(App.root_db))
                {
                    connSQLite.CreateTable <ForeingProfile>();
                }

                ForeingBox foreingBox;
                ForeingBox A          = new ForeingBox();
                ForeingBox oldForeing = new ForeingBox();

                //Validar que la box no exista
                using (var connSQLite = new SQLite.SQLiteConnection(App.root_db))
                {
                    A = connSQLite.FindWithQuery <ForeingBox>("select * from ForeingBox where ForeingBox.BoxId = " + box_id + " and ForeingBox.UserRecivedId = " + MainViewModel.GetInstance().User.UserId);
                }

                if (A == null)
                {
                    //Inicializar la box foranea
                    foreingBox = new ForeingBox
                    {
                        BoxId         = box_id,
                        UserId        = user_id,
                        Time          = DateTime.Now,
                        ImagePath     = ForeingUser.ImagePath,
                        UserTypeId    = ForeingUser.UserTypeId,
                        FirstName     = ForeingUser.FirstName,
                        LastName      = ForeingUser.LastName,
                        Edad          = ForeingUser.Edad,
                        Ubicacion     = ForeingUser.Ubicacion,
                        Ocupacion     = ForeingUser.Ocupacion,
                        Conexiones    = ForeingUser.Conexiones,
                        UserRecivedId = MainViewModel.GetInstance().User.UserId
                    };

                    //Insertar la box foranea
                    using (var connSQLite = new SQLite.SQLiteConnection(App.root_db))
                    {
                        connSQLite.CreateTable <ForeingBox>();
                        connSQLite.Insert(foreingBox);
                    }
                }
                else
                {
                    using (var connSQLite = new SQLite.SQLiteConnection(App.root_db))
                    {
                        oldForeing = A;
                        connSQLite.ExecuteScalar <ForeingBox>("UPDATE ForeingBox SET Conexiones = ? WHERE ForeingBox.UserId = ?", ForeingUser.Conexiones, ForeingUser.UserId);
                        connSQLite.ExecuteScalar <ForeingBox>("UPDATE ForeingBox SET Time = ? WHERE ForeingBox.BoxId = ?", DateTime.Now, A.BoxId);
                        A = connSQLite.FindWithQuery <ForeingBox>("select * from ForeingBox where ForeingBox.BoxId = ?", box_id);
                    }
                    foreingBox = A;
                }

                if (box_id != 0)
                {
                    if (A != null)
                    {
                        using (var connSQLite = new SQLite.SQLiteConnection(App.root_db))
                        {
                            connSQLite.Execute("Delete from ForeingProfile Where ForeingProfile.BoxId = ?", A.BoxId);
                        }
                    }

                    #region Foreing Profiles New Code
                    await GetListEmail(user_id, box_id);
                    await GetListPhone(user_id, box_id);
                    await GetListSM(user_id, box_id);
                    await GetListWhatsapp(user_id, box_id);

                    #endregion

                    if (NotNull1 == true && NotNull2 == true && NotNull3 == true && NotNull4 == true)
                    {
                        Device.BeginInvokeOnMainThread(() =>
                        {
                            MainViewModel.GetInstance().ForeingBox = new ForeingBoxViewModel(foreingBox);
                            if (PopupNavigation.PopupStack.Count != 0)
                            {
                                PopupNavigation.Instance.PopAllAsync();
                            }

                            if (A == null)
                            {
                                MainViewModel.GetInstance().ListForeignBox.AddList(foreingBox);
                            }
                            else
                            {
                                //Box anterior
                                //oldForeing
                                MainViewModel.GetInstance().ListForeignBox.UpdateList(foreingBox.UserId);
                            }
                            PopupNavigation.Instance.PushAsync(new ForeingBoxPage(foreingBox, true));
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
Пример #8
0
        private void GoToTestPage()
        {
            /*MainViewModel.GetInstance().Testing = new TestingViewModel();
             * Navigation.PushAsync(new Testing());
             * //await Launcher.OpenAsync(new Uri("https://www.facebook.com/roy.a.mustang"));*/

            //insertar box foranea
            System.Text.StringBuilder sb;
            ForeingBox     foreingBox;
            ForeingProfile foreingProfile;
            int            BoxId  = 44; //44
            int            UserId = 3;  //3

            //Inicializar la box foranea
            foreingBox = new ForeingBox
            {
                BoxId      = BoxId,
                UserId     = UserId,
                Time       = DateTime.Now,
                ImagePath  = MainViewModel.GetInstance().User.ImageFullPath,
                UserTypeId = 1,
                FirstName  = "Rodrigo",
                LastName   = "Rodriguez"
            };

            //Insertar la box foranea
            using (var connSQLite = new SQLite.SQLiteConnection(App.root_db))
            {
                connSQLite.Insert(foreingBox);
            }

            string cadenaConexion = @"data source=serverappmynfo.database.windows.net;initial catalog=mynfo;user id=adminmynfo;password=4dmiNFC*Atx2020;Connect Timeout=60";
            string 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;
            string 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;
            string 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 = " + BoxId;
            string 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 =" + BoxId;

            //Recorrer la lista de perfiles para insertarlos
            //Emails
            using (SqlConnection connection = new SqlConnection(cadenaConexion))
            {
                sb = new System.Text.StringBuilder();
                sb.Append(queryGetEmails);

                string sql = sb.ToString();

                using (SqlCommand command = new SqlCommand(sql, connection))
                {
                    connection.Open();
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            foreingProfile = new ForeingProfile
                            {
                                BoxId       = BoxId,
                                UserId      = UserId,
                                ProfileName = (string)reader["Name"],
                                value       = (string)reader["Email"],
                                ProfileType = "Email"
                            };

                            //Insertar la box foranea
                            using (var connSQLite = new SQLite.SQLiteConnection(App.root_db))
                            {
                                connSQLite.Insert(foreingProfile);
                            }
                        }
                    }

                    connection.Close();
                }
            }
            //PHones
            using (SqlConnection connection = new SqlConnection(cadenaConexion))
            {
                sb = new System.Text.StringBuilder();
                sb.Append(queryGetPhones);

                string sql = sb.ToString();

                using (SqlCommand command = new SqlCommand(sql, connection))
                {
                    connection.Open();
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            foreingProfile = new ForeingProfile
                            {
                                BoxId       = BoxId,
                                UserId      = UserId,
                                ProfileName = (string)reader["Name"],
                                value       = (string)reader["Number"],
                                ProfileType = "Phone"
                            };

                            //Insertar la box foranea
                            using (var connSQLite = new SQLite.SQLiteConnection(App.root_db))
                            {
                                connSQLite.Insert(foreingProfile);
                            }
                        }
                    }

                    connection.Close();
                }
            }
            //Whatsapp
            using (SqlConnection connection = new SqlConnection(cadenaConexion))
            {
                sb = new System.Text.StringBuilder();
                sb.Append(queryGetWhatsapp);

                string sql = sb.ToString();

                using (SqlCommand command = new SqlCommand(sql, connection))
                {
                    connection.Open();
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            foreingProfile = new ForeingProfile
                            {
                                BoxId       = BoxId,
                                UserId      = UserId,
                                ProfileName = (string)reader["Name"],
                                value       = (string)reader["Number"],
                                ProfileType = "Whatsapp"
                            };

                            //Insertar la box foranea
                            using (var connSQLite = new SQLite.SQLiteConnection(App.root_db))
                            {
                                connSQLite.Insert(foreingProfile);
                            }
                        }
                    }

                    connection.Close();
                }
            }
            //Social media
            using (SqlConnection connection = new SqlConnection(cadenaConexion))
            {
                sb = new System.Text.StringBuilder();
                sb.Append(queryGetSMProfiles);

                string sql = sb.ToString();

                using (SqlCommand command = new SqlCommand(sql, connection))
                {
                    connection.Open();
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            int IdRedSocial = (int)reader["RedSocialId"];
                            var Name        = string.Empty;
                            switch (IdRedSocial)
                            {
                            case 1:
                                Name = "Facebook";
                                break;

                            case 2:
                                Name = "Instagram";
                                break;

                            case 3:
                                Name = "Twitter";
                                break;

                            case 4:
                                Name = "Snapchat";
                                break;

                            case 5:
                                Name = "LinkedIn";
                                break;

                            case 6:
                                Name = "TikTok";
                                break;

                            case 7:
                                Name = "Youtube";
                                break;

                            case 8:
                                Name = "Spotify";
                                break;

                            case 9:
                                Name = "Twitch";
                                break;

                            case 10:
                                Name = "WebPage";
                                break;

                            default:
                                break;
                            }
                            ;
                            foreingProfile = new ForeingProfile
                            {
                                BoxId       = BoxId,
                                UserId      = UserId,
                                ProfileName = (string)reader["ProfileName"],
                                value       = (string)reader["link"],
                                ProfileType = Name
                            };

                            //Insertar la box foranea
                            using (var connSQLite = new SQLite.SQLiteConnection(App.root_db))
                            {
                                connSQLite.Insert(foreingProfile);
                            }
                        }
                    }

                    connection.Close();
                }
            }

            MainViewModel.GetInstance().ListForeignBox.AddList(foreingBox);
            MainViewModel.GetInstance().ListForeignBox.GetList();
            //Enviar a detalles de la box foranea cuando se inserta
            App.Navigator.PushAsync(new ForeingBoxPage(foreingBox, true));
            //App.Current.MainPage = new Xamarin.Forms.NavigationPage(new Mynfo.Views.ForeingBoxPage(foreingBox, true));
        }
        void OnListViewItemSelected(object sender, SelectedItemChangedEventArgs e)
        {
            ForeingBox selectedItem = e.SelectedItem as ForeingBox;

            ForeignBoxList.SelectedItem = null;
        }
Пример #10
0
        public static async void InsertForeignData(int user_id, int box_id)
        {
            ApiService apiService = new ApiService();

            int  user_I      = user_id;
            var  apiSecurity = Application.Current.Resources["APISecurity"].ToString();
            User box_detail  = new User();

            AddViewToUser(user_I);
            box_detail = await apiService.GetUserId(apiSecurity,
                                                    "/api",
                                                    "/Users",
                                                    user_I);

            using (var connSQLite = new SQLite.SQLiteConnection(App.root_db))
            {
                connSQLite.CreateTable <ForeingProfile>();
            }

            ForeingBox     foreingBox;
            ForeingProfile foreingProfile;
            ForeingBox     A          = new ForeingBox();
            ForeingBox     oldForeing = new ForeingBox();;

            //Validar que la box no exista
            using (var connSQLite = new SQLite.SQLiteConnection(App.root_db))
            {
                A = connSQLite.FindWithQuery <ForeingBox>("select * from ForeingBox where ForeingBox.BoxId = " + box_id + " and ForeingBox.UserRecivedId = " + MainViewModel.GetInstance().User.UserId);
            }

            if (A == null)
            {
                //Inicializar la box foranea
                foreingBox = new ForeingBox
                {
                    BoxId  = box_id,
                    UserId = user_I,
                    //Time = Convert.ToDateTime(nfcData[0].time).ToUniversalTime(),
                    Time          = DateTime.Now,
                    ImagePath     = box_detail.ImagePath,
                    UserTypeId    = box_detail.UserTypeId,
                    FirstName     = box_detail.FirstName,
                    LastName      = box_detail.LastName,
                    Edad          = box_detail.Edad,
                    Ubicacion     = box_detail.Ubicacion,
                    Ocupacion     = box_detail.Ocupacion,
                    Conexiones    = box_detail.Conexiones,
                    UserRecivedId = MainViewModel.GetInstance().User.UserId
                };

                //Insertar la box foranea
                using (var connSQLite = new SQLite.SQLiteConnection(App.root_db))
                {
                    connSQLite.Insert(foreingBox);
                }
            }
            else
            {
                using (var connSQLite = new SQLite.SQLiteConnection(App.root_db))
                {
                    oldForeing = A;
                    connSQLite.ExecuteScalar <ForeingBox>("UPDATE ForeingBox SET Conexiones = ? WHERE ForeingBox.UserId = ?", box_detail.Conexiones, box_detail.UserId);
                    connSQLite.ExecuteScalar <ForeingBox>("UPDATE ForeingBox SET Time = ? WHERE ForeingBox.BoxId = ?", DateTime.Now, A.BoxId);
                    A = connSQLite.FindWithQuery <ForeingBox>("select * from ForeingBox where ForeingBox.BoxId = ?", box_id);
                }
                foreingBox = A;
            }
            try
            {
                if (box_id != 0)
                {
                    //using (var connSQLite = new SQLite.SQLiteConnection(App.root_db))
                    //{
                    //    connSQLite.CreateTable<Profile_get>();
                    //}
                    if (A != null)
                    {
                        using (var connSQLite = new SQLite.SQLiteConnection(App.root_db))
                        {
                            connSQLite.Execute("Delete from ForeingProfile Where ForeingProfile.BoxId = ?", A.BoxId);
                        }
                    }
                    #region ForeignProfiles
                    System.Text.StringBuilder sb;
                    string cadenaConexion = @"data source=serverappmynfo.database.windows.net;initial catalog=mynfo;user id=adminmynfo;password=4dmiNFC*Atx2020;Connect Timeout=60";

                    //string cadenaConexion = @"data source=serverappmynfo1.database.windows.net;initial catalog=mynfo;user id=adminmynfo;password=4dmiNFC*Atx2020;Connect Timeout=60";

                    //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 = " + box_id;
                    string queryGetBoxPhone = "select * from dbo.ProfilePhones " +
                                              "join dbo.Box_ProfilePhone on" +
                                              "(dbo.ProfilePhones.ProfilePhoneId = dbo.Box_ProfilePhone.ProfilePhoneId) " +
                                              "where dbo.Box_ProfilePhone.BoxId = " + box_id;
                    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_id;
                    string queryGetBoxWhatsappProfiles = "select * from dbo.ProfileWhatsapps " +
                                                         "join dbo.Box_ProfileWhatsapp on" +
                                                         "(dbo.ProfileWhatsapps.ProfileWhatsappId = dbo.Box_ProfileWhatsapp.ProfileWhatsappId) " +
                                                         "where dbo.Box_ProfileWhatsapp.BoxId = " + box_id;

                    //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())
                                {
                                    foreingProfile = new ForeingProfile
                                    {
                                        BoxId       = box_id,
                                        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(foreingProfile);
                                    }
                                }
                            }

                            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())
                                {
                                    foreingProfile = new ForeingProfile
                                    {
                                        BoxId       = box_id,
                                        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(foreingProfile);
                                    }
                                }
                            }

                            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())
                                {
                                    foreingProfile = new ForeingProfile
                                    {
                                        BoxId       = box_id,
                                        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(foreingProfile);
                                    }
                                }
                            }
                            conn1.Close();
                        }
                    }

                    //Consulta para obtener perfiles Whatsapp
                    using (SqlConnection conn1 = new SqlConnection(cadenaConexion))
                    {
                        sb = new System.Text.StringBuilder();
                        sb.Append(queryGetBoxWhatsappProfiles);

                        string sql = sb.ToString();

                        using (SqlCommand command = new SqlCommand(sql, conn1))
                        {
                            conn1.Open();
                            using (SqlDataReader reader = command.ExecuteReader())
                            {
                                while (reader.Read())
                                {
                                    foreingProfile = new ForeingProfile
                                    {
                                        BoxId       = box_id,
                                        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(foreingProfile);
                                    }
                                }
                            }

                            conn1.Close();
                        }
                    }
                    #endregion
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        //App.Navigator.PushAsync(new ForeingBoxPage(foreingBox, true));
                        MainViewModel.GetInstance().ForeingBox = new ForeingBoxViewModel(foreingBox);
                        //App.Navigator.PopAsync();
                        if (PopupNavigation.PopupStack.Count != 0)
                        {
                            PopupNavigation.Instance.PopAllAsync();
                        }
                        //PopupNavigation.Instance.PushAsync(new ForeingBoxPage(foreingBox, true));
                        if (A == null)
                        {
                            MainViewModel.GetInstance().ListForeignBox.AddList(foreingBox);
                        }
                        else
                        {
                            //Box anterior
                            //oldForeing
                            MainViewModel.GetInstance().ListForeignBox.UpdateList(foreingBox.UserId);
                        }
                        PopupNavigation.Instance.PushAsync(new ForeingBoxPage(foreingBox, true));
                    });
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
Пример #11
0
        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);
        }
Пример #12
0
 public ForeingBoxViewModel(ForeingBox _foreingBox)
 {
     DataFill(_foreingBox);
 }
 public void AddList(ForeingBox _foreingBox)
 {
     ForeingBox.Add(_foreingBox);
 }
Пример #14
0
 public ForeingBoxViewModel(ForeingBox _foreingBox, bool isAfterReceiving = false)
 {
     DataFill(_foreingBox);
 }
Пример #15
0
        public static async void InsertForeignData(string user_id, int box_id)
        {
            ApiService apiService = new ApiService();

            int  user_I      = Convert.ToInt32(user_id);
            var  apiSecurity = Application.Current.Resources["APISecurity"].ToString();
            User box_detail  = new User();

            box_detail = await apiService.GetUserId(apiSecurity,
                                                    "/api",
                                                    "/Users",
                                                    user_I);

            using (var connSQLite = new SQLite.SQLiteConnection(App.root_db))
            {
                connSQLite.CreateTable <ForeingProfile>();
            }

            ForeingBox     foreingBox;
            ForeingProfile foreingProfile;

            //Validar que la box no exista
            //using (var connSQLite = new SQLite.SQLiteConnection(App.root_db))
            //{
            //    connSQLite.CreateTable<ForeingBox>();
            //}



            //Inicializar la box foranea
            foreingBox = new ForeingBox
            {
                BoxId  = box_id,
                UserId = user_I,
                //Time = Convert.ToDateTime(nfcData[0].time).ToUniversalTime(),
                Time       = DateTime.Now,
                ImagePath  = box_detail.ImagePath,
                UserTypeId = box_detail.UserTypeId,
                FirstName  = box_detail.FirstName,
                LastName   = box_detail.LastName
            };

            //Insertar la box foranea
            using (var connSQLite = new SQLite.SQLiteConnection(App.root_db))
            {
                connSQLite.Insert(foreingBox);
            }
            try
            {
                if (box_id != 0)
                {
                    using (var connSQLite = new SQLite.SQLiteConnection(App.root_db))
                    {
                        connSQLite.CreateTable <Profile_get>();
                    }


                    System.Text.StringBuilder sb;
                    //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";

                    //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 = " + box_id;
                    string queryGetBoxPhone = "select * from dbo.ProfilePhones " +
                                              "join dbo.Box_ProfilePhone on" +
                                              "(dbo.ProfilePhones.ProfilePhoneId = dbo.Box_ProfilePhone.ProfilePhoneId) " +
                                              "where dbo.Box_ProfilePhone.BoxId = " + box_id;
                    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_id;

                    //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())
                                {
                                    foreingProfile = new ForeingProfile
                                    {
                                        BoxId       = box_id,
                                        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(foreingProfile);
                                    }
                                }
                            }

                            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())
                                {
                                    foreingProfile = new ForeingProfile
                                    {
                                        BoxId       = box_id,
                                        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(foreingProfile);
                                    }
                                }
                            }

                            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())
                                {
                                    foreingProfile = new ForeingProfile
                                    {
                                        BoxId       = box_id,
                                        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(foreingProfile);
                                    }
                                }
                            }
                            conn1.Close();
                        }
                    }
                }
                Device.BeginInvokeOnMainThread(() =>
                {
                    //App.Navigator.PushAsync(new ForeingBoxPage(foreingBox, true));
                    MainViewModel.GetInstance().ForeingBox = new ForeingBoxViewModel(foreingBox, true);
                    Application.Current.MainPage.Navigation.PushModalAsync(new ForeingBoxPage(foreingBox, true));
                    MainViewModel.GetInstance().ListForeignBox.AddList(foreingBox);
                });
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }