private void btnGenerateAndEmail_Click(object sender, EventArgs e)
        {
            ItemRpt rpt      = BuildReport();
            string  filename = string.Format("{0}\\Emails\\Sales[Item][{1}].xls", Application.StartupPath, DateTime.Now.ToString("yyyyMMdd_HHmm"));

            rpt.WriteExcelReport(filename);

            mApplicationController.Email(null, null, filename);
        }
        private void btnGenerate_Click(object sender, EventArgs e)
        {
            ItemRpt rpt = BuildReport();

            string filename = string.Format("{0}\\Reports\\Sales[Item].htm", Application.StartupPath);

            rpt.WriteHtmlReport(filename);

            RptViewer.Navigate(filename);
        }
        private void btnGenerateAndEmail_Click(object sender, EventArgs e)
        {
            ItemRpt rpt      = BuildReport();
            string  filename = string.Format("{0}{1}Emails{2}Purchases[Item][{3}].xls",
                                             Application.StartupPath,
                                             System.IO.Path.DirectorySeparatorChar,
                                             System.IO.Path.DirectorySeparatorChar,
                                             DateTime.Now.ToString("yyyyMMdd_HHmm"));

            rpt.WriteExcelReport(filename);
        }
        private void btnGenerate_Click(object sender, EventArgs e)
        {
            ItemRpt rpt = BuildReport();

            string filename = string.Format("{0}{1}Reports{2}Purchases[Item].htm",
                                            Application.StartupPath,
                                            System.IO.Path.DirectorySeparatorChar,
                                            System.IO.Path.DirectorySeparatorChar);

            rpt.WriteHtmlReport(filename);

            RptViewer.Navigate(filename);
        }
        private ItemRpt BuildReport()
        {
            ItemRpt rpt = new ItemRpt(mApplicationController.mAccountant);

            rpt.YearFrom = int.Parse(txtFromYear.Text);
            rpt.YearTo   = int.Parse(txtToYear.Text);

            rpt.DisplayItemNumber            = chkItemNumber.Checked;
            rpt.DisplayItemName              = chkItemName.Checked;
            rpt.DisplayBatchNumber           = chkBatchNumber.Checked;
            rpt.DisplaySerialNumber          = chkSerialNumber.Checked;
            rpt.DisplayExpiryDate            = chkExpiryDate.Checked;
            rpt.DisplayBrand                 = chkBrand.Checked;
            rpt.DisplayColor                 = chkColor.Checked;
            rpt.DisplayGender                = chkGender.Checked;
            rpt.DisplaySize                  = chkSize.Checked;
            rpt.DisplayPurchaseAmount        = chkPurchaseAmount.Checked;
            rpt.DisplayCostOfPurchasesAmount = chkCostOfPurchases.Checked;
            rpt.DisplayGrossProfit           = chkGrossProfit.Checked;
            rpt.DisplayProfitMargin          = chkProfitMargin.Checked;
            rpt.DisplayUnitsSold             = chkUnitsSold.Checked;
            rpt.DisplayAverageCost           = chkAverageCost.Checked;

            rpt.FieldOrder[ItemRpt.FieldName.ItemNumber]            = int.Parse(cboItemNumber.Text);
            rpt.FieldOrder[ItemRpt.FieldName.ItemName]              = int.Parse(cboItemName.Text);
            rpt.FieldOrder[ItemRpt.FieldName.BatchNumber]           = int.Parse(cboBatchNumber.Text);
            rpt.FieldOrder[ItemRpt.FieldName.SerialNumber]          = int.Parse(cboSerialNumber.Text);
            rpt.FieldOrder[ItemRpt.FieldName.ExpiryDate]            = int.Parse(cboExpiryDate.Text);
            rpt.FieldOrder[ItemRpt.FieldName.Brand]                 = int.Parse(cboBrand.Text);
            rpt.FieldOrder[ItemRpt.FieldName.Color]                 = int.Parse(cboColor.Text);
            rpt.FieldOrder[ItemRpt.FieldName.Gender]                = int.Parse(cboGender.Text);
            rpt.FieldOrder[ItemRpt.FieldName.Size]                  = int.Parse(cboSize.Text);
            rpt.FieldOrder[ItemRpt.FieldName.PurchaseAmount]        = int.Parse(cboPurchaseAmount.Text);
            rpt.FieldOrder[ItemRpt.FieldName.CostOfPurchasesAmount] = int.Parse(cboCostOfPurchases.Text);
            rpt.FieldOrder[ItemRpt.FieldName.GrossProfit]           = int.Parse(cboGrossProfit.Text);
            rpt.FieldOrder[ItemRpt.FieldName.ProfitMargin]          = int.Parse(cboProfitMargin.Text);
            rpt.FieldOrder[ItemRpt.FieldName.UnitsSold]             = int.Parse(cboUnitsSold.Text);
            rpt.FieldOrder[ItemRpt.FieldName.AverageCost]           = int.Parse(cboAverageCost.Text);

            rpt.IncludeCompanyAddress    = chkIncludeCompanyAddress.Checked;
            rpt.IncludeCompanyName       = chkIncludeCompanyName.Checked;
            rpt.IncludeReportDateAndTime = chkIncludeReportDateAndTime.Checked;

            return(rpt);
        }
        private void BtnSave_Click(object sender, EventArgs e)
        {
            dlgSave.Filter = "Excel Files (*.xls)|*.xls|HTML Files (*.htm)|*.htm|Text Files (*.txt)|*.txt|PDF Files (*.pdf)|*.pdf|Rich Text Files (*.rtf)|*.rtf";
            if (dlgSave.ShowDialog() == DialogResult.OK)
            {
                string filename = dlgSave.FileName;
                string ext      = System.IO.Path.GetExtension(filename.ToLower());

                ItemRpt rpt = BuildReport();
                if (ext.Equals(".xls"))
                {
                    rpt.WriteExcelReport(filename);
                }
                else if (ext.Equals(".htm"))
                {
                    rpt.WriteHtmlReport(filename);
                }
                else if (ext.Equals(".txt"))
                {
                    rpt.WriteDelimitedTextReport(filename);
                }
                else if (ext.Equals(".pdf"))
                {
                    bool landscape = false;
                    if (MessageBox.Show("Do you want to save the PDF in Landscape view?", "PDF Landscape View", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        landscape = true;
                    }

                    rpt.WritePdfReport(filename, landscape);
                }
                else if (ext.Equals(".rtf"))
                {
                    rpt.WriteRtfReport(filename);
                }

                if (MessageBox.Show("Do you want to open the file", "File Saved", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    System.Diagnostics.Process.Start(filename);
                }
            }
        }