Exemple #1
0
    /// <summary>
    ///
    /// </summary>
    /// <returns></returns>
    private IList <string> GetSelectedIds(string selectionKey)
    {
        List <string> ids = new List <string>();

        if (selectionKey == "selectAll")
        {
            GroupContextService groupContextService = ApplicationContext.Current.Services.Get <IGroupContextService>() as GroupContextService;
            if (groupContextService != null)
            {
                CachedGroup currentGroup = groupContextService.GetGroupContext().CurrentGroupInfo.CurrentGroup;
                ids = currentGroup.GetIdList();
            }
        }
        else
        {
            ISelectionService srv = SelectionServiceRequest.GetSelectionService();
            ISelectionContext selectionContext = srv.GetSelectionContext(selectionKey);
            ids = selectionContext.GetSelectedIds();
        }

        return(ids);
    }
    protected void LoadGrid()
    {
        if (this.Visible)
        {
            GenerateScript();

            EnableEstCloseControls();

            GroupContext groupContext = GroupContext.GetGroupContext();

            string fromSQL   = null;
            string whereSQL  = null;
            string selectSQL = null;
            string groupSQL  = null;
            //string joinSQL = null;
            IList <DbParameter> parameters;


            if (groupContext.CurrentGroupID != "LOOKUPRESULTS")
            {
                GroupInfo groupInfo = new GroupInfo();
                groupInfo.GroupID = groupContext.CurrentGroupID;
                fromSQL           = groupInfo.FromSQL;
                whereSQL          = groupInfo.WhereSQL;
                parameters        = groupInfo.Parameters;
            }
            else
            {
                CachedGroup groupInfo = groupContext.CurrentGroupInfo.CurrentGroup;
                fromSQL    = groupInfo.GroupInformation.FromSQL;
                whereSQL   = groupInfo.GroupInformation.WhereSQL;
                parameters = groupInfo.GroupInformation.Parameters;
            }

            // the joing caused ambiguous columns in the select clause so aliases had to be specified.
            // I made an assumption that opportunity is a required table and that the format of the
            // query would remain the same.  Shaky at best, I know.
            //string opportunityAlias = null;
            //int startIndex = fromSQL.ToLower().IndexOf("opportunity ") + "opportunity ".Length;
            //int stringLength = fromSQL.ToLower().IndexOf(" ", startIndex);
            //opportunityAlias = fromSQL.Substring(startIndex, stringLength - startIndex);

            //if (whereSQL != "")
            //    whereSQL = " WHERE " + whereSQL;
            //selectSQL = "SELECT opportunityid, " + opportunityAlias + ".description, estimatedclose, closeprobability, addtoforecast, " + opportunityAlias + ".notes, salespotential, UserInfoCustom.LastName + ', ' + UserInfoCustom.FirstName as AccountManager";
            //joinSQL = "LEFT OUTER JOIN USERINFO UserInfoCustom ON (" + opportunityAlias + ".AccountManagerId = UserInfoCustom.USERID)";
            //groupSQL = selectSQL + " FROM " + fromSQL + " " + joinSQL + " " + whereSQL;

            if (whereSQL != "")
            {
                whereSQL = " WHERE " + whereSQL;
            }
            selectSQL = "SELECT opportunityid, description, estimatedclose, closeprobability, accountmanagerid, addtoforecast, notes, salespotential";
            groupSQL  = selectSQL + " FROM " + fromSQL + " " + whereSQL;

            var vConn    = GroupInfo.GetOpenConnection();
            var vAdapter = new OleDbDataAdapter(groupSQL, vConn as OleDbConnection);
            foreach (DbParameter p in parameters)
            {
                vAdapter.SelectCommand.Parameters.Add(p);
            }

            DataTable dt = new DataTable();
            try
            {
                using (new SparseQueryScope())
                {
                    vAdapter.Fill(dt);
                }
            }
            catch
            {
                //throw new GroupInfoException(string.Format("Error Executing SQL", groupSQL), e);
                throw new Exception("Error Executing SQL");
            }
            finally
            {
                vConn.Close();
            }

            UpdateOppsGrid.DataSource = dt;
            UpdateOppsGrid.DataBind();
            CalcOppValues();
        }
    }