Exemplo n.º 1
0
        /// <summary>
        /// set all task properties to local vaariables
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ReportGeneratorUI_Load(object sender, EventArgs e)
        {
            //dgvReportParameter.VirtualMode = true;
            BuildDataTable();

            _prefixFilename = _taskHost.Properties["PrefixFilename"].GetValue(_taskHost) == null ? "" : _taskHost.Properties["PrefixFilename"].GetValue(_taskHost).ToString();
            _snapshot       = _taskHost.Properties["Snapshot"].GetValue(_taskHost) != null && (bool)_taskHost.Properties["Snapshot"].GetValue(_taskHost);
            _recordset      = _taskHost.Properties["Recordset"].GetValue(_taskHost) == null ? "" : _taskHost.Properties["Recordset"].GetValue(_taskHost).ToString();

            cbWindowsAuthorization.Checked = _taskHost.Properties["WindowsAuthorization"].GetValue(_taskHost) == null || (bool)_taskHost.Properties["WindowsAuthorization"].GetValue(_taskHost);
            txtReports.Text       = _taskHost.Properties["Reportname"].GetValue(_taskHost) == null ? "" : _taskHost.Properties["Reportname"].GetValue(_taskHost).ToString();
            txtDatasetname.Text   = _taskHost.Properties["Datasetname"].GetValue(_taskHost) == null ? "" : _taskHost.Properties["Datasetname"].GetValue(_taskHost).ToString();
            txtLocation.Text      = _taskHost.Properties["Filename"].GetValue(_taskHost) == null ? "" : _taskHost.Properties["Filename"].GetValue(_taskHost).ToString();
            cbAddPrefix.Checked   = _taskHost.Properties["Prefix"].GetValue(_taskHost) != null && (bool)_taskHost.Properties["Prefix"].GetValue(_taskHost);
            cbShowInDebug.Checked = _taskHost.Properties["DebugMode"].GetValue(_taskHost) != null && (bool)_taskHost.Properties["DebugMode"].GetValue(_taskHost);
            txtReportServer.Text  = _taskHost.Properties["ReportServer"].GetValue(_taskHost) == null ? @"http://localhost/reportserver" : _taskHost.Properties["ReportServer"].GetValue(_taskHost).ToString();
            _reportType           = _taskHost.Properties["ReportType"].GetValue(_taskHost) == null ? "SQL Server Report" : _taskHost.Properties["ReportType"].GetValue(_taskHost).ToString();
            txtUsername.Text      = _taskHost.Properties["Username"].GetValue(_taskHost) == null ? "" : _taskHost.Properties["Username"].GetValue(_taskHost).ToString();
            txtDomain.Text        = _taskHost.Properties["Domain"].GetValue(_taskHost) == null ? "" : _taskHost.Properties["Domain"].GetValue(_taskHost).ToString();
            txtPassword.Text      = _taskHost.Properties["Password"].GetValue(_taskHost) == null ? "" : _taskHost.Properties["Password"].GetValue(_taskHost).ToString();

            var reportparameterObjectValue = _taskHost.Properties["Reportparameter"].GetValue(_taskHost);

            if (reportparameterObjectValue != null)
            {
                _reportparameter = ReportGenerator.GetParameterDataTable(reportparameterObjectValue.ToString());
            }

            cbReportType.SelectedItem = _reportType;

            cbxPrefixFilename.BeginUpdate();

            AddVariableToRow("Choose a Variable");

            //foreach (var var in _taskHost.Variables.Cast<Variable>().Where(var => !var.ReadOnly))
            foreach (var var in _taskHost.Variables)
            {
                if (!var.ReadOnly)
                {
                    cbxPrefixFilename.Items.Add(var.QualifiedName);
                    AddVariableToRow(var.QualifiedName);
                }
            }

            cbExpirationDateTime.DataSource    = _variable.Copy();
            cbExpirationDateTime.ValueMember   = "Variable";
            cbExpirationDateTime.DisplayMember = "Variable";
            cbExpirationDateTime.SelectedValue = _taskHost.Properties["ExpirationDateTime"].GetValue(_taskHost) == null ? "Choose a Variable" : _taskHost.Properties["ExpirationDateTime"].GetValue(_taskHost).ToString();

            cbExecutionDateTime.DataSource    = _variable.Copy();
            cbExecutionDateTime.ValueMember   = "Variable";
            cbExecutionDateTime.DisplayMember = "Variable";
            cbExecutionDateTime.SelectedValue = _taskHost.Properties["ExecutionDateTime"].GetValue(_taskHost) == null ? "Choose a Variable" : _taskHost.Properties["ExecutionDateTime"].GetValue(_taskHost).ToString();

            cbExecutionId.DataSource    = _variable.Copy();
            cbExecutionId.ValueMember   = "Variable";
            cbExecutionId.DisplayMember = "Variable";
            cbExecutionId.SelectedValue = _taskHost.Properties["ExecutionId"].GetValue(_taskHost) == null ? "Choose a Variable" : _taskHost.Properties["ExecutionId"].GetValue(_taskHost).ToString();

            cbHistoryId.DataSource    = _variable.Copy();
            cbHistoryId.ValueMember   = "Variable";
            cbHistoryId.DisplayMember = "Variable";
            cbHistoryId.SelectedValue = _taskHost.Properties["HistoryId"].GetValue(_taskHost) == null ? "Choose a Variable" : _taskHost.Properties["HistoryId"].GetValue(_taskHost).ToString();

            cbNumPages.DataSource    = _variable.Copy();
            cbNumPages.ValueMember   = "Variable";
            cbNumPages.DisplayMember = "Variable";
            cbNumPages.SelectedValue = _taskHost.Properties["NumPages"].GetValue(_taskHost) == null ? "Choose a Variable" : _taskHost.Properties["NumPages"].GetValue(_taskHost).ToString();

            numTimeOut.Value = _taskHost.Properties["TimeOut"].GetValue(_taskHost) == null ? 30000 : Convert.ToInt32(_taskHost.Properties["TimeOut"].GetValue(_taskHost));


            if (_reportparameter != null)
            {
                SetParameter(_reportparameter);
            }

            //Set the selected variable
            if (_prefixFilename != null)
            {
                cbxPrefixFilename.SelectedItem = _prefixFilename;
            }

            cbxPrefixFilename.EndUpdate();

            cbxRecordset.BeginUpdate();

            //foreach (var var in _taskHost.Variables.Cast<Variable>().Where(var => !var.ReadOnly))
            foreach (var var in _taskHost.Variables)
            {
                if (!var.ReadOnly)
                {
                    cbxRecordset.Items.Add(var.QualifiedName);
                }
            }

            if (_recordset != null)
            {
                cbxRecordset.SelectedItem = _recordset;
            }



            cbxRecordset.EndUpdate();

            ChangeUi();
            //AddComboBoxColumns();
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (!String.IsNullOrEmpty(txtLocation.Text))
            {
                var fi = new FileInfo(txtLocation.Text);

                if (fi.DirectoryName != null && !Directory.Exists(fi.DirectoryName))
                {
                    MessageBox.Show(Resources.The_specified_report_folder_does_not_exist_,
                                    Resources.ReportGeneratorTask_, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    try
                    {
                        _taskHost.Properties["Recordset"].SetValue(_taskHost, cbxRecordset.SelectedItem.ToString());
                    }
                    catch
                    {
                        _taskHost.Properties["Recordset"].SetValue(_taskHost, null);
                    }

                    try
                    {
                        _taskHost.Properties["PrefixFilename"].SetValue(_taskHost,
                                                                        cbxPrefixFilename.SelectedItem.ToString());
                    }
                    catch
                    {
                        _taskHost.Properties["PrefixFilename"].SetValue(_taskHost, null);
                    }

                    try
                    {
                        //_Param = ReportGenerator.SerializeObject(GetDataTable());
                        _param = ReportGenerator.GetParameterString(GetDataTable());
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString());
                        _param = null;
                    }
                }


                _taskHost.Properties["TimeOut"].SetValue(_taskHost, Convert.ToInt32(numTimeOut.Value));

                _taskHost.Properties["ExecutionDateTime"].SetValue(_taskHost, cbExecutionDateTime.SelectedValue);
                _taskHost.Properties["ExpirationDateTime"].SetValue(_taskHost, cbExpirationDateTime.SelectedValue);
                _taskHost.Properties["ExecutionId"].SetValue(_taskHost, cbExecutionId.SelectedValue);
                _taskHost.Properties["HistoryId"].SetValue(_taskHost, cbHistoryId.SelectedValue);
                _taskHost.Properties["NumPages"].SetValue(_taskHost, cbNumPages.SelectedValue);

                _taskHost.Properties["Reportparameter"].SetValue(_taskHost, _param);
                _taskHost.Properties["Reportname"].SetValue(_taskHost, txtReports.Text);
                _taskHost.Properties["Filename"].SetValue(_taskHost, txtLocation.Text);
                _taskHost.Properties["Datasetname"].SetValue(_taskHost, txtDatasetname.Text);
                _taskHost.Properties["Prefix"].SetValue(_taskHost, cbAddPrefix.Checked);
                _taskHost.Properties["DebugMode"].SetValue(_taskHost, cbShowInDebug.Checked);
                _taskHost.Properties["Snapshot"].SetValue(_taskHost, cbSnapshot.Checked);
                _taskHost.Properties["ReportType"].SetValue(_taskHost, cbReportType.Items[cbReportType.SelectedIndex].ToString());
                _taskHost.Properties["ReportServer"].SetValue(_taskHost, txtReportServer.Text);
                _taskHost.Properties["Username"].SetValue(_taskHost, txtUsername.Text);
                _taskHost.Properties["Domain"].SetValue(_taskHost, txtDomain.Text);
                _taskHost.Properties["Password"].SetValue(_taskHost, txtPassword.Text);
                _taskHost.Properties["WindowsAuthorization"].SetValue(_taskHost, cbWindowsAuthorization.Checked);
                DialogResult = DialogResult.OK;
            }
            else
            {
                MessageBox.Show(Resources.There_was_no_filename_specified_, Resources.ReportGeneratorTask_, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }