private void dgFieldList_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e) { if (e.ColumnIndex == 0) { FieldNameMapper mapper = _fieldListMapper[e.RowIndex]; mapper.Selected = !mapper.Selected; RenumberColumns(); } }
private void btnMoveUp_Click(object sender, EventArgs e) { try { DataGridViewCell cell = dgFieldList.CurrentCell; if (cell.RowIndex != 0) { FieldNameMapper cold = _fieldListMapper[cell.RowIndex]; _fieldListMapper.Remove(cold); _fieldListMapper.Insert(cell.RowIndex - 1, cold); dgFieldList.CurrentCell = dgFieldList[1, cell.RowIndex - 1]; } RenumberColumns(); } catch { } }
protected DataTable GetExportDataTable(List <object> list, List <FieldNameMapper> mapper, object ExportObjectType) { DataTable dt; if (ExportObjectType is Student) { List <Student> listNew = list.ConvertAll(x => x as Student); dt = CommonFunctions.ToDataTable <Student>(listNew); } else if (ExportObjectType is Staff) { List <Staff> listNew = list.ConvertAll(x => x as Staff); dt = CommonFunctions.ToDataTable <Staff>(listNew); } else if (ExportObjectType is Doctor) { List <Doctor> listNew = list.ConvertAll(x => x as Doctor); dt = CommonFunctions.ToDataTable <Doctor>(listNew); } else if (ExportObjectType is Specialist) { List <Specialist> listNew = list.ConvertAll(x => x as Specialist); dt = CommonFunctions.ToDataTable <Specialist>(listNew); } else if (ExportObjectType is Incident) { List <Incident> listNew = list.ConvertAll(x => x as Incident); dt = CommonFunctions.ToDataTable <Incident>(listNew); } else if (ExportObjectType is ResidentRollCall) { List <ResidentRollCall> listNew = list.ConvertAll(x => x as ResidentRollCall); dt = CommonFunctions.ToDataTable <ResidentRollCall>(listNew); } else if (ExportObjectType is ResidentMonthlyCallSummary) { List <ResidentMonthlyCallSummary> listNew = list.ConvertAll(x => x as ResidentMonthlyCallSummary); dt = CommonFunctions.ToDataTable <ResidentMonthlyCallSummary>(listNew); } else if (ExportObjectType is ResidentYearlyCallSummaryByResident) { List <ResidentYearlyCallSummaryByResident> listNew = list.ConvertAll(x => x as ResidentYearlyCallSummaryByResident); dt = CommonFunctions.ToDataTable <ResidentYearlyCallSummaryByResident>(listNew); } else if (ExportObjectType is ResidentYearlyCallSummaryByMonth) { List <ResidentYearlyCallSummaryByMonth> listNew = list.ConvertAll(x => x as ResidentYearlyCallSummaryByMonth); dt = CommonFunctions.ToDataTable <ResidentYearlyCallSummaryByMonth>(listNew); } else { throw new NotImplementedException("not implemented"); } //List<Student> list = this.ExportDataList.ConvertAll(x => x as Student); List <DataColumn> columnsToBeRemoved = new List <DataColumn>(); List <FieldNameMapper> columnsToBeAdded = new List <FieldNameMapper>(); foreach (DataColumn col in dt.Columns) { FieldNameMapper fm = mapper.Find(x => x.PropertyName == col.ColumnName && x.Selected == true); if (fm != null) { columnsToBeAdded.Add(fm); } else { //dt.Columns.Remove(col); columnsToBeRemoved.Add(col); } } foreach (DataColumn col in columnsToBeRemoved) { dt.Columns.Remove(col); } columnsToBeAdded = columnsToBeAdded.OrderBy(x => x.ColumnPosition).ToList(); foreach (FieldNameMapper map in columnsToBeAdded) { DataColumn col = dt.Columns[map.PropertyName]; col.ColumnName = map.PrintName; col.SetOrdinal((int)map.ColumnPosition - 1); } return(dt); }