private void printChildRows(DataRow parentRow, Worksheet ws, ref int rowCount, ref DataTable childRaw) { DataTable child = null; int ID = parentRow.Field<int>("ALLOCATIONID"); child = MasterData.Allocation_SystemList_Get(allocationID: ID); int i = 0, j = 1; formatChild(child); printChildHeader(ws, ref rowCount, child.Columns); foreach (DataRow row in child.Rows) { WTSUtility.importDataRow(ref childRaw, row); j = 2; foreach (object value in row.ItemArray) { ws.Cells[rowCount + i, j].PutValue(value); j++; } i++; } rowCount += child.Rows.Count; }
private void loadGridData() { _dtSystem = MasterData.SystemList_Get(includeArchive: false); if (_dtSystem != null && _qfSystemID != 0) { _dtSystem.DefaultView.RowFilter = string.Format(" WTS_SYSTEMID IN (0, {0}) ", _qfSystemID.ToString()); _dtSystem = _dtSystem.DefaultView.ToTable(); } DataSet dsAllocation = MasterData.AllocationList_Get(includeArchive: false); if (dsAllocation != null && dsAllocation.Tables.Count > 0) { _dtAllocation = dsAllocation.Tables[0]; } if (_dtAllocation != null && _qfAllocationID != 0) { _dtAllocation.DefaultView.RowFilter = string.Format(" AllocationID = {0} ", _qfAllocationID.ToString()); _dtAllocation = _dtAllocation.DefaultView.ToTable(); } DataTable dt = MasterData.Allocation_SystemList_Get(allocationID: this._qfAllocationID, systemID: this._qfSystemID); if (dt != null) { if (_qfSystemID > 0) { dt.Columns["WTS_SYSTEM"].SetOrdinal(dt.Columns["AllocationID"].Ordinal); dt.Columns["WTS_SYSTEMID"].SetOrdinal(dt.Columns["WTS_SYSTEM"].Ordinal); dt.AcceptChanges(); } this.DCC = dt.Columns; Page.ClientScript.RegisterArrayDeclaration("_dcc", JsonConvert.SerializeObject(DCC, Newtonsoft.Json.Formatting.None)); ListItem item = null; foreach (DataRow row in _dtAllocation.Rows) { item = ddlQF.Items.FindByValue(row["AllocationID"].ToString()); if (item == null) { ddlQF.Items.Add(new ListItem(row["Allocation"].ToString(), row["AllocationID"].ToString())); } } item = ddlQF.Items.FindByValue(_qfAllocationID.ToString()); if (item != null) { item.Selected = true; } foreach (DataRow row in _dtSystem.Rows) { item = ddlQF_System.Items.FindByValue(row["WTS_SYSTEMID"].ToString()); if (item == null) { ddlQF_System.Items.Add(new ListItem(row["WTS_SYSTEM"].ToString(), row["WTS_SYSTEMID"].ToString())); } } item = ddlQF_System.Items.FindByValue(_qfSystemID.ToString()); if (item != null) { item.Selected = true; } InitializeColumnData(ref dt); dt.AcceptChanges(); } if (_qfAllocationID != 0 && dt != null && dt.Rows.Count > 0) { dt.DefaultView.RowFilter = string.Format(" AllocationID = {0} OR (AllocationID = 0 AND WTS_SYSTEMID = 0) ", _qfAllocationID.ToString()); dt = dt.DefaultView.ToTable(); } if (_qfSystemID != 0 && dt != null && dt.Rows.Count > 0) { dt.DefaultView.RowFilter = string.Format(" WTS_SYSTEMID = {0} OR (WTS_SYSTEMID = 0 AND AllocationID = 0) OR WTS_SYSTEMID IS NULL ", _qfSystemID.ToString()); dt = dt.DefaultView.ToTable(); } int count = dt.Rows.Count; count = count > 0 ? count - 1 : count; //need to subtract the empty row spanRowCount.InnerText = count.ToString(); grdMD.DataSource = dt; grdMD.DataBind(); }