public DataSetViewer(Controller myCon, DataSetCollection ds)
        {
            InitializeComponent();

            this.dsArray = ds;
            this.con = myCon;
        }
        public ReportPrinter(Controller myCon, DataSetCollection dsArray, string xslAssemblyPath, string xslAssemblyPath2, DataTable chartOfAccounts, int reportNumber)
        {
            InitializeComponent();

            this.reportNumber = reportNumber;
            this.dsArray = dsArray;
            this.con = myCon;
            this.chartOfAccounts = chartOfAccounts;

            // this: creates an XmlReader; from this assembly's manifest; using the supplied stylesheet.
            // (should be done here to minimize IO during loop)
            this.xslAssemblyStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(xslAssemblyPath);
            this.xslAssemblyStream2 = Assembly.GetExecutingAssembly().GetManifestResourceStream(xslAssemblyPath2);
        }
        public void combineXML(string[] filenames)
        {
            // create a temporary dataset
            DataSetCollection multiSetXml = new DataSetCollection();

            // load the xml files into the dataset

            for (int i = 0; i < filenames.Length;i++ )
            {
                DataSet tempDS = new DataSet();
                tempDS.ReadXml(filenames[i]);
                multiSetXml.Add(tempDS);
            }

            // combine the tables into one big table
            currentDataSet = combineDataSets(multiSetXml);

            // display that table in the main window for review
            form.setDataSource(currentDataSet);
        }
        private DataSet combineDataSets(DataSetCollection multiSetColl)
        {
            // for each dataset
            for(int i=1;i<multiSetColl.Count;i++)
            {
                multiSetColl[0].Tables["Allocation"].Merge(
                    multiSetColl[i].Tables["Allocation"]);
                multiSetColl[0].Tables["Split"].Merge(
                    multiSetColl[i].Tables["Split"]);
            }

            return multiSetColl[0];
        }
        private DataSetCollection categorizeRows(string sortColumn1, string sortColumn2, string sortColumn3, DataSet dataSet)
        {
            // Create the query.
            var transaction =
                from DataRow row in dataSet.Tables["Allocation"].Rows
                orderby row[sortColumn1] ascending, row[sortColumn2] ascending, row[sortColumn3] ascending
                group row by row[sortColumn1] into newGroup
                orderby newGroup.Key
                select newGroup;

            // create a temporary dataset
            DataSetCollection dataSetArray = new DataSetCollection();

            foreach (var rowGroup in transaction)
            {
                DataSet tempDS = dataSet.Clone();
                tempDS.ExtendedProperties["user"] = rowGroup.Key.ToString();

                foreach (var row in rowGroup)
                {
                    tempDS.Tables["Allocation"].ImportRow(row);

                    foreach(DataRow sRow in dataSet.Tables["Split"].Rows)
                    {
                        //TODO: Does this actually do anything?
                        if(sRow["ChargeID"] == ((DataRow)row)["ChargeID"])
                        {
                            tempDS.Tables["Split"].ImportRow(sRow);
                        }
                    }

                }

                dataSetArray.Add(tempDS);
            }

            return dataSetArray;
        }
        public void saveSplitFile(string savePath, DataSetCollection dsToSave)
        {
            // make sure the last character of the path is a slash
            if(!savePath.EndsWith("\\"))
            {
                savePath += "\\";
            }

            // for each table
            foreach (DataSet ds in dsToSave)
            {
                // export the data to an XML file, with schema included for datatyping
                ds.WriteXml(savePath + ds.ExtendedProperties["user"] + ".xml",XmlWriteMode.WriteSchema);
            }
        }
        public void printReport3()
        {
            if (currentDataSet != null)
            {
                currentDataSet.AcceptChanges();

                string containsNull = validateRows(currentDataSet);

                if (containsNull != null)
                {
                    // don't categorizeRows without filling in info.
                    MessageBox.Show(form, "Check that the Company and Account fields in the highlighted row are accurate." , "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    form.highlightRow(containsNull);
                }
                else
                {
                    //TODO: What is this for?
                    //currentDataSet.Tables[0].Columns["Company"].DataType = Type.GetType("System.String");
                    //DataRow[] rowsCopy = new DataRow[currentDataSet.Tables[0].Rows.Count];
                    //currentDataSet.Tables[0].Rows.CopyTo(rowsCopy, 0);

                    // resolve Split transactions into their splits
                    DataSet tempDS = resolveSplits(currentDataSet);

                    //tempdataset =
                    //// create a temporary dataset
            //                    DataSetCollection dataSetArray = new DataSetCollection();

                    DataSetCollection dsColl = new DataSetCollection();
                    dsColl.Add(createAudit("Company", tempDS));
                    dsColl.Add(createAudit("Cardholder Name", tempDS));

                    //initDataSet(tempDataSet);

                    // create a viewer window, populate the data, and display it.
                    ReportPrinter rp = new ReportPrinter(this, dsColl, "Trillium_CC_Allocation.report3.xsl",
                        "Trillium_CC_Allocation.report3a.xsl", chartOfAccounts.Tables["Companies"], 3);
                    rp.ShowDialog(form);
                }
            }
            else
            {
                MessageBox.Show(form, "Combine XML files before trying to print.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
        public void printDataGrid()
        {
            if (currentDataSet != null)
            {
                currentDataSet.AcceptChanges();

                string containsNull = validateRows(currentDataSet);

                if (containsNull != null)
                {
                    // Warn about empty rows
                    MessageBox.Show(form, "Not all Company and Account fields are accurate.\r\n\r\nCheck that the Company and Account fields in the \r\nhighlighted row are accurate before submitting."
                        , "Warning", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    form.highlightRow(containsNull);
                }

                DataSetCollection dsColl = new DataSetCollection();
                dsColl.Add(currentDataSet);

                // create a viewer window, populate the data, and display it.
                ReportPrinter rp = new ReportPrinter(this, dsColl, "Trillium_CC_Allocation.report1.xsl", null, 1);
                rp.ShowDialog(form);

            }
            else
            {
                MessageBox.Show(form, "Open a file before trying to print.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }