public async void UpdatePlayer(Player player)
        {
            var existingPlayer = _allPlayers.Find(x => x.Id == player.Id);

            if (existingPlayer == null)
            {
                AddPlayer(player);
                return;
            }

            var record = new StoreRecord <Player>
            {
                Storename = "Players",
                Data      = player
            };

            await _dbManager.UpdateRecord(record);

            PropertyInfo[] properties = typeof(Player).GetProperties();

            foreach (var prop in properties)
            {
                if (prop.GetValue(existingPlayer) != prop.GetValue(player))
                {
                    prop.SetValue(existingPlayer, prop.GetValue(player));
                }
            }

            _allPlayers.Remove(existingPlayer);
        }
Exemple #2
0
 private static void Prefix(AdmiraltyManager __instance)
 {
     if (_settings.InfRifleStock || _settings.InfRifleStockArmory)
     {
         EPickerContent epickerContent = __instance.SelectedItem.ContentType;
         if (epickerContent != EPickerContent.Cannon)
         {
             if (epickerContent == EPickerContent.Rifle)
             {
                 StoreRecord storeRecord = (__instance.SelectedItem.ContentItem as RifleItem).StoreRecord;
                 if (_settings.InfRifleStock)
                 {
                     storeRecord.Shop = 999999;
                 }
                 if (_settings.InfRifleStockArmory)
                 {
                     storeRecord.Armory = 999999;
                 }
             }
         }
         else
         {
             CannonModule cannon      = (__instance.SelectedItem.ContentItem as CannonItem).Cannon;
             StoreModule  storeCannon = PlayerController.instance.GetStoreCannon(cannon, true);
             if (_settings.InfRifleStock)
             {
                 storeCannon.Shop = 999999;
             }
             if (_settings.InfRifleStockArmory)
             {
                 storeCannon.Armory = 999999;
             }
         }
     }
 }
Exemple #3
0
        private async Task PopulateDatabaseAsync()
        {
            var powers = new Power[]
            {
                new Power {
                    Id = 0, Name = "Single_Shot"
                },
                new Power {
                    Id = 1, Name = "Pummel"
                },
            };

            foreach (var power in powers)
            {
                var p = await IndexedDBManager.GetRecordById <int, Power>("Powers", power.Id);

                var record = new StoreRecord <Power>
                {
                    Storename = "Powers",
                    Data      = power,
                };
                if (p == null)
                {
                    await IndexedDBManager.AddRecord(record);
                }
                else
                {
                    await IndexedDBManager.UpdateRecord(record);
                }
            }
        }
        public JsonResult UpdatePreferences(string ShopUrl, string StoreName, string StoreAddress1, string Suburb, string Postcode, string Phone, string ApiKey, int CountryCode)
        {
            //update values
            DbEngine conn = new DbEngine();

            conn.UpdateStringValues(ShopUrl, "FastwayApiKey", ApiKey);
            conn.UpdateStringValues(ShopUrl, "StoreName", StoreName);
            conn.UpdateStringValues(ShopUrl, "StoreAddress1", StoreAddress1);
            conn.UpdateStringValues(ShopUrl, "Suburb", Suburb);
            conn.UpdateStringValues(ShopUrl, "Phone", Phone);
            conn.UpdateStringValues(ShopUrl, "Postcode", Postcode);
            conn.UpdateIntergerValues(ShopUrl, "CountryCode", CountryCode);
            //from store data forming json for front-end
            StoreRecord          details        = conn.GetShopRecord(ShopUrl);
            JavaScriptSerializer jsonSerialiser = new JavaScriptSerializer();
            string storeDetails = jsonSerialiser.Serialize(details);

            try
            {
                return(Json(new
                {//return status success
                    Updated = storeDetails
                }));
            }
            catch (Exception e)
            {//error
                throw e;
            }
        }
Exemple #5
0
 //重置组内容
 public void SetGroup(StoneManager _this, StoreRecord oldStore, StoreItem Item)
 {
     _this.GroupDatas.Remove(oldStore.Id);
     _this.GroupDatas[Item.Id] = Item;
     _this.mDbData.Items.Remove(oldStore.Id);
     _this.mDbData.Items[Item.Id] = Item.mDbData;
 }
Exemple #6
0
        public static async Task DownloadUIDataAndSaveInIndexedDB()
        {
            if (!LocalData.uiTranslator.TSUIWordNativesList.Any())
            {
                LocalData.uiTranslator.TSUIWordNativesList = await WebApiFunctions.CmdGetAllUIWordNatives();
            }

            LocalData.uiTranslator.PrepareDict(await WebApiFunctions.CmdGetAllUIWordForeigns(LocalData.uiTranslator.CurrUILanguage.ID));



            if (LocalData.UsingIndexedDb)
            {
                foreach (var item in LocalData.uiTranslator.TSUIWordsPairsList)
                {
                    var newRecord = new StoreRecord <TSUIWordsPair>
                    {
                        Storename = "UILangDict" + LocalData.uiTranslator.CurrUILanguage.Code,
                        Data      = item
                    };

                    await LocalData.indexedDbManager.AddRecord(newRecord);
                }
            }
        }
        private void Exchange(int index, StoreRecord storeRecord)
        {
            if (storeRecord == null)
            {
                return;
            }
            var _index = index;
            var _count = 1;

            //每日购买限制
            var _tbEx = Table.GetExdata(storeRecord.DayCount);

            if (_tbEx == null)
            {
                return;
            }

            int vipCount = 0;

            for (int i = 0; i < PlayerDataManager.Instance.TbVip.BuyItemId.Length; i++)
            {
                if (PlayerDataManager.Instance.TbVip.BuyItemId[i] == _index && i < PlayerDataManager.Instance.TbVip.BuyItemCount.Length)
                {
                    vipCount = PlayerDataManager.Instance.TbVip.BuyItemCount[i];
                }
            }
            var _dayCount = _tbEx.InitValue + vipCount;


            //当前剩余购买次数
            var _curCount = PlayerDataManager.Instance.GetExData(storeRecord.DayCount);
            var _times    = _dayCount - _curCount;

            var _tbSkillUpGrading = Table.GetSkillUpgrading(storeRecord.WaveValue);

            if (null == _tbSkillUpGrading || 0 == _tbSkillUpGrading.Values.Count)
            {
                return;
            }
            if (index == (int)eExchangeType.Gold)
            {
                if (PlayerDataManager.Instance.GetRes(storeRecord.NeedType) < DataModel.GoldNeedDiamond)
                {
                    GameUtils.ShowHintTip(300401);
                    PlayerDataManager.Instance.ShowItemInfoGet(storeRecord.NeedType);
                    return;
                }
            }
            else if (index == (int)eExchangeType.Exp)
            {
                if (PlayerDataManager.Instance.GetRes(storeRecord.NeedType) < DataModel.ExpNeedDiamond)
                {
                    GameUtils.ShowHintTip(100003320);
                    PlayerDataManager.Instance.ShowItemInfoGet(storeRecord.NeedType);
                    return;
                }
            }
            NetManager.Instance.StartCoroutine(ShopPurchaseCoroutine(_index, _count));
        }
 public void CleanUp()
 {
     DataModel = new ExchangeDataModel();
     m_tbStore = Table.GetStore(STOREID);
     if (m_tbStore == null)
     {
         return;
     }
 }
Exemple #9
0
        private static bool DoWePublishThisRecord(StoreRecord storeRecord)
        {
            var result = storeRecord.Key != "audit";

            if (result)
            {
                _storeRecords.Add(storeRecord);
            }
            return(result);
        }
Exemple #10
0
        public async Task UpdateAsync <T>(string storeName, T updateItem)
        {
            var updateRecord = new StoreRecord <T>
            {
                Storename = storeName,
                Data      = updateItem
            };

            await _dbManager.UpdateRecord(updateRecord);
        }
Exemple #11
0
        public async Task AddAsync <T>(string storeName, T valueItem)
        {
            var newRecord = new StoreRecord <T>
            {
                Storename = storeName,
                Data      = valueItem
            };

            await _dbManager.AddRecord(newRecord);
        }
        public async void AddPlayer(Player player)
        {
            var record = new StoreRecord <Player>
            {
                Storename = "Players",
                Data      = player
            };

            await _dbManager.AddRecord(record);

            _allPlayers.Add(player);
        }
        private void GetExpNumByLevel(StoreRecord storeRecord)
        {
            int level = PlayerDataManager.Instance.GetLevel();

            if (level <= 100)
            {
                DataModel.ExpNum = storeRecord.ItemCount;
            }
            else
            {
                DataModel.ExpNum = storeRecord.ItemCount + ((level - 100) / 10) * storeRecord.BlessGrow;
            }
        }
        public async Task MoveFlashcard(FlashcardWord flashcardWord, int group)
        {
            StoreRecord <FlashcardWord> record;

            flashcardWord.Day           = group;
            flashcardWord.LastTrainDate = DateTime.Now.Ticks;
            record = new StoreRecord <FlashcardWord>
            {
                Storename = DbConstants.FlashcardsStoreName,
                Data      = flashcardWord
            };

            await DbManager.UpdateRecord(record);
        }
 public void CleanUp()
 {
     DataModel     = new ExchangeDataModel();
     m_tbStoreGold = Table.GetStore((int)eExchangeType.Gold);
     if (m_tbStoreGold == null)
     {
         return;
     }
     m_tbStoreExp = Table.GetStore((int)eExchangeType.Exp);
     if (m_tbStoreExp == null)
     {
         return;
     }
 }
Exemple #16
0
    public void IsCanUse(StoreRecord tbStore, StoreCellData item)
    {
        if (item.Limit == 0)
        {
            item.CanUse = false;
            return;
        }
        if (tbStore.ItemId < 0)
        {
            item.CanUse = false;
            return;
        }
        var tbItemBase = Table.GetItemBase(tbStore.ItemId);

        item.CanUse = PlayerDataManager.Instance.ItemOrEquipCanUse(tbItemBase);
    }
Exemple #17
0
        /// <summary>
        /// Controller to update customer preferences
        /// </summary>
        /// <param name="shopUrl">web url of the store</param>
        /// <returns></returns>
        public ActionResult Preferences(string shopUrl)
        {
            //object to get store data from DB
            StoreRecord details = new StoreRecord();
            //db object to query
            DbEngine conn = new DbEngine();

            //get store data
            details = conn.GetShopRecord(shopUrl);
            //from store data forming json for front-end
            JavaScriptSerializer jsonSerialiser = new JavaScriptSerializer();
            string storeDetails = jsonSerialiser.Serialize(details);

            Response.Write("<input id='shopUrl' type='hidden' value='" + shopUrl + "'>");
            Response.Write("<input id='shopDetails' type='hidden' value='" + storeDetails + "'>");
            return(View());
        }
Exemple #18
0
    public async Task SaveGameAsync(string gameId, int slot, GameState state)
    {
        var saveGameRecord = new StoreRecord <SavedGame>
        {
            Storename = StoreName,
            Data      = SavedGame.Create(gameId, slot, state)
        };

        if (await SavedGameExists(gameId, slot))
        {
            await _dbManager.UpdateRecord(saveGameRecord);
        }
        else
        {
            await _dbManager.AddRecord(saveGameRecord);
        }
    }
Exemple #19
0
        public static async Task GetUILanguages()
        {
            LocalData.uiTranslator.ComboUILanguagesSelectedIndex = 1;

            if (!LocalData.uiTranslator.TSUILanguagesList.Any())
            {
                LocalData.uiTranslator.TSUILanguagesList = await WebApiFunctions.CmdGetAllUILanguages();



                if (LocalData.UsingIndexedDb)
                {
                    List <TSUILanguage> ListInIndexedDB = await LocalData.indexedDbManager.GetRecords <TSUILanguage>("UILanguages");

                    foreach (var item in LocalData.uiTranslator.TSUILanguagesList)
                    {
                        if (ListInIndexedDB is null)
                        {
                            await AddUILanguageAndStore(item);
                        }
                        else
                        {
                            if (ListInIndexedDB.Any(x => x.Code.Equals(item.Code, StringComparison.InvariantCultureIgnoreCase)))
                            {
                                if (item.Version != ListInIndexedDB.Single(x => x.Code.Equals(item.Code, StringComparison.InvariantCultureIgnoreCase)).Version)
                                {
                                    var updateRecord = new StoreRecord <TSUILanguage>
                                    {
                                        Storename = "UILanguages",
                                        Data      = item
                                    };

                                    await LocalData.indexedDbManager.UpdateRecord(updateRecord);

                                    await LocalData.indexedDbManager.ClearStore("UILangDict" + item.Code);
                                }
                            }
                            else
                            {
                                await AddUILanguageAndStore(item);
                            }
                        }
                    }
                }
            }
        }
Exemple #20
0
        private static async Task AddUILanguageAndStore(TSUILanguage item)
        {
            if (LocalData.UsingIndexedDb)
            {
                var newRecord = new StoreRecord <TSUILanguage>
                {
                    Storename = "UILanguages",
                    Data      = item
                };

                await LocalData.indexedDbManager.AddRecord(newRecord);


                if (!item.Code.Equals("en", StringComparison.InvariantCultureIgnoreCase))
                {
                    AddStoreForLang(item.Code);
                }
            }
        }
Exemple #21
0
            private static void Prefix(AdmiraltyManager __instance)
            {
                bool flag = Main._settings.InfRifleStock || Main._settings.InfRifleStockArmory;

                if (flag)
                {
                    EPickerContent contentType = __instance.SelectedItem.ContentType;
                    bool           flag2       = contentType != EPickerContent.Cannon;
                    if (flag2)
                    {
                        bool flag3 = contentType == EPickerContent.Rifle;
                        if (flag3)
                        {
                            StoreRecord storeRecord   = (__instance.SelectedItem.ContentItem as RifleItem).StoreRecord;
                            bool        infRifleStock = Main._settings.InfRifleStock;
                            if (infRifleStock)
                            {
                                storeRecord.Shop = 999999;
                            }
                            bool infRifleStockArmory = Main._settings.InfRifleStockArmory;
                            if (infRifleStockArmory)
                            {
                                storeRecord.Armory = 999999;
                            }
                        }
                    }
                    else
                    {
                        CannonModule cannon         = (__instance.SelectedItem.ContentItem as CannonItem).Cannon;
                        StoreModule  storeCannon    = PlayerController.instance.GetStoreCannon(cannon, true);
                        bool         infRifleStock2 = Main._settings.InfRifleStock;
                        if (infRifleStock2)
                        {
                            storeCannon.Shop = 999999;
                        }
                        bool infRifleStockArmory2 = Main._settings.InfRifleStockArmory;
                        if (infRifleStockArmory2)
                        {
                            storeCannon.Armory = 999999;
                        }
                    }
                }
            }
        // Only required to save to database, resolve will be = to object properties
        // Because -> Obj Person {"FirstName":"A","LastName":"B"} = Dictionary<string, object> {"FirstName":"A","LastName":"B"}
        // Usage dictionary instead of type for the possibility of ignoring properties, eg ForeignKeyAttribute properties
        private StoreRecord <object> ConvertToObjectRecord(string storeName, object data)
        {
            var properties = data.GetType().GetProperties().Where(x => x.CustomAttributes.All(y => y.AttributeType != typeof(ForeignKeyAttribute)));

            var keyValueData = new Dictionary <string, object>();

            foreach (var property in properties)
            {
                var propertyNameInStore = this.FirstToLower(property.Name);

                keyValueData.Add(propertyNameInStore, property.GetValue(data));
            }

            var storeRecord = new StoreRecord <object>()
            {
                Data      = keyValueData,
                Storename = storeName
            };

            return(storeRecord);
        }
Exemple #23
0
        public async Task <StoreRecord> CreateAsync(StoreRecordCreateApiModel created, int userId)
        {
            var goods = await _mediator.GetByIdAsync <GetHospitalGoodsRequest, GetHospitalGoodsResponse>(created.HospitalGoodsId);

            var record = new StoreRecord
            {
                BeforeQty            = created.BeforeQty,
                ChangeTypeId         = created.ChangeTypeId,
                CreateTime           = DateTime.Now,
                CreateUserId         = userId,
                HospitalDepartmentId = created.HospitalDepartmentId,
                HospitalGoodsId      = created.HospitalGoodsId,
                Price     = goods.Price,
                ChangeQty = created.ChangeQty,
                Recrdno   = created.Recrdno,
            };

            _context.StoreRecord.Add(record);
            _context.SaveChanges();

            return(record);
        }
Exemple #24
0
        public async Task SaveCollection(IEnumerable <ContactEntity> contacts)
        {
            int newCount    = 0;
            int updateCount = 0;
            int skipCount   = 0;

            foreach (ContactEntity c in contacts)
            {
                var getContact = await dbManager.GetRecordById <string, ContactEntity>("Contacts", c.Id);

                var writeContact = new StoreRecord <ContactEntity>
                {
                    Storename = "Contacts",
                    Data      = c
                };
                if (getContact == null || string.IsNullOrEmpty(getContact.Id))
                {
                    await dbManager.AddRecord(writeContact);

                    newCount++;
                }
                else
                {
                    if (getContact.ETag != c.ETag)
                    {
                        await dbManager.UpdateRecord <ContactEntity>(writeContact);

                        updateCount++;
                    }
                    else
                    {
                        skipCount++;
                    }
                }
            }
            NotifyPropertyChanged("Contacts");
        }
Exemple #25
0
        public StoreRecord CreateStore(int?teeyootUserId, string title, string description, string url, bool hideStore, bool crossSelling, IList <String> selectedCampaigns)
        {
            try
            {
                var store = new StoreRecord()
                {
                    Title         = title,
                    Description   = description,
                    CrossSelling  = crossSelling,
                    HideStore     = hideStore,
                    TeeyootUserId = teeyootUserId,
                    Url           = url
                };

                _storeRepository.Create(store);
                List <LinkStoreCampaignRecord> campaigns = new List <LinkStoreCampaignRecord>();

                foreach (var campaignId in selectedCampaigns)
                {
                    var campaign      = _campaignService.GetCampaignById(int.Parse(campaignId));
                    var storeCampaign = new LinkStoreCampaignRecord()
                    {
                        CampaignRecord = campaign, StoreRecord = store
                    };
                    _linkStoreCampaignRepository.Create(storeCampaign);
                    campaigns.Add(storeCampaign);
                }

                store.Campaigns = campaigns;
                return(store);
            }
            catch
            {
                throw;
            }
        }
Exemple #26
0
 //重置组内容
 public void SetGroup(StoreRecord oldStore, StoreItem Item)
 {
     mImpl.SetGroup(this, oldStore, Item);
 }
Exemple #27
0
        //https://www.jerriepelser.com/tutorials/airport-explorer/google-places/retrieving/
        public async Task <int> FindStoreAsync(double latitude, double longitude)
        {
            var result = await _storeDAO.FindStoreAsync(latitude, longitude).ConfigureAwait(false);

            if (result == Constants.NoStoreFoundCode)
            {
                var searchResponse = await GooglePlaces.NearBySearch.QueryAsync(new PlacesNearBySearchRequest
                {
                    Key      = Constants.GoogleApiKey,
                    Location = new Location(latitude, longitude),
                    Radius   = 60
                }).ConfigureAwait(false);

                // If we did not get a good response, or the list of results are empty, store not found
                if (!searchResponse.Status.HasValue || searchResponse.Status.Value != Status.Ok || !searchResponse.Results.Any())
                {
                    return(result);
                }

                // Get the first result
                var resultsEnumerator = searchResponse.Results.GetEnumerator();
                resultsEnumerator.Reset();
                resultsEnumerator.MoveNext();
                resultsEnumerator.MoveNext();

                var nearbyResult = resultsEnumerator.Current;

                var placeId = nearbyResult.PlaceId;

                // Execute the details request
                var detailsResonse = await GooglePlaces.Details.QueryAsync(new PlacesDetailsRequest
                {
                    Key     = Constants.GoogleApiKey,
                    PlaceId = placeId
                });

                // If we did not get a good response then get out of here
                if (!detailsResonse.Status.HasValue || detailsResonse.Status.Value != Status.Ok)
                {
                    throw new Exception(Constants.GooglePlacesApiFailureMessage);
                }

                // Retrieve the details
                var detailsResult = detailsResonse.Result;

                var formattedAddress = detailsResult.FormattedAddress;
                var storeName        = detailsResult.Name;

                // Closest address is a city, not a store
                if (!formattedAddress.Any(char.IsDigit))
                {
                    return(result);
                }

                var geometry  = detailsResult.Geometry;
                var storeLat  = geometry.Location.Latitude;
                var storeLong = geometry.Location.Longitude;

                var record = new StoreRecord(storeName, storeLat, storeLong, placeId, Constants.NoValueString);

                result = await _storeDAO.CreateAsync(record).ConfigureAwait(false);

                return(result);
            }
            else
            {
                return(result);
            }
        }
        //Method to get all store records, along with country from address
        public List<StoreRecord> getAllStores()
        {
            List<StoreRecord> storeRecordList = new List<StoreRecord>();

            try
            {
                connection.Open();
                MySqlCommand command;
                MySqlDataReader data;
                string query = "BEGIN; CREATE OR REPLACE VIEW t AS SELECT * FROM store; SELECT * FROM t;";

                //Get all stores and the relative address's country (in the database as Country)

                //string query = "SELECT * FROM store INNER_JOIN Address On store.addressID=Address.addressID";
                List<StoreRecord> listOfStores = new List<StoreRecord>();

                command = new MySqlCommand(query, connection);
                data = command.ExecuteReader();

                while (data.Read())
                {
                    int id = data.GetInt32("idStore");
                    String name = data.GetString("Name");
                    String contactnumber = data.GetString("ContactNumber");

                    StoreRecord store = new StoreRecord(id, name);
                    store.setContactNumber(contactnumber);

                    listOfStores.Add(store);

                }
                connection.Close();

                return listOfStores;
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                return null;
            }
        }
        public JsonResult MultiLabelPrinting(string ShopUrl, string Instruction, float Weight, string Labels, string Reference, string FullDetails)
        {
            //DB connection to query store details
            DbEngine newDB = new DbEngine();
            //get store details with provided url
            StoreRecord storeDetails = newDB.GetShopRecord(ShopUrl);
            //Labeldetails entity to query
            Labeldetails label = new Labeldetails();

            ///populate store details for query
            label.apiKey      = storeDetails.FastwayApiKey;
            label.fromCompany = storeDetails.StoreName;

            if (storeDetails.Phone != "" && storeDetails.Phone != null && storeDetails.Phone != "null")
            {
                label.fromPhone = storeDetails.Phone;
            }
            label.fromAddress1        = storeDetails.StoreAddress1;
            label.fromCity            = storeDetails.Suburb;
            label.fromPostcode        = storeDetails.Postcode;
            label.weight              = Math.Ceiling(Weight * 100) / 100;
            label.specialInstruction1 = Instruction;
            label.countryCode         = storeDetails.CountryCode;

            //parsing the labels addresses details
            JArray ls  = JArray.Parse(Labels);
            JArray fds = JArray.Parse(FullDetails);

            List <string> references = Reference.Split(',').ToList();

            List <Labeldetails> labelDetails = new List <Labeldetails>();

            for (var i = 0; i < ls.Count; i++)
            {
                if (ls[i]["BaseLabel"].ToString() != "")
                {
                    Labeldetails l = label;
                    if (ls[i]["Company"].ToString() != "" && ls[i]["Company"].ToString() != null && ls[i]["Company"].ToString() != "null")
                    {
                        l.toCompany     = ls[i]["Company"].ToString();
                        l.toContactName = ls[i]["Name"].ToString();
                    }
                    else
                    {
                        l.toCompany = ls[i]["Name"].ToString();
                    }

                    if (references.Count > 0)
                    {
                        l.reference = references[i];
                    }

                    l.toAddress1 = ls[i]["Address1"].ToString();
                    l.toAddress2 = ls[i]["Address2"].ToString();
                    l.toPostcode = ls[i]["Postcode"].ToString();
                    l.toCity     = ls[i]["Suburb"].ToString();

                    l.labelColour = ls[i]["Service"].ToString();
                    l.labelNumber = ls[i]["BaseLabel"].ToString();
                    l.ruralNumber = ls[i]["RuralLabel"].ToString();

                    l.toRfName = ls[i]["Destination"].ToString();

                    labelDetails.Add(l);
                }
            }

            try
            {
                PdfDocument doc = new PdfDocument();
                if (labelDetails.Count > 0)
                {
                    FastwayAPI getBase = new FastwayAPI();
                    doc = getBase.PrintMultipleLabels(labelDetails, doc);
                }

                MemoryStream pdfStream = new MemoryStream();
                doc.Save(pdfStream, false);
                byte[] pdfBytes = pdfStream.ToArray();

                var pdfString = Convert.ToBase64String(pdfBytes);


                return(Json(new
                {//return status success
                    PdfBase64Stream = pdfString
                }));
            }
            catch (Exception e)
            {     //error
                return(Json(new
                { //return status success
                    Error = e.Message
                }));
            }
        }
        public JsonResult MultiLabelQuery(string ShopUrl, string Address1, string Address2, string Suburb, string Postcode, float Weight, string Instruction, string Type)
        {
            //DB connection to query store details
            DbEngine newDB = new DbEngine();
            //get store details with provided url
            StoreRecord storeDetails = newDB.GetShopRecord(ShopUrl);
            //Labeldetails entity to query
            Labeldetails label = new Labeldetails();

            //populate store details for query
            label.apiKey       = storeDetails.FastwayApiKey;
            label.fromAddress1 = storeDetails.StoreAddress1;
            label.fromCity     = storeDetails.Suburb;
            label.fromPostcode = storeDetails.Postcode;
            //populate delivery details for query
            label.toAddress1 = Address1;
            label.toAddress2 = Address2;
            label.toCity     = Suburb;
            label.toPostcode = Postcode;
            //populate parcel details for query
            label.weight      = (double)Weight;
            label.countryCode = storeDetails.CountryCode;

            List <string> labelNumbers = new List <string>();
            string        destRF       = "";

            try
            {
                if (Type != "Parcel")
                {
                    if (Weight > 5)
                    {
                        labelNumbers.Add("No Service Found");
                    }
                    else
                    {
                        label.specialInstruction1 = Instruction;

                        //new fastwayAPI object to query
                        FastwayAPI getLabel = new FastwayAPI();
                        //get label with V2 method
                        Labeldetails l = new Labeldetails();

                        if (Type == "SAT-NAT-A3")
                        {
                            List <UsableLabel> services = getLabel.ServiceQuery(label);
                            if (services.First().BaseLabelColour == "BROWN")
                            {
                                label.labelColour = services[services.FindIndex(a => a.BaseLabelColour == "SAT-LOC-A3")].BaseLabelColour;
                            }
                            else
                            {
                                label.labelColour = Type;
                            }
                        }
                        else
                        {
                            label.labelColour = Type;
                        }
                        l = getLabel.LabelQueryV2(label);
                        labelNumbers.Add(l.labelNumber);
                        labelNumbers.Add(l.ruralNumber);
                        destRF = l.toRfName;
                    }
                }
                else
                {
                    //new fastwayAPI object to query
                    FastwayAPI getLabel = new FastwayAPI();
                    //get label with V2 method
                    Labeldetails       l        = new Labeldetails();
                    List <UsableLabel> services = getLabel.ServiceQuery(label);
                    label.labelColour = services.First().BaseLabelColour;
                    l = getLabel.LabelQueryV2(label);
                    labelNumbers.Add(l.labelNumber);
                    labelNumbers.Add(l.ruralNumber);
                    destRF = l.toRfName;
                }
            }
            catch (Exception)
            {
                labelNumbers.Add("No Service Found");
            }
            return(Json(new
            {//return details about availabel service
                BaseLabel = labelNumbers[0],
                RuralLabel = labelNumbers[1],
                Service = label.labelColour,
                DestRF = destRF
            }));
        }
        public JsonResult LabelQuery(string ShopUrl, string Address1, string Address2, string Suburb, string Postcode, string Region, float Weight, string Type)
        {
            //DB connection to query store details
            DbEngine newDB = new DbEngine();
            //get store details with provided url
            StoreRecord storeDetails = newDB.GetShopRecord(ShopUrl);
            //Labeldetails entity to query
            Labeldetails label = new Labeldetails();

            //populate store details for query
            label.apiKey       = storeDetails.FastwayApiKey;
            label.fromAddress1 = storeDetails.StoreAddress1;
            label.fromCity     = storeDetails.Suburb;
            label.fromPostcode = storeDetails.Postcode;
            //populate delivery details for query
            label.toAddress1 = Address1;
            label.toAddress2 = Address2;
            label.toCity     = Suburb;
            label.toPostcode = Postcode;
            //populate parcel details for query
            label.weight      = (double)Weight;
            label.countryCode = storeDetails.CountryCode;
            //FastwayAPI object for service query
            FastwayAPI newApiCall = new FastwayAPI();
            //Call fastway API and receive back a list of available service
            List <UsableLabel> services = newApiCall.ServiceQuery(label);
            //UsableLabel entity to respond
            UsableLabel service = new UsableLabel();

            try
            {
                if (services.First().CostexgstTotalChargeToEndUser != 0)
                {         //if no service found
                    if (services.Count == 1 && Type != "Parcel")
                    {     //no service and type was "Parcel"
                        return(Json(new
                        { //return an Error code
                            Error = "No Service Available"
                        }));
                    }
                    else//service(s) available
                    {
                        if (Type == "Parcel")
                        {//type was "Parcel", assign parcel option to response json
                            service = services.First();
                        }
                        else
                        {//type was NOT "Parcel", get service based on value of Type
                            if (Type == "SAT-NAT-A3")
                            {
                                if (services.First().BaseLabelColour == "BROWN")
                                {
                                    service = services[services.FindIndex(a => a.BaseLabelColour == "SAT-LOC-A3")];
                                }
                                else
                                {
                                    service = services[services.FindIndex(a => a.BaseLabelColour == Type)];
                                }
                            }
                            else
                            {
                                service = services[services.FindIndex(a => a.BaseLabelColour == Type)];
                            }
                        }
                        return(Json(new
                        {//return details about availabel service
                            BaseLabelColour = service.BaseLabelColour,
                            TotalCost = service.CostexgstTotalChargeToEndUser,
                            Rural = service.RuralLabelCostExgst > 0 ? true : false,
                            Excess = service.ExcessLabelCount,
                            Saturday = services.First().Saturday
                        }));
                    }
                }
                else
                {
                    return(Json(new
                    {//Error code from Fastway NOTE: will need to handle different type of error HERE
                        Error = "No Service Available"
                    }));
                }
            }
            catch (Exception e)
            {
                //general error code Note: will need to handle these
                throw e;
            }
        }
        //Method to return every sale from every store
        public List<StoreRecord> chartStoresRecords(int choice)
        {
            try
            {
                connection.Open();
                MySqlCommand command;
                MySqlDataReader data;
                string query = "SELECT * FROM store";
                List<StoreRecord> listOfStores = new List<StoreRecord>();

                command = new MySqlCommand(query, connection);
                data = command.ExecuteReader();

                while (data.Read())
                {
                    int id = data.GetInt32("idStore");
                    String name = data.GetString("Name");

                    //decimal value = getProductPrice(data.GetInt32("Product_idProduct"));
                    StoreRecord store = new StoreRecord(id, name);
                    //store.setStoreSales(chartStoresSales(id));
                    //store.setCountry(getStoreCountry(id));

                    listOfStores.Add(store);

                }
                connection.Close();

                if (choice == 0)
                {
                    foreach (StoreRecord singStore in listOfStores)
                    {
                        singStore.setStoreSales(chartStoresSales(singStore.getStoreID()));
                    }
                    foreach (StoreRecord singStore in listOfStores)
                    {
                        singStore.setCountry(getStoreCountry(singStore.getStoreID()));
                    }
                }

                else if (choice == 1)
                {
                    foreach (StoreRecord singStore in listOfStores)
                    {
                        singStore.setStoreSales(getWaterPData(singStore.getStoreID()));
                    }
                    foreach (StoreRecord singStore in listOfStores)
                    {
                        singStore.setCountry(getStoreCountry(singStore.getStoreID()));
                    }
                }
                else
                {

                    foreach (StoreRecord singStore in listOfStores)
                    {
                        singStore.setStoreSales(chartMonthGross(singStore.getStoreID()));
                    }

                }

                return listOfStores;

            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                return null;
            }
        }