|
using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using System.Data;
using System.Text;
using System.Xml;
using Microsoft.WindowsCE.Forms;
using System.Net.Sockets;
using System.Threading;
using System.ComponentModel;
namespace CF_Proj_Mgr
{
/// <summary>
/// This is the main form in the project. The form consists of a listbox and a
/// readonly edit box. There are also some labels for displaying information
/// about the currently selected project.
/// </summary>
public class MainForm : System.Windows.Forms.Form
{
public Microsoft.WindowsCE.Forms.InputPanel inputPanel1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.ListBox listOfProjects;
private System.Windows.Forms.MenuItem menuSave;
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.ContextMenu prjContextMenu;
private System.Windows.Forms.MenuItem editMenuItem;
private System.Windows.Forms.MenuItem delMenuItem;
private System.Windows.Forms.Label prjUpdateDate;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label prjCompany;
private System.Windows.Forms.TextBox prjUpdate;
private System.Windows.Forms.MenuItem menuItem4;
private System.Windows.Forms.MenuItem menuNew;
private System.Windows.Forms.MenuItem menuEdit;
private System.Windows.Forms.MenuItem menuDelete;
private System.Windows.Forms.MenuItem menuReLoad;
private System.Windows.Forms.Label prjSalesGuy;
private System.Windows.Forms.MenuItem prjCntxtMnuSendIR;
private static ArrayList myProjects;
private Thread thServ;
private System.Windows.Forms.MenuItem menuItem2;
private System.Windows.Forms.MenuItem menuItem3;
private System.Windows.Forms.MenuItem aboutMnuItem;
private System.Windows.Forms.MenuItem menuItem6;
private FileIO fio;
public MainForm()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
inputPanel1 = new InputPanel();
myProjects = new ArrayList();
fio = new FileIO();
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(MainForm));
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuNew = new System.Windows.Forms.MenuItem();
this.menuEdit = new System.Windows.Forms.MenuItem();
this.menuDelete = new System.Windows.Forms.MenuItem();
this.menuItem4 = new System.Windows.Forms.MenuItem();
this.menuSave = new System.Windows.Forms.MenuItem();
this.menuReLoad = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.menuItem3 = new System.Windows.Forms.MenuItem();
this.listOfProjects = new System.Windows.Forms.ListBox();
this.prjContextMenu = new System.Windows.Forms.ContextMenu();
this.editMenuItem = new System.Windows.Forms.MenuItem();
this.delMenuItem = new System.Windows.Forms.MenuItem();
this.prjCntxtMnuSendIR = new System.Windows.Forms.MenuItem();
this.prjUpdateDate = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.prjCompany = new System.Windows.Forms.Label();
this.prjUpdate = new System.Windows.Forms.TextBox();
this.prjSalesGuy = new System.Windows.Forms.Label();
this.aboutMnuItem = new System.Windows.Forms.MenuItem();
this.menuItem6 = new System.Windows.Forms.MenuItem();
//
// mainMenu1
//
this.mainMenu1.MenuItems.Add(this.menuItem1);
//
// menuItem1
//
this.menuItem1.MenuItems.Add(this.aboutMnuItem);
this.menuItem1.MenuItems.Add(this.menuItem6);
this.menuItem1.MenuItems.Add(this.menuNew);
this.menuItem1.MenuItems.Add(this.menuEdit);
this.menuItem1.MenuItems.Add(this.menuDelete);
this.menuItem1.MenuItems.Add(this.menuItem4);
this.menuItem1.MenuItems.Add(this.menuSave);
this.menuItem1.MenuItems.Add(this.menuReLoad);
this.menuItem1.MenuItems.Add(this.menuItem2);
this.menuItem1.MenuItems.Add(this.menuItem3);
this.menuItem1.Text = "Projects";
this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click);
//
// menuNew
//
this.menuNew.Text = "New";
this.menuNew.Click += new System.EventHandler(this.menuItemNew_Click);
//
// menuEdit
//
this.menuEdit.Text = "Edit";
//
// menuDelete
//
this.menuDelete.Text = "Delete";
//
// menuItem4
//
this.menuItem4.Text = "-";
//
// menuSave
//
this.menuSave.Text = "Save";
this.menuSave.Click += new System.EventHandler(this.menuSave_Click);
//
// menuReLoad
//
this.menuReLoad.Text = "ReLoad";
this.menuReLoad.Click += new System.EventHandler(this.menuReLoad_Click);
//
// menuItem2
//
this.menuItem2.Text = "-";
//
// menuItem3
//
this.menuItem3.Text = "Exit";
this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click);
//
// listOfProjects
//
this.listOfProjects.ContextMenu = this.prjContextMenu;
this.listOfProjects.Size = new System.Drawing.Size(240, 128);
this.listOfProjects.SelectedIndexChanged += new System.EventHandler(this.SelectedIndexChanged);
//
// prjContextMenu
//
this.prjContextMenu.MenuItems.Add(this.editMenuItem);
this.prjContextMenu.MenuItems.Add(this.delMenuItem);
this.prjContextMenu.MenuItems.Add(this.prjCntxtMnuSendIR);
//
// editMenuItem
//
this.editMenuItem.Text = "Edit";
this.editMenuItem.Click += new System.EventHandler(this.editMenuItem_Click);
//
// delMenuItem
//
this.delMenuItem.Text = "Delete";
this.delMenuItem.Click += new System.EventHandler(this.delMenuItem_Click);
//
// prjCntxtMnuSendIR
//
this.prjCntxtMnuSendIR.Text = "Send Via IR";
this.prjCntxtMnuSendIR.Click += new System.EventHandler(this.prjCntxtMnuSendIR_Click);
//
// prjUpdateDate
//
this.prjUpdateDate.Location = new System.Drawing.Point(32, 152);
this.prjUpdateDate.Size = new System.Drawing.Size(200, 16);
//
// label3
//
this.label3.Location = new System.Drawing.Point(8, 136);
this.label3.Size = new System.Drawing.Size(24, 16);
this.label3.Text = "Co.";
//
// prjCompany
//
this.prjCompany.Location = new System.Drawing.Point(32, 136);
this.prjCompany.Size = new System.Drawing.Size(200, 16);
//
// prjUpdate
//
this.prjUpdate.AcceptsReturn = true;
this.prjUpdate.Location = new System.Drawing.Point(0, 200);
this.prjUpdate.Multiline = true;
this.prjUpdate.ReadOnly = true;
this.prjUpdate.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.prjUpdate.Size = new System.Drawing.Size(240, 72);
this.prjUpdate.Text = "";
//
// prjSalesGuy
//
this.prjSalesGuy.Location = new System.Drawing.Point(32, 168);
this.prjSalesGuy.Size = new System.Drawing.Size(200, 16);
//
// aboutMnuItem
//
this.aboutMnuItem.Text = "About";
this.aboutMnuItem.Click += new System.EventHandler(this.aboutMnuItem_Click);
//
// menuItem6
//
this.menuItem6.Text = "-";
//
// MainForm
//
this.Controls.Add(this.prjSalesGuy);
this.Controls.Add(this.prjUpdate);
this.Controls.Add(this.prjCompany);
this.Controls.Add(this.label3);
this.Controls.Add(this.prjUpdateDate);
this.Controls.Add(this.listOfProjects);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Menu = this.mainMenu1;
this.Text = "CF Project Manager";
this.Closing += new System.ComponentModel.CancelEventHandler(this.FormClosing);
this.GotFocus += new System.EventHandler(this.MainForm_GotFocus);
this.Load += new System.EventHandler(this.MainForm_FormLoad);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main()
{
Application.Run(new MainForm());
}
private void menuItemNew_Click(object sender, System.EventArgs e)
{
project pr = new project();
ProjectDlg p = new ProjectDlg( pr );
if ( p.ShowDialog()== DialogResult.OK )
{
listOfProjects.Items.Add( p.Name.Text );
// transfer data from dialog
pr.Name = p.Name.Text;
pr.Description = p.Description.Text;
pr.Resource = p.Manager.Text;
myProjects.Add( pr);
inputPanel1.Enabled = false;
}
}
private void menuSave_Click(object sender, System.EventArgs e)
{
(new FileIO()).SaveFile( "\\My Documents\\Projects.xml", myProjects );
}
private void menuItem1_Click(object sender, System.EventArgs e)
{
}
private void MainForm_GotFocus(object sender, System.EventArgs e)
{
// inputPanel1.Enabled = false;
}
private void MainForm_FormLoad(object sender, System.EventArgs e)
{
// variable to set running to true
fio.isRunning = true;
// create and start the thread
this.thServ = new Thread (new ThreadStart(fio.SrvRoutine));
this.thServ.Start();
// load the file we want to edit
menuReLoad_Click( sender, e);
}
private void delMenuItem_Click(object sender, System.EventArgs e)
{
string toDelete;
toDelete = listOfProjects.SelectedItem.ToString();
if ( MessageBox.Show("Really Delete?",toDelete,MessageBoxButtons.YesNo,MessageBoxIcon.Question,MessageBoxDefaultButton.Button1 ) == DialogResult.Yes )
{
foreach ( project p in myProjects )
{
if ( p.Name == toDelete )
{
listOfProjects.Items.Remove(p.Name);
myProjects.Remove(p);
break;
}
}
listOfProjects.Refresh();
}
}
private void editMenuItem_Click(object sender, System.EventArgs e)
{
project pr = new project();
ProjectDlg pd;
foreach ( project p in myProjects )
{
if ( p.Name == listOfProjects.SelectedItem.ToString() )
{
listOfProjects.Items.Remove(p.Name);
pd = new ProjectDlg(p);
pd.ShowDialog();
listOfProjects.Items.Add(p.Name);
listOfProjects.Refresh();
inputPanel1.Enabled = false;
listOfProjectsReSort();
break;
}
}
}
private void SelectedIndexChanged(object sender, System.EventArgs e)
{
foreach ( project p in myProjects )
{
if ( p.Name == listOfProjects.SelectedItem.ToString() )
{
prjCompany.Text = p.Customer.Name;
prjUpdateDate.Text = p.Customer.Contact + " " + p.Customer.Phone;
prjUpdate.Text = p.GetDescriptionAndNotes();
//p.GetAllNotes(); //p.GetLatestNote();
prjSalesGuy.Text = p.SalesGuy;
break;
}
}
}
public void listOfProjectsReSort()
{
listOfProjects.Items.Clear();
myProjects.Sort( new ProjectComparer( SortDirection.Ascending) );
foreach( project p in myProjects )
{
listOfProjects.Items.Add( p.Name );
}
listOfProjects.Refresh();
}
private void menuReLoad_Click(object sender, System.EventArgs e)
{
myProjects.RemoveRange( 0, myProjects.Count );
(new FileIO()).LoadFile("\\My Documents\\Projects.xml", myProjects);
listOfProjectsReSort();
}
private void prjCntxtMnuSendIR_Click(object sender, System.EventArgs e)
{
// find the appropriate project
foreach ( project p in myProjects )
{
if ( p.Name == listOfProjects.SelectedItem.ToString() )
{
ArrayList al = new ArrayList(1);
al.Add( p );
// create a file with a single record
fio.SaveFile("\\tmpIRPrjs.txt", al);
break;
}
}
// send the file
fio.SendFileToIR("\\tmpIRPrjs.txt");
}
public static void AddProject( project p )
{
bool foundOne = false;
project projToDel = null;
// find the appropriate project
foreach ( project myP in myProjects )
{
if ( myP.Name == p.Name )
{
foundOne = true;
projToDel = myP;
break;
}
}
if ( foundOne )
{
if ( MessageBox.Show("Replace?",projToDel.Name,MessageBoxButtons.YesNo,MessageBoxIcon.Question,MessageBoxDefaultButton.Button1 ) == DialogResult.Yes )
{
myProjects.Remove(projToDel);
myProjects.Add(p);
}
}
else
myProjects.Add(p);
}
private void menuItem3_Click(object sender, System.EventArgs e)
{
this.Close();
}
private void FormClosing(object sender, System.ComponentModel.CancelEventArgs e)
{
fio.isRunning = false;
Thread.Sleep(550);
}
private void aboutMnuItem_Click(object sender, System.EventArgs e)
{
AboutDlg ad = new AboutDlg();
ad.ShowDialog();
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.