Пример #1
0
        private void ShowSystemName_Load(object sender, EventArgs e)
        {
            var systemcollection  = new AutoCompleteStringCollection();
            var stationcollection = new AutoCompleteStringCollection();


            using (var elite = new elite_testingEntities())
            {
                var systemlist  = elite.Systems.ToList();
                var stationlist = elite.Stations.ToList();
                foreach (var x in systemlist)
                {
                    systemcollection.Add(x.name);
                }

                foreach (var x in stationlist)
                {
                    stationcollection.Add(x.name);
                }
            }

            textBox2.AutoCompleteCustomSource = systemcollection;
            textBox1.AutoCompleteCustomSource = stationcollection;

            textBox2.Text = OCRThingee.Systemname;
            textBox1.Text = OCRThingee.Stationname;
        }
Пример #2
0
        private void tabControl2_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (tabControl2.SelectedTab != tabControl2.TabPages["TabPage1"])
            {
                return;
            }
            _source.Clear();
            _systemcollectionstrings.Clear();

            var systemvalues = new Dictionary <int, string>();

            using (var elite = new elite_testingEntities())
            {
                var systemcollection = from p in elite.Systems select p;
                _systemcollectionstrings.AddRange(systemcollection.Select(x => x.name));
                foreach (var v in systemcollection.ToList())
                {
                    systemvalues.Add(v.sysId, v.name);
                }
            }
            _source.AddRange(_systemcollectionstrings.ToArray());
            comboBox1.DataSource               = new BindingSource(systemvalues, null);
            comboBox1.DisplayMember            = "Value";
            comboBox1.ValueMember              = "Key";
            comboBox1.AutoCompleteMode         = AutoCompleteMode.Suggest;
            comboBox1.AutoCompleteCustomSource = _source;
            comboBox1.AutoCompleteSource       = AutoCompleteSource.CustomSource;

            comboBox4.DataSource               = new BindingSource(systemvalues, null);
            comboBox4.DisplayMember            = "Value";
            comboBox4.ValueMember              = "Key";
            comboBox4.AutoCompleteMode         = AutoCompleteMode.Suggest;
            comboBox4.AutoCompleteCustomSource = _source;
            comboBox4.AutoCompleteSource       = AutoCompleteSource.CustomSource;
        }
Пример #3
0
        private async void btn_AddRowToDatabase_Click(object sender, EventArgs e)
        {
            using (var elite = new elite_testingEntities())
            {
                try
                {
                    var cloned = new DataGridView();
                    cloned.Columns.Add(new DataGridViewTextBoxColumn());
                    cloned.Columns.Add(new DataGridViewTextBoxColumn());
                    cloned.Columns.Add(new DataGridViewTextBoxColumn());
                    cloned.Columns.Add(new DataGridViewTextBoxColumn());
                    cloned.Columns.Add(new DataGridViewTextBoxColumn());
                    cloned.Columns.Add(new DataGridViewTextBoxColumn());
                    cloned.Columns.Add(new DataGridViewTextBoxColumn());
                    cloned.Columns.Add(new DataGridViewTextBoxColumn());
                    cloned.Columns[0].Name = "SystemName";
                    cloned.Columns[1].Name = "StationName";
                    cloned.Columns[2].Name = "GoodsName";
                    cloned.Columns[3].Name = "SellPrice";
                    cloned.Columns[4].Name = "BuyPrice";
                    cloned.Columns[5].Name = "NumSupply";
                    cloned.Columns[6].Name = "GalacticAverage";

                    foreach (var y in
                             dg_OCRRows.Rows.Cast <DataGridViewRow>().Where(y => y.Cells[2].Value.ToString() != ""))
                    {
                        cloned.Rows.Add(CloneWithValues(y));
                    }
                    var   task = UpdateDatabaseAsync(elite, cloned);
                    await task;
                    tradeitemsTableAdapter.Fill(eliteDataSet.tradeitems);

                    stationsTableAdapter.Fill(eliteDataSet.stations);

                    systemsTableAdapter.Fill(eliteDataSet.systems);

                    itemsTableAdapter.Fill(eliteDataSet.items);

                    dataGridView2.Refresh();
                    dataGridView3.Refresh();
                    dataGridView4.Refresh();
                    dataGridView5.Refresh();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message.ToString(CultureInfo.InvariantCulture));
                }
            }
        }
Пример #4
0
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            var cmb = (ComboBox)sender;

            if (cmb.SelectedItem == null)
            {
                return;
            }
            var x = (KeyValuePair <int, string>)cmb.SelectedItem;

            _stationcollectionstrings.Clear();
            var stationvalues = new Dictionary <int, string>();

            using (var elite = new elite_testingEntities())
            {
                var stationcollection = from p in elite.Systems
                                        where p.sysId == x.Key
                                        join u in elite.Stations on p.sysId equals u.sysid
                                        select u;
                var list = stationcollection.ToList();
                if (list.Count > 0)
                {
                    _stationcollectionstrings.AddRange(stationcollection.Select(station => station.name));

                    _stationsource.AddRange(_stationcollectionstrings.ToArray());


                    foreach (var station in list)
                    {
                        stationvalues.Add(station.stationId, station.name);
                    }
                }
                else
                {
                    _stationsource.Add("");
                    stationvalues.Add(0, "NO STATION");
                }
            }
            comboBox2.DisplayMember            = "Value";
            comboBox2.ValueMember              = "Key";
            comboBox2.DataSource               = new BindingSource(stationvalues, null);
            comboBox2.AutoCompleteMode         = AutoCompleteMode.Suggest;
            comboBox2.AutoCompleteCustomSource = _stationsource;
            comboBox2.AutoCompleteSource       = AutoCompleteSource.CustomSource;
            comboBox2.AutoCompleteMode         = AutoCompleteMode.Suggest;
        }
Пример #5
0
        public ConsumerItemsList()
        {
            var elite = new elite_testingEntities();

            _items = (from item in elite.Items select item.name).ToArray();
        }
Пример #6
0
        private void button6_Click(object sender, EventArgs e)
        {
            if (txtCargo.Text == "")
            {
                MessageBox.Show(@"Enter the number of cargo spaces in the ship.");
                return;
            }

            if (CreditsTextBox.Text == "")
            {
                MessageBox.Show(@"Enter the amount of credits you have.");
            }


            int num;

            if (!int.TryParse(txtCargo.Text, out num))
            {
                return;
            }

            int credits;

            if (!int.TryParse(CreditsTextBox.Text, out credits))
            {
                return;
            }

            using (var elite = new elite_testingEntities())
            {
                var originatingstationKvp = (KeyValuePair <int, string>)comboBox2.SelectedItem;

                if (originatingstationKvp.Key == 0)
                {
                    return;
                }
                var destinationsystemKey = (KeyValuePair <int, string>)comboBox4.SelectedItem;

                var destinationstation = from system in elite.Systems
                                         join station in elite.Stations on system.sysId equals station.sysid
                                         join tradeitem in elite.Tradeitems on station.stationId equals tradeitem.stationid
                                         join item in elite.Items on tradeitem.itemid equals item.itemId
                                         where tradeitem.sellprice > 0
                                         where system.sysId == destinationsystemKey.Key
                                         select new
                {
                    TradeitemId   = tradeitem.itemid,
                    SystemName    = system.name,
                    StationID     = station.stationId,
                    StationName   = station.name,
                    TradeItemName = item.name,
                    Supply        = tradeitem.supply,
                    BuyPrice      = tradeitem.buyprice,
                    SellPrice     = tradeitem.sellprice
                };



                var originatingstation = from station in elite.Stations
                                         join tradeitem in elite.Tradeitems on station.stationId equals tradeitem.stationid
                                         join item in elite.Items on tradeitem.itemid equals item.itemId
                                         join system in elite.Systems on station.sysid equals system.sysId
                                         where tradeitem.supply > 0
                                         where tradeitem.buyprice > 0
                                         where station.stationId == originatingstationKvp.Key
                                         select new
                {
                    TradeitemId   = tradeitem.itemid,
                    SystemName    = system.name,
                    StationID     = station.stationId,
                    StationName   = station.name,
                    TradeItemName = item.name,
                    Supply        = tradeitem.supply,
                    BuyPrice      = tradeitem.buyprice,
                    SellPrice     = tradeitem.sellprice
                };



                var profit = from t in originatingstation
                             join f in destinationstation
                             on t.TradeitemId equals f.TradeitemId
                             where t.BuyPrice <f.SellPrice && (credits / t.BuyPrice > 0)
                                               let numberBought = (credits / t.BuyPrice)> num ? num : (credits / t.BuyPrice)
                             select new
                {
                    TradeitemID = f.TradeitemId,
                    f.SystemName,
                    f.StationID,
                    f.StationName,
                    f.TradeItemName,
                    t.Supply,
                    t.BuyPrice,
                    f.SellPrice,
                    NumberBought = numberBought,
                    Profit       = (f.SellPrice - t.BuyPrice) * numberBought
                };


                var y = profit.ToList();


                y = y.OrderByDescending(v => v.Profit).GroupBy(v => v.StationID).SelectMany(g => g).ToList();

                var bindingSource1 = new BindingSource {
                    DataSource = y
                };

                dataGridView1.DataSource = bindingSource1;
            }
        }
Пример #7
0
        private static void UpdateDatabase(elite_testingEntities elite, DataGridView thegrid)
        {
            var thissystem = elite.Systems.ToList();

            for (int index = 0; index < thegrid.Rows.Count; index++)
            {
                DataGridViewRow y = thegrid.Rows[index];
                if (y.Cells[0].FormattedValue == null)
                {
                    continue;
                }
                if (string.IsNullOrEmpty(y.Cells[0].FormattedValue.ToString()))
                {
                    continue;
                }
                if (y.Cells[1].FormattedValue == null)
                {
                    continue;
                }
                if (string.IsNullOrEmpty(y.Cells[1].FormattedValue.ToString()))
                {
                    continue;
                }
                if (y.Cells[2].FormattedValue == null)
                {
                    continue;
                }
                if (string.IsNullOrEmpty(y.Cells[2].FormattedValue.ToString()))
                {
                    continue;
                }
                if (y.Cells[3].FormattedValue == null)
                {
                    continue;
                }
                if (string.IsNullOrEmpty(y.Cells[3].FormattedValue.ToString()))
                {
                    continue;
                }
                if (y.Cells[4].FormattedValue == null)
                {
                    continue;
                }
                if (string.IsNullOrEmpty(y.Cells[4].FormattedValue.ToString()))
                {
                    continue;
                }
                if (y.Cells[5].FormattedValue == null)
                {
                    continue;
                }
                if (string.IsNullOrEmpty(y.Cells[5].FormattedValue.ToString()))
                {
                    continue;
                }
                if (y.Cells[6].FormattedValue == null)
                {
                    continue;
                }
                if (string.IsNullOrEmpty(y.Cells[6].FormattedValue.ToString()))
                {
                    continue;
                }


                var system  = y.Cells[0].FormattedValue.ToString();
                var station = y.Cells[1].FormattedValue.ToString();
                station = station.RemoveChars('\n');
                var goodsname = y.Cells[2].FormattedValue.ToString();
                var sellprice = y.Cells[3].FormattedValue.ToString();
                var buyprice  = y.Cells[4].FormattedValue.ToString();
                var numsupply = y.Cells[5].FormattedValue.ToString();

                var thesystem = thissystem.Find(s => s.name == system);

                if (thesystem == null)
                {
                    elite.Systems.Add(new system {
                        name = system
                    });
                    elite.SaveChanges();
                    thissystem = elite.Systems.ToList();

                    thesystem = thissystem.Find(s => s.name == system);
                }

                var            count = elite.Stations.Count(s => s.sysid == thesystem.sysId);
                station        thestation;
                List <station> systemstationlist;
                if (count < 1)
                {
                    thestation = null;
                }
                else
                {
                    systemstationlist = elite.Stations.Where(s => s.sysid == thesystem.sysId).ToList();
                    thestation        = systemstationlist.Find(s => s.name == station);
                }


                if (thestation == null)
                {
                    elite.Stations.Add(new station {
                        name = station, sysid = thesystem.sysId
                    });

                    elite.SaveChanges();

                    systemstationlist = elite.Stations.Where(s => s.sysid == thesystem.sysId).ToList();
                    thestation        = systemstationlist.Find(s => s.name == station);
                }

                var goodslist = elite.Items.ToList();
                var thisgood  = goodslist.Find(s => s.name == goodsname);
                if (thisgood == null)
                {
                    elite.Items.Add(new item {
                        name = goodsname
                    });
                    elite.SaveChanges();
                    goodslist = elite.Items.ToList();
                    thisgood  = goodslist.Find(s => s.name == goodsname);
                }


                var tradeitemlist =
                    elite.Tradeitems.Where(s => s.stationid == thestation.stationId).ToList();
                var thistradeitem = tradeitemlist.Find(s => s.itemid == thisgood.itemId);
                if (buyprice == "")
                {
                    buyprice = "0";
                }

                if (sellprice == "")
                {
                    sellprice = "0";
                }
                if (numsupply == "")
                {
                    numsupply = "0";
                }
                var decbuyprice  = int.Parse(buyprice);
                var decsellprice = int.Parse(sellprice);
                var intsupply    = int.Parse(numsupply);
                if (thistradeitem != null)
                {
                    thistradeitem.lastupdate = DateTime.Now;
                    thistradeitem.buyprice   = decbuyprice;
                    thistradeitem.sellprice  = decsellprice;
                    thistradeitem.supply     = intsupply;

                    elite.SaveChanges();
                }
                else
                {
                    elite.Tradeitems.Add(new tradeitem
                    {
                        lastupdate = DateTime.Now,
                        stationid  = thestation.stationId,
                        itemid     = thisgood.itemId,
                        buyprice   = decbuyprice,
                        sellprice  = decsellprice,
                        supply     = intsupply
                    });
                    elite.SaveChanges();
                }
            }
        }
Пример #8
0
 public Task UpdateDatabaseAsync(elite_testingEntities elite, DataGridView thegrid)
 {
     return(Task.Run(() => UpdateDatabase(elite, thegrid)));
 }