Ejemplo n.º 1
0
        private void btnCalc_Click(object sender, EventArgs e)
        {
            if (rdbPartTime.Checked is false && rdbFulltime.Checked is false)
            {
                MessageBox.Show("You must choose the job's frequency.");
                return;
            }

            txtDailyW.Text = WorkActions.CalculateDay(workDays, rdbPartTime, dtpWork.Value).ToString();
            txtMonthW.Text = WorkActions.CalculateMonth(workDays, rdbPartTime, dtpWork.Value.Month, dtpWork.Value.Year).ToString();
            txtYearW.Text  = WorkActions.CalculateYear(workDays, rdbPartTime, dtpWork.Value.Year).ToString();
        }
Ejemplo n.º 2
0
        private void dtpWork_Leave(object sender, EventArgs e)
        {
            try
            {
                if (lsbData.Items.Count == 0)
                {
                    throw new Exception("No data.");
                }

                txtDailyW.Text = WorkActions.CalculateDay(workDays, rdbPartTime, dtpWork.Value).ToString();
                txtMonthW.Text = WorkActions.CalculateMonth(workDays, rdbPartTime, dtpWork.Value.Month, dtpWork.Value.Year).ToString();
                txtYearW.Text  = WorkActions.CalculateYear(workDays, rdbPartTime, dtpWork.Value.Year).ToString();
            }
            catch (Exception)
            {
                txtDailyW.Text = string.Empty;
            }
        }
Ejemplo n.º 3
0
        private void ExcelExport(List <WorkDay> workDaysList, int rowcount) // Exports the data table to excel.
        {
            var xlfile = new Microsoft.Office.Interop.Excel.Application {
                Visible = false
            };

            //Get a new workbook.
            var oWb    = (Microsoft.Office.Interop.Excel._Workbook)(xlfile.Workbooks.Add(Missing.Value));
            var oSheet = (Microsoft.Office.Interop.Excel._Worksheet)oWb.ActiveSheet;

            //Add table headers going cell by cell.

            oSheet.Cells[1, 1] = "EntryNumber";
            oSheet.Cells[1, 2] = "Date";
            oSheet.Cells[1, 3] = "Hours";
            oSheet.Cells[1, 4] = "Earned";

            for (int i = 0; i < rowcount - 1; i++) //Data from list to excel
            {
                oSheet.Cells[i + 2, 1] = i + 1;
                oSheet.Cells[i + 2, 2] = workDaysList[i].DateAndTime.ToShortDateString();
                oSheet.Cells[i + 2, 3] = workDaysList[i].Hours;
                oSheet.Cells[i + 2, 4] = WorkActions.LocalCalculate(workDaysList[i], rdbIsPart);
            }

            using (var savefd = new SaveFileDialog()) // for custom saving
            {
                savefd.Filter       = @"Microsoft Excel(*.xlsx)|*xlsx|Microsoft Excel 97-2003 Worksheet(*.xls)|*.xls|Excel macro-enabled workbook(*.xlsm)|*xlsm;";
                savefd.DefaultExt   = "xlsx";
                savefd.AddExtension = true;
                savefd.ShowDialog();
                var path = savefd.FileName;
                oWb.SaveAs(path);
                if (path == String.Empty)
                {
                    return;
                }
            }
            oWb.Close();
            Marshal.ReleaseComObject(oWb);
            Marshal.ReleaseComObject(oSheet);
            Marshal.ReleaseComObject(xlfile);
            MessageBox.Show("Success!", "Info", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
        }
Ejemplo n.º 4
0
        private void Export_Load(object sender, EventArgs e) // Previews the wage data in a table.
        {
            dsgExport.ColumnCount           = 4;
            dsgExport.ColumnHeadersVisible  = true;
            dsgExport.Columns[0].HeaderText = "Entry number";
            dsgExport.Columns[1].HeaderText = "Date";
            dsgExport.Columns[2].HeaderText = "Hours";
            dsgExport.Columns[3].HeaderText = "Money earned";

            for (int i = 0; i < lsbfromsource.Count; i++)
            {
                dsgExport.Rows.Add();
                dsgExport.Rows[i].Cells[0].Value = i + 1;
                dsgExport.Rows[i].Cells[1].Value = lsbfromsource.OfType <WorkDay>().ToArray()[i].DateAndTime.ToShortDateString();
                dsgExport.Rows[i].Cells[2].Value = lsbfromsource.OfType <WorkDay>().ToArray()[i].Hours;
                dsgExport.Rows[i].Cells[3].Value = WorkActions.LocalCalculate(lsbfromsource.OfType <WorkDay>().ToArray()[i], rdbIsPart);
            }

            dsgExport.ReadOnly = true;
        }
Ejemplo n.º 5
0
        private void btnDEL_Click(object sender, EventArgs e)
        {
            if (workDays.Capacity == 0)
            {
                MessageBox.Show("No days to delete.");
                return;
            }
            foreach (var day in workDays)
            {
                if (day.DateAndTime == dtpWork.Value)
                {
                    lsbData.Items.Remove(day);
                    workDays.Remove(day);
                    txtDailyW.Text = WorkActions.CalculateDay(workDays, rdbPartTime, dtpWork.Value).ToString();
                    txtMonthW.Text = WorkActions.CalculateMonth(workDays, rdbPartTime, dtpWork.Value.Month, dtpWork.Value.Year).ToString();
                    MessageBox.Show(@"Success!");
                    return;
                }
            }

            MessageBox.Show(@"Failure. Day doesn't exist on the list.");
        }
Ejemplo n.º 6
0
        //Exports the info to sender object in the form of a table.
        public void ExportInfo(object sender, RadioButton rdbDay, RadioButton rdbMonth, int rowcount)
        {
            if (MarkedStatus(rdblist) is false)
            {
                MessageBox.Show("Select export scope in order to continue.");
                return;
            }

            if (sender == btnExText) // txt file export.
            {
                if (rdbDay.Checked)  // Export for daily wage.
                {
                    try
                    {
                        var toworkdays = lsbfromsource.Cast <WorkDay>();
                        var filterDay  = toworkdays.First(d => d.DateAndTime.Date == dtpExportInfo.Value.Date);    //get fitting days
                        using (var savefd = new SaveFileDialog())
                        {
                            savefd.Filter       = @"Text files (*.txt)|*.txt";
                            savefd.DefaultExt   = "txt";
                            savefd.AddExtension = true;
                            savefd.ShowDialog();

                            var path = savefd.FileName;
                            var lsbDataStreamWriter = new StreamWriter(path, false);
                            lsbDataStreamWriter.WriteLine(filterDay + $" Wage earned: {WorkActions.LocalCalculate(filterDay, rdbIsPart)}");
                            MessageBox.Show("File saved successfully.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);

                            lsbDataStreamWriter.Close();
                            return;
                        }
                    }
                    catch (ArgumentException)
                    {
                    }
                    catch (Exception exception)
                    {
                        MessageBox.Show(exception.Message, @"Error", MessageBoxButtons.OK, MessageBoxIcon.None);
                    }
                }
                else if (rdbMonth.Checked)     // Export for monthly wage.
                {
                    try
                    {
                        var toworkdays   = lsbfromsource.Cast <WorkDay>();
                        var filteredList = toworkdays.Where(d => d.DateAndTime.Month == dtpExportInfo.Value.Month && d.DateAndTime.Year == dtpExportInfo.Value.Year);      //get fitting days
                        using (var savefd = new SaveFileDialog())
                        {
                            savefd.Filter       = @"Text files (*.txt)|*.txt";
                            savefd.DefaultExt   = "txt";
                            savefd.AddExtension = true;
                            savefd.ShowDialog();

                            var path = savefd.FileName;
                            var lsbDataStreamWriter = new StreamWriter(path, false);
                            foreach (var item in filteredList)
                            {
                                lsbDataStreamWriter.WriteLine((WorkDay)item + $" Wage earned: {WorkActions.LocalCalculate(item as WorkDay, rdbIsPart)}");
                                MessageBox.Show("File saved successfully.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }

                            lsbDataStreamWriter.Close();
                            return;
                        }
                    }
                    catch (ArgumentException)
                    {
                    }
                    catch (Exception exception)
                    {
                        MessageBox.Show(exception.Message, @"Error", MessageBoxButtons.OK, MessageBoxIcon.None);
                    }
                }
                else     // Export for yearly wage.
                {
                    try
                    {
                        var toworkdays   = lsbfromsource.Cast <WorkDay>();
                        var filteredList = toworkdays.Where(d => d.DateAndTime.Year == dtpExportInfo.Value.Year);      //get fitting days
                        using (var savefd = new SaveFileDialog())
                        {
                            savefd.Filter       = @"Text files (*.txt)|*.txt";
                            savefd.DefaultExt   = "txt";
                            savefd.AddExtension = true;
                            savefd.ShowDialog();

                            var path = savefd.FileName;
                            var lsbDataStreamWriter = new StreamWriter(path, false);
                            foreach (var item in filteredList)
                            {
                                lsbDataStreamWriter.WriteLine((WorkDay)item + $" Wage earned: {WorkActions.LocalCalculate(item as WorkDay, rdbIsPart)}");
                                MessageBox.Show("File saved successfully.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }

                            lsbDataStreamWriter.Close();
                            return;
                        }
                    }
                    catch (Exception exception)
                    {
                        MessageBox.Show(exception.Message, @"Error", MessageBoxButtons.OK, MessageBoxIcon.None);
                    }
                }
            }

            #region excelExport
            try
            {
                if (rdbDay.Checked)
                {
                    var            toworkdaysD = lsbfromsource.Cast <WorkDay>();
                    List <WorkDay> filterDay   = new List <WorkDay>();
                    filterDay.Add(toworkdaysD.First(d => d.DateAndTime.Date == dtpExportInfo.Value.Date));
                    ExcelExport(filterDay, rowcount);
                    return;
                }
                if (rdbMonth.Checked)
                {
                    var toworkdaysM   = lsbfromsource.Cast <WorkDay>();
                    var filteredListM = toworkdaysM.Where(d =>
                                                          d.DateAndTime.Month == dtpExportInfo.Value.Month &&
                                                          d.DateAndTime.Year == dtpExportInfo.Value.Year).ToList();
                    ExcelExport(filteredListM, rowcount);
                    return;
                }
                var toworkdaysY   = lsbfromsource.Cast <WorkDay>();
                var filteredListY = toworkdaysY.Where(d => d.DateAndTime.Year == dtpExportInfo.Value.Year).ToList();
                ExcelExport(filteredListY, rowcount);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
            #endregion
        }