Exemplo n.º 1
0
        public EditPriceData(CsvRow csvRow, List<string> commodities)
        {
            InitializeComponent();

            RowToEdit = csvRow;

            tbEditSystem.Text        = RowToEdit.SystemName;
            tbEditStation.Text       = RowToEdit.StationID;
            cbEditCommodityName.Text = RowToEdit.CommodityName;
            nEditSell.Value          = RowToEdit.SellPrice;
            nEditBuy.Value           = RowToEdit.BuyPrice;
            nEditDemand.Value        = RowToEdit.Demand;
            nEditSupply.Value        = RowToEdit.Supply;
            tbEditDemandLevel.Text   = RowToEdit.DemandLevel;
            tbEditSupplyLevel.Text   = RowToEdit.SupplyLevel;
            dtpEditSampleDate.Value  = RowToEdit.SampleDate;
            tbEditFilename.Text      = RowToEdit.SourceFileName;

            foreach (var x in commodities.OrderBy(y => y))
                cbEditCommodityName.Items.Add(x);
        }
Exemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.OK;

            var returnValue = new CsvRow
            {
                SystemName = tbEditSystem.Text,
                StationID = tbEditStation.Text + " ["+tbEditSystem.Text+"]",
                CommodityName = cbEditCommodityName.Text,
                SellPrice = nEditSell.Value,
                BuyPrice = nEditBuy.Value,
                Demand = nEditDemand.Value,
                Supply = nEditSupply.Value,
                DemandLevel = tbEditDemandLevel.Text,
                SupplyLevel = tbEditSupplyLevel.Text,
                SampleDate = dtpEditSampleDate.Value,
                SourceFileName = tbEditFilename.Text
            };

            RowToEdit = returnValue;

            Close();
        }
Exemplo n.º 3
0
 private bool getStationSelection(CsvRow x, bool noRestriction=false)
 {
     if(noRestriction)
         return true;
     else
         return (!cbLimitLightYears.Checked || Distance(x.SystemName)) &&
                (!cbStationToStar.Checked   || StationDistance(x.SystemName, x.StationName));
 }
Exemplo n.º 4
0
        public bool checkPricePlausibility(string[] DataRows, bool simpleEDDNCheck = false)
        {
            bool implausible = false;

            foreach (string s in DataRows)
            {
                if (s.Contains(";"))
                {
                    string[] values = s.Split(';');
                    CsvRow currentRow = new CsvRow();

                    currentRow.SellPrice    = -1;
                    currentRow.BuyPrice     = -1;
                    currentRow.Demand       = -1;
                    currentRow.Supply       = -1;

                    currentRow.SystemName       = values[0];
                    currentRow.StationName      = _textInfo.ToTitleCase(values[1].ToLower());
                    currentRow.StationID        = _textInfo.ToTitleCase(values[1].ToLower()) + " [" + currentRow.SystemName + "]";
                    currentRow.CommodityName    = _textInfo.ToTitleCase(values[2].ToLower());

                    if (!String.IsNullOrEmpty(values[3]))
                        Decimal.TryParse(values[3], out currentRow.SellPrice);
                    if (!String.IsNullOrEmpty(values[4]))
                        Decimal.TryParse(values[4], out currentRow.BuyPrice);
                    if (!String.IsNullOrEmpty(values[5]))
                        Decimal.TryParse(values[5], out currentRow.Demand);
                    if (!String.IsNullOrEmpty(values[7]))
                        Decimal.TryParse(values[7], out currentRow.Supply);

                    currentRow.DemandLevel      = _textInfo.ToTitleCase(values[6].ToLower());
                    currentRow.SupplyLevel      = _textInfo.ToTitleCase(values[8].ToLower());

                    DateTime.TryParse(values[9], out currentRow.SampleDate);

                    EDCommoditiesExt CommodityData = myMilkyway.getCommodity(getLocalizedCommodity(enLanguage.eng, currentRow.CommodityName));
    
                    if (currentRow.CommodityName == "Panik")
                        Debug.Print("STOP");
                    
                    if(currentRow.Demand > 0)
                        currentRow.DemandLevel = "MED";

                    if(currentRow.DemandLevel ==  "")
                        currentRow.SupplyLevel = "MED";

                    if (CommodityData != null)
                    { 
                        if ((!String.IsNullOrEmpty(currentRow.SupplyLevel)) && (!String.IsNullOrEmpty(currentRow.DemandLevel)))
                        {
                            // demand AND supply !?
                            implausible = true;
                        }
                        else if ((!String.IsNullOrEmpty(currentRow.SupplyLevel)) || (simpleEDDNCheck && (currentRow.Supply > 0)))
                        { 
                            // check supply data             

                            if ((currentRow.SellPrice <= 0) || (currentRow.BuyPrice <= 0))
                            { 
                                // both on 0 is not plausible
                                implausible = true;
                            }

                            if (((CommodityData.PriceWarningLevel_Supply_Sell_Low  >= 0) && (currentRow.SellPrice < CommodityData.PriceWarningLevel_Supply_Sell_Low)) ||
                                ((CommodityData.PriceWarningLevel_Supply_Sell_High >= 0) && (currentRow.SellPrice > CommodityData.PriceWarningLevel_Supply_Sell_High)))
                            {
                                // sell price is out of range
                                implausible = true;
                            }

                            if (((CommodityData.PriceWarningLevel_Supply_Buy_Low  >= 0) && (currentRow.BuyPrice  < CommodityData.PriceWarningLevel_Supply_Buy_Low)) ||
                                ((CommodityData.PriceWarningLevel_Supply_Buy_High >= 0) && (currentRow.SellPrice > CommodityData.PriceWarningLevel_Supply_Buy_High)))
                            {
                                // buy price is out of range
                                implausible = true;
                            }

                            if (currentRow.Supply.Equals(-1))
                            {   
                                // no supply quantity
                                implausible = true;
                            }

                        }
                        else if ((!String.IsNullOrEmpty(currentRow.DemandLevel)) || (simpleEDDNCheck && (currentRow.Demand > 0)))
                        { 
                            // check demand data

                            if (currentRow.SellPrice <= 0)
                            {
                                // at least the sell price must be present
                                implausible = true;
                            }

                            if (((CommodityData.PriceWarningLevel_Demand_Sell_Low  >= 0) && (currentRow.SellPrice < CommodityData.PriceWarningLevel_Demand_Sell_Low)) ||
                                ((CommodityData.PriceWarningLevel_Demand_Sell_High >= 0) && (currentRow.SellPrice > CommodityData.PriceWarningLevel_Demand_Sell_High)))
                            {
                                // buy price is out of range
                                implausible = true;
                            }

                            if (currentRow.BuyPrice >= 0) 
                                if (((CommodityData.PriceWarningLevel_Demand_Buy_Low  >= 0) && (currentRow.BuyPrice < CommodityData.PriceWarningLevel_Demand_Buy_Low)) ||
                                    ((CommodityData.PriceWarningLevel_Demand_Buy_High >= 0) && (currentRow.BuyPrice > CommodityData.PriceWarningLevel_Demand_Buy_High)))
                                {
                                    // buy price is out of range
                                    implausible = true;
                                }

                            if (currentRow.Demand.Equals(-1))
                            {
                                // no supply quantity
                                implausible = true;
                            }
                        }
                        else
                        { 
                            // nothing ?!
                            implausible = true;
                        }
                    }
                }

                if (implausible)
                    break;
            }

            return implausible;
        }
Exemplo n.º 5
0
        private void RenameStation(object sender, EventArgs e)
        {
            var existingStationName = getCmbItemKey(cmbStation.SelectedItem);

            tbStationRename.Text    = _textInfo.ToTitleCase(tbStationRename.Text.ToLower());

            var newStationName = tbStationRename.Text + " [" + tbSystemRename.Text + "]";

            List<CsvRow> newRows = new List<CsvRow>();

            foreach (var row in StationDirectory[existingStationName])
            {
                CsvRow newRow = new CsvRow
                {
                    BuyPrice = row.BuyPrice,
                    Cargo = row.Cargo,
                    CommodityName = row.CommodityName,
                    Demand = row.Demand,
                    DemandLevel = row.DemandLevel,
                    SampleDate = row.SampleDate,
                    SellPrice = row.SellPrice,
                    StationName = tbStationRename.Text,
                    StationID = newStationName,
                    Supply = row.Supply,
                    SupplyLevel = row.SupplyLevel,
                    SystemName = tbSystemRename.Text,
                    SourceFileName = row.SourceFileName
                };

                newRows.Add(newRow);
            }


            StationDirectory.Remove(existingStationName);

            if (!StationDirectory.ContainsKey(newStationName))
                StationDirectory.Add(newStationName, newRows);
            else StationDirectory[newStationName].AddRange(newRows);

            var newCommodityDirectory = new CommodityDirectory();

            foreach (var collectionOfRows in CommodityDirectory)
            {
                newRows = new List<CsvRow>();

                foreach (var row in collectionOfRows.Value)
                {

                    CsvRow newRow = new CsvRow
                    {
                        BuyPrice = row.BuyPrice,
                        Cargo = row.Cargo,
                        CommodityName = row.CommodityName,
                        Demand = row.Demand,
                        DemandLevel = row.DemandLevel,
                        SampleDate = row.SampleDate,
                        SellPrice = row.SellPrice,
                        StationID = row.StationID == existingStationName ? newStationName : row.StationID,
                        Supply = row.Supply,
                        SupplyLevel = row.SupplyLevel,
                        SystemName = row.StationID == existingStationName ? tbSystemRename.Text : row.SystemName
                    };

                    newRows.Add(newRow);
                }

                newCommodityDirectory.Add(collectionOfRows.Key, newRows);
            }

            CommodityDirectory = newCommodityDirectory;

            //Remove duplicates (incl. historical)
            var newStationDirectory = new List<CsvRow>();

            var distinctCommodityNames = StationDirectory[newStationName].ToList().Select(x => x.CommodityName).Distinct();

            foreach (var c in distinctCommodityNames)
            {
                newStationDirectory.Add(StationDirectory[newStationName].ToList().Where(x => x.CommodityName == c).OrderByDescending(x => x.SampleDate).First());
            }

            StationDirectory[newStationName] = newStationDirectory;

            var newCommodityDirectory2 = new CommodityDirectory();

            for (int i = 0; i < CommodityDirectory.Keys.Count; i++)
            {
                var distinctStationNames = CommodityDirectory.ElementAt(i).Value.Select(x => x.StationID).Distinct();
                foreach (var d in distinctStationNames)
                {
                    if (!newCommodityDirectory2.Keys.Contains(CommodityDirectory.ElementAt(i).Key))
                        newCommodityDirectory2.Add(CommodityDirectory.ElementAt(i).Key, new List<CsvRow> { CommodityDirectory.ElementAt(i).Value.ToList().Where(x => x.StationID == d).OrderByDescending(x => x.SampleDate).First() });
                    else newCommodityDirectory2[CommodityDirectory.ElementAt(i).Key].Add(CommodityDirectory.ElementAt(i).Value.ToList().Where(x => x.StationID == d).OrderByDescending(x => x.SampleDate).First());
                }
            }

            CommodityDirectory = newCommodityDirectory2;

            _StationHistory.RenameStation(existingStationName, newStationName);

            SetupGui();
        }
Exemplo n.º 6
0
        private void ImportCsvString(string line, bool suspendDuplicateChecking = false, bool postToEddn = false, bool updateStationVisitations = false)
        {
            var values = line.Split(';');
            bool ignoreThisRecord = false;

            CsvRow currentRow = new CsvRow();

            currentRow.SystemName = values[0];
            currentRow.StationName = _textInfo.ToTitleCase(values[1].ToLower());
            currentRow.StationID = _textInfo.ToTitleCase(values[1].ToLower()) + " [" + currentRow.SystemName + "]";
            currentRow.CommodityName = _textInfo.ToTitleCase(values[2].ToLower());
            Decimal.TryParse(values[3], out currentRow.SellPrice);
            Decimal.TryParse(values[4], out currentRow.BuyPrice);
            Decimal.TryParse(values[5], out currentRow.Demand);
            currentRow.DemandLevel = _textInfo.ToTitleCase(values[6].ToLower());
            Decimal.TryParse(values[7], out currentRow.Supply);
            currentRow.SupplyLevel = _textInfo.ToTitleCase(values[8].ToLower());
            DateTime.TryParse(values[9], out currentRow.SampleDate);

            #region Extended CSV Information
            if (values.GetLength(0) > 10)
            {
                currentRow.SourceFileName = values[10];
            }
            #endregion

            if (currentRow.CommodityName != "")
            {
                if (updateStationVisitations)
                    _StationHistory.addVisit(currentRow.StationID);

                if (!suspendDuplicateChecking)
                {
                    
                    if (StationDirectory.ContainsKey(currentRow.StationID))
                    {
                        var obsoleteData =
                            StationDirectory[currentRow.StationID].Where(
                                x =>
                                    x.StationID == currentRow.StationID && x.CommodityName == currentRow.CommodityName &&
                                    x.SampleDate <= currentRow.SampleDate).ToList();

                        // is there older data for delete ?
                        foreach (var x in obsoleteData)
                        {
                            StationDirectory[currentRow.StationID].Remove(x);
                            CommodityDirectory[currentRow.CommodityName].Remove(x);
                        }

                        // is there already data that is younger than this new record
                        var selfIsObsolete =
                            StationDirectory[currentRow.StationID].Where(
                                x =>
                                    x.StationID == currentRow.StationID && x.CommodityName == currentRow.CommodityName &&
                                    x.SampleDate > currentRow.SampleDate).ToList();
                        if (selfIsObsolete.Count > 0)
                        { 
                            ignoreThisRecord = true;  
                        }
                    }
                }

                if (!ignoreThisRecord) 
                {
                    if (!StationDirectory.ContainsKey(currentRow.StationID))
                        StationDirectory.Add(currentRow.StationID, new List<CsvRow>());


                    if (suspendDuplicateChecking || StationDirectory[currentRow.StationID].Count(x => x.StationID == currentRow.StationID && x.CommodityName == currentRow.CommodityName && x.SampleDate == currentRow.SampleDate) == 0)
                    {
                        StationDirectory[currentRow.StationID].Add(currentRow);

                        if (!CommodityDirectory.ContainsKey(currentRow.CommodityName))
                            CommodityDirectory.Add(currentRow.CommodityName, new List<CsvRow>());

                        CommodityDirectory[currentRow.CommodityName].Add(currentRow);

                        if (postToEddn && cbPostOnImport.Checked && currentRow.SystemName != "SomeSystem")
                            EDDNComm.sendToEdDDN(currentRow);
                    }
                }
            }
        }
        /// <summary>
        /// register everything for sending with this function.
        /// 2 seconds after the last registration all data will be sent automatically
        /// </summary>
        /// <param name="CommodityData"></param>
        public void sendToEdDDN(CsvRow CommodityData)
        {
            // register next data row
            _SendItems.Enqueue(CommodityData);

            // reset the timer
            _SendDelayTimer.Start();

        }