private void DeleteBudgetRows_ToCompletion() { GridTableView grdTableVw = grdFollowUpBudget.MasterTableView; GridDataItemCollection itemCollection = grdTableVw.Items; foreach (GridItem gridItem in itemCollection) { if (!(gridItem is GridEditableItem)) { continue; } GridEditableItem item = gridItem as GridEditableItem; CheckBox chkSelected = item["SelectBudgetCol"].FindControl("chkDeleteCol") as CheckBox; if (chkSelected == null) { continue; } if (!chkSelected.Checked) { continue; } int idAssociate = ApplicationConstants.INT_NULL_VALUE; int.TryParse(item["IdAssociate"].Text, out idAssociate); FollowUpCompletionBudget followUpCompletionBudget = new FollowUpCompletionBudget(SessionManager.GetSessionValueNoRedirect(this.Page, SessionStrings.CONNECTION_MANAGER)); followUpCompletionBudget.DeleteBudgetRows(currentProject.Id, idAssociate, ReturnBudgetVersionFromCombo()); } }
private void GetSelectedCheckboxes() { GridTableView grdTableVw = grdFollowUpBudget.MasterTableView; GridDataItemCollection itemCollection = grdTableVw.Items; Dictionary <int, bool> selectedItems = new Dictionary <int, bool>(); foreach (GridItem gridItem in itemCollection) { if (!(gridItem is GridEditableItem)) { continue; } GridEditableItem item = gridItem as GridEditableItem; //CheckBox chkSelected = item["SelectWPCol"].FindControl("chkWPCol") as CheckBox; CheckBox chkSelected = item["SelectBudgetCol"].FindControl("chkDeleteCol") as CheckBox; if (chkSelected == null) { continue; } if (!chkSelected.Checked) { continue; } int idAssociate = ApplicationConstants.INT_NULL_VALUE; if (int.TryParse(item["IdAssociate"].Text, out idAssociate)) { selectedItems.Add(idAssociate, true); } } SessionManager.SetSessionValue(this, SELECTED_ITEMS, selectedItems); }
/// <summary> /// Selects the items which have been previously selected /// </summary> /// <param name="collection"></param> /// <param name="items"></param> /// <param name="callback"></param> private void SelectItems(HashSet <string> collection, GridDataItemCollection items, Action <GridDataItem> callback) { GridDataItem currentDataItem; for (int i = 0; i < items.Count; i++) { currentDataItem = items[i]; //Generates the unique identifier for the item string uniqueIdentifier = GenerateUniqueIdentifier(currentDataItem); //Checks if the item was previously selected if (collection.Contains(uniqueIdentifier)) { (currentDataItem.FindControl(CheckBoxId) as CheckBox).Checked = true; currentDataItem.Selected = true; } if (callback != null) { callback.Invoke(currentDataItem); } if (currentDataItem.ChildItem != null) { // If the item has a nested table view selects the child items bool expanded = currentDataItem.Expanded; currentDataItem.Expanded = true; GridTableView ownerTableView = currentDataItem.ChildItem.NestedTableViews[0]; string ownerTableViewDataKeyName = ownerTableView.DataKeyNames[0]; this.SelectItems(TableViews[ownerTableView.Name], ownerTableView.Items, callback); //Returns the previous expanded state currentDataItem.Expanded = expanded; } } }
private void CopyBudgetRows_Revised() { GridTableView grdTableVw = grdCopyBudget.MasterTableView; GridDataItemCollection itemCollection = grdTableVw.Items; foreach (GridItem gridItem in itemCollection) { if (!(gridItem is GridEditableItem)) { continue; } GridEditableItem item = gridItem as GridEditableItem; CheckBox chkSelected = item["SelectAssociateCol"].FindControl("chkSelectAssociate") as CheckBox; if (chkSelected == null) { continue; } if (!chkSelected.Checked) { continue; } int idAssociateNM = ApplicationConstants.INT_NULL_VALUE; int.TryParse(item["IdAssociate"].Text, out idAssociateNM); FollowUpRevisedBudget followUpRevisedBudget = new FollowUpRevisedBudget(SessionManager.GetSessionValueNoRedirect(this.Page, SessionStrings.CONNECTION_MANAGER)); followUpRevisedBudget.CopyRevisedBudget(currentProject.Id, GetIdAssociateLM(), idAssociateNM); } }
public void DoExport(GridCommandEventArgs e, GridColumnCollection Columns, GridDataItemCollection Items) { ExportSettings.ExportOnlyData = true; ExportSettings.OpenInNewWindow = true; ExportSettings.Excel.Format = GridExcelExportFormat.Html; ExportSettings.Pdf.PaperSize = GridPaperSize.A4; ExportSettings.Pdf.PageHeight = Unit.Parse("210mm"); ExportSettings.Pdf.PageWidth = Unit.Parse("297mm"); ExportSettings.Pdf.AllowPrinting = true; switch (e.CommandArgument.ToString()) { case "Excel": Task.Factory.StartNew(() => AsyncExportExcel(Columns, Items)).Wait(); break; case "Word": Task.Factory.StartNew(() => AsyncExportWord(Columns, Items)).Wait(); break; case "Pdf": Task.Factory.StartNew(() => AsyncExportPdf()).Wait(); break; } }
protected void AddBtn_Click(object sender, EventArgs e) { try { txtError.Text = string.Empty; if (!string.IsNullOrEmpty(txtName.Text)) { ProductOption option = new ProductOption(); option.OptionName = txtName.Text; List <ProductOption> childList = null; bool flag = true; if (txtParent.Checked) { childList = new List <ProductOption>(); GridDataItemCollection coll = grdOptions.Items; if (coll != null) { for (int i = 0; i < coll.Count; i++) { CheckBox chk = coll[i].FindControl("txtSelected") as CheckBox; if (chk != null) { GridDataItem dataitem = coll[i]; if (chk.Checked) { GridEditableItem editItem = coll[i] as GridEditableItem; int id = (int)editItem.GetDataKeyValue("ProductOptionID"); ProductOption childOption = (from po in entities.ProductOptions where po.OptionID == id select po).FirstOrDefault(); } } } } } if (flag) { entities.ProductOptions.Add(option); entities.SaveChanges(); SessionMessage = "Product option has been saved successfully."; Response.Redirect("ProductOptions.aspx"); } } else { txtError.Text = "You must provide all valid values."; } } catch (Exception ex) { txtError.Text = (ex.InnerException != null) ? ex.InnerException.Message : ex.Message; } }
/// <summary> /// Event handler for the Click event of btnSave /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnMoveBudget_Click(object sender, EventArgs e) { try { int idAssociateNM = ApplicationConstants.INT_NULL_VALUE; string BudgetCode = GetBudgetCode(); switch (BudgetCode) { case ApplicationConstants.MODULE_REVISED: MoveBudgetRows_Revised(); break; case ApplicationConstants.MODULE_REFORECAST: MoveBudgetRows_ToCompletion(); break; default: throw new NotImplementedException(ApplicationMessages.EXCEPTION_NOT_IMPLEMENTED); } GridTableView grdTableVw = grdMoveBudget.MasterTableView; GridDataItemCollection itemCollection = grdTableVw.Items; string associateNameTo = null; foreach (GridDataItem gridItem in itemCollection) { associateNameTo = gridItem["Associate"].Text; idAssociateNM = GetIdAssociateNM(gridItem); if (idAssociateNM == ApplicationConstants.INT_NULL_VALUE) { continue; } else { break; } } lblMoveBudgetStatus.Text = "Budget successfully moved from " + hdnAssociateName.Value + " to " + associateNameTo; } catch (IndException indExc) { HideChildControls(); ShowError(indExc); return; } catch (Exception exc) { HideChildControls(); ShowError(new IndException(exc)); return; } }
// Rebinds a radgrid and highlights the row based on the value to look for and the field // Used after adding, updating or deleting from a grid public static void HighlightRowByValue_Rebind(RadGrid aGrid, string aUniqueName, string aValue) { GridDataItemCollection _items = aGrid.MasterTableView.Items; aGrid.Rebind(); for (int i = 0; i < _items.Count; i++) { GridDataItem _itemToCheck = _items[i]; if (_itemToCheck[aUniqueName].Text == aValue) { aGrid.MasterTableView.Items[i].Selected = true; break; } } }
protected void btnCopyCoreTeam_Click(object sender, EventArgs e) { try { GridTableView grdTableVw = grdCopyCoreTeam.MasterTableView; GridDataItemCollection itemCollection = grdTableVw.Items; foreach (GridItem gridItem in itemCollection) { if (!(gridItem is GridEditableItem)) { continue; } GridEditableItem item = gridItem as GridEditableItem; CheckBox chkSelected = item["SelectProjectCol"].FindControl("chkSelectProject") as CheckBox; if (chkSelected == null) { continue; } if (!chkSelected.Checked) { continue; } int idTargetProject = ApplicationConstants.INT_NULL_VALUE; int.TryParse(item["IdProject"].Text, out idTargetProject); ProjectCopyCoreTeam copyCoreTeam = new ProjectCopyCoreTeam(SessionManager.GetSessionValueNoRedirect(this, SessionStrings.CONNECTION_MANAGER)); copyCoreTeam.IdProject = currentProject.Id; copyCoreTeam.IdTargetProject = idTargetProject; int result = copyCoreTeam.CopyProjectCoreTeam(); } LoadGrid(); lblStatus.Text = "Core team successfully copied"; } catch (IndException ex) { ShowError(ex); return; } catch (Exception ex) { ShowError(new IndException(ex)); return; } }
private void MoveBudgetRows_Revised() { GridTableView grdTableVw = grdMoveBudget.MasterTableView; GridDataItemCollection itemCollection = grdTableVw.Items; foreach (GridItem gridItem in itemCollection) { int idAssociateNM = GetIdAssociateNM(gridItem); if (idAssociateNM != ApplicationConstants.INT_NULL_VALUE) { FollowUpRevisedBudget followUpRevisedBudget = new FollowUpRevisedBudget(SessionManager.GetSessionValueNoRedirect(this.Page, SessionStrings.CONNECTION_MANAGER)); followUpRevisedBudget.MoveRevisedBudget(currentProject.Id, GetIdAssociateLM(), idAssociateNM, SessionManager.GetCurrentUser(this).IdAssociate); btnMoveBudget.Visible = false; } } }
private void SetGridHyperlinkUrl() { string budgetVersion = ReturnBudgetVersionFromCombo(); GridDataItemCollection itemCollection = grdFollowUpBudget.Items; foreach (GridItem gridItem in itemCollection) { if (gridItem is GridEditableItem) { GridEditableItem item = gridItem as GridEditableItem; HyperLink gridHyperlink = item["NavigateCol"].FindControl("btnNavigate") as HyperLink; HyperLink copyBudget = item["CopyCol"].FindControl("btnCopyBudget") as HyperLink; int idAssociate = ApplicationConstants.INT_NULL_VALUE; int.TryParse(item["IdAssociate"].Text, out idAssociate); string cmbTypeSelectedValue = CmbTypeSelectedValue; switch (cmbTypeSelectedValue) { case ApplicationConstants.BUDGET_TYPE_INITIAL: gridHyperlink.NavigateUrl = "~/Pages/Budget/WPPreselection/WPPreselection.aspx?Code=" + ApplicationConstants.MODULE_INITIAL + "&IdAssociate=" + idAssociate + "&BudgetVersion=" + budgetVersion + "&IsFromFollowUp=1"; break; case ApplicationConstants.BUDGET_TYPE_REVISED: gridHyperlink.NavigateUrl = "~/Pages/Budget/WPPreselection/WPPreselection.aspx?Code=" + ApplicationConstants.MODULE_REVISED + "&IdAssociate=" + idAssociate + "&BudgetVersion=" + budgetVersion + "&IsFromFollowUp=1"; copyBudget.NavigateUrl = "~/Pages/Budget/CopyBudget/CopyBudget.aspx?Code=" + ApplicationConstants.MODULE_REVISED + "&IdAssociate=" + idAssociate + "&BudgetVersion=" + budgetVersion; break; case ApplicationConstants.BUDGET_TYPE_TOCOMPLETION: gridHyperlink.NavigateUrl = "~/Pages/Budget/WPPreselection/WPPreselection.aspx?Code=" + ApplicationConstants.MODULE_REFORECAST + "&IdAssociate=" + idAssociate + "&BudgetVersion=" + budgetVersion + "&IsFromFollowUp=1"; copyBudget.NavigateUrl = "~/Pages/Budget/CopyBudget/CopyBudget.aspx?Code=" + ApplicationConstants.MODULE_REFORECAST + "&IdAssociate=" + idAssociate + "&BudgetVersion=" + budgetVersion; break; default: gridHyperlink.NavigateUrl = "~/Pages/Budget/WPPreselection/WPPreselection.aspx?Code=" + ApplicationConstants.MODULE_INITIAL + "&IdAssociate=" + idAssociate; break; } gridHyperlink.NavigateUrl += "&BudgetType=" + (cmbType.SelectedIndex - 1); copyBudget.NavigateUrl += "&BudgetType=" + (cmbType.SelectedIndex - 1); } } }
private void MoveBudgetRows_ToCompletion() { int moveReleased = 0; GridTableView grdTableVw = grdMoveBudget.MasterTableView; GridDataItemCollection itemCollection = grdTableVw.Items; ReforecastBudget reforecastBudget = new ReforecastBudget(SessionManager.GetConnectionManager(this)); reforecastBudget.IdProject = currentProject.Id; object lastRevisedValidatedVersion = reforecastBudget.GetLastValidatedVersion(); if (lastRevisedValidatedVersion != null && int.Parse(lastRevisedValidatedVersion.ToString()) > 0) { moveReleased = 1; } foreach (GridItem gridItem in itemCollection) { int idAssociateNM = GetIdAssociateNM(gridItem); if (idAssociateNM == ApplicationConstants.INT_NULL_VALUE) { continue; } else { FollowUpCompletionBudget followUpCompletionBudget = new FollowUpCompletionBudget(SessionManager.GetSessionValueNoRedirect(this.Page, SessionStrings.CONNECTION_MANAGER)); if (moveReleased == 0) { followUpCompletionBudget.MoveCompletionBudget(currentProject.Id, GetIdAssociateLM(), idAssociateNM, SessionManager.GetCurrentUser(this).IdAssociate); } else { followUpCompletionBudget.MoveCompletionBudgetReleasedVersion(currentProject.Id, GetIdAssociateLM(), idAssociateNM, SessionManager.GetCurrentUser(this).IdAssociate); } btnMoveBudget.Visible = false; } } }
private void RestoreSelectedItems() { Dictionary <int, bool> selectedItems = SessionManager.GetSessionValueNoRedirect(this, SELECTED_ITEMS) as Dictionary <int, bool>; if (selectedItems == null) { return; } foreach (KeyValuePair <int, bool> pair in selectedItems) { int idAssociate = pair.Key; GridTableView grdTableVw = grdFollowUpBudget.MasterTableView; GridDataItemCollection itemCollection = grdTableVw.Items; foreach (GridItem gridItem in itemCollection) { if (!(gridItem is GridEditableItem)) { continue; } GridEditableItem item = gridItem as GridEditableItem; //CheckBox chkSelected = item["SelectWPCol"].FindControl("chkWPCol") as CheckBox; CheckBox chkSelected = item["SelectBudgetCol"].FindControl("chkDeleteCol") as CheckBox; if (chkSelected == null) { continue; } int currentAssociate = ApplicationConstants.INT_NULL_VALUE; if (int.TryParse(item["IdAssociate"].Text, out currentAssociate)) { if (currentAssociate == idAssociate) { chkSelected.Checked = true; } } } } }
protected void btnDelete_Click(object sender, EventArgs e) { try { //store the changed values from grid to dataset StoreValuesToDataSet(); GridTableView grdTableVw = grdImportDetails.MasterTableView; GridDataItemCollection itemCollection = grdTableVw.Items; foreach (GridItem gridItem in itemCollection) { if (!(gridItem is GridEditableItem)) { continue; } GridEditableItem item = gridItem as GridEditableItem; HtmlInputCheckBox chkSelected = item["DeleteCol"].FindControl("chkDeleteCol") as HtmlInputCheckBox; if (chkSelected == null) { continue; } if (!chkSelected.Checked) { continue; } int idRow = ApplicationConstants.INT_NULL_VALUE; if (int.TryParse(item["RowNumber"].Text, out idRow)) { DataRow[] dr = DsLogs.Tables[0].Select("IdImport=" + IdImport + " and IdRow=" + idRow); dr[0].Delete(); } } } catch (Exception ex) { ShowError(new IndException(ex)); } }
private void AsyncExportWord(GridColumnCollection Columns, GridDataItemCollection Items) { Table table = ExportHelper.TableFromGrid(Columns, Items); ExportHelper.ExportToWord(table, Page, string.Format("{0}{1}", ExportSettings.FileName, FileHelper.DOC)); }
/// <summary> /// Esegue i comandi presenti sulla griglia. /// /// Filter /// CustomChangePage /// Export /// ExportFull /// Page /// ClearFilter /// /// </summary> /// <param name="e"></param> protected override void OnItemCommand(GridCommandEventArgs e) { switch (e.CommandName) { case "Filter": { CustomPageIndex = 0; FinderFiltering(e); DelegateDataBindingFinder(); break; } case "CustomChangePage": { int newPageIndex; if (int.TryParse(((RadTextBox)e.Item.FindControl("txtCurrentPage")).Text, out newPageIndex)) { CustomPageIndex = newPageIndex - 1; DelegateDataBindingFinder(); } break; } case "Export": { DoExport(e); break; } case "ExportFull": { // TODO: riscrivere la procedura di export. Utilizzare una copia del finder per estrarre i dati da mettere sull'esportazione e mappare le colonne già presenti nella griglia. // Il finder viene chiamato 2 volte: // 1) la prima chiamata serve per riempire tutta la griglia e poi lanciare l'export. // 2) La seconda chiamata invece serve per resettare i dati in gliglia e mettere solo quelli visualizzabili. int oldPageSize = Finder.PageSize, oldPageIndex = Finder.CustomPageIndex, oldGridPageSize = this.PageSize, oldGridPageCount = this.PageCount; // 1) base.PageSize = this.PageCount * this.PageSize; base.CustomPageIndex = 0; Finder.PageSize = this.PageCount * this.PageSize; Finder.CustomPageIndex = 0; DelegateDataBindingFinder(); GridColumnCollection gridColumns = this.Columns; GridDataItemCollection gridItems = this.Items; // 2) this.PageSize = oldGridPageSize; Finder.PageSize = oldPageSize; Finder.CustomPageIndex = oldPageIndex; DelegateDataBindingFinder(); // esporto le colonne e gli elementi presenti nella griglia completa. DoExport(e, gridColumns, gridItems); break; } case "Page": { DoPaging(e); break; } case "ClearFilters": { // TODO: rifare il metodo di pulizia filtri. /* * FilterHelper.RemoveFilterClientState(Page.Session, CommonUtil.GetInstance().AppTempPath, CustomPageIndex + 1); */ Finder.FilterExpressionsClear(); PersistFinder(); DelegateDataBindingFinder(); break; } default: { base.OnItemCommand(e); break; } } }
/// <summary> /// Selects the items which have been previously selected /// </summary> /// <param name="collection"></param> /// <param name="items"></param> /// <param name="callback"></param> private void SelectItems(HashSet<string> collection, GridDataItemCollection items, Action<GridDataItem> callback) { GridDataItem currentDataItem; for (int i = 0; i < items.Count; i++) { currentDataItem = items[i]; //Generates the unique identifier for the item string uniqueIdentifier = GenerateUniqueIdentifier(currentDataItem); //Checks if the item was previously selected if (collection.Contains(uniqueIdentifier)) { (currentDataItem.FindControl(CheckBoxId) as CheckBox).Checked = true; currentDataItem.Selected = true; } if (callback != null) { callback.Invoke(currentDataItem); } if (currentDataItem.ChildItem != null) { // If the item has a nested table view selects the child items bool expanded = currentDataItem.Expanded; currentDataItem.Expanded = true; GridTableView ownerTableView = currentDataItem.ChildItem.NestedTableViews[0]; string ownerTableViewDataKeyName = ownerTableView.DataKeyNames[0]; this.SelectItems(TableViews[ownerTableView.Name], ownerTableView.Items, callback); //Returns the previous expanded state currentDataItem.Expanded = expanded; } } }
/// <summary> /// Creazione della tabella di esportazione a partire dalle colonne e dagli item presenti nella griglia. /// </summary> /// <param name="gridColumns"></param> /// <param name="gridItems"></param> /// <param name="border"></param> /// <returns></returns> public static Table TableFromGrid(GridColumnCollection gridColumns, GridDataItemCollection gridItems, bool border = true) { Table table = new Table(); table.Style.Add("border-collapse", "collapse"); List <KeyValuePair <int, List <string> > > columns = new List <KeyValuePair <int, List <string> > >(); //Recupero estraggo le informazioni delle colonne presenti nella griglia double width = 0; int fanta = 0; foreach (GridColumn col in gridColumns) { if (col.Visible && col.Display && col.UniqueName != "ClientSelectColumn") { List <string> list = new List <string>(); list.Add(col.HeaderText); list.Add(col.ColumnType); list.Add(col.HeaderStyle.Width.Value.ToString()); KeyValuePair <int, List <string> > column = new KeyValuePair <int, List <string> >(fanta, list); columns.Add(column); width += col.HeaderStyle.Width.Value; } fanta = fanta + 1; } //Creo l'intestazione TableRow rowHeader = new TableRow(); foreach (KeyValuePair <int, List <string> > item in columns) { TableCell cellStyle = new TableCell(); double wPerc = (Convert.ToDouble(item.Value[2]) / width) * 100; cellStyle.Width = Unit.Percentage(wPerc); cellStyle.Font.Bold = true; cellStyle.BorderStyle = BorderStyle.Solid; cellStyle.BorderWidth = Unit.Pixel(1); cellStyle.Text = item.Value[0]; rowHeader.Cells.Add(cellStyle); } table.Rows.Add(rowHeader); //Creo i righe contenenti i dati GridDataItemCollection items = gridItems; foreach (GridDataItem item in items) { TableRow rowData = new TableRow(); foreach (KeyValuePair <int, List <string> > x in columns) { if (x.Key >= 0 && x.Key <= item.Cells.Count) { TableCell cellStyle = new TableCell(); cellStyle.BorderStyle = BorderStyle.Solid; cellStyle.BorderWidth = Unit.Pixel(1); // Più 2 per evitare le due colonne iniziali --> calcolo al volo l'offset per eliminare le prime colonne. int offset = Math.Abs(columns.Count - item.Cells.Count); cellStyle.Text = CellToString(item.Cells[x.Key + offset]); rowData.Cells.Add(cellStyle); } } table.Rows.Add(rowData); } return(table); }