private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            LinqServerModeSource LinqSM = new LinqServerModeSource()
            {
                ElementType     = typeof(WpfApplication15.ProductModel),
                KeyExpression   = "ProductModelID",
                QueryableSource = new DataClasses1DataContext().ProductModels
            };

            gridControl1.ItemsSource = LinqSM;
        }
        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            TableView            view         = values[0] as TableView;
            GridControl          gridControl1 = view.Grid;
            int                  rowIndex     = (int)values[1];
            ProductModel         drv          = gridControl1.GetRow(rowIndex) as ProductModel;
            LinqServerModeSource dLinqSM      = new LinqServerModeSource()
            {
                ElementType   = typeof(WpfApplication15.Product),
                KeyExpression = "ProductID",
            };
            Table <Product> tp      = new DataClasses1DataContext().Products;
            var             myQuery =
                from prod in tp
                where prod.ProductModelID == drv.ProductModelID
                select prod;

            dLinqSM.QueryableSource = myQuery;
            return(dLinqSM);
        }
Ejemplo n.º 3
0
        private void LoadCampaignList(eCampaignListLoadCallee pLoadType)
        {
            /**
             * unsubscribe this event first so that only data source change
             * will be triggered. this to avoid double calls to related modules
             * when changing views or rows or data source.
             */
            this.SetGridChangeRowEvent(false);
            int _FocusedRow = gvCampaignList.FocusedRowHandle;
            DateTime logDate1 = DateTime.UtcNow;
            m_CampaignListSelectedRow = 0;

            /**
             * set this flag to let know the dialog component that a new campaign list
             * has been loaded, thus, needing to create another dialog instance based
             * on this loaded campaign.
             */
            if (pLoadType == eCampaignListLoadCallee.CampaignListChange ||
                pLoadType == eCampaignListLoadCallee.EventLogOnLoad)
                m_BrightSalesProperty.CampaignBooking.Questionnaire.State = SelectionProperty.DialogEditorState.Empty;

            try {
                m_lsmsCampaignListData = null;
                m_efDbModel = null;
                m_efDbModel = new BrightPlatformEntities(UserSession.EntityConnection) {
                    CommandTimeout = 0
                };

                gcCampaignList.DataSource = null;
                gvCampaignList.Columns.Clear();
                gvCampaignList.FindFilterText = string.Empty;
                lblTotalRows.Text = "Records: 0";
                this.InitializeCampaignListControls(false);
                this.ClearGridFilter();

                if (m_BrightSalesProperty.CampaignList.CampaignListMode == SelectionProperty.CampaignListMode.CompaniesOnly) {
                    m_efDbModel.FIPopulateCampaignListCompanies(SubCampaignId, UserSession.CurrentUser.UserId);
                    int _final_list_id = m_efDbModel.final_lists.FirstOrDefault(i => i.sub_campaign_id == SubCampaignId).id;
                    m_lsmsCampaignListData = new LinqServerModeSource() {
                        DefaultSorting = "id",
                        KeyExpression = "uid",
                        QueryableSource = m_efDbModel.vw_campaign_list_companies.Where(i =>
                            i.final_list_id == _final_list_id &&
                            i.user_id == UserSession.CurrentUser.UserId
                        ).AsQueryable()
                        //QueryableSource = m_efDbModel.FIGetVwCampaignListCompanies(_final_list_id, UserSession.CurrentUser.UserId).ToList().AsQueryable()
                    };
                    m_lsmsCampaignListData.ExceptionThrown += new LinqServerModeExceptionThrownEventHandler(_lsmsCampaignListData_ExceptionThrown);
                    m_lsmsCampaignListData.InconsistencyDetected += new LinqServerModeInconsistencyDetectedEventHandler(_lsmsCampaignListData_InconsistencyDetected);

                    //gcCampaignList.DataSource = m_efDbModel.FIGetVwCampaignListCompanies(_final_list_id, UserSession.CurrentUser.UserId);
                    /** /
                    m_lsmsCampaignListData = new LinqServerModeSource()
                    {
                        DefaultSorting = "id",
                        KeyExpression = "uid",
                        QueryableSource = m_efDbModel.FIGetVwCampaignListCompanies(_final_list_id, UserSession.CurrentUser.UserId).ToList().AsQueryable()
                    };
                    m_lsmsCampaignListData.ExceptionThrown += new LinqServerModeExceptionThrownEventHandler(_lsmsCampaignListData_ExceptionThrown);
                    m_lsmsCampaignListData.InconsistencyDetected += new LinqServerModeInconsistencyDetectedEventHandler(_lsmsCampaignListData_InconsistencyDetected);
                    /**/

                    gcCampaignList.DataSource = m_lsmsCampaignListData;
                    gvCampaignList.Columns["uid"].Visible = false;
                    gvCampaignList.Columns["user_id"].Visible = false;
                    gvCampaignList.Columns["id"].Visible = false;
                    gvCampaignList.Columns["account_id"].Visible = false;
                    gvCampaignList.Columns["locked"].Visible = false;
                    gvCampaignList.Columns["locked_by"].Visible = false;
                    gvCampaignList.Columns["locked_timestamp"].Visible = false;
                    gvCampaignList.Columns["final_list_id"].Visible = false;
                    gvCampaignList.Columns["account_latitude"].Visible = false;
                    gvCampaignList.Columns["account_longitude"].Visible = false;
                    gvCampaignList.Columns["contact_id"].Visible = false;
                    gvCampaignList.Columns["account_address"].Visible = false;
                    gvCampaignList.Columns["contact_status"].Visible = false;
                }
                else if (m_BrightSalesProperty.CampaignList.CampaignListMode == SelectionProperty.CampaignListMode.CampaniesAndContacts) {
                    int _final_list_id = m_efDbModel.final_lists.FirstOrDefault(i => i.sub_campaign_id == SubCampaignId).id;
                    m_efDbModel.FIPopulateCampaignListCompaniesAndContacts(SubCampaignId, _final_list_id, UserSession.CurrentUser.UserId);
                    m_lsmsCampaignListData = new LinqServerModeSource() {
                        DefaultSorting = "id",
                        KeyExpression = "uid",
                        QueryableSource = m_efDbModel.vw_campaign_list_companies_and_contacts.Where(i =>
                            i.final_list_id == _final_list_id &&
                            i.user_id == UserSession.CurrentUser.UserId
                        ).AsQueryable()
                        //QueryableSource = m_efDbModel.FIGetVwCampaignListCompaniesAndContacts(_final_list_id, UserSession.CurrentUser.UserId).ToList().AsQueryable()
                    };
                    m_lsmsCampaignListData.ExceptionThrown += new LinqServerModeExceptionThrownEventHandler(_lsmsCampaignListData_ExceptionThrown);
                    m_lsmsCampaignListData.InconsistencyDetected += new LinqServerModeInconsistencyDetectedEventHandler(_lsmsCampaignListData_InconsistencyDetected);

                    //gcCampaignList.DataSource = m_efDbModel.FIGetVwCampaignListCompaniesAndContacts(_final_list_id, UserSession.CurrentUser.UserId);

                    /** /
                    m_lsmsCampaignListData = new LinqServerModeSource()
                    {
                        DefaultSorting = "id",
                        KeyExpression = "uid",
                        QueryableSource = m_efDbModel.FIGetVwCampaignListCompaniesAndContacts(_final_list_id, UserSession.CurrentUser.UserId).ToList().AsQueryable()
                    };
                    m_lsmsCampaignListData.ExceptionThrown += new LinqServerModeExceptionThrownEventHandler(_lsmsCampaignListData_ExceptionThrown);
                    m_lsmsCampaignListData.InconsistencyDetected += new LinqServerModeInconsistencyDetectedEventHandler(_lsmsCampaignListData_InconsistencyDetected);
                    /**/

                    gcCampaignList.DataSource = m_lsmsCampaignListData;
                    gvCampaignList.Columns["uid"].Visible = false;
                    gvCampaignList.Columns["user_id"].Visible = false;
                    gvCampaignList.Columns["id"].Visible = false;
                    gvCampaignList.Columns["account_id"].Visible = false;
                    gvCampaignList.Columns["locked"].Visible = false;
                    gvCampaignList.Columns["locked_by"].Visible = false;
                    gvCampaignList.Columns["locked_timestamp"].Visible = false;
                    gvCampaignList.Columns["final_list_id"].Visible = false;
                    gvCampaignList.Columns["account_latitude"].Visible = false;
                    gvCampaignList.Columns["account_longitude"].Visible = false;
                    gvCampaignList.Columns["contact_id"].Visible = false;
                    gvCampaignList.Columns["account_address"].Visible = false;
                    gvCampaignList.Columns["contact_latitude"].Visible = false;
                    gvCampaignList.Columns["contact_longitude"].Visible = false;
                    gvCampaignList.Columns["contact_address"].Visible = false;
                    gvCampaignList.Columns["contact_status"].Caption = "Dialog Status";
                    gvCampaignList.Columns["contact_status"].VisibleIndex = 7;
                }

                //if (gvCampaignList.FocusedRowHandle == 0)
                //    gvCampaignList.FocusedRowHandle = GridControl.InvalidRowHandle;

                gvCampaignList.BestFitColumns();
                //this.SetDefaultSelectedCampaignListItem();
                this.InitializeCampaignListControls(true);
                lblTotalRows.Text = "Records: " + gvCampaignList.RowCount.ToString();
                if (pLoadType == eCampaignListLoadCallee.Refresh)
                    gvCampaignList.FocusedRowHandle = _FocusedRow;
                else if (pLoadType == eCampaignListLoadCallee.EventLogOnLoad) {
                    //if (m_objSubCampaignAppointmentParams == null)
                    //    this.SetCampaignListAppointmentParams();
                }
                else
                    this.SetCampaignListAppointmentParams();

                /**
                 * re-subscribe the event after loading data.
                 */
                this.SetGridChangeRowEvent(true);
                m_DoneLoadingCampaignList = true;
            }
            catch (Exception e) {
                if (e.InnerException != null && e.InnerException.Message != null)
                    NotificationDialog.Information("Bright Sales", e.InnerException.Message);
                else
                    NotificationDialog.Information("Bright Sales", e.Message);

                return;
            }

            #region Log
            DateTime logDate2 = DateTime.UtcNow;
            string completeLoadingTime = logDate2.Subtract(logDate1).ToString("ss") + ":" + logDate2.Subtract(logDate1).Milliseconds;

            var log = BrightSalesFacade.Logger;
            log.SetLogField(LoggingField.campaign_id, CampaignId.ToString());
            log.SetLogField(LoggingField.campaign_name, CampaignName);
            log.SetLogField(LoggingField.sub_campaign_id, SubCampaignId.ToString());
            log.SetLogField(LoggingField.sub_campaign_name, SubCampaignName);
            log.SetLogField(LoggingField.customer_id, CustomerId.ToString());
            log.SetLogField(LoggingField.customer_name, CustomerName);
            log.SetLogField(LoggingField.contact_id, null);
            log.SetLogField(LoggingField.contact_name, null);
            log.SetLogField(LoggingField.dialog_id, null);
            log.SetLogField(LoggingField.account_id, null);
            log.SetLogField(LoggingField.account_name, null);
            log.SetLogField(LoggingField.complete_loading_time, completeLoadingTime);
            log.SetLogField(LoggingField.nr_companies_campagin_list, gvCampaignList.RowCount.ToString());

            if (m_BrightSalesProperty.CampaignList.CampaignListMode == SelectionProperty.CampaignListMode.CompaniesOnly)
                log.SetLogField(LoggingField.sub_campagin_list_type, "company");
            else if (m_BrightSalesProperty.CampaignList.CampaignListMode == SelectionProperty.CampaignListMode.CampaniesAndContacts)
                log.SetLogField(LoggingField.sub_campagin_list_type, "company_and_contact");
            else
                log.SetLogField(LoggingField.sub_campagin_list_type, "none");

            log.SendInfo("load_sub_campaign", "loading sub campaign details");
            #endregion
        }
Ejemplo n.º 4
0
        private DataTable ConvertToDataTable(LinqServerModeSource data)
        {
            //GridView view = new GridView();
            //view.DataSource = data;
            GridView gv = new GridView();
            GridControl gc = new GridControl();
            gc.MainView = gv;
            gc.ViewCollection.AddRange(new DevExpress.XtraGrid.Views.Base.BaseView[] { gv });

            gc.DataSource = data;
            gc.RefreshDataSource();

            DataTable dt = new DataTable();

            // add the columns to the datatable
            GridView view = gc.FocusedView as GridView;

            for (int i = 0; i < view.Columns.Count; i++)
            {
                dt.Columns.Add(view.Columns[i].FieldName);
            }
            dt.Columns["Company_Last_Contact"].DataType = typeof(DateTime);
            dt.Columns["Company_Last_Contact"].AllowDBNull = true;

            for (int i = 0; i < view.DataRowCount; i++)
            {
                DataRow dr;
                dr = dt.NewRow();
                for (int x = 0; x < view.Columns.Count; x++)
                {
                    if (view.Columns[x].FieldName == "Company_Last_Contact")
                    {
                        try
                        {
                            if (view.GetRowCellValue(i, dt.Columns[x].ColumnName) != null)
                            {
                                dr[x] = Convert.ToDateTime(view.GetRowCellValue(i, dt.Columns[x].ColumnName));
                            }
                            else
                            {
                                dr[x] = DBNull.Value;
                            }
                        }
                        catch (Exception e)
                        {
                            m_EventBus.Notify(new FrmSalesConsultantEvents.Tracer() {
                                ErrorMessage = e.Message
                            });
                            dr[x] = DBNull.Value;
                        }
                    }
                    else
                    {
                        dr[x] = view.GetRowCellValue(i, dt.Columns[x].ColumnName);
                    }
                }
                dt.Rows.Add(dr);

            }
            gc.Dispose();
            gc = null;

            return dt;
        }