private void ShowList() { try { dgMainList.Controls.Clear(); dtData = equip.GetEquipList(); dgMainList.DataSource = new DataView(dtData); dgMainList.DataBind(); } catch (Exception ex) { throw new Exception(ex.Message, ex); } finally { if (dtData != null) { dtData.Dispose(); } if (loc != null) { loc.Dispose(); } if (dep != null) { dep.Dispose(); } if (mm != null) { mm.Dispose(); } } }
private void ShowList() { int i, j; clsCustomFieldsDef cfd = null; string sTypeName; try { dgMainList.Controls.Clear(); dtResult = new DataTable("Result"); dtData = equip.GetEquipList(); if (dtData.Rows.Count > 0) { //arrCFD = _functions.CustomFieldsParse(dtData, Convert.ToInt32(Session["EquipTypeId"])); arrCFD = _functions.GetCustomFields(false, equip.iTypeId.Value, HttpContext.Current.User.Identity.Name); if (arrCFD.Count > 0) { // adding fixed fields dtResult.Columns.Add("id"); // adding variable columns and fields for (i = 0; i < arrCFD.Count; i++) { cfd = (clsCustomFieldsDef)arrCFD[i]; dtResult.Columns.Add(cfd.Name); _column = new BoundColumn(); _column.DataField = cfd.Name; _column.HeaderText = cfd.NameText; dgMainList.Columns.Add(_column); if (cfd.NameLookupTable == "EquipModels") // adding make column if model is exist { _column = null; _column = new BoundColumn(); dtResult.Columns.Add("MakeName"); _column.DataField = "MakeName"; _column.HeaderText = "Make"; dgMainList.Columns.Add(_column); } cfd = null; _column = null; } // fill fields for (i = 0; i < dtData.Rows.Count; i++) { // fill fixed fields drItem = dtResult.NewRow(); drItem["Id"] = dtData.Rows[i]["Id"]; // fill variable fields for (j = 0; j < arrCFD.Count; j++) { cfd = (clsCustomFieldsDef)arrCFD[j]; sTypeName = _functions.GetFieldTypeText(cfd.FieldTypeId) + cfd.NumberColumn.ToString(); switch (cfd.FieldTypeId) { case DBFieldType._lookup: switch (cfd.NameLookupTable) { case "EquipModels": mm = new clsMakesModels(); mm.iOrgId = _functions.GetUserOrgId(HttpContext.Current.User.Identity.Name, false); mm.iModelId = Convert.ToInt32(dtData.Rows[i][sTypeName]); mm.GetModelMakes(); drItem[cfd.Name] = mm.sModelName; drItem["MakeName"] = mm.sMakeName; break; case "Departments": dep = new clsDepartments(); dep.cAction = "S"; dep.iOrgId = _functions.GetUserOrgId(HttpContext.Current.User.Identity.Name, false); dep.iId = Convert.ToInt32(dtData.Rows[i][sTypeName]); if (dep.DepartmentDetail() == 0) { drItem[cfd.Name] = dep.sName.Value; } break; case "Locations": loc = new clsLocations(); loc.cAction = "S"; loc.iOrgId = _functions.GetUserOrgId(HttpContext.Current.User.Identity.Name, false); loc.iId = Convert.ToInt32(dtData.Rows[i][sTypeName]); if (loc.LocationDetail() == 0) { drItem[cfd.Name] = loc.sName.Value; } break; default: break; } break; case DBFieldType._bit: if (((bool)dtData.Rows[i][sTypeName]) == true) { drItem[cfd.Name] = "Yes"; } else { drItem[cfd.Name] = "No"; } break; default: drItem[cfd.Name] = dtData.Rows[i][sTypeName]; break; } cfd = null; } dtResult.Rows.Add(drItem); } } else { Session["lastpage"] = ParentPageURL; Session["error"] = _functions.ErrorMessage(102); Response.Redirect("error.aspx", false); } } dgMainList.DataSource = new DataView(dtResult); dgMainList.DataBind(); } catch (Exception ex) { throw new Exception(ex.Message); } finally { if (dtData != null) { dtData.Dispose(); } if (loc != null) { loc.Dispose(); } if (dep != null) { dep.Dispose(); } if (mm != null) { mm.Dispose(); } } }