private List <string> GetListWithDataFromRowByUnique(zCollectedRowsTable currentRow, List <string> columnsUniqueNames, int applicationId) { List <string> newValueRowList = new List <string>(); foreach (string uniqueName in columnsUniqueNames) { newValueRowList.Add(GetValueFromKnownRowByUniqueMark(currentRow, uniqueName, applicationId)); } return(newValueRowList); }
private string GetValueFromKnownRowByUniqueMark(zCollectedRowsTable currentRow, string uniqueName, int applicationId) { zColumnTable currentColumn = GetColumnByUniqueMark(uniqueName, applicationId); CompetitionDataContext competitionDataBase = new CompetitionDataContext(); zCollectedDataTable currentCollectedData = (from a in competitionDataBase.zCollectedDataTable where a.FK_CollectedRowsTable == currentRow.ID && a.FK_ColumnTable == currentColumn.ID select a).FirstOrDefault(); if (currentCollectedData == null) { return(""); } DataProcess dataProcess = new DataProcess(); dataProcess.ClearTotalUp(); int dType = (int)currentColumn.DataType; if (dataProcess.IsCellReadWrite(dType)) { return(dataProcess.GetReadWriteString(currentColumn, currentCollectedData)); } if (dataProcess.IsCellCheckBox(dType)) { return(dataProcess.GetBoolDataValue(currentColumn, currentCollectedData).ToString()); } if (dataProcess.IsCellDate(dType)) { return(dataProcess.GetDateDataValue(currentColumn, currentCollectedData).ToString()); } if (dataProcess.IsCellReadOnly(dType)) { return(dataProcess.GetReadOnlyString(currentColumn, currentCollectedData, applicationId, currentRow.ID, 0)); } return(""); }
public string GetReadOnlyString(zColumnTable currentColumn, zCollectedDataTable currentCollectedData, int applicationId, int currentRowId, int gvRowId) { CompetitionDataContext competitionDataBase = new CompetitionDataContext(); DataType dataType = new DataType(); #region iterator if (dataType.IsDataTypeIterator(currentColumn.DataType)) { _toTotalUp = gvRowId; return((gvRowId).ToString()); } #endregion #region sum if (dataType.IsDataTypeSum(currentColumn.DataType)) { zColumnTable columnToSum = (from a in competitionDataBase.zColumnTable where a.ID == currentColumn.FK_ColumnTable select a).FirstOrDefault(); double AllSum = 0; if (dataType.IsDataTypeInteger(columnToSum.DataType)) { AllSum = (int)(from a in competitionDataBase.zCollectedDataTable where a.FK_ColumnTable == columnToSum.ID && a.Active == true join b in competitionDataBase.zCollectedRowsTable on a.FK_CollectedRowsTable equals b.ID where b.Active == true && b.FK_ApplicationTable == applicationId select a.ValueInt).Distinct().Sum(); } if (dataType.IsDataTypeFloat(columnToSum.DataType) || dataType.IsCellCalculateInRow(columnToSum.DataType)) { AllSum = (double) (from a in competitionDataBase.zCollectedDataTable where a.FK_ColumnTable == columnToSum.ID && a.Active == true join b in competitionDataBase.zCollectedRowsTable on a.FK_CollectedRowsTable equals b.ID where b.Active == true && b.FK_ApplicationTable == applicationId select a.ValueDouble).Distinct().Sum(); } if (dataType.IsDataTypeBit(columnToSum.DataType)) { AllSum = (from a in competitionDataBase.zCollectedDataTable where a.FK_ColumnTable == columnToSum.ID && a.Active == true join b in competitionDataBase.zCollectedRowsTable on a.FK_CollectedRowsTable equals b.ID where b.Active == true && b.FK_ApplicationTable == applicationId && a.ValueBit == true select a).Distinct().Count(); } _toTotalUp = AllSum; return(AllSum.ToString()); } #endregion #region ConstantNecessarily if (dataType.IsDataTypeConstantNecessarilyShow(currentColumn.DataType)) { zCollectedDataTable getCollectedData = (from a in competitionDataBase.zCollectedDataTable where a.ID == currentCollectedData.ValueFK_CollectedDataTable select a).FirstOrDefault(); return(getCollectedData.ValueText); } #endregion #region MaxValue if (dataType.IsDataTypeMaxValue(currentColumn.DataType)) { zColumnTable columnToFind = (from a in competitionDataBase.zColumnTable where a.ID == currentColumn.FK_ColumnTable select a).FirstOrDefault(); string tmpResult = ""; if (dataType.IsDataTypeInteger(columnToFind.DataType)) { _toTotalUp = (double)(from a in competitionDataBase.zCollectedDataTable where a.FK_ColumnTable == columnToFind.ID && a.Active == true join b in competitionDataBase.zCollectedRowsTable on a.FK_CollectedRowsTable equals b.ID where b.Active == true && b.FK_ApplicationTable == applicationId select a.ValueInt).Distinct() .OrderByDescending(param => param) .FirstOrDefault(); tmpResult = _toTotalUp.ToString(); } if (dataType.IsDataTypeFloat(columnToFind.DataType)) { _toTotalUp = (double)(from a in competitionDataBase.zCollectedDataTable where a.FK_ColumnTable == columnToFind.ID && a.Active == true join b in competitionDataBase.zCollectedRowsTable on a.FK_CollectedRowsTable equals b.ID where b.Active == true && b.FK_ApplicationTable == applicationId select a.ValueDouble).Distinct() .OrderByDescending(param => param) .FirstOrDefault(); tmpResult = _toTotalUp.ToString(); } if (dataType.IsDataTypeDate(columnToFind.DataType)) { tmpResult = (from a in competitionDataBase.zCollectedDataTable where a.FK_ColumnTable == columnToFind.ID && a.Active == true join b in competitionDataBase.zCollectedRowsTable on a.FK_CollectedRowsTable equals b.ID where b.Active == true && b.FK_ApplicationTable == applicationId select a.ValueDataTime).Distinct() .OrderByDescending(param => param) .FirstOrDefault().ToString().Split(' ')[0]; } return(tmpResult); } #endregion #region MinValue if (dataType.IsDataTypeMinValue(currentColumn.DataType)) { zColumnTable columnToFind = (from a in competitionDataBase.zColumnTable where a.ID == currentColumn.FK_ColumnTable select a).FirstOrDefault(); string tmpResult = ""; if (dataType.IsDataTypeInteger(columnToFind.DataType)) { _toTotalUp = (double) (from a in competitionDataBase.zCollectedDataTable where a.FK_ColumnTable == columnToFind.ID && a.Active == true join b in competitionDataBase.zCollectedRowsTable on a.FK_CollectedRowsTable equals b.ID where b.Active == true && b.FK_ApplicationTable == applicationId select a.ValueInt).Distinct() .OrderBy(param => param) .FirstOrDefault(); tmpResult = _toTotalUp.ToString(); } if (dataType.IsDataTypeFloat(columnToFind.DataType)) { _toTotalUp = (double) (from a in competitionDataBase.zCollectedDataTable where a.FK_ColumnTable == columnToFind.ID && a.Active == true join b in competitionDataBase.zCollectedRowsTable on a.FK_CollectedRowsTable equals b.ID where b.Active == true && b.FK_ApplicationTable == applicationId select a.ValueDouble).Distinct() .OrderBy(param => param) .FirstOrDefault(); tmpResult = _toTotalUp.ToString(); } if (dataType.IsDataTypeDate(columnToFind.DataType)) { tmpResult = (from a in competitionDataBase.zCollectedDataTable where a.FK_ColumnTable == columnToFind.ID && a.Active == true join b in competitionDataBase.zCollectedRowsTable on a.FK_CollectedRowsTable equals b.ID where b.Active == true && b.FK_ApplicationTable == applicationId select a.ValueDataTime).Distinct() .OrderBy(param => param) .FirstOrDefault().ToString().Split(' ')[0]; } return(tmpResult); } #endregion #region CollectedNecessarily if (dataType.IsDataTypeNecessarilyShow(currentColumn.DataType)) { zCollectedDataTable getCollectedData = (from a in competitionDataBase.zCollectedDataTable where a.ID == currentCollectedData.ValueFK_CollectedDataTable select a).FirstOrDefault(); return(getCollectedData.ValueText); } #endregion #region CollectedNecessarilyWithParams if (dataType.IsDataTypeNecessarilyShowWithParam(currentColumn.DataType)) { if (currentCollectedData.ValueFK_CollectedDataTable != null) { zCollectedDataTable getCollectedData = (from a in competitionDataBase.zCollectedDataTable where a.ID == currentCollectedData.ValueFK_CollectedDataTable select a).FirstOrDefault(); return(getCollectedData.ValueText); } } #endregion #region sumWithParams if (dataType.IsDataTypeSymWithParam(currentColumn.DataType)) { zCollectedDataTable collectedDataFrom = (from a in competitionDataBase.zCollectedDataTable where a.FK_CollectedRowsTable == currentRowId && a.FK_ColumnTable == currentColumn.FK_ColumnConnectFromTable select a).FirstOrDefault(); int iD = (int)collectedDataFrom.ValueFK_CollectedDataTable; //мы получили по сути ID мероприятия для которого считаем List <zCollectedRowsTable> collectedDataRowsToSum = (from a in competitionDataBase.zCollectedDataTable where a.Active == true && a.FK_ColumnTable == currentColumn.FK_ColumnConnectToTable && a.ValueFK_CollectedDataTable == iD join b in competitionDataBase.zCollectedRowsTable on a.FK_CollectedRowsTable equals b.ID where b.Active == true && b.FK_ApplicationTable == applicationId select b).Distinct().ToList(); //получили список строк в таблице из которой берем числа для суммирования и только те строки которые нам нужны double sum = 0; foreach (zCollectedRowsTable currentRowToSum in collectedDataRowsToSum) { sum += GetValueFromCollectedData(currentRowToSum.ID, (int)currentColumn.FK_ColumnTable); } _toTotalUp = sum; return(sum.ToString()); } #endregion #region aplikcationName if (dataType.IsDataTypeNameOfApplication(currentColumn.DataType)) { return((from a in competitionDataBase.zApplicationTable where a.ID == applicationId select a.Name).FirstOrDefault()); } #endregion #region oneToOneWithParams if (dataType.IsDataTypeOneToOneWithParams(currentColumn.DataType)) { zColumnTable columnConnectetFrom = (from a in competitionDataBase.zColumnTable where a.ID == currentColumn.FK_ColumnConnectFromTable select a).FirstOrDefault(); zColumnTable columnConnectetTo = (from a in competitionDataBase.zColumnTable where a.ID == currentColumn.FK_ColumnConnectToTable select a).FirstOrDefault(); zColumnTable collumnToGetValue = (from a in competitionDataBase.zColumnTable where a.ID == currentColumn.FK_ColumnTable select a).FirstOrDefault(); zCollectedDataTable collectedDataFrom = (from a in competitionDataBase.zCollectedDataTable where a.Active == true && a.FK_CollectedRowsTable == currentRowId && a.FK_ColumnTable == columnConnectetFrom.ID select a).FirstOrDefault(); // значение которое ссылается if ((columnConnectetFrom != null) && (columnConnectetTo != null) && (collumnToGetValue != null)) { if (columnConnectetFrom.DataType == columnConnectetTo.DataType) // значит оба ссылаются на одного и того же// не тестировано { /* zCollectedRowsTable distatntRow = (from a in competitionDataBase.zCollectedRowsTable * where a.Active == true * join b in competitionDataBase.zCollectedDataTable * on a.ID equals b.FK_CollectedRowsTable * where b.ID == collectedDataFrom.ValueFK_CollectedDataTable * select a).FirstOrDefault(); * * zCollectedDataTable distantRowValue = (from a in competitionDataBase.zCollectedDataTable * where a.Active == true * && a.FK_CollectedRowsTable == distatntRow.ID * && a.FK_ColumnTable == collumnToGetValue.ID * select a).FirstOrDefault(); * * if (distantRowValue != null) * { * if (IsCellReadWrite(collumnToGetValue.DataType)) * { * return (GetReadWriteString(collumnToGetValue, distantRowValue)); * } * }*/ } else //наш ссылается на него { zCollectedRowsTable distatntRow = (from a in competitionDataBase.zCollectedRowsTable where a.Active == true join b in competitionDataBase.zCollectedDataTable on a.ID equals b.FK_CollectedRowsTable where b.ID == collectedDataFrom.ValueFK_CollectedDataTable select a).FirstOrDefault(); //нащли далбнюю строку if (distatntRow != null) //дальней строки нет { zCollectedDataTable distantRowValue = (from a in competitionDataBase.zCollectedDataTable where a.Active == true && a.FK_CollectedRowsTable == distatntRow.ID && a.FK_ColumnTable == collumnToGetValue.ID select a).FirstOrDefault(); if (distantRowValue != null) { if (IsCellReadWrite(collumnToGetValue.DataType)) { return(GetReadWriteString(collumnToGetValue, distantRowValue)); } if (IsCellCalculateInRow(collumnToGetValue.DataType)) { return((distantRowValue.ValueDouble).ToString()); } } } } } } #endregion #region DropDown if (dataType.IsDataTypeDropDown(currentColumn.DataType)) { return(GetDropDownSelectedValueString(currentColumn, currentCollectedData, applicationId, currentRowId)); } #endregion #region applikcationCreateName if (dataType.IsDataTypeApplicationCreateDate(currentColumn.DataType)) { var tmp = (from a in competitionDataBase.zApplicationTable where a.ID == applicationId select a).FirstOrDefault(); if (tmp == null) { return("error"); } if (tmp.CretaDateTime == null) { return("error"); } return(tmp.CretaDateTime.ToString().Split(' ')[0]); } #endregion #region CalcInRow if (dataType.IsCellCalculateInRow(currentColumn.DataType)) { if (currentCollectedData.ValueDouble.ToString() == "") { return(0.ToString()); } _toTotalUp = Convert.ToDouble(currentCollectedData.ValueDouble); return(currentCollectedData.ValueDouble.ToString()); } #endregion #region AtLeastOneWithCheckBox if (dataType.IsDataTypeConstntAtLeastOneWithCheckBoxParam(currentColumn.DataType)) { zCollectedDataTable getCollectedData = (from a in competitionDataBase.zCollectedDataTable where a.ID == currentCollectedData.ValueFK_CollectedDataTable select a).FirstOrDefault(); if (getCollectedData == null) { return(""); } if (getCollectedData.ValueFK_CollectedDataTable == null) { return(""); } zCollectedDataTable getCollectedData2 = (from a in competitionDataBase.zCollectedDataTable where a.ID == getCollectedData.ValueFK_CollectedDataTable select a).FirstOrDefault(); return(getCollectedData2.ValueText); } #endregion return(""); }