private bool CreateRuleTrend(string fileName, int seriesId)
 {
     lock (createRuleTrends)
     {
         try
         {
             var list  = ModelGenerate.GenerateRuleTrends(seriesId);
             var rules = new RuleTrendsService();
             if (list != null)
             {
                 for (int i = 0; i < list.Count; ++i)
                 {
                     rules.InsertElement(new RuleTrendBindingModel
                     {
                         SeriesId         = seriesId,
                         FuzzyTrendName   = Converter.ToFuzzyTrendLabel(list[i].FuzzyTrendName),
                         FuzzyTrendId     = Convert.ToInt32(list[i].FuzzyTrendId),
                         FuzzyLabelFromId = Convert.ToInt32(list[i].FuzzyLabelFromId),
                         FuzzyLabelToId   = Convert.ToInt32(list[i].FuzzyLabelToId)
                     });
                 }
                 return(true);
             }
             else
             {
                 throw new Exception("Не получен список правил");
             }
         }
         catch (Exception ex)
         {
             throw new Exception(string.Format("CreateRuleTrend {0}: {1}", fileName, ex.Message));
         }
     }
 }
 private void buttonApply_Click(object sender, EventArgs e)
 {
     try
     {
         var rules = new RuleTrendsService();
         if (MessageBox.Show("Сохранить правила?", "Анализ временных рядов", MessageBoxButtons.YesNo,
                             MessageBoxIcon.Question) == DialogResult.Yes)
         {
             for (int i = 0; i < dataGridView.Rows.Count; ++i)
             {
                 rules.InsertElement(new RuleTrendBindingModel
                 {
                     SeriesId         = _seriesId,
                     FuzzyTrendName   = Converter.ToFuzzyTrendLabel(dataGridView.Rows[i].Cells[1].Value.ToString()),
                     FuzzyTrendId     = Convert.ToInt32(dataGridView.Rows[i].Cells[5].Value),
                     FuzzyLabelFromId = Convert.ToInt32(dataGridView.Rows[i].Cells[6].Value),
                     FuzzyLabelToId   = Convert.ToInt32(dataGridView.Rows[i].Cells[7].Value)
                 });
             }
             DialogResult = DialogResult.OK;
             Close();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Ошибка при добавлении: " + ex.Message, "Анализ временных рядов", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }