Subversion Repository Public Repository

CommodityUtility

This repository has no backups
This repository's network speed is throttled to 100KB/sec

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
´╗┐using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Data;
using System.Collections;

namespace CommodityUtility
{
    public static class Program
    {
        #region Data Sets
        public static CommodityUtility.IslandDataSet mainIslandDataSet;
        public static CommodityUtility.TrackingDataSet mainTrackingDataSet;

        public static CommodityUtility.IslandDataSetTableAdapters.IslandPairsTableAdapter mainIslandPairsTableAdapter;
        public static CommodityUtility.IslandDataSetTableAdapters.IslandTableAdapter mainIslandTableAdapter;
        public static CommodityUtility.IslandDataSetTableAdapters.DefaultsTableAdapter mainDefaultsTableAdapter;
        public static CommodityUtility.IslandDataSetTableAdapters.EstimatedCostViewTableAdapter mainEstimatedCostViewTableAdapter;
        public static CommodityUtility.IslandDataSetTableAdapters.TableAdapterManager mainIslandTableAdapterManager;

        public static CommodityUtility.TrackingDataSetTableAdapters.CommodityListTableAdapter mainCommodityListTableAdapter;
        public static CommodityUtility.TrackingDataSetTableAdapters.CommoditySaleTypeTableAdapter mainCommoditySaleTypeTableAdapter;
        public static CommodityUtility.TrackingDataSetTableAdapters.CommodityTableAdapter mainCommodityTableAdapter;
        public static CommodityUtility.TrackingDataSetTableAdapters.CommodityTransportsTableAdapter mainCommodityTransportsTableAdapter;
        public static CommodityUtility.TrackingDataSetTableAdapters.CommodityTransportViewTableAdapter mainCommodityTransportViewTableAdapter;
        public static CommodityUtility.TrackingDataSetTableAdapters.CommodityTypeListTableAdapter mainCommodityTypeListTableAdapter;
        public static CommodityUtility.TrackingDataSetTableAdapters.TotalProfitViewTableAdapter mainTotalProfitViewTableAdapter;
        public static CommodityUtility.TrackingDataSetTableAdapters.TransportDetailsTableAdapter mainTransportDetailsTableAdapter;
        public static CommodityUtility.TrackingDataSetTableAdapters.TransportSummaryViewTableAdapter mainTransportSummaryViewTableAdapter;
        public static CommodityUtility.TrackingDataSetTableAdapters.TableAdapterManager mainTrackingTableAdapterManager;
        #endregion

        #region Properties
        private static int _SwillDefault;
        public static int SwillDefault { get { return _SwillDefault; } set { _SwillDefault = value; } }
        private static int _GrogDefault;
        public static int GrogDefault { get { return _GrogDefault; } set { _GrogDefault = value; } }
        private static int _RumDefault;
        public static int RumDefault { get { return _RumDefault; } set { _RumDefault = value; } }
        private static int _ShotDefault;
        public static int ShotDefault { get { return _ShotDefault; } set { _ShotDefault = value; } }
        private static int _DistanceModDefault;
        public static int DistanceModDefault { get {return _DistanceModDefault;} set {_DistanceModDefault = value;} }
        #endregion  
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            InitializeDataSets();
            InitializeProperties();
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Parent());
        }

        static private void InitializeProperties()
        {
            DataRow row = mainIslandDataSet.Defaults.Rows[0];
            SwillDefault = Convert.ToInt32(row["swill"]);
            GrogDefault = Convert.ToInt32(row["grog"]);
            RumDefault = Convert.ToInt32(row["rum"]);
            ShotDefault = Convert.ToInt32(row["shot"]);
            DistanceModDefault = Convert.ToInt32(row["distanceMod"]);
        }

        static private void InitializeDataSets()
        {
            mainIslandDataSet = new IslandDataSet();
            mainIslandPairsTableAdapter = new CommodityUtility.IslandDataSetTableAdapters.IslandPairsTableAdapter();
            mainIslandTableAdapter = new CommodityUtility.IslandDataSetTableAdapters.IslandTableAdapter();
            mainIslandTableAdapterManager = new CommodityUtility.IslandDataSetTableAdapters.TableAdapterManager();
            mainDefaultsTableAdapter = new CommodityUtility.IslandDataSetTableAdapters.DefaultsTableAdapter();

            mainIslandPairsTableAdapter.Fill(mainIslandDataSet.IslandPairs);
            mainIslandTableAdapter.Fill(mainIslandDataSet.Island);
            mainDefaultsTableAdapter.Fill(mainIslandDataSet.Defaults);

            mainTrackingDataSet = new TrackingDataSet();
            mainTrackingTableAdapterManager = new CommodityUtility.TrackingDataSetTableAdapters.TableAdapterManager();
            mainCommodityListTableAdapter = new CommodityUtility.TrackingDataSetTableAdapters.CommodityListTableAdapter();
            mainCommoditySaleTypeTableAdapter = new CommodityUtility.TrackingDataSetTableAdapters.CommoditySaleTypeTableAdapter();
            mainCommodityTableAdapter = new CommodityUtility.TrackingDataSetTableAdapters.CommodityTableAdapter();
            mainCommodityTransportsTableAdapter = new CommodityUtility.TrackingDataSetTableAdapters.CommodityTransportsTableAdapter();
            mainCommodityTransportViewTableAdapter = new CommodityUtility.TrackingDataSetTableAdapters.CommodityTransportViewTableAdapter();
            mainCommodityTypeListTableAdapter = new CommodityUtility.TrackingDataSetTableAdapters.CommodityTypeListTableAdapter();
            mainTotalProfitViewTableAdapter = new CommodityUtility.TrackingDataSetTableAdapters.TotalProfitViewTableAdapter();
            mainTransportDetailsTableAdapter = new CommodityUtility.TrackingDataSetTableAdapters.TransportDetailsTableAdapter();
            mainTransportSummaryViewTableAdapter = new CommodityUtility.TrackingDataSetTableAdapters.TransportSummaryViewTableAdapter();

            mainCommodityTypeListTableAdapter.Fill(mainTrackingDataSet.CommodityTypeList);
            mainCommodityListTableAdapter.Fill(mainTrackingDataSet.CommodityList);
            mainCommoditySaleTypeTableAdapter.Fill(mainTrackingDataSet.CommoditySaleType);
            mainCommodityTableAdapter.FillBy(mainTrackingDataSet.Commodity);
            mainCommodityTransportsTableAdapter.Fill(mainTrackingDataSet.CommodityTransports);
            mainCommodityTransportViewTableAdapter.Fill(mainTrackingDataSet.CommodityTransportView);
            mainTotalProfitViewTableAdapter.Fill(mainTrackingDataSet.TotalProfitView);
            mainTransportSummaryViewTableAdapter.Fill(mainTrackingDataSet.TransportSummaryView);
            mainTransportDetailsTableAdapter.Fill(mainTrackingDataSet.TransportDetails);

            mainIslandTableAdapterManager.BackupDataSetBeforeUpdate = false;
            mainIslandTableAdapterManager.IslandPairsTableAdapter = mainIslandPairsTableAdapter;
            mainIslandTableAdapterManager.IslandTableAdapter = mainIslandTableAdapter;
            mainIslandTableAdapterManager.DefaultsTableAdapter = mainDefaultsTableAdapter;

            mainTrackingTableAdapterManager.BackupDataSetBeforeUpdate = false;
            mainTrackingTableAdapterManager.CommodityListTableAdapter = mainCommodityListTableAdapter;
            mainTrackingTableAdapterManager.CommoditySaleTypeTableAdapter = mainCommoditySaleTypeTableAdapter;
            mainTrackingTableAdapterManager.CommodityTableAdapter = mainCommodityTableAdapter;
            mainTrackingTableAdapterManager.CommodityTransportsTableAdapter = mainCommodityTransportsTableAdapter;
            mainTrackingTableAdapterManager.CommodityTypeListTableAdapter = mainCommodityTypeListTableAdapter;
            mainTrackingTableAdapterManager.TransportDetailsTableAdapter = mainTransportDetailsTableAdapter;
            mainTrackingTableAdapterManager.UpdateOrder = CommodityUtility.TrackingDataSetTableAdapters.TableAdapterManager.UpdateOrderOption.InsertUpdateDelete;
        }

        /// <summary>
        /// Places the two islands into an arraylist in alphabetical order.
        /// Ensures that the island in the first element will be the island in the firstIsland column 
        /// of the IslandPairs table.
        /// </summary>
        /// <param name="island1"></param>
        /// <param name="island2"></param>
        /// <returns></returns>
        public static ArrayList GetIslandPair(string island1, string island2)
        {
            ArrayList islands = new ArrayList();
            string firstIsland = island1;
            string secondIsland = island2;
            
            // ArrayList.Sort provided inconsistent results, and sometimes cleared the list for some reason.
            // Which island comes first alphabetically?
            int result = firstIsland.CompareTo(secondIsland);

            // If result < 0, the first island is already first alphabetically.
            // If result = 0, the islands are the same so it doesn't matter which is first
            // If result > 0, the second island is first alphabetically.  Swap them.
            if (result > 0)
            {
                string temp = firstIsland;
                firstIsland = secondIsland;
                secondIsland = temp;
            }

            islands.Add(firstIsland);
            islands.Add(secondIsland);

            return islands;
        }

        /// <summary>
        /// Retrieves the distance between two islands
        /// </summary>
        /// <param name="island1"></param>
        /// <param name="island2"></param>
        /// <returns></returns>
        public static int GetDistance(string island1, string island2)
        {
            ArrayList islands = GetIslandPair(island1, island2);

            //IslandDataSet data = new IslandDataSet();
            //IslandDataSetTableAdapters.IslandPairsTableAdapter adapter = new CommodityUtility.IslandDataSetTableAdapters.IslandPairsTableAdapter();
            //adapter.FillBy(data.IslandPairs, islands[0].ToString(), islands[1].ToString());
            //return Convert.ToInt32(data.IslandPairs.Rows[0].Field<int>("distance"));

            // Retrieve single row from database that matches the island pair
            mainIslandPairsTableAdapter.FillBy(mainIslandDataSet.IslandPairs, islands[0].ToString(), islands[1].ToString());
            int returnValue = Convert.ToInt32(mainIslandDataSet.IslandPairs.Rows[0].Field<int>("distance"));

            // Refresh the IslandPairs table with all rows
            mainIslandPairsTableAdapter.Fill(mainIslandDataSet.IslandPairs);
            return returnValue;
        }
        /// <summary>
        /// Calculates the estimated cost based on distance between islands
        /// </summary>
        /// <param name="distance"></param>
        /// <param name="distanceMod"></param>
        /// <returns></returns>
        public static int GetEstimatedCost(int distance, int distanceMod)
        {
            return (distance * distanceMod) - (10 * distance);
        }
        /// <summary>
        /// Calculates the estimated cost when given a starting and ending island
        /// </summary>
        /// <param name="island1"></param>
        /// <param name="island2"></param>
        /// <returns></returns>
        public static int GetEstimatedCost(string island1, string island2)
        {
            //int distanceMod = GetDistanceModifier();
            int distance = GetDistance(island1, island2);
            //return GetEstimatedCost(distance, distanceMod);
            return GetEstimatedCost(distance, DistanceModDefault);
        }
        
    }
}

Commits for CommodityUtility/Program.cs

Diff revisions: vs.
Revision Author Commited Message
3 wysperia picture wysperia Thu 14 Jul, 2011 20:21:16 +0000

Version 1.0