Esempio n. 1
0
        // starting the day includes starting logging
        // if there is no csv writer then you can select or create one
        // it will also prompt you if you want to enable emails for OTRS
        private void LoggingButton_Click(object sender, RoutedEventArgs e)
        {
            // If logging is NOT on
            if (!_main_window.Logging)
            {
                // create a csv writer if it does not exist. when you have to restart the program or it closes
                // can select the already created log and continue writing to it for the week
                if (_main_window.IsCsvNull())
                {
                    System.Windows.MessageBox.Show("Select a csv file to log to.", "Notice");
                    OpenFileDialog fd = new OpenFileDialog();
                    fd.Multiselect = false;
                    fd.Filter      = "CSV Files (*.csv)|*.csv";
                    DialogResult res = fd.ShowDialog();
                    if (System.Windows.Forms.DialogResult.OK == res)
                    {
                        _main_window.CreateLog(fd.FileName, FileMode.Append);
                        _main_window.LogPath = Path.GetDirectoryName(fd.FileName); // update logging directory
                        //DirectoryTextBlock.Text = _main_window.LogPath;
                    }
                    else // user did not select a file to log to
                    {
                        var create = System.Windows.MessageBox.Show("No file selected. Create a new log?", "No Log Selected", MessageBoxButton.YesNo);
                        if (create == MessageBoxResult.Yes)
                        { // create a log
                            _main_window.CreateLog("Week_of_" + DateTime.Now.ToString("MM-dd-yyyy"), FileMode.Create);
                        }
                        else
                        { // if user says no to creating a log then don't start logging
                            System.Windows.MessageBox.Show("No file selected or created. Not starting log", "Notice");
                            return;
                        }
                    }
                }

                _main_window.StartLog(); //! this defaults to setting Logging to true and EmailLogging to true

                // ask if want to enable emails
                //var result = System.Windows.Forms.MessageBox.Show("Would you like to enable emails?", "Email", MessageBoxButtons.YesNo);
                //if (result == System.Windows.Forms.DialogResult.Yes)
                //{
                //    _main_window.EmailLogging = false; // set to false before calling next function so it can execute correctly and enable EmailLogging
                //}
                //emailButton_Click(new object(), new RoutedEventArgs()); //!! this will set main windows EmailLogging accordingly

                //MessageWindow mw = new MessageWindow("Start New day \n" + DateTime.Now.ToString("MM-dd-yyyy"), 3.0);
                // mw.Show();
                LogGoingTextBlock.Text = "Logging: Yes";
                LoggingButton.Content  = "Disable Logging";
            }

            // Logging IS already on
            else
            {
                _main_window.EndLog();
                LogGoingTextBlock.Text = "Logging: No";
                LoggingButton.Content  = "Enable Logging";
            }
        }