コード例 #1
0
 public CASExcelParserSubcontr()
 {
     FindTitleBehavior      = new FindExcelTitleSubcontr();
     FindPeriodListBehavior = new FindExcelPeriodListSubcontr();
     FindAllocMoneyBehavior = new FindExcelAllocMoneySubcontr();
 }
コード例 #2
0
        /// <summary>
        /// метод нахождения периодов в Excel файле субподрядчика
        /// </summary>
        /// <param name="path"></param>
        public List <Period> FindPeriodList(object[,] array, int index)
        {
            if (this.array == null)
            {
                this.array = array;
                Cell leftTop = findLeftTopCell();
                leftTop.Row--;
                while (array[leftTop.Row - 1, leftTop.Column] == null)
                {
                    leftTop.Row--;
                }
                for (int i = leftTop.Row; i < array.Length / array.GetLength(1); i++)
                {
                    bool swt = false;
                    for (int j = 1; j <= array.GetLength(1); j++)
                    {
                        DateTime date = findDate(array[i, j]);
                        if (date.Year != 2)
                        {
                            leftTop.Row    = i;
                            leftTop.Column = j;
                            swt            = true;
                            break;
                        }
                    }
                    if (swt)
                    {
                        break;
                    }
                }
                DateTime lastDate = new DateTime();
                for (int i = leftTop.Column; i < array.GetLength(1); i++)
                {
                    DateTime newDate = findDate(array[leftTop.Row, i]);
                    if (newDate.Year != 2)
                    {
                        PeriodsList.Add(newDate);
                        ColumnsPeriodsList.Add(i);
                        lastDate = newDate;
                    }
                    else if (!topCell(leftTop.Row, i))
                    {
                        PeriodsList.Add(lastDate);
                        ColumnsPeriodsList.Add(i);
                    }
                }
                SupplementYears(PeriodsList);
            }

            for (int i = 1, j = 0; i < PeriodsList.Count; i++, j++)
            {
                if (PeriodsList[i].Month == PeriodsList[i - 1].Month)
                {
                    DeletedIndexes.Add(i - 1);
                    PeriodsList.RemoveAt(i - 1);
                    i--;
                }
            }

            FindExcelTitleSubcontr finder = new FindExcelTitleSubcontr();
            int            line           = CellOf(finder.FindTitle(array, index).Title).Row;
            List <decimal> moneys         = new List <decimal>();
            decimal        sum            = 0;

            for (int i = 0; i < ColumnsPeriodsList.Count; i++)
            {
                if (DeletedIndexes.Exists(x => x == i))
                {
                    if (array[line, ColumnsPeriodsList[i]] != null)
                    {
                        sum += decimal.Parse(array[line, ColumnsPeriodsList[i]].ToString());
                    }
                    DeletedIndexes.Remove(i);
                    ColumnsPeriodsList.RemoveAt(i);
                    i--;
                }
                else
                {
                    if (array[line, ColumnsPeriodsList[i]] != null)
                    {
                        moneys.Add(sum + decimal.Parse(array[line, ColumnsPeriodsList[i]].ToString()));
                    }
                    else
                    {
                        moneys.Add(sum);
                    }
                    sum = 0;
                }
            }

            List <Period> result = new List <Period>();

            for (int i = 0; i < PeriodsList.Count; i++)
            {
                Period newPeriod = new Period()
                {
                    Date  = PeriodsList[i],
                    Money = moneys[i]
                };
                result.Add(newPeriod);
            }

            return(result);
        }