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
´╗┐using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Data;

namespace CommodityUtility
{
    public class CommodityTabTransport
    {
        #region Properties
        private string _originIsland;
        public string OriginIsland { get {return _originIsland;} set {_originIsland = value;} }
        private string _DestinationIsland;
        public string DestinationIsland { get { return _DestinationIsland; } set { _DestinationIsland = value; } }
        private double _Purchase;
        public double Purchase { get { return _Purchase; } set { _Purchase = value; } }
        private double _Sale;
        public double Sale { get { return _Sale; } set { _Sale = value; } }
        private int _Modifier;
        public int Modifier { get { return _Modifier; } set { _Modifier = value; } }
        private double _Profit;
        public double Profit { get { return _Profit; } set { _Profit = value; } }
        private ArrayList commodityList;
        public int CommodityCount { get { return commodityList.Count; } }
        private int _TransportID;
        public int TransportID { get { return _TransportID; } set { _TransportID = value; } }
        #endregion

        public CommodityTabTransport()
        {
            this.commodityList = new ArrayList();
            SelectIslands select = new SelectIslands();
            select.ShowDialog();

            string island1 = this.OriginIsland = select.Pair_Island1;
            string island2 = this.DestinationIsland = select.Pair_Island2;
            this.Modifier = select.Pair_EstCost;
            this.TransportID = 0;
        }

        public CommodityTabTransport(int id)
        {
            this.commodityList = new ArrayList();
            Program.mainTransportSummaryViewTableAdapter.FillBy(Program.mainTrackingDataSet.TransportSummaryView, id);
            DataRow row = Program.mainTrackingDataSet.TransportSummaryView.Rows[0];
            this.OriginIsland = row["StartIsland"].ToString();
            this.DestinationIsland = row["EndIsland"].ToString();
            this.Modifier = Program.GetEstimatedCost(this.OriginIsland, this.DestinationIsland);
            this.Purchase = Convert.ToDouble(row["PurchasePrice"]);
            this.Sale = Convert.ToDouble(row["SalePrice"]);
            this.Profit = Convert.ToDouble(row["Profit"]);
            this.TransportID = id;

            Program.mainCommodityTransportsTableAdapter.FillBy(Program.mainTrackingDataSet.CommodityTransports, id);
            foreach (DataRow ctRow in Program.mainTrackingDataSet.CommodityTransports)
            {
                this.commodityList.Add(Convert.ToInt32(ctRow["commodID"]));
            }
            Program.mainCommodityTransportsTableAdapter.Fill(Program.mainTrackingDataSet.CommodityTransports);
        }
        public void CalculateProfit()
        {
            this.Profit = this.Sale - this.Purchase - this.Modifier;
        }
        public bool AddCommodity(int id)
        {
            if (!commodityList.Contains(id))
            {
                this.commodityList.Add(id);
                return true;
            }
            else
                return false;
        }
        public bool RemoveCommodity(int id)
        {
            if (commodityList.Contains(id))
            {
                this.commodityList.Remove(id);
                return true;
            }
            else
                return false;
        }
        public bool SaveTransportDetails()
        {
            try
            {
                EditTransport newTransport;

                if (this.TransportID > 0)
                {
                    newTransport = new EditTransport(this.TransportID);
                    newTransport.ShowDialog();
                }
                else
                {
                    newTransport = new EditTransport(this);
                    newTransport.ShowDialog();
                }

                this.TransportID = newTransport.TransportID;

                if (!newTransport.DialogResult.Equals(System.Windows.Forms.DialogResult.Ignore))
                {
                    foreach (int commID in commodityList)
                    {
                        DataRow row = Program.mainTrackingDataSet.CommodityTransports.NewRow();
                        row["transportID"] = this.TransportID;
                        row["commodID"] = commID;
                        row["startIsland"] = this.OriginIsland;
                        row["endIsland"] = this.DestinationIsland;

                        string select = "transportID = " + this.TransportID + " and commodID = " + commID;
                        DataRow[] testRows = Program.mainTrackingDataSet.CommodityTransports.Select(select);
                        if (testRows.Length == 0)
                            Program.mainTrackingDataSet.CommodityTransports.Rows.Add(row);
                    }


                    foreach (int commID in commodityList)
                    {
                        DataRow row = Program.mainTrackingDataSet.Commodity.FindByid(commID);
                        row["dateSold"] = DateTime.Today.ToShortDateString();
                    }

                    Program.mainTrackingTableAdapterManager.UpdateAll(Program.mainTrackingDataSet);
                    Program.mainTrackingDataSet.AcceptChanges();
                    return true;
                }
                else
                    return false;
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Unable to save transport details: " + ex.Message);
                return false;
            }
        }
       

    }
}

Commits for CommodityUtility/CommodityTabTransport.cs

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

Version 1.0