Example #1
0
            private void GetReportPageBaseData()
            {
                m_IsEmpty = false;
                if (this.gridView1.DataRowCount == null || this.gridView1.DataRowCount < 1) {
                    BrightVision.Common.UI.NotificationDialog.Information("Reports", "No data to preview.");
                    m_IsEmpty = true;
                    return;
                }

                using (BrightPlatformEntities _efDbModel = new BrightPlatformEntities(m_DatabaseConnection) { CommandTimeout = 0 }) {
                    m_eftConfigData = _efDbModel.view_configuration.FirstOrDefault(i => i.id == m_ViewConfigId);
                    m_eftSubCampaign = _efDbModel.subcampaigns.FirstOrDefault(i => i.id == m_eftConfigData.subcampaign_id);
                    m_eftCampaign = _efDbModel.campaigns.FirstOrDefault(i => i.id == m_eftSubCampaign.campaign_id);
                    m_eftCustomer = _efDbModel.customers.FirstOrDefault(i => i.id == m_eftCampaign.customer_id);
                    _efDbModel.Detach(m_eftConfigData);
                    _efDbModel.Detach(m_eftSubCampaign);
                    _efDbModel.Detach(m_eftCampaign);
                    _efDbModel.Detach(m_eftCustomer);
                    _efDbModel.FIUpdateContactTitles();

                    /**
                     * if send email, get data for sub_campaign_account_list and final_list.
                     */
                    if (m_CallingEnvironment == eCallingEnvironment.BrightSales_SendEmail && m_AccountId > 0) {
                        m_eftFinalList = _efDbModel.final_lists.FirstOrDefault(i => i.sub_campaign_id == m_eftSubCampaign.id);
                        if (m_eftFinalList != null) {
                            _efDbModel.Detach(m_eftFinalList);
                            m_eftSubCampaignAccountList = _efDbModel.sub_campaign_account_lists.FirstOrDefault(i =>
                                i.final_list_id == m_eftFinalList.id &&
                                i.account_id == m_AccountId
                            );
                                _efDbModel.Detach(m_eftSubCampaignAccountList);
                        }
                    }
                }

                if (m_eftConfigData == null || m_eftConfigData.report_layout_config == null) {
                    WaitDialog.Close();
                    if (m_IsWebPortalCall)
                        throw new Exception("No layout available for the selected view.");

                    BrightVision.Common.UI.NotificationDialog.Information("Reports", "No layout available for this view.");
                    return;
                }

                if (string.IsNullOrEmpty(m_eftConfigData.report_data_config)) {
                    WaitDialog.Close();
                    if (m_IsWebPortalCall)
                        throw new Exception("No parameter layout has been set for this report.");

                    BrightVision.Common.UI.NotificationDialog.Information("Reports", "No parameter layout has been set for this report.");
                    return;
                }

                m_ReportPageTemplateProperty = SerializeUtility.DeserializeFromXml<TemplateProperty>(m_eftConfigData.report_data_config);
                m_ReportPageDataSet = this.GetReportDataSet(m_ReportPageTemplateProperty);

                /**
                 * if has sort info, then apply.
                 */
                #region Sorting Logic
                if (!string.IsNullOrEmpty(m_GridSortInfo)) {
                    string sortExpression = this.GetSortExpression(gridView1);
                    if (!string.IsNullOrEmpty(sortExpression)) {
                        string[] _SortInfoCollection = sortExpression.Split(';');

                        ReportDataSet _rdsTemporary = (ReportDataSet)m_ReportPageDataSet.Clone();
                        DataSet _dsSortedData = new DataSet();
                        Dictionary<string, List<string>> _TableSortRules = new Dictionary<string, List<string>>();

                        /**
                         * group all sort rules by table.
                         */
                        foreach (string _SortInfo in _SortInfoCollection) {
                            string[] _item = _SortInfo.Split('|');
                            string _FieldNameInfo = this.GetTableFieldName(_item[0].ToString());
                            if (!string.IsNullOrEmpty(_FieldNameInfo)) {
                                string[] _val = _FieldNameInfo.Split('|');
                                string _TableName = _val[0];
                                string _FieldName = _val[1];

                                /**
                                 * create new table sort rule.
                                 * else, update existing table sort rule.
                                 *
                                 * format:
                                 * <column_name1>|<sort_rule1>;<column_name2>|<sort_rule2>; and so on ...
                                 *
                                 * this would later be processed by splitting the sort rules by semicolon(;),
                                 * then split by bar(|).
                                 */
                                string _ColumnName = m_ReportPageDataSet.Tables[_TableName].Columns[_FieldName].ColumnName;
                                string _SortOrder = _item[1].ToString();
                                if (!_TableSortRules.ContainsKey(_TableName))
                                    _TableSortRules.Add(_TableName, new List<string>());

                                _TableSortRules[_TableName].Add(string.Format("{0} {1}", _ColumnName, _SortOrder));
                            }
                        }

                        /**
                         * set the sorting rules from KeyValuePair<string, List<string>> from _TableSortRules
                         * string = table name
                         * List<string> = sort rules
                         */
                        foreach (KeyValuePair<string, List<string>> _pair in _TableSortRules) {
                            DataTable _dtToSort = m_ReportPageDataSet.Tables[_pair.Key];
                            _dtToSort.DefaultView.Sort = string.Join(",", _TableSortRules[_pair.Key].ToArray());
                            _dsSortedData.Tables.Add(_dtToSort.DefaultView.ToTable());
                        }

                        /**
                         * copy all tables to the temporary report data set.
                         * then overwrite the original report data set with the
                         * temporary report dataset, since it contains the sorted
                         * tables that the report needs.
                         *
                         * order of the tables, according to relationship:
                         * 1. account
                         * 2. accountdynamic
                         * 3. accountstatic
                         * 4. contact
                         * 5. contactdynamic
                         * 6. contactstatic
                         * 7. clientinfo
                         * 8. customers
                         */
                        if (_dsSortedData.Tables["account"] != null)
                            this.CopyTableRows(ref _rdsTemporary, _dsSortedData.Tables["account"].Rows, "account");
                        else
                            this.CopyTableRows(ref _rdsTemporary, m_ReportPageDataSet.Tables["account"].Rows, "account");

                        if (_dsSortedData.Tables["accountdynamic"] != null)
                            this.CopyTableRows(ref _rdsTemporary, _dsSortedData.Tables["accountdynamic"].Rows, "accountdynamic");
                        else
                            this.CopyTableRows(ref _rdsTemporary, m_ReportPageDataSet.Tables["accountdynamic"].Rows, "accountdynamic");

                        if (_dsSortedData.Tables["accountstatic"] != null)
                            this.CopyTableRows(ref _rdsTemporary, _dsSortedData.Tables["accountstatic"].Rows, "accountstatic");
                        else
                            this.CopyTableRows(ref _rdsTemporary, m_ReportPageDataSet.Tables["accountstatic"].Rows, "accountstatic");

                        if (_dsSortedData.Tables["contact"] != null)
                            this.CopyTableRows(ref _rdsTemporary, _dsSortedData.Tables["contact"].Rows, "contact");
                        else
                            this.CopyTableRows(ref _rdsTemporary, m_ReportPageDataSet.Tables["contact"].Rows, "contact");

                        if (_dsSortedData.Tables["contactdynamic"] != null)
                            this.CopyTableRows(ref _rdsTemporary, _dsSortedData.Tables["contactdynamic"].Rows, "contactdynamic");
                        else
                            this.CopyTableRows(ref _rdsTemporary, m_ReportPageDataSet.Tables["contactdynamic"].Rows, "contactdynamic");

                        if (_dsSortedData.Tables["contactstatic"] != null)
                            this.CopyTableRows(ref _rdsTemporary, _dsSortedData.Tables["contactstatic"].Rows, "contactstatic");
                        else
                            this.CopyTableRows(ref _rdsTemporary, m_ReportPageDataSet.Tables["contactstatic"].Rows, "contactstatic");

                        if (_dsSortedData.Tables["clientinfo"] != null)
                            this.CopyTableRows(ref _rdsTemporary, _dsSortedData.Tables["clientinfo"].Rows, "clientinfo");
                        else
                            this.CopyTableRows(ref _rdsTemporary, m_ReportPageDataSet.Tables["clientinfo"].Rows, "clientinfo");

                        if (_dsSortedData.Tables["customers"] != null)
                            this.CopyTableRows(ref _rdsTemporary, _dsSortedData.Tables["customers"].Rows, "customers");
                        else
                            this.CopyTableRows(ref _rdsTemporary, m_ReportPageDataSet.Tables["customers"].Rows, "customers");

                        m_ReportPageDataSet = null;
                        m_ReportPageDataSet = _rdsTemporary;
                    }
                }
                #endregion
            }
Example #2
0
        private void btnLoad_Click(object sender, EventArgs e)
        {
            if (worker.IsBusy) {
                worker.CancelAsync();
                return;
            }

            WaitDialog.Show("Generating report pages ...");
            using (BrightPlatformEntities _efDbContext = new BrightPlatformEntities(UserSession.EntityConnection) { CommandTimeout = 0 }) {
                _efDbContext.FIUpdateContactTitles();
            }
            if (m_ViewConfigId < 1) {
                string val = (string)ccbeSubcampaign.EditValue;
                if (!string.IsNullOrEmpty(val)) {
                    List<int> subcampaign_ids = new List<int>();
                    var strVals = val.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                    strVals.ForEach(delegate(string x) {
                        subcampaign_ids.Add(int.Parse(x));
                    });
                    this.ClearPages();
                    this.GenerateReportPages(subcampaign_ids.ToArray());
                    worker.RunWorkerAsync();
                }
            }
            else {
                List<int> subcampaign_ids = new List<int>();
                subcampaign_ids.Add(m_efoViewConfig.subcampaign_id);
                this.ClearPages();
                this.GenerateReportPages(subcampaign_ids.ToArray(), m_efoViewConfig.id);
                worker.RunWorkerAsync();
            }
            WaitDialog.Close();
        }