//=========================== SYNC SYSTEM ============================= /// <summary> /// Upload entire information item/order list from FTP/Cloud_Sync/FullSync directory /// </summary> public static void DownloadAllInformation() { string syncText = ""; string emailAddress = GetSettingsValue("SYNC_EMAIL"); try { if (Global.isOnWifi()) // only try on WiFi (most data will block this) { List <string> lines = new List <string>(); // Copy local repository to FTP Server if (Device.OS == TargetPlatform.Android || Device.OS == TargetPlatform.iOS) { // Read from FTP File //string[] lines = GetFileContent(emailAddress + SyncFileName) lines = AESGCM .SimpleDecryptWithPassword( DependencyService.Get <IFtpWebRequest>().FTPRead(emailAddress + FullSyncFileName), AESGCMKey) .Split(new[] { Environment.NewLine }, StringSplitOptions.None).ToList(); } // Load items and orders from downloaded file foreach (string line in lines) { // Load items if (line.Contains("||[IT_LO]=")) { Item New_Item = new Item(); New_Item.Name = Parse_Line_Information(line, "IT_DE_"); New_Item.Status = Parse_Line_Information(line, "IT_ST_") == "" ? "0" : Parse_Line_Information(line, "IT_ST_"); New_Item.RefundAlert = Parse_Line_Information(line, "IT_RE_") == "1" ? true : false; New_Item.consumedStatus = Convert.ToInt32(Parse_Line_Information(line, "IT_CO_", "||", "2")); New_Item.Location = Parse_Line_Information(line, "IT_LO"); New_Item.Payment_Type = Parse_Line_Information(line, "IT_PA_"); New_Item.Category = Parse_Line_Information(line, "IT_CA_"); New_Item.Discount_Amt = Convert.ToDouble(Parse_Line_Information(line, "IT_DI_", "||", "0")); New_Item.Price = Convert.ToDouble(Parse_Line_Information(line, "IT_PR_")); New_Item.Quantity = Convert.ToInt32(Parse_Line_Information(line, "IT_QU_")); New_Item.Date = Convert.ToDateTime(Parse_Line_Information(line, "IT_DA_")); New_Item.Refund_Date = Parse_Line_Information(line, "IT_RD_").Length > 0 ? Convert.ToDateTime(Parse_Line_Information(line, "IT_RD_")) : DateTime.Now; New_Item.Memo = Parse_Line_Information(line, "IT_ME_"); New_Item.OrderID = Parse_Line_Information(line, "IT_ID_"); GlobalItemList.Add(New_Item); } // Load orders else if (line.Contains("||[OR_QU_]=")) { Order New_Order = new Order(); New_Order.Location = Parse_Line_Information(line, "OR_LO_"); New_Order.OrderMemo = Parse_Line_Information(line, "OR_ME_"); New_Order.Payment = Parse_Line_Information(line, "OR_PA_"); New_Order.Tax_Overridden = (Parse_Line_Information(line, "OR_TO_") == "1"); New_Order.Order_Total_Pre_Tax = Convert.ToDouble(Parse_Line_Information(line, "OR_PP_")); New_Order.GC_Amount = Convert.ToDouble(Parse_Line_Information(line, "OR_GC_", "||", "0")); New_Order.Order_Taxes = Convert.ToDouble(Parse_Line_Information(line, "OR_TA_")); New_Order.Order_Discount_Amt = Convert.ToDouble(Parse_Line_Information(line, "OR_DI_", "||", "0")); New_Order.Order_Quantity = Convert.ToInt32(Parse_Line_Information(line, "OR_QU_")); New_Order.Date = Convert.ToDateTime(Parse_Line_Information(line, "OR_DA_")); New_Order.OrderID = Parse_Line_Information(line, "OR_ID_"); GlobalOrderList.Add(New_Order); } } foreach (Item item in GlobalItemList) { Debug.WriteLine(item.ToString()); } } } catch (Exception Ex) { Debug.WriteLine("No file found: " + Ex); } }
//=========================== LOAD FILES ============================== /// <summary> /// Load all local information from configuration file /// </summary> public static string LoadLocalInformation() { ResetParameters(); try { string[] lines = GetFileContent(ConfigFileName) .Split(new [] { Environment.NewLine }, StringSplitOptions.None); List <string> tempLocation = new List <string>(); List <string> tempPayment = new List <string>(); List <string> tempCategories = new List <string>(); foreach (string line in lines) { #region Load Local Settings if (line.Contains("[PE_SE]")) { SetSettingsValue("SYNC_EMAIL", Parse_Line_Information(line, "SYNC_EMAIL")); SetSettingsValue("EMAIL_VALIDATED", Parse_Line_Information(line, "EMAIL_VALIDATED")); } #endregion #region Load Locations if (line.Contains("[LO_NA_]=")) { tempLocation.Add(Parse_Line_Information(line, "LO_NA_")); } #endregion #region Load Payments if (line.Contains("[PA_NA_]=")) { tempPayment.Add(Parse_Line_Information(line, "PA_NA_")); } #endregion #region Load Categories if (line.Contains("[CA_NA_]=")) { tempCategories.Add(Parse_Line_Information(line, "CA_NA_")); } #endregion #region Load Items if (line.Contains("[LT_NA_]=")) { MasterItemList.Add(new Item( Parse_Line_Information(line, "LT_NA_"), Convert.ToDouble(Parse_Line_Information(line, "LT_PR_")), Convert.ToInt32(Parse_Line_Information(line, "LT_QU_")), Parse_Line_Information(line, "LT_CA_"), Parse_Line_Information(line, "LT_ID_") )); } #endregion #region Load Orders if (line.Contains("[LR_LO_]=")) { OrderList.Add(new Order( Parse_Line_Information(line, "LR_LO_"), //Convert.ToDouble(Parse_Line_Information(line, "PRETAX_PRICE")), Parse_Line_Information(line, "LR_PA_"), Convert.ToDateTime(Parse_Line_Information(line, "LR_DA_")), Parse_Line_Information(line, "LR_SY_") == "1", Parse_Line_Information(line, "LR_ID_") )); } #endregion #region Load ShopItem List if (line.Contains("[SI_NA_]=")) { ShoppingList.Add(new ShopItem(Parse_Line_Information(line, "SI_NA_"), Parse_Line_Information(line, "SI_CA_") )); } #endregion #region Load Global Items if (line.Contains("||[IT_LO]=")) { Item New_Item = new Item(); New_Item.Name = Parse_Line_Information(line, "IT_DE_"); New_Item.Status = Parse_Line_Information(line, "IT_ST_") == "" ? "0" : Parse_Line_Information(line, "IT_ST_"); New_Item.RefundAlert = Parse_Line_Information(line, "IT_RE_") == "1" ? true : false; New_Item.consumedStatus = Convert.ToInt32(Parse_Line_Information(line, "IT_CO_", "||", "2")); New_Item.Location = Parse_Line_Information(line, "IT_LO"); New_Item.Payment_Type = Parse_Line_Information(line, "IT_PA_"); New_Item.Category = Parse_Line_Information(line, "IT_CA_"); New_Item.Discount_Amt = Convert.ToDouble(Parse_Line_Information(line, "IT_DI_", "||", "0")); New_Item.Price = Convert.ToDouble(Parse_Line_Information(line, "IT_PR_")); New_Item.Quantity = Convert.ToInt32(Parse_Line_Information(line, "IT_QU_")); New_Item.Date = Convert.ToDateTime(Parse_Line_Information(line, "IT_DA_")); New_Item.Refund_Date = Parse_Line_Information(line, "IT_RD_").Length > 0 ? Convert.ToDateTime(Parse_Line_Information(line, "IT_RD_")) : DateTime.Now; New_Item.Memo = Parse_Line_Information(line, "IT_ME_"); New_Item.OrderID = Parse_Line_Information(line, "IT_ID_"); GlobalItemList.Add(New_Item); } #endregion #region Load Global Orders // Load orders else if (line.Contains("||[OR_QU_]=")) { Order New_Order = new Order(); New_Order.Location = Parse_Line_Information(line, "OR_LO_"); New_Order.OrderMemo = Parse_Line_Information(line, "OR_ME_"); New_Order.Payment = Parse_Line_Information(line, "OR_PA_"); New_Order.Tax_Overridden = (Parse_Line_Information(line, "OR_TO_") == "1"); New_Order.Order_Total_Pre_Tax = Convert.ToDouble(Parse_Line_Information(line, "OR_PP_")); New_Order.GC_Amount = Convert.ToDouble(Parse_Line_Information(line, "OR_GC_", "||", "0")); New_Order.Order_Taxes = Convert.ToDouble(Parse_Line_Information(line, "OR_TA_")); New_Order.Order_Discount_Amt = Convert.ToDouble(Parse_Line_Information(line, "OR_DI_", "||", "0")); New_Order.Order_Quantity = Convert.ToInt32(Parse_Line_Information(line, "OR_QU_")); New_Order.Date = Convert.ToDateTime(Parse_Line_Information(line, "OR_DA_")); New_Order.OrderID = Parse_Line_Information(line, "OR_ID_"); GlobalOrderList.Add(New_Order); } #endregion } // Load all synced orders LoadSyncFile(); // Sort locations LocationList = new ObservableCollection <string>(tempLocation.OrderBy(x => x)); PaymentList = new ObservableCollection <string>(tempPayment.OrderBy(x => x)); CategoryList = new ObservableCollection <string>(tempCategories.OrderBy(x => x)); // Remove synced orders from current orders return(RemoveSyncedOrders()); } catch (Exception ex) { Debug.WriteLine("Error with loading file: " + ex); } return(""); }