Example #1
0
        /// <summary>
        /// 构造列表数据字段数组,此过程在Initialize()过程中被自动调用
        /// </summary>
        protected virtual void ConstructFelds()
        {
            if (!String.IsNullOrEmpty(ShowFields))
            {
                //构造显示的数据字段
                string[] tmpFields = ShowFields.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

                foreach (string item in tmpFields)
                {
                    if (!Fields.Contains(item))
                    {
                        Fields.Add(item);
                    }
                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
//            if (!IsPostBack)
            {
                // extract URL parameters
                if (Request.Params["UCE"] != null)
                {
                    UserControlForEditing = Request.Params["UCE"];
                }
                if (Request.Params["BO"] != null)
                {
                    BaseObject = Request.Params["BO"];
                }
                if (Request.Params["SF"] != null)
                {
                    ShowFields = Request.Params["SF"];
                }
                if (Request.Params["DF"] != null)
                {
                    DisplayFields = Request.Params["DF"];
                }
                if (Request.Params["SEL"] != null)
                {
                    SelectionField = Request.Params["SEL"];
                }
                if (Request.Params["ID"] != null)
                {
                    SelectionID = Request.Params["ID"];
                }
                if (Request.Params["ORD"] != null)
                {
                    OrderField = Request.Params["ORD"];
                }
                if (Request.Params["LNK"] != null)
                {
                    LinkField = Request.Params["LNK"];
                }

                // configure the entity data source
                // use the commandtext to specify the query
                string Query = "select " + ShowFields + " from " + BaseObject + " where " + SelectionField + "=@Par order by " + OrderField;
                EntityDataSourceLinks.CommandText = Query;
                EntityDataSourceLinks.CommandParameters.Clear();
                EntityDataSourceLinks.CommandParameters.Add("Par", System.Data.DbType.Guid, SelectionID);

                // now generate the columns
                GridView1.AutoGenerateColumns = false;
                string[] FieldList  = ShowFields.Split(',');
                string[] FieldNames = DisplayFields.Split(',');
                for (int i = 0; i < FieldList.Count(); i++)
                {
                    BoundField bc = new BoundField();

                    bc.DataField  = FieldList[i];
                    bc.HeaderText = FieldList[i];
                    if (FieldNames.Count() > i)
                    {
                        bc.HeaderText = FieldNames[i];
                    }
                    bc.Visible = bc.HeaderText.ToUpper() != "X";

                    // strip of leading this like it.
                    if (bc.DataField.IndexOf('.') > 0)
                    {
                        bc.DataField = bc.DataField.Split('.')[1];
                    }
                    if (bc.HeaderText.IndexOf('.') > 0)
                    {
                        bc.HeaderText = bc.HeaderText.Split('.')[1];
                    }

                    GridView1.Columns.Add(bc);
                }
            }
        }
Example #3
0
        internal override string show()
        {
            StringBuilder sb = new StringBuilder();

            if (String.IsNullOrEmpty(EntityName))
            {
                return(Provider.GetResource("Select entity"));
            }

            Cinar.Database.Table tbl = Provider.Database.Tables[EntityName];
            if (tbl == null)
            {
                return(Provider.GetResource("The table [entityName] coulnd't be found").Replace("[entityName]", EntityName));
            }

            string         pageUrl   = Provider.Request.Url.Scheme + "://" + Provider.Request.Url.Authority + Provider.Request.RawUrl;
            CinarUriParser uriParser = new CinarUriParser(pageUrl);

            if (!String.IsNullOrEmpty(Provider.Request["delete"]))
            {
                deleteEntity();
                uriParser.QueryPart.Remove("delete");
                pageUrl = uriParser.ToString();
            }

            BaseEntity testEntity = Provider.CreateEntity(EntityName);

            if (String.IsNullOrEmpty(ShowFields))
            {
                ShowFields = String.Format("{0},Visible", testEntity.GetNameColumn());
            }

            StringBuilder sbFrom = new StringBuilder();

            sbFrom.AppendFormat("[{0}]\n", EntityName);

            // generate SQL
            string[] showFieldsArr       = ShowFields.Split(',');
            string[] showFieldsArrWithAs = new string[showFieldsArr.Length];
            for (int i = 0; i < showFieldsArr.Length; i++)
            {
                string       field = showFieldsArr[i];
                PropertyInfo pi    = testEntity.GetType().GetProperty(field);
                EditFormFieldPropsAttribute attrib     = (EditFormFieldPropsAttribute)CMSUtility.GetAttribute(pi, typeof(EditFormFieldPropsAttribute));
                ColumnDetailAttribute       fieldProps = (ColumnDetailAttribute)CMSUtility.GetAttribute(pi, typeof(ColumnDetailAttribute));

                string caption = Provider.GetResource(pi.DeclaringType.Name + "." + pi.Name);

                if (fieldProps.References != null)
                {
                    BaseEntity testRefEntity = Provider.CreateEntity(fieldProps.References.Name);
                    showFieldsArrWithAs[i] = "T" + field + "." + testRefEntity.GetNameColumn() + " as [" + caption + "]";

                    sbFrom.AppendFormat("\tleft join [{0}] as {1} ON {1}.{2} = [{3}].{4}\n", fieldProps.References.Name, "T" + field, "Id", EntityName, field);
                }
                else
                {
                    showFieldsArrWithAs[i] = EntityName + "." + field + " as [" + caption + "]";
                }
            }
            ShowFields = String.Join(",", showFieldsArrWithAs);
            ShowFields = EntityName + ".Id," + ShowFields;

            FilterParser filterParser = new FilterParser(this.Filter, EntityName);

            string where = filterParser.GetWhere();

            int pageNo = 0;

            Int32.TryParse(Provider.Request["pageNo"], out pageNo);

            string sql = Provider.Database.AddPagingToSQL(String.Format(@"
                select
                    {0}
                from
                    {1}
                where
                    1=1 {2}
                order by
                    {3} {4}
            ",
                                                                        ShowFields,
                                                                        sbFrom.ToString(),
                                                                        String.IsNullOrEmpty(where) ? "" : ("and " + where),
                                                                        EntityName + "." + this.OrderBy,
                                                                        this.Ascending ? "asc" : "desc"),
                                                          HowManyItems,
                                                          pageNo);

            DataTable dt = Provider.Database.GetDataTable(sql, filterParser.GetParams());

            sb.Append("<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">\n");

            // header
            sb.Append("<tr class=\"header\">\n");
            for (int i = 0; i < dt.Columns.Count; i++)
            {
                if (i == 0)
                {
                    continue;
                }
                string colName = dt.Columns[i].ColumnName;
                string img     = "";
                uriParser.QueryPart["orderBy"] = showFieldsArr[i - 1];
                if (this.OrderBy == showFieldsArr[i - 1])
                {
                    uriParser.QueryPart["ascending"] = (!this.Ascending).ToString();
                    img = this.Ascending ? " (asc)" : " (desc)";
                }
                else
                {
                    uriParser.QueryPart["ascending"] = "True";
                }
                sb.AppendFormat("<td><a href=\"{0}\">{1}</a>{2}</td>\n", uriParser.ToString(), colName, img);
            }
            if (this.Editable)
            {
                sb.AppendFormat("<td>{0}</td>\n", "&nbsp;");
            }
            if (this.Deletable)
            {
                sb.AppendFormat("<td>{0}</td>\n", "&nbsp;");
            }
            sb.Append("</tr>\n");

            string nameField = testEntity.GetNameColumn();

            // data
            uriParser = new CinarUriParser(pageUrl);
            foreach (DataRow dr in dt.Rows)
            {
                sb.Append("<tr class=\"data\">\n");
                string editUrl = this.EditPage + "?item=" + dr[0] + "&returnUrl=" + Provider.Server.UrlEncode(Provider.Request.RawUrl);
                for (int i = 0; i < dt.Columns.Count; i++)
                {
                    if (i == 0)
                    {
                        continue;
                    }
                    object data = (dr.IsNull(i) || dr[i].Equals("")) ? "&nbsp;" : dr[i];
                    if (showFieldsArr[i - 1] == nameField && this.Editable)
                    {
                        data = "<a href=\"" + editUrl + "\">" + data + "</a>";
                    }
                    if (dr.Table.Columns[i].DataType == typeof(bool))
                    {
                        data = ((bool)data) ? Provider.GetResource("Yes") : Provider.GetResource("No");
                    }
                    sb.AppendFormat("<td>{0}</td>\n", data);
                }
                if (this.Deletable)
                {
                    uriParser.QueryPart["delete"] = dr[0].ToString();
                    sb.AppendFormat("<td><span class=\"cbtn cdelete\" onclick=\"if(confirm('Kayýt silinecek!')) location.href='{0}'\"></span></td>\n", uriParser.ToString());
                }
                if (this.Editable)
                {
                    sb.AppendFormat("<td><span class=\"cbtn cedit\" onclick=\"location.href='{0}'\"></span></td>\n", editUrl);
                }
                sb.Append("</tr>\n");
            }

            // paging
            string prevPageLink = "", nextPageLink = "";

            uriParser = new CinarUriParser(pageUrl);
            if (pageNo > 0)
            {
                uriParser.QueryPart["pageNo"] = (pageNo - 1).ToString();
                prevPageLink = String.Format("<a href=\"{0}\"><< {1}</a>&nbsp;&nbsp;", uriParser.Uri.ToString(), Provider.GetModuleResource("Previous Page"));
            }
            if (dt.Rows.Count == HowManyItems)
            {
                uriParser.QueryPart["pageNo"] = (pageNo + 1).ToString();
                nextPageLink = String.Format("&nbsp;&nbsp;<a href=\"{0}\">{1} >></a>", uriParser.Uri.ToString(), Provider.GetModuleResource("Next Page"));
            }

            sb.AppendFormat("<tr class=\"footer\"><td colspan=\"100\">{0} {1}</td></tr>\n", prevPageLink, nextPageLink);
            sb.Append("</table>\n");

            if (!String.IsNullOrEmpty(NewRecordLink))
            {
                sb.AppendFormat("<p class=\"newRec\"><a href=\"{0}\">{1}</a></p>\n", this.EditPage + "?returnUrl=" + Provider.Server.UrlEncode(Provider.Request.RawUrl), NewRecordLink);
            }

            return(sb.ToString());
        }