protected void PopulateAvailableAssets() { intModel = Int32.Parse(ddlModel.SelectedValue.ToString()); lblAssetsSelectedCount.Text = "0"; pnlAssetsAvailable.Visible = true; dlAssetsSelection.DataSource = null; dlAssetsSelection.DataBind(); string strFilterCriteria = ""; strFilterCriteria = strFilterCriteria + " LocationId =" + hdnLocation.Value; strFilterCriteria = strFilterCriteria + " AND "; strFilterCriteria = strFilterCriteria + " ClassId =" + ddlClass.SelectedValue.ToString(); strFilterCriteria = strFilterCriteria + " AND "; strFilterCriteria = strFilterCriteria + " EnvironmentId =" + hdnEnvironment.Value; strFilterCriteria = "( " + strFilterCriteria + " )"; string strSort = "AssetSerial"; DataSet ds = oAsset.GetAssetsAll(intModel, (int)AssetStatus.Available); DataTable dtAssets = null; dtAssets = ds.Tables[0]; //Remove assets from selection -where previous request is in process for the assets if (dtAssets != null) { DataSet dsWIPAssets = oAssetOrder.GetActiveAssetOrderAssets(intModel); DataTable dtWIPAssets = dsWIPAssets.Tables[0]; foreach (DataRow dr in dtWIPAssets.Rows) { DataRow[] drAssestsToRemove = null; string strFilterCriteriaRemove; strFilterCriteriaRemove = "AssetId =" + dr["AssetId"].ToString(); drAssestsToRemove = dtAssets.Select(strFilterCriteriaRemove); foreach (DataRow drTmp in drAssestsToRemove) { dtAssets.Rows.Remove(drTmp); } } } DataRow[] drSelect = null; drSelect = dtAssets.Select(strFilterCriteria, strSort); dlAssetsSelection.DataSource = drSelect; dlAssetsSelection.DataBind(); }
protected void PopulateAvailableAssetsSummary() { trAssetsSummary.Style.Add("Display", "inline"); intModel = Int32.Parse(ddlModel.SelectedValue); dlAssetsSummary.DataSource = null; dlAssetsSummary.DataBind(); dlAssetsSelection.DataSource = null; dlAssetsSelection.DataBind(); lblTotalAssetsSelected.Text = "0"; DataTable dtAssets = null; DataSet dsAssets = null; dsAssets = oAsset.GetAssetsAll(intModel, (int)AssetStatus.Available); dtAssets = dsAssets.Tables[0]; if (Int32.Parse(rblOrderType.SelectedValue) == (int)AssetOrderType.Movement) { dsAssets = oAsset.GetAssetsAll(intModel, (int)AssetStatus.InUse); if (dtAssets != null) { foreach (DataRow dr in dsAssets.Tables[0].Rows) { dtAssets.ImportRow(dr); } } else { dtAssets = dsAssets.Tables[0]; } } //Remove assets from selection -where previous request is in process for the assets if (dtAssets != null) { DataSet dsWIPAssets = oAssetOrder.GetActiveAssetOrderAssets(intModel); DataTable dtWIPAssets = dsWIPAssets.Tables[0]; foreach (DataRow dr in dtWIPAssets.Rows) { DataRow[] drAssestsToRemove = null; string strFilterCriteriaRemove; strFilterCriteriaRemove = "AssetId =" + dr["AssetId"].ToString(); drAssestsToRemove = dtAssets.Select(strFilterCriteriaRemove); foreach (DataRow drTmp in drAssestsToRemove) { dtAssets.Rows.Remove(drTmp); } } } string[] strColumnNames = { "LocationId", "Location", "ClassId", "Class", "EnvironmentId", "Environment" }; string strSort = " Location,Class,Environment "; DataTable dtSummary = dtAssets.DefaultView.ToTable(true, strColumnNames); dtSummary.Columns.Add("Available", Type.GetType("System.Int32")); dtSummary.Columns.Add("Selected", Type.GetType("System.Int32")); dtSummary.Columns.Add("FilterCriteria", Type.GetType("System.String")); foreach (DataRow drSummary in dtSummary.Rows) { DataRow[] drAvailables = null; string strFilterCriteria = ""; strFilterCriteria = strFilterCriteria + (drSummary["LocationId"] == DBNull.Value ? " LocationId IS Null" : (drSummary["LocationId"].ToString() == "" ? " LocationId =''" : "LocationId =" + drSummary["LocationId"].ToString())); strFilterCriteria = strFilterCriteria + " AND "; strFilterCriteria = strFilterCriteria + (drSummary["ClassId"] == DBNull.Value ? " ClassId IS Null" : (drSummary["ClassId"].ToString() == "" ? " ClassId =''" : " ClassId =" + drSummary["ClassId"].ToString())); strFilterCriteria = strFilterCriteria + " AND "; strFilterCriteria = strFilterCriteria + (drSummary["EnvironmentId"] == DBNull.Value ? " EnvironmentId IS Null" : (drSummary["EnvironmentId"].ToString() == "" ? " EnvironmentId =''" : " EnvironmentId =" + drSummary["EnvironmentId"].ToString())); strFilterCriteria = "( " + strFilterCriteria + " )"; drAvailables = dtAssets.Select(strFilterCriteria); drSummary["Available"] = drAvailables.Length; drSummary["Selected"] = 0; drSummary["FilterCriteria"] = strFilterCriteria; if (hdnOrderId.Value != "" && hdnOrderId.Value != "0") //Get the selected asset count { foreach (DataRow drAvailable in drAvailables) { DataSet dsSelected = oAssetOrder.GetAssetOrderAssetSelection(Int32.Parse(hdnOrderId.Value), Int32.Parse(drAvailable["AssetId"].ToString())); if (dsSelected.Tables[0].Rows.Count > 0) { drSummary["Selected"] = Int32.Parse(drSummary["Selected"].ToString()) + 1; int intTotalAssetsSelected = Int32.Parse(lblTotalAssetsSelected.Text) + 1; lblTotalAssetsSelected.Text = intTotalAssetsSelected.ToString(); } } } } dtSummary.DefaultView.Sort = strSort; dlAssetsSummary.DataSource = dtSummary; dlAssetsSummary.DataBind(); }