diff options
-rwxr-xr-x | About.cs | 137 | ||||
-rw-r--r-- | CSV.cs | 116 | ||||
-rw-r--r-- | Config.cs | 150 | ||||
-rw-r--r-- | Config.xml | 47 | ||||
-rw-r--r-- | MainForm.cs | 561 | ||||
-rwxr-xr-x[-rw-r--r--] | Query.cs (renamed from TugTable.cs) | 197 | ||||
-rw-r--r-- | TLReader.MainForm.resources | bin | 5283 -> 4949 bytes | |||
-rw-r--r-- | TLReader.cmbx | 30 | ||||
-rw-r--r-- | TLReader.prjx | 66 | ||||
-rw-r--r-- | Util.cs | 98 |
10 files changed, 739 insertions, 663 deletions
diff --git a/About.cs b/About.cs new file mode 100755 index 0000000..252ee68 --- /dev/null +++ b/About.cs @@ -0,0 +1,137 @@ +// TLReader - reads access database containing tug info
+// Copyright (C) 2004 Ian Cowburn
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+using System;
+using System.Windows.Forms;
+using System.Reflection;
+
+namespace TLReader
+{
+ /// <summary>
+ /// Description of About.
+ /// </summary>
+ public class About : System.Windows.Forms.Form
+ {
+ private System.Windows.Forms.Label label;
+ private System.Windows.Forms.RichTextBox m_text;
+ private System.Windows.Forms.Label m_version;
+ private System.Windows.Forms.Button m_ok;
+ public About()
+ {
+ //
+ // The InitializeComponent() call is required for Windows Forms designer support.
+ //
+ InitializeComponent();
+
+ m_text.Text+="This program is free software; you can redistribute it and/or ";
+ m_text.Text+="modify it under the terms of the GNU General Public License ";
+ m_text.Text+="as published by the Free Software Foundation; either version 2 ";
+ m_text.Text+="of the License, or (at your option) any later version.\n";
+ m_text.Text+="\n";
+ m_text.Text+="This program is distributed in the hope that it will be useful, ";
+ m_text.Text+="but WITHOUT ANY WARRANTY; without even the implied warranty of ";
+ m_text.Text+="MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ";
+ m_text.Text+="GNU General Public License for more details.\n";
+ m_text.Text+="\n";
+ m_text.Text+="You should have received a copy of the GNU General Public License ";
+ m_text.Text+="along with this program; if not, write to the Free Software ";
+ m_text.Text+="Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n";
+
+ m_version.Text="Version " +
+ Assembly.GetExecutingAssembly().GetName().Version.Major + "."+
+ Assembly.GetExecutingAssembly().GetName().Version.Minor;
+ }
+
+ #region Windows Forms Designer generated code
+ /// <summary>
+ /// This method is required for Windows Forms designer support.
+ /// Do not change the method contents inside the source code editor. The Forms designer might
+ /// not be able to load this method if it was changed manually.
+ /// </summary>
+ private void InitializeComponent() {
+ this.m_ok = new System.Windows.Forms.Button();
+ this.m_version = new System.Windows.Forms.Label();
+ this.m_text = new System.Windows.Forms.RichTextBox();
+ this.label = new System.Windows.Forms.Label();
+ this.SuspendLayout();
+ //
+ // m_ok
+ //
+ this.m_ok.Location = new System.Drawing.Point(416, 312);
+ this.m_ok.Name = "m_ok";
+ this.m_ok.Size = new System.Drawing.Size(96, 24);
+ this.m_ok.TabIndex = 1;
+ this.m_ok.Text = "OK";
+ this.m_ok.Click += new System.EventHandler(this.OnOK);
+ //
+ // m_version
+ //
+ this.m_version.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
+ this.m_version.Location = new System.Drawing.Point(416, 8);
+ this.m_version.Name = "m_version";
+ this.m_version.Size = new System.Drawing.Size(96, 32);
+ this.m_version.TabIndex = 3;
+ this.m_version.Text = "Version 1.0";
+ this.m_version.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
+ //
+ // m_text
+ //
+ this.m_text.BackColor = System.Drawing.SystemColors.Info;
+ this.m_text.Font = new System.Drawing.Font("Courier New", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
+ this.m_text.Location = new System.Drawing.Point(8, 48);
+ this.m_text.Name = "m_text";
+ this.m_text.ReadOnly = true;
+ this.m_text.Size = new System.Drawing.Size(504, 256);
+ this.m_text.TabIndex = 0;
+ this.m_text.TabStop = false;
+ this.m_text.Text = "";
+ //
+ // label
+ //
+ this.label.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
+ this.label.Location = new System.Drawing.Point(8, 8);
+ this.label.Name = "label";
+ this.label.Size = new System.Drawing.Size(400, 32);
+ this.label.TabIndex = 2;
+ this.label.Text = "TLReader (c) Copyright 2004 Ian Cowburn";
+ this.label.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
+ //
+ // About
+ //
+ this.AutoScaleBaseSize = new System.Drawing.Size(5, 14);
+ this.ClientSize = new System.Drawing.Size(522, 343);
+ this.Controls.Add(this.m_version);
+ this.Controls.Add(this.label);
+ this.Controls.Add(this.m_ok);
+ this.Controls.Add(this.m_text);
+ this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
+ this.MaximizeBox = false;
+ this.MinimizeBox = false;
+ this.Name = "About";
+ this.ShowInTaskbar = false;
+ this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
+ this.Text = "About";
+ this.ResumeLayout(false);
+ }
+ #endregion
+ void OnOK(object sender, System.EventArgs e)
+ {
+ Close();
+ }
+
+ }
+}
@@ -1,59 +1,57 @@ -// TLReader - reads access database containing tug info -// Copyright (C) 2004 Ian Cowburn -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// -using System; -using System.IO; - -namespace TLReader -{ - /// <summary> - /// Description of CSV. - /// </summary> - public class CSV - { - public CSV(StreamWriter w) - { - m_str=w; - m_first=true; - } - - public void Value(string s) - { - s=s.Replace("\r\n"," "); - s=s.Replace("\n\r"," "); - s=s.Replace('\n',' '); - s=s.Replace('"','\''); - - if (!m_first) - { - m_str.Write(','); - } - - m_str.Write("\""+s+"\""); - m_first=false; - } - - public void EndLine() - { - m_str.WriteLine(); - m_first=true; - } - - private StreamWriter m_str; - private bool m_first; - } -} +// TLReader - reads access database containing tug info
+// Copyright (C) 2004 Ian Cowburn
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+using System;
+using System.IO;
+
+namespace TLReader
+{
+ /// <summary>
+ /// Description of CSV.
+ /// </summary>
+ public class CSV
+ {
+ public CSV(StreamWriter w)
+ {
+ m_str=w;
+ m_first=true;
+ }
+
+ public void Value(string s)
+ {
+ s=Util.NewLineToSpace(s);
+ s=s.Replace('"','\'');
+
+ if (!m_first)
+ {
+ m_str.Write(',');
+ }
+
+ m_str.Write("\""+s+"\"");
+ m_first=false;
+ }
+
+ public void EndLine()
+ {
+ m_str.WriteLine();
+ m_first=true;
+ }
+
+ private StreamWriter m_str;
+ private bool m_first;
+ }
+}
@@ -1,76 +1,74 @@ -// TLReader - reads access database containing tug info -// Copyright (C) 2004 Ian Cowburn -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// -using System; -using System.IO; -using System.Xml; -using System.Xml.Serialization; - -namespace TLReader -{ - public class Config - { - public static TLConfig Load() - { - string fn="config.xml"; - - if (!File.Exists(fn)) - { - fn="..\\..\\config.xml"; - } - - XmlSerializer xml = new XmlSerializer(typeof(TLConfig)); - FileStream fs = new FileStream(fn,FileMode.Open); - - TLConfig conf=(TLConfig)xml.Deserialize(fs); - - fs.Close(); - - return conf; - } - - private Config() - { - } - } - - public class Table - { - public Table() - { - } - - public string Name; - public string Fields; - } - - public class TLConfig - { - public TLConfig() - { - } - - public string Connect; - public Table Intro; - public Table Landcode; - public Table Owners; - public Table TugDetails; - public Table Wharves; - public Table TugList; - public string Query; - } -} +// TLReader - reads access database containing tug info
+// Copyright (C) 2004 Ian Cowburn
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+using System;
+using System.IO;
+using System.Xml;
+using System.Xml.Serialization;
+
+namespace TLReader
+{
+ public class Config
+ {
+ public static TLConfig Load()
+ {
+ string fn="config.xml";
+
+ if (!File.Exists(fn))
+ {
+ fn="..\\..\\config.xml";
+ }
+
+ XmlSerializer xml = new XmlSerializer(typeof(TLConfig));
+ FileStream fs = new FileStream(fn,FileMode.Open);
+
+ TLConfig conf=(TLConfig)xml.Deserialize(fs);
+
+ fs.Close();
+
+ conf.DisplayNames=Util.RemoveNewLine(conf.DisplayNames);
+ conf.Query=Util.NewLineToSpace(conf.Query);
+
+ return conf;
+ }
+
+ private Config()
+ {
+ }
+ }
+
+ public class Table
+ {
+ public Table()
+ {
+ }
+
+ public string Name;
+ public string Fields;
+ }
+
+ public class TLConfig
+ {
+ public TLConfig()
+ {
+ }
+
+ public string Connect;
+ public string DisplayNames;
+ public string Query;
+ }
+}
@@ -1,27 +1,20 @@ -<TLConfig> -<Connect>Driver={Microsoft Access Driver (*.mdb)};DBQ=E:\\tuglist00.mdb</Connect> -<Intro> - <Name>intro</Name> - <Fields>LastUpdate,Names,Ships,TitelText</Fields> -</Intro> -<Landcode> - <Name>LANDCODE</Name> - <Fields>CODE,COUNTRY,NAT</Fields> -</Landcode> -<Owners> - <Name>owners</Name> - <Fields>OwnerNR,Short,NAT,Description,Adres,Colors NR</Fields> -</Owners> -<TugDetails> - <Name>tugdetails</Name> - <Fields>TugNR,Specifications,Link,WharfNR</Fields> -</TugDetails> -<Wharves> - <Name>Wharves</Name> - <Fields>WharfNR,Short,NAT,Description,Adres</Fields> -</Wharves> -<TugList> - <Name>tuglist00</Name> - <Fields>NR,NAME,NAT,BUILD,SCRAP,BRT,PK,YardNR,ONAMES,PicNR,SITE,TugNR,OwnerNR,RegNR,EuroNR,CallSign</Fields> -</TugList> -</TLConfig> +<TLConfig>
+<Connect>Driver={Microsoft Access Driver (*.mdb)};DBQ=E:\\tuglist00.mdb</Connect>
+<DisplayNames>
+Tug Name,
+Nationality,
+Owner's Name,
+Owner's Nationality,
+Owner's Description,
+Owner's Address
+</DisplayNames>
+<Query>
+select tuglist00.name,
+ tuglist00.nat,
+ owners.short,
+ owners.nat,
+ owners.description,
+ owners.adres
+ from tuglist00,owners where tuglist00.ownerNR=owners.ownerNR
+</Query>
+</TLConfig>
diff --git a/MainForm.cs b/MainForm.cs index c6d6cb4..dc1e38a 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -1,300 +1,261 @@ -// TLReader - reads access database containing tug info -// Copyright (C) 2004 Ian Cowburn -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// -using System; -using System.Windows.Forms; -using System.Data; -using System.Data.Common; -using System.Data.Odbc; -using System.Collections; -using System.IO; - -namespace TLReader -{ - /// <summary> - /// Description of MainForm. - /// </summary> - public class MainForm : System.Windows.Forms.Form - { - private System.Windows.Forms.Label label; - private System.Windows.Forms.ComboBox m_tableSelect; - private System.Windows.Forms.Button m_quitButton; - private System.Windows.Forms.ListView m_list; - private System.Windows.Forms.ProgressBar m_progress; - private System.Windows.Forms.Button m_csvButton; - - private OdbcConnection m_dbase; - private TLConfig m_config; - private TugTable m_intro; - private TugTable m_landcode; - private TugTable m_owners; - private TugTable m_tdetails; - private TugTable m_wharves; - private TugTable m_tlist; - - private Hashtable m_tables; - - public MainForm() - { - // - // The InitializeComponent() call is required for Windows Forms designer support. - // - InitializeComponent(); - - m_config=Config.Load(); - - m_dbase=new OdbcConnection(m_config.Connect); - - m_dbase.Open(); - - Text+=" - "+m_dbase.Database; - - m_intro=new TugTable(m_dbase,m_config.Intro); - m_landcode=new TugTable(m_dbase,m_config.Landcode); - m_owners=new TugTable(m_dbase,m_config.Owners); - m_tdetails=new TugTable(m_dbase,m_config.TugDetails); - m_wharves=new TugTable(m_dbase,m_config.Wharves); - m_tlist=new TugTable(m_dbase,m_config.TugList); - - m_tables=new Hashtable(); - - m_tables.Add("Intro",m_intro); - m_tables.Add("Landcode",m_landcode); - m_tables.Add("Owners",m_owners); - m_tables.Add("Tugdetails",m_tdetails); - m_tables.Add("Tuglist",m_tlist); - m_tables.Add("Wharves",m_wharves); - - m_tableSelect.SelectedIndex=0; - - FillList(); - } - - [STAThread] - public static void Main(string[] args) - { - try - { - Application.Run(new MainForm()); - } - catch(Exception e) - { - Util.Error(e.ToString()); - } - } - - #region Windows Forms Designer generated code - /// <summary> - /// This method is required for Windows Forms designer support. - /// Do not change the method contents inside the source code editor. The Forms designer might - /// not be able to load this method if it was changed manually. - /// </summary> - private void InitializeComponent() { - this.m_csvButton = new System.Windows.Forms.Button(); - this.m_progress = new System.Windows.Forms.ProgressBar(); - this.m_list = new System.Windows.Forms.ListView(); - this.m_quitButton = new System.Windows.Forms.Button(); - this.m_tableSelect = new System.Windows.Forms.ComboBox(); - this.label = new System.Windows.Forms.Label(); - this.SuspendLayout(); - // - // m_csvButton - // - this.m_csvButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.m_csvButton.Location = new System.Drawing.Point(448, 504); - this.m_csvButton.Name = "m_csvButton"; - this.m_csvButton.Size = new System.Drawing.Size(104, 32); - this.m_csvButton.TabIndex = 1; - this.m_csvButton.Text = "Export as CSV"; - this.m_csvButton.Click += new System.EventHandler(this.OnExportCSV); - // - // m_progress - // - this.m_progress.Location = new System.Drawing.Point(8, 504); - this.m_progress.Name = "m_progress"; - this.m_progress.Size = new System.Drawing.Size(424, 32); - this.m_progress.TabIndex = 3; - // - // m_list - // - this.m_list.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.m_list.FullRowSelect = true; - this.m_list.GridLines = true; - this.m_list.HideSelection = false; - this.m_list.Location = new System.Drawing.Point(8, 40); - this.m_list.Name = "m_list"; - this.m_list.Size = new System.Drawing.Size(664, 456); - this.m_list.TabIndex = 2; - this.m_list.View = System.Windows.Forms.View.Details; - // - // m_quitButton - // - this.m_quitButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.m_quitButton.Location = new System.Drawing.Point(568, 504); - this.m_quitButton.Name = "m_quitButton"; - this.m_quitButton.Size = new System.Drawing.Size(104, 32); - this.m_quitButton.TabIndex = 0; - this.m_quitButton.Text = "Quit"; - this.m_quitButton.Click += new System.EventHandler(this.OnQuit); - // - // m_tableSelect - // - this.m_tableSelect.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.m_tableSelect.Items.AddRange(new object[] { - "Intro", - "Landcode", - "Owners", - "Tugdetails", - "Tuglist", - "Wharves"}); - this.m_tableSelect.Location = new System.Drawing.Point(64, 8); - this.m_tableSelect.Name = "m_tableSelect"; - this.m_tableSelect.Size = new System.Drawing.Size(200, 21); - this.m_tableSelect.Sorted = true; - this.m_tableSelect.TabIndex = 4; - this.m_tableSelect.SelectedIndexChanged += new System.EventHandler(this.OnSelectTable); - // - // label - // - this.label.Location = new System.Drawing.Point(16, 8); - this.label.Name = "label"; - this.label.Size = new System.Drawing.Size(40, 24); - this.label.TabIndex = 5; - this.label.Text = "Table:"; - this.label.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; - // - // MainForm - // - this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); - this.ClientSize = new System.Drawing.Size(680, 541); - this.Controls.Add(this.label); - this.Controls.Add(this.m_tableSelect); - this.Controls.Add(this.m_progress); - this.Controls.Add(this.m_list); - this.Controls.Add(this.m_csvButton); - this.Controls.Add(this.m_quitButton); - this.MinimumSize = new System.Drawing.Size(320, 200); - this.Name = "MainForm"; - this.Text = "Tuglist Reader"; - this.ResumeLayout(false); - } - #endregion - - void OnQuit(object sender, System.EventArgs e) - { - Close(); - } - - void OnExportCSV(object sender, System.EventArgs e) - { - TugTable t=(TugTable)m_tables[m_tableSelect.Text]; - SaveFileDialog fsel=new SaveFileDialog(); - - fsel.Filter="CSV files (*.csv)|*.csv|All files (*.*)|*.*"; - fsel.RestoreDirectory=true; - - if(fsel.ShowDialog()==DialogResult.OK) - { - StreamWriter str=File.CreateText(fsel.FileName); - - if(str!=null) - { - m_progress.Maximum=m_list.Items.Count+1; - m_progress.Step=1; - m_progress.Value=0; - - CSV csv=new CSV(str); - - foreach (string s in t.Fields) - { - csv.Value(s); - } - - csv.EndLine(); - m_progress.PerformStep(); - - foreach (ListViewItem i in m_list.Items) - { - //csv.Value(i.Text); - - foreach (ListViewItem.ListViewSubItem si in i.SubItems) - { - csv.Value(si.Text); - } - - csv.EndLine(); - m_progress.PerformStep(); - } - - str.Close(); - } - else - { - Util.Error("Failed to open "+fsel.FileName); - } - } - - m_progress.Value=0; - } - - private void FillList() - { - TugTable t=(TugTable)m_tables[m_tableSelect.Text]; - int f; - - m_list.Columns.Clear(); - m_list.Items.Clear(); - - foreach (string s in t.Fields) - { - m_list.Columns.Add(s,100,HorizontalAlignment.Left); - } - - for(f=0;f<t.Count;f++) - { - ArrayList l=new ArrayList(); - - foreach (string s in t.Row(f)) - { - l.Add(s); - } - - AddRow(l); - } - } - - private void AddRow(ArrayList l) - { - ListViewItem i=new ListViewItem((string)l[0]); - - for(int f=1;f<l.Count;f++) - { - i.SubItems.Add((string)l[f]); - } - - m_list.Items.Add(i); - } - - void OnSelectTable(object sender, System.EventArgs e) - { - FillList(); - } - - } -} +// TLReader - reads access database containing tug info
+// Copyright (C) 2004 Ian Cowburn
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+using System;
+using System.Windows.Forms;
+using System.Data;
+using System.Data.Common;
+using System.Data.Odbc;
+using System.Collections;
+using System.IO;
+
+namespace TLReader
+{
+ /// <summary>
+ /// Description of MainForm.
+ /// </summary>
+ public class MainForm : System.Windows.Forms.Form
+ {
+ private System.Windows.Forms.Button m_quitButton;
+ private System.Windows.Forms.ListView m_list;
+ private System.Windows.Forms.Button m_aboutButton;
+ private System.Windows.Forms.ProgressBar m_progress;
+ private System.Windows.Forms.Button m_csvButton;
+
+ private OdbcConnection m_dbase;
+ private Query m_query;
+ private TLConfig m_config;
+
+ public MainForm()
+ {
+ //
+ // The InitializeComponent() call is required for Windows Forms designer support.
+ //
+ InitializeComponent();
+
+ m_config=Config.Load();
+
+ m_dbase=new OdbcConnection(m_config.Connect);
+
+ m_dbase.Open();
+
+ Text+=" - "+m_dbase.Database;
+
+ m_query=new Query(m_dbase,m_config.DisplayNames,m_config.Query);
+
+ FillList();
+ }
+
+ [STAThread]
+ public static void Main(string[] args)
+ {
+ try
+ {
+ Application.Run(new MainForm());
+ }
+ catch(Exception e)
+ {
+ Util.Error(e.ToString());
+ }
+ }
+
+ #region Windows Forms Designer generated code
+ /// <summary>
+ /// This method is required for Windows Forms designer support.
+ /// Do not change the method contents inside the source code editor. The Forms designer might
+ /// not be able to load this method if it was changed manually.
+ /// </summary>
+ private void InitializeComponent() {
+ this.m_csvButton = new System.Windows.Forms.Button();
+ this.m_progress = new System.Windows.Forms.ProgressBar();
+ this.m_aboutButton = new System.Windows.Forms.Button();
+ this.m_list = new System.Windows.Forms.ListView();
+ this.m_quitButton = new System.Windows.Forms.Button();
+ this.SuspendLayout();
+ //
+ // m_csvButton
+ //
+ this.m_csvButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.m_csvButton.Location = new System.Drawing.Point(448, 504);
+ this.m_csvButton.Name = "m_csvButton";
+ this.m_csvButton.Size = new System.Drawing.Size(104, 32);
+ this.m_csvButton.TabIndex = 1;
+ this.m_csvButton.Text = "Export as CSV";
+ this.m_csvButton.Click += new System.EventHandler(this.OnExportCSV);
+ //
+ // m_progress
+ //
+ this.m_progress.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
+ | System.Windows.Forms.AnchorStyles.Right)));
+ this.m_progress.Location = new System.Drawing.Point(128, 512);
+ this.m_progress.Name = "m_progress";
+ this.m_progress.Size = new System.Drawing.Size(304, 16);
+ this.m_progress.TabIndex = 3;
+ //
+ // m_aboutButton
+ //
+ this.m_aboutButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
+ this.m_aboutButton.Location = new System.Drawing.Point(8, 504);
+ this.m_aboutButton.Name = "m_aboutButton";
+ this.m_aboutButton.Size = new System.Drawing.Size(104, 32);
+ this.m_aboutButton.TabIndex = 4;
+ this.m_aboutButton.Text = "About";
+ this.m_aboutButton.Click += new System.EventHandler(this.OnAbout);
+ //
+ // m_list
+ //
+ this.m_list.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
+ | System.Windows.Forms.AnchorStyles.Left)
+ | System.Windows.Forms.AnchorStyles.Right)));
+ this.m_list.FullRowSelect = true;
+ this.m_list.GridLines = true;
+ this.m_list.HideSelection = false;
+ this.m_list.Location = new System.Drawing.Point(8, 8);
+ this.m_list.Name = "m_list";
+ this.m_list.Size = new System.Drawing.Size(664, 488);
+ this.m_list.Sorting = System.Windows.Forms.SortOrder.Ascending;
+ this.m_list.TabIndex = 2;
+ this.m_list.View = System.Windows.Forms.View.Details;
+ //
+ // m_quitButton
+ //
+ this.m_quitButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.m_quitButton.Location = new System.Drawing.Point(568, 504);
+ this.m_quitButton.Name = "m_quitButton";
+ this.m_quitButton.Size = new System.Drawing.Size(104, 32);
+ this.m_quitButton.TabIndex = 0;
+ this.m_quitButton.Text = "Quit";
+ this.m_quitButton.Click += new System.EventHandler(this.OnQuit);
+ //
+ // MainForm
+ //
+ this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
+ this.ClientSize = new System.Drawing.Size(680, 541);
+ this.Controls.Add(this.m_aboutButton);
+ this.Controls.Add(this.m_progress);
+ this.Controls.Add(this.m_list);
+ this.Controls.Add(this.m_csvButton);
+ this.Controls.Add(this.m_quitButton);
+ this.MinimumSize = new System.Drawing.Size(420, 200);
+ this.Name = "MainForm";
+ this.Text = "Tuglist Reader";
+ this.ResumeLayout(false);
+ }
+ #endregion
+
+ void OnQuit(object sender, System.EventArgs e)
+ {
+ Close();
+ }
+
+ void OnExportCSV(object sender, System.EventArgs e)
+ {
+ SaveFileDialog fsel=new SaveFileDialog();
+
+ fsel.Filter="CSV files (*.csv)|*.csv|All files (*.*)|*.*";
+ fsel.RestoreDirectory=true;
+
+ if(fsel.ShowDialog()==DialogResult.OK)
+ {
+ StreamWriter str=File.CreateText(fsel.FileName);
+
+ if(str!=null)
+ {
+ m_progress.Maximum=m_list.Items.Count+1;
+ m_progress.Step=1;
+ m_progress.Value=0;
+
+ CSV csv=new CSV(str);
+
+ foreach (string s in m_query.Fields)
+ {
+ csv.Value(s);
+ }
+
+ csv.EndLine();
+ m_progress.PerformStep();
+
+ foreach (ListViewItem i in m_list.Items)
+ {
+ //csv.Value(i.Text);
+
+ foreach (ListViewItem.ListViewSubItem si in i.SubItems)
+ {
+ csv.Value(si.Text);
+ }
+
+ csv.EndLine();
+ m_progress.PerformStep();
+ }
+
+ str.Close();
+ }
+ else
+ {
+ Util.Error("Failed to open "+fsel.FileName);
+ }
+ }
+
+ m_progress.Value=0;
+ }
+
+ private void FillList()
+ {
+ int f;
+
+ m_list.Columns.Clear();
+ m_list.Items.Clear();
+
+ foreach (string s in m_query.Fields)
+ {
+ m_list.Columns.Add(s,100,HorizontalAlignment.Left);
+ }
+
+ for(f=0;f<m_query.Count;f++)
+ {
+ ArrayList l=new ArrayList();
+
+ foreach (string s in m_query.Row(f))
+ {
+ l.Add(s);
+ }
+
+ AddRow(l);
+ }
+ }
+
+ private void AddRow(ArrayList l)
+ {
+ ListViewItem i=new ListViewItem((string)l[0]);
+
+ for(int f=1;f<l.Count;f++)
+ {
+ i.SubItems.Add((string)l[f]);
+ }
+
+ m_list.Items.Add(i);
+ }
+
+ void OnAbout(object sender, System.EventArgs e)
+ {
+ About a=new About();
+
+ a.ShowDialog(this);
+ }
+
+ }
+}
diff --git a/TugTable.cs b/Query.cs index 3b77c1f..2404703 100644..100755 --- a/TugTable.cs +++ b/Query.cs @@ -1,114 +1,83 @@ -// TLReader - reads access database containing tug info -// Copyright (C) 2004 Ian Cowburn -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// -using System; -using System.Data; -using System.Data.Common; -using System.Data.Odbc; -using System.Collections; -using System.Collections.Specialized; -using System.Windows.Forms; - -namespace TLReader -{ - /// <summary> - /// Description of TugTable. - /// </summary> - public class TugTable - { - public TugTable(OdbcConnection con, Table t) - { - string sql="select "; - bool first=true; - - m_fields=new StringCollection(); - m_fields.AddRange(t.Fields.Split(new char[] {','})); - - foreach (string s in m_fields) - { - if (first) - { - sql+="["+s+"]"; - } - else - { - sql+=", ["+s+"]"; - } - - first=false; - } - - sql+=" from "+t.Name; - - OdbcCommand cmd=new OdbcCommand(sql,con); - OdbcDataReader r=cmd.ExecuteReader(); - - m_data=new ArrayList(); - - while(r.Read()) - { - StringCollection row=new StringCollection(); - - for(int f=0;f<m_fields.Count;f++) - { - string val="No data"; - - if (!r.IsDBNull(f)) - { - val=r.GetValue(f).ToString(); - } - - row.Add(val); - } - - m_data.Add(row); - } - - r.Close(); - } - - public int Count - { - get {return m_data.Count;} - } - - public StringCollection Fields - { - get {return m_fields;} - } - - public string Get(string field,int index) - { - StringCollection d=(StringCollection)m_data[index]; - - return d[m_fields.IndexOf(field)]; - } - - public string Get(string field,string index_as_string) - { - return Get(field,Convert.ToInt32(index_as_string)); - } - - public StringCollection Row(int row) - { - return (StringCollection)m_data[row]; - } - - private ArrayList m_data; - private StringCollection m_fields; - } -} +// TLReader - reads access database containing tug info
+// Copyright (C) 2004 Ian Cowburn
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+using System;
+using System.Data;
+using System.Data.Common;
+using System.Data.Odbc;
+using System.Collections;
+using System.Collections.Specialized;
+using System.Windows.Forms;
+
+namespace TLReader
+{
+ /// <summary>
+ /// Description of Query.
+ /// </summary>
+ public class Query
+ {
+ public Query(OdbcConnection con, string columns, string query)
+ {
+ m_fields=new StringCollection();
+ m_fields.AddRange(columns.Split(new char[] {','}));
+
+ OdbcCommand cmd=new OdbcCommand(query,con);
+ OdbcDataReader r=cmd.ExecuteReader();
+
+ m_data=new ArrayList();
+
+ while(r.Read())
+ {
+ StringCollection row=new StringCollection();
+
+ for(int f=0;f<m_fields.Count;f++)
+ {
+ string val="No data";
+
+ if (!r.IsDBNull(f))
+ {
+ val=r.GetValue(f).ToString();
+ }
+
+ row.Add(val);
+ }
+
+ m_data.Add(row);
+ }
+
+ r.Close();
+ }
+
+ public int Count
+ {
+ get {return m_data.Count;}
+ }
+
+ public StringCollection Fields
+ {
+ get {return m_fields;}
+ }
+
+ public StringCollection Row(int row)
+ {
+ return (StringCollection)m_data[row];
+ }
+
+ private ArrayList m_data;
+ private StringCollection m_fields;
+ }
+}
diff --git a/TLReader.MainForm.resources b/TLReader.MainForm.resources Binary files differindex 6f03156..ac48dbd 100644 --- a/TLReader.MainForm.resources +++ b/TLReader.MainForm.resources diff --git a/TLReader.cmbx b/TLReader.cmbx index aa12666..073a7e2 100644 --- a/TLReader.cmbx +++ b/TLReader.cmbx @@ -1,16 +1,16 @@ -<Combine fileversion="1.0" name="TLReader" description=""> - <StartMode startupentry="TLReader" single="True"> - <Execute entry="TLReader" type="None" /> - </StartMode> - <Entries> - <Entry filename=".\.\TLReader.prjx" /> - </Entries> - <Configurations active="Debug"> - <Configuration name="Release"> - <Entry name="TLReader" configurationname="Debug" build="False" /> - </Configuration> - <Configuration name="Debug"> - <Entry name="TLReader" configurationname="Debug" build="False" /> - </Configuration> - </Configurations> +<Combine fileversion="1.0" name="TLReader" description="">
+ <StartMode startupentry="TLReader" single="True">
+ <Execute entry="TLReader" type="None" />
+ </StartMode>
+ <Entries>
+ <Entry filename=".\.\TLReader.prjx" />
+ </Entries>
+ <Configurations active="Debug">
+ <Configuration name="Release">
+ <Entry name="TLReader" configurationname="Debug" build="False" />
+ </Configuration>
+ <Configuration name="Debug">
+ <Entry name="TLReader" configurationname="Debug" build="False" />
+ </Configuration>
+ </Configurations>
</Combine>
\ No newline at end of file diff --git a/TLReader.prjx b/TLReader.prjx index a7463aa..6229aba 100644 --- a/TLReader.prjx +++ b/TLReader.prjx @@ -1,33 +1,35 @@ -<Project name="TLReader" standardNamespace="TLReader" description="" newfilesearch="None" enableviewstate="True" version="1.1" projecttype="C#"> - <Contents> - <File name=".\MainForm.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> - <File name=".\AssemblyInfo.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> - <File name=".\DefaultNamespace.MainForm.resources" subtype="Code" buildaction="EmbedAsResource" dependson="" data="" /> - <File name=".\TLReader.MainForm.resources" subtype="Code" buildaction="EmbedAsResource" dependson="" data="" /> - <File name=".\TugTable.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> - <File name=".\Config.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> - <File name=".\Config.xml" subtype="Code" buildaction="Nothing" dependson="" data="" /> - <File name=".\Util.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> - <File name=".\CSV.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> - <File name=".\table.txt" subtype="Code" buildaction="Nothing" dependson="" data="" /> - </Contents> - <References /> - <DeploymentInformation target="" script="" strategy="File" /> - <Configuration runwithwarnings="True" name="Release"> - <CodeGeneration runtime="MsNet" compiler="Csc" compilerversion="" warninglevel="4" nowarn="" includedebuginformation="False" optimize="True" unsafecodeallowed="False" generateoverflowchecks="False" mainclass="" target="WinExe" definesymbols="" generatexmldocumentation="False" win32Icon="" /> - <Execution commandlineparameters="" consolepause="False" /> - <Output directory="..\bin\Release" assembly="TLReader" executeScript="" executeBeforeBuild="" executeAfterBuild="" /> - </Configuration> - <Configurations active="Release"> - <Configuration runwithwarnings="False" name="Debug"> - <CodeGeneration runtime="MsNet" compiler="Csc" compilerversion="" warninglevel="4" nowarn="" includedebuginformation="True" optimize="False" unsafecodeallowed="False" generateoverflowchecks="True" mainclass="" target="WinExe" definesymbols="" generatexmldocumentation="False" win32Icon="" /> - <Execution commandlineparameters="" consolepause="False" /> - <Output directory="..\bin\Debug" assembly="TLReader" executeScript="" executeBeforeBuild="" executeAfterBuild="" /> - </Configuration> - <Configuration runwithwarnings="True" name="Release"> - <CodeGeneration runtime="MsNet" compiler="Csc" compilerversion="" warninglevel="4" nowarn="" includedebuginformation="False" optimize="True" unsafecodeallowed="False" generateoverflowchecks="False" mainclass="" target="WinExe" definesymbols="" generatexmldocumentation="False" win32Icon="" /> - <Execution commandlineparameters="" consolepause="False" /> - <Output directory="..\bin\Release" assembly="TLReader" executeScript="" executeBeforeBuild="" executeAfterBuild="" /> - </Configuration> - </Configurations> +<Project name="TLReader" standardNamespace="TLReader" description="" newfilesearch="None" enableviewstate="True" version="1.1" projecttype="C#">
+ <Contents>
+ <File name=".\MainForm.cs" subtype="Code" buildaction="Compile" dependson="" data="" />
+ <File name=".\AssemblyInfo.cs" subtype="Code" buildaction="Compile" dependson="" data="" />
+ <File name=".\DefaultNamespace.MainForm.resources" subtype="Code" buildaction="EmbedAsResource" dependson="" data="" />
+ <File name=".\TLReader.MainForm.resources" subtype="Code" buildaction="EmbedAsResource" dependson="" data="" />
+ <File name=".\Config.cs" subtype="Code" buildaction="Compile" dependson="" data="" />
+ <File name=".\Config.xml" subtype="Code" buildaction="Nothing" dependson="" data="" />
+ <File name=".\Util.cs" subtype="Code" buildaction="Compile" dependson="" data="" />
+ <File name=".\CSV.cs" subtype="Code" buildaction="Compile" dependson="" data="" />
+ <File name=".\table.txt" subtype="Code" buildaction="Nothing" dependson="" data="" />
+ <File name=".\Query.cs" subtype="Code" buildaction="Compile" dependson="" data="" />
+ <File name=".\About.cs" subtype="Code" buildaction="Compile" dependson="" data="" />
+ <File name=".\FavToHTML.About.resources" subtype="Code" buildaction="EmbedAsResource" dependson="" data="" />
+ </Contents>
+ <References />
+ <DeploymentInformation target="" script="" strategy="File" />
+ <Configuration runwithwarnings="True" name="Release">
+ <CodeGeneration runtime="MsNet" compiler="Csc" compilerversion="" warninglevel="4" nowarn="" includedebuginformation="False" optimize="True" unsafecodeallowed="False" generateoverflowchecks="False" mainclass="" target="WinExe" definesymbols="" generatexmldocumentation="False" win32Icon="" />
+ <Execution commandlineparameters="" consolepause="False" />
+ <Output directory="..\bin\Release" assembly="TLReader" executeScript="" executeBeforeBuild="" executeAfterBuild="" />
+ </Configuration>
+ <Configurations active="Release">
+ <Configuration runwithwarnings="False" name="Debug">
+ <CodeGeneration runtime="MsNet" compiler="Csc" compilerversion="" warninglevel="4" nowarn="" includedebuginformation="True" optimize="False" unsafecodeallowed="False" generateoverflowchecks="True" mainclass="" target="WinExe" definesymbols="" generatexmldocumentation="False" win32Icon="" />
+ <Execution commandlineparameters="" consolepause="False" />
+ <Output directory="..\bin\Debug" assembly="TLReader" executeScript="" executeBeforeBuild="" executeAfterBuild="" />
+ </Configuration>
+ <Configuration runwithwarnings="True" name="Release">
+ <CodeGeneration runtime="MsNet" compiler="Csc" compilerversion="" warninglevel="4" nowarn="" includedebuginformation="False" optimize="True" unsafecodeallowed="False" generateoverflowchecks="False" mainclass="" target="WinExe" definesymbols="" generatexmldocumentation="False" win32Icon="" />
+ <Execution commandlineparameters="" consolepause="False" />
+ <Output directory="..\bin\Release" assembly="TLReader" executeScript="" executeBeforeBuild="" executeAfterBuild="" />
+ </Configuration>
+ </Configurations>
</Project>
\ No newline at end of file @@ -1,40 +1,58 @@ -// TLReader - reads access database containing tug info -// Copyright (C) 2004 Ian Cowburn -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// -using System; -using System.Windows.Forms; - -namespace TLReader -{ - /// <summary> - /// Description of Util. - /// </summary> - public class Util - { - public static void Error(string msg) - { - MessageBox.Show(msg,"Error", - MessageBoxButtons.OK,MessageBoxIcon.Error); - } - - public static void Notice(string msg) - { - MessageBox.Show(msg,"Notice", - MessageBoxButtons.OK,MessageBoxIcon.Information); - } - } -} +// TLReader - reads access database containing tug info
+// Copyright (C) 2004 Ian Cowburn
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+using System;
+using System.Windows.Forms;
+
+namespace TLReader
+{
+ /// <summary>
+ /// Description of Util.
+ /// </summary>
+ public class Util
+ {
+ public static void Error(string msg)
+ {
+ MessageBox.Show(msg,"Error",
+ MessageBoxButtons.OK,MessageBoxIcon.Error);
+ }
+
+ public static void Notice(string msg)
+ {
+ MessageBox.Show(msg,"Notice",
+ MessageBoxButtons.OK,MessageBoxIcon.Information);
+ }
+
+ public static string NewLineToSpace(string s)
+ {
+ s=s.Replace("\r\n"," ");
+ s=s.Replace("\n\r"," ");
+ s=s.Replace('\n',' ');
+
+ return s;
+ }
+
+ public static string RemoveNewLine(string s)
+ {
+ s=s.Replace("\r\n","");
+ s=s.Replace("\n\r","");
+ s=s.Replace("\n","");
+
+ return s;
+ }
+ }
+}
|