Example #1
0
 public MainForm()
 {
     InitializeComponent();
     _pattern = new PattertInfo();
     //_columns = new List<ColumnInfo>();
     FillColumns();
     _allOffers       = new AllOffers();
     _offerCategories = new OfferCategories();
 }
Example #2
0
 private void LinkChilds(OfferCategory category, AllOffers offers)
 {
     foreach (var child in category.Childs)
     {
         child.Offers.Clear();
         foreach (var offer in offers.Offers.Where(offer => offer.CategoryId == child.Id))
         {
             child.Offers.Add(offer);
         }
         LinkChilds(child, offers);
     }
 }
Example #3
0
 public void LinkOffers(AllOffers offers)
 {
     foreach (var category in Categories)
     {
         category.Offers.Clear();
         foreach (var offer in offers.Offers.Where(offer => offer.CategoryId == category.Id))
         {
             category.Offers.Add(offer);
         }
         LinkChilds(category, offers);
     }
 }
Example #4
0
        private void ExportToExcel(string fileName, AllOffers allOffers, List <ColumnInfo> columns)
        {
            if (columns.Count == 0)
            {
                return;
            }
            var s        = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray();
            var rowCount = allOffers.Offers.Count + 1;
            var colCount = columns.Count;

            object[,] arr = new object[rowCount, colCount];
            // добавим заголовки
            var n = 0;

            foreach (var column in columns)
            {
                arr[0, n++] = column.Text;
            }
            // основная таблица, построчно
            var row = 1;

            foreach (var offer in allOffers.Offers)
            {
                n = 0;
                foreach (var column in columns)
                {
                    arr[row, n++] = CalculateValue(offer, _pattern, column, true);
                }
                row++;
            }

            dynamic xl = Activator.CreateInstance(Type.GetTypeFromProgID("Excel.Application"));

            try
            {
                Cursor = Cursors.WaitCursor;
                var wb    = xl.Workbooks.Add();
                var sheet = wb.Sheets[1];
                var range = sheet.Range(string.Format("A1:{0}{1}", s[colCount - 1], rowCount));
                range.Value = arr;
                wb.SaveAs(fileName);
                wb.Close();
            }
            finally
            {
                xl.Quit();
                xl     = null;
                Cursor = Cursors.Default;
            }
        }