Example #1
0
            public IEnumerator GetEnumerator()
            {
                _arguments.AddSupportedCapabilities(DataSourceCapabilities.Page);
                _arguments.AddSupportedCapabilities(DataSourceCapabilities.Sort);
                _arguments.AddSupportedCapabilities(DataSourceCapabilities.RetrieveTotalRowCount);

                EditableArrayList list = (EditableArrayList)_objectBinder.List;

                _arguments.TotalRowCount = list.Count;

                if (!string.IsNullOrEmpty(_arguments.SortExpression))
                {
                    list = new EditableArrayList(list.ItemType, list.Count);
                    list.AddRange(_objectBinder.List);
                    list.SortEx(_arguments.SortExpression);
                }

                int start = _arguments.StartRowIndex >= 0? _arguments.StartRowIndex: 0;
                int count = _arguments.MaximumRows > 0?
                            Math.Min(_arguments.MaximumRows, list.Count): list.Count;

                for (int i = 0; i < count; i++)
                {
                    object o = list[i + start];

                    yield return(o is ICustomTypeDescriptor? o: new ObjectHolder(o, _objectBinder));
                }
            }
Example #2
0
    protected void btnAddCatManJob_Click(object sender, EventArgs e)
    {
        string vettedCreateJobText = Regex.Replace(txtCreateJob.Text.ToLower(), @"[\s]+", "");

        try
        {
            if (vettedCreateJobText != null && vettedCreateJobText != "" && vettedCreateJobText.Length <= 50)
            {
                sds.ConnectionString = Resources.ConnectionStrings.ATHENA;

                sds.SelectCommand = Resources.CatalogManagerSQLQueries.VerifyRegexSelect;
                DataSourceSelectArguments dssa = new DataSourceSelectArguments();
                dssa.AddSupportedCapabilities(DataSourceCapabilities.RetrieveTotalRowCount);
                dssa.RetrieveTotalRowCount = true;
                DataView dv = (DataView)sds.Select(dssa);

                if (dv.Count == 0)
                {
                    sds.InsertCommand = Resources.CatalogManagerSQLQueries.InsertCleanValues;
                    sds.Insert();

                    sds.UpdateCommand = Resources.CatalogManagerSQLQueries.UpdateJobs;
                    sds.Update();
                }
            }
            txtCreateJob.Text = String.Empty;
        }
        catch (InvalidCastException ex) { }
    }
    protected void btnSubmitSuperCategoryChanges_Click(object sender, EventArgs e)
    {
        string preEditState           = (string)(Session["preEditState"]);
        string preEditState2          = (string)(Session["preEditState2"]);
        string vettedtxtSuperCategory = Regex.Replace(txtSuperCategory.Text.ToLower(), "[ \t\n]+", "");

        try
        {
            if (vettedtxtSuperCategory != null && vettedtxtSuperCategory != "" && vettedtxtSuperCategory.Length <= 50 && txtSuperCategory.Text != ddlSuperCategory.Text)
            {
                sds.ConnectionString = Resources.ConnectionStrings.ATHENA;

                sds.SelectCommand = Resources.CatalogManagerSQLQueries.VerifySuper;
                DataSourceSelectArguments dssa = new DataSourceSelectArguments();
                dssa.AddSupportedCapabilities(DataSourceCapabilities.RetrieveTotalRowCount);
                dssa.RetrieveTotalRowCount = true;
                DataView dv = (DataView)sds.Select(dssa);
                if (preEditState == ddlMegaCategory.Text)
                {
                    if (dv.Count == 0)
                    {
                        sds.UpdateCommand = Resources.CatalogManagerSQLQueries.UpdateSuper;
                        sds.Update();
                        sds.InsertCommand = Resources.CatalogManagerSQLQueries.InsertSuper;
                        sds.Insert();
                    }
                }
            }
            preEditState          = String.Empty;
            preEditState2         = String.Empty;
            txtSuperCategory.Text = String.Empty;
        }
        catch (InvalidCastException ex) { }
    }
    protected void btnAddCategory_Click(object sender, EventArgs e)
    {
        string vettedTxtCreateCategory1 = Regex.Replace(txtCreateCategory.Text.Trim(), "[^a-zA-Z0-9 ]+", "");

        try
        {
            string vettedTxtCreateCategory2 = Regex.Replace(vettedTxtCreateCategory1.ToLower(), "[ \n\t]", "");
            if (vettedTxtCreateCategory2 != null && vettedTxtCreateCategory2 != "" && vettedTxtCreateCategory2.Length <= 75 && vettedTxtCreateCategory2.Length >= 4)
            {
                sds.ConnectionString = Resources.ConnectionStrings.ATHENA;

                sds.SelectCommand = Resources.CatalogManagerSQLQueries.FormattedCat;
                DataSourceSelectArguments dssa = new DataSourceSelectArguments();
                dssa.AddSupportedCapabilities(DataSourceCapabilities.RetrieveTotalRowCount);
                dssa.RetrieveTotalRowCount = true;
                DataView dv = (DataView)sds.Select(dssa);

                if (dv.Count == 0)
                {
                    SqlDataAdapter adapter = new SqlDataAdapter();
                    SqlCommand     command = new SqlCommand(Resources.CatalogManagerSQLQueries.InsertNewCategory);
                    command.Connection  = new SqlConnection(sds.ConnectionString);
                    command.CommandType = CommandType.StoredProcedure;

                    command.Parameters.Add("@Mega", SqlDbType.NVarChar, 50).Value  = ddlMegaCategory.Text;
                    command.Parameters.Add("@Super", SqlDbType.NVarChar, 50).Value = ddlSuperCategory.Text;
                    command.Parameters.Add("@Cat", SqlDbType.NVarChar, 50).Value   = txtCreateCategory.Text;

                    adapter.InsertCommand = command;
                    command.Connection.Open();
                    adapter.InsertCommand.ExecuteNonQuery();
                    command.Connection.Dispose();
                }
                else
                {
                    errorMessage.Insert(0, "You're doing it wrong");
                    lblErrorMessage.Text    = string.Join("<br />", errorMessage);
                    lblErrorMessage.Visible = true;
                }
            }
            else
            {
                errorMessage.Insert(0, "You're doing it wrong");
                lblErrorMessage.Text    = string.Join("<br />", errorMessage);
                lblErrorMessage.Visible = true;
            }
        }
        catch (Exception ex)
        {
            errorMessage.Insert(0, "The machine is confused");
            lblErrorMessage.Text           = string.Join("<br />", errorMessage);
            lblErrorMessage.Visible        = true;
            txtCreateCategory.Text         = String.Empty;
            ddlMegaCategory.SelectedIndex  = 0;
            ddlSuperCategory.SelectedIndex = 0;
            ddlCategory.SelectedIndex      = 0;
            ddlSubCategory.SelectedIndex   = 0;
        }
        txtCreateCategory.Text = String.Empty;
    }
Example #5
0
        private void AddSupportedCapabilities(DataSourceSelectArguments arguments)
        {
            if (CanSort)
            {
                arguments.AddSupportedCapabilities(DataSourceCapabilities.Sort);
            }
            if (CanRetrieveTotalRowCount)
            {
                arguments.AddSupportedCapabilities(DataSourceCapabilities.RetrieveTotalRowCount);
            }
            if (CanPage)
            {
                arguments.AddSupportedCapabilities(DataSourceCapabilities.Page);
            }

            arguments.RaiseUnsupportedCapabilitiesError(this);
        }
    protected void btnSubmitSubCategoryChanges_Click(object sender, EventArgs e)
    {
        string preEditState         = (string)(Session["preEditState"]);
        string preEditState2        = (string)(Session["preEditState2"]);
        string vettedtxtSubCategory = Regex.Replace(txtCreateSubCategory.Text.ToLower(), "[ \t\n]+", "");

        try
        {
            if (vettedtxtSubCategory != null && vettedtxtSubCategory != "" && vettedtxtSubCategory.Length <= 50 && txtCreateSubCategory.Text != ddlSubCategory.Text)
            {
                sds.ConnectionString = Resources.ConnectionStrings.ATHENA;

                sds.SelectCommand = Resources.CatalogManagerSQLQueries.VerifySubCat;
                DataSourceSelectArguments dssa = new DataSourceSelectArguments();
                dssa.AddSupportedCapabilities(DataSourceCapabilities.RetrieveTotalRowCount);
                dssa.RetrieveTotalRowCount = true;
                DataView dv = (DataView)sds.Select(dssa);
                if (preEditState == ddlCategory.Text)
                {
                    if (dv.Count == 0)
                    {
                        sds.InsertCommand = Resources.CatalogManagerSQLQueries.InsertSubCat;
                        sds.Insert();

                        sds.UpdateCommand = Resources.CatalogManagerSQLQueries.UpdateSubCat;
                        sds.Update();

                        sds.UpdateCommand = Resources.CatalogManagerSQLQueries.UpdateSubCatInGlobalProduct;
                        sds.Update();

                        sds.InsertCommand = Resources.CatalogManagerSQLQueries.InsertSubCatIntoLog;
                        sds.Insert();
                    }
                }
                if (preEditState != ddlCategory.Text && ddlCategory.SelectedIndex > 1)
                {
                    SqlDataAdapter adapter = new SqlDataAdapter();
                    SqlCommand     command = new SqlCommand(Resources.CatalogManagerSQLQueries.UpdateCatUnderEditSubCat);
                    command.Connection  = new SqlConnection(sds.ConnectionString);
                    command.CommandType = CommandType.StoredProcedure;

                    command.Parameters.Add("@CatInDDL", SqlDbType.NVarChar, 50).Value  = ddlCategory.Text;
                    command.Parameters.Add("@SubCatTxt", SqlDbType.NVarChar, 50).Value = txtCreateSubCategory.Text;

                    adapter.InsertCommand = command;
                    command.Connection.Open();
                    adapter.InsertCommand.ExecuteNonQuery();
                    command.Connection.Dispose();
                }
            }
            preEditState  = String.Empty;
            preEditState2 = String.Empty;
        }
        catch (InvalidCastException ex) { }
    }
Example #7
0
 /// <summary>
 /// Executa a consulta para recupera os itens.
 /// </summary>
 /// <param name="arguments"></param>
 /// <returns></returns>
 protected override System.Collections.IEnumerable ExecuteSelect(DataSourceSelectArguments arguments)
 {
     if (CanPage)
     {
         arguments.AddSupportedCapabilities(DataSourceCapabilities.Page);
     }
     if (CanRetrieveTotalRowCount)
     {
         arguments.AddSupportedCapabilities(DataSourceCapabilities.RetrieveTotalRowCount);
     }
     if (arguments.RetrieveTotalRowCount)
     {
         arguments.TotalRowCount = Count();
     }
     if (_owner.Items is Colosoft.Collections.IVirtualList && arguments.MaximumRows > 0)
     {
         var virtualList = (Colosoft.Collections.IVirtualList)_owner.Items;
         virtualList.Configure(arguments.MaximumRows);
     }
     return(CreateEnumerableData(_owner.Items, arguments));
 }
Example #8
0
        IEnumerable IExcuteableDataSource.Select(DataSourceSelectArguments arguments)
        {
            _mOrderBy = string.IsNullOrEmpty(DefaultOrderBy) ? new OrderBy((DESC)"Id") : OrderBy.Parse(DefaultOrderBy);

            arguments.AddSupportedCapabilities(DataSourceCapabilities.Sort);
            arguments.AddSupportedCapabilities(DataSourceCapabilities.Page);
            arguments.AddSupportedCapabilities(DataSourceCapabilities.RetrieveTotalRowCount);
            string se = arguments.SortExpression;

            if (!string.IsNullOrEmpty(se))
            {
                DefaultOrderBy = se;
                _mOrderBy      = OrderBy.Parse(se, typeof(T));
            }
            int      pageIndex     = (arguments.MaximumRows == 0) ? 0 : arguments.StartRowIndex / arguments.MaximumRows;
            int      totalRowCount = arguments.TotalRowCount;
            List <T> ret           = ExecuteSelect(_condition, _mOrderBy, arguments.MaximumRows, pageIndex, ref totalRowCount);

            arguments.TotalRowCount = totalRowCount;
            return(ret);
        }
Example #9
0
        protected override void PerformSelect()
        {
            if (!IsBoundUsingDataSourceID)
            {
                OnDataBinding(EventArgs.Empty);
            }

            DataSourceView dataSourceView = GetData();

            DataSourceViewSelectCallback callback =
                delegate(IEnumerable data)
            {
                if (IsBoundUsingDataSourceID)
                {
                    OnDataBinding(EventArgs.Empty);
                }
                PerformDataBinding(data);
            };

            if (EnablePaging && dataSourceView.CanPage)
            {
                DataSourceSelectArguments selectArguments = CreateDataSourceSelectArguments();
                selectArguments.StartRowIndex = PageSize * PageIndex;
                selectArguments.MaximumRows   = PageSize;
                dataSourceView.Select(selectArguments, callback);
            }
            else
            {
                DataSourceSelectArguments selectArguments = CreateDataSourceSelectArguments();
                if (dataSourceView.CanPage)
                {
                    selectArguments.AddSupportedCapabilities(DataSourceCapabilities.None);
                    selectArguments.StartRowIndex = 0;
                    selectArguments.MaximumRows   = Int16.MaxValue;
                }
                dataSourceView.Select(selectArguments, callback);
            }

            RequiresDataBinding = false;
            MarkAsDataBound();

            OnDataBound(EventArgs.Empty);
        }
Example #10
0
        private int GetTotalRowCount()
        {
            int            totalRowCount  = 0;
            DataSourceView dataSourceView = GetData();

            if (dataSourceView.CanRetrieveTotalRowCount)
            {
                DataSourceSelectArguments selectArguments = CreateDataSourceSelectArguments();
                selectArguments.AddSupportedCapabilities(DataSourceCapabilities.RetrieveTotalRowCount);
                selectArguments.RetrieveTotalRowCount = true;
                DataSourceViewSelectCallback callback =
                    delegate
                {
                    totalRowCount = selectArguments.TotalRowCount;
                };
                dataSourceView.Select(selectArguments, callback);
            }
            return(totalRowCount);
        }
    protected void ddl_College_FiscalYear_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddl_fiscalyear.SelectedIndex > 0 && ddl_College.SelectedIndex > 0)
        {
            pan_Acc.Visible = true;
            DataSourceSelectArguments dssa = new DataSourceSelectArguments();
            dssa.AddSupportedCapabilities(DataSourceCapabilities.RetrieveTotalRowCount);
            dssa.RetrieveTotalRowCount = true;
            DataView dv = (DataView)SQLDS_Accountablity.Select(dssa);

            Label1.Text = dv.Table.Rows[0][0].ToString();
            hf_Accountability_Id.Value = dv.Table.Rows[0][0].ToString();
            lbl_Acc_Id.Text = dv.Table.Rows[0][0].ToString();
            txt_Note.Text = dv.Table.Rows[0][4].ToString();

            //ds_Level.DataBind();
            dv = (DataView)ds_Level.Select(dssa);
            lbl_Level.Text = dv.Table.Rows[0][1].ToString();
            hf_Level_Id.Value = dv.Table.Rows[0][0].ToString();

            ddl_Acct_Next_Level.DataBind();

            //ds_Acc_Narr.DataBind();
            //SqlDS_Gender.DataBind();
            //SqlDS_Race.DataBind();
            //ds_2p1_Spec_Pop.DataBind();
            //ds_3p1_Spec_Pop.DataBind();
            //ds_4p1_Spec_Pop.DataBind();
            //ds_5p1_Spec_Pop.DataBind();
            //ds_5p2_Spec_Pop.DataBind();
            //ds_Enrollment.DataBind();

            rg_Narratives.DataBind();
            rg_Enrollment.DataBind();
        }
        else
            pan_Acc.Visible = false;
    }
Example #12
0
        protected override IEnumerable ExecuteSelect(DataSourceSelectArguments arguments)
        {
            if (!String.IsNullOrEmpty(Source.FindMethod))
            {
                return(ExecuteCustomSelect(arguments));
            }

            if (CanPage)
            {
                arguments.AddSupportedCapabilities(DataSourceCapabilities.Page);
            }

            if (CanSort)
            {
                arguments.AddSupportedCapabilities(DataSourceCapabilities.Sort);
            }

            if (CanRetrieveTotalRowCount)
            {
                arguments.AddSupportedCapabilities(DataSourceCapabilities.RetrieveTotalRowCount);
            }

            ActiveRecordDataSourceFindEventArgs args = new ActiveRecordDataSourceFindEventArgs();

            CreateCriteriaFromFindParameters(args);
            CreateOrderFromFindParameters(args, arguments.SortExpression);

            //set default sort
            if (args.Order.Count <= 0)
            {
                CreateOrderFromFindParameters(args, Source.DefaultSort);
            }

            args.ModelType = BuildManager.GetType(Source.TypeName, false, true);

            Source.OnBeforeFind(args);

            if (args.Cancel)
            {
                return(null);
            }

            Array result = null;

            try
            {
                if (arguments.RetrieveTotalRowCount)
                {
                    arguments.TotalRowCount = ExecuteCount(args);
                }

                bool useSlicedFind = false;
                int  firstResult   = 0;
                int  maxResults    = 0;

                if (CanPage)
                {
                    useSlicedFind = true;
                    firstResult   = arguments.StartRowIndex;
                    maxResults    = arguments.MaximumRows;
                }
                else if (Source.DefaultMaximumRows > 0)
                {
                    useSlicedFind = true;
                    firstResult   = 0;
                    maxResults    = Source.DefaultMaximumRows;
                }

                if (useSlicedFind)
                {
                    result = ActiveRecordMediator.SlicedFindAll(args.ModelType, firstResult, maxResults, args.Order.ToArray(), args.Criteria.ToArray());
                }
                else
                {
                    result = ActiveRecordMediator.FindAll(args.ModelType, args.Order.ToArray(), args.Criteria.ToArray());
                }
            }
            catch (Exception e)
            {
                args.Exception = e;
                args.WasError  = true;

                Source.OnFindError(args);

                if (Source.ThrowOnError && !args.DoNotThrow)
                {
                    throw;
                }

                return(null);
            }

            args.Result = result;

            Source.OnFind(args);

            return(result);
        }
    protected void ReloadData()
    {
        DataView dv1 = (DataView)sqlds_accountablityCheck.Select(DataSourceSelectArguments.Empty);
            DataSet rowcountds = dv1.Table.DataSet.Copy();
            if (rowcountds.Tables[0].Rows[0][0].ToString() == "0")
            {
                btnCreate.Visible = true;

                lbl_Acc_Id.Text = "";
                lbl_Acc_Id.Visible = false;
                txt_Note.Visible = false;
                lbl_Level.Visible = false;
                hf_Level_Id.Visible = false;
                ddl_Acct_Next_Level.Visible = false;
                btn_Save.Visible = false;
                Label3.Visible = false;
                Label4.Visible = false;
                Label5.Visible = false;
                Label6.Visible = false;
                HL_Errors.Visible = false;
                HL_RPLIST.Visible = false;
                lnkSubmit.Visible = false;
                if (Session[Session.SessionID + "roleid"].ToString() != "101")
                {
                    btnCreate.Visible = false;
                }
                else
                {
                    btnCreate.Visible = true;
                }

                lbl_error.Visible = true;
            }
            else
            {
                btnCreate.Visible = false;
                lbl_error.Visible = false;
                if (ddl_fiscalyear.SelectedIndex > 0)
                {
                    SQLDS_Accountablity.SelectParameters.Clear();
                    SQLDS_Accountablity.SelectParameters.Add("p_key_college_id", ddl_College.SelectedValue);
                    SQLDS_Accountablity.SelectParameters.Add("p_nbr_fiscal_year", ddl_fiscalyear.SelectedValue);
                    SQLDS_Accountablity.SelectParameters.Add("p_txt_created_by", HttpContext.Current.User.Identity.Name.ToString());
                    SQLDS_Accountablity.Select(DataSourceSelectArguments.Empty);

                    DataSourceSelectArguments dssa = new DataSourceSelectArguments();
                    dssa.AddSupportedCapabilities(DataSourceCapabilities.RetrieveTotalRowCount);
                    dssa.RetrieveTotalRowCount = true;
                    DataView dv = (DataView)SQLDS_Accountablity.Select(dssa);

                    hf_Accountability_Id.Value = dv.Table.Rows[0][0].ToString();
                    lbl_Acc_Id.Text = dv.Table.Rows[0][0].ToString();
                    txt_Note.Text = dv.Table.Rows[0][4].ToString();

                    dv = (DataView)ds_Level.Select(dssa);
                    lbl_Level.Text = dv.Table.Rows[0][1].ToString();
                    Session.Add(HttpContext.Current.User.Identity.Name + Session.SessionID + "LevelTitle", lbl_Level.Text);
                    hf_Level_Id.Value = dv.Table.Rows[0][0].ToString();

                    ddl_Acct_Next_Level.DataBind();
                    lbl_Acc_Id.Visible = true;
                    txt_Note.Visible = true;
                    lbl_Level.Visible = true;
                    hf_Level_Id.Visible = true;
                    ddl_Acct_Next_Level.Visible = true;
                    btn_Save.Visible = true;
                    Label3.Visible = true;
                    Label4.Visible = true;
                    Label5.Visible = true;
                    Label6.Visible = true;

                    HL_RPLIST.Visible = true;
                    lnkSubmit.Visible = true;
                }
                else
                {
                    lbl_Acc_Id.Text = "";
                    txt_Note.Text = "";
                    lbl_Level.Text = "";
                    hf_Level_Id.Value = "";
                    //ds_Acct_Next_Level.DataBind();
                    ddl_Acct_Next_Level.Items.Clear();
                    HL_Errors.Visible = false;
                    HL_RPLIST.Visible = false;
                    lnkSubmit.Visible = false;
                }
            }
    }
    protected void btnCreate_Click(object sender, EventArgs e)
    {
        // Create an Accountability Report
        if (ddl_fiscalyear.SelectedIndex > 0)
        {

            SQLDS_Accountablity.InsertParameters.Clear();
            SQLDS_Accountablity.InsertParameters.Add("p_key_college_id", ddl_College.SelectedValue);
            SQLDS_Accountablity.InsertParameters.Add("p_nbr_fiscal_year", ddl_fiscalyear.SelectedValue);
            SQLDS_Accountablity.InsertParameters.Add("p_txt_created_by", HttpContext.Current.User.Identity.Name.ToString());
            SQLDS_Accountablity.Insert();

            SQLDS_Accountablity.SelectParameters.Clear();
            SQLDS_Accountablity.SelectParameters.Add("p_key_college_id", ddl_College.SelectedValue);
            SQLDS_Accountablity.SelectParameters.Add("p_nbr_fiscal_year", ddl_fiscalyear.SelectedValue);
            SQLDS_Accountablity.SelectParameters.Add("p_txt_created_by",HttpContext.Current.User.Identity.Name.ToString());
            SQLDS_Accountablity.Select(DataSourceSelectArguments.Empty);

            DataSourceSelectArguments dssa = new DataSourceSelectArguments();
            dssa.AddSupportedCapabilities(DataSourceCapabilities.RetrieveTotalRowCount);
            dssa.RetrieveTotalRowCount = true;
            DataView dv = (DataView)SQLDS_Accountablity.Select(dssa);

            hf_Accountability_Id.Value = dv.Table.Rows[0][0].ToString();
            lbl_Acc_Id.Text = dv.Table.Rows[0][0].ToString();
            txt_Note.Text = dv.Table.Rows[0][4].ToString();

            dv = (DataView)ds_Level.Select(dssa);
            lbl_Level.Text = dv.Table.Rows[0][1].ToString();
            hf_Level_Id.Value = dv.Table.Rows[0][0].ToString();

            ddl_Acct_Next_Level.DataBind();
            lbl_Acc_Id.Visible = true;
            txt_Note.Visible = true;
            lbl_Level.Visible = true;
            hf_Level_Id.Visible = true;
            ddl_Acct_Next_Level.Visible = true;
            btn_Save.Visible = true;
            Label3.Visible = true;
            Label4.Visible = true;
            Label5.Visible = true;
            Label6.Visible = true;

            HL_RPLIST.Visible = true;
            lnkSubmit.Visible = true;
        }
        else
        {
            lbl_Acc_Id.Text = "";
            txt_Note.Text = "";
            lbl_Level.Text = "";
            hf_Level_Id.Value = "";
            //ds_Acct_Next_Level.DataBind();
            ddl_Acct_Next_Level.Items.Clear();
            HL_Errors.Visible = false;
            HL_RPLIST.Visible = false;
            lnkSubmit.Visible = false;
            btn_Save.Visible = false;
        }

        LoadSession();
        ReloadData();
    }
        protected override IAsyncResult BeginExecuteSelect(
            DataSourceSelectArguments arguments,
            AsyncCallback asyncCallback,
            object asyncState)
        {
            ADXTrace.Instance.TraceInfo(TraceCategory.Application, "Begin");

            if (CanSort)
            {
                arguments.AddSupportedCapabilities(DataSourceCapabilities.Sort);
            }

            if (CanPage)
            {
                arguments.AddSupportedCapabilities(DataSourceCapabilities.Page);
            }

            if (CanRetrieveTotalRowCount)
            {
                arguments.AddSupportedCapabilities(DataSourceCapabilities.RetrieveTotalRowCount);
            }

            string           fetchXml;
            QueryByAttribute query;

            InitializeParameters(out fetchXml, out query);

            // raise pre-event
            CrmDataSourceSelectingEventArgs selectingArgs = new CrmDataSourceSelectingEventArgs(
                Owner,
                arguments,
                fetchXml,
                query);

            OnSelecting(selectingArgs);

            IEnumerable selectResult = null;

            if (selectingArgs.Cancel)
            {
                ADXTrace.Instance.TraceInfo(TraceCategory.Application, "Cancel");
                return(new SynchronousAsyncSelectResult(selectResult, asyncCallback, asyncState));
            }

            // merge event results
            arguments.RaiseUnsupportedCapabilitiesError(this);
            fetchXml = selectingArgs.FetchXml;

            if (CancelSelectOnNullParameter && string.IsNullOrEmpty(fetchXml) && query == null)
            {
                ADXTrace.Instance.TraceInfo(TraceCategory.Application, "CancelSelectOnNullParameter");
                return(new SynchronousAsyncSelectResult(selectResult, asyncCallback, asyncState));
            }

            try
            {
                _client = OrganizationServiceContextFactory.Create(Owner.CrmDataContextName);

                if (!string.IsNullOrEmpty(fetchXml))
                {
                    var fetch = ToFetch(arguments, fetchXml);

                    ADXTrace.Instance.TraceInfo(TraceCategory.Application, "End");

                    return(ExecuteSelect(_client, null, fetch, asyncCallback, asyncState));
                }

                if (query != null)
                {
                    ADXTrace.Instance.TraceInfo(TraceCategory.Application, "QueryByAttribute");

                    // the SortExpression has high priority, apply it to the query
                    AppendSortExpressionToQuery(arguments.SortExpression, order => query.Orders.Add(order));

                    ADXTrace.Instance.TraceInfo(TraceCategory.Application, "End");

                    return(ExecuteSelect(_client, query, null, asyncCallback, asyncState));
                }
            }
            catch (System.Web.Services.Protocols.SoapException ex)
            {
                ADXTrace.Instance.TraceError(TraceCategory.Application, string.Format("{0}\n\n{1}", ex.Detail.InnerXml, ex.ToString()));
            }
            catch (Exception e)
            {
                ADXTrace.Instance.TraceError(TraceCategory.Application, string.Format("Exception: {0}", e.ToString()));

                _client = null;

                return(new SynchronousAsyncSelectResult(e, asyncCallback, asyncState));
            }

            ADXTrace.Instance.TraceInfo(TraceCategory.Application, "End");

            return(new SynchronousAsyncSelectResult(selectResult, asyncCallback, asyncState));
        }
        protected override IEnumerable ExecuteSelect(DataSourceSelectArguments args)
        {
            args.AddSupportedCapabilities(DataSourceCapabilities.Page);
            args.AddSupportedCapabilities(DataSourceCapabilities.RetrieveTotalRowCount);

            args.RaiseUnsupportedCapabilitiesError(this);

            var parameters = Owner.SelectParameters.GetValues(HttpContext.Current, Owner);

            var filter       = GetFilter(args, parameters);
            var logicalNames = GetLogicalNames(args, parameters);
            var pageSize     = GetPageSize(args, parameters);
            var pageNumber   = GetPageNumber(args, parameters, pageSize);
            var queryText    = GetQueryText(args, parameters);
            ContextLanguageInfo contextLanguage;
            var multiLanguageEnabled = TryGetLanguageCode(out contextLanguage);

            if (string.IsNullOrWhiteSpace(queryText) && string.IsNullOrWhiteSpace(filter))
            {
                args.TotalRowCount = 0;

                return(new CrmEntitySearchResultPage(new List <ICrmEntitySearchResult>(), 0, pageNumber, pageSize));
            }

            var provider = SearchManager.GetProvider(Owner.SearchProvider);
            var query    = new CrmEntityQuery(queryText, pageNumber, pageSize, logicalNames, contextLanguage.ContextLanguage, multiLanguageEnabled, filter);

            var selectingArgs = new SearchDataSourceSelectingEventArgs(provider, query);

            Owner.OnSelecting(selectingArgs);

            if (selectingArgs.Cancel)
            {
                args.TotalRowCount = 0;

                return(new CrmEntitySearchResultPage(new List <ICrmEntitySearchResult>(), 0, pageNumber, pageSize));
            }

            try
            {
                using (var searcher = provider.GetIndexSearcher())
                {
                    var results = searcher.Search(query);

                    args.TotalRowCount = results.ApproximateTotalHits;

                    Owner.OnSelected(new SearchDataSourceStatusEventArgs(provider, query, results));

                    return(results);
                }
            }
            catch (Exception e)
            {
                ADXTrace.Instance.TraceError(TraceCategory.Application, e.ToString());

                var selectedArgs = new SearchDataSourceStatusEventArgs(provider, query, new CrmEntitySearchResultPage(new List <ICrmEntitySearchResult>(), 0, pageNumber, pageSize))
                {
                    Exception = e
                };

                Owner.OnSelected(selectedArgs);

                if (!selectedArgs.ExceptionHandled)
                {
                    throw;
                }

                args.TotalRowCount = 0;

                return(new CrmEntitySearchResultPage(new List <ICrmEntitySearchResult>(), 0, pageNumber, pageSize));
            }
        }
    private String GetCurrentLevel_Id()
    {
        try
        {
            DecipherSession myobj = new DecipherSession(Session[Session.SessionID + HttpContext.Current.User.Identity + "accountiblityids"].ToString());
            SQLDS_Accountablity.SelectParameters.Clear();
            SQLDS_Accountablity.SelectParameters.Add("p_key_college_id", myobj.CollID.ToString());
            SQLDS_Accountablity.SelectParameters.Add("p_nbr_fiscal_year", myobj.FiscalYear.ToString());
            SQLDS_Accountablity.Select(DataSourceSelectArguments.Empty);


            DataSourceSelectArguments dssa = new DataSourceSelectArguments();
            dssa.AddSupportedCapabilities(DataSourceCapabilities.RetrieveTotalRowCount);
            dssa.RetrieveTotalRowCount = true;
            DataView dv = (DataView)SQLDS_Accountablity.Select(dssa);


            return dv.Table.Rows[0][3].ToString();
        }
        catch
        {
            return "";
        }

        return "";
    }
        public void RaiseUnsupportedCapabilitiesError()
        {
            PockerDataSourceView      view = new PockerDataSourceView();
            DataSourceSelectArguments arg  = new DataSourceSelectArguments();

            arg.RaiseUnsupportedCapabilitiesError(view);
            Assert.IsFalse(view.RaiseUnsupportedCapabilityErrorCalled, "RaiseUnsupportedCapabilitiesError");

            view = new PockerDataSourceView();
            arg  = new DataSourceSelectArguments();
            arg.StartRowIndex = 10;
            arg.RaiseUnsupportedCapabilitiesError(view);
            Assert.IsTrue(view.RaiseUnsupportedCapabilityErrorCalled, "RaiseUnsupportedCapabilitiesError");
            Assert.AreEqual(DataSourceCapabilities.Page, view.DataSourceCapabilities, "RaiseUnsupportedCapabilitiesError");

            view            = new PockerDataSourceView();
            arg             = new DataSourceSelectArguments();
            arg.MaximumRows = 5;
            arg.RaiseUnsupportedCapabilitiesError(view);
            Assert.IsTrue(view.RaiseUnsupportedCapabilityErrorCalled, "RaiseUnsupportedCapabilitiesError");
            Assert.AreEqual(DataSourceCapabilities.Page, view.DataSourceCapabilities, "RaiseUnsupportedCapabilitiesError");

            view = new PockerDataSourceView();
            arg  = new DataSourceSelectArguments();
            arg.SortExpression = "Sort";
            arg.RaiseUnsupportedCapabilitiesError(view);
            Assert.IsTrue(view.RaiseUnsupportedCapabilityErrorCalled, "RaiseUnsupportedCapabilitiesError");
            Assert.AreEqual(DataSourceCapabilities.Sort, view.DataSourceCapabilities, "RaiseUnsupportedCapabilitiesError");

            view = new PockerDataSourceView();
            arg  = new DataSourceSelectArguments();
            arg.RetrieveTotalRowCount = true;
            arg.RaiseUnsupportedCapabilitiesError(view);
            Assert.IsTrue(view.RaiseUnsupportedCapabilityErrorCalled, "RaiseUnsupportedCapabilitiesError");
            Assert.AreEqual(DataSourceCapabilities.RetrieveTotalRowCount, view.DataSourceCapabilities, "RaiseUnsupportedCapabilitiesError");

            view = new PockerDataSourceView();
            arg  = new DataSourceSelectArguments();
            arg.AddSupportedCapabilities(DataSourceCapabilities.Page | DataSourceCapabilities.Sort | DataSourceCapabilities.RetrieveTotalRowCount);
            arg.SortExpression        = "Sort";
            arg.StartRowIndex         = 10;
            arg.MaximumRows           = 5;
            arg.RetrieveTotalRowCount = true;
            arg.RaiseUnsupportedCapabilitiesError(view);
            Assert.IsFalse(view.RaiseUnsupportedCapabilityErrorCalled, "RaiseUnsupportedCapabilitiesError");

            view = new PockerDataSourceView();
            arg  = new DataSourceSelectArguments();
            arg.SortExpression        = "Sort";
            arg.StartRowIndex         = 10;
            arg.MaximumRows           = 5;
            arg.RetrieveTotalRowCount = true;
            arg.RaiseUnsupportedCapabilitiesError(view);
            Assert.IsTrue(view.RaiseUnsupportedCapabilityErrorCalled, "RaiseUnsupportedCapabilitiesError");
            Assert.AreEqual(DataSourceCapabilities.RetrieveTotalRowCount, view.DataSourceCapabilities, "RaiseUnsupportedCapabilitiesError");

            view = new PockerDataSourceView();
            arg  = new DataSourceSelectArguments();
            arg.SortExpression = "Sort";
            arg.StartRowIndex  = 10;
            arg.MaximumRows    = 5;
            arg.RaiseUnsupportedCapabilitiesError(view);
            Assert.IsTrue(view.RaiseUnsupportedCapabilityErrorCalled, "RaiseUnsupportedCapabilitiesError");
            Assert.AreEqual(DataSourceCapabilities.Page, view.DataSourceCapabilities, "RaiseUnsupportedCapabilitiesError");
        }
        protected internal override IEnumerable ExecuteSelect(DataSourceSelectArguments arguments)
        {
            SqlCacheDependency dependency;

            if (this.SelectCommand.Length == 0)
            {
                return(null);
            }
            DbConnection connection = this._owner.CreateConnection(this._owner.ConnectionString);

            if (connection == null)
            {
                throw new InvalidOperationException(System.Web.SR.GetString("SqlDataSourceView_CouldNotCreateConnection", new object[] { this._owner.ID }));
            }
            DataSourceCache cache          = this._owner.Cache;
            bool            flag           = (cache != null) && cache.Enabled;
            string          sortExpression = arguments.SortExpression;

            if (this.CanPage)
            {
                arguments.AddSupportedCapabilities(DataSourceCapabilities.Page);
            }
            if (this.CanSort)
            {
                arguments.AddSupportedCapabilities(DataSourceCapabilities.Sort);
            }
            if (this.CanRetrieveTotalRowCount)
            {
                arguments.AddSupportedCapabilities(DataSourceCapabilities.RetrieveTotalRowCount);
            }
            if (flag)
            {
                if (this._owner.DataSourceMode != SqlDataSourceMode.DataSet)
                {
                    throw new NotSupportedException(System.Web.SR.GetString("SqlDataSourceView_CacheNotSupported", new object[] { this._owner.ID }));
                }
                arguments.RaiseUnsupportedCapabilitiesError(this);
                DataSet set = this._owner.LoadDataFromCache(0, -1) as DataSet;
                if (set != null)
                {
                    IOrderedDictionary parameterValues = this.FilterParameters.GetValues(this._context, this._owner);
                    if (this.FilterExpression.Length > 0)
                    {
                        SqlDataSourceFilteringEventArgs args = new SqlDataSourceFilteringEventArgs(parameterValues);
                        this.OnFiltering(args);
                        if (args.Cancel)
                        {
                            return(null);
                        }
                    }
                    return(FilteredDataSetHelper.CreateFilteredDataView(set.Tables[0], sortExpression, this.FilterExpression, parameterValues));
                }
            }
            DbCommand command = this._owner.CreateCommand(this.SelectCommand, connection);

            this.InitializeParameters(command, this.SelectParameters, null);
            command.CommandType = GetCommandType(this.SelectCommandType);
            SqlDataSourceSelectingEventArgs e = new SqlDataSourceSelectingEventArgs(command, arguments);

            this.OnSelecting(e);
            if (e.Cancel)
            {
                return(null);
            }
            string sortParameterName = this.SortParameterName;

            if (sortParameterName.Length > 0)
            {
                if (command.CommandType != CommandType.StoredProcedure)
                {
                    throw new NotSupportedException(System.Web.SR.GetString("SqlDataSourceView_SortParameterRequiresStoredProcedure", new object[] { this._owner.ID }));
                }
                command.Parameters.Add(this._owner.CreateParameter(this.ParameterPrefix + sortParameterName, sortExpression));
                arguments.SortExpression = string.Empty;
            }
            arguments.RaiseUnsupportedCapabilitiesError(this);
            sortExpression = arguments.SortExpression;
            if (this.CancelSelectOnNullParameter)
            {
                int count = command.Parameters.Count;
                for (int i = 0; i < count; i++)
                {
                    DbParameter parameter = command.Parameters[i];
                    if (((parameter != null) && (parameter.Value == null)) && ((parameter.Direction == ParameterDirection.Input) || (parameter.Direction == ParameterDirection.InputOutput)))
                    {
                        return(null);
                    }
                }
            }
            this.ReplaceNullValues(command);
            IEnumerable enumerable = null;

            switch (this._owner.DataSourceMode)
            {
            case SqlDataSourceMode.DataReader:
            {
                if (this.FilterExpression.Length > 0)
                {
                    throw new NotSupportedException(System.Web.SR.GetString("SqlDataSourceView_FilterNotSupported", new object[] { this._owner.ID }));
                }
                if (sortExpression.Length > 0)
                {
                    throw new NotSupportedException(System.Web.SR.GetString("SqlDataSourceView_SortNotSupported", new object[] { this._owner.ID }));
                }
                bool flag4 = false;
                try
                {
                    if (connection.State != ConnectionState.Open)
                    {
                        connection.Open();
                    }
                    enumerable = command.ExecuteReader(CommandBehavior.CloseConnection);
                    flag4      = true;
                    SqlDataSourceStatusEventArgs args6 = new SqlDataSourceStatusEventArgs(command, 0, null);
                    this.OnSelected(args6);
                }
                catch (Exception exception2)
                {
                    bool flag5;
                    if (!flag4)
                    {
                        SqlDataSourceStatusEventArgs args7 = new SqlDataSourceStatusEventArgs(command, 0, exception2);
                        this.OnSelected(args7);
                        if (!args7.ExceptionHandled)
                        {
                            throw;
                        }
                        return(enumerable);
                    }
                    exception2 = this.BuildCustomException(exception2, DataSourceOperation.Select, command, out flag5);
                    if (flag5)
                    {
                        throw exception2;
                    }
                    throw;
                }
                return(enumerable);
            }

            case SqlDataSourceMode.DataSet:
                dependency = null;
                if (flag && (cache is SqlDataSourceCache))
                {
                    SqlDataSourceCache cache2 = (SqlDataSourceCache)cache;
                    if (string.Equals(cache2.SqlCacheDependency, "CommandNotification", StringComparison.OrdinalIgnoreCase))
                    {
                        if (!(command is SqlCommand))
                        {
                            throw new InvalidOperationException(System.Web.SR.GetString("SqlDataSourceView_CommandNotificationNotSupported", new object[] { this._owner.ID }));
                        }
                        dependency = new SqlCacheDependency((SqlCommand)command);
                        break;
                    }
                }
                break;

            default:
                return(enumerable);
            }
            DbDataAdapter adapter      = this._owner.CreateDataAdapter(command);
            DataSet       dataSet      = new DataSet();
            int           affectedRows = 0;
            bool          flag2        = false;

            try
            {
                affectedRows = adapter.Fill(dataSet, base.Name);
                flag2        = true;
                SqlDataSourceStatusEventArgs args3 = new SqlDataSourceStatusEventArgs(command, affectedRows, null);
                this.OnSelected(args3);
            }
            catch (Exception exception)
            {
                if (flag2)
                {
                    bool flag3;
                    exception = this.BuildCustomException(exception, DataSourceOperation.Select, command, out flag3);
                    if (flag3)
                    {
                        throw exception;
                    }
                    throw;
                }
                SqlDataSourceStatusEventArgs args4 = new SqlDataSourceStatusEventArgs(command, affectedRows, exception);
                this.OnSelected(args4);
                if (!args4.ExceptionHandled)
                {
                    throw;
                }
            }
            finally
            {
                if (connection.State == ConnectionState.Open)
                {
                    connection.Close();
                }
            }
            DataTable table = (dataSet.Tables.Count > 0) ? dataSet.Tables[0] : null;

            if (flag && (table != null))
            {
                this._owner.SaveDataToCache(0, -1, dataSet, dependency);
            }
            if (table == null)
            {
                return(enumerable);
            }
            IOrderedDictionary values = this.FilterParameters.GetValues(this._context, this._owner);

            if (this.FilterExpression.Length > 0)
            {
                SqlDataSourceFilteringEventArgs args5 = new SqlDataSourceFilteringEventArgs(values);
                this.OnFiltering(args5);
                if (args5.Cancel)
                {
                    return(null);
                }
            }
            return(FilteredDataSetHelper.CreateFilteredDataView(table, sortExpression, this.FilterExpression, values));
        }
Example #20
0
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        Clear();
        string        connectionStr = ConfigurationManager.ConnectionStrings["UcccPubMedDB"].ConnectionString;
        SqlConnection myConnection  = new SqlConnection(connectionStr);
        string        sqlStatement  = "";
        string        sqlStatement2 = "";
        string        sqlStatement3 = "";

        if (txtPmid.Text != "" || txtPmcid.Text != "")
        {
            if (txtPmid.Text != "")
            {
                sqlStatement =
                    "select p.*,pp.authorlist, lyn.description as final_confirm, pp.review_editorial" +
                    " from publication p" +
                    " inner join publication_processing pp on p.publication_id = pp.publication_id" +
                    " left outer join l_yes_no lyn" +
                    " on pp.final_confirm_id = lyn.l_yes_no_id" +
                    " where p.pmid = " + txtPmid.Text;

                sqlStatement2 =
                    "select pp.publication_program_id," +
                    " lp.abbreviation as program," +
                    " case when lfg.group_number >= 0 then" +
                    " 'FG ' + convert(varchar,lfg.group_number) + '-' + lfg.description" +
                    " else lfg.description end" +
                    " as focus_group" +
                    " from publication_program pp" +
                    " inner join publication p" +
                    " on pp.publication_id = p.publication_id" +
                    " inner join l_program lp" +
                    " on pp.l_program_id = lp.l_program_id" +
                    " left outer join l_focus_group lfg" +
                    " on pp.l_focus_group_id = lfg.l_focus_group_id" +
                    " where p.pmid = " +
                    txtPmid.Text;

                sqlStatement3 =
                    "select" +
                    " lr.description as resource" +
                    " from publication_resource pr" +
                    " inner join publication p" +
                    " on pr.publication_id = p.publication_id" +
                    " inner join l_resource lr" +
                    " on pr.l_resource_id = lr.l_resource_id" +
                    " where p.pmid = " +
                    txtPmid.Text;
            }
            else if (txtPmcid.Text != "")
            {
                sqlStatement =
                    "select p.*,pp.authorlist, lyn.description as final_confirm, pp.review_editorial" +
                    " from publication p" +
                    " inner join publication_processing pp on p.publication_id = pp.publication_id" +
                    " left outer join l_yes_no lyn" +
                    " on pp.final_confirm_id = lyn.l_yes_no_id" +
                    " where p.pmcid = '" + txtPmcid.Text + "'";

                sqlStatement2 =
                    "select pp.publication_program_id," +
                    " lp.abbreviation as program," +
                    " case when lfg.group_number >= 0 then" +
                    " 'FG ' + convert(varchar,lfg.group_number) + '-' + lfg.description" +
                    " else lfg.description end" +
                    " as focus_group" +
                    " from publication_program pp" +
                    " inner join publication p" +
                    " on pp.publication_id = p.publication_id" +
                    " inner join l_program lp" +
                    " on pp.l_program_id = lp.l_program_id" +
                    " left outer join l_focus_group lfg" +
                    " on pp.l_focus_group_id = lfg.l_focus_group_id" +
                    " where p.pmcid = '" +
                    txtPmcid.Text + "'";

                sqlStatement3 =
                    "select" +
                    " lr.description as resource" +
                    " from publication_resource pr" +
                    " inner join publication p" +
                    " on pr.publication_id = p.publication_id" +
                    " inner join l_resource lr" +
                    " on pr.l_resource_id = lr.l_resource_id" +
                    " where p.pmcid = '" +
                    txtPmcid.Text + "'";
            }
            SqlDataSource ds = new SqlDataSource(connectionStr, sqlStatement);
            dvPublication.DataSource = ds;

            DataSourceSelectArguments dssa = new DataSourceSelectArguments();
            dssa.AddSupportedCapabilities(DataSourceCapabilities.RetrieveTotalRowCount);
            dssa.RetrieveTotalRowCount = true;
            DataView dv = (DataView)ds.Select(dssa);
            if (dv.Table.Rows.Count > 0)
            {
                dvPublication.DataBind();
                btnEdit.Visible = true;
            }
            else
            {
                ErrorMessage.Text = "No pub in database. You can import it.";
                btnImport.Visible = true;
            }

            SqlDataSource ds2 = new SqlDataSource(connectionStr, sqlStatement2);
            gvProgram.DataSource = ds2;
            gvProgram.DataBind();

            SqlDataSource ds3 = new SqlDataSource(connectionStr, sqlStatement3);
            gvResource.DataSource = ds3;
            gvResource.DataBind();
        }
        else if (txtTitle.Text != "")
        {
            sqlStatement =
                "select p.publication_id," +
                " p.pmid," +
                " p.article_title" +
                " from publication p" +
                " where p.article_title like '%" +
                txtTitle.Text +
                "%'";

            Helper.BindGridview(sqlStatement, gvPublication);
        }
        else if (txtLastName.Text != "")
        {
            sqlStatement =
                "select p.publication_id," +
                " p.pmid," +
                " p.article_title" +
                " from publication p" +
                " inner join publication_processing pp" +
                " on p.publication_id = pp.publication_id" +
                " where pp.authorlist like '%" +
                txtLastName.Text +
                "%'";

            Helper.BindGridview(sqlStatement, gvPublication);
        }
    }
Example #21
0
        protected Array ExecuteCustomSelect(DataSourceSelectArguments arguments)
        {
            if (CanPage)
            {
                arguments.AddSupportedCapabilities(DataSourceCapabilities.Page);
            }

            if (CanSort)
            {
                arguments.AddSupportedCapabilities(DataSourceCapabilities.Sort);
            }

            if (CanRetrieveTotalRowCount)
            {
                arguments.AddSupportedCapabilities(DataSourceCapabilities.RetrieveTotalRowCount);
            }

            ActiveRecordDataSourceFindEventArgs args = new ActiveRecordDataSourceFindEventArgs();

            CreateOrderFromFindParameters(args, arguments.SortExpression);

            if (args.Order.Count <= 0)
            {
                CreateOrderFromFindParameters(args, Source.DefaultSort);
            }

            args.ModelType = BuildManager.GetType(Source.TypeName, false, true);

            Source.OnBeforeFind(args);

            if (args.Cancel)
            {
                return(null);
            }

            bool useSlicedFind = false;
            int  firstResult   = 0;
            int  maxResults    = 0;

            if (CanPage)
            {
                useSlicedFind = true;
                firstResult   = arguments.StartRowIndex;
                maxResults    = arguments.MaximumRows;
            }
            else if (Source.DefaultMaximumRows > 0)
            {
                useSlicedFind = true;
                firstResult   = 0;
                maxResults    = Source.DefaultMaximumRows;
            }

            Dictionary <string, object> methodParameters = CreateMethodParametersFromFindParameters();

            if (!String.IsNullOrEmpty(Source.FindMethodFirstResultParam) && useSlicedFind)
            {
                methodParameters[Source.FindMethodFirstResultParam] = firstResult;
            }

            if (!String.IsNullOrEmpty(Source.FindMethodMaxResultsParam) && useSlicedFind)
            {
                methodParameters[Source.FindMethodMaxResultsParam] = maxResults;
            }

            if (!String.IsNullOrEmpty(Source.FindMethodOrderParam) && CanSort)
            {
                methodParameters[Source.FindMethodOrderParam] = args.Order.ToArray();
            }

            Array result = null;

            try
            {
                if (arguments.RetrieveTotalRowCount)
                {
                    arguments.TotalRowCount = ExecuteCount(args);
                }

                MethodInfo findMethod;
                Dictionary <string, int> methodParameterNameToIndex;

                ResolveCustomFindMethod(args.ModelType, methodParameters, out findMethod, out methodParameterNameToIndex);

                if (findMethod == null)
                {
                    throw new ApplicationException(String.Format("Invalid custom find method '{0}'.", Source.FindMethod));
                }

                object[] findMethodArgs = new object[methodParameters.Keys.Count];

                foreach (string key in methodParameters.Keys)
                {
                    findMethodArgs[methodParameterNameToIndex[key]] = methodParameters[key];
                }

                result = findMethod.Invoke(null, findMethodArgs) as Array;
            }
            catch (Exception e)
            {
                args.Exception = e;
                args.WasError  = true;

                Source.OnFindError(args);

                if (Source.ThrowOnError && !args.DoNotThrow)
                {
                    throw;
                }

                return(null);
            }

            args.Result = result;

            Source.OnFind(args);

            return(result);
        }
Example #22
0
        protected override IEnumerable ExecuteSelect(DataSourceSelectArguments arguments)
        {
            Tracing.FrameworkInformation("CrmMetadataDataSourceView", "ExecuteSelect", "Begin");

            if (CanSort)
            {
                arguments.AddSupportedCapabilities(DataSourceCapabilities.Sort);
            }

            if (CanPage)
            {
                arguments.AddSupportedCapabilities(DataSourceCapabilities.Page);
            }

            if (CanRetrieveTotalRowCount)
            {
                arguments.AddSupportedCapabilities(DataSourceCapabilities.RetrieveTotalRowCount);
            }

            // merge SelectParameters
            IOrderedDictionary parameters = SelectParameters.GetValues(Context, Owner);

            string sortExpression = GetNonNullOrEmpty(
                arguments.SortExpression,
                parameters[_sortExpressionParameterName] as string,
                SortExpression);
            string entityName = GetNonNullOrEmpty(
                parameters[_entityNameParameterName] as string,
                EntityName);
            string attributeName = GetNonNullOrEmpty(
                parameters[_attributeNameParameterName] as string,
                AttributeName);

            var metadataFlags = MetadataFlags;

            if (parameters.Contains(_metadataFlagsParameterName))
            {
                metadataFlags = (parameters[_metadataFlagsParameterName] as string).ToEnum <EntityFilters>();
            }

            var entityFlags = EntityFlags;

            if (parameters.Contains(_entityFlagsParameterName))
            {
                entityFlags = (parameters[_entityFlagsParameterName] as string).ToEnum <EntityFilters>();
            }

            // raise pre-event
            CrmMetadataDataSourceSelectingEventArgs selectingArgs = new CrmMetadataDataSourceSelectingEventArgs(
                Owner,
                arguments,
                entityName,
                attributeName,
                metadataFlags,
                entityFlags,
                sortExpression);

            OnSelecting(selectingArgs);

            if (selectingArgs.Cancel)
            {
                Tracing.FrameworkInformation("CrmMetadataDataSourceView", "ExecuteSelect", "Cancel");
                return(null);
            }

            // merge event results
            arguments.RaiseUnsupportedCapabilitiesError(this);
            sortExpression = selectingArgs.SortExpression;
            entityName     = selectingArgs.EntityName;
            attributeName  = selectingArgs.AttributeName;
            metadataFlags  = selectingArgs.MetadataFlags;
            entityFlags    = selectingArgs.EntityFlags;

            if (CancelSelectOnNullParameter && string.IsNullOrEmpty(entityName) && string.IsNullOrEmpty(attributeName))
            {
                Tracing.FrameworkInformation("CrmMetadataDataSourceView", "ExecuteSelect", "CancelSelectOnNullParameter");
                return(null);
            }

            IEnumerable result       = null;
            int         rowsAffected = 0;

            try
            {
                if (Owner.CacheParameters.Enabled)
                {
                    var cacheKey = GetCacheKey(metadataFlags, entityFlags, entityName, attributeName, sortExpression);

                    result = ObjectCacheManager.Get(cacheKey,
                                                    cache =>
                    {
                        var metadata = ExecuteSelect(entityName, attributeName, sortExpression, entityFlags, metadataFlags, out rowsAffected);
                        return(metadata);
                    },
                                                    (cache, metadata) =>
                    {
                        if (metadata != null)
                        {
                            var dependencies = GetCacheDependencies(metadata);
                            cache.Insert(cacheKey, metadata, dependencies);
                        }
                    });
                }
                else
                {
                    result = ExecuteSelect(entityName, attributeName, sortExpression, entityFlags, metadataFlags, out rowsAffected);
                }
            }
            catch (System.Web.Services.Protocols.SoapException ex)
            {
                Tracing.FrameworkError("CrmMetadataDataSourceView", "ExecuteSelect", "{0}\n\n{1}", ex.Detail.InnerXml, ex);
            }
            catch (Exception e)
            {
                Tracing.FrameworkError("CrmMetadataDataSourceView", "ExecuteSelect", "Exception: {0}", e);

                // raise post-event with exception
                CrmMetadataDataSourceStatusEventArgs selectedExceptionArgs = new CrmMetadataDataSourceStatusEventArgs(0, e);
                OnSelected(selectedExceptionArgs);

                if (!selectedExceptionArgs.ExceptionHandled)
                {
                    throw;
                }

                return(result);
            }

            // raise post-event
            CrmMetadataDataSourceStatusEventArgs selectedArgs = new CrmMetadataDataSourceStatusEventArgs(rowsAffected, null);

            OnSelected(selectedArgs);

            Tracing.FrameworkInformation("CrmMetadataDataSourceView", "ExecuteSelect", "End");

            return(result);
        }