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

namespace CommodityUtility
{
    public partial class EditTransport : Form
    {
        string type;
        public CommodityTabTransport newTransport;
        private int _TransportID;
        public int TransportID { get { return _TransportID; } set { _TransportID = value; } }

        public EditTransport()
        {
            InitializeComponent();
            type = "normal";
            newTransport = null;
        }

        public EditTransport(CommodityTabTransport t)
        {
            InitializeComponent();
            this.type = "new";
            this.newTransport = t;
        }

        public EditTransport(int id)
        {
            InitializeComponent();
            this.type = "single";
            this.TransportID = id;
            this.newTransport = null;
        }

        private void transportDetailsBindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {
            Save();
        }

        private void Save()
        {
            this.Validate();
            this.transportDetailsBindingSource.EndEdit();
            Program.mainTrackingTableAdapterManager.UpdateAll(Program.mainTrackingDataSet);
            Program.mainTrackingDataSet.AcceptChanges();
            if (this.TransportID == 0)
                this.TransportID = Convert.ToInt32(transportDetailsBindingNavigator.PositionItem.Text);
             
        }
        private void EditTransport_Load(object sender, EventArgs e)
        {
            Program.mainTransportDetailsTableAdapter.Fill(Program.mainTrackingDataSet.TransportDetails);
        }
        private void EditTransport_Shown(object sender, EventArgs e)
        {
            if (this.type.Equals("new"))
            {
                this.bindingNavigatorAddNewItem.PerformClick();
                this.dateDateTimePicker.Value = DateTime.Today;
                this.comboBox1.SelectedValue = this.newTransport.OriginIsland;
                this.comboBox2.SelectedValue = this.newTransport.DestinationIsland;
                this.distanceModifierTextBox.Text = this.newTransport.Modifier.ToString();
            }
            else if (this.type.Equals("single"))
            {
                Program.mainTransportDetailsTableAdapter.FillBy(Program.mainTrackingDataSet.TransportDetails, TransportID);
            }
        }
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBox1 != null)
            {
                LoadCost();
            }
        }
        private void LoadCost()
        {
            if (this.comboBox1.SelectedValue != null && this.comboBox2.SelectedValue != null)
                this.distanceModifierTextBox.Text = Program.GetEstimatedCost(this.comboBox1.SelectedValue.ToString(), this.comboBox2.SelectedValue.ToString()).ToString();
        }
        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBox2 != null)
            {
                LoadCost();
            }
        }
        private int GetTextBoxValue(TextBox tb)
        {
            if (tb.Text.Equals(string.Empty))
                return 0;
            else
                return Convert.ToInt32(tb.Text);
        }
        private void CalculateTotal()
        {
            int startingValue = 0;
            startingValue += GetTextBoxValue(startShotTextBox) * Program.ShotDefault;
            startingValue += GetTextBoxValue(startSwillTextBox) * Program.SwillDefault;
            startingValue += GetTextBoxValue(startGrogTextBox) * Program.GrogDefault;
            startingValue += GetTextBoxValue(startRumTextBox) * Program.RumDefault;

            int endingValue = 0;
            endingValue += GetTextBoxValue(endSwillTextBox) * Program.SwillDefault;
            endingValue += GetTextBoxValue(endGrogTextBox) * Program.GrogDefault;
            endingValue += GetTextBoxValue(endRumTextBox) * Program.RumDefault;
            endingValue += GetTextBoxValue(endShotTextBox) * Program.ShotDefault;

            int pillage = GetTextBoxValue(pillageTextBox);
            int cost = GetTextBoxValue(distanceModifierTextBox);

            totalTextBox.Text = (endingValue - startingValue + pillage - cost).ToString();
        }
        private void TextboxChanged(object sender, EventArgs e)
        {
            CalculateTotal();
        }
        private void EditTransport_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (e.CloseReason.Equals(CloseReason.UserClosing))
            {
                if (MessageBox.Show("Save Changes?", "Save?", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    Save();
                }
                else
                    this.DialogResult = DialogResult.Ignore;
            }
        }
    }
}

Commits for CommodityUtility/EditTransport.cs

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

Version 1.0