Пример #1
0
 private void FormMain_Load(object sender, EventArgs e)
 {
     this.Cursor = Cursors.WaitCursor;
     settings    = new SettingsManager(Settings.SettingsFile, new string[] { "roots =1" });
     c           = new Calculator(Settings.SettingsFile);
     selected    = new List <Parameter>();
     found       = new List <TreeNode>();
     xl          = new XLSExport(Settings.SettingsFile);
     int[] r = null;
     try
     {
         r = settings["roots"].Split(';').Select(s => int.Parse(s.Trim())).ToArray();
     }
     catch (Exception ex)
     {
         formError frm = new formError("Невозможно прочитать в настройках список корней",
                                       "Ошибка!", Settings.ErrorInfo(ex, "formMain.FormMain_Load"));
         frm.ShowDialog();
         Application.Exit();
     }
     try
     {
         aiis = new AIIS(Settings.SettingsFile, r);
     }
     catch (Exception ex)
     {
         formError frm = new formError("Невозможно создать главный объект",
                                       "Ошибка!", Settings.ErrorInfo(ex, "formMain.FormMain_Load"));
         frm.ShowDialog();
         this.Close();
     }
     this.WindowState = FormWindowState.Maximized;
     calFrom.SetDate(new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1));
     calTill.SetDate(DateTime.Today.AddDays(-1));
     FillTree(null, aiis.Roots);
     LoadPresets();
     aiis.PointsUpdate += Aiis_PointsUpdate;
     this.Cursor        = Cursors.Default;
 }
Пример #2
0
        /// <summary>
        /// Dates horizontally in the two top rows, parameters vertically in the three left columns
        /// </summary>
        /// <param name="selectedParams"></param>
        /// <param name="dtStart"></param>
        /// <param name="dtEnd"></param>
        /// <param name="delta"></param>
        /// <param name="title"></param>
        public void OutputLandscape(List <Parameter> selectedParams, Reports reportType,
                                    DateTime dtStart, DateTime dtEnd, TimeSpan delta, string title, bool integral)
        {
            pb = new frmProgress();
            Excel.Range cell;
            int         percent;
            int         firstColumn = 5, firstRow = 2;
            int         totalParams = selectedParams.Count;
            int         totalColumns = (int)(dtEnd.AddDays(1).Subtract(dtStart).TotalSeconds / delta.TotalSeconds);
            int         totalData = totalColumns * totalParams;
            int         completed = 0;
            int         currentColumn, currentRow;
            string      val;
            DataTable   values;

            #region Prepare table
            xls = new Excel.Application();
            xls.SheetsInNewWorkbook = 1;
            wb = xls.Workbooks.Add();
            Excel.Worksheet ws = (Excel.Worksheet)wb.Worksheets[1];
            ws.Name                  = title;
            cell                     = (Excel.Range)(ws.Cells[1, 1]);
            cell.Value               = "Подстанция";
            cell.ColumnWidth         = 24;
            cell.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
            cell                     = (Excel.Range)(ws.Cells[1, 2]);
            cell.Value               = "Присоединение";
            cell.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
            cell.ColumnWidth         = 24;
            cell                     = (Excel.Range)(ws.Cells[1, 3]);
            cell.Value               = "Канал";
            cell.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
            cell.ColumnWidth         = 8;
            cell                     = (Excel.Range)(ws.Cells[1, 4]);
            cell.Value               = "Сумма";
            cell.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
            cell.ColumnWidth         = 16;
            cell.Interior.Color      = Excel.XlRgbColor.rgbGray;
            DateTime currentDate = dtStart;
            currentColumn = firstColumn;
            while (currentDate < dtEnd.AddDays(1))
            {
                cell                     = (Excel.Range)(ws.Cells[1, currentColumn]);
                cell.Value               = currentDate;
                cell.NumberFormat        = (delta.TotalDays >= 1) ? "dd.mm.yyyy" : "dd.mm.yyyy HH:mm;@";
                cell.ColumnWidth         = 18;
                cell.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
                cell.Font.Bold           = true;
                currentDate              = currentDate.Add(delta);
                currentColumn++;
            }
            if (reportType == Reports.PairOfFixed)
            {
                totalColumns = 2;
            }
            else
            {
                totalColumns = (int)(dtEnd.AddDays(1).Subtract(dtStart).TotalSeconds / delta.TotalSeconds);
            }
            #endregion
            currentRow = firstRow;
            pb.Show();
            foreach (Parameter p in selectedParams)
            {
                currentColumn           = firstColumn;
                ws.Cells[currentRow, 1] = p.ParentPoint.GetAncestor(PointTypes.Substation).Name;
                ws.Cells[currentRow, 2] = p.ParentPoint.Name;
                ws.Cells[currentRow, 3] = p.TypeName;
                cell = (Excel.Range)(ws.Cells[currentRow, 4]);
                if (integral)
                {
                    cell.FormulaR1C1 = string.Format("=RC[{0}]-RC[1]", totalColumns);
                }
                else
                {
                    cell.FormulaR1C1 = string.Format("=SUM(RC[1]:RC[{0}])", totalColumns);
                }
                cell.NumberFormat        = "#,##0.00";
                cell.Font.Bold           = true;
                cell.HorizontalAlignment = Excel.XlHAlign.xlHAlignRight;
                cell.Interior.Color      = Excel.XlRgbColor.rgbGrey;
                values = null;
                try
                {
                    switch (reportType)
                    {
                    case Reports.Hours:
                        values = c.HourValues(p.Id.ToString(), dtStart, dtEnd);
                        break;

                    case Reports.Halfhours:
                        values = c.HalfhourValues(p.Id.ToString(), dtStart, dtEnd);
                        break;

                    case Reports.Daily:
                        values = c.DailyValues(p.Id.ToString(), dtStart, dtEnd);
                        break;

                    case Reports.Fixed:
                        values = c.FixedValues(p.Id.ToString(), dtStart, dtEnd, true, false);
                        break;

                    case Reports.FixedWithoutKtr:
                        values = c.FixedValues(p.Id.ToString(), dtStart, dtEnd, false, false);
                        break;

                    case Reports.PairOfFixed:
                        values = c.PairOfFixedValues(p.Id.ToString(), dtStart, dtEnd);
                        break;

                    case Reports.Measured:
                        values = c.FixedValues(p.Id.ToString(), dtStart, dtEnd, false, true);
                        break;

                    case Reports.Log:
                        throw new Exception("PortraitOutput: this method cannot otuput <Meters' logs> report");
                    }
                }
                catch (Exception ex)
                {
                    string details = Settings.ErrorInfo(ex, "XLSExport.OutputLandscape") + Environment.NewLine +
                                     "id_point = " + p.ParentPoint.ID.ToString() + ", id_pp = " + p.Id.ToString();
                    formError frm = new formError("Ошибка при выгрузке значений из БД", "Ошибка!", details);
                    frm.ShowDialog();
                    return;
                }
                foreach (DataRow row in values.Rows)
                {
                    cell = ws.Cells[currentRow, currentColumn];
                    if (row[1] == null || Convert.IsDBNull(row[1]))
                    {
                        val = "--";
                    }
                    else
                    {
                        cell.NumberFormat = "#,##0.00";
                        val = row[1].ToString().Replace(',', '.');
                    }
                    if (row[2] == null || Convert.IsDBNull(row[2]) || (int)row[2] != 0)
                    {
                        cell.Font.Color = Excel.XlRgbColor.rgbRed;
                    }
                    cell.Value = val;
                    currentColumn++;
                    completed++;
                    percent = 100 * completed / totalData;
                    pb.SetProgress(percent);
                }
                currentRow++;
            }
            #region Finish table
            ws.UsedRange.Borders.LineStyle = Excel.XlLineStyle.xlContinuous;
            xls.Visible = true;
            cell        = (Excel.Range)ws.Cells[firstRow, firstColumn];
            cell.Select();
            Excel.Windows xlsWindows = wb.Windows;
            Excel.Window  xlsWindow  = xlsWindows[1];
            xlsWindow.FreezePanes = true;
            wb.Activate();
            xlsWindow.Activate();
            #endregion
            pb.Close();
            releaseObject(ws);
            releaseObject(wb);
            releaseObject(xls);
        }
Пример #3
0
        private void FillTree(TreeNode parent, List <Energosphere.Point> children)
        {
            TreeNode currentNode;

            if (parent == null)
            {
                treePoints.Nodes.Clear();
            }
            int imageIndex;

            try
            {
                foreach (Energosphere.Point point in children)
                {
                    switch (point.Type)
                    {
                    case PointTypes.Abstaract:
                    case PointTypes.Building:
                    case PointTypes.Equipment:
                    case PointTypes.LineLink:
                    case PointTypes.PointLink:
                    case PointTypes.Room:
                    case PointTypes.SupplyPoint:
                    case PointTypes.TN:
                    case PointTypes.TT:
                    case PointTypes.Meter:
                        continue;
                    }
                    if (parent != null && parent.Nodes.ContainsKey(point.ID.ToString()))
                    {
                        continue;
                    }
                    if (imageIndexes.ContainsKey((int)point.Type))
                    {
                        imageIndex = (int)imageIndexes[(int)point.Type];
                    }
                    else
                    {
                        imageIndex = 13;
                    }
                    if (parent == null)
                    {
                        currentNode = treePoints.Nodes.Add(point.ID.ToString(),
                                                           point.Name.ToString(),
                                                           imageIndex,
                                                           imageIndex);
                    }
                    else
                    {
                        currentNode = parent.Nodes.Add(point.ID.ToString(),
                                                       point.Name.ToString(),
                                                       imageIndex,
                                                       imageIndex);
                    }

                    if (point.Type == PointTypes.Feeder || point.Type == PointTypes.FeederWithBypass) // если этот узел - Присоединение или ОВ
                    {
                        foreach (Parameter par in point.Parameters)
                        {
                            currentNode.Nodes.Add("_" + par.Id,
                                                  currentNode.Text + " (" + par.TypeName + ")",
                                                  imageIndexes[(int)PointTypes.PointParameter],
                                                  imageIndexes[(int)PointTypes.PointParameter]);
                        }
                    } // end of if (point.Type == PointTypes.Feeder || point.Type == PointTypes.FeederWithBypass)
                }     // end of foreach (Energosphere.Point point in children)
                txtSelectedCount.Text = "0";
            }         // end of try
            catch (Exception ex)
            {
                string    details = Settings.ErrorInfo(ex, "formMain.FillTree");
                formError err     = new formError("Ошибка при построении дерева",
                                                  "Ошибка!",
                                                  details + Environment.NewLine + "Добавлено узлов: " + treePoints.GetNodeCount(true));
                err.ShowDialog();
            } // end of catch
        }     // end of method FillTree
Пример #4
0
        private void LstPresets_DoubleClick(object sender, EventArgs e)
        {
            string    fileName;
            Parameter current;

            TreeNode[] found;
            if (lstPresets.SelectedIndex >= 0)
            {
                this.Cursor = Cursors.WaitCursor;
                treePoints.CollapseAll();
                fileName = lstPresets.Text + ".pst";
                if (File.Exists(fileName))
                {
                    BtnDeselectAll_Click(sender, e);
                    selected = new List <Parameter>();
                    foreach (string line in File.ReadAllLines(fileName))
                    {
                        current = aiis.AllParameters.FirstOrDefault(p => p.Id.ToString() == line);
                        if (current == null)
                        {
                            current = aiis.LoadParameter(line);
                        }
                        selected.Add(current);
                    }
                    processChecks = false;
                    foreach (Parameter par in selected)
                    {
                        found = treePoints.Nodes.Find("_" + par.Id.ToString(), true);
                        if (found.Length == 1)
                        {
                            found[0].Checked = true;
                        }
                        else
                        {
                            formError frm = new formError("Ошибка загрузки расчетной схемы", "Ошибка!",
                                                          Settings.ErrorInfo(new Exception("Parameter isn't in the tree yet, but it should be"),
                                                                             "formMain.LstPresets_DoubleClick") +
                                                          Environment.NewLine + "ip_pp = " + par.Id.ToString());
                            frm.ShowDialog();
                            Application.Exit();
                        }
                    }
                    found = treePoints.Nodes.Find("_" + selected[0], true);
                    if (found.Length == 1)
                    {
                        found[0].EnsureVisible();
                        treePoints.SelectedNode = found[0];
                    }
                    CountChecked();
                    processChecks = true;
                }
                else
                {
                    var details = Settings.ErrorInfo(null, "formMain.LstPresets_DoubleClick") +
                                  Environment.NewLine + "Files present: " + Environment.NewLine +
                                  string.Join(Environment.NewLine, Directory.GetFiles(Environment.CurrentDirectory));
                    formError frm = new formError("Не найден набор " + lstPresets.Text, "Ошибка!", details);
                    frm.ShowDialog();
                }
                this.Cursor = Cursors.Default;
            }
        }