Esempio n. 1
0
        private void BindGrid1()
        {
            if (Grid2.SelectedRowIndex < 0)
            {
                return;
            }

            int classId = Convert.ToInt32(Grid2.DataKeys[Grid2.SelectedRowIndex][0]);

            DataTable table = null;

            if (classId == 101)
            {
                table = DataSourceUtil.GetDataTable();
            }
            else
            {
                table = DataSourceUtil.GetDataTable2();
            }

            Grid1.DataSource = table;
            Grid1.DataBind();

            UpdateClassDesc(classId);
        }
        private void BindGrid()
        {
            DataTable table = DataSourceUtil.GetDataTable();

            Grid1.DataSource = table;
            Grid1.DataBind();
        }
Esempio n. 3
0
        // 表格过滤
        public DataTable GetFilteredTable(JArray filteredData)
        {
            // 示例使用的模拟数据是一次性返回的,因此我们需要新建一个 DataTable 来过滤返回的数据
            // 注:实际应用环境请不要这么做!!!(可以将过滤条件直接用于数据库检索)
            DataTable source = DataSourceUtil.GetDataTable();

            DataTable result = source.Clone();

            foreach (DataRow row in source.Rows)
            {
                bool filtered = true;
                foreach (JObject filteredObj in filteredData)
                {
                    if (!CheckDataRow(row, filteredObj))
                    {
                        filtered = false;
                        break;
                    }
                }

                if (filtered)
                {
                    result.Rows.Add(row.ItemArray);
                }
            }

            return(result);
        }
        private DataTable GetFilteredData(string gender, string[] majors)
        {
            DataTable table = DataSourceUtil.GetDataTable();

            DataView view = table.DefaultView;

            List <string> filters = new List <string>();

            // 性别过滤
            if (!String.IsNullOrEmpty(gender))
            {
                filters.Add(String.Format("Gender = {0}", gender));
            }

            // 专业过滤
            if (majors != null && majors.Length > 0)
            {
                List <string> majorFilters = new List <string>();
                foreach (string ddb in majors)
                {
                    majorFilters.Add(String.Format("Major = '{0}'", ddb));
                }
                filters.Add("(" + String.Join(" OR ", majorFilters.ToArray()) + ")");
            }

            if (filters.Count > 0)
            {
                view.RowFilter = String.Join(" AND ", filters.ToArray());
            }

            return(table);
        }
Esempio n. 5
0
        // GET: GridDataUrl/GridDataUrlData
        public ActionResult Index(bool?data2)
        {
            JArray ja = new JArray();

            DataTable source = null;

            if (data2.HasValue && data2.Value)
            {
                source = DataSourceUtil.GetDataTable2();
            }
            else
            {
                source = DataSourceUtil.GetDataTable();
            }

            foreach (DataRow row in source.Rows)
            {
                JObject jo = new JObject();
                jo.Add("Id", (int)row["Id"]);
                jo.Add("Name", row["Name"].ToString());
                jo.Add("Gender", (int)row["Gender"]);
                jo.Add("EntranceYear", (int)row["EntranceYear"]);
                jo.Add("AtSchool", (bool)row["AtSchool"]);
                jo.Add("Major", row["Major"].ToString());
                jo.Add("Group", (int)row["Group"]);

                ja.Add(jo);
            }

            return(Content(ja.ToString(Newtonsoft.Json.Formatting.None)));
        }
        /// <summary>
        /// 模拟数据库分页(实际项目中请直接使用SQL语句返回分页数据!)
        /// </summary>
        /// <returns></returns>
        private DataTable GetPagedDataTable(int pageIndex, int pageSize, bool?data2)
        {
            DataTable source = null;

            if (data2.HasValue && data2.Value)
            {
                source = DataSourceUtil.GetDataTable2();
            }
            else
            {
                source = DataSourceUtil.GetDataTable();
            }

            DataTable paged = source.Clone();

            int rowbegin = pageIndex * pageSize;
            int rowend   = (pageIndex + 1) * pageSize;

            if (rowend > source.Rows.Count)
            {
                rowend = source.Rows.Count;
            }

            for (int i = rowbegin; i < rowend; i++)
            {
                paged.ImportRow(source.Rows[i]);
            }

            return(paged);
        }
Esempio n. 7
0
 // 模拟在服务器端保存数据
 // 特别注意:在真实的开发环境中,不要在Session放置大量数据,否则会严重影响服务器性能
 private DataTable GetSourceData()
 {
     if (Session[KEY_FOR_DATASOURCE_SESSION] == null)
     {
         Session[KEY_FOR_DATASOURCE_SESSION] = DataSourceUtil.GetDataTable();
     }
     return((DataTable)Session[KEY_FOR_DATASOURCE_SESSION]);
 }
        private void BindGrid()
        {
            ViewState["UseDataSource1"] = true;

            DataTable table = DataSourceUtil.GetDataTable();

            Grid1.DataSource = table;
            Grid1.DataBind();
        }
Esempio n. 9
0
        private void BindGrid()
        {
            DataTable table = DataSourceUtil.GetDataTable();

            Grid1.DataSource = table;
            Grid1.DataBind();

            Grid1.SelectedRowIndexArray = new int[] { 4, 9 };
        }
Esempio n. 10
0
        // GET: Grid/ExcelGroupField/ExportToExcel
        public ActionResult ExportToExcel(JArray content)
        {
            DataTable source = DataSourceUtil.GetDataTable();

            //string TH_HTML = "<th>{0}</th>";
            string TD_HTML = "<td>{0}</td>";
            //string TD_IMAGE_HTML = "<td><img src=\"{0}\"></td>";

            StringBuilder sb = new StringBuilder();

            sb.Append("<meta http-equiv=\"Content-Type\" content=\"application/vnd.ms-excel;charset=utf-8\"/>");
            sb.Append("<table cellspacing=\"0\" rules=\"all\" border=\"1\" style=\"border-collapse:collapse;\">");


            MultiHeaderTable mht = new MultiHeaderTable();

            mht.ResolveMultiHeaderTable(content);

            foreach (List <object[]> rows in mht.MultiTable)
            {
                sb.Append("<tr>");
                foreach (object[] cell in rows)
                {
                    int     rowspan = Convert.ToInt32(cell[0]);
                    int     colspan = Convert.ToInt32(cell[1]);
                    JObject column  = cell[2] as JObject;

                    sb.AppendFormat("<th{0}{1}{2}>{3}</th>",
                                    rowspan != 1 ? " rowspan=\"" + rowspan + "\"" : "",
                                    colspan != 1 ? " colspan=\"" + colspan + "\"" : "",
                                    colspan != 1 ? " style=\"text-align:center;\"" : "",
                                    column.Value <string>("text"));
                }
                sb.Append("</tr>");
            }


            int rowIndex = 1;

            foreach (DataRow row in source.Rows)
            {
                sb.Append("<tr>");
                sb.AppendFormat(TD_HTML, rowIndex++);
                sb.AppendFormat(TD_HTML, row["Name"]);
                sb.AppendFormat(TD_HTML, row["Gender"].ToString() == "1" ? "男" : "女");
                sb.AppendFormat(TD_HTML, row["ChineseScore"]);
                sb.AppendFormat(TD_HTML, row["MathScore"]);
                sb.AppendFormat(TD_HTML, row["TotalScore"]);
                sb.AppendFormat(TD_HTML, row["Major"]);
                sb.AppendFormat(TD_HTML, ((DateTime)row["LogTime"]).ToString("yyyy-MM-dd"));
                sb.Append("</tr>");
            }
            sb.Append("</table>");


            return(File(Encoding.UTF8.GetBytes(sb.ToString()), "application/vnd.ms-excel", "myexcel.xls"));
        }
Esempio n. 11
0
        // GET/POST 都可以
        public ActionResult ExportToExcel(JObject content)
        {
            Dictionary <string, int> contentDic = content.ToObject <Dictionary <string, int> >();

            DataTable source = DataSourceUtil.GetDataTable();

            string TH_HTML       = "<th>{0}</th>";
            string TD_HTML       = "<td>{0}</td>";
            string TD_IMAGE_HTML = "<td><img src=\"{0}\"></td>";

            StringBuilder sb = new StringBuilder();

            sb.Append("<meta http-equiv=\"Content-Type\" content=\"application/vnd.ms-excel;charset=utf-8\"/>");
            sb.Append("<table cellspacing=\"0\" rules=\"all\" border=\"1\" style=\"border-collapse:collapse;\">");

            sb.Append("<tr>");
            sb.AppendFormat(TH_HTML, "");
            sb.AppendFormat(TH_HTML, "姓名");
            sb.AppendFormat(TH_HTML, "性别");
            sb.AppendFormat(TH_HTML, "入学年份");
            sb.AppendFormat(TH_HTML, "是否在校");
            sb.AppendFormat(TH_HTML, "所学专业");
            sb.AppendFormat(TH_HTML, "分组");
            sb.AppendFormat(TH_HTML, "语文成绩");
            sb.Append("</tr>");

            int rowIndex = 1;

            foreach (DataRow row in source.Rows)
            {
                string rowId = row["Id"].ToString();

                sb.Append("<tr>");
                sb.AppendFormat(TD_HTML, rowIndex++);
                sb.AppendFormat(TD_HTML, row["Name"]);
                sb.AppendFormat(TD_HTML, row["Gender"].ToString() == "1" ? "男" : "女");
                sb.AppendFormat(TD_HTML, row["EntranceYear"]);
                sb.AppendFormat(TD_HTML, (bool)row["AtSchool"] ? "√" : "×");
                sb.AppendFormat(TD_HTML, row["Major"]);
                sb.AppendFormat(TD_IMAGE_HTML, GetAbsoluteUrl(String.Format("~/res/images/16/{0}.png", row["Group"])));
                if (contentDic.ContainsKey(rowId))
                {
                    sb.AppendFormat(TD_HTML, contentDic[rowId]);
                }
                else
                {
                    // 未找到!
                    sb.AppendFormat(TD_HTML, "");
                }
                sb.Append("</tr>");
            }
            sb.Append("</table>");


            return(File(Encoding.UTF8.GetBytes(sb.ToString()), "application/vnd.ms-excel", "myexcel.xls"));
        }
Esempio n. 12
0
        private DataView GetSortedDataView(string sortField, string sortDirection)
        {
            // 模拟数据排序
            DataTable table = DataSourceUtil.GetDataTable();
            DataView  view1 = table.DefaultView;

            view1.Sort = String.Format("{0} {1}", sortField, sortDirection);

            return(view1);
        }
Esempio n. 13
0
        private void BindGrid()
        {
            DataTable table = DataSourceUtil.GetDataTable();

            for (int i = 0; i < 2; i++)
            {
                table.Merge(DataSourceUtil.GetDataTable(), true);
            }

            Grid1.DataSource = table;
            Grid1.DataBind();
        }
        public ActionResult Grid1_Sort(string[] Grid1_fields, string Grid1_sortField, string Grid1_sortDirection)
        {
            // 模拟数据排序
            DataTable table = DataSourceUtil.GetDataTable();
            DataView  view1 = table.DefaultView;

            view1.Sort = String.Format("{0} {1}", Grid1_sortField, Grid1_sortDirection);

            // 更新表格数据源
            UIHelper.Grid("Grid1").DataSource(view1, Grid1_fields);

            return(UIHelper.Result());
        }
Esempio n. 15
0
        private void BindGrid()
        {
            string sortField     = Grid1.SortField;
            string sortDirection = Grid1.SortDirection;

            DataTable table = DataSourceUtil.GetDataTable();

            DataView view1 = table.DefaultView;

            view1.Sort = String.Format("{0} {1}", sortField, sortDirection);

            Grid1.DataSource = view1;
            Grid1.DataBind();
        }
Esempio n. 16
0
        // 模拟在服务器端保存数据
        // 特别注意:在真实的开发环境中,不要在Session放置大量数据,否则会严重影响服务器性能
        private DataTable GetSourceData()
        {
            if (Session[KEY_FOR_DATASOURCE_SESSION] == null)
            {
                DataTable table = DataSourceUtil.GetDataTable();

                // 修改最后一行的数据
                DataRow lastRow = table.Rows[table.Rows.Count - 1];
                lastRow["Major"] = "<b>" + lastRow["Major"] + "&</b>";

                Session[KEY_FOR_DATASOURCE_SESSION] = table;
            }
            return((DataTable)Session[KEY_FOR_DATASOURCE_SESSION]);
        }
Esempio n. 17
0
        private DataTable GetClassDetailTable(int classId)
        {
            DataTable table = null;

            if (classId == 101)
            {
                table = DataSourceUtil.GetDataTable();
            }
            else
            {
                table = DataSourceUtil.GetDataTable2();
            }

            return(table);
        }
        /// <summary>
        /// 模拟返回总项数
        /// </summary>
        /// <returns></returns>
        private int GetTotalCount(bool?data2)
        {
            DataTable source = null;

            if (data2.HasValue && data2.Value)
            {
                source = DataSourceUtil.GetDataTable2();
            }
            else
            {
                source = DataSourceUtil.GetDataTable();
            }

            return(source.Rows.Count);
        }
Esempio n. 19
0
        public ActionResult Button1_Click(string[] fields, string source)
        {
            var grid1 = UIHelper.Grid("Grid1");

            if (source == "source1")
            {
                grid1.DataSource(DataSourceUtil.GetDataTable(), fields);
                grid1.Attribute("data-source-key", "source2");
            }
            else
            {
                grid1.DataSource(null);
                grid1.Attribute("data-source-key", "source1");
            }

            return(UIHelper.Result());
        }
Esempio n. 20
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            DataTable table;

            if (Convert.ToBoolean(ViewState["EMPTY_DATA_SOURCE"]))
            {
                ViewState["EMPTY_DATA_SOURCE"] = false;
                table = DataSourceUtil.GetDataTable();
            }
            else
            {
                ViewState["EMPTY_DATA_SOURCE"] = true;
                table = null;
            }

            Grid1.DataSource = table;
            Grid1.DataBind();
        }
        protected void Button2_Click(object sender, EventArgs e)
        {
            DataTable table;

            if (Convert.ToBoolean(ViewState["UseDataSource1"]))
            {
                ViewState["UseDataSource1"] = false;
                table = DataSourceUtil.GetDataTable2();
            }
            else
            {
                ViewState["UseDataSource1"] = true;
                table = DataSourceUtil.GetDataTable();
            }

            Grid1.DataSource = table;
            Grid1.DataBind();
        }
        // 模拟在服务器端保存数据
        // 特别注意:在真实的开发环境中,不要在Session放置大量数据,否则会严重影响服务器性能
        private DataTable GetSourceData()
        {
            if (Session[KEY_FOR_DATASOURCE_SESSION] == null)
            {
                DataTable hobbyTable = GetHobbyTable();

                // 修改数据源的结构,增加 HobbyText 项
                DataTable table = DataSourceUtil.GetDataTable();
                table.Columns.Add(new DataColumn("HobbyText", typeof(String)));
                foreach (DataRow row in table.Rows)
                {
                    row["HobbyText"] = GetHobbyText(hobbyTable, row["Hobby"].ToString());
                }

                Session[KEY_FOR_DATASOURCE_SESSION] = table;
            }
            return((DataTable)Session[KEY_FOR_DATASOURCE_SESSION]);
        }
Esempio n. 23
0
        private void AutoBindGrid(string gridSourceKey, JArray gridFields)
        {
            var grid1 = UIHelper.Grid("Grid1");

            DataTable source = null;

            if (gridSourceKey == "table1")
            {
                source        = DataSourceUtil.GetDataTable2();
                gridSourceKey = "table2";
            }
            else
            {
                source        = DataSourceUtil.GetDataTable();
                gridSourceKey = "table1";
            }

            grid1.DataSource(source, gridFields);
            grid1.Attribute("data-source-key", gridSourceKey);
        }
Esempio n. 24
0
        private void LoadData()
        {
            DataTable table = DataSourceUtil.GetDataTable();

            int       newtableID = 101;
            DataTable newtable   = table.Clone();

            for (int i = 0; i <= 2; i++)
            {
                foreach (DataRow row in table.Rows)
                {
                    row["Id"] = newtableID;
                    newtable.ImportRow(row);

                    newtableID++;
                }
            }

            ViewBag.Grid1DataSource = newtable;
        }
Esempio n. 25
0
        public ActionResult Grid1_RowMove(JArray rowIds)
        {
            DataTable originalTable = DataSourceUtil.GetDataTable();
            DataTable newTable      = originalTable.Clone();

            foreach (string rowId in rowIds)
            {
                DataRow rowInOriginalTable = FindRow(rowId, originalTable);
                if (rowInOriginalTable != null)
                {
                    newTable.ImportRow(rowInOriginalTable);
                }
            }

            Session[KEY_FOR_DATASOURCE_SESSION] = newTable;

            ShowNotify("数据保存成功!");

            return(UIHelper.Result());
        }
Esempio n. 26
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            DataTable table;

            if (Convert.ToBoolean(ViewState["UseDataSource1"]))
            {
                ViewState["UseDataSource1"] = false;
                table = DataSourceUtil.GetDataTable2();
            }
            else
            {
                ViewState["UseDataSource1"] = true;
                table = DataSourceUtil.GetDataTable();
            }

            // 重新绑定数据前,先清空高亮的行数据
            highlightRows.Text = "";

            Grid1.DataSource = table;
            Grid1.DataBind();
        }
        public ActionResult btnSubmit_Click(string[] Grid1_fields, JArray Grid1_modifiedData)
        {
            DataTable source = DataSourceUtil.GetDataTable();

            foreach (JObject modifiedRow in Grid1_modifiedData)
            {
                string status = modifiedRow.Value <string>("status");
                int    rowId  = Convert.ToInt32(modifiedRow.Value <string>("id"));

                if (status == "modified")
                {
                    UpdateDataRow(modifiedRow, rowId, source);
                }
            }

            UIHelper.Grid("Grid1").DataSource(source, Grid1_fields);
            UIHelper.Label("labResult").Text(String.Format("用户修改的数据:<pre>{0}</pre>", Grid1_modifiedData.ToString(Newtonsoft.Json.Formatting.Indented)), false);

            ShowNotify("数据保存成功!(表格数据已重新绑定)");

            return(UIHelper.Result());
        }
        // GET: GridDataUrl/SortingData
        public ActionResult Index(string sortField, string sortDirection, bool?data2)
        {
            JArray ja = new JArray();

            DataTable source = null;

            if (data2.HasValue && data2.Value)
            {
                source = DataSourceUtil.GetDataTable2();
            }
            else
            {
                source = DataSourceUtil.GetDataTable();
            }

            DataView view1 = source.DefaultView;

            view1.Sort = String.Format("{0} {1}", sortField, sortDirection);

            DataTable sortedTable = view1.ToTable();

            foreach (DataRow row in sortedTable.Rows)
            {
                JObject jo = new JObject();
                jo.Add("Id", (int)row["Id"]);
                jo.Add("Name", row["Name"].ToString());
                jo.Add("Gender", (int)row["Gender"]);
                jo.Add("EntranceYear", (int)row["EntranceYear"]);
                jo.Add("AtSchool", (bool)row["AtSchool"]);
                jo.Add("Major", row["Major"].ToString());
                jo.Add("Group", (int)row["Group"]);

                ja.Add(jo);
            }

            return(Content(ja.ToString(Newtonsoft.Json.Formatting.None)));
        }
        // GET: Grid/DynamicColumns
        public ActionResult Index()
        {
            InitGridColumns();

            return(View(DataSourceUtil.GetDataTable()));
        }
Esempio n. 30
0
        public ActionResult btnSearch_Click(string[] Grid1_fields)
        {
            UIHelper.Grid("Grid1").DataSource(DataSourceUtil.GetDataTable(), Grid1_fields);

            return(UIHelper.Result());
        }