Esempio n. 1
0
        void ux_DGVCellReport_Click(object sender, EventArgs e)
        {
            ToolStripMenuItem tsmi = (ToolStripMenuItem)sender;

            DataTable dt = ((DataTable)((BindingSource)ux_datagridviewMain.DataSource).DataSource).Clone();

            // NOTE: because of the way the DGV adds rows to the selectedRows collection
            //       we have to process the rows in the opposite direction they were selected in...
            int rowStart = 0;
            int rowStop = ux_datagridviewMain.SelectedRows.Count;
            int stepValue = 1;
            if (ux_datagridviewMain.SelectedRows.Count > 1 && ux_datagridviewMain.SelectedRows[0].Index > ux_datagridviewMain.SelectedRows[1].Index)
            {
                rowStart = ux_datagridviewMain.SelectedRows.Count - 1;
                rowStop = -1;
                stepValue = -1;
            }

            DataGridViewRow dgvrow = null;
            // Process the rows in the opposite direction they were selected by the user...
            for (int i = rowStart; i != rowStop; i += stepValue)
            {
                dgvrow = ux_datagridviewMain.SelectedRows[i];
                if (!dgvrow.IsNewRow)
                {
                    dt.Rows.Add(((DataRowView)dgvrow.DataBoundItem).Row.ItemArray);
                }
            }

            //            ReportForm crustyReport = new ReportForm(dt, @"C:\VisualStudio2008_SVN\MyPlayground\MyPlayground\FieldLabel1.rpt");
            string fullPathName = tsmi.Tag.ToString();
            if (System.IO.File.Exists(fullPathName))
            {
                ReportForm crustyReport = new ReportForm(dt, fullPathName);
            crustyReport.StartPosition = FormStartPosition.CenterParent;
            _sharedUtils.UpdateControls(crustyReport.Controls, crustyReport.Name);
                crustyReport.ShowDialog();
            }
            RefreshMainDGVFormatting();
        }
Esempio n. 2
0
        private void ux_buttonPrintCrystalReport_Click(object sender, EventArgs e)
        {
            //DataTable dt = ((DataTable)((BindingSource)ux_datagridviewMain.DataSource).DataSource).Clone();

            //// NOTE: because of the way the DGV adds rows to the selectedRows collection
            ////       we have to process the rows in the opposite direction they were selected in...
            //int rowStart = 0;
            //int rowStop = ux_datagridviewMain.SelectedRows.Count;
            //int stepValue = 1;
            //if (ux_datagridviewMain.SelectedRows.Count > 1 && ux_datagridviewMain.SelectedRows[0].Index > ux_datagridviewMain.SelectedRows[1].Index)
            //{
            //    rowStart = ux_datagridviewMain.SelectedRows.Count - 1;
            //    rowStop = -1;
            //    stepValue = -1;
            //}

            //DataGridViewRow dgvrow = null;
            //// Process the rows in the opposite direction they were selected by the user...
            //for (int i = rowStart; i != rowStop; i += stepValue)
            //{
            //    dgvrow = ux_datagridviewMain.SelectedRows[i];
            //    if (!dgvrow.IsNewRow)
            //    {
            //        dt.Rows.Add(((DataRowView)dgvrow.DataBoundItem).Row.ItemArray);
            //    }
            //}

            //            ReportForm crustyReport = new ReportForm(dt, @"C:\VisualStudio2008_SVN\MyPlayground\MyPlayground\FieldLabel1.rpt");
            string fullPathName = System.Windows.Forms.Application.StartupPath + "\\Reports\\" + ux_comboboxCrystalReports.Text;
            if (System.IO.File.Exists(fullPathName))
            {
                // By default print just the current order...
                string pkeys = ":orderrequestid=" + ((DataRowView)_orderRequestBindingSource.Current).Row["order_request_id"].ToString();
                // Unless the user wants all orders in the Wizard printed at once...
                if (ux_checkboxPrintAllOrders.Checked) pkeys = _orderRequestPKeys;
                // Find a compatible dataview for the selected Crystal Report...
                System.Collections.Generic.Dictionary<string, string> reportsMap = _sharedUtils.GetReportsMapping();
                string dataviewName = "";
                if (reportsMap.ContainsKey(ux_comboboxCrystalReports.Text.Trim().ToUpper()))
                {
                    string dataviewNames = reportsMap[ux_comboboxCrystalReports.Text.Trim().ToUpper()];
                    if (dataviewNames.Length > 0)
                    {
                        dataviewName = dataviewNames.Split('|')[0].Trim().ToLower();
                    }
                }

                if (!string.IsNullOrEmpty(dataviewName))
                {
                    // Get the data using the suggested dataview...
                    DataSet ds = _sharedUtils.GetWebServiceData(dataviewName, pkeys, 0, 0);
                    // Get a copy of the Reports-->Dataviews Mapping...
                    if (ds.Tables.Contains(dataviewName))
                    {
                        DataGridView dgv = new DataGridView();
                        _sharedUtils.BuildReadOnlyDataGridView(dgv, ds.Tables[dataviewName]);
                        if (dgv != null &&
                            dgv.DataSource != null &&
                            dgv.DataSource.GetType() == typeof(DataTable))
                        {
                            // Okay it looks like we have a datagridview with a datasource = datatable (with FKeys and code_values resolved) - so extract it and use in the report...
                            DataTable dt = (DataTable)dgv.DataSource;
                            // Got the data so now we can generate the Crystal Report...
                            GRINGlobal.Client.Common.ReportForm crustyReport = new ReportForm(dt, fullPathName);
                            crustyReport.StartPosition = FormStartPosition.CenterParent;
                            _sharedUtils.UpdateControls(crustyReport.Controls, crustyReport.Name);
                            crustyReport.ShowDialog();
                        }
                    }
                }
            }
        }