Exemplo n.º 1
0
 protected void ocultarCeldaComandos(GridView cuadricula)
 {
     //
     foreach (GridViewRow fila in cuadricula.Rows)
     {
         if (fila.RowType == DataControlRowType.DataRow)
         {
             foreach (TableCell celda in fila.Cells)
             {
                 DataControlField campo = ((DataControlFieldCell)celda).ContainingField;
                 if (campo.GetType().Name == "CommandField")
                 {
                     celda.Visible = false;
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
 private bool IsPropValue(DataControlField f, string PropName, string PropValue)
 {
     try
     {
         Type t = f.GetType();
         System.Reflection.PropertyInfo pi = t.GetProperty(PropName);
         if (pi == null)
         {
             return(false);
         }
         if (pi.PropertyType.FullName != "System.String")
         {
             return(false);
         }
         string s = pi.GetValue(f, null).ToString();
         return(s == PropValue);
     }
     catch
     {
         return(false);
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// 用IList(IModel)数据源来绑定GridView
        /// </summary>
        /// <param name="m"></param>
        public void BindGrid <T>(IList <T> source)
        {
            this.DataSource = source;
            this.DataBind();

            if (source.Count == 0)
            {
                return;
            }

            IList <UD_TableList> _tables = new UD_TableListBLL()._GetModelList("ModelName='" + ((IModel)source[0]).ModelName + "'");

            if (_tables.Count == 0)
            {
                return;
            }
            UD_TableList table = _tables[0];

            IList <UD_ModelFields> fields = new UD_TableListBLL(table.ID).GetModelFields();

            for (int i = 0; i < Columns.Count; i++)
            {
                DataControlField column = Columns[i];

                if (column.GetType().Name == "BoundField")
                {
                    BoundField field = (BoundField)column;
                    if (!column.Visible)
                    {
                        continue;
                    }

                    IList <UD_ModelFields> _models = UD_ModelFieldsBLL.GetModelList("TableID='" + table.ID.ToString() + "' AND FieldName='" + field.DataField + "'");
                    if (_models.Count == 0)
                    {
                        continue;
                    }
                    UD_ModelFields model = _models[0];

                    switch (model.RelationType)
                    {
                    case 1:         //关联字典表
                        foreach (GridViewRow row in Rows)
                        {
                            Dictionary <string, Dictionary_Data> dic = DictionaryBLL.GetDicCollections(model.RelationTableName, false);
                            row.Cells[i].Text = dic.ContainsKey(row.Cells[i].Text) ? dic[row.Cells[i].Text].Name : "";
                        }
                        break;

                    case 2:         //关联实体表
                        foreach (GridViewRow row in Rows)
                        {
                            row.Cells[i].Text = TreeTableBLL.GetRelationTableDataValue(model.RelationTableName, model.RelationValueField, model.RelationTextField, row.Cells[i].Text);
                        }
                        break;
                    }

                    if (model.DataType == 4)  //日期型
                    {
                        foreach (GridViewRow row in Rows)
                        {
                            if (row.Cells[i].Text.StartsWith("1900-01-01"))
                            {
                                row.Cells[i].Text = "";
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
        public void BindGrid()
        {
            FillDataSource();
            DataBind();
            Binded = true;

            if (PanelCode != "" && ViewState["TreeColumn"] != null)
            {
                Dictionary <string, UD_Panel_ModelFields> dicTreeColumnList = (Dictionary <string, UD_Panel_ModelFields>)ViewState["TreeColumn"];
                for (int i = 0; i < Columns.Count; i++)
                {
                    DataControlField column = Columns[i];

                    if (column.GetType().Name == "BoundField")
                    {
                        BoundField field = (BoundField)column;
                        if (!column.Visible)
                        {
                            continue;
                        }

                        foreach (GridViewRow row in Rows)
                        {
                            if (row.Cells[i].Text.StartsWith("1900-01-01"))
                            {
                                row.Cells[i].Text = "";
                            }
                        }

                        if (!dicTreeColumnList.ContainsKey(field.DataField))
                        {
                            continue;
                        }

                        UD_Panel_ModelFields     _panel_modelfields = dicTreeColumnList[field.DataField];
                        Dictionary <int, string> cachevalue         = new Dictionary <int, string>();

                        foreach (GridViewRow row in Rows)
                        {
                            int value = 0;
                            if (int.TryParse(row.Cells[i].Text, out value))
                            {
                                if (cachevalue.ContainsKey(value))
                                {
                                    row.Cells[i].Text = cachevalue[value];
                                }
                                else
                                {
                                    if (_panel_modelfields.TreeLevel == 100)
                                    {
                                        //显示全路径
                                        row.Cells[i].Text = TreeTableBLL.GetFullPathName(new UD_ModelFieldsBLL(_panel_modelfields.FieldID, true).Model.RelationTableName, value);
                                    }
                                    else
                                    {
                                        //显示父级
                                        if (_panel_modelfields.DisplayMode == 1)
                                        {
                                            row.Cells[i].Text = TreeTableBLL.GetSuperIDByLevel(new UD_ModelFieldsBLL(_panel_modelfields.FieldID, true).Model.RelationTableName, value, _panel_modelfields.TreeLevel).ToString();
                                        }
                                        else
                                        {
                                            row.Cells[i].Text = TreeTableBLL.GetSuperNameByLevel(new UD_ModelFieldsBLL(_panel_modelfields.FieldID, true).Model.RelationTableName, value, _panel_modelfields.TreeLevel);
                                        }
                                    }
                                    cachevalue.Add(value, row.Cells[i].Text);
                                }
                            }
                        }
                    }
                }
            }
        }
        public static void OutputExcel(Nandasoft.WebControls.NDGridView grid, string excelFileName)
        {
            Page page = (Page)HttpContext.Current.Handler;

            string[] flag = new string[grid.Columns.Count];
            for (int i = 0; i < grid.Columns.Count; i++)
            {
                DataControlField col = grid.Columns[i];

                //只有可见的邦定列和选择列才输出
                if (col.Visible && (col.GetType() == typeof(BoundField) || col.GetType() == typeof(CheckBoxField)))
                {
                    flag[i] = col.HeaderText;
                }
                else
                {
                    flag[i] = "";
                }
            }
            page.Response.Clear();
            string fileName = System.Web.HttpUtility.UrlEncode(System.Text.Encoding.UTF8.GetBytes(excelFileName));

            page.Response.AddHeader("Content-Disposition", "filename=" + fileName + ".xls");
            page.Response.ContentType = "application/vnd.ms-excel";
            page.Response.Charset     = "utf-8";

            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            sb.Append("<HTML><HEAD><TITLE>" + fileName + "</TITLE><META http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"></head><body>");
            sb.Append("<table border=1>");
            sb.Append("<tr><b>");
            for (int i = 0; i < grid.Columns.Count; i++)
            {
                if (flag[i] != "")
                {
                    sb.Append("<td>" + grid.Columns[i].HeaderText + "</td>");
                }
            }
            sb.Append("</b></tr>");


            for (int i = 0; i < grid.Rows.Count; i++)
            {
                if (((CheckBox)grid.Rows[i].Cells[1].FindControl("CheckBoxSelect")).Checked == true)
                {
                    sb.AppendLine("<tr>");
                    for (int j = 0; j < grid.Columns.Count; j++)
                    {
                        if (flag[j] != "")
                        {
                            if (grid.Rows[i].Cells[j].Controls.Count > 0)
                            {
                                if (grid.Rows[i].Cells[j].Controls[0].GetType().ToString().Trim() == "System.Web.UI.WebControls.CheckBox")
                                {
                                    if (((CheckBox)grid.Rows[i].Cells[j].Controls[0]).Checked)
                                    {
                                        sb.Append("<td>是</td>");
                                    }
                                    else
                                    {
                                        sb.Append("<td>否</td>");
                                    }
                                }
                                else
                                {
                                    sb.Append("<td>" + grid.Rows[i].Cells[j].Text + "</td>");
                                }
                            }
                            else
                            {
                                sb.Append("<td>" + grid.Rows[i].Cells[j].Text + "</td>");
                            }
                        }
                    }
                    sb.AppendLine("</tr>");
                }
            }

            sb.Append("</table>");
            sb.Append("</body></html>");

            page.Response.BinaryWrite(System.Text.Encoding.GetEncoding("utf-8").GetBytes(sb.ToString()));
            page.Response.End();
        }