Пример #1
0
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            // Get input data, parse date and time
            var date          = DateTime.Parse(txtBoxDate.Text).ToString("yyyy-MM-dd");
            var time          = DateTime.Parse(txtBoxTime.Text).ToString("HH:mm:ss");
            var startingPoint = txtBoxStartingPoint.Text;
            var destination   = txtBoxDestination.Text;
            var purpose       = "";

            if (btnBusiness.IsChecked == true)
            {
                purpose = "Business";
            }
            else if (btnPersonal.IsChecked == true)
            {
                purpose = "Personal";
            }
            var purposeDetails = txtBoxTripDetails.Text;
            var totalDistance  = Convert.ToDouble(txtBoxTotalDistance.Text);

            // Create a new mileage log entry
            var mileageLog = new MileageLog {
                Date = date, StartTime = time, StartingPoint = startingPoint, Destination = destination, Purpose = purpose, PurposeDetails = purposeDetails, TotalDistance = totalDistance
            };

            db.MileageLogs.Add(mileageLog);
            db.SaveChanges();

            // Close modal window
            mdDialog1.IsOpen = false;

            // Refresh list
            Refresh();
        }
Пример #2
0
        /*
         * Method Name: btnEdit_Click
         * Description:
         * Parameters: object sender, RoutedEventArgs e
         * Returns: none
         */
        private void btnEdit_Click(object sender, RoutedEventArgs e)
        {
            var row = (DataGridRow)dataGridMileageLogs.ItemContainerGenerator.ContainerFromItem(dataGridMileageLogs.CurrentCell.Item);

            // selectedRow
            MileageLog selectedRow = (MileageLog)row.Item;

            var query = from m in db.MileageLogs
                        where m.Id == selectedRow.Id
                        select m;

            logEntryToEdit = query.FirstOrDefault();

            txtBoxEditDate.Text          = DateTime.Parse(logEntryToEdit.Date).ToString("MMM d, yyyy");
            txtBoxEditTime.Text          = DateTime.Parse(logEntryToEdit.StartTime).ToString("t");
            txtBoxEditStartingPoint.Text = logEntryToEdit.StartingPoint;
            txtBoxEditDestination.Text   = logEntryToEdit.Destination;
            var purpose = logEntryToEdit.Purpose;

            if (purpose == "Business")
            {
                btnEditBusiness.IsChecked = true;
            }
            else if (purpose == "Personal")
            {
                btnEditPersonal.IsChecked = true;
            }
            txtBoxEditTripDetails.Text   = logEntryToEdit.PurposeDetails;
            txtBoxEditTotalDistance.Text = logEntryToEdit.TotalDistance.ToString();
        }
Пример #3
0
        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            MileageLog selectedLog = (MileageLog)dataGridMileageLogs.SelectedItem;
            var        query       = from m in db.MileageLogs
                                     where m.Id == selectedLog.Id
                                     select m;

            var logToDelete = query.FirstOrDefault();

            db.MileageLogs.Remove(logToDelete);
            db.SaveChanges();

            // Refresh list
            Refresh();
        }
Пример #4
0
        private void ExportWord()
        {
            // Set file path
            string fileName  = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            string extension = ".docx";

            fileName += @"\example" + extension;

            // Create file
            var doc = DocX.Create(fileName);

            // Set the document margins
            doc.MarginLeft   = 40f;
            doc.MarginRight  = 40f;
            doc.MarginTop    = 40;
            doc.MarginBottom = 40f;

            // Create Table with rows and columns
            Xceed.Words.NET.Table t = doc.AddTable(dataGridMileageLogs.Items.Count + 1, 7);
            t.Alignment = Alignment.center;
            t.Design    = TableDesign.TableGrid;

            // Set the header colours
            t.Rows[0].Cells[0].FillColor = System.Drawing.Color.LightGray;
            t.Rows[0].Cells[1].FillColor = System.Drawing.Color.LightGray;
            t.Rows[0].Cells[2].FillColor = System.Drawing.Color.LightGray;
            t.Rows[0].Cells[3].FillColor = System.Drawing.Color.LightGray;
            t.Rows[0].Cells[4].FillColor = System.Drawing.Color.LightGray;
            t.Rows[0].Cells[5].FillColor = System.Drawing.Color.LightGray;
            t.Rows[0].Cells[6].FillColor = System.Drawing.Color.LightGray;

            Formatting boldFormatting = new Formatting();

            boldFormatting.Bold = true;

            // Set the header titles
            t.Rows[0].Cells[0].Paragraphs.First().Append("Date", boldFormatting);
            t.Rows[0].Cells[1].Paragraphs.First().Append("Start Time", boldFormatting);
            t.Rows[0].Cells[2].Paragraphs.First().Append("Starting Point", boldFormatting);
            t.Rows[0].Cells[3].Paragraphs.First().Append("Destination", boldFormatting);
            t.Rows[0].Cells[4].Paragraphs.First().Append("Classification", boldFormatting);
            t.Rows[0].Cells[5].Paragraphs.First().Append("Details", boldFormatting);
            t.Rows[0].Cells[6].Paragraphs.First().Append("Total Kilometres Driven", boldFormatting);

            int count = 0;

            var itemsSource = dataGridMileageLogs.ItemsSource;

            if (itemsSource != null)
            {
                foreach (var item in itemsSource)
                {
                    var row = dataGridMileageLogs.ItemContainerGenerator.ContainerFromItem(item) as DataGridRow;
                    if (row != null)
                    {
                        count++;
                        MileageLog logEntry = (MileageLog)row.Item;
                        t.Rows[count].Cells[0].Paragraphs.First().Append(logEntry.Date);
                        t.Rows[count].Cells[1].Paragraphs.First().Append(logEntry.StartTime);
                        t.Rows[count].Cells[2].Paragraphs.First().Append(logEntry.StartingPoint);
                        t.Rows[count].Cells[3].Paragraphs.First().Append(logEntry.Destination);
                        t.Rows[count].Cells[4].Paragraphs.First().Append(logEntry.Purpose);
                        t.Rows[count].Cells[5].Paragraphs.First().Append(logEntry.PurposeDetails);
                        t.Rows[count].Cells[6].Paragraphs.First().Append(logEntry.TotalDistance.ToString("F"));
                    }
                }
            }

            // Insert Table
            doc.InsertTable(t);

            // Save document
            doc.Save();

            // Start Word
            Process.Start("WINWORD.EXE", fileName);
        }