using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using Excel = Microsoft.Office.Interop.Excel;
using Microsoft.Office.Interop.Excel;
using System.Runtime.ExceptionServices;
namespace Navigations_delivery_report
{
public partial class Form1 : Form
{
Excel.Application xlap = new Excel.Application();
public Form1()
{
InitializeComponent();
textBox1.Text = Environment.UserName;
}
private void label1_Click(object sender, EventArgs e)
{
}
private void label5_Click(object sender, EventArgs e)
{ }
private void textBox1_TextChanged(object sender, EventArgs e)
{ }
private void button1_Click(object sender, EventArgs e)
{
string result = "Please Enter ";
if (textBox1.Text == string.Empty)
{
result += " Name,";
}
if (textBox2.Text == string.Empty)
{
result += " CallSign,";
}
if (textBox3.Text == string.Empty)
{
result += " Departure,";
}
if (textBox4.Text == string.Empty)
{
result += " Arrival,";
}
if (textBox5.Text == string.Empty)
{
result += " Fuel,";
}
if (textBox6.Text == string.Empty)
{
result += " Cost,";
}
if (textBox7.Text == string.Empty)
{
result += " Time,";
}
if (comboBox1.SelectedItem == null)
{
result += " Type Of Route,";
}
if (comboBox2.SelectedItem == null)
{
result += " Route Method,";
}
if (checkBox1.Checked == false)
{
result += " Confirm OFP Matches ATC Plan,";
}
else
{
if (result.Contains(','))
{
result = result.Remove(result.LastIndexOf(','));
}
}
if (result != "Please Enter ")
{
MessageBox.Show(result);
}
else
{
Excel.Workbook xlworkbook;
Excel.Worksheet xlworksheet;
object misValue = System.Reflection.Missing.Value;
xlworkbook = xlap.Workbooks.Add(misValue);
xlworksheet = (Excel.Worksheet)xlworkbook.Worksheets.get_Item(1);
xlworksheet.Cells[1, 1] = textBox1.Text;
xlworksheet.Cells[1, 2] = dateTimePicker1.Value;
xlworksheet.Cells[1, 3] = textBox2.Text;
xlworksheet.Cells[1, 4] = textBox3.Text;
xlworksheet.Cells[1, 5] = textBox4.Text;
xlworksheet.Cells[1, 6] = textBox5.Text;
xlworksheet.Cells[1, 7] = textBox6.Text;
xlworksheet.Cells[1, 8] = textBox7.Text;
xlworksheet.Cells[1, 9] = textBox8.Text;
xlworksheet.Cells[1, 10] = textBox9.Text;
xlworksheet.Cells[1, 11] = comboBox1.Text;
xlworksheet.Cells[1, 12] = comboBox2.Text;
xlworkbook.SaveAs(@"C:\demo\savings_" + DateTime.Now.ToString("yyyyMMdd_hmmss") + ".csv");
xlworkbook.Close(true);
xlap.Quit();
textBox2.Clear();
textBox3.Clear();
textBox4.Clear();
textBox5.Clear();
textBox6.Clear();
textBox7.Clear();
comboBox1.SelectedIndex = -1;
comboBox2.SelectedIndex = -1;
checkBox1.Checked = false;
textBox2.Focus();
}
}
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
Close();
}
public void Button3_Click(object sender, EventArgs e)
{
textBox2.Clear();
textBox3.Clear();
textBox4.Clear();
textBox5.Clear();
textBox6.Clear();
textBox7.Clear();
comboBox1.SelectedIndex = -1;
comboBox2.SelectedIndex = -1;
checkBox1.Checked = false;
textBox2.Focus();
}
private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{
dateTimePicker1.CustomFormat = "yyyy-mm-dd";
}
private void textBox8_TextChanged(object sender, EventArgs e)
{
}
private void textBox9_TextChanged(object sender, EventArgs e)
{
}
private void button4_Click(object sender, EventArgs e)
{
}
private void textBox6_TextChanged(object sender, EventArgs e)
{
}
private void textBox5_TextChanged(object sender, EventArgs e)
{
}
}
}