protected void ApplyLayout(int layoutIndex, ASPxGridView grid) { if (grid != null) { grid.BeginUpdate(); try { grid.ClearSort(); switch (layoutIndex) { case 0: grid.GroupBy(grid.Columns["ItemType"]); break; case 1: grid.GroupBy(grid.Columns["ItemType"]); grid.GroupBy(grid.Columns["ItemName"]); break; case 2: grid.GroupBy(grid.Columns["ItemQty"]); break; } } finally { grid.EndUpdate(); } grid.ExpandAll(); } }
public void CreateGridViewRetale(Page mypage, ASPxGridView gridViewName, DataTable sourceField, int modulerelateid, string keyFieldName, string ID, bool isStored) { try { //SETTING GRID gridViewName.KeyFieldName = isStored ? keyFieldName : keyFieldName.ToLower(); gridViewName.ClientInstanceName = ID; gridViewName.ID = ID; gridViewName.Width = Unit.Percentage(100); //add checkbox column GridViewCommandColumn gridCommandColumn = new GridViewCommandColumn(); gridCommandColumn.ShowSelectCheckbox = true; gridCommandColumn.VisibleIndex = 0; gridCommandColumn.HeaderTemplate = new MyHeaderCheckBox(gridViewName.ClientInstanceName, true); gridCommandColumn.Width = Unit.Pixel(35); gridViewName.Columns.Add(gridCommandColumn); //lay duong dan form newedit string popupWindowControlURL = string.Format(ConfigurationManager.AppSettings["PopupMasterURL"].ToString(), modulerelateid); //lấy thông tin module hiện tại với quyền userid hiện tại DataTable dtCheckRight = ObjectUtils.getModuleRolesByUser(modulerelateid, CU.getuserid()); string formsetting = ""; if (dtCheckRight.Rows[0]["formsetting"] != null) formsetting = dtCheckRight.Rows[0]["formsetting"].ToString();//gviewrl.GetRowKey(gviewrl.GetFocusedRowIndex()).toString() //tao su kien doubleclick cho lưới gridViewName.ClientSideEvents.RowDblClick = "function(s,e){ js:openModalEditWindowRelate('" + popupWindowControlURL + "','" + formsetting + "',s.GetRowKey(e.visibleIndex));}"; //kiem tra cache column if (mypage.Session["colcollect_gridrlMain" + modulerelateid] != null) { GridViewColumn[] colarray = mypage.Session["colcollect_gridrlMain" + modulerelateid] as GridViewColumn[]; gridViewName.Columns.AddRange(colarray); List<List<ASPxSummaryItem>> summarylist = mypage.Session["colcollect_gridMain_summary" + modulerelateid] as List<List<ASPxSummaryItem>>; if (summarylist != null) { if (summarylist.Count > 0) { gridViewName.Settings.ShowFooter = true; gridViewName.GroupSummary.AddRange(summarylist[0]); gridViewName.TotalSummary.AddRange(summarylist[1]); } } } else { List<ASPxSummaryItem> groupitem = new List<ASPxSummaryItem>(); List<ASPxSummaryItem> footeritem = new List<ASPxSummaryItem>(); GridViewColumn[] colarray = new GridViewColumn[sourceField.Rows.Count]; string objectnamefk = string.Empty; for (int i = 0; i < sourceField.Rows.Count; i++) { //SiAuto.Main.LogString("cot" + i.ToString(), sourceField.Rows[i]["fieldname"].ToString()); string fieldtext = sourceField.Rows[i]["fieldtext"].ToString(); string fieldname = isStored ? sourceField.Rows[i]["fieldname"].ToString() : sourceField.Rows[i]["fieldname"].ToString().ToLower(); string tablename = sourceField.Rows[i]["tablename"].ToString().ToLower(); string alias = sourceField.Rows[i]["alias"].ToString().ToLower(); int width = sourceField.Rows[i]["width"].ToString() == string.Empty ? 0 : int.Parse(sourceField.Rows[i]["width"].ToString()); string format = sourceField.Rows[i]["format"].ToString(); string tempeditor = sourceField.Rows[i]["tempeditor"].ToString(); string datasource = sourceField.Rows[i]["datasource"].ToString(); int isGroup = sourceField.Rows[i]["isGroup"].ToString() == string.Empty ? 0 : int.Parse(sourceField.Rows[i]["isGroup"].ToString()); string SummaryCalculator = sourceField.Rows[i]["SummaryCalculator"].ToString(); bool ishidden = false; bool.TryParse(sourceField.Rows[i]["ishidden"].ToString(), out ishidden); bool ishyperlinkrelate = sourceField.Rows[i]["ishyperlinkrelate"].ToString() == "True" ? true : false; switch (sourceField.Rows[i]["tempcolumn"].ToString().ToLower()) { case "textcolumn": { if (objectnamefk == string.Empty) objectnamefk = ObjectUtils.getObjectNameFromModuleId(modulerelateid); GridViewDataTextColumn dc = BuildTextColumn(fieldtext, fieldname, alias, width, format, tempeditor, modulerelateid, tablename, datasource, ishyperlinkrelate, keyFieldName, objectnamefk); gridViewName.Columns.Add(dc); colarray[i] = dc; break; } case "checkcolumn": { GridViewDataCheckColumn dc = BuildCheckColumn(fieldtext, fieldname, alias, width); gridViewName.Columns.Add(dc); colarray[i] = dc; break; } case "datecolumn": { GridViewDataDateColumn dc = BuildDateColumn(fieldtext, fieldname, alias, width, format); gridViewName.Columns.Add(dc); colarray[i] = dc; break; } case "progressbarcolumn": { GridViewDataProgressBarColumn dc = BuildProgressBarColumn(fieldtext, fieldname, alias, width); gridViewName.Columns.Add(dc); colarray[i] = dc; break; } } gridViewName.Columns[fieldname].Visible = !ishidden; List<ASPxSummaryItem> sitem = SummaryCalculatorOnGview(fieldname, fieldtext, SummaryCalculator, gridViewName); if (sitem != null) { groupitem.Add(sitem[0]); footeritem.Add(sitem[1]); } } List<List<ASPxSummaryItem>> summarylist = new List<List<ASPxSummaryItem>>(); summarylist.Add(groupitem); summarylist.Add(footeritem); mypage.Session["colcollect_gridrlMain" + modulerelateid] = colarray; mypage.Session["colcollect_gridMain_summary" + modulerelateid] = summarylist; } DataRow[] dataRows = sourceField.Select("isGroup>0", "isGroup ASC"); if (dataRows.Length > 0) { gridViewName.Settings.ShowFooter = true; for (int i = 0; i < dataRows.Length; i++) { string fieldname = dataRows[i]["fieldname"].ToString(); gridViewName.GroupBy(gridViewName.Columns[fieldname]); ((GridViewDataTextColumn)gridViewName.Columns[fieldname]).GroupIndex = i; gridViewName.GroupSummary.Add(DevExpress.Data.SummaryItemType.Count, fieldname).DisplayFormat = "Tổng:{0}"; } } SiAuto.Main.LogColored(System.Drawing.Color.Chocolate, keyFieldName); } catch (Exception ex) { SiAuto.Main.LogColored(System.Drawing.Color.Red, ex.ToString()); } }
/// <summary> /// Hàm tạo column gridview động /// </summary> /// <param name="gridViewName">Tên lưới</param> /// <param name="sourceField">DataTable chứa danh sách các field column cần tạo control</param> /// <param name="strSQLDatasource">Datasource cho gridview</param> /// <param name="ssParamsListGridView">Danh dách các tham số để load datasource cho gridview</param> public void CreateGridViewDynamic(Page mypage, ASPxGridView gridViewName, DataTable sourceField, int moduleid, string keyFieldName, bool isStored) { try { //gridViewName.Columns.Clear(); gridViewName.KeyFieldName = isStored ? keyFieldName : keyFieldName.ToLower(); gridViewName.ClientInstanceName = "gview";//dat ten nay co dinh, khong thay doi duoc //Add header template GridViewCommandColumn gridCommandColumn = new GridViewCommandColumn(); gridCommandColumn.ShowSelectCheckbox = true; gridCommandColumn.SelectAllCheckboxMode = GridViewSelectAllCheckBoxMode.Page; gridCommandColumn.VisibleIndex = 0; gridCommandColumn.Width = Unit.Pixel(35); gridViewName.Columns.Add(gridCommandColumn); //gridViewName.TotalSummary.Clear(); // if (mypage.Session["colcollect_gridMain" + moduleid] != null) { GridViewColumn[] colarray = mypage.Session["colcollect_gridMain" + moduleid] as GridViewColumn[]; gridViewName.Columns.AddRange(colarray); List<List<ASPxSummaryItem>> summarylist = mypage.Session["colcollect_gridMain_summary" + moduleid] as List<List<ASPxSummaryItem>>; if (summarylist != null) { if (summarylist.Count > 0) { gridViewName.Settings.ShowFooter = true; gridViewName.GroupSummary.AddRange(summarylist[0]); gridViewName.TotalSummary.AddRange(summarylist[1]); } } } else { string objectnamemain = string.Empty; List<ASPxSummaryItem> groupitem = new List<ASPxSummaryItem>(); List<ASPxSummaryItem> footeritem = new List<ASPxSummaryItem>(); GridViewColumn[] colarray = new GridViewColumn[sourceField.Rows.Count]; for (int i = 0; i < sourceField.Rows.Count; i++) { string fieldtext = sourceField.Rows[i]["fieldtext"].ToString(); string fieldname = isStored ? sourceField.Rows[i]["fieldname"].ToString() : sourceField.Rows[i]["fieldname"].ToString().ToLower(); string tablename = sourceField.Rows[i]["tablename"].ToString().ToLower(); string alias = sourceField.Rows[i]["alias"].ToString().ToLower(); int width = sourceField.Rows[i]["width"].ToString() == string.Empty ? 0 : int.Parse(sourceField.Rows[i]["width"].ToString()); string format = sourceField.Rows[i]["format"].ToString(); string tempeditor = sourceField.Rows[i]["tempeditor"].ToString(); string datasource = sourceField.Rows[i]["datasource"].ToString(); int isGroup = sourceField.Rows[i]["isGroup"].ToString() == string.Empty ? -1 : int.Parse(sourceField.Rows[i]["isGroup"].ToString()); string SummaryCalculator = sourceField.Rows[i]["SummaryCalculator"].ToString(); bool ishidden = false; bool.TryParse(sourceField.Rows[i]["ishidden"].ToString(), out ishidden); switch (sourceField.Rows[i]["tempcolumn"].ToString().ToLower()) { case "bandcolumn": { GridViewBandColumn band = new GridViewBandColumn(fieldtext); gridViewName.Columns.Add(band); colarray[i] = band; break; } case "textcolumn": { if (objectnamemain == string.Empty) objectnamemain = ObjectUtils.getObjectNameFromModuleId(moduleid); GridViewDataTextColumn dc = BuildTextColumn(fieldtext, fieldname, alias, width, format, tempeditor, moduleid, tablename, datasource, false, keyFieldName, objectnamemain); if (i < 2 && Utils.isMobileBrowser()) dc.FixedStyle = GridViewColumnFixedStyle.Left; gridViewName.Columns.Add(dc); colarray[i] = dc; break; } case "checkcolumn": { GridViewDataCheckColumn dc = BuildCheckColumn(fieldtext, fieldname, alias, width); if (i < 2 && Utils.isMobileBrowser()) dc.FixedStyle = GridViewColumnFixedStyle.Left; gridViewName.Columns.Add(dc); colarray[i] = dc; break; } case "datecolumn": { GridViewDataDateColumn dc = BuildDateColumn(fieldtext, fieldname, alias, width, format); if (i < 2 && Utils.isMobileBrowser()) dc.FixedStyle = GridViewColumnFixedStyle.Left; gridViewName.Columns.Add(dc); colarray[i] = dc; break; } case "progressbarcolumn": { GridViewDataProgressBarColumn dc = BuildProgressBarColumn(fieldtext, fieldname, alias, width); if (i < 2 && Utils.isMobileBrowser()) dc.FixedStyle = GridViewColumnFixedStyle.Left; gridViewName.Columns.Add(dc); colarray[i] = dc; break; } } gridViewName.Columns[fieldname].Visible = !ishidden; List<ASPxSummaryItem> sitem = SummaryCalculatorOnGview(fieldname, fieldtext, SummaryCalculator, gridViewName); if (sitem != null) { groupitem.Add(sitem[0]); footeritem.Add(sitem[1]); } } List<List<ASPxSummaryItem>> summarylist = new List<List<ASPxSummaryItem>>(); summarylist.Add(groupitem); summarylist.Add(footeritem); mypage.Session["colcollect_gridMain" + moduleid] = colarray; mypage.Session["colcollect_gridMain_summary" + moduleid] = summarylist; } DataRow[] dataRows = sourceField.Select("ISNULL(isGroup,-1)>=0", "isGroup ASC"); SiAuto.Main.LogDataTable("danh sach field chuan bi group filter ISNULL(isGroup,-1)>=0 isGroup ASC", sourceField); if (dataRows.Length > 0) { gridViewName.Settings.ShowGroupPanel = true; gridViewName.Settings.ShowFooter = true; for (int i = 0; i < dataRows.Length; i++) { string fieldname = isStored ? dataRows[i]["fieldname"].ToString() : dataRows[i]["fieldname"].ToString().ToLower(); SiAuto.Main.LogColored(Color.Orange, fieldname); gridViewName.GroupBy(gridViewName.Columns[fieldname], i); //((GridViewDataTextColumn)gridViewName.Columns[fieldname]).GroupIndex = i; //gridViewName.GroupSummary.Add(DevExpress.Data.SummaryItemType.Count, fieldname).DisplayFormat = "Tổng:{0}"; } } SiAuto.Main.LogColored(System.Drawing.Color.Chocolate, keyFieldName); } catch (Exception ex) { SiAuto.Main.LogColored(System.Drawing.Color.Red, ex.ToString()); } }