📄 mainform.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using MSProject = Microsoft.Office.Interop.MSProject;
namespace PrjXlsRpt
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class MainForm : System.Windows.Forms.Form
{
private const string FILTER_PROJECT = "Microsoft Project (*.mpp)|*.mpp|All Files (*.*)|*.*";
private const string FILTER_EXCEL = "Excel XML (*.xml)|*.xml|All Files (*.*)|*.*";
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox projectFileName;
private System.Windows.Forms.Button browseProject;
private System.Windows.Forms.Button browseExcel;
private System.Windows.Forms.TextBox excelFileName;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Button execute;
private System.Windows.Forms.Button exit;
private System.Windows.Forms.Label revision;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.DateTimePicker dateTimePicker;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public MainForm()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
Text = Application.ProductName;
revision.Text = "Ver: " + Application.ProductVersion;
dateTimePicker.Value = System.DateTime.Now;
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
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()
{
this.label1 = new System.Windows.Forms.Label();
this.projectFileName = new System.Windows.Forms.TextBox();
this.browseProject = new System.Windows.Forms.Button();
this.browseExcel = new System.Windows.Forms.Button();
this.excelFileName = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.execute = new System.Windows.Forms.Button();
this.exit = new System.Windows.Forms.Button();
this.revision = new System.Windows.Forms.Label();
this.dateTimePicker = new System.Windows.Forms.DateTimePicker();
this.label3 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// label1
//
this.label1.Location = new System.Drawing.Point(8, 8);
this.label1.Name = "label1";
this.label1.TabIndex = 0;
this.label1.Text = "Project File Name:";
//
// projectFileName
//
this.projectFileName.Location = new System.Drawing.Point(8, 32);
this.projectFileName.Name = "projectFileName";
this.projectFileName.Size = new System.Drawing.Size(520, 20);
this.projectFileName.TabIndex = 0;
this.projectFileName.Text = "";
//
// browseProject
//
this.browseProject.Location = new System.Drawing.Point(536, 32);
this.browseProject.Name = "browseProject";
this.browseProject.Size = new System.Drawing.Size(32, 23);
this.browseProject.TabIndex = 1;
this.browseProject.Text = "...";
this.browseProject.Click += new System.EventHandler(this.browseProject_Click);
//
// browseExcel
//
this.browseExcel.Location = new System.Drawing.Point(537, 88);
this.browseExcel.Name = "browseExcel";
this.browseExcel.Size = new System.Drawing.Size(32, 23);
this.browseExcel.TabIndex = 3;
this.browseExcel.Text = "...";
this.browseExcel.Click += new System.EventHandler(this.browseExcel_Click);
//
// excelFileName
//
this.excelFileName.Location = new System.Drawing.Point(9, 88);
this.excelFileName.Name = "excelFileName";
this.excelFileName.Size = new System.Drawing.Size(520, 20);
this.excelFileName.TabIndex = 2;
this.excelFileName.Text = "";
//
// label2
//
this.label2.Location = new System.Drawing.Point(9, 64);
this.label2.Name = "label2";
this.label2.TabIndex = 3;
this.label2.Text = "Excel File Name:";
//
// execute
//
this.execute.Location = new System.Drawing.Point(416, 200);
this.execute.Name = "execute";
this.execute.TabIndex = 5;
this.execute.Text = "Execute";
this.execute.Click += new System.EventHandler(this.execute_Click);
//
// exit
//
this.exit.Location = new System.Drawing.Point(496, 200);
this.exit.Name = "exit";
this.exit.TabIndex = 6;
this.exit.Text = "Exit";
this.exit.Click += new System.EventHandler(this.exit_Click);
//
// revision
//
this.revision.Location = new System.Drawing.Point(8, 200);
this.revision.Name = "revision";
this.revision.Size = new System.Drawing.Size(160, 23);
this.revision.TabIndex = 8;
this.revision.Text = "revision";
//
// dateTimePicker
//
this.dateTimePicker.Location = new System.Drawing.Point(112, 128);
this.dateTimePicker.Name = "dateTimePicker";
this.dateTimePicker.TabIndex = 4;
//
// label3
//
this.label3.Location = new System.Drawing.Point(8, 128);
this.label3.Name = "label3";
this.label3.TabIndex = 10;
this.label3.Text = "Evaluation Date:";
//
// MainForm
//
this.AcceptButton = this.execute;
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(578, 232);
this.Controls.Add(this.label3);
this.Controls.Add(this.dateTimePicker);
this.Controls.Add(this.revision);
this.Controls.Add(this.exit);
this.Controls.Add(this.execute);
this.Controls.Add(this.browseExcel);
this.Controls.Add(this.excelFileName);
this.Controls.Add(this.projectFileName);
this.Controls.Add(this.label2);
this.Controls.Add(this.browseProject);
this.Controls.Add(this.label1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.Name = "MainForm";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new MainForm());
}
private void browseProject_Click(object sender, System.EventArgs e) {
OpenFileDialog dlg = new OpenFileDialog();
dlg.Filter = FILTER_PROJECT;
if(projectFileName.Text.Length > 0) {
dlg.FileName = projectFileName.Text;
}
if(dlg.ShowDialog() == DialogResult.Cancel) {
return;
}
projectFileName.Text = dlg.FileName;
}
private void browseExcel_Click(object sender, System.EventArgs e) {
SaveFileDialog dlg = new SaveFileDialog();
dlg.Filter = FILTER_EXCEL;
if(excelFileName.Text.Length > 0) {
dlg.FileName = excelFileName.Text;
}
if(dlg.ShowDialog() == DialogResult.Cancel) {
return;
}
excelFileName.Text = dlg.FileName;
}
private void execute_Click(object sender, System.EventArgs e) {
if(projectFileName.Text.Length == 0) {
MessageBox.Show("You need to specify a project file.", Text);
return;
}
if(excelFileName.Text.Length == 0) {
MessageBox.Show("You need to specify an excel file to save the data to.", Text);
return;
}
Cursor = Cursors.WaitCursor;
Project project = new Project();
string err = project.Load(projectFileName.Text);
if(err.Length > 0) {
MessageBox.Show(err, "Error");
Cursor = Cursors.Default;
return;
}
project.EvaluateTasks(dateTimePicker.Value, 6, 6);
err = project.Save(excelFileName.Text);
if(err.Length > 0) {
MessageBox.Show(err, "Error");
Cursor = Cursors.Default;
return;
}
MessageBox.Show("Operation complete.", Text);
Cursor = Cursors.Default;
}
private void exit_Click(object sender, System.EventArgs e) {
Application.Exit();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -