Ejemplo n.º 1
0
        private List <List <string> > GetNestedDataList(List <string> columnsUniqueNames, int applicationId)
        {
            List <List <string> > newNestedList = new List <List <string> >();
            //по первому марку найдем список строк в базе
            zColumnTable firstColumnInUniques = GetColumnByUniqueMark(columnsUniqueNames[0], applicationId);

            if (firstColumnInUniques == null)
            {
                return(null);
            }
            List <zCollectedRowsTable> rowsList = GetRowsThatHaveColumn(firstColumnInUniques, applicationId);

            newNestedList.Add(GetColmnNamesForNestedList(columnsUniqueNames, applicationId));
            int i = 1;

            if (rowsList == null)
            {
                return(null);
            }
            foreach (zCollectedRowsTable currentRow in rowsList)
            {
                newNestedList.Add(GetListWithDataFromRowByUnique(currentRow, columnsUniqueNames, applicationId, i));
                i++;
            }

            List <int> toTotalUp = GetToTotalUpColumnIdList(columnsUniqueNames, applicationId);

            if (toTotalUp.Any())
            {
                newNestedList.Add(GetTotalUpStringList(newNestedList, toTotalUp));
            }
            return(newNestedList);
        }
Ejemplo n.º 2
0
        public string   GetDropDownSelectedValueString(zColumnTable currentColumn, zCollectedDataTable currentCollectedData, int applicationId, int currentRowId)
        {
            CompetitionDataContext competitionDataBase = new CompetitionDataContext();
            DataType dataType = new DataType();

            #region ConstantDropDown

            if (dataType.IsDataTypeConstantDropDown(currentColumn.DataType))
            {
                zCollectedDataTable getCollectedData =
                    (from a in competitionDataBase.zCollectedDataTable
                     where a.ID == currentCollectedData.ValueFK_CollectedDataTable
                     select a).FirstOrDefault();
                return(getCollectedData.ValueText);
            }

            #endregion
            #region OtherTableDropDown

            if (dataType.IsDataTypeDropDown(currentColumn.DataType))
            {
                zCollectedDataTable getCollectedData =
                    (from a in competitionDataBase.zCollectedDataTable
                     where a.ID == currentCollectedData.ValueFK_CollectedDataTable
                     select a).FirstOrDefault();
                return(getCollectedData.ValueText);
            }

            #endregion
            return("");
        }
Ejemplo n.º 3
0
        public double   GetValueFromCollectedData(int rowId, int columnId)
        {
            CompetitionDataContext competitionDataBase = new CompetitionDataContext();
            zColumnTable           currentColumn       = (from a in competitionDataBase.zColumnTable
                                                          where a.ID == columnId
                                                          select a).FirstOrDefault();
            DataType dataType = new DataType();

            if (columnId != null)
            {
                zCollectedDataTable currenCollectedDataTable = (from a in competitionDataBase.zCollectedDataTable
                                                                where a.Active == true &&
                                                                a.FK_ColumnTable == columnId &&
                                                                a.FK_CollectedRowsTable == rowId
                                                                select a).FirstOrDefault();

                if (dataType.IsDataTypeFloat(currentColumn.DataType) || dataType.IsCellCalculateInRow(currentColumn.DataType))
                {
                    return((double)currenCollectedDataTable.ValueDouble);
                }
                if (dataType.IsDataTypeInteger(currentColumn.DataType))
                {
                    return((double)currenCollectedDataTable.ValueInt);
                }
                if (dataType.IsDataTypeBit(currentColumn.DataType))
                {
                    if ((bool)currenCollectedDataTable.ValueBit)
                    {
                        return(1);
                    }
                }
            }
            return(0);
        }
Ejemplo n.º 4
0
        private bool IsColumnTotalUpByUniqueMark(string uniqueMark, int applicationId)
        {
            zColumnTable myColumn = GetColumnByUniqueMark(uniqueMark, applicationId);

            if (myColumn == null)
            {
                return(false);
            }
            if (myColumn.TotalUp == true)
            {
                return(true);
            }
            return(false);
        }
            private List <List <string> > GetNestedDataList(List <string> columnsUniqueNames, int applicationId)
            {
                List <List <string> > newNestedList = new List <List <string> >();
                //по первому марку найдем список строк в базе
                zColumnTable firstColumnInUniques   = GetColumnByUniqueMark(columnsUniqueNames[0], applicationId);
                List <zCollectedRowsTable> rowsList = GetRowsThatHaveColumn(firstColumnInUniques, applicationId);

                foreach (zCollectedRowsTable currentRow in rowsList)
                {
                    newNestedList.Add(GetListWithDataFromRowByUnique(currentRow, columnsUniqueNames, applicationId));
                }


                return(newNestedList);
            }
Ejemplo n.º 6
0
        private zColumnTable FindColumnWithUniqueMark(int applicationId, string uniqueMark)
        {
            CompetitionDataContext competitionDataBase = new CompetitionDataContext();
            zColumnTable           currentColumn       = (from a in competitionDataBase.zColumnTable
                                                          where a.Active == true &&
                                                          a.UniqueMark == uniqueMark
                                                          join b in competitionDataBase.zSectionTable
                                                          on a.FK_SectionTable equals b.ID
                                                          where b.Active == true
                                                          join c in competitionDataBase.zApplicationTable
                                                          on b.FK_CompetitionsTable equals c.FK_CompetitionTable
                                                          where c.Active == true &&
                                                          c.ID == applicationId
                                                          select a).FirstOrDefault();

            return(currentColumn);
        }
Ejemplo n.º 7
0
        public bool     GetBoolDataValue(zColumnTable currentColumn, zCollectedDataTable currentCollectedData)
        {
            DataType dataType = new DataType();

            #region bit
            if (dataType.IsDataTypeBit(currentColumn.DataType))
            {
                if (currentCollectedData.ValueBit == null)
                {
                    return(false);
                }
                else
                {
                    return((bool)currentCollectedData.ValueBit);
                }
            }
            #endregion
            return(false);
        }
Ejemplo n.º 8
0
        private List <string> GetColmnNamesForNestedList(List <string> columnsUniqueNames, int applicationId)
        {
            List <string> columnNames = new List <string>();

            foreach (string currentUnique in columnsUniqueNames)
            {
                zColumnTable currentColumn = GetColumnByUniqueMark(currentUnique, applicationId);
                //CompetitionDataContext competitionDataBase = new CompetitionDataContext();
                if (currentColumn != null)
                {
                    columnNames.Add(currentColumn.Name);
                }
                else
                {
                    columnNames.Add("Без названия");
                }
            }
            return(columnNames);
        }
            private List <zCollectedRowsTable> GetRowsThatHaveColumn(zColumnTable firstColumn, int applicationId)
            {
                CompetitionDataContext     competitionDataBase       = new CompetitionDataContext();
                List <zCollectedRowsTable> currentCollecterRowsTable =
                    (from a in competitionDataBase.zCollectedRowsTable
                     where a.Active == true &&
                     a.FK_ApplicationTable == applicationId
                     join b in competitionDataBase.zCollectedDataTable
                     on a.ID equals b.FK_CollectedRowsTable
                     where b.Active == true &&
                     b.FK_ColumnTable == firstColumn.ID
                     select a).Distinct().ToList();

                if (currentCollecterRowsTable.Count < 1)
                {
                    return(null);//нет строк
                }
                return(currentCollecterRowsTable);
            }
 protected void DeleteButtonClick(object sender, EventArgs e)
 {
     Button button = (Button)sender;
     {
         int iD = Convert.ToInt32(button.CommandArgument);
         CompetitionDataContext competitionDataBase = new CompetitionDataContext();
         zColumnTable           columnToDelete      = (from a in competitionDataBase.zColumnTable
                                                       where a.ID == iD
                                                       select a).FirstOrDefault();
         if (columnToDelete != null)
         {
             columnToDelete.Active = false;
             competitionDataBase.SubmitChanges();
         }
         else
         {
             //error
         }
     }
 }
            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("");
            }
Ejemplo n.º 12
0
        public DateTime GetDateDataValue(zColumnTable currentColumn, zCollectedDataTable currentCollectedData)
        {
            DataType dataType = new DataType();

            #region date

            if (dataType.IsDataTypeDate(currentColumn.DataType))
            {
                if (currentCollectedData.ValueDataTime == null)
                {
                    return(DateTime.Today);
                }
                else
                {
                    return((DateTime)currentCollectedData.ValueDataTime);
                }
            }

            #endregion

            return(DateTime.Today);
        }
Ejemplo n.º 13
0
        public string   GetStringValueFromCollectedData(int rowId, int columnId)
        {
            CompetitionDataContext competitionDataBase = new CompetitionDataContext();
            zColumnTable           currentColumn       = (from a in competitionDataBase.zColumnTable
                                                          where a.ID == columnId
                                                          select a).FirstOrDefault();
            DataType dataType = new DataType();

            if (columnId != null)
            {
                zCollectedDataTable currenCollectedDataTable = (from a in competitionDataBase.zCollectedDataTable
                                                                where a.Active == true &&
                                                                a.FK_ColumnTable == columnId &&
                                                                a.FK_CollectedRowsTable == rowId
                                                                select a).FirstOrDefault();

                if (dataType.IsDataTypeText(currentColumn.DataType))
                {
                    return(currenCollectedDataTable.ValueText);
                }
            }
            return("");
        }
        private string FindValue(zColumnTable column, int applicationId)
        {
            CompetitionDataContext competitionDataBase = new CompetitionDataContext();
            DataType dataType = new DataType();

            List <zCollectedDataTable> collectedDataList = (from a in competitionDataBase.zCollectedDataTable
                                                            where a.FK_ColumnTable == column.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).Distinct().ToList();

            if (collectedDataList.Count == 1)
            {
                if (dataType.IsDataTypeText(column.DataType))
                {
                    return(collectedDataList[0].ValueText);
                }
            }

            return("NULL");
        }
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!Page.IsPostBack)
     {
         DataType dataType = new DataType();
         DataTypeDropDownList.Items.AddRange(dataType.GetDataTypeListItemCollection());
         var sessionParam1 = Session["CompetitionID"];
         var sessionParam2 = Session["SectionID"];
         var sessionParam3 = Session["ColumnID"];
         if ((sessionParam1 == null) || (sessionParam2 == null) || (sessionParam3 == null))
         {
             //error
             Response.Redirect("ChooseSection.aspx");
         }
         else
         {
             int competitionId = (int)sessionParam1;
             int sectionId     = (int)sessionParam2;
             int columnId      = (int)sessionParam3;
             CompetitionDataContext competitionDataBase = new CompetitionDataContext();
             FkToColumnDropDown.Items.AddRange(GetColumnsInThisApplicationWithoutThisSection(sectionId, competitionId));
             FkToConstantDropDown.Items.AddRange(GetConstantList(competitionId));
             Fk_ColumnConnectFromDropDown.Items.AddRange(GetColumnsInThisSection(sectionId));
             Fk_ColumnConnectToDropDown.Items.AddRange(GetColumnsInThisApplicationWithoutThisSection(sectionId, competitionId));
             BitColumnsDropDown.Items.AddRange(GetColumnsInThisApplicationWithBitDataType(sectionId, competitionId));
             LeftValueDropDown.Items.AddRange(GetColumnsInThisSection(sectionId));
             RightValueDropDown.Items.AddRange(GetColumnsInThisSection(sectionId));
             if (columnId > 0)
             {
                 zColumnTable currentColum = (from a in competitionDataBase.zColumnTable
                                              where a.Active == true &&
                                              a.ID == columnId &&
                                              a.FK_SectionTable == sectionId
                                              select a).FirstOrDefault();
                 if (currentColum == null)
                 {
                     //error
                     Response.Redirect("ChooseColumn.aspx");
                 }
                 else
                 {
                     NameTextBox.Text        = currentColum.Name;
                     DescriptionTextBox.Text = currentColum.Description;
                     UniqueMarkTextBox.Text  = currentColum.UniqueMark;
                     if (currentColum.SortBy != null)
                     {
                         SortByCheckBox.Checked = (bool)currentColum.SortBy;
                     }
                     if (currentColum.TotalUp != null)
                     {
                         TotalUpCheckBox.Checked = (bool)currentColum.TotalUp;
                     }
                     if (currentColum.Visible != null)
                     {
                         VisibleCheckBox.Checked = (bool)currentColum.Visible;
                     }
                     DataTypeDropDownList.SelectedIndex = currentColum.DataType;
                     if (dataType.DataTypeWithConnectionToCollected(currentColum.DataType))
                     {
                         FkToColumnDropDown.Items.FindByValue(currentColum.FK_ColumnTable.ToString()).Selected = true;
                         //ChooseColumnForDropDownDiv.Visible = true;
                     }
                     if (dataType.DataTypeWithConnectionToConstant(currentColum.DataType))
                     {
                         FkToConstantDropDown.Items.FindByValue(currentColum.FK_ConstantListsTable.ToString())
                         .Selected = true;
                         //ChooseConstantForDropDownDiv.Visible = true;
                         //TotalUpCheckBox.Visible = false;
                     }
                     if (dataType.DataTypeWithConnectionToColumnsWithParams(currentColum.DataType))
                     {
                         Fk_ColumnConnectFromDropDown.Items.FindByValue(currentColum.FK_ColumnConnectFromTable.ToString()).Selected = true;
                         Fk_ColumnConnectToDropDown.Items.FindByValue(currentColum.FK_ColumnConnectToTable.ToString()).Selected     = true;
                         //Panel1.Visible = true;
                         FkToColumnDropDown.Items.FindByValue(currentColum.FK_ColumnTable.ToString()).Selected = true;
                         //ChooseColumnForDropDownDiv.Visible = true;
                     }
                     if (dataType.IsCellCalculateInRow(currentColum.DataType))
                     {
                         LeftValueDropDown.Items.FindByValue(currentColum.FK_ColumnConnectFromTable.ToString()).Selected = true;
                         RightValueDropDown.Items.FindByValue(currentColum.FK_ColumnConnectToTable.ToString()).Selected  = true;
                     }
                     if (dataType.DataTypeDependOfBit(currentColum.DataType))
                     {
                         //FkToColumnDropDown.Items.FindByValue(currentColum.FK_ColumnTable.ToString()).Selected = true;
                         BitColumnsDropDown.Items.FindByValue(currentColum.FK_ColumnConnectToTable.ToString()).Selected = true;
                         //ChooseColumnForDropDownDiv.Visible = true;
                         //ChooseBitForDepend.Visible = true;
                     }
                     ShowOnlyAppropriateDivs();
                 }
             }
         }
     }
 }
Ejemplo n.º 16
0
        public bool CreateDocument(string templatePath, string newFilePath, int applicationId, int documentType)
        {
            #region создаем экземпляры нужных классов
            XmlTableCreate xmlTableCreate = new XmlTableCreate();
            #endregion
            #region открываем шаблон
            string      xmlFile  = File.ReadAllText(templatePath);
            XmlDocument document = new XmlDocument();
            document.LoadXml(xmlFile);
            #endregion
            #region старый вариант

            /*
             * List<zColumnTable> columnListWithUniqueMark = FindColumnsWithUniqueMarkExist(applicationId);
             * foreach (zColumnTable currentColumn in columnListWithUniqueMark)
             * {
             *  xmlFile = xmlFile.Replace(currentColumn.UniqueMark, FindValue(currentColumn, applicationId));
             * }*/
            #endregion
            XmlNode sectNode = FindNode(document.ChildNodes, "wx:sect");
            //нам нужен список того в файле что нужно заменить)
            // пока что 2 вхождения ищем
            //1) #Table* заменяем весь ноде после секции
            //2) #Line*  заменяем только значение нода
            TagsToReplace       tagsToReplaceClass  = new TagsToReplace();
            CreateXmlTable      createXmlTableClass = new CreateXmlTable();
            List <TagToReplace> tagsToReplaces      = tagsToReplaceClass.GetTagsToReplace(document);
            //мы получили список того что нужно заменить
            #region поочереди заменяем
            foreach (TagToReplace currentTagToReplace in tagsToReplaces)
            {
                if (currentTagToReplace.ReplaceType == 2)
                {
                    XmlNode newXmlNode = createXmlTableClass.GetXmlTable(document, currentTagToReplace, applicationId);
                    if (newXmlNode != null)
                    {
                        document.ImportNode(newXmlNode, true);
                        sectNode.AppendChild(newXmlNode);
                        XmlNode lastNode      = FindNodeByValue(sectNode.ChildNodes, currentTagToReplace.TagsNode.OuterXml);
                        XmlNode nodeToReplace = FindAfterParentNode(sectNode, lastNode);
                        if (nodeToReplace != null)
                        {
                            sectNode.ReplaceChild(newXmlNode, nodeToReplace);
                        }
                    }
                    else
                    {
                        XmlNode childNode = FindNodeByValue(document.ChildNodes, currentTagToReplace.TagsNode.Value);
                        childNode.Value = "Данные не внесены";
                    }
                }
                else if (currentTagToReplace.ReplaceType == 1)
                {
                    XmlNode      childNode     = FindNodeByValue(document.ChildNodes, "ZLinez" + currentTagToReplace.ReplacemantList[0] + "Z");
                    zColumnTable currentColumn = FindColumnWithUniqueMark(applicationId, currentTagToReplace.ReplacemantList[0]);
                    if (currentColumn != null)
                    {
                        childNode.Value = FindValue(currentColumn, applicationId);
                    }
                    if (childNode == null)
                    {
                        //childNode.Value = "Значение отсутствует";
                    }
                }
            }
            #endregion
            #region подчищаем и сохраняем в файл
            string newXmlFile = document.OuterXml;
            newXmlFile = newXmlFile.Replace("xmlns:w=\"w\"", "").Replace("xmlns:wx=\"wx\"", "").Replace("xmlns:wsp=\"wsp\"", "");
            File.WriteAllText(newFilePath, newXmlFile);
            #endregion
            #region конвертируем его в другой формат
            Converter converter = new Converter();
            converter.Convert(newFilePath, newFilePath, documentType);
            ConvertedFileExtension = converter.ConvertedFilaExtension;
            ConvertedFilePath      = converter.ConvertedFilePath;
            #endregion
            return(true);
        }
Ejemplo n.º 17
0
        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("");
        }
        protected void CreateSaveButton_Click(object sender, EventArgs e)
        {
            CompetitionDataContext competitionDataBase = new CompetitionDataContext();
            var sessionParam1 = Session["CompetitionID"];
            var sessionParam2 = Session["SectionID"];
            var sessionParam3 = Session["ColumnID"];

            if ((sessionParam1 == null) || (sessionParam2 == null) || (sessionParam3 == null))
            {
                //error
                Response.Redirect("ChooseSection.aspx");
            }
            else
            {
                int      dataTypeSelectedValue = Convert.ToInt32(Convert.ToInt32(DataTypeDropDownList.SelectedValue));
                DataType dataType      = new DataType();
                int      competitionId = (int)sessionParam1;
                int      sectionId     = (int)sessionParam2;
                int      columnId      = (int)sessionParam3;

                zColumnTable currentColumn    = null;
                bool         isNewRowKInTable = false;
                if (columnId > 0)
                {
                    isNewRowKInTable = false;
                }
                else
                {
                    isNewRowKInTable = true;
                }

                if (isNewRowKInTable)
                {
                    currentColumn = new zColumnTable();
                }
                else
                {
                    currentColumn = (from a in competitionDataBase.zColumnTable
                                     where a.Active == true &&
                                     a.ID == columnId &&
                                     a.FK_SectionTable == sectionId
                                     select a).FirstOrDefault();
                }

                if ((NameTextBox.Text.Length > 0) && (DescriptionTextBox.Text.Length > 0))
                {
                    if (currentColumn == null)
                    {
                        //error
                        Response.Redirect("ChooseColumn.aspx");
                    }
                    else
                    {
                        currentColumn.Name            = NameTextBox.Text;
                        currentColumn.Description     = DescriptionTextBox.Text;
                        currentColumn.Active          = true;
                        currentColumn.FK_SectionTable = sectionId;
                        currentColumn.DataType        = dataTypeSelectedValue;
                        currentColumn.TotalUp         = TotalUpCheckBox.Checked;
                        currentColumn.SortBy          = SortByCheckBox.Checked;
                        currentColumn.UniqueMark      = UniqueMarkTextBox.Text;
                        currentColumn.Visible         = VisibleCheckBox.Checked;
                        if (dataType.DataTypeWithConnectionToCollected(dataTypeSelectedValue))
                        {
                            currentColumn.FK_ColumnTable = Convert.ToInt32(FkToColumnDropDown.SelectedValue);
                        }
                        if (dataType.DataTypeWithConnectionToConstant(dataTypeSelectedValue))
                        {
                            currentColumn.FK_ConstantListsTable = Convert.ToInt32(FkToConstantDropDown.SelectedValue);
                        }
                        if (dataType.DataTypeWithConnectionToColumnsWithParams(dataTypeSelectedValue))
                        {
                            currentColumn.FK_ColumnTable            = Convert.ToInt32(FkToColumnDropDown.SelectedValue);
                            currentColumn.FK_ColumnConnectFromTable = Convert.ToInt32(Fk_ColumnConnectFromDropDown.SelectedValue);
                            currentColumn.FK_ColumnConnectToTable   = Convert.ToInt32(Fk_ColumnConnectToDropDown.SelectedValue);
                        }
                        if (dataType.DataTypeDependOfBit(dataTypeSelectedValue))
                        {
                            //currentColumn.FK_ColumnTable = Convert.ToInt32(FkToColumnDropDown.SelectedValue);
                            currentColumn.FK_ColumnConnectToTable = Convert.ToInt32(BitColumnsDropDown.SelectedValue);
                        }
                        if (isNewRowKInTable)
                        {
                            competitionDataBase.zColumnTable.InsertOnSubmit(currentColumn);
                        }

                        if (dataType.IsCellCalculateInRow(dataTypeSelectedValue))
                        {
                            currentColumn.FK_ColumnConnectFromTable = Convert.ToInt32(LeftValueDropDown.SelectedValue);
                            currentColumn.FK_ColumnConnectToTable   = Convert.ToInt32(RightValueDropDown.SelectedValue);
                        }

                        competitionDataBase.SubmitChanges();
                    }
                }
            }
            Response.Redirect("ChooseColumn.aspx");
        }
Ejemplo n.º 19
0
        public string   GetReadWriteString(zColumnTable currentColumn, zCollectedDataTable currentCollectedData)
        {
            try
            {
                DataType dataType = new DataType();

                #region float

                if (dataType.IsDataTypeFloat(currentColumn.DataType))
                {
                    validator.Enabled                 = true;
                    validator.ContentType             = ValidationDataType.Double;
                    validator.ErrorMessage            = "Только числовое значение!";
                    validator.MinValue                = (-100000000000).ToString();
                    validator.MaxValue                = 100000000000.ToString();
                    validator.RequireValidatorEnabled = true;
                    validator.TextBoxTextMode         = TextBoxMode.SingleLine;
                    if (currentCollectedData.ValueDouble != null)
                    {
                        double doubleValue = (double)currentCollectedData.ValueDouble;
                        _toTotalUp = doubleValue;
                        return(doubleValue.ToString());
                    }
                }

                #endregion

                #region Date

                if (dataType.IsDataTypeDate(currentColumn.DataType))
                {
                    validator.Enabled                 = true;
                    validator.ErrorMessage            = "Введите корректную дату";
                    validator.ContentType             = ValidationDataType.Date;
                    validator.MinValue                = "1900/01/01";
                    validator.MaxValue                = "2100/01/01";
                    validator.RequireValidatorEnabled = true;
                    validator.TextBoxTextMode         = TextBoxMode.SingleLine;
                    if (currentCollectedData.ValueDataTime != null)
                    {
                        DateTime dateTime = (DateTime)currentCollectedData.ValueDataTime;
                        string   tmpStr   = dateTime.ToString().Split(' ')[0];
                        string[] tmpArray = tmpStr.Split('.');
                        string   tmp2     = tmpArray[2] + "-" + tmpArray[1] + "-" + tmpArray[0];
                        return(tmp2);
                    }
                }

                #endregion

                #region int

                validator.Enabled = true;
                if (dataType.IsDataTypeInteger(currentColumn.DataType))
                {
                    validator.ContentType             = ValidationDataType.Integer;
                    validator.ErrorMessage            = "Только целочисленное значение!";
                    validator.MinValue                = Int32.MinValue.ToString();
                    validator.MaxValue                = Int32.MaxValue.ToString();
                    validator.RequireValidatorEnabled = true;
                    validator.TextBoxTextMode         = TextBoxMode.SingleLine;
                    if (currentCollectedData.ValueInt != null)
                    {
                        int intValue = (int)currentCollectedData.ValueInt;
                        _toTotalUp = intValue;
                        return(intValue.ToString());
                    }
                }

                #endregion

                #region text

                if (dataType.IsDataTypeText(currentColumn.DataType))
                {
                    validator.Enabled                 = false;
                    validator.ContentType             = ValidationDataType.String;
                    validator.ErrorMessage            = "Введите текст!";
                    validator.MinValue                = 1.ToString();
                    validator.MaxValue                = 50000.ToString();
                    validator.RequireValidatorEnabled = true;
                    validator.TextBoxTextMode         = TextBoxMode.MultiLine;
                    return(currentCollectedData.ValueText);
                }

                #endregion
            }
            catch
            {
                return("0");
            }

            return("0");
        }