Ejemplo n.º 1
0
        private void cmdCommodity_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                m_NoRefresh = true;

                EDCommoditiesExt currentCommodity = CurrentCommodity;
                if (currentCommodity == null)
                {
                    return;
                }

                txtId.Text             = currentCommodity.Id.ToString();
                txtCategory.Text       = currentCommodity.Category.NToString();
                txtAveragePrice.Text   = currentCommodity.AveragePrice.ToString();
                txtDemandSellLow.Text  = currentCommodity.PriceWarningLevel_Demand_Sell_Low.ToString();
                txtDemandSellHigh.Text = currentCommodity.PriceWarningLevel_Demand_Sell_High.ToString();
                txtDemandBuyLow.Text   = currentCommodity.PriceWarningLevel_Demand_Buy_Low.ToString();
                txtDemandBuyHigh.Text  = currentCommodity.PriceWarningLevel_Demand_Buy_High.ToString();

                txtSupplySellLow.Text  = currentCommodity.PriceWarningLevel_Supply_Sell_Low.ToString();
                txtSupplySellHigh.Text = currentCommodity.PriceWarningLevel_Supply_Sell_High.ToString();
                txtSupplyBuyLow.Text   = currentCommodity.PriceWarningLevel_Supply_Buy_Low.ToString();
                txtSupplyBuyHigh.Text  = currentCommodity.PriceWarningLevel_Supply_Buy_High.ToString();

                m_NoRefresh = false;
            }
            catch (Exception ex)
            {
                throw new Exception("error in cmdCommodity_SelectedIndexChanged method", ex);
            }
        }
Ejemplo n.º 2
0
        private void txtField_TextChanged(object sender, EventArgs e)
        {
            if (!m_NoRefresh)
            {
                int     IntValue;
                TextBox currentTextBox = ((TextBox)sender);

                if (int.TryParse(currentTextBox.Text, out IntValue))
                {
                    m_DataChanged = true;

                    EDCommoditiesExt currentCommodity = CurrentCommodity;
                    if (currentCommodity == null)
                    {
                        return;
                    }

                    currentCommodity.PriceWarningLevel_Demand_Sell_Low  = int.Parse(txtDemandSellLow.Text);
                    currentCommodity.PriceWarningLevel_Demand_Sell_High = int.Parse(txtDemandSellHigh.Text);
                    currentCommodity.PriceWarningLevel_Demand_Buy_Low   = int.Parse(txtDemandBuyLow.Text);
                    currentCommodity.PriceWarningLevel_Demand_Buy_High  = int.Parse(txtDemandBuyHigh.Text);

                    currentCommodity.PriceWarningLevel_Supply_Sell_Low  = int.Parse(txtSupplySellLow.Text);
                    currentCommodity.PriceWarningLevel_Supply_Sell_High = int.Parse(txtSupplySellHigh.Text);
                    currentCommodity.PriceWarningLevel_Supply_Buy_Low   = int.Parse(txtSupplyBuyLow.Text);
                    currentCommodity.PriceWarningLevel_Supply_Buy_High  = int.Parse(txtSupplyBuyHigh.Text);
                }
                else
                {
                    currentTextBox.Text = m_OldValue;
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// saves the RN-specific commodity data to a file
        /// </summary>
        /// <param name="File">json-file to save</param>
        /// <param name="Stationtype"></param>
        public void saveRNCommodityData(string Filename, bool BackupOldFile)
        {
            List <EDCommoditiesWarningLevels> WarningLevels = EDCommoditiesExt.extractWarningLevels(m_Commodities);

            string newFile, backupFile;


            newFile    = String.Format("{0}_new{1}", Path.Combine(Path.GetDirectoryName(Filename), Path.GetFileNameWithoutExtension(Filename)), Path.GetExtension(Filename));
            backupFile = String.Format("{0}_bak{1}", Path.Combine(Path.GetDirectoryName(Filename), Path.GetFileNameWithoutExtension(Filename)), Path.GetExtension(Filename));

            File.WriteAllText(newFile, JsonConvert.SerializeObject(WarningLevels));

            // we delete the current file not until the new file is written without errors

            rotateSaveFiles(Filename, newFile, backupFile, BackupOldFile);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// loads the commodity data from the files
        /// </summary>
        /// <param name="EDDBCommodityDatafile"></param>
        /// <param name="RNCommodityDatafile"></param>
        /// <param name="createNonExistingFile"></param>
        internal bool loadCommodityData(string EDDBCommodityDatafile, string RNCommodityDatafile, bool createNonExistingFile, bool CheckOnly = false)
        {
            bool notExisting = false;
            List <EDCommoditiesWarningLevels> RNCommodities;
            List <EDCommodities> EDDBCommodities = JsonConvert.DeserializeObject <List <EDCommodities> >(File.ReadAllText(EDDBCommodityDatafile));

            if (CheckOnly)
            {
                if (File.Exists(RNCommodityDatafile))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }

            if (File.Exists(RNCommodityDatafile))
            {
                RNCommodities = JsonConvert.DeserializeObject <List <EDCommoditiesWarningLevels> >(File.ReadAllText(RNCommodityDatafile));
            }
            else
            {
                notExisting   = true;
                RNCommodities = new List <EDCommoditiesWarningLevels>();
            }

            m_Commodities = EDCommoditiesExt.mergeCommodityData(EDDBCommodities, RNCommodities);

            if (notExisting)
            {
                calculateNewPriceLimits();
            }

            saveRNCommodityData(RNCommodityDatafile, true);

            return(true);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// adds objects for not yet existing localized commodities
        /// </summary>
        internal void addLocalized2RN(dsCommodities.NamesDataTable localizedCommodities)
        {
            EDCommoditiesExt EDCommodity    = null;
            enLanguage foundLanguage        = enLanguage.eng;
            bool changed                    = false;

            foreach (dsCommodities.NamesRow localizedItem in localizedCommodities)
            {

                // look if the name is available at least in one language
                foreach (enLanguage availableLanguage in Enum.GetValues(typeof(enLanguage)))
                { 
                    foundLanguage = availableLanguage;
                    EDCommodity =  m_Commodities.Find(x => x.Name.Equals(localizedItem[availableLanguage.ToString()].ToString(), StringComparison.InvariantCultureIgnoreCase));
                    if(EDCommodity != null)
                        break;
                }

                if(EDCommodity != null)
                { 
                    // found
                    if((foundLanguage != enLanguage.eng) && (localizedItem.eng != Program.COMMODITY_NOT_SET))
                    { 
                        // it's not the base(=english) name, but the base(=english) name is available -> change this
                        EDCommodity.Name = localizedItem.eng;
                        changed = true;
                    }
                }
                else
                {
                    // not found, add it with the available 
                    EDCommodity = new EDCommoditiesExt();
                    EDCommodity.Name = localizedItem.eng;

                    if(EDCommodity.Name == Program.COMMODITY_NOT_SET)
                    {
                        // base(=english) name not available, get the next existing name
                        foreach (enLanguage availableLanguage in Enum.GetValues(typeof(enLanguage)))
                        {
                            if(localizedItem[availableLanguage.ToString()].ToString() != Program.COMMODITY_NOT_SET)
                            {
                                // got it -> break
                                EDCommodity.Name = localizedItem[availableLanguage.ToString()].ToString();
                                break;
                            }
                        }                  
                    }
                    EDCommodity.Id = m_Commodities.Max(x => x.Id) + 1;
                    EDCommodity.AveragePrice = -1;

                    m_Commodities.Add(EDCommodity);

                    changed = true;
                }

                if(changed)
                    saveRNCommodityData(@"./Data/commodities_RN.json", true);
            }

        }
Ejemplo n.º 6
0
        /// <summary>
        /// adds objects for not yet existing localized commodities
        /// </summary>
        internal void addLocalized2RN(dsCommodities.NamesDataTable localizedCommodities)
        {
            EDCommoditiesExt EDCommodity   = null;
            enLanguage       foundLanguage = enLanguage.eng;
            bool             changed       = false;

            foreach (dsCommodities.NamesRow localizedItem in localizedCommodities)
            {
                // look if the name is available at least in one language
                foreach (enLanguage availableLanguage in Enum.GetValues(typeof(enLanguage)))
                {
                    foundLanguage = availableLanguage;
                    EDCommodity   = m_Commodities.Find(x => x.Name.Equals(localizedItem[availableLanguage.ToString()].ToString(), StringComparison.InvariantCultureIgnoreCase));
                    if (EDCommodity != null)
                    {
                        break;
                    }
                }

                if (EDCommodity != null)
                {
                    // found
                    if ((foundLanguage != enLanguage.eng) && (localizedItem.eng != Program.COMMODITY_NOT_SET))
                    {
                        // it's not the base(=english) name, but the base(=english) name is available -> change this
                        EDCommodity.Name = localizedItem.eng;
                        changed          = true;
                    }
                }
                else
                {
                    // not found, add it with the available
                    EDCommodity      = new EDCommoditiesExt();
                    EDCommodity.Name = localizedItem.eng;

                    if (EDCommodity.Name == Program.COMMODITY_NOT_SET)
                    {
                        // base(=english) name not available, get the next existing name
                        foreach (enLanguage availableLanguage in Enum.GetValues(typeof(enLanguage)))
                        {
                            if (localizedItem[availableLanguage.ToString()].ToString() != Program.COMMODITY_NOT_SET)
                            {
                                // got it -> break
                                EDCommodity.Name = localizedItem[availableLanguage.ToString()].ToString();
                                break;
                            }
                        }
                    }
                    EDCommodity.Id           = m_Commodities.Max(x => x.Id) + 1;
                    EDCommodity.AveragePrice = -1;

                    m_Commodities.Add(EDCommodity);

                    changed = true;
                }

                if (changed)
                {
                    saveRNCommodityData(@"./Data/commodities_RN.json", true);
                }
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// calculating the market prices and save them as min and max values for new OCR_ed data,
        /// if "FileName" is not nothing the new data will is saves in this file
        ///
        /// </summary>
        /// <param name="FileName">name of the file to save to</param>
        public void calculateNewPriceLimits(string FileName = "")
        {
            Dictionary <int, MarketData> collectedData = calculateAveragePrices();

            foreach (MarketData Commodity in collectedData.Values)
            {
                EDCommoditiesExt CommodityBasedata = m_Commodities.Find(x => x.Id == Commodity.Id);

                if (CommodityBasedata != null)
                {
                    if (Commodity.BuyPrices_Demand.Count() > 0)
                    {
                        CommodityBasedata.PriceWarningLevel_Demand_Buy_Low = Commodity.BuyPrices_Demand.Min();
                    }
                    else
                    {
                        CommodityBasedata.PriceWarningLevel_Demand_Buy_Low = -1;
                    }

                    if (Commodity.BuyPrices_Demand.Count() > 0)
                    {
                        CommodityBasedata.PriceWarningLevel_Demand_Buy_High = Commodity.BuyPrices_Demand.Max();
                    }
                    else
                    {
                        CommodityBasedata.PriceWarningLevel_Demand_Buy_High = -1;
                    }

                    if (Commodity.BuyPrices_Supply.Count() > 0)
                    {
                        CommodityBasedata.PriceWarningLevel_Supply_Buy_Low = Commodity.BuyPrices_Supply.Min();
                    }
                    else
                    {
                        CommodityBasedata.PriceWarningLevel_Supply_Buy_Low = -1;
                    }

                    if (Commodity.BuyPrices_Supply.Count() > 0)
                    {
                        CommodityBasedata.PriceWarningLevel_Supply_Buy_High = Commodity.BuyPrices_Supply.Max();
                    }
                    else
                    {
                        CommodityBasedata.PriceWarningLevel_Supply_Buy_High = -1;
                    }

                    if (Commodity.BuyPrices_Demand.Count() > 0)
                    {
                        CommodityBasedata.PriceWarningLevel_Demand_Sell_Low = Commodity.SellPrices_Demand.Min();
                    }
                    else
                    {
                        CommodityBasedata.PriceWarningLevel_Demand_Sell_Low = -1;
                    }

                    if (Commodity.SellPrices_Demand.Count() > 0)
                    {
                        CommodityBasedata.PriceWarningLevel_Demand_Sell_High = Commodity.SellPrices_Demand.Max();
                    }
                    else
                    {
                        CommodityBasedata.PriceWarningLevel_Demand_Sell_High = -1;
                    }

                    if (Commodity.SellPrices_Supply.Count() > 0)
                    {
                        CommodityBasedata.PriceWarningLevel_Supply_Sell_Low = Commodity.SellPrices_Supply.Min();
                    }
                    else
                    {
                        CommodityBasedata.PriceWarningLevel_Supply_Sell_Low = -1;
                    }

                    if (Commodity.SellPrices_Supply.Count() > 0)
                    {
                        CommodityBasedata.PriceWarningLevel_Supply_Sell_High = Commodity.SellPrices_Supply.Max();
                    }
                    else
                    {
                        CommodityBasedata.PriceWarningLevel_Supply_Sell_High = -1;
                    }
                }
                else
                {
                    Debug.Print("STOP");
                }

                //if (CommodityBasedata.Name == "Palladium")
                //    Debug.Print("STOP, doppelt belegt  " + CommodityBasedata.Name);
                //    Debug.Print("STOP");

                //Debug.Print("");
                //Debug.Print("");
                //Debug.Print(CommodityBasedata.Name + " :");
                //Debug.Print("Demand Buy Min \t\t" + Commodity_Class.BuyPrices_Demand.Min().ToString("F0"));
                //Debug.Print("Demand Buy Average\t" + Commodity_Class.BuyPrices_Demand.Average().ToString("F0") + " (" + Commodity_Class.BuyPrices_Demand.Count() + " values)");
                //Debug.Print("Demand Buy Max\t\t" + Commodity_Class.BuyPrices_Demand.Max().ToString("F0"));
                //Debug.Print("");
                //Debug.Print("Demand Sell Min\t\t" + Commodity_Class.SellPrices_Demand.Min().ToString("F0"));
                //Debug.Print("Demand Sell Average\t" + Commodity_Class.SellPrices_Demand.Average().ToString("F0") + " (" + Commodity_Class.SellPrices_Demand.Count() + " values)");
                //Debug.Print("Demand Sell Max\t\t" + Commodity_Class.SellPrices_Demand.Max().ToString("F0"));
                //Debug.Print("");
                //Debug.Print("Supply Buy Min\t\t" + Commodity_Class.BuyPrices_Supply.Min().ToString("F0"));
                //Debug.Print("Supply Buy Average\t" + Commodity_Class.BuyPrices_Supply.Average().ToString("F0") + " (" + Commodity_Class.BuyPrices_Supply.Count() + " values)");
                //Debug.Print("Supply Buy Max\t\t" + Commodity_Class.BuyPrices_Supply.Max().ToString("F0"));
                //Debug.Print("");
                //Debug.Print("Supply Sell Min\t\t" + Commodity_Class.SellPrices_Supply.Min().ToString("F0"));
                //Debug.Print("Supply Sell Average\t" + Commodity_Class.SellPrices_Supply.Average().ToString("F0") + " (" + Commodity_Class.SellPrices_Supply.Count() + " values)");
                //Debug.Print("Supply Sell Max\t\t" + Commodity_Class.SellPrices_Supply.Max().ToString("F0"));
            }

            if (!String.IsNullOrEmpty(FileName))
            {
                saveRNCommodityData(FileName, true);
            }
        }