public bool AddSubCategoryOffline(SubCategoryOfflineViewModel newSubCategoryOffline, string _synced)
        {
            bool result = false;
            try
            {
                using (var db = new SQLite.SQLiteConnection(_dbPath))
                {
                    SubCategoryOffline objSubCategoryOffline = new SubCategoryOffline();

                    objSubCategoryOffline.categoryId = Convert.ToString(newSubCategoryOffline.categoryId);
                    objSubCategoryOffline.organizationId = Convert.ToString(newSubCategoryOffline.organizationId);
                    objSubCategoryOffline.categoryCode = Convert.ToString(newSubCategoryOffline.categoryCode);
                    objSubCategoryOffline.categoryDescription = newSubCategoryOffline.categoryDescription;
                    objSubCategoryOffline.parentCategoryId = newSubCategoryOffline.parentCategoryId;
                    objSubCategoryOffline.parentCategory = newSubCategoryOffline.parentCategory;
                    objSubCategoryOffline.imageName = newSubCategoryOffline.imageName;
                    objSubCategoryOffline.active = newSubCategoryOffline.active;

                    objSubCategoryOffline.synced = _synced;  // i.e. Need to synced when online and Update the synced status = "True"

                    db.RunInTransaction(() =>
                    {
                        db.Insert(objSubCategoryOffline);
                    });
                }

                result = true;
            }//try
            catch (Exception ex)
            {

            }//catch
            return result;
        }
        public SubCategoryDetailsPage()
        {
            InitializeComponent();

            if (IsolatedStorageSettings.ApplicationSettings.Contains("islogin"))
            {
                if (!(Convert.ToString(IsolatedStorageSettings.ApplicationSettings["islogin"]).ToLower() == "yes"))
                {
                    NavigationService.Navigate(new Uri("/Views/Login/LoginPage.xaml", UriKind.RelativeOrAbsolute));
                }
                else
                {
                    if (ISOFile.FileExists("viewSubCategoryDetails"))//read current user login details
                    {
                        using (IsolatedStorageFileStream fileStream = ISOFile.OpenFile("viewSubCategoryDetails", FileMode.Open))
                        {
                            //====================================================================================================================
                            // Read Category Details
                            //====================================================================================================================
                            ObjSubCategoryData = new SubCategoryOfflineViewModel();
                            DataContractSerializer serializer = new DataContractSerializer(typeof(SubCategoryOfflineViewModel));
                            ObjSubCategoryData = (SubCategoryOfflineViewModel)serializer.ReadObject(fileStream);
                            lblSubCategory.Text = ObjSubCategoryData.categoryCode;
                            lblDescription.Text = ObjSubCategoryData.categoryDescription;
                            lblCategory.Text = ObjSubCategoryData.parentCategory;
                            if (!string.IsNullOrEmpty(ObjSubCategoryData.fullImagePath))
                            {
                                imgSubCategory.ImageSource = new BitmapImage(new Uri(ObjSubCategoryData.fullImagePath, UriKind.RelativeOrAbsolute));
                            }
                            else
                            {
                                imgSubCategory.ImageSource = new BitmapImage(new Uri("/Assets/category/icon_sub_categories.png", UriKind.RelativeOrAbsolute));
                            }
                        }
                    }
                }
            }
            else
            {
                NavigationService.Navigate(new Uri("/Views/Login/LoginPage.xaml", UriKind.RelativeOrAbsolute));
            }
        }
        void wc_UploadStringCompleted(object sender, UploadStringCompletedEventArgs e)
        {
            try
            {
                CategoryDataProvider _CategoryDataProvider = new CategoryDataProvider();

                if (e.Result.Contains("no Sub Category found"))
                {
                    ListSubCategoryData = new List<SubCategoryOfflineViewModel>();
                    this.lstSubCateoryItems.ItemsSource = ListSubCategoryData;
                }
                else
                {
                    //Parse JSON result
                    var rootObject = JsonConvert.DeserializeObject<RootObject_SubCategory>(e.Result);
                    if (rootObject.success == 1)
                    {
                        foreach (var itm in rootObject.response.data)
                        {
                            SubCategoryOfflineViewModel obj = new SubCategoryOfflineViewModel();
                            obj.categoryId = Convert.ToString(itm.categoryId);
                            obj.organizationId = Convert.ToString(itm.organizationId);
                            obj.categoryCode = Convert.ToString(itm.categoryCode);
                            obj.categoryDescription = itm.categoryDescription;
                            obj.parentCategoryId = itm.parentCategoryId;
                            obj.parentCategory = itm.parentCategory;
                            obj.imageName = itm.imageName;
                            obj.active = itm.active;

                            _CategoryDataProvider = new CategoryDataProvider();
                            var result = _CategoryDataProvider.AddSubCategoryOffline(obj, "True");
                            if (result == true)
                            {
                                //MessageBox.Show("successfully registerd Sub Category.");
                            }
                        }

                        //====================================================================================================================
                        // Fill Sub Category List From Offline DB
                        //====================================================================================================================

                        _CategoryDataProvider = new CategoryDataProvider();
                        ListSubCategoryData = new List<SubCategoryOfflineViewModel>();
                        foreach (var itm in rootObject.response.data)
                        {
                            var Source = "/Assets/category/icon_sub_categories.png";
                            if (!string.IsNullOrEmpty(itm.imageName))
                            {
                                Source = Utilities.GetMarketplaceURL() + uploadImagePath.SUBCATEGORY + itm.imageName;
                            }

                            ListSubCategoryData.Add(new SubCategoryOfflineViewModel { categoryId = itm.categoryId, organizationId = itm.organizationId, categoryCode = itm.categoryCode, categoryDescription = itm.categoryDescription, imageName = itm.imageName, imagePath = itm.imagePath, active = itm.active, parentCategoryId = itm.parentCategoryId, createDt = itm.createDt, lastModifiedDt = itm.lastModifiedDt, lastModifiedBy = itm.lastModifiedBy, parentCategory = itm.parentCategory, fullImagePath = Source });
                        };
                        this.lstSubCateoryItems.ItemsSource = ListSubCategoryData;

                        // hide Loader
                        myIndeterminateProbar.Visibility = Visibility.Collapsed;
                    }
                    else
                    {
                        MessageBox.Show(rootObject.response.message.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Something wrong happened.");
            }
            finally
            {
                // hide Loader
                myIndeterminateProbar.Visibility = Visibility.Collapsed;
            }
        }
        private void ImgAddSubCateory_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            if (Utilities.CheckInternetConnection())
            {
                // ----------------------------------------------------------------------
                // "Network Status: Connected."

                //====================================================================================================================
                // Add new Sub Category
                //====================================================================================================================

                SubCategoryOfflineViewModel _CategoryDataContext = new SubCategoryOfflineViewModel();
                // Set page mode for Add record of SubCategory
                _redirectMode = "Add";
                _CategoryDataContext.mode = "Add";
                if (ISOFile.FileExists("viewSubCategoryDetails"))
                {
                    ISOFile.DeleteFile("viewSubCategoryDetails");
                }
                using (IsolatedStorageFileStream fileStream = ISOFile.OpenFile("viewSubCategoryDetails", FileMode.Create))
                {
                    DataContractSerializer serializer = new DataContractSerializer(typeof(SubCategoryOfflineViewModel));
                    serializer.WriteObject(fileStream, _CategoryDataContext);

                    NavigationService.Navigate(new Uri("/Views/SubCategory/SubCategoryAddEditPage.xaml", UriKind.RelativeOrAbsolute));
                }
            }
            else
            {
                // ----------------------------------------------------------------------
                //  "Network Status: Not Connected."

                MessageBox.Show("You can not create a new sub category in offline mode.");
            }
        }
        private void ImgAddSubCateory_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            //====================================================================================================================
            // Add new Sub Category
            //====================================================================================================================

            SubCategoryOfflineViewModel _CategoryDataContext = new SubCategoryOfflineViewModel();
            // Set page mode for Add record of SubCategory
            _redirectMode = "Add";
            _CategoryDataContext.mode = "Add";
            if (ISOFile.FileExists("viewSubCategoryDetails"))
            {
                ISOFile.DeleteFile("viewSubCategoryDetails");
            }
            using (IsolatedStorageFileStream fileStream = ISOFile.OpenFile("viewSubCategoryDetails", FileMode.Create))
            {
                DataContractSerializer serializer = new DataContractSerializer(typeof(SubCategoryOfflineViewModel));
                serializer.WriteObject(fileStream, _CategoryDataContext);

                NavigationService.Navigate(new Uri("/Views/SubCategory/SubCategoryAddEditPage.xaml", UriKind.RelativeOrAbsolute));
            }
        }