private void cargarCombo()
 {
     SubSonic.Select ef = new SubSonic.Select();
     ef.From(SysEfector.Schema);
     ef.Where(SysEfector.Columns.IdZona).IsEqualTo(9);
     ef.And(SysEfector.Columns.Complejidad).IsEqualTo(2);
     ef.OrderAsc("nombre");
     ddlEfector.DataSource = ef.ExecuteTypedList <SysEfector>();
     ddlEfector.DataBind();
     ddlEfector.Items.Insert(0, new ListItem("TODOS", "0"));
 }
Exemple #2
0
        /// <summary>
        /// Handles the <see cref="E:System.Web.UI.Control.Init"/> event.
        /// </summary>
        /// <param name="e">An <see cref="T:System.EventArgs"/> object that contains the event data.</param>
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            if (!DesignMode)
            {
                // load em up
                // cheap way to check for load state
                if (Items.Count == 0)
                {
                    if (!String.IsNullOrEmpty(tableName))
                    {
                        DataProvider provider = DataService.GetInstance(ProviderName);
                        SqlQuery     q        = new Select(provider).From(tableName);
                        q.CheckLogicalDelete();

                        if (String.IsNullOrEmpty(valueField) || String.IsNullOrEmpty(textField))
                        {
                            // look it up using the table schema
                            TableSchema.Table tbl = DataService.GetSchema(tableName, providerName, TableType.Table);
                            if (tbl != null)
                            {
                                if (String.IsNullOrEmpty(valueField))
                                {
                                    valueField = tbl.PrimaryKey.ColumnName;
                                }

                                if (String.IsNullOrEmpty(textField))
                                {
                                    textField = tbl.Columns.Count > 1 ? tbl.Columns[1].ColumnName : tbl.Columns[0].ColumnName;
                                }
                            }
                            else
                            {
                                throw new Exception("Table name '" + tableName + "' using Provider '" + providerName + "' doesn't work");
                            }
                        }

                        q.SelectColumnList = new[] { valueField, textField };
                        if (!String.IsNullOrEmpty(OrderField))
                        {
                            q.OrderAsc(OrderField);
                        }
                        else
                        {
                            q.OrderAsc(textField);
                        }

                        if (!String.IsNullOrEmpty(WhereField))
                        {
                            q.Where(WhereField).IsEqualTo(WhereValue);
                        }

                        IDataReader rdr = null;

                        try
                        {
                            rdr = q.ExecuteReader();
                            while (rdr.Read())
                            {
                                ListItem item = new ListItem(rdr[1].ToString(), rdr[0].ToString());
                                Items.Add(item);
                            }
                        }
                        catch (DataException x)
                        {
                            throw new Exception("Error loading up ListItems for " + ClientID + ": " + x.Message);
                        }
                        finally
                        {
                            if (rdr != null)
                            {
                                rdr.Close();
                            }
                        }

                        ListItem prompt = new ListItem(promptText, PromptValue);
                        if (showPrompt)
                        {
                            Items.Insert(0, prompt);
                        }

                        if (!String.IsNullOrEmpty(SelectedValue))
                        {
                            foreach (ListItem item in Items)
                            {
                                if (Utility.IsMatch(item.Value, SelectedValue))
                                {
                                    item.Selected = true;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Loads the grid.
        /// </summary>
        private void LoadGrid()
        {
            if (String.IsNullOrEmpty(tableName))
            {
                throw new ArgumentException("No tableName property set - please be sure to set the name of the table or view you'd like to see", tableName);
            }

            DecideSortDirection();

            //load the data
            DataProvider provider = DataService.GetInstance(ProviderName);
            SqlQuery     q        = new Select(provider).From(tableName);

            //set the select list
            StringBuilder selectList = new StringBuilder("*");

            if (!String.IsNullOrEmpty(columnList))
            {
                selectList = new StringBuilder();
                for (int i = 0; i < colList.Count; i++)
                {
                    selectList.Append(colList[i].ToString().Trim());
                    if (i + 1 < colList.Count)
                    {
                        selectList.Append(",");
                    }
                }
            }

            q.SelectColumnList = selectList.ToString().Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            //sorting
            if (!String.IsNullOrEmpty(sortBy))
            {
                TableSchema.TableColumn col = provider.GetTableSchema(tableName, TableType.Table).GetColumn(sortBy);
                if (col != null && col.MaxLength < 2048 && col.DataType != DbType.Binary && col.DataType != DbType.Byte)
                {
                    if (String.IsNullOrEmpty(sortDirection) || sortDirection.Trim() == SqlFragment.ASC.Trim())
                    {
                        q.OrderAsc(sortBy);
                    }
                    else
                    {
                        q.OrderDesc(sortBy);
                    }
                }
            }

            //paging
            if (pageSize > 0)
            {
                q.Paged(pageIndex, pageSize);
                ddlPages.SelectedValue = pageIndex.ToString();
            }

            //honor logical deletes
            q.CheckLogicalDelete();

            //where
            if (!String.IsNullOrEmpty(whereExpression))
            {
                q.WhereExpression(whereExpression);
            }

            SqlQueryBridge.AddLegacyWhereCollection(q, whereCollection);

            DataSet ds = q.ExecuteDataSet();

            if (ds.Tables.Count > 0)
            {
                dataSource = ds.Tables[0];
            }
            else
            {
                throw new Exception("Bad query - no data returned. Did you set the correct provider?");
            }

            EnsureTotals(q);
            //set the buttons
            SetPagingButtonState();
            //create a table
            BuildRows();
        }