Beispiel #1
0
 void OnDestroy()
 {
     if (GameManager.Instance.isSoundOn)
     {
         Gauss.PlayProjectileExplosionSound();
     }
 }
Beispiel #2
0
        public override void FindBestCuts()
        {
            unchecked
            {
                for (int i = 0; i < cutcosts.Length(); i++)
                {
                    NarrayUtil.ExtPut(dimage, i, (int)(cutcosts[i] + 10), 0xff0000);
                }
                for (int i = 0; i < cutcosts.Length(); i++)
                {
                    NarrayUtil.ExtPut(dimage, i, (int)(min_thresh + 10), 0x800000);
                }
            }
            Floatarray temp = new Floatarray();

            Gauss.Gauss1d(temp, cutcosts, 3.0f);
            cutcosts.Move(temp);
            SegmRoutine.local_minima(ref bestcuts, cutcosts, min_range, min_thresh);
            for (int i = 0; i < bestcuts.Length(); i++)
            {
                Narray <Point> cut = cuts[bestcuts[i]];
                for (int j = 0; j < cut.Length(); j++)
                {
                    Point p = cut[j];
                    NarrayUtil.ExtPut(dimage, p.X, p.Y, 0x00ff00);
                }
            }
            ///-if(debug.Length > 0) write_image_packed(debug, dimage);
            // dshow1d(cutcosts,"Y");
            //dshow(dimage,"Y");
        }
Beispiel #3
0
        public void GetGuassTest(int[,] matrix, int[] expected)
        {
            Gauss gauss = new Gauss(matrix);

            int[] actual = gauss.GetGuass();
            Assert.AreEqual(expected, actual);
        }
Beispiel #4
0
        //高斯反算
        private void btnSConvert_Click(object sender, EventArgs e)
        {
            //从ListView中获取坐标值
            List <string> listStrX = new List <string>();
            List <string> listStrY = new List <string>();

            Data.FromListView(this.listSSource, listStrX, listStrY);

            int ykm = Convert.ToInt32(txtYKM.Text) / 1000;
            //获取所选椭球参数值
            double a = Convert.ToDouble(txtA.Text);
            //由于double精度有限,所以选择通过扁率的倒数β来计算e的平方
            double e2 = (2 * Convert.ToDouble(txtB.Text) - 1) /
                        Convert.ToDouble(txtB.Text) / Convert.ToDouble(txtB.Text);
            Gauss gauss = new Gauss(a, e2);

            MyList <string> BLStr = new MyList <string>();

            for (int i = 0; i < listStrX.Count; i++)
            {
                double Brad = gauss.Get_Brad(Convert.ToDouble(listStrX[i]), Convert.ToDouble(listStrY[i]), ykm);
                double lRad = gauss.Get_lrad(Convert.ToDouble(listStrX[i]), Convert.ToDouble(listStrY[i]), ykm);
                double Bdms = Convert.ToDouble(DmsRad.rad2dms(Brad));
                double ldms = Convert.ToDouble(DmsRad.rad2dms(lRad));
                //保留四位小数
                BLStr.Add(String.Format("{0:f4}", Bdms), String.Format("{0:f4}", ldms));
            }

            listZDes.BeginUpdate();
            Data.AddDataList(listSDes, BLStr.ListX, BLStr.ListY);
            listZDes.EndUpdate();
        }
Beispiel #5
0
        private void btnGauss_Click(object sender, EventArgs e)
        {
            txtMatrix.Clear();
            txtResult.Clear();

            try
            {
                Gauss mt = new Gauss(dgvEcuaciones.RowCount, dgvEcuaciones.ColumnCount);

                float[,] matIn = llenarArray();

                for (int i = 0; i < dgvEcuaciones.RowCount; i++)
                {
                    for (int j = 0; j < dgvEcuaciones.ColumnCount; j++)
                    {
                        mt.SetValue(i, j, matIn[i, j]);
                    }
                }

                mt.Cambio   += new EventHandler <MatrizEventArgs>(mt_Cambio);
                mt.Completo += new EventHandler <MatrizEventArgs>(mt_Completo);

                mt.ApplyGaussMethod();
            }
            catch
            {
                //....
            }
        }
        public void When_Solve_SLE()
        {
            // Arrange
            Matrix A = new Matrix(3, 3);

            A.Elem[0][0] = 2;
            A.Elem[0][1] = 3;
            A.Elem[0][2] = -1;

            A.Elem[1][0] = 1;
            A.Elem[1][1] = -2;
            A.Elem[1][2] = 1;

            A.Elem[2][0] = 1;
            A.Elem[2][1] = 0;
            A.Elem[2][2] = 2;

            Vector F = new Vector(3);

            F.Elem[0] = 9;
            F.Elem[1] = 3;
            F.Elem[2] = 2;

            LUDecomposition lu = new LUDecomposition();


            // Act
            Vector luRes    = lu.StartSolver(A, F);
            Vector gaussRes = Gauss.StartSolver(A, F);

            // Assert
            Assert.That(A * luRes == F);
            Assert.That(A * gaussRes == F);
        }
Beispiel #7
0
        private static Mat GaussBlur(Mat mat, double current, double newSigma)
        {
            var sigma = Math.Sqrt(MathHelper.Sqr(newSigma) - MathHelper.Sqr(current));

            return
                (sigma < 1e-6
                    ? mat.Clone()
                    : ConvolutionHelper.Convolution(mat, Gauss.GetKernel(sigma)));
        }
        public void SolverCoreTestSparseMatrixNd()
        {
            const int    N = 50;
            SparseMatrix a = new SparseMatrix(N, N);

            // Make matrix diagonal
            for (int i = 0; i < N; i++)
            {
                a[i, i] = 1;
            }
            // Apply random rotations around each pair of axes. This will keep det(A) ~ 1
            Random rand = new Random();

            for (int i = 0; i < N; i++)
            {
                for (int j = i + 1; j < N; j++)
                {
                    double       angle = rand.NextDouble() * 2 * Math.PI;
                    SparseMatrix r     = new SparseMatrix(N, N);
                    for (int k = 0; k < N; k++)
                    {
                        r[k, k] = 1;
                    }
                    r[i, i] = r[j, j] = Math.Cos(angle);
                    r[i, j] = Math.Sin(angle);
                    r[j, i] = -Math.Sin(angle);
                    a       = a * r;
                }
            }

            var ainit = a.Copy();
            // Generate random vector
            Vector b = Vector.Zeros(N);

            for (int i = 0; i < N; i++)
            {
                b[i] = rand.NextDouble();
            }

            var binit = b.Clone();
            // Solve system
            Stopwatch sw = new Stopwatch();

            sw.Start();
            Vector x = new Vector(Gauss.Solve(a, b));

            sw.Stop();
            Trace.WriteLine("Gaussian elimination took: " + sw.ElapsedTicks);
            // Put solution into system
            Vector b2 = ainit * x;

            // Verify result is the same
            Assert.IsTrue(Vector.GetLInfinityNorm(binit, b2) < 1e-6);
        }
        public void SolverCoreTest2d()
        {
            var a = new double[][] {
                new double[] { 2, 1 },
                new double[] { -1, 1 }
            };
            var b      = new Vector(1, -2);
            var x      = Gauss.SolveCore(a, b);
            var answer = new Vector(1, -1);

            Assert.IsTrue(Vector.GetLInfinityNorm(x, answer) < 1e-10);
        }
        public void SolverCoreTest3d()
        {
            var a = new double[][] {
                new double[] { 2, 1, -1 },
                new double[] { -3, -1, 2 },
                new double[] { -2, 1, 2 }
            };
            var b      = new Vector(8, -11, -3);
            var x      = Gauss.SolveCore(a, b);
            var answer = new Vector(2, 3, -1);

            Assert.IsTrue(Vector.GetLInfinityNorm(x, answer) < 1e-10);
        }
Beispiel #11
0
        public static void skeletal_features(Bytearray endpoints, Bytearray junctions,
                                             Bytearray image, float presmooth, float skelsmooth)
        {
            Bytearray temp = new Bytearray();

            temp.Copy(image);
            NarrayUtil.Greater(temp, (byte)128, (byte)0, (byte)255);
            if (presmooth > 0f)
            {
                Gauss.Gauss2d(temp, presmooth, presmooth);
                NarrayUtil.Greater(temp, (byte)128, (byte)0, (byte)255);
            }
        }
Beispiel #12
0
        public static void binsmooth(Bytearray binary, Floatarray input, float sigma)
        {
            Floatarray smoothed = new Floatarray();

            smoothed.Copy(input);
            smoothed -= NarrayUtil.Min(smoothed);
            smoothed /= NarrayUtil.Max(smoothed);
            if (sigma > 0)
            {
                Gauss.Gauss2d(smoothed, sigma, sigma);
            }
            binarize_with_threshold(binary, smoothed, 0.5f);
        }
Beispiel #13
0
        private void btnProcessImage_Click(object sender, EventArgs e)
        {
            _algoryths["Собеля"]          = new Sobel(_parameterSettingForm.SobelLimit);
            _algoryths["Гаусса"]          = new Gauss(_parameterSettingForm.Sigma);
            _algoryths["Медианный"]       = new MedianFilter(_parameterSettingForm.WindowSize);
            _algoryths["Скользящее окно"] = new SlidingWindow(_parameterSettingForm.WindowSize);
            if (_imageIsLoaded)
            {
                pictureBoxResult.Image = _algoryths[cmbBox.Text].Process(new Bitmap(pictureBoxResult.Image));
                return;
            }

            MessageBox.Show("Load image first!");
        }
Beispiel #14
0
 public static void main_menu()
 {
     while (true)
     {
         Console.Clear();
         Console.WriteLine("1.solve test matrix");
         Console.WriteLine("2.solve random matrix");
         Console.WriteLine("3.exit");
         char ans = Console.ReadKey().KeyChar;
         switch (ans)
         {
             case '1':
                 {
                     Gauss g = new Gauss(Program.tst, 3);
                     Console.WriteLine("Source matrix : ");
                     Printer.print_2d_array(Program.tst);
                     Console.WriteLine("Solutions : ");
                     Printer.print_1d_array(g.solve_matrix());
                     Console.WriteLine("Determinant : ");
                     Console.WriteLine(g.get_determ());
                     Console.ReadKey();
                     break;
                 }
             case '2':
                 {
                     Gauss g = new Gauss(5);
                     g.init_matrix_randoms(-10, 10);
                     Console.WriteLine("Source matrix : ");
                     Printer.print_2d_array(g.getMatrix);
                     Console.WriteLine("Solutions : ");
                     Printer.print_1d_array(g.solve_matrix());
                     Console.WriteLine("Determinant : ");
                     Console.WriteLine(g.get_determ());
                     Console.ReadKey();
                     break;
                 }
             case '3':
                 {
                     return;
                     //break;
                 }
             default:
                 {
                     main_menu();
                     break;
                 }
         }
     }
 }
Beispiel #15
0
        protected override void OnBarUpdate()
        {
            _price = Input[0];
            if (CurrentBar == 0)
            {
                _w   = 2 * Pi / Period;
                _b   = (1 - Math.Cos(_w)) / (Math.Pow(_sqrtOf2, 2.0 / _poles) - 1);
                _aa  = -_b + Math.Sqrt(_b * _b + 2 * _b);
                _a1  = 1.0 - _aa;
                _a12 = _a1 * _a1;
                _a13 = _a1 * _a1 * _a1;
                _a14 = _a12 * _a12;
                _a2  = _aa * _aa;
                _a3  = _aa * _aa * _aa;
                _a4  = _a2 * _a2;
                _y1  = _price;
                _y2  = _y1;
                _y3  = _y2;
                _y4  = _y3;
            }

            if (CurrentBar < Period)
            {
                return;
            }

            switch (_poles)
            {
            case 1:
                _y = _aa * _price + _a1 * _y1; break;

            case 2:
                _y = _a2 * _price + 2 * _a1 * _y1 - _a12 * _y2; break;

            case 3:
                _y = _a3 * _price + 3 * _a1 * _y1 - 3 * _a12 * _y2 + _a13 * _y3; break;

            case 4:
                _y = _a4 * _price + 4 * _a1 * _y1 - 6 * _a12 * _y2 + 4 * _a13 * _y3 - _a14 * _y4; break;
            }
            if (FirstTickOfBar)
            {
                _y4 = _y3;
                _y3 = _y2;
                _y2 = _y1;
                _y1 = _y;
            }
            Gauss.Set(_y);
        }
Beispiel #16
0
        public void GetZ_Range_AreEqual()
        {
            var tests = new double[] { -4, -3, -2, -1 - 0.5, 0, 0.5, 1, 2, 3, 4 };

            var exp = new double[] { 0, 0.0013, 0.0228, 0.0668, 0.5, 0.6915, 0.8413, 0.9772, 0.9987, 1 };

            for (var i = 0; i < tests.Length; i++)
            {
                var z = Math.Round(Gauss.GetZ(tests[i]), 4);

                Console.WriteLine(z);

                Assert.AreEqual(exp[i], z, "GetZ({0}) should lead to {1}.", tests[i], exp[i]);
            }
        }
Beispiel #17
0
        public void Gauss_Range_RandomTest()
        {
            const int Tests    = 100;
            const int MinValue = -2000000;
            const int MaxValue = int.MaxValue / 6;

            for (int i = 0; i < Tests; ++i)
            {
                long n = rnd.Next(MinValue, MaxValue + 1);

                long?expected = GaussSolution(n);
                long?actual   = Gauss.RangeSum(n);

                Assert.AreEqual(expected, actual);
            }
        }
        protected void rescale(Floatarray outv, Floatarray sub)
        {
            if (sub.Rank() != 2)
            {
                throw new Exception("CHECK_ARG: sub.Rank()==2");
            }
            int   csize  = PGeti("csize");
            int   indent = PGeti("indent");
            float s      = Math.Max(sub.Dim(0), sub.Dim(1)) / (float)(csize - indent - indent);

            if (PGeti("noupscale") > 0 && s < 1.0f)
            {
                s = 1.0f;
            }
            float sig = s * PGetf("aa");
            float dx  = (csize * s - sub.Dim(0)) / 2;
            float dy  = (csize * s - sub.Dim(1)) / 2;

            if (sig > 1e-3f)
            {
                Gauss.Gauss2d(sub, sig, sig);
            }
            outv.Resize(csize, csize);
            outv.Fill(0f);
            for (int i = 0; i < csize; i++)
            {
                for (int j = 0; j < csize; j++)
                {
                    float x = i * s - dx;
                    float y = j * s - dy;
                    if (x < 0 || x >= sub.Dim(0))
                    {
                        continue;
                    }
                    if (y < 0 || y >= sub.Dim(1))
                    {
                        continue;
                    }
                    float value = ImgOps.bilin(sub, x, y);
                    outv[i, j] = value;
                }
            }

            /*Global.Debugf("fe", "{0} {1} ({2}) -> {3} {4} ({5})\n",
             *     sub.Dim(0), sub.Dim(1), NarrayUtil.Max(sub),
             *     outv.Dim(0), outv.Dim(1), NarrayUtil.Max(outv));*/
        }
Beispiel #19
0
        private void toolBL2xy_Click(object sender, EventArgs e)
        {
            Gauss pos = new Gauss(Obs.Datum, Obs.L0);

            for (int i = 0; i < Obs.Data.Count; i++)
            {
                double x, y;
                double B = Obs.Data[i].B;
                double L = Obs.Data[i].L;
                pos.BL2xy(B, L, out x, out y);
                Obs.Data[i].x = x;
                Obs.Data[i].y = y;
            }
            xy = true;
            UpdateViews();
            //return res;
        }
Beispiel #20
0
        public static Polynomial GetApprox(double[] xvals, double[] yvals)
        {
            if (xvals.Length != yvals.Length)
            {
                throw new ArgumentException();
            }
            int n = xvals.Length;

            double[,] coefs = new double[matrSize, matrSize];
            double GetCoef(int row, int column)
            {
                double res = 0;

                for (int i = 0; i < n; i++)
                {
                    res += Math.Pow(xvals[i], row + column);
                }
                return(res);
            }

            for (int i = 0; i < matrSize; i++)
            {
                for (int j = 0; j < matrSize; j++)
                {
                    coefs[i, j] = GetCoef(i, j);
                }
            }
            double GetFr(int row)
            {
                double res = 0;

                for (int i = 0; i < n; i++)
                {
                    res += Math.Pow(xvals[i], row) * yvals[i];
                }
                return(res);
            }

            double[,] fr = new double[matrSize, 1];
            for (int i = 0; i < matrSize; i++)
            {
                fr[i, 0] = GetFr(i);
            }
            double[] solution = Gauss.Solve(new Matrix(coefs, matrSize, matrSize), new Matrix(fr, matrSize, 1));
            return(new Polynomial(solution));
        }
Beispiel #21
0
        public static void scale_to(Floatarray v, Floatarray sub, int csize, float noupscale = 1.0f, float aa = 1.0f)
        {
            // compute the scale factor
            float s = Math.Max(sub.Dim(0), sub.Dim(1)) / (float)csize;

            // don't upscale if that's prohibited
            if (s < noupscale)
            {
                s = 1.0f;
            }

            // compute the offset to keep the input centered in the output
            float dx = (csize * s - sub.Dim(0)) / 2;
            float dy = (csize * s - sub.Dim(1)) / 2;

            // antialiasing via Gaussian convolution
            float sig = s * aa;

            if (sig > 1e-3f)
            {
                Gauss.Gauss2d(sub, sig, sig);
            }

            // now compute the output image via bilinear interpolation
            v.Resize(csize, csize);
            v.Fill(0f);
            for (int i = 0; i < csize; i++)
            {
                for (int j = 0; j < csize; j++)
                {
                    float x = i * s - dx;
                    float y = j * s - dy;
                    if (x < 0 || x >= sub.Dim(0))
                    {
                        continue;
                    }
                    if (y < 0 || y >= sub.Dim(1))
                    {
                        continue;
                    }
                    float value = ImgOps.bilin(sub, x, y);
                    v[i, j] = value;
                }
            }
        }
Beispiel #22
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            for (int i = 0; i < matrixGrid.Children.Count; i++)
            {
                try
                {
                    data[(int)i / 4][i % 4] = Double.Parse(((TextBox)matrixGrid.Children[i]).Text);
                }
                catch (Exception ex)
                {
                    result.Content = ex.Message + " at [" + ((int)i / 4 + 1) + "], [" + (i % 4 + 1) + "] element.";
                    return;
                }
            }

            for(int i = 0; i < vectorB.Children.Count; i++)
            {
                try
                {
                    b[i] = Double.Parse(((TextBox)vectorB.Children[i]).Text);
                }
                catch (Exception ex)
                {
                    result.Content = ex.Message + " at [" + (i + 1) + "] element in vector b.";
                    return;

                }
            }

            Gauss g = new Gauss(4,4);
            double []res = g.Solve(data,b);

            StringBuilder resStrBldr = new StringBuilder();
            for (int i = 0; i < res.Length; i++)
            {
                resStrBldr.Append(res[i]);
                if(i != res.Length - 1)
                    resStrBldr.Append(";\n ");
            }
            result.Content = "Result is \n[ " + resStrBldr + " ]";
        }
Beispiel #23
0
        public static double FindAt(Mat image, int radius, int x, int y)
        {
            var gauss = Gauss.GetFullKernel(radius / 3.0);

            double a = 0, b = 0, c = 0;

            for (var u = -radius; u <= radius; u++)
            {
                for (var v = -radius; v <= radius; v++)
                {
                    var ix         = ConvolutionHelper.ConvolveCell(image, SobelHelper.SobelKernelX, x + u, y + v);
                    var iy         = ConvolutionHelper.ConvolveCell(image, SobelHelper.SobelKernelY, x + u, y + v);
                    var gaussPoint = gauss.GetPixel(u + radius, v + radius, BorderWrapType.Copy);
                    a += gaussPoint * ix * ix;
                    b += gaussPoint * ix * iy;
                    c += gaussPoint * iy * iy;
                }
            }

            return(LambdaMin(a, b, c));
        }
Beispiel #24
0
        //高斯批量正算
        private void btnZConvert_Click(object sender, EventArgs e)
        {
            //从ListView中获取经纬度
            List <string> listStrB = new List <string>();
            List <string> listStrL = new List <string>();

            Data.FromListView(this.listZSource, listStrB, listStrL);

            if (txtn.Text == "")
            {
                MessageBox.Show("请输入带号!", "Error");
                return;
            }

            int    n   = Convert.ToInt32(txtn.Text);
            double l0  = Gauss.l0rad(n);
            int    ykm = Convert.ToInt32(txtYKM.Text) / 1000;
            //获取所选椭球参数值
            double a = Convert.ToDouble(txtA.Text);
            //由于double精度有限,所以选择通过扁率的倒数β来计算e的平方
            double e2 = (2 * Convert.ToDouble(txtB.Text) - 1) /
                        Convert.ToDouble(txtB.Text) / Convert.ToDouble(txtB.Text);
            Gauss gauss = new Gauss(a, e2);

            MyList <string> xyStr = new MyList <string>();

            for (int i = 0; i < listStrB.Count; i++)
            {
                double lrad = DmsRad.dms2rad(listStrL[i]) - l0;
                double x    = gauss.Get_x(DmsRad.dms2rad(listStrB[i]), lrad);
                double y    = gauss.Get_y(DmsRad.dms2rad(listStrB[i]), lrad, n, ykm);

                xyStr.Add(x.ToString(), y.ToString());
            }

            listZDes.BeginUpdate();
            Data.AddDataList(listZDes, xyStr.ListX, xyStr.ListY);
            listZDes.EndUpdate();
        }
Beispiel #25
0
        static void Main(string[] args)
        {
            Console.OutputEncoding = System.Text.Encoding.Default;
            int    a   = 2;
            int    b   = 5;
            double eps = 0.0001;

            Console.WriteLine($"Вiдрiзок iнтегрування —> x = [{a};{b}]");
            Console.WriteLine($"Задана точність еps = {eps}");
            Sympson val = new Sympson();
            int     n   = 10;

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine($"\nМетодом Сімпсона при n = 10:");
            Console.ResetColor();
            Console.WriteLine($"Integral = {val.SympsonMethod(a, b, n):f7}");
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("\nМетодом Гауса при m = 4");
            Console.ResetColor();
            Gauss gauss1 = new Gauss();

            Console.WriteLine($"Integral = {gauss1.gauss(a, b):f7}");
        }
Beispiel #26
0
        /*
         * public static WrappedImage GetHarrisMatrix(int windowSize, int windowRadius, int width, int height)
         * {
         *  WrappedImage harrisMat = new WrappedImage(height, width);
         *
         *  Mat SobelX = SobelHelper.GetSobelX(_image, BorderHandling.Mirror);
         *  Mat SobelY = SobelHelper.GetSobelY(_image, BorderHandling.Mirror);
         *
         *  for (int y = 0; y < height; y++)
         *  {
         *      for (int x = 0; x < width; x++)
         *      {
         *          double[,] gauss = ConvolutionMatrix.CountGaussMatrix(windowSize);
         *
         *          // Считаем матрицу H
         *          double[,] currentMatrix = new double[2, 2];
         *          for (int u = -windowRadius; u <= windowRadius; u++)
         *          {
         *              for (int v = -windowRadius; v <= windowRadius; v++)
         *              {
         *                  double Ix = WrappedImage.getPixel(SobelX, y + u, x + v, BorderHandling.Mirror);
         *                  double Iy = WrappedImage.getPixel(SobelY, y + u, x + v, BorderHandling.Mirror);
         *
         *                  double gaussPoint = CommonMath.getPixel(gauss, u + windowRadius, v + windowRadius, 3);
         *
         *                  currentMatrix[0, 0] += Math.Pow(Ix, 2) * gaussPoint;
         *                  currentMatrix[0, 1] += Ix * Iy * gaussPoint;
         *                  currentMatrix[1, 0] += Ix * Iy * gaussPoint;
         *                  currentMatrix[1, 1] += Math.Pow(Iy, 2) * gaussPoint;
         *              }
         *          }
         *
         *          double[] eigenvalues = getEigenvalues(currentMatrix);
         *          harrisMat.buffer[y, x] = Math.Min(eigenvalues[0], eigenvalues[1]);
         *      }
         *  }
         *
         *  return harrisMat;
         * }
         *
         * static public double[] getEigenvalues(double[,] matrix) // Считаем собственные числа
         * {
         *  double[] eigenvalues = new double[2];
         *
         *  double a = 1;
         *  double b = -matrix[0, 0] - matrix[1, 1];
         *  double c = matrix[0, 0] * matrix[1, 1] - matrix[0, 1] * matrix[1, 0];
         *  double d = Math.Pow(b, 2) - 4 * a * c;
         *  if (Math.Abs(d) < 1e-4)
         *      d = 0;
         *  if (d < 0)
         *  {
         *      return eigenvalues;
         *  }
         *
         *  eigenvalues[0] = (-b + Math.Sqrt(d)) / (2 * a);
         *  eigenvalues[1] = (-b - Math.Sqrt(d)) / (2 * a);
         *
         *  return eigenvalues;
         * }
         */


        public static Mat Find(Mat image, int radius, double threshold, BorderWrapType borderWrap)
        {
            var gauss  = Gauss.GetFullKernel(radius / 3D);
            var gaussK = gauss.Width / 2;

            var dx = new Mat(image.Width, image.Height);
            var dy = new Mat(image.Width, image.Height);

            SobelHelper.Sobel(image, dx, dy, BorderWrapType.Mirror);

            var lambdas = new Mat(image.Width, image.Height);

            for (var x = 0; x < image.Width; x++)
            {
                for (var y = 0; y < image.Height; y++)
                {
                    double a = 0, b = 0, c = 0;

                    for (var u = -radius; u <= radius; u++)
                    {
                        for (var v = -radius; v <= radius; v++)
                        {
                            var multiplier = gauss.GetAt(u + gaussK, v + gaussK);

                            a += multiplier * MathHelper.Sqr(dx.GetPixel(x + u, y + v, borderWrap));
                            b += multiplier * dx.GetPixel(x + u, y + v, borderWrap) *
                                 dy.GetPixel(x + u, y + v, borderWrap);
                            c += multiplier * MathHelper.Sqr(dy.GetPixel(x + u, y + v, borderWrap));
                        }
                    }

                    lambdas.Set(x, y, LambdaMin(a, b, c));
                }
            }

            return(CornerDetectionHelper.FindPoints(lambdas, threshold));
        }
Beispiel #27
0
        public void FindBestCuts()
        {
            /*Intarray segm = new Intarray();
             * segm.Copy(dimage);
             * ImgLabels.simple_recolor(segm);
             * ImgIo.write_image_packed("debug1.png", segm);*/
            unchecked
            {
                for (int i = 0; i < cutcosts.Length(); i++)
                {
                    NarrayUtil.ExtPut(dimage, i, (int)(cutcosts[i] + 10), 0xff0000);
                }
                for (int i = 0; i < cutcosts.Length(); i++)
                {
                    NarrayUtil.ExtPut(dimage, i, (int)(min_thresh + 10), 0x800000);
                }
            }
            Floatarray temp = new Floatarray();

            Gauss.Gauss1d(temp, cutcosts, cost_smooth);
            cutcosts.Move(temp);
            SegmRoutine.local_minima(ref bestcuts, cutcosts, min_range, min_thresh);
            for (int i = 0; i < bestcuts.Length(); i++)
            {
                Narray <Point> cut = cuts[bestcuts[i]];
                for (int j = 0; j < cut.Length(); j++)
                {
                    Point p = cut[j];
                    NarrayUtil.ExtPut(dimage, p.X, p.Y, 0x00ff00);
                }
            }

            /*segm.Copy(dimage);
             * ImgLabels.simple_recolor(segm);
             * ImgIo.write_image_packed("debug2.png", segm);*/
        }
Beispiel #28
0
        public bool LFCS(string projectSUID, int type, float ratedCapacity)
        {
            try
            {
                string strCon1 = ",PSP_ELCDEVICE WHERE PSPDEV.SUID = PSP_ELCDEVICE.DeviceSUID AND PSP_ELCDEVICE.ProjectSUID = '" + projectSUID + "'  AND KSwitchStatus ='0'";
                string strCon2 = null;
                string strCon = null;
                string strData = null;
                string strBus = null;
                string strBranch = null;
                double Rad_to_Deg =  Math.PI / 180;
                {
                   // checkfhandfdj(projectSUID, ratedCapacity);
                    strCon2 = " AND Type = '01'";
                    strCon = strCon1 + strCon2;
                    IList listMX = Services.BaseService.GetList("SelectPSPDEVByCondition", strCon);
                    strCon2 = " AND Type = '05'";
                    strCon = strCon1 + strCon2;
                    IList listXL = Services.BaseService.GetList("SelectPSPDEVByCondition", strCon);
                    strCon2 = " AND Type = '02'";
                    strCon = strCon1 + strCon2;
                    IList listBYQ2 = Services.BaseService.GetList("SelectPSPDEVByCondition", strCon);
                    strCon2 = " AND Type = '03'";
                    strCon = strCon1 + strCon2;
                    IList listBYQ3 = Services.BaseService.GetList("SelectPSPDEVByCondition", strCon);
                    strData += (listXL.Count + listBYQ2.Count + listBYQ3.Count * 3).ToString() + " " + listMX.Count.ToString() + " " + listMX.Count.ToString() + " " + "0.00001" + " " + "100" + " " + "0" + " " + "0";
                    foreach (PSPDEV dev in listXL)
                    {
                        if (dev.KSwitchStatus == "0")
                        {
                            if (strBranch != null)
                            {
                                strBranch += "\r\n";
                            }
                            if (strData != null)
                            {
                                strData += "\r\n";
                            }
                            if (dev.FirstNode==dev.LastNode)
                            {
                                if (dev.UnitFlag == "0")
                                {
                                    strBranch += dev.FirstNode.ToString() + " " + dev.LastNode.ToString() + " " + dev.Name.ToString() + " " + "3" + " " + dev.LineR.ToString() + " " + dev.LineTQ.ToString() + " " + (dev.LineGNDC * 2).ToString() + " " + "0" + " " + "0";
                                    strData += (dev.FirstNode.ToString() + " " + dev.LastNode.ToString() + " " + "0" + " " + (dev.LineR).ToString() + " " + (dev.LineTQ).ToString() + " " + (dev.LineGNDC).ToString() + " " + "0" + " " + dev.Name.ToString());
                                }
                                else
                                {
                                    strBranch += dev.FirstNode.ToString() + " " + dev.LastNode.ToString() + " " + dev.Name.ToString() + " " + "3" + " " + (dev.LineR * ratedCapacity / (dev.ReferenceVolt * dev.ReferenceVolt)).ToString() + " " + (dev.LineTQ * ratedCapacity / (dev.ReferenceVolt * dev.ReferenceVolt)).ToString() + " " + (dev.LineGNDC * 2 * dev.ReferenceVolt * dev.ReferenceVolt / (ratedCapacity * 1000000)).ToString() + " " + "0" + " " + "0";
                                    strData += (dev.FirstNode.ToString() + " " + dev.LastNode.ToString() + " " + "0" + " " + (dev.LineR * ratedCapacity / (dev.ReferenceVolt * dev.ReferenceVolt)).ToString() + " " + (dev.LineTQ * ratedCapacity / (dev.ReferenceVolt * dev.ReferenceVolt)).ToString() + " " + ((dev.LineGNDC) * dev.ReferenceVolt * dev.ReferenceVolt / (ratedCapacity * 1000000)).ToString() + " " + "0" + " " + dev.Name.ToString());
                                }
                            }
                            else
                            {
                                if (dev.UnitFlag == "0")
                                {
                                    strBranch += dev.FirstNode.ToString() + " " + dev.LastNode.ToString() + " " + dev.Name.ToString() + " " + "1" + " " + dev.LineR.ToString() + " " + dev.LineTQ.ToString() + " " + (dev.LineGNDC * 2).ToString() + " " + "0" + " " + "0";
                                    strData += (dev.FirstNode.ToString() + " " + dev.LastNode.ToString() + " " + "0" + " " + (dev.LineR).ToString() + " " + (dev.LineTQ).ToString() + " " + (dev.LineGNDC).ToString() + " " + "0" + " " + dev.Name.ToString());
                                }
                                else
                                {
                                    strBranch += dev.FirstNode.ToString() + " " + dev.LastNode.ToString() + " " + dev.Name.ToString() + " " + "1" + " " + (dev.LineR * ratedCapacity / (dev.ReferenceVolt * dev.ReferenceVolt)).ToString() + " " + (dev.LineTQ * ratedCapacity / (dev.ReferenceVolt * dev.ReferenceVolt)).ToString() + " " + (dev.LineGNDC * 2 * dev.ReferenceVolt * dev.ReferenceVolt / (ratedCapacity * 1000000)).ToString() + " " + "0" + " " + "0";
                                    strData += (dev.FirstNode.ToString() + " " + dev.LastNode.ToString() + " " + "0" + " " + (dev.LineR * ratedCapacity / (dev.ReferenceVolt * dev.ReferenceVolt)).ToString() + " " + (dev.LineTQ * ratedCapacity / (dev.ReferenceVolt * dev.ReferenceVolt)).ToString() + " " + ((dev.LineGNDC) * dev.ReferenceVolt * dev.ReferenceVolt / (ratedCapacity * 1000000)).ToString() + " " + "0" + " " + dev.Name.ToString());
                                }
                            }

                        }
                    }
                    foreach (PSPDEV dev in listBYQ2)
                    {
                        if (dev.KSwitchStatus == "0")
                        {
                            if (strBranch != null)
                            {
                                strBranch += "\r\n";
                            }
                            if (strData != null)
                            {
                                strData += "\r\n";
                            }
                            if (dev.UnitFlag == "0")
                            {
                                strBranch += dev.FirstNode.ToString() + " " + dev.LastNode.ToString() + " " + dev.Name.ToString() + " " + "2" + " " + dev.LineR.ToString() + " " + dev.LineTQ.ToString() + " " + (dev.LineGNDC * 2).ToString() + " " + dev.K.ToString() + " " + dev.G.ToString();
                                strData += (dev.FirstNode.ToString() + " " + dev.LastNode.ToString() + " " + "1" + " " + (dev.LineR).ToString() + " " + (dev.LineTQ).ToString() + " " + (dev.K).ToString() + " " + dev.G.ToString() + " " + dev.Name.ToString());
                            }
                            else
                            {
                                strBranch += dev.FirstNode.ToString() + " " + dev.LastNode.ToString() + " " + dev.Name.ToString() + " " + "2" + " " + (dev.LineR * ratedCapacity / (dev.ReferenceVolt * dev.ReferenceVolt)).ToString() + " " + (dev.LineTQ * ratedCapacity / (dev.ReferenceVolt * dev.ReferenceVolt)).ToString() + " " + (dev.LineGNDC * 2 * dev.ReferenceVolt * dev.ReferenceVolt / (ratedCapacity * 1000000)).ToString() + " " + dev.K.ToString() + " " + dev.G.ToString();
                                strData += (dev.FirstNode.ToString() + " " + dev.LastNode.ToString() + " " + "1" + " " + (dev.LineR * ratedCapacity / (dev.ReferenceVolt * dev.ReferenceVolt)).ToString() + " " + (dev.LineTQ * ratedCapacity / (dev.ReferenceVolt * dev.ReferenceVolt)).ToString() + " " + (dev.K.ToString()).ToString() + " " + dev.G.ToString() + " " + dev.Name.ToString());
                            }
                        }
                    }
                    foreach (PSPDEV dev in listBYQ3)
                    {
                        if (dev.KSwitchStatus == "0")
                        {

                            if (dev.UnitFlag == "0")
                            {
                                if (strBranch != null)
                                {
                                    strBranch += "\r\n";
                                }
                                if (strData != null)
                                {
                                    strData += "\r\n";
                                }
                                strBranch += dev.FirstNode.ToString() + " " + dev.LastNode.ToString() + " " + dev.Name.ToString() + " " + "2" + " " + dev.HuganTQ1.ToString() + " " + dev.HuganTQ4.ToString() + " " + "0" + " " + dev.K.ToString() + " " + "0";
                                strData += (dev.FirstNode.ToString() + " " + dev.LastNode.ToString() + " " + "1" + " " + (dev.HuganTQ1).ToString() + " " + (dev.HuganTQ4).ToString() + " " + (dev.K).ToString() + " " + "0" + " " + dev.Name.ToString());
                                if (strBranch != null)
                                {
                                    strBranch += "\r\n";
                                }
                                if (strData != null)
                                {
                                    strData += "\r\n";
                                }
                                strBranch += dev.LastNode.ToString() + " " + dev.Flag.ToString() + " " + dev.Name.ToString() + " " + "2" + " " + dev.HuganTQ2.ToString() + " " + dev.HuganTQ5.ToString() + " " + "0" + " " + dev.StandardCurrent.ToString() + " " + "0";
                                strData += (dev.LastNode.ToString() + " " + dev.Flag.ToString() + " " + "1" + " " + (dev.HuganTQ2).ToString() + " " + (dev.HuganTQ5).ToString() + " " + (dev.StandardCurrent).ToString() + " " + "0" + " " + dev.Name.ToString());
                                if (strBranch != null)
                                {
                                    strBranch += "\r\n";
                                }
                                if (strData != null)
                                {
                                    strData += "\r\n";
                                }
                                strBranch += dev.FirstNode.ToString() + " " + dev.Flag.ToString() + " " + dev.Name.ToString() + " " + "2" + " " + dev.HuganTQ3.ToString() + " " + dev.ZeroTQ.ToString() + " " + "0" + " " + dev.BigP.ToString() + " " + "0";
                                strData += (dev.FirstNode.ToString() + " " + dev.Flag.ToString() + " " + "1" + " " + (dev.HuganTQ3).ToString() + " " + (dev.ZeroTQ).ToString() + " " + (dev.BigP).ToString() + " " + "0" + " " + dev.Name.ToString());

                            }
                            else
                            {
                                if (strBranch != null)
                                {
                                    strBranch += "\r\n";
                                }
                                if (strData != null)
                                {
                                    strData += "\r\n";
                                }
                                strBranch += dev.FirstNode.ToString() + " " + dev.LastNode.ToString() + " " + dev.Name.ToString() + " " + "2" + " " + (dev.HuganTQ1 * ratedCapacity / (dev.ReferenceVolt * dev.ReferenceVolt)).ToString() + " " + (dev.HuganTQ4 * ratedCapacity / (dev.ReferenceVolt * dev.ReferenceVolt)).ToString() + " " + "0" + " " + dev.K.ToString() + " " + "0";
                                strData += (dev.FirstNode.ToString() + " " + dev.LastNode.ToString() + " " + "1" + " " + (dev.HuganTQ1 * ratedCapacity / (dev.ReferenceVolt * dev.ReferenceVolt)).ToString() + " " + (dev.HuganTQ4 * ratedCapacity / (dev.ReferenceVolt * dev.ReferenceVolt)).ToString() + " " + (dev.K).ToString() + " " + "0" + " " + dev.Name.ToString());
                                if (strBranch != null)
                                {
                                    strBranch += "\r\n";
                                }
                                if (strData != null)
                                {
                                    strData += "\r\n";
                                }
                                strBranch += dev.LastNode.ToString() + " " + dev.Flag.ToString() + " " + dev.Name.ToString() + " " + "2" + " " + (dev.HuganTQ2 * ratedCapacity / (dev.ReferenceVolt * dev.ReferenceVolt)).ToString() + " " + (dev.HuganTQ5 * ratedCapacity / (dev.ReferenceVolt * dev.ReferenceVolt)).ToString() + " " + "0" + " " + dev.StandardCurrent.ToString() + " " + "0";
                                strData += (dev.LastNode.ToString() + " " + dev.Flag.ToString() + " " + "1" + " " + (dev.HuganTQ2 * ratedCapacity / (dev.ReferenceVolt * dev.ReferenceVolt)).ToString() + " " + (dev.HuganTQ5 * ratedCapacity / (dev.ReferenceVolt * dev.ReferenceVolt)).ToString() + " " + (dev.StandardCurrent).ToString() + " " + "0" + " " + dev.Name.ToString());
                                if (strBranch != null)
                                {
                                    strBranch += "\r\n";
                                }
                                if (strData != null)
                                {
                                    strData += "\r\n";
                                }
                                strBranch += dev.FirstNode.ToString() + " " + dev.Flag.ToString() + " " + dev.Name.ToString() + " " + "2" + " " + (dev.HuganTQ3 * ratedCapacity / (dev.ReferenceVolt * dev.ReferenceVolt)).ToString() + " " + (dev.ZeroTQ * ratedCapacity / (dev.ReferenceVolt * dev.ReferenceVolt)).ToString() + " " + "0" + " " + dev.BigP.ToString() + " " + "0";
                                strData += (dev.FirstNode.ToString() + " " + dev.Flag.ToString() + " " + "1" + " " + (dev.HuganTQ3 * ratedCapacity / (dev.ReferenceVolt * dev.ReferenceVolt)).ToString() + " " + (dev.ZeroTQ * ratedCapacity / (dev.ReferenceVolt * dev.ReferenceVolt)).ToString() + " " + (dev.BigP).ToString() + " " + "0" + " " + dev.Name.ToString());
                            }
                        }
                    }
                    foreach (PSPDEV dev in listMX)
                    {
                        if (dev.KSwitchStatus == "0")
                        {
                            if (strBus != null)
                            {
                                strBus += "\r\n";
                            }
                            if (strData != null)
                            {
                                strData += "\r\n";
                            }
                            double outP = 0;
                            double outQ = 0;
                            double inputP = 0;
                            double inputQ = 0;
                            string strCon3 = ",PSP_ELCDEVICE WHERE PSPDEV.SUID = PSP_ELCDEVICE.DeviceSUID AND PSP_ELCDEVICE.ProjectSUID = '" + projectSUID + "' AND Type = '04' AND IName = '" + dev.Name + "'";
                            IList listFDJ = Services.BaseService.GetList("SelectPSPDEVByCondition", strCon3);
                            string strCon4 = ",PSP_ELCDEVICE WHERE PSPDEV.SUID = PSP_ELCDEVICE.DeviceSUID AND PSP_ELCDEVICE.ProjectSUID = '" + projectSUID + "' AND Type = '12' AND IName = '" + dev.Name + "'";
                            IList listFH = Services.BaseService.GetList("SelectPSPDEVByCondition", strCon4);
                            foreach (PSPDEV devFDJ in listFDJ)
                            {
                                if (devFDJ.UnitFlag == "0")
                                {
                                    outP += devFDJ.OutP;
                                    outQ += devFDJ.OutQ;
                                }
                                else
                                {
                                    outP += devFDJ.OutP / ratedCapacity;
                                    outQ += devFDJ.OutQ / ratedCapacity;
                                }
                            }
                            foreach (PSPDEV devFH in listFH)
                            {
                                if (devFH.UnitFlag == "0")
                                {
                                    inputP += devFH.InPutP;
                                    inputQ += devFH.InPutQ;
                                    //上海新加
                                    if (devFH.OutP != 0)
                                    {
                                        inputP += devFH.OutP;
                                    }
                                    if (devFH.OutQ != 0)
                                    {
                                        inputQ += devFH.OutQ;
                                    }
                                }
                                else
                                {
                                    inputP += devFH.InPutP / ratedCapacity;
                                    inputQ += devFH.InPutQ / ratedCapacity;
                                    //上海新加
                                    if (devFH.OutP != 0)
                                    {
                                        inputP += devFH.OutP/ ratedCapacity;
                                    }
                                    if (devFH.OutQ != 0)
                                    {
                                        inputQ += devFH.OutQ/ ratedCapacity;
                                    }
                                }
                            }
                            //if (mxflag.ContainsKey(dev.SUID))
                            //{
                            //    gltj tj = mxflag[dev.SUID];
                            //    outP += tj.outP;
                            //    outQ += tj.outQ;
                            //    inputP += tj.inputP;
                            //    inputQ += tj.inputQ;
                            //}

                            if (dev.UnitFlag == "0")
                            {
                                outP += dev.OutP;
                                outQ += dev.OutQ;
                                inputP += dev.InPutP;
                                inputQ += dev.InPutQ ;
                                strBus += (dev.Number.ToString() + " " + dev.Name.ToString() + " " + MXNodeType(dev.NodeType) + " " + (dev.VoltR ).ToString() + " " + (dev.VoltV * Rad_to_Deg).ToString() + " " + ((inputP - outP)).ToString() + " " + ((inputQ - outQ)).ToString());
                                //strData += (dev.FirstNode.ToString() + " " + dev.LastNode.ToString() + " " + "0" + " " + (dev.LineR).ToString() + " " + (dev.LineTQ).ToString() + " " + (dev.LineGNDC).ToString() + " " + "0" + " " + dev.Name.ToString());
                                if (dev.NodeType == "1")
                                {
                                    strData += (dev.Number.ToString() + " " + dev.Name.ToString() + " " + dev.NodeType + " " + ((outP)).ToString() + " " + ((outQ)).ToString());
                                }
                                else if (dev.NodeType == "2")
                                {
                                    strData += (dev.Number.ToString() + " " + dev.Name.ToString() + " " + dev.NodeType + " " + ((outP)).ToString() + " " + (dev.VoltR).ToString());
                                }
                                else if (dev.NodeType == "0")
                                {
                                    strData += (dev.Number.ToString() + " " + dev.Name.ToString() + " " + dev.NodeType + " " + (dev.VoltR).ToString() + " " + "0");
                                }
                            }
                            else
                            {
                                outP += dev.OutP / ratedCapacity;
                                outQ += dev.OutQ / ratedCapacity;
                                inputP += dev.InPutP / ratedCapacity;
                                inputQ += dev.InPutQ / ratedCapacity;
                                strBus += (dev.Number.ToString() + " " + dev.Name.ToString() + " " + MXNodeType(dev.NodeType) + " " + (dev.VoltR / dev.ReferenceVolt).ToString() + " " + (dev.VoltV * Rad_to_Deg).ToString() + " " + ((inputP - outP)).ToString() + " " + ((inputQ - outQ)).ToString());
                                //strData += (dev.FirstNode.ToString() + " " + dev.LastNode.ToString() + " " + "0" + " " + (dev.LineR * ratedCapacity / (dev.ReferenceVolt * dev.ReferenceVolt)).ToString() + " " + (dev.LineTQ * ratedCapacity / (dev.ReferenceVolt * dev.ReferenceVolt)).ToString() + " " + ((dev.LineGNDC) * dev.ReferenceVolt * dev.ReferenceVolt / (ratedCapacity * 1000000)).ToString() + " " + "0" + " " + dev.Name.ToString());
                                if (dev.NodeType == "1")
                                {
                                    strData += (dev.Number.ToString() + " " + dev.Name.ToString() + " " + dev.NodeType + " " + (outP).ToString() + " " + (outQ).ToString());
                                }
                                else if (dev.NodeType == "2")
                                {
                                    strData += (dev.Number.ToString() + " " + dev.Name.ToString() + " " + dev.NodeType + " " + (outP).ToString() + " " + (dev.VoltR / dev.ReferenceVolt).ToString());
                                }
                                else if (dev.NodeType == "0")
                                {
                                    strData += (dev.Number.ToString() + " " + dev.Name.ToString() + " " + dev.NodeType + " " + (dev.VoltR / dev.ReferenceVolt).ToString() + " " + "0");
                                }
                            }
                        }
                    }
                    foreach (PSPDEV dev in listMX)
                    {
                        if (dev.KSwitchStatus == "0")
                        {
                            if (strData != null)
                            {
                                strData += "\r\n";
                            }
                            double outP = 0;
                            double outQ = 0;
                            double inputP = 0;
                            double inputQ = 0;
                            string strCon3 = ",PSP_ELCDEVICE WHERE PSPDEV.SUID = PSP_ELCDEVICE.DeviceSUID AND PSP_ELCDEVICE.ProjectSUID = '" + projectSUID + "' AND Type = '04' AND IName = '" + dev.Name + "'";
                            IList listFDJ = Services.BaseService.GetList("SelectPSPDEVByCondition", strCon3);
                            string strCon4 = ",PSP_ELCDEVICE WHERE PSPDEV.SUID = PSP_ELCDEVICE.DeviceSUID AND PSP_ELCDEVICE.ProjectSUID = '" + projectSUID + "' AND Type = '12' AND IName = '" + dev.Name + "'";
                            IList listFH = Services.BaseService.GetList("SelectPSPDEVByCondition", strCon4);
                            foreach (PSPDEV devFDJ in listFDJ)
                            {
                                if (devFDJ.UnitFlag == "0")
                                {
                                    outP += devFDJ.OutP;
                                    outQ += devFDJ.OutQ;
                                }
                                else
                                {
                                    outP += devFDJ.OutP / ratedCapacity;
                                    outQ += devFDJ.OutQ / ratedCapacity;
                                }
                            }
                            foreach (PSPDEV devFH in listFH)
                            {
                                if (devFH.UnitFlag == "0")
                                {
                                    inputP += devFH.InPutP;
                                    inputQ += devFH.InPutQ;
                                    //上海新加
                                    if (devFH.OutP != 0)
                                    {
                                        inputP += devFH.OutP;
                                    }
                                    if (devFH.OutQ != 0)
                                    {
                                        inputQ += devFH.OutQ;
                                    }
                                }
                                else
                                {
                                    inputP += devFH.InPutP / ratedCapacity;
                                    inputQ += devFH.InPutQ / ratedCapacity;
                                    //上海新加
                                    if (devFH.OutP != 0)
                                    {
                                        inputP += devFH.OutP/ ratedCapacity;
                                    }
                                    if (devFH.OutQ != 0)
                                    {
                                        inputQ += devFH.OutQ/ ratedCapacity;
                                    }
                                }
                            }
                            if (dev.UnitFlag == "0")
                            {
                                outP += dev.OutP;
                                outQ += dev.OutQ;
                                inputP += dev.InPutP;
                                inputQ += dev.InPutQ;
                            }
                            else
                            {
                                outP += dev.OutP / ratedCapacity;
                                outQ += dev.OutQ / ratedCapacity;
                                inputP += dev.InPutP / ratedCapacity;
                                inputQ += dev.InPutQ / ratedCapacity;
                            }
                            strData += (dev.Number.ToString() + " " + dev.Name.ToString() + " " + "0" + " " + "0" + " " + "0" + " " + "0" + " " + "0" + " " + ((inputP)).ToString() + " " + ((inputQ)).ToString());

                        }
                    }
                }
                if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\data.txt"))
                {
                    File.Delete(System.Windows.Forms.Application.StartupPath + "\\data.txt");
                }
                if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\branch.txt"))
                {
                    File.Delete(System.Windows.Forms.Application.StartupPath + "\\branch.txt");
                }
                if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\bus.txt"))
                {
                    File.Delete(System.Windows.Forms.Application.StartupPath + "\\bus.txt");
                }
                FileStream VK = new FileStream((System.Windows.Forms.Application.StartupPath + "\\data.txt"), FileMode.OpenOrCreate);
                StreamWriter str1 = new StreamWriter(VK, Encoding.Default);
                str1.Write(strData);
                str1.Close();

                FileStream VK1 = new FileStream((System.Windows.Forms.Application.StartupPath + "\\branch.txt"), FileMode.OpenOrCreate);
                StreamWriter str3 = new StreamWriter(VK1, Encoding.Default);
                str3.Write(strBranch);
                str3.Close();
                FileStream L = new FileStream((System.Windows.Forms.Application.StartupPath + "\\bus.txt"), FileMode.OpenOrCreate);
                StreamWriter str2 = new StreamWriter(L, Encoding.Default);
                str2.Write(strBus);
                str2.Close();

                if (strData.Contains("非数字") || strData.Contains("正无穷大") || strBus.Contains("非数字") || strBus.Contains("正无穷大") || strBranch.Contains("非数字") || strBranch.Contains("正无穷大"))
                {
                    MessageBox.Show("缺少参数,请检查输入参数!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return false;
                }

                if (type == 1)
                {
                    if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\PF1.txt"))
                    {
                        File.Delete(System.Windows.Forms.Application.StartupPath + "\\PF1.txt");
                    }
                    if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\DH1.txt"))
                    {
                        File.Delete(System.Windows.Forms.Application.StartupPath + "\\DH1.txt");
                    }
                    if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\IH1.txt"))
                    {
                        File.Delete(System.Windows.Forms.Application.StartupPath + "\\IH1.txt");
                    }
                    NIULA nr = new NIULA();
                    nr.CurrentCal();
                    if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\PF1.txt"))
                    {
                    }
                    else
                    {
                        return false;
                    }
                    FileStream pf = new FileStream(System.Windows.Forms.Application.StartupPath + "\\PF1.txt", FileMode.Open);
                    StreamReader readLine = new StreamReader(pf, Encoding.Default);
                    char[] charSplit = new char[] { ' ' };
                    string strLine = readLine.ReadLine();
                    while (strLine != null && strLine != "")
                    {
                        string[] array1 = strLine.Split(charSplit);
                        strCon2 = " AND Type= '01' AND Number = " + array1[0];
                        strCon = strCon1 + strCon2;
                        PSPDEV devMX = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByCondition", strCon);
                        if (devMX != null)
                        {
                            PSP_ElcDevice elcDev = new PSP_ElcDevice();
                            elcDev.ProjectSUID = projectSUID;
                            elcDev.DeviceSUID = devMX.SUID;
                            elcDev = (PSP_ElcDevice)Services.BaseService.GetObject("SelectPSP_ElcDeviceByKey", elcDev);
                            if (elcDev != null)
                            {
                                elcDev.COL1 = devMX.Name;
                                elcDev.COL19 = devMX.ReferenceVolt.ToString();
                                elcDev.COL20 = ratedCapacity.ToString();
                                double temp = 0.0;
                                double.TryParse(array1[1], out temp);
                                elcDev.COL2 = (temp * (devMX.ReferenceVolt)).ToString();
                                temp = 0.0;
                                double.TryParse(array1[2], out temp);
                                elcDev.COL3 = (temp * Rad_to_Deg).ToString();
                                temp = 0.0;
                                double.TryParse(array1[3], out temp);
                                elcDev.COL4 = (temp * ratedCapacity).ToString();
                                temp = 0.0;
                                double.TryParse(array1[4], out temp);
                                elcDev.COL5 = (temp * ratedCapacity).ToString();

                                Services.BaseService.Update<PSP_ElcDevice>(elcDev);
                            }
                        }
                        strLine = readLine.ReadLine();
                    }
                    readLine.Close();
                    if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\DH1.txt"))
                    {
                    }
                    else
                    {
                        return false;
                    }
                    FileStream dh = new FileStream(System.Windows.Forms.Application.StartupPath + "\\DH1.txt", FileMode.Open);
                    readLine = new StreamReader(dh, Encoding.Default);
                    strLine = readLine.ReadLine();
                    while (strLine != null && strLine != "")
                    {
                        string[] array1 = strLine.Split(charSplit);
                        strCon2 = " AND Type= '05' AND Name = '" + array1[0] + "' AND FirstNode = " + array1[1] + " AND LastNode = " + array1[2];
                        strCon = strCon1 + strCon2;
                        PSPDEV devMX = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByCondition", strCon);
                        if (devMX != null)
                        {
                            PSP_ElcDevice elcDev = new PSP_ElcDevice();
                            elcDev.ProjectSUID = projectSUID;
                            elcDev.DeviceSUID = devMX.SUID;
                            elcDev = (PSP_ElcDevice)Services.BaseService.GetObject("SelectPSP_ElcDeviceByKey", elcDev);
                            if (elcDev != null)
                            {
                                elcDev.COL1 = devMX.Name;
                                elcDev.COL2 = devMX.FirstNode.ToString();
                                elcDev.COL3 = devMX.LastNode.ToString();
                                elcDev.COL19 = devMX.ReferenceVolt.ToString();
                                if (Convert.ToDouble(devMX.Burthen) == 0.0)
                                {
                                    elcDev.COL20 = ratedCapacity.ToString();
                                }
                                else
                                    elcDev.COL20 = devMX.Burthen.ToString();
                                double temp = 0.0;
                                double.TryParse(array1[3], out temp);
                                elcDev.COL4 = (temp * ratedCapacity).ToString();
                                temp = 0.0;
                                double.TryParse(array1[4], out temp);
                                elcDev.COL5 = (temp * ratedCapacity).ToString();
                                temp = 0.0;
                                double.TryParse(array1[5], out temp);
                                elcDev.COL6 = (temp * ratedCapacity).ToString();
                                temp = 0.0;
                                double.TryParse(array1[6], out temp);
                                elcDev.COL7 = (temp * ratedCapacity).ToString();

                                temp = 0.0;
                                double.TryParse(array1[7], out temp);
                                elcDev.COL8 = (temp * ratedCapacity).ToString();
                                temp = 0.0;
                                double.TryParse(array1[8], out temp);
                                elcDev.COL9 = (temp * ratedCapacity).ToString();
                                temp = 0.0;
                                double.TryParse(array1[9], out temp);
                                elcDev.COL10 = (temp * ratedCapacity / (Math.Sqrt(3) * devMX.ReferenceVolt)).ToString();

                                temp = 0.0;
                                double.TryParse(array1[10], out temp);
                                elcDev.COL11 = (temp * Rad_to_Deg).ToString();
                                temp = 0.0;
                                double.TryParse(array1[11], out temp);
                                elcDev.COL12 = (temp * (devMX.ReferenceVolt)).ToString();
                                temp = 0.0;
                                double.TryParse(array1[12], out temp);
                                elcDev.COL13 = (temp * (devMX.ReferenceVolt)).ToString();
                                PSP_ElcDevice elcTemp = (PSP_ElcDevice)Services.BaseService.GetObject("SelectPSP_ElcDeviceByKey", elcDev);

                                Services.BaseService.Update<PSP_ElcDevice>(elcDev);
                            }
                        }
                        strLine = readLine.ReadLine();
                    }
                    readLine.Close();
                    if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\IH1.txt"))
                    {
                    }
                    else
                    {
                        return false;
                    }
                    FileStream ih = new FileStream(System.Windows.Forms.Application.StartupPath + "\\IH1.txt", FileMode.Open);
                    readLine = new StreamReader(ih, Encoding.Default);
                    strLine = readLine.ReadLine();
                    while (strLine != null && strLine != "")
                    {
                        string[] array1 = strLine.Split(charSplit);
                        strCon2 = " AND Type= '05' AND Name = '" + array1[0] + "' AND FirstNode = " + array1[1] + " AND LastNode = " + array1[2];
                        strCon = strCon1 + strCon2;
                        PSPDEV devMX = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByCondition", strCon);
                        if (devMX != null)
                        {
                            PSP_ElcDevice elcDev = new PSP_ElcDevice();
                            elcDev.ProjectSUID = projectSUID;
                            elcDev.DeviceSUID = devMX.SUID;
                            elcDev = (PSP_ElcDevice)Services.BaseService.GetObject("SelectPSP_ElcDeviceByKey", elcDev);
                            if (elcDev != null)
                            {
                                elcDev.COL1 = devMX.Name;
                                elcDev.COL2 = devMX.FirstNode.ToString();
                                elcDev.COL3 = devMX.LastNode.ToString();
                                elcDev.COL19 = devMX.ReferenceVolt.ToString();
                                if (Convert.ToDouble(devMX.Burthen) == 0.0)
                                {
                                    elcDev.COL20 = ratedCapacity.ToString();
                                }
                                else
                                    elcDev.COL20 = devMX.Burthen.ToString();
                                double temp = 0.0;
                                double.TryParse(array1[3], out temp);
                                elcDev.COL14 = (temp * ratedCapacity / (Math.Sqrt(3) * devMX.ReferenceVolt)).ToString();
                                temp = 0.0;
                                double.TryParse(array1[4], out temp);
                                elcDev.COL15 = (temp * Rad_to_Deg).ToString();
                                PSP_ElcDevice elcTemp = (PSP_ElcDevice)Services.BaseService.GetObject("SelectPSP_ElcDeviceByKey", elcDev);

                                Services.BaseService.Update<PSP_ElcDevice>(elcDev);
                            }
                        }
                        strLine = readLine.ReadLine();
                    }
                    readLine.Close();
                }
                else if (type == 2)
                {
                    if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\PF2.txt"))
                    {
                        File.Delete(System.Windows.Forms.Application.StartupPath + "\\PF2.txt");
                    }
                    if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\DH2.txt"))
                    {
                        File.Delete(System.Windows.Forms.Application.StartupPath + "\\DH2.txt");
                    }
                    if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\IH2.txt"))
                    {
                        File.Delete(System.Windows.Forms.Application.StartupPath + "\\IH2.txt");
                    }
                    PQ_PowerFlowCalClass pq = new PQ_PowerFlowCalClass();
                    pq.CurrentCal();

                    if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\PF2.txt"))
                    {
                    }
                    else
                    {
                        return false;
                    }
                    FileStream pf = new FileStream(System.Windows.Forms.Application.StartupPath + "\\PF2.txt", FileMode.Open);
                    StreamReader readLine = new StreamReader(pf, Encoding.Default);
                    char[] charSplit = new char[] { ' ' };
                    string strLine = readLine.ReadLine();
                    while (strLine != null && strLine != "")
                    {
                        string[] array1 = strLine.Split(charSplit);
                        strCon2 = " AND Type= '01' AND Number = " + array1[0];
                        strCon = strCon1 + strCon2;
                        PSPDEV devMX = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByCondition", strCon);
                        if (devMX != null)
                        {
                            PSP_ElcDevice elcDev = new PSP_ElcDevice();
                            elcDev.ProjectSUID = projectSUID;
                            elcDev.DeviceSUID = devMX.SUID;
                            elcDev = (PSP_ElcDevice)Services.BaseService.GetObject("SelectPSP_ElcDeviceByKey", elcDev);
                            if (elcDev != null)
                            {
                                elcDev.COL21 = devMX.Name;
                                elcDev.COL39 = devMX.ReferenceVolt.ToString();
                                elcDev.COL40 = ratedCapacity.ToString();
                                double temp = 0.0;
                                double.TryParse(array1[1], out temp);
                                elcDev.COL22 = (temp * (devMX.ReferenceVolt)).ToString();
                                temp = 0.0;
                                double.TryParse(array1[2], out temp);
                                elcDev.COL23 = (temp * Rad_to_Deg).ToString();
                                temp = 0.0;
                                double.TryParse(array1[3], out temp);
                                elcDev.COL24 = (temp * ratedCapacity).ToString();
                                temp = 0.0;
                                double.TryParse(array1[4], out temp);
                                elcDev.COL25 = (temp * ratedCapacity).ToString();
                                PSP_ElcDevice elcTemp = (PSP_ElcDevice)Services.BaseService.GetObject("SelectPSP_ElcDeviceByKey", elcDev);

                                Services.BaseService.Update<PSP_ElcDevice>(elcDev);
                            }
                        }
                        strLine = readLine.ReadLine();
                    }
                    readLine.Close();
                    if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\DH2.txt"))
                    {
                    }
                    else
                    {
                        return false;
                    }
                    FileStream dh = new FileStream(System.Windows.Forms.Application.StartupPath + "\\DH2.txt", FileMode.Open);
                    readLine = new StreamReader(dh, Encoding.Default);
                    strLine = readLine.ReadLine();
                    while (strLine != null && strLine != "")
                    {
                        string[] array1 = strLine.Split(charSplit);
                        strCon2 = " AND Type= '05' AND Name = '" + array1[0] + "' AND FirstNode = " + array1[1] + " AND LastNode = " + array1[2];
                        strCon = strCon1 + strCon2;
                        PSPDEV devMX = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByCondition", strCon);
                        if (devMX != null)
                        {
                            PSP_ElcDevice elcDev = new PSP_ElcDevice();
                            elcDev.ProjectSUID = projectSUID;
                            elcDev.DeviceSUID = devMX.SUID;
                            elcDev = (PSP_ElcDevice)Services.BaseService.GetObject("SelectPSP_ElcDeviceByKey", elcDev);
                            if (elcDev != null)
                            {
                                elcDev.COL21 = devMX.Name;
                                elcDev.COL22 = devMX.FirstNode.ToString();
                                elcDev.COL23 = devMX.LastNode.ToString();
                                elcDev.COL39 = devMX.ReferenceVolt.ToString();
                                elcDev.COL40 = ratedCapacity.ToString();
                                double temp = 0.0;
                                double.TryParse(array1[3], out temp);
                                elcDev.COL24 = (temp * ratedCapacity).ToString();
                                temp = 0.0;
                                double.TryParse(array1[4], out temp);
                                elcDev.COL25 = (temp * ratedCapacity).ToString();
                                temp = 0.0;
                                double.TryParse(array1[5], out temp);
                                elcDev.COL26 = (temp * ratedCapacity).ToString();
                                temp = 0.0;
                                double.TryParse(array1[6], out temp);
                                elcDev.COL27 = (temp * ratedCapacity).ToString();

                                temp = 0.0;
                                double.TryParse(array1[7], out temp);
                                elcDev.COL28 = (temp * ratedCapacity).ToString();
                                temp = 0.0;
                                double.TryParse(array1[8], out temp);
                                elcDev.COL29 = (temp * ratedCapacity).ToString();
                                temp = 0.0;
                                double.TryParse(array1[9], out temp);
                                elcDev.COL30 = (temp * ratedCapacity / (Math.Sqrt(3) * devMX.ReferenceVolt)).ToString();

                                temp = 0.0;
                                double.TryParse(array1[10], out temp);
                                elcDev.COL31 = (temp * Rad_to_Deg).ToString();
                                temp = 0.0;
                                double.TryParse(array1[11], out temp);
                                elcDev.COL32 = (temp * (devMX.ReferenceVolt)).ToString();
                                temp = 0.0;
                                double.TryParse(array1[12], out temp);
                                elcDev.COL33 = (temp * (devMX.ReferenceVolt)).ToString();
                                PSP_ElcDevice elcTemp = (PSP_ElcDevice)Services.BaseService.GetObject("SelectPSP_ElcDeviceByKey", elcDev);

                                Services.BaseService.Update<PSP_ElcDevice>(elcDev);
                            }
                        }
                        strLine = readLine.ReadLine();
                    }
                    readLine.Close();
                    if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\IH2.txt"))
                    {
                    }
                    else
                    {
                        return false;
                    }
                    FileStream ih = new FileStream(System.Windows.Forms.Application.StartupPath + "\\IH2.txt", FileMode.Open);
                    readLine = new StreamReader(ih, Encoding.Default);
                    strLine = readLine.ReadLine();
                    while (strLine != null && strLine != "")
                    {
                        string[] array1 = strLine.Split(charSplit);
                        strCon2 = " AND Type= '05' AND Name = '" + array1[0] + "' AND FirstNode = " + array1[1] + " AND LastNode = " + array1[2];
                        strCon = strCon1 + strCon2;
                        PSPDEV devMX = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByCondition", strCon);
                        if (devMX != null)
                        {
                            PSP_ElcDevice elcDev = new PSP_ElcDevice();
                            elcDev.ProjectSUID = projectSUID;
                            elcDev.DeviceSUID = devMX.SUID;
                            elcDev = (PSP_ElcDevice)Services.BaseService.GetObject("SelectPSP_ElcDeviceByKey", elcDev);
                            if (elcDev != null)
                            {
                                elcDev.COL21 = devMX.Name;
                                elcDev.COL22 = devMX.FirstNode.ToString();
                                elcDev.COL23 = devMX.LastNode.ToString();
                                elcDev.COL39 = devMX.ReferenceVolt.ToString();
                                elcDev.COL40 = ratedCapacity.ToString();
                                double temp = 0.0;
                                double.TryParse(array1[3], out temp);
                                elcDev.COL34 = (temp * ratedCapacity / (Math.Sqrt(3) * devMX.ReferenceVolt)).ToString();
                                temp = 0.0;
                                double.TryParse(array1[4], out temp);
                                elcDev.COL35 = (temp * Rad_to_Deg).ToString();
                                PSP_ElcDevice elcTemp = (PSP_ElcDevice)Services.BaseService.GetObject("SelectPSP_ElcDeviceByKey", elcDev);

                                Services.BaseService.Update<PSP_ElcDevice>(elcDev);
                            }
                        }
                        strLine = readLine.ReadLine();
                    }
                    readLine.Close();
                }
                else if (type == 3)
                {
                    if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\PF3.txt"))
                    {
                        File.Delete(System.Windows.Forms.Application.StartupPath + "\\PF3.txt");
                    }
                    if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\DH3.txt"))
                    {
                        File.Delete(System.Windows.Forms.Application.StartupPath + "\\DH3.txt");
                    }
                    if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\IH3.txt"))
                    {
                        File.Delete(System.Windows.Forms.Application.StartupPath + "\\IH3.txt");
                    }
                    Gauss gs = new Gauss();
                    gs.CurrentCal();

                    if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\PF3.txt"))
                    {
                    }
                    else
                    {
                        return false;
                    }
                    FileStream pf = new FileStream(System.Windows.Forms.Application.StartupPath + "\\PF3.txt", FileMode.Open);
                    StreamReader readLine = new StreamReader(pf, Encoding.Default);
                    char[] charSplit = new char[] { ' ' };
                    string strLine = readLine.ReadLine();
                    while (strLine != null && strLine != "")
                    {
                        string[] array1 = strLine.Split(charSplit);
                        strCon2 = " AND Type= '01' AND Number = " + array1[0];
                        strCon = strCon1 + strCon2;
                        PSPDEV devMX = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByCondition", strCon);
                        if (devMX != null)
                        {
                            PSP_ElcDevice elcDev = new PSP_ElcDevice();
                            elcDev.ProjectSUID = projectSUID;
                            elcDev.DeviceSUID = devMX.SUID;
                            elcDev = (PSP_ElcDevice)Services.BaseService.GetObject("SelectPSP_ElcDeviceByKey", elcDev);
                            if (elcDev != null)
                            {
                                elcDev.COL41 = devMX.Name;
                                elcDev.COL59 = devMX.ReferenceVolt.ToString();
                                elcDev.COL60 = ratedCapacity.ToString();
                                double temp = 0.0;
                                double.TryParse(array1[1], out temp);
                                elcDev.COL42 = (temp * (devMX.ReferenceVolt)).ToString();
                                temp = 0.0;
                                double.TryParse(array1[2], out temp);
                                elcDev.COL43 = (temp * Rad_to_Deg).ToString();
                                temp = 0.0;
                                double.TryParse(array1[3], out temp);
                                elcDev.COL44 = (temp * ratedCapacity).ToString();
                                temp = 0.0;
                                double.TryParse(array1[4], out temp);
                                elcDev.COL45 = (temp * ratedCapacity).ToString();
                                PSP_ElcDevice elcTemp = (PSP_ElcDevice)Services.BaseService.GetObject("SelectPSP_ElcDeviceByKey", elcDev);

                                Services.BaseService.Update<PSP_ElcDevice>(elcDev);
                            }
                        }
                        strLine = readLine.ReadLine();
                    }
                    readLine.Close();
                    if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\DH3.txt"))
                    {
                    }
                    else
                    {
                        return false;
                    }
                    FileStream dh = new FileStream(System.Windows.Forms.Application.StartupPath + "\\DH3.txt", FileMode.Open);
                    readLine = new StreamReader(dh, Encoding.Default);
                    strLine = readLine.ReadLine();
                    while (strLine != null && strLine != "")
                    {
                        string[] array1 = strLine.Split(charSplit);
                        strCon2 = " AND Type= '05' AND Name = '" + array1[0] + "' AND FirstNode = " + array1[1] + " AND LastNode = " + array1[2];
                        strCon = strCon1 + strCon2;
                        PSPDEV devMX = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByCondition", strCon);
                        if (devMX != null)
                        {
                            PSP_ElcDevice elcDev = new PSP_ElcDevice();
                            elcDev.ProjectSUID = projectSUID;
                            elcDev.DeviceSUID = devMX.SUID;
                            elcDev = (PSP_ElcDevice)Services.BaseService.GetObject("SelectPSP_ElcDeviceByKey", elcDev);
                            if (elcDev != null)
                            {
                                elcDev.COL41 = devMX.Name;
                                elcDev.COL42 = devMX.FirstNode.ToString();
                                elcDev.COL43 = devMX.LastNode.ToString();
                                elcDev.COL59 = devMX.ReferenceVolt.ToString();
                                elcDev.COL60 = ratedCapacity.ToString();
                                double temp = 0.0;
                                double.TryParse(array1[3], out temp);
                                elcDev.COL44 = (temp * ratedCapacity).ToString();
                                temp = 0.0;
                                double.TryParse(array1[4], out temp);
                                elcDev.COL45 = (temp * ratedCapacity).ToString();
                                temp = 0.0;
                                double.TryParse(array1[5], out temp);
                                elcDev.COL46 = (temp * ratedCapacity).ToString();
                                temp = 0.0;
                                double.TryParse(array1[6], out temp);
                                elcDev.COL47 = (temp * ratedCapacity).ToString();

                                temp = 0.0;
                                double.TryParse(array1[7], out temp);
                                elcDev.COL48 = (temp * ratedCapacity).ToString();
                                temp = 0.0;
                                double.TryParse(array1[8], out temp);
                                elcDev.COL49 = (temp * ratedCapacity).ToString();
                                temp = 0.0;
                                double.TryParse(array1[9], out temp);
                                elcDev.COL50 = (temp * ratedCapacity / (Math.Sqrt(3) * devMX.ReferenceVolt)).ToString();

                                temp = 0.0;
                                double.TryParse(array1[10], out temp);
                                elcDev.COL51 = (temp * Rad_to_Deg).ToString();
                                temp = 0.0;
                                double.TryParse(array1[11], out temp);
                                elcDev.COL52 = (temp * (devMX.ReferenceVolt)).ToString();
                                temp = 0.0;
                                double.TryParse(array1[12], out temp);
                                elcDev.COL53 = (temp * (devMX.ReferenceVolt)).ToString();
                                PSP_ElcDevice elcTemp = (PSP_ElcDevice)Services.BaseService.GetObject("SelectPSP_ElcDeviceByKey", elcDev);

                                Services.BaseService.Update<PSP_ElcDevice>(elcDev);
                            }
                        }
                        strLine = readLine.ReadLine();
                    }
                    readLine.Close();
                    if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\IH3.txt"))
                    {
                    }
                    else
                    {
                        return false;
                    }
                    FileStream ih = new FileStream(System.Windows.Forms.Application.StartupPath + "\\IH3.txt", FileMode.Open);
                    readLine = new StreamReader(ih, Encoding.Default);
                    strLine = readLine.ReadLine();
                    while (strLine != null && strLine != "")
                    {
                        string[] array1 = strLine.Split(charSplit);
                        strCon2 = " AND Type= '05' AND Name = '" + array1[0] + "' AND FirstNode = " + array1[1] + " AND LastNode = " + array1[2];
                        strCon = strCon1 + strCon2;
                        PSPDEV devMX = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByCondition", strCon);
                        if (devMX != null)
                        {
                            PSP_ElcDevice elcDev = new PSP_ElcDevice();
                            elcDev.ProjectSUID = projectSUID;
                            elcDev.DeviceSUID = devMX.SUID;
                            elcDev = (PSP_ElcDevice)Services.BaseService.GetObject("SelectPSP_ElcDeviceByKey", elcDev);
                            if (elcDev != null)
                            {
                                elcDev.COL41 = devMX.Name;
                                elcDev.COL42 = devMX.FirstNode.ToString();
                                elcDev.COL43 = devMX.LastNode.ToString();
                                elcDev.COL59 = devMX.ReferenceVolt.ToString();
                                elcDev.COL60 = ratedCapacity.ToString();
                                double temp = 0.0;
                                double.TryParse(array1[3], out temp);
                                elcDev.COL54 = (temp * ratedCapacity / (Math.Sqrt(3) * devMX.ReferenceVolt)).ToString();
                                temp = 0.0;
                                double.TryParse(array1[4], out temp);
                                elcDev.COL55 = (temp * Rad_to_Deg).ToString();
                                PSP_ElcDevice elcTemp = (PSP_ElcDevice)Services.BaseService.GetObject("SelectPSP_ElcDeviceByKey", elcDev);

                                Services.BaseService.Update<PSP_ElcDevice>(elcDev);
                            }
                        }
                        strLine = readLine.ReadLine();
                    }
                    readLine.Close();
                }
                else if (type == 4)
                {
                    if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\PF4.txt"))
                    {
                        File.Delete(System.Windows.Forms.Application.StartupPath + "\\PF4.txt");
                    }
                    if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\DH4.txt"))
                    {
                        File.Delete(System.Windows.Forms.Application.StartupPath + "\\DH4.txt");
                    }
                    if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\IH4.txt"))
                    {
                        File.Delete(System.Windows.Forms.Application.StartupPath + "\\IH4.txt");
                    }
                    ZYZ zy = new ZYZ();
                    zy.CurrentCal();

                    if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\PF4.txt"))
                    {
                    }
                    else
                    {
                        return false;
                    }
                    FileStream pf = new FileStream(System.Windows.Forms.Application.StartupPath + "\\PF4.txt", FileMode.Open);
                    StreamReader readLine = new StreamReader(pf, Encoding.Default);
                    char[] charSplit = new char[] { ' ' };
                    string strLine = readLine.ReadLine();
                    while (strLine != null && strLine != "")
                    {
                        string[] array1 = strLine.Split(charSplit);
                        strCon2 = " AND Type= '01' AND Number = " + array1[0];
                        strCon = strCon1 + strCon2;
                        PSPDEV devMX = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByCondition", strCon);
                        if (devMX != null)
                        {
                            PSP_ElcDevice elcDev = new PSP_ElcDevice();
                            elcDev.ProjectSUID = projectSUID;
                            elcDev.DeviceSUID = devMX.SUID;
                            elcDev = (PSP_ElcDevice)Services.BaseService.GetObject("SelectPSP_ElcDeviceByKey", elcDev);
                            if (elcDev != null)
                            {
                                elcDev.COL61 = devMX.Name;
                                elcDev.COL79 = devMX.ReferenceVolt.ToString();
                                elcDev.COL80 = ratedCapacity.ToString();
                                double temp = 0.0;
                                double.TryParse(array1[1], out temp);
                                elcDev.COL62 = (temp * (devMX.ReferenceVolt)).ToString();
                                temp = 0.0;
                                double.TryParse(array1[2], out temp);
                                elcDev.COL63 = (temp * Rad_to_Deg).ToString();
                                temp = 0.0;
                                double.TryParse(array1[3], out temp);
                                elcDev.COL64 = (temp * ratedCapacity).ToString();
                                temp = 0.0;
                                double.TryParse(array1[4], out temp);
                                elcDev.COL65 = (temp * ratedCapacity).ToString();
                                PSP_ElcDevice elcTemp = (PSP_ElcDevice)Services.BaseService.GetObject("SelectPSP_ElcDeviceByKey", elcDev);

                                Services.BaseService.Update<PSP_ElcDevice>(elcDev);
                            }
                        }
                        strLine = readLine.ReadLine();
                    }
                    readLine.Close();
                    if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\DH4.txt"))
                    {
                    }
                    else
                    {
                        return false;
                    }
                    FileStream dh = new FileStream(System.Windows.Forms.Application.StartupPath + "\\DH4.txt", FileMode.Open);
                    readLine = new StreamReader(dh, Encoding.Default);
                    strLine = readLine.ReadLine();
                    while (strLine != null && strLine != "")
                    {
                        string[] array1 = strLine.Split(charSplit);
                        strCon2 = " AND Type= '05' AND Name = '" + array1[0] + "' AND FirstNode = " + array1[1] + " AND LastNode = " + array1[2];
                        strCon = strCon1 + strCon2;
                        PSPDEV devMX = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByCondition", strCon);
                        if (devMX != null)
                        {
                            PSP_ElcDevice elcDev = new PSP_ElcDevice();
                            elcDev.ProjectSUID = projectSUID;
                            elcDev.DeviceSUID = devMX.SUID;
                            elcDev = (PSP_ElcDevice)Services.BaseService.GetObject("SelectPSP_ElcDeviceByKey", elcDev);
                            if (elcDev != null)
                            {
                                elcDev.COL61 = devMX.Name;
                                elcDev.COL62 = devMX.FirstNode.ToString();
                                elcDev.COL63 = devMX.LastNode.ToString();
                                elcDev.COL79 = devMX.ReferenceVolt.ToString();
                                elcDev.COL80 = ratedCapacity.ToString();
                                double temp = 0.0;
                                double.TryParse(array1[3], out temp);
                                elcDev.COL64 = (temp * ratedCapacity).ToString();
                                temp = 0.0;
                                double.TryParse(array1[4], out temp);
                                elcDev.COL65 = (temp * ratedCapacity).ToString();
                                temp = 0.0;
                                double.TryParse(array1[5], out temp);
                                elcDev.COL66 = (temp * ratedCapacity).ToString();
                                temp = 0.0;
                                double.TryParse(array1[6], out temp);
                                elcDev.COL67 = (temp * ratedCapacity).ToString();

                                temp = 0.0;
                                double.TryParse(array1[7], out temp);
                                elcDev.COL68 = (temp * ratedCapacity).ToString();
                                temp = 0.0;
                                double.TryParse(array1[8], out temp);
                                elcDev.COL69 = (temp * ratedCapacity).ToString();
                                temp = 0.0;
                                double.TryParse(array1[9], out temp);
                                elcDev.COL70 = (temp * ratedCapacity / (Math.Sqrt(3) * devMX.ReferenceVolt)).ToString();

                                temp = 0.0;
                                double.TryParse(array1[10], out temp);
                                elcDev.COL71 = (temp * Rad_to_Deg).ToString();
                                temp = 0.0;
                                double.TryParse(array1[11], out temp);
                                elcDev.COL72 = (temp * (devMX.ReferenceVolt)).ToString();
                                temp = 0.0;
                                double.TryParse(array1[12], out temp);
                                elcDev.COL73 = (temp * (devMX.ReferenceVolt)).ToString();
                                PSP_ElcDevice elcTemp = (PSP_ElcDevice)Services.BaseService.GetObject("SelectPSP_ElcDeviceByKey", elcDev);

                                Services.BaseService.Update<PSP_ElcDevice>(elcDev);
                            }
                        }
                        strLine = readLine.ReadLine();
                    }
                    readLine.Close();
                    if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\IH4.txt"))
                    {
                    }
                    else
                    {
                        return false;
                    }
                    FileStream ih = new FileStream(System.Windows.Forms.Application.StartupPath + "\\IH4.txt", FileMode.Open);
                    readLine = new StreamReader(ih, Encoding.Default);
                    strLine = readLine.ReadLine();
                    while (strLine != null && strLine != "")
                    {
                        string[] array1 = strLine.Split(charSplit);
                        strCon2 = " AND Type= '05' AND Name = '" + array1[0] + "' AND FirstNode = " + array1[1] + " AND LastNode = " + array1[2];
                        strCon = strCon1 + strCon2;
                        PSPDEV devMX = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByCondition", strCon);
                        if (devMX != null)
                        {
                            PSP_ElcDevice elcDev = new PSP_ElcDevice();
                            elcDev.ProjectSUID = projectSUID;
                            elcDev.DeviceSUID = devMX.SUID;
                            elcDev = (PSP_ElcDevice)Services.BaseService.GetObject("SelectPSP_ElcDeviceByKey", elcDev);
                            if (elcDev != null)
                            {
                                elcDev.COL61 = devMX.Name;
                                elcDev.COL62 = devMX.FirstNode.ToString();
                                elcDev.COL63 = devMX.LastNode.ToString();
                                elcDev.COL79 = devMX.ReferenceVolt.ToString();
                                elcDev.COL80 = ratedCapacity.ToString();
                                double temp = 0.0;
                                double.TryParse(array1[3], out temp);
                                elcDev.COL74 = (temp * ratedCapacity / (Math.Sqrt(3) * devMX.ReferenceVolt)).ToString();
                                temp = 0.0;
                                double.TryParse(array1[4], out temp);
                                elcDev.COL75 = (temp * Rad_to_Deg).ToString();
                                PSP_ElcDevice elcTemp = (PSP_ElcDevice)Services.BaseService.GetObject("SelectPSP_ElcDeviceByKey", elcDev);

                                Services.BaseService.Update<PSP_ElcDevice>(elcDev);
                            }
                        }
                        strLine = readLine.ReadLine();
                    }
                    readLine.Close();
                }

            }
            catch (System.Exception ex)
            {
                MessageBox.Show("潮流计算结果不收敛,请检查输入参数!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }
            return true;
        }
Beispiel #29
0
        public void ExecuteCalculate()
        {
            Text = "";
            ResX = "";
            double[][] a;
            double[]   b;
            ToArrays(out a, out b);

            int n = Matrix.Count;

            double[][] a0 = new double[n][];
            double[]   b0 = new double[n];
            for (int i = 0; i < n; i++)
            {
                a0[i] = new double[n];
                for (int j = 0; j < n; j++)
                {
                    a0[i][j] = a[i][j];
                }
                b0[i] = b[i];
            }


            for (int i = 0; i < n; i++)
            {
                if (a[i][i] == 0)
                {
                    Text = "Эл-ты на главной диагонали не должны быть нулевыми";
                    MessageBox.Show(n + "");
                    return;
                }
            }

            if (IsIt)
            {
                SimpleIterations si = new SimpleIterations(n);

                si.A = a0;
                si.B = b0;

                double eps = TextEps.HasValue ? TextEps.Value : 0.001;

                double[] res = si.Calculate(eps);

                if (res == null)
                {
                    Text = si.Log[0];
                    return;
                }

                for (int i = 0; i < si.Log.Count; i++)
                {
                    Text += si.Log[i];
                }

                ResX += "Решение найдено за " + (si.Log.Count - 1) + " итераций\n\n";
                for (int i = 0; i < n; i++)
                {
                    ResX += "x" + (i + 1) + " = " + Math.Round(res[i], (eps % 1).ToString().Length - 2) + '\n';
                }
                ResX += "\n******ПРОВЕРКА******\n";
                double[] check = new double[n];
                double   temp  = 0;
                int      tr;
                for (int i = 0; i < n; i++)
                {
                    temp = 0;
                    for (int j = 0; j < n; j++)
                    {
                        temp += a[i][j] * res[j];
                    }
                    tr = (b[i] % 1).ToString().Length - 2;
                    if (tr < 0 || tr > 15)
                    {
                        tr = 2;
                    }
                    check[i] = Math.Round(temp, tr);
                    b[i]     = Math.Round(b[i], tr);
                }
                bool ans = true;
                for (int i = 0; i < n; i++)
                {
                    ResX += check[i];
                    if (check[i] == b[i])
                    {
                        ResX += " = ";
                    }
                    else
                    {
                        ResX += " != ";
                        ans   = false;
                    }
                    ResX += b[i] + "\n";
                }
                if (ans)
                {
                    ResX += "\nПроверка пройдена.";
                }
                else
                {
                    ResX += "\nПроверка не пройдена.";
                }
            }
            else
            {
                n    = 3;
                ga   = new Gauss(n);
                ga.A = a0;
                ga.B = b0;

                double eps = TextEps.HasValue ? TextEps.Value : 0.001;

                double[] res = ga.Calculate();

                for (int i = 0; i < n; i++)
                {
                    ResX += "x" + (i + 1) + " = " + Math.Round(res[i], (eps % 1).ToString().Length - 2) + '\n';
                }
                CurStep = 2;
                ResX   += "\n******ПРОВЕРКА******\n";
                double[] check = new double[n];
                double   temp  = 0;
                int      tr;
                for (int i = 0; i < n; i++)
                {
                    temp = 0;
                    for (int j = 0; j < n; j++)
                    {
                        temp += a[i][j] * res[j];
                    }
                    tr = (b[i] % 1).ToString().Length - 2;
                    if (tr < 0 || tr > 15)
                    {
                        tr = 2;
                    }
                    check[i] = Math.Round(temp, tr);
                    b[i]     = Math.Round(b[i], tr);
                }
                bool ans = true;
                for (int i = 0; i < n; i++)
                {
                    ResX += check[i];
                    if (check[i] == b[i])
                    {
                        ResX += " = ";
                    }
                    else
                    {
                        ResX += " != ";
                        ans   = false;
                    }
                    ResX += b[i] + "\n";
                }
                if (ans)
                {
                    ResX += "\nПроверка пройдена.";
                }
                else
                {
                    ResX += "\nПроверка не пройдена.";
                }
            }
        }
Beispiel #30
0
 public long?Gauss_Range_ErrorTests(long n) => Gauss.RangeSum(n);
Beispiel #31
0
 public long?Gauss_Range_ValidTests(long n) => Gauss.RangeSum(n);
        protected void rescale(Floatarray v, Floatarray input)
        {
            if (input.Rank() != 2)
            {
                throw new Exception("CHECK_ARG: sub.Rank()==2");
            }

            Floatarray sub = new Floatarray();
            // find the largest connected component
            // and crop to its bounding box
            // (use a binary version of the character
            // to compute the bounding box)
            Intarray components = new Intarray();
            float    threshold  = PGetf("threshold") * NarrayUtil.Max(input);

            Global.Debugf("biggestcc", "threshold {0}", threshold);
            components.MakeLike(input);
            components.Fill(0);
            for (int i = 0; i < components.Length(); i++)
            {
                components[i] = (input[i] > threshold ? 1 : 0);
            }
            int      n      = ImgLabels.label_components(ref components);
            Intarray totals = new Intarray(n + 1);

            totals.Fill(0);
            for (int i = 0; i < components.Length(); i++)
            {
                totals[components[i]]++;
            }
            totals[0] = 0;
            Narray <Rect> boxes = new Narray <Rect>();

            ImgLabels.bounding_boxes(ref boxes, components);
            int  biggest = NarrayUtil.ArgMax(totals);
            Rect r       = boxes[biggest];
            int  pad     = (int)(PGetf("pad") + 0.5f);

            r.PadBy(pad, pad);
            Global.Debugf("biggestcc", "({0}) {1}[{2}] :: {3} {4} {5} {6}",
                          n, biggest, totals[biggest],
                          r.x0, r.y0, r.x1, r.y1);

            // now perform normal feature extraction
            // (use the original grayscale input)
            sub = input;
            ImgMisc.Crop(sub, r);
            int   csize = PGeti("csize");
            float s     = Math.Max(sub.Dim(0), sub.Dim(1)) / (float)csize;

            if (PGetf("noupscale") > 0 && s < 1.0f)
            {
                s = 1.0f;
            }
            float sig = s * PGetf("aa");
            float dx  = (csize * s - sub.Dim(0)) / 2f;
            float dy  = (csize * s - sub.Dim(1)) / 2f;

            if (sig > 1e-3f)
            {
                Gauss.Gauss2d(sub, sig, sig);
            }
            v.Resize(csize, csize);
            v.Fill(0f);
            for (int i = 0; i < csize; i++)
            {
                for (int j = 0; j < csize; j++)
                {
                    float x = i * s - dx;
                    float y = j * s - dy;
                    if (x < 0 || x >= sub.Dim(0))
                    {
                        continue;
                    }
                    if (y < 0 || y >= sub.Dim(1))
                    {
                        continue;
                    }
                    float value = ImgOps.bilin(sub, x, y);
                    v[i, j] = value;
                }
            }

            /*Global.Debugf("biggestcc", "{0} {1} ({2}) -> {3} {4} ({5})",
             *     sub.Dim(0), sub.Dim(1), NarrayUtil.Max(sub),
             *     v.Dim(0), v.Dim(1), NarrayUtil.Max(v));*/
        }
Beispiel #33
0
        private void PspGaussSeidel()
        {
            if (!Check())
            {
                return;
            }
            try
            {
                XmlNodeList list = tlVectorControl1.SVGDocument.SelectNodes("svg/*[@flag='" + "1" + "']");

                foreach (XmlNode node in list)
                {
                    SvgElement element = node as SvgElement;
                    tlVectorControl1.SVGDocument.CurrentElement = element;
                    tlVectorControl1.Delete();
                }

                if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\PF3.txt"))
                {
                    File.Delete(System.Windows.Forms.Application.StartupPath + "\\PF3.txt");
                }
                if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\DH3.txt"))
                {
                    File.Delete(System.Windows.Forms.Application.StartupPath + "\\DH3.txt");
                }
                if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\IH3.txt"))
                {
                    File.Delete(System.Windows.Forms.Application.StartupPath + "\\IH3.txt");
                }

                Gauss gass = new Gauss();
                gass.CurrentCal();

                double yinzi = 0, capability = 0, volt = 0, current = 0;
                PSPDEV benchmark = new PSPDEV();
                benchmark.Type = "power";
                benchmark.SvgUID = tlVectorControl1.SVGDocument.SvgdataUid;
                IList list3 = Services.BaseService.GetList("SelectPSPDEVBySvgUIDAndType", benchmark);
                if (list3 == null)
                {
                    MessageBox.Show("请设置基准后再进行计算!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                foreach (PSPDEV dev in list3)
                {
                    yinzi = Convert.ToDouble(dev.PowerFactor);
                    capability = Convert.ToDouble(dev.StandardCurrent);
                    volt = Convert.ToDouble(dev.StandardVolt);
                    if (dev.PowerFactor == 0)
                    {
                        yinzi = 1;
                    }
                    if (dev.StandardCurrent == 0)
                    {
                        capability = 1;
                    }
                    if (dev.StandardVolt == 0)
                    {
                        volt = 1;
                    }
                    current = capability / (Math.Sqrt(3) * volt);
                };
                if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\PF3.txt") && File.Exists(System.Windows.Forms.Application.StartupPath + "\\DH3.txt") && File.Exists(System.Windows.Forms.Application.StartupPath + "\\IH3.txt"))
                {
                }
                else
                {
                    MessageBox.Show("数据不收敛,请调整参数后重新计算!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                FileStream dh = new FileStream(System.Windows.Forms.Application.StartupPath + "\\PF3.txt", FileMode.Open);
                StreamReader readLine = new StreamReader(dh);
                string strLine;
                string[] array1;
                char[] charSplit = new char[] { ' ' };
                strLine = readLine.ReadLine();
                string octor = "节点电压 ";

                while (strLine != null)
                {
                    array1 = strLine.Split(charSplit);
                    string[] dev = new string[8];
                    dev.Initialize();
                    int i = 0;
                    foreach (string str in array1)
                    {
                        if (str != "")
                        {
                            dev[i++] = str;
                        }
                        if (str.Contains("NAN"))
                        {
                            MessageBox.Show("参数错误,请调整参数后重新计算!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return;
                        }
                    }
                    PSPDEV pspDev = new PSPDEV();
                    pspDev.Number = Convert.ToInt32(Convert.ToDouble(dev[0]));
                    pspDev.SvgUID = tlVectorControl1.SVGDocument.CurrentLayer.ID;
                    pspDev.Type = "Use";
                    pspDev = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByNumberAndSvgUIDAndType", pspDev);
                    if (pspDev != null)
                    {
                        if (pspDev.Burthen == 0) goto Label_end;//如果容量为0当作T接点跳过
                        XmlElement element = tlVectorControl1.SVGDocument.SelectSingleNode("svg/*[@id='" + pspDev.EleID + "']") as XmlElement;
                        if (element != null)
                        {
                            RectangleF bound = ((IGraph)element).GetBounds();
                            XmlElement n1 = tlVectorControl1.SVGDocument.CreateElement("text") as Text;
                            XmlElement n2 = tlVectorControl1.SVGDocument.CreateElement("text") as Text;
                            n1.SetAttribute("x", Convert.ToString(bound.X));
                            n1.SetAttribute("y", Convert.ToString(bound.Y - 20));

                            n1.InnerText = (Convert.ToDouble(dev[1]) * volt).ToString("N2");
                            octor += " ";
                            octor += Convert.ToString(n1.InnerText);
                            n1.SetAttribute("layer", SvgDocument.currentLayer);
                            //MessageBox.Show(Convert.ToString(n1.InnerText));
                            n1.SetAttribute("flag", "1");

                            if (Convert.ToDouble(dev[1]) > 1.05 || Convert.ToDouble(dev[1]) < 0.95)//电压越限,需修改
                                n1.SetAttribute("stroke", "#FF0000");
                            if (pspDev.NodeType == "0")
                            {
                                if (Convert.ToDouble(dev[4]) >= 0)
                                {
                                    double tempb = Convert.ToDouble(pspDev.Burthen);
                                    n2.SetAttribute("x", Convert.ToString(bound.X));
                                    n2.SetAttribute("y", Convert.ToString(bound.Y + bound.Height + 20));
                                    n2.InnerText = ((Convert.ToDouble(dev[3]) * capability).ToString("N2") + "  + " + "j" + (Convert.ToDouble(dev[4]) * capability).ToString("N2"));
                                    n2.SetAttribute("layer", SvgDocument.currentLayer);
                                    n2.SetAttribute("flag", "1");
                                    double tempi = Convert.ToDouble(dev[3]) * capability;
                                    double tempj = Convert.ToDouble(dev[4]) * capability;
                                    double temptotal = Math.Sqrt(tempi * tempi + tempj * tempj);
                                    if (temptotal > Convert.ToDouble(pspDev.Burthen))
                                    {
                                        n2.SetAttribute("stroke", "#FF0000");
                                    }
                                }
                                else
                                {
                                    double tempb = Convert.ToDouble(pspDev.Burthen);
                                    n2.SetAttribute("x", Convert.ToString(bound.X));
                                    n2.SetAttribute("y", Convert.ToString(bound.Y + bound.Height + 15));
                                    n2.InnerText = (Convert.ToDouble(dev[3]) * capability).ToString("N2") + " - " + "j" + (Math.Abs(Convert.ToDouble(dev[4]) * capability)).ToString("N2");
                                    n2.SetAttribute("layer", SvgDocument.currentLayer);
                                    n2.SetAttribute("flag", "1");
                                    double tempi = Convert.ToDouble(dev[3]) * capability;
                                    double tempj = Convert.ToDouble(dev[4]) * capability;
                                    double temptotal = Math.Sqrt(tempi * tempi + tempj * tempj);
                                    if (temptotal > Convert.ToDouble(pspDev.Burthen))
                                    {
                                        n2.SetAttribute("stroke", "#FF0000");
                                    }
                                }
                                tlVectorControl1.SVGDocument.RootElement.AppendChild(n2);
                            }
                            tlVectorControl1.SVGDocument.RootElement.AppendChild(n1);
                            tlVectorControl1.Operation = ToolOperation.Select;
                            tlVectorControl1.Refresh();
                        }
                    }
                Label_end:
                    strLine = readLine.ReadLine();
                }
                readLine.Close();

                //MessageBox.Show(octor);
                octor = "线路电流 ";

                FileStream ih = new FileStream(System.Windows.Forms.Application.StartupPath + "\\IH3.txt", FileMode.Open);
                StreamReader ihLine = new StreamReader(ih);
                FileStream dhdh = new FileStream(System.Windows.Forms.Application.StartupPath + "\\DH3.txt", FileMode.Open);
                StreamReader dhLine = new StreamReader(dhdh);
                string strIH;
                string strDH;
                string[] array2;
                string[] array3;
                strIH = ihLine.ReadLine();
                strDH = dhLine.ReadLine();
                while (strIH != null && strDH != null)
                {

                    array2 = strIH.Split(charSplit);
                    array3 = strDH.Split(charSplit);
                    string[] dev = new string[8];
                    string[] devDH = new string[13];
                    dev.Initialize();
                    devDH.Initialize();
                    int i = 0;
                    foreach (string str in array2)
                    {
                        if (str != "")
                        {
                            dev[i++] = str;
                        }
                        if (str.Contains("NAN"))
                        {
                            MessageBox.Show("参数错误,请调整参数后重新计算!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return;
                        }
                    }
                    int j = 0;
                    foreach (string str in array3)
                    {
                        if (str != "")
                        {
                            devDH[j++] = str;
                        }
                    }
                    PSPDEV pspDev = new PSPDEV();
                    pspDev.Name = dev[0];
                    pspDev.SvgUID = tlVectorControl1.SVGDocument.CurrentLayer.ID;
                    pspDev.Type = "Polyline";
                    pspDev = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByName", pspDev);
                    if (pspDev != null && pspDev.LineStatus == "运行")
                    {
                        XmlElement element = tlVectorControl1.SVGDocument.SelectSingleNode("svg/*[@id='" + pspDev.EleID + "']") as XmlElement;
                        if (element != null)
                        {
                            PointF[] t = ((Polyline)element).Points;

                            PointF[] t2 = ((Polyline)element).FirstTwoPoint;
                            t = t2;

                            PointF midt = new PointF((float)((t2[0].X + t2[1].X) / 2), (float)((t2[0].Y + t2[1].Y) / 2));
                            float angel = 0f;
                            angel = (float)(180 * Math.Atan2((t2[1].Y - t2[0].Y), (t2[1].X - t2[0].X)) / Math.PI);

                            string l3 = Convert.ToString(midt.X);
                            string l4 = Convert.ToString(midt.Y);

                            string tran = ((Polyline)element).Transform.ToString();

                            PointF center = new PointF((float)(t[0].X + (t[1].X - t[0].X) / 2), (float)(t[0].Y + (t[1].Y - t[0].Y) / 2));
                            XmlElement n1 = tlVectorControl1.SVGDocument.CreateElement("text") as Text;
                            XmlElement n2 = tlVectorControl1.SVGDocument.CreateElement("polyline") as Polyline;
                            XmlElement n3 = tlVectorControl1.SVGDocument.CreateElement("text") as Text;

                            PointF pStart = new PointF(center.X + (float)(15 * Math.Sin((angel) * Math.PI / 180)), center.Y - (float)(15 * Math.Cos((angel) * Math.PI / 180)));
                            PointF pStart2 = new PointF(center.X - (float)(23 * Math.Sin((angel) * Math.PI / 180)), center.Y + (float)(23 * Math.Cos((angel) * Math.PI / 180)));
                            PSPDEV psp = new PSPDEV();
                            psp.FirstNode = pspDev.FirstNode;
                            psp.LastNode = pspDev.LastNode;
                            psp.SvgUID = pspDev.SvgUID;
                            PSPDEV tempss = new PSPDEV();
                            IList listParallel = Services.BaseService.GetList("SelectPSPDEVBySvgUIDandFirstOrLastNode", psp);
                            foreach (PSPDEV devP in listParallel)
                            {
                                if ((angel > 10 && angel < 90) || (angel < 0 && Math.Abs(angel) < 90) || (angel > 180 && angel < 350))
                                {
                                    if (((devP.X1) > (pspDev.X1)))
                                    {
                                        pStart = new PointF(center.X - (float)(23 * Math.Sin((angel) * Math.PI / 180)), center.Y + (float)(23 * Math.Cos((angel) * Math.PI / 180)));
                                        pStart2 = new PointF(center.X + (float)(23 * Math.Sin((angel) * Math.PI / 180)), center.Y - (float)(23 * Math.Cos((angel) * Math.PI / 180)));
                                    }
                                }
                                else if ((angel >= 0 && angel <= 10) || (angel >= 350 && angel <= 360) || (angel < 0 && Math.Abs(angel) <= 90))
                                {
                                    if (((devP.Y1) > (pspDev.Y1)))
                                    {
                                        pStart = new PointF(center.X - (float)(23 * Math.Sin((angel) * Math.PI / 180)), center.Y + (float)(23 * Math.Cos((angel) * Math.PI / 180)));
                                        pStart2 = new PointF(center.X + (float)(23 * Math.Sin((angel) * Math.PI / 180)), center.Y - (float)(23 * Math.Cos((angel) * Math.PI / 180)));
                                    }
                                }
                                else if ((angel < 0 && Math.Abs(angel) > 90) || (angel >= 90 && angel <= 180))
                                {
                                    if (((devP.Y1) > (pspDev.Y1)))
                                    {
                                        pStart = new PointF(center.X - (float)(7 * Math.Sin((angel) * Math.PI / 180)), center.Y + (float)(7 * Math.Cos((angel) * Math.PI / 180)));
                                        pStart2 = new PointF(center.X + (float)(7 * Math.Sin((angel) * Math.PI / 180)), center.Y - (float)(7 * Math.Cos((angel) * Math.PI / 180)));
                                    }
                                }

                                //if ((Math.Abs(angel) > 90))
                                //{

                                //    if (((devP.X1 + devP.Y1) > (pspDev.X1 + pspDev.Y1)))
                                //    {
                                //        pStart = new PointF(center.X - (float)(15 * Math.Sin((angel) * Math.PI / 180)), center.Y + (float)(15 * Math.Cos((angel) * Math.PI / 180)));
                                //    }
                                //    else
                                //    {
                                //        pStart = new PointF(center.X + (float)(15 * Math.Sin((angel) * Math.PI / 180)), center.Y - (float)(15 * Math.Cos((angel) * Math.PI / 180)));

                                //    }
                                //}
                            }

                            PointF newp1 = new PointF(t[0].X + (t[1].X - t[0].X) / 2 - (float)(15 * Math.Sin(angel)), t[0].Y + (t[1].Y - t[0].Y) / 2 - (float)(15 * Math.Cos(angel)));

                            n1.SetAttribute("x", Convert.ToString(pStart.X));
                            n1.SetAttribute("y", Convert.ToString(pStart.Y));
                            //n3.SetAttribute("x", Convert.ToString(pStart2.X));
                            //double temp = (Convert.ToDouble(devDH[6]) + Convert.ToDouble(devDH[10]) * volt * volt / 1000000) * capability;
                            //if (temp >= 0)
                            //{
                            //    n3.InnerText = ((Convert.ToDouble(devDH[5]) + Convert.ToDouble(devDH[9]) * volt * volt / 1000000) * capability).ToString() + " + " + "j" + temp.ToString();
                            //}
                            //else
                            //{
                            //    n3.InnerText = ((Convert.ToDouble(devDH[5]) + Convert.ToDouble(devDH[9]) * volt * volt / 1000000) * capability).ToString() + " - " + "j" + (Math.Abs(temp)).ToString();
                            //}

                            //n3.SetAttribute("layer", SvgDocument.currentLayer);
                            //n3.SetAttribute("flag", "1");
                            //n3.SetAttribute("stroke", "#0000FF");
                            //n1.SetAttribute("x", Convert.ToString(t[0].X + (t[1].X - t[0].X) / 2));
                            //n1.SetAttribute("y", Convert.ToString(t[0].Y + (t[1].Y - t[0].Y) / 2));
                            if (Convert.ToDouble(devDH[4]) >= 0)
                            {
                                n1.InnerText = (Math.Abs(Convert.ToDouble(devDH[3]) * capability)).ToString("N2") + " + j" + (Math.Abs(Convert.ToDouble(devDH[4]) * capability)).ToString("N2");
                            }
                            else
                            {
                                n1.InnerText = (Math.Abs(Convert.ToDouble(devDH[3]) * capability)).ToString("N2") + " - j" + (Math.Abs(Convert.ToDouble(devDH[4]) * capability)).ToString("N2");
                            }
                            n1.SetAttribute("layer", SvgDocument.currentLayer);
                            n1.SetAttribute("flag", "1");
                            if (listParallel != null)
                            {
                                if (Convert.ToDouble(dev[3]) > ((PSPDEV)listParallel[0]).LineChange)//电流越限,需修改。

                                    n1.SetAttribute("stroke", "#FF0000");
                            }

                            PointF p1 = new PointF(midt.X - (float)(10 * Math.Cos((angel + 25) * Math.PI / 180)), midt.Y - (float)(10 * Math.Sin((angel + 25) * Math.PI / 180)));
                            PointF p2 = new PointF(midt.X - (float)(10 * Math.Cos((angel + 335) * Math.PI / 180)), midt.Y - (float)(10 * Math.Sin((angel + 335) * Math.PI / 180)));

                            if (Convert.ToDouble(devDH[3]) < 0)
                            {
                                p1 = new PointF(midt.X - (float)(10 * Math.Cos((angel + 155) * Math.PI / 180)), midt.Y - (float)(10 * Math.Sin((angel + 155) * Math.PI / 180)));
                                p2 = new PointF(midt.X - (float)(10 * Math.Cos((angel + 205) * Math.PI / 180)), midt.Y - (float)(10 * Math.Sin((angel + 205) * Math.PI / 180)));
                            }

                            string l1 = Convert.ToString(p1.X);
                            string l2 = Convert.ToString(p1.Y);
                            string l5 = Convert.ToString(p2.X);
                            string l6 = Convert.ToString(p2.Y);

                            //n2.SetAttribute("stroke", "#FF0000");
                            n2.SetAttribute("points", l1 + " " + l2 + "," + l3 + " " + l4 + "," + l5 + " " + l6);
                            n2.SetAttribute("fill-opacity", "1");
                            n2.SetAttribute("layer", SvgDocument.currentLayer);
                            n2.SetAttribute("flag", "1");
                            tlVectorControl1.SVGDocument.RootElement.AppendChild(n2);
                            tlVectorControl1.SVGDocument.CurrentElement = n2 as SvgElement;

                            tlVectorControl1.SVGDocument.RootElement.AppendChild(n1);
                            tlVectorControl1.Operation = ToolOperation.Select;

                            tlVectorControl1.SVGDocument.CurrentElement = n1 as SvgElement;

                            //if (Convert.ToDouble(dev[3]) <= 0)
                            RectangleF ttt = ((Polyline)element).GetBounds();

                            tlVectorControl1.RotateSelection(angel, pStart);
                            if (Math.Abs(angel) > 90)
                                tlVectorControl1.RotateSelection(180, pStart);
                            //tlVectorControl1.RotateSelection((float)(Math.Atan((t[1].Y - t[0].Y) / (t[1].X - t[0].X)) * 180 / Math.PI), pt4[0]);
                            //tlVectorControl1.RotateSelection(-10, (new PointF(center.X+10,center.Y+10)));
                            //tlVectorControl1.SVGDocument.RootElement.AppendChild(n3);
                            //tlVectorControl1.Operation = ToolOperation.Select;
                            //tlVectorControl1.SVGDocument.CurrentElement = n3 as SvgElement;
                            //tlVectorControl1.RotateSelection(360 + angel, pStart2);
                            //if (Math.Abs(angel) > 90)
                            //    tlVectorControl1.RotateSelection(-180, pStart2);

                            PointF newp = new PointF(center.X + 10, center.Y + 10);

                            tlVectorControl1.Refresh();

                        }

                    }
                    strIH = ihLine.ReadLine();
                    strDH = dhLine.ReadLine();
                }

                ihLine.Close();
                dhLine.Close();
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("参数错误,请调整参数后重新计算!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
        }
Beispiel #34
0
        static void Main(string[] args)
        {
            List<double> DatosW = new List<double>();
            List<double> DatosX = new List<double>();
            List<double> DatosY = new List<double>();
            List<double> DatosZ = new List<double>();

            DatosW.Add(345); DatosW.Add(168); DatosW.Add(94); DatosW.Add(187); DatosW.Add(621); DatosW.Add(255);
            DatosX.Add(65); DatosX.Add(18); DatosX.Add(0); DatosX.Add(185); DatosX.Add(87); DatosX.Add(0);
            DatosY.Add(23); DatosY.Add(18); DatosY.Add(0); DatosY.Add(98); DatosY.Add(10); DatosY.Add(0);
            DatosZ.Add(31.4); DatosZ.Add(14.6); DatosZ.Add(6.4); DatosZ.Add(28.3); DatosZ.Add(42.1); DatosZ.Add(15.3);

            Gauss G = new Gauss();
            Funciones F = new Funciones();
            double[,] a = F.llenarMatriz(DatosW, DatosX, DatosY, DatosZ);
            double[] r = new double[a.GetLength(0)];
            double[] resultados = new double[a.GetLength(0)];
            G.ShowMatrix(a, "Ejemplo 1");
            if (G.ResolverGauss(a, r))
                resultados = G.ShowSolution(r);
            else
                Console.WriteLine("No es un sistema de ecuaciones lineales");
            double B0 = resultados[0];
            double B1 = resultados[1];
            double B2 = resultados[2];
            double B3 = resultados[3];
            double Wk = 185; double Xk = 150; double Yk = 45;
            double z = F.obtenerZ(Wk, Xk, Yk, B0, B1, B2, B3);
            Console.WriteLine("La z = " + z);
            double rango = F.calcularRango(Wk, Xk, Yk, DatosW.Count - 4 , DatosW, DatosX, DatosY, DatosZ, B0, B1, B2, B3);
            Console.WriteLine("UPI = " + (z + rango));
            Console.WriteLine("LPI = " + (z - rango));

            Console.ReadLine();
            ////////////////////////////////////////////////////
            List<double> DatosW2 = new List<double>();
            List<double> DatosX2 = new List<double>();
            List<double> DatosY2 = new List<double>();
            List<double> DatosZ2 = new List<double>();

            DatosW2.Add(1142); DatosW2.Add(863); DatosW2.Add(1065); DatosW2.Add(554); DatosW2.Add(983); DatosW2.Add(256);
            DatosX2.Add(1060); DatosX2.Add(995); DatosX2.Add(3205); DatosX2.Add(120); DatosX2.Add(2896); DatosX2.Add(485);
            DatosY2.Add(325); DatosY2.Add(98); DatosY2.Add(23); DatosY2.Add(0); DatosY2.Add(120); DatosY2.Add(88);
            DatosZ2.Add(201); DatosZ2.Add(98); DatosZ2.Add(162); DatosZ2.Add(54); DatosZ2.Add(138); DatosZ2.Add(61);

            double[,] a2 = F.llenarMatriz(DatosW2, DatosX2, DatosY2, DatosZ2);
            double[] r2 = new double[a2.GetLength(0)];
            double[] resultados2 = new double[a2.GetLength(0)];
            G.ShowMatrix(a, "Ejemplo 1");
            if (G.ResolverGauss(a2, r2))
                resultados2 = G.ShowSolution(r2);
            else
                Console.WriteLine("No es un sistema de ecuaciones lineales");
            double B02 = resultados2[0];
            double B12 = resultados2[1];
            double B22 = resultados2[2];
            double B32 = resultados2[3];
            double Wk2 = 650; double Xk2 = 3000; double Yk2 = 155;
            double z2 = F.obtenerZ(Wk2, Xk2, Yk2, B02, B12, B22, B32);
            Console.WriteLine("La z = " + z2);
            double rango2 = F.calcularRango(Wk2, Xk2, Yk2, DatosW2.Count - 4, DatosW2, DatosX2, DatosY2, DatosZ2, B02, B12, B22, B32);
            Console.WriteLine("UPI = " + (z2 + rango2));
            Console.WriteLine("LPI = " + (z2 - rango2));

            Console.ReadLine();
        }
Beispiel #35
0
        private void dotNetBarManager1_ItemClick(object sender, EventArgs e)
        {
            FileStream dh;
            StreamReader readLine;
            char[] charSplit;
            string strLine;
            string[] array1;
            string output = null;
            string[] array2;

            string strLine2;

            char[] charSplit2 = new char[] { ' ' };
            FileStream op;
            StreamWriter str1;
            FileStream dh2;
            StreamReader readLine2;
            Excel.Application ex;
            Excel.Worksheet xSheet;
            Excel.Application result1;
            Excel.Worksheet tempSheet;
            Excel.Worksheet newWorksheet;
            DevComponents.DotNetBar.ButtonItem btItem = sender as DevComponents.DotNetBar.ButtonItem;
            //Layer layer1 = (Layer)LayerBox.ComboBoxEx.SelectedItem;
            if (btItem != null)
            {
                switch (btItem.Name)
                {
                    #region 文件操作
                    case "mNew":
                        try
                        {
                            //{
                            XmlNodeList list = tlVectorControl1.SVGDocument.SelectNodes("svg/*[@layer='" + tlVectorControl1.SVGDocument.CurrentLayer.ID + "']");
                            for (int i = 0; i < list.Count; i++)
                            {
                                SvgElement ele = (SvgElement)list[i];
                                if (ele.LocalName == "polyline")
                                {
                                    PSPDEV _dev = new PSPDEV();
                                    _dev.EleID = ele.ID;
                                    _dev.SvgUID = tlVectorControl1.SVGDocument.CurrentLayer.ID;
                                    _dev = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVBySvgUIDandEleID", _dev);

                                    if (_dev == null)
                                    {
                                        LineInfo _pl = new LineInfo();
                                        _pl.EleID = ele.ID;
                                        _pl.SvgUID = tlVectorControl1.SVGDocument.CurrentLayer.ID;
                                        _pl = (LineInfo)Services.BaseService.GetObject("SelectLineInfoByEleID", _pl);
                                        if (_pl != null)
                                        {
                                            PSPDEV pspDev = new PSPDEV();
                                            pspDev.SUID = Guid.NewGuid().ToString();
                                            pspDev.EleID = ele.GetAttribute("id");
                                            pspDev.SvgUID = tlVectorControl1.SVGDocument.CurrentLayer.ID;
                                            pspDev.Number = -1;
                                            pspDev.FirstNode = -1;
                                            pspDev.LastNode = -1;
                                            pspDev.Type = "Polyline";
                                            pspDev.Lable = "支路";
                                            pspDev.Name = _pl.LineName;
                                            pspDev.LineLength = Convert.ToDouble(_pl.Length);
                                            pspDev.LineLevel = _pl.Voltage;
                                            pspDev.LineType = _pl.LineType;
                                            pspDev.LineStatus = "运行";
                                            Services.BaseService.Create<PSPDEV>(pspDev);
                                        }
                                    }
                                }
                                if (ele.LocalName == "use")
                                {
                                    PSPDEV _dev = new PSPDEV();
                                    _dev.EleID = ele.ID;
                                    _dev.SvgUID = tlVectorControl1.SVGDocument.CurrentLayer.ID;
                                    _dev = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVBySvgUIDandEleID", _dev);

                                    if (_dev == null)
                                    {
                                        substation _pl = new substation();
                                        _pl.EleID = ele.ID;
                                        _pl.SvgUID = tlVectorControl1.SVGDocument.CurrentLayer.ID;
                                        _pl = (substation)Services.BaseService.GetObject("SelectsubstationByEleID", _pl);
                                        if (_pl != null)
                                        {
                                            PSPDEV pspDev = new PSPDEV();
                                            pspDev.SUID = Guid.NewGuid().ToString();
                                            pspDev.EleID = ele.GetAttribute("id");
                                            pspDev.SvgUID = tlVectorControl1.SVGDocument.CurrentLayer.ID;
                                            pspDev.Number = -1;
                                            pspDev.FirstNode = -1;
                                            pspDev.LastNode = -1;
                                            pspDev.Type = "Use";
                                            pspDev.Lable = "变电站";
                                            pspDev.Name = _pl.EleName;
                                            pspDev.VoltR = Convert.ToDouble(_pl.ObligateField1);
                                            pspDev.Burthen = _pl.Number;
                                            Services.BaseService.Create<PSPDEV>(pspDev);
                                        }
                                    }

                                }

                            }

                            PSPDEV pppp = new PSPDEV();
                            pppp.Type = "power";
                            pppp.SvgUID = tlVectorControl1.SVGDocument.SvgdataUid;
                            IList listpp = Services.BaseService.GetList("SelectPSPDEVBySvgUIDAndType", pppp);
                            if (listpp == null || listpp.Count == 0)
                            {

                                if (MessageBox.Show("新建的潮流计算,需要设置基准值,是否立即设置??", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
                                {
                                    PSPDEV pspDev2 = new PSPDEV();

                                    //pspDev2.SUID = Guid.NewGuid().ToString();
                                    pspDev2.Type = "Power";
                                    pspDev2.SvgUID = tlVectorControl1.SVGDocument.SvgdataUid;
                                    pspDev2 = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVBySvgUIDAndType", pspDev2);
                                    if (pspDev2 != null)
                                    {
                                    }
                                    else
                                    {
                                        pspDev2 = new PSPDEV();
                                        pspDev2.SUID = Guid.NewGuid().ToString();
                                        pspDev2.Type = "Power";
                                        pspDev2.SvgUID = tlVectorControl1.SVGDocument.SvgdataUid;
                                        Services.BaseService.Create<PSPDEV>(pspDev2);
                                    }
                                    powerf pp = new powerf(pspDev2);
                                    if (pp.ShowDialog() == DialogResult.OK)
                                    {
                                        pspDev2.PowerFactor = Convert.ToDouble(pp.powerfactor);
                                        pspDev2.StandardVolt = Convert.ToDouble(pp.standardvolt);
                                        pspDev2.StandardCurrent = Convert.ToDouble(pp.standardcurrent);
                                        pspDev2.BigP = Convert.ToDouble(pp.bigP);
                                        Services.BaseService.Update<PSPDEV>(pspDev2);
                                        //PSPDEV voltall = new PSPDEV();
                                        //voltall.Type = "Use";
                                        //voltall.Lable = "电厂";
                                        //voltall.SvgUID = tlVectorControl1.SVGDocument.CurrentLayer.ID;
                                        //IList allvolt = Services.BaseService.GetList("SelectPSPDEVBySvgUIDandLableandType", voltall);
                                        //foreach (PSPDEV dev in allvolt)
                                        //{
                                        //    dev.OutP = Convert.ToDouble(dev.Burthen) * pspDev2.BigP;
                                        //    //dev.InPutP=dev.Burthen*pspDev2.BigP;
                                        //    dev.OutQ = dev.OutP * Math.Tan(Math.Acos(pspDev2.PowerFactor));
                                        //    Services.BaseService.Update<PSPDEV>(dev);
                                        //}
                                        //voltall.Lable = "变电站";
                                        //allvolt = Services.BaseService.GetList("SelectPSPDEVBySvgUIDandLableandType", voltall);
                                        //foreach (PSPDEV dev in allvolt)
                                        //{
                                        //    dev.InPutP = Convert.ToDouble(dev.Burthen) * pspDev2.BigP;
                                        //    //dev.InPutP=dev.Burthen*pspDev2.BigP;
                                        //    dev.InPutQ = dev.InPutP * pspDev2.BigP * Math.Tan(Math.Acos(pspDev2.PowerFactor));
                                        //    Services.BaseService.Update<PSPDEV>(dev);
                                        //}

                                    }
                                    //powerf pf=new powerf()
                                }
                            }
                            if (!Check())
                            {
                                return;
                            }
                            NIULA pspniula = new NIULA();
                            pspniula.CurrentCal();

                            if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\" + tlVectorControl1.SVGDocument.FileName + "牛拉法计算结果.xls"))
                            {
                                File.Delete(System.Windows.Forms.Application.StartupPath + "\\" + tlVectorControl1.SVGDocument.FileName + "牛拉法计算结果.xls");
                                //OpenRead(System.Windows.Forms.Application.StartupPath + "\\" + tlVectorControl1.SVGDocument.FileName + ".xls");
                            }

                            double yinzi = 0, capability = 0, volt = 0, current = 0, Rad_to_Deg = 57.29577951;
                            PSPDEV benchmark = new PSPDEV();
                            benchmark.Type = "power";
                            benchmark.SvgUID = tlVectorControl1.SVGDocument.SvgdataUid;
                            IList list3 = Services.BaseService.GetList("SelectPSPDEVBySvgUIDAndType", benchmark);
                            if (list3 == null)
                            {
                                MessageBox.Show("请设置基准后再进行计算!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                return;
                            }
                            foreach (PSPDEV dev in list3)
                            {
                                yinzi = Convert.ToDouble(dev.PowerFactor);
                                capability = Convert.ToDouble(dev.StandardCurrent);
                                volt = Convert.ToDouble(dev.StandardVolt);
                                if (dev.PowerFactor == 0)
                                {
                                    yinzi = 1;
                                }
                                if (dev.StandardCurrent == 0)
                                {
                                    capability = 1;
                                }
                                if (dev.StandardVolt == 0)
                                {
                                    volt = 1;
                                }
                                current = capability / (Math.Sqrt(3) * volt);

                            }
                            if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\PF1.txt"))
                            {
                            }
                            else
                            {
                                return;
                            }
                            dh = new FileStream(System.Windows.Forms.Application.StartupPath + "\\PF1.txt", FileMode.Open);
                            readLine = new StreamReader(dh);

                            charSplit = new char[] { ' ' };
                            strLine = readLine.ReadLine();

                            output += ("全网母线(发电、负荷)结果报表 " + "\r\n" + "\r\n");
                            output += ("单位:kA\\kV\\MW\\Mvar" + "\r\n" + "\r\n");
                            output += ("母线名" + "," + "电压幅值" + "," + "电压相角" + "," + "有功发电" + "," + "无功发电" + "," + "有功负荷" + "," + "无功负荷" + "," + "越限标志" + "," + "过载标志" + "\r\n");
                            int count = 0;
                            while (strLine != null && strLine != "")
                            {
                                array1 = strLine.Split(charSplit);
                                string[] dev = new string[9];
                                dev.Initialize();
                                int i = 0;
                                count++;
                                PSPDEV CR = new PSPDEV();
                                CR.SvgUID = tlVectorControl1.SVGDocument.CurrentLayer.ID;

                                foreach (string str in array1)
                                {
                                    if (str != "")
                                    {
                                        if (str != "NaN")
                                        {
                                            dev[i++] = Convert.ToDouble(str).ToString();
                                        }
                                        else
                                        {
                                            dev[i++] = str;
                                        }

                                    }

                                }

                                CR.Number = Convert.ToInt32(dev[0]);
                                CR.Type = "Use";
                                CR = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByNumberAndSvgUIDAndType", CR);
                                double vTemp = Convert.ToDouble(dev[1]) * volt;
                                double vTemp1 = volt * 95 / 100;
                                double vTemp2 = volt * 105 / 100;

                                if (vTemp >= vTemp1 && vTemp <= vTemp2)
                                {
                                    dev[5] = "0";
                                }
                                else
                                {
                                    dev[5] = "1";
                                }
                                if (Convert.ToDouble(dev[3]) * capability > Convert.ToDouble(CR.Burthen))
                                {
                                    dev[6] = "1";
                                }
                                else
                                {
                                    dev[6] = "0";
                                }

                                if (Convert.ToDouble(dev[3]) < 0)
                                {
                                    output += CR.Name + "," + (Convert.ToDouble(dev[1]) * volt).ToString() + "," + (Convert.ToDouble(dev[2]) * Rad_to_Deg).ToString() + "," + "0" + "," + "0" + "," + (Convert.ToDouble(dev[3]) * capability).ToString() + "," + (Convert.ToDouble(dev[4]) * capability).ToString() + "," + dev[5] + "," + dev[6] + "\r\n";
                                }
                                else
                                {
                                    output += CR.Name + "," + (Convert.ToDouble(dev[1]) * volt).ToString() + "," + (Convert.ToDouble(dev[2]) * Rad_to_Deg).ToString() + "," + (Convert.ToDouble(dev[3]) * capability).ToString() + "," + (Convert.ToDouble(dev[4]) * capability).ToString() + "," + "0" + "," + "0" + "," + dev[5] + "," + dev[6] + "\r\n";
                                }
                                strLine = readLine.ReadLine();
                            }
                            PSPDEV ct = new PSPDEV();
                            ct.SvgUID = tlVectorControl1.SVGDocument.CurrentLayer.ID;
                            ct.Type = "Use";
                            IList cont = Services.BaseService.GetList("SelectPSPDEVBySvgUIDAndType", ct);
                            if (count < cont.Count)
                            {
                                MessageBox.Show("请进行潮流计算后再查看结果!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                readLine.Close();
                                return;

                            }
                            readLine.Close();
                            if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\result.csv"))
                            {
                                File.Delete(System.Windows.Forms.Application.StartupPath + "\\result.csv");
                            }
                            op = new FileStream((System.Windows.Forms.Application.StartupPath + "\\result.csv"), FileMode.OpenOrCreate);
                            str1 = new StreamWriter(op, Encoding.GetEncoding("GB2312"));
                            str1.Write(output);
                            str1.Close();

                            if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\DH1.txt"))
                            {
                            }
                            else
                            {
                                return;
                            }
                            if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\IH1.txt"))
                            {
                            }
                            else
                            {
                                return;
                            }
                            dh = new FileStream(System.Windows.Forms.Application.StartupPath + "\\DH1.txt", FileMode.Open);
                            dh2 = new FileStream(System.Windows.Forms.Application.StartupPath + "\\IH1.txt", FileMode.Open);
                            readLine2 = new StreamReader(dh2);
                            readLine = new StreamReader(dh);
                            charSplit = new char[] { ' ' };
                            strLine = readLine.ReadLine();
                            strLine2 = readLine2.ReadLine();

                            output = null;

                            output += ("全网交流线结果报表" + "\r\n" + "\r\n");
                            output += ("单位:kA\\kV\\MW\\Mvar" + "\r\n" + "\r\n");
                            output += ("支路名称" + "," + "支路有功" + "," + "支路无功" + "," + "有功损耗" + "," + "无功损耗" + "," + "电流幅值" + "," + "电流相角" + "," + "越限标志" + "," + "\r\n");
                            while (strLine != null && strLine2 != null && strLine != "" && strLine2 != "")
                            {
                                array1 = strLine.Split(charSplit);
                                array2 = strLine2.Split(charSplit2);

                                string[] dev = new string[20];
                                dev.Initialize();
                                int i = 0;
                                PSPDEV CR = new PSPDEV();
                                CR.SvgUID = tlVectorControl1.SVGDocument.CurrentLayer.ID;

                                foreach (string str in array1)
                                {
                                    if (str != "")
                                    {
                                        if (i == 0)
                                        {
                                            dev[i++] = str.ToString();
                                        }
                                        else
                                        {
                                            if (str != "NaN")
                                            {
                                                dev[i++] = Convert.ToDouble(str).ToString();
                                            }
                                            else
                                            {
                                                dev[i++] = str;
                                            }

                                        }
                                    }

                                }
                                i = 7;
                                for (int j = 3; j < 5; j++)
                                {
                                    if (array2[j] != "")
                                    {
                                        if (array2[j] != "NaN")
                                        {
                                            dev[i++] = Convert.ToDouble(array2[j]).ToString();
                                        }
                                        else
                                        {
                                            dev[i++] = array2[j];
                                        }
                                    }

                                }
                                CR.Name = dev[0];
                                CR.Type = "Polyline";
                                CR = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByName", CR);

                                if (CR != null)
                                {
                                    if (Convert.ToDouble(dev[7]) * current * 1000 > CR.LineChange)
                                    {
                                        dev[11] = "1";
                                    }
                                    else
                                    {
                                        dev[11] = "0";
                                    }
                                    output += CR.Name + "," + (Convert.ToDouble(dev[3]) * capability).ToString() + "," + (Convert.ToDouble(dev[4]) * capability).ToString() + "," + (Convert.ToDouble(dev[5]) * capability).ToString() + "," + (Convert.ToDouble(dev[6]) * capability).ToString() + "," + (Convert.ToDouble(dev[7]) * current).ToString() + "," + (Convert.ToDouble(dev[8]) * Rad_to_Deg).ToString() + "," + dev[11] + "," + "\r\n";
                                }
                                else
                                {
                                    CR = new PSPDEV();
                                    CR.Name = dev[0];
                                    CR.Type = "TransformLine";
                                    CR.SvgUID = tlVectorControl1.SVGDocument.CurrentLayer.ID;
                                    CR = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByName", CR);
                                    if (CR != null)
                                    {
                                        if (Convert.ToDouble(dev[7]) * current * 1000 > CR.LineChange)
                                        {
                                            dev[11] = "1";
                                        }
                                        else
                                        {
                                            dev[11] = "0";
                                        }
                                        output += CR.Name + "," + (Convert.ToDouble(dev[3]) * capability).ToString() + "," + (Convert.ToDouble(dev[4]) * capability).ToString() + "," + (Convert.ToDouble(dev[5]) * capability).ToString() + "," + (Convert.ToDouble(dev[6]) * capability).ToString() + "," + (Convert.ToDouble(dev[7]) * current).ToString() + "," + (Convert.ToDouble(dev[8]) * Rad_to_Deg).ToString() + "," + dev[11] + "," + "\r\n";
                                    }
                                }

                                strLine = readLine.ReadLine();
                                strLine2 = readLine2.ReadLine();
                            }
                            readLine.Close();
                            readLine2.Close();
                            if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\result1.csv"))
                            {
                                File.Delete(System.Windows.Forms.Application.StartupPath + "\\result1.csv");
                            }
                            op = new FileStream((System.Windows.Forms.Application.StartupPath + "\\result1.csv"), FileMode.OpenOrCreate);
                            str1 = new StreamWriter(op, Encoding.GetEncoding("GB2312"));
                            str1.Write(output);
                            str1.Close();

                            ex = new Excel.Application();
                            ex.Application.Workbooks.Add(System.Windows.Forms.Application.StartupPath + "\\result.csv");
                            xSheet = (Excel.Worksheet)ex.Worksheets[1];
                            ex.Worksheets.Add(System.Reflection.Missing.Value, xSheet, 1, System.Reflection.Missing.Value);

                            result1 = new Excel.Application();
                            result1.Application.Workbooks.Add(System.Windows.Forms.Application.StartupPath + "\\result1.csv");
                            tempSheet = (Excel.Worksheet)result1.Worksheets.get_Item(1);
                            newWorksheet = (Excel.Worksheet)ex.Worksheets.get_Item(2);
                            newWorksheet.Name = "线路电流";
                            xSheet.Name = "母线潮流";
                            ex.Visible = true;

                            tempSheet.Cells.Select();
                            tempSheet.Cells.Copy(System.Reflection.Missing.Value);
                            newWorksheet.Paste(System.Reflection.Missing.Value, System.Reflection.Missing.Value);
                            xSheet.Rows.AutoFit();
                            xSheet.Columns.AutoFit();
                            newWorksheet.Rows.AutoFit();
                            newWorksheet.Columns.AutoFit();
                            xSheet.get_Range(xSheet.Cells[1, 1], xSheet.Cells[1, 9]).MergeCells = true;
                            xSheet.get_Range(xSheet.Cells[1, 1], xSheet.Cells[1, 1]).Font.Size = 20;
                            xSheet.get_Range(xSheet.Cells[1, 1], xSheet.Cells[1, 1]).Font.Name = "黑体";
                            xSheet.get_Range(xSheet.Cells[1, 1], xSheet.Cells[1, 1]).HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
                            xSheet.get_Range(xSheet.Cells[5, 1], xSheet.Cells[5, 9]).Interior.ColorIndex = 45;
                            xSheet.get_Range(xSheet.Cells[6, 1], xSheet.Cells[xSheet.UsedRange.Rows.Count, 1]).Interior.ColorIndex = 6;
                            xSheet.get_Range(xSheet.Cells[6, 2], xSheet.Cells[xSheet.UsedRange.Rows.Count, 9]).NumberFormat = "0.0000_ ";
                            xSheet.get_Range(xSheet.Cells[3, 1], xSheet.Cells[xSheet.UsedRange.Rows.Count, 9]).Font.Name = "楷体_GB2312";

                            newWorksheet.get_Range(newWorksheet.Cells[1, 1], newWorksheet.Cells[1, 9]).MergeCells = true;
                            newWorksheet.get_Range(newWorksheet.Cells[1, 1], newWorksheet.Cells[1, 1]).Font.Size = 20;
                            newWorksheet.get_Range(newWorksheet.Cells[1, 1], newWorksheet.Cells[1, 1]).Font.Name = "黑体";
                            newWorksheet.get_Range(newWorksheet.Cells[1, 1], newWorksheet.Cells[1, 1]).HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
                            newWorksheet.get_Range(newWorksheet.Cells[5, 1], newWorksheet.Cells[5, 8]).Interior.ColorIndex = 45;
                            newWorksheet.get_Range(newWorksheet.Cells[6, 1], newWorksheet.Cells[newWorksheet.UsedRange.Rows.Count, 1]).Interior.ColorIndex = 6;
                            newWorksheet.get_Range(newWorksheet.Cells[6, 2], newWorksheet.Cells[newWorksheet.UsedRange.Rows.Count, 9]).NumberFormat = "0.0000_ ";
                            newWorksheet.get_Range(newWorksheet.Cells[3, 1], newWorksheet.Cells[newWorksheet.UsedRange.Rows.Count, 9]).Font.Name = "楷体_GB2312";

                            //op = new FileStream((System.Windows.Forms.Application.StartupPath + "\\fck.excel"), FileMode.OpenOrCreate);
                            //str1 = new StreamWriter(op, Encoding.GetEncoding("GB2312"));

                            string fn = tlVectorControl1.SVGDocument.FileName;

                            //result1.Save(System.Windows.Forms.Application.StartupPath + "\\fck.xls");

                            newWorksheet.SaveAs(System.Windows.Forms.Application.StartupPath + "\\" + fn + "牛拉法计算结果.xls", Excel.XlFileFormat.xlXMLSpreadsheet, null, null, false, false, false, null, null, null);

                            //str1.Write();
                            //op.Close();

                            System.Windows.Forms.Clipboard.Clear();
                            result1.Workbooks.Close();
                            result1.Quit();

                        }
                        catch (System.Exception e1)
                        {
                            MessageBox.Show("请进行潮流计算后再查看结果!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        //}
                        break;
                    case "mOpen":
                        if (tlVectorControl1.IsModified == true)
                        {
                            DialogResult a;
                            a = MessageBox.Show("图形已修改,是否保存?", "提示", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information);

                            if (a == DialogResult.Yes)
                            {
                                Save();
                            }
                            else if (a == DialogResult.No)
                            {
                            }
                            else if (a == DialogResult.Cancel)
                            {
                                return;
                            }

                        }
                        Open();

                        break;
                    case "btExSymbol":
                        tlVectorControl1.ExportSymbol();
                        break;
                    case "mjxt"://导入接线图

                        string _svguid = ConfigurationSettings.AppSettings.Get("SvgID");
                        frmYear f = new frmYear();
                        f.uid = _svguid;
                        f.Show();
                        //ImportJxt jxt = new ImportJxt(tlVectorControl1);
                        //jxt.Import();
                        break;
                    case "mSave":
                        SaveAllLayer();

                        break;
                    case "mExit":
                        this.Close();
                        break;
                    case "bt1":
                        //InitTK();
                        break;
                    case "mFin":
                        frmGProList p = new frmGProList();
                        p.Show();
                        p.LoadData(LoadData());
                        break;
                    case "bt2":
                        break;
                    case "mPriSet":
                        this.tlVectorControl1.Operation = ToolOperation.InterEnclosurePrint;
                        break;
                    case "mPrint":
                        tlVectorControl1.Print();
                        break;
                    case "mImport":
                        ExportImage();
                        break;
                    case "mView":
                        //frmSvgView fView = new frmSvgView();
                        //fView.Open(tlVectorControl1.SVGDocument.CurrentLayer.ID);
                        //fView.Show();

                        break;

                    //case "mIncreaseView":
                    //    tlVectorControl1.Operation = ToolOperation.IncreaseView;
                    //    break;
                    case "mRzb":
                        frmRatio fRat = new frmRatio();
                        string viewRat = tlVectorControl1.SVGDocument.getRZBRatio();
                        if (viewRat != "")
                        {
                            fRat.InitData(viewRat);
                        }
                        if (fRat.ShowDialog() == DialogResult.OK)
                        {
                            viewRat = fRat.ViewScale;
                            tlVectorControl1.SVGDocument.setRZBRatio(viewRat);
                        }
                        break;

                    case "mAbout":

                        frmAbout frma = new frmAbout();
                        frma.ShowDialog();
                        break;

                    case "ButtonItem10":
                        int temp411 = 10;
                        frmConvert frmc = new frmConvert();
                        frmc.ShowDialog();
                        temp411++;
                        break;

                    //基础操作
                    case "mFreeTransform":
                        tlVectorControl1.Operation = ToolOperation.FreeTransform;

                        break;
                    case "mCJ":
                        tlVectorControl1.Operation = ToolOperation.PolyLine;
                        csOperation = CustomOperation.OP_MeasureDistance;
                        break;
                    //case "ButtonItem2":
                    //    break;
                    #endregion
                    #region 基础图元
                    case "mDecreaseView":
                        tlVectorControl1.Operation = ToolOperation.DecreaseView;

                        break;
                    case "mIncreaseView":

                        tlVectorControl1.Operation = ToolOperation.IncreaseView;
                        break;
                    case "mRoam":
                        tlVectorControl1.Operation = ToolOperation.Roam;

                        break;
                    case "mSelect":
                        tlVectorControl1.Operation = ToolOperation.Select;
                        break;
                    case "mSel":

                        tlVectorControl1.Operation = ToolOperation.FreeTransform;
                        break;
                    //case "mFreeTransform":
                    //    tlVectorControl1.Operation = ToolOperation.FreeTransform;

                    //    break;
                    case "mFreeLines"://锁套
                        tlVectorControl1.Operation = ToolOperation.FreeLines;

                        break;
                    case "mFreePath":
                        tlVectorControl1.Operation = ToolOperation.FreePath;

                        break;
                    case "mShapeTransform":
                        tlVectorControl1.Operation = ToolOperation.ShapeTransform;

                        break;
                    case "mAngleRectangle":
                        tlVectorControl1.Operation = ToolOperation.AngleRectangle;

                        break;
                    case "mEllipse":
                        tlVectorControl1.Operation = ToolOperation.Ellipse;

                        break;
                    case "mLine":
                        tlVectorControl1.Operation = ToolOperation.ConnectLine_Polyline;

                        break;
                    case "mPolyline":
                        tlVectorControl1.Operation = ToolOperation.PolyLine;

                        break;
                    case "mConnectLine":
                        tlVectorControl1.Operation = ToolOperation.ConnectLine;
                        break;

                    case "mPolygon":
                        tlVectorControl1.Operation = ToolOperation.Polygon;

                        break;
                    case "mImage":
                        tlVectorControl1.Operation = ToolOperation.Image;
                        break;
                    case "mText":
                        tlVectorControl1.Operation = ToolOperation.Text;
                        break;
                    case "mBezier":
                        tlVectorControl1.Operation = ToolOperation.Bezier;

                        break;
                    case "ButtonItem2":
                        fileType = true;
                        if (fileType == true)
                        {
                            LoadShape("symbol20.xml");
                            //jxtbar(1);
                        }
                        else
                        {
                            LoadShape("symbol21.xml");
                            //jxtbar(0);
                        }
                        tlVectorControl1.SVGDocument.CurrentLayer.ID = Guid.NewGuid().ToString();
                        SvgDocument.currentLayer = Layer.CreateNew("默认层", tlVectorControl1.SVGDocument).ID;
                        tlVectorControl1.IsModified = false;
                        frmElementName dlgnew2 = new frmElementName();
                        dlgnew2.TextInput = tlVectorControl1.SVGDocument.FileName;
                        if (dlgnew2.ShowDialog() == DialogResult.OK)
                        {
                            tlVectorControl1.SVGDocument.FileName = dlgnew2.TextInput;
                            Save();
                        }
                        //NewFile(fileType);
                        break;
                    case "ButtonItem8":
                        fileType = false;
                        //NewFile(fileType);
                        tlVectorControl1.NewFile();
                        if (fileType == true)
                        {
                            LoadShape("symbol20.xml");
                            //jxtbar(1);
                        }
                        else
                        {
                            LoadShape("symbol21.xml");
                            //jxtbar(0);
                        }
                        tlVectorControl1.SVGDocument.CurrentLayer.ID = Guid.NewGuid().ToString();
                        SvgDocument.currentLayer = Layer.CreateNew("默认层", tlVectorControl1.SVGDocument).ID;
                        tlVectorControl1.IsModified = false;
                        frmElementName dlgnew3 = new frmElementName();
                        dlgnew3.TextInput = tlVectorControl1.SVGDocument.FileName;
                        if (dlgnew3.ShowDialog() == DialogResult.OK)
                        {
                            tlVectorControl1.SVGDocument.FileName = dlgnew3.TextInput;
                            Save();
                        }
                        break;
                    case "mCheck":
                        Check();
                        break;
                    case "niula":
                        //MessageBox.Show(Directory.GetCurrentDirectory());
                        //frmTLpsp el = new frmTLpsp();
                        PspNIULA();
                        //oThread = new Thread(new ThreadStart(el.PspNIULA));
                        //oThread.Start();
                        //try
                        //{
                        //    time = new System.Threading.Timer(new TimerCallback(method), null, 50000, 60000);
                        //}
                        //catch { }
                        break;
                    case "pq":
                        //frmTLpsp e2 = new frmTLpsp();
                        PspPQ();
                        break;
                    //case "ShortCut":
                    //    ShortCutCheck();
                    //    break;
                    case "GaussSeidel":
                        PspGaussSeidel();
                        break;
                    case "PowerLossCal":
                        PspPowerLossCal();
                        break;
                    case "N_RZYz":
                        PspN_RZYz();
                        break;
                    case "WebRela":                        //进行网络N-1检验

                        WebCalAndPrint();
                        break;
                    case "TransRela":                       //进行变压器N-1检验

                        break;
                    case "DuanluResult":
                        //ShortCutCheck();
                        //PSPDEV pspDuanlu = new PSPDEV();
                        //pspDuanlu.SvgUID = tlVectorControl1.SVGDocument.CurrentLayer.ID;
                        //frmDuanlu dudu = new frmDuanlu(pspDuanlu);
                        //PSPDEV Duanlu = new PSPDEV();
                        //Duanlu.SvgUID = tlVectorControl1.SVGDocument.CurrentLayer.ID;

                        //if (dudu.ShowDialog() == DialogResult.OK)
                        //{

                        //    Duanlu = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByName", Duanlu);
                        //    n4 = Convert.ToInt32(dudu.hscool);
                        //    if (Duanlu.Type == "Use")
                        //    {
                        //        n1 = Duanlu.Number;
                        //        n2 = Duanlu.Number;
                        //        string dlr=n1.ToString();
                        //        if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\dlb.txt"))
                        //        {
                        //            File.Delete(System.Windows.Forms.Application.StartupPath+"\\dlb.txt");
                        //        }

                        //        FileStream VK = new FileStream((System.Windows.Forms.Application.StartupPath+"\\data.txt"), FileMode.OpenOrCreate);
                        //        StreamWriter str11 = new StreamWriter(VK);
                        //        str11.Write(dlr);
                        //        str11.Close();

                        //        n4 = 0;
                        //    }
                        //    if (Duanlu.Type == "Polyline")
                        //    {
                        //        n1 = Duanlu.FirstNode;
                        //        n2 = Duanlu.LastNode;
                        //    }
                        //    switch (dudu.DuanluType){

                        //        case "单相接地":
                        //            n3 = 1;
                        //            break;

                        //        case "两相接地":
                        //            n3 = 3;
                        //            break;
                        //        case "两相故障":
                        //            n3 = 2;
                        //            break;
                        //        case "三相故障":
                        //            n3 = 0;
                        //            break;
                        //        default:
                        //            n3 = 1;
                        //            break;
                        //    }
                        //    duanlu.myshort(n1, n2, n3, n4);
                        // }
                        break;
                    //case "DuanluResult":
                    //    il = 1;
                    //    break;
                    case "dd":
                        //SubPrint = true;
                        tlVectorControl1.Operation = ToolOperation.InterEnclosurePrint;
                        break;

                    case "NiulaResult":
                        try
                        {
                            //{
                            if (!Check())
                            {
                                return;
                            }
                            NIULA pspniula = new NIULA();
                            pspniula.CurrentCal();

                            if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\" + tlVectorControl1.SVGDocument.FileName + "牛拉法计算结果.xls"))
                            {
                                File.Delete(System.Windows.Forms.Application.StartupPath + "\\" + tlVectorControl1.SVGDocument.FileName + "牛拉法计算结果.xls");
                                //OpenRead(System.Windows.Forms.Application.StartupPath + "\\" + tlVectorControl1.SVGDocument.FileName + ".xls");
                            }

                            double yinzi = 0, capability = 0, volt = 0, current = 0, standvolt = 0, Rad_to_Deg = 57.29577951;
                            PSPDEV benchmark = new PSPDEV();
                            benchmark.Type = "power";
                            benchmark.SvgUID = tlVectorControl1.SVGDocument.SvgdataUid;
                            IList list3 = Services.BaseService.GetList("SelectPSPDEVBySvgUIDAndType", benchmark);
                            if (list3 == null)
                            {
                                MessageBox.Show("请设置基准后再进行计算!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                return;
                            }
                            foreach (PSPDEV dev in list3)
                            {
                                yinzi = Convert.ToDouble(dev.PowerFactor);
                                capability = Convert.ToDouble(dev.StandardCurrent);
                                volt = Convert.ToDouble(dev.StandardVolt);
                                if (dev.PowerFactor == 0)
                                {
                                    yinzi = 1;
                                }
                                if (dev.StandardCurrent == 0)
                                {
                                    capability = 1;
                                }
                                if (dev.StandardVolt == 0)
                                {
                                    volt = 1;
                                }
                                standvolt = volt;
                                current = capability / (Math.Sqrt(3) * volt);

                            }
                            capability = 100;

                            if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\PF1.txt"))
                            {
                            }
                            else
                            {
                                return;
                            }
                            dh = new FileStream(System.Windows.Forms.Application.StartupPath + "\\PF1.txt", FileMode.Open);
                            readLine = new StreamReader(dh);

                            charSplit = new char[] { ' ' };
                            strLine = readLine.ReadLine();

                            output += ("全网母线(发电、负荷)结果报表 " + "\r\n" + "\r\n");
                            output += ("单位:kA\\kV\\MW\\Mvar" + "\r\n" + "\r\n");
                            output += ("母线名" + "," + "电压幅值" + "," + "电压相角" + "," + "有功发电" + "," + "无功发电" + "," + "有功负荷" + "," + "无功负荷" + "," + "越限标志" + "," + "过载标志" + "\r\n");
                            int count = 0;
                            while (strLine != null && strLine != "")
                            {
                                array1 = strLine.Split(charSplit);
                                string[] dev = new string[9];
                                dev.Initialize();
                                int i = 0;
                                count++;
                                PSPDEV CR = new PSPDEV();
                                CR.SvgUID = tlVectorControl1.SVGDocument.CurrentLayer.ID;

                                foreach (string str in array1)
                                {
                                    if (str != "")
                                    {
                                        if (str != "NaN")
                                        {
                                            dev[i++] = Convert.ToDouble(str).ToString();
                                        }
                                        else
                                        {
                                            dev[i++] = str;
                                        }

                                    }

                                }

                                CR.Number = Convert.ToInt32(dev[0]);
                                CR.Type = "Use";
                                CR = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByNumberAndSvgUIDAndType", CR);
                                if (CR.ReferenceVolt != null && CR.ReferenceVolt != 0)
                                {
                                    volt = CR.ReferenceVolt;
                                }
                                else
                                    volt = standvolt;
                                current = capability / (Math.Sqrt(3) * volt);
                                double vTemp = Convert.ToDouble(dev[1]) * volt;
                                double vTemp1 = volt * 95 / 100;
                                double vTemp2 = volt * 105 / 100;

                                if (vTemp >= vTemp1 && vTemp <= vTemp2)
                                {
                                    dev[5] = "0";
                                }
                                else
                                {
                                    dev[5] = "1";
                                }
                                if (Convert.ToDouble(dev[3]) * capability > Convert.ToDouble(CR.Burthen))
                                {
                                    dev[6] = "1";
                                }
                                else
                                {
                                    dev[6] = "0";
                                }

                                if (Convert.ToDouble(dev[3]) < 0)
                                {
                                    output += CR.Name + "," + (Convert.ToDouble(dev[1]) * volt).ToString() + "," + (Convert.ToDouble(dev[2]) * Rad_to_Deg).ToString() + "," + "0" + "," + "0" + "," + (Convert.ToDouble(dev[3]) * capability).ToString() + "," + (Convert.ToDouble(dev[4]) * capability).ToString() + "," + dev[5] + "," + dev[6] + "\r\n";
                                }
                                else
                                {
                                    output += CR.Name + "," + (Convert.ToDouble(dev[1]) * volt).ToString() + "," + (Convert.ToDouble(dev[2]) * Rad_to_Deg).ToString() + "," + (Convert.ToDouble(dev[3]) * capability).ToString() + "," + (Convert.ToDouble(dev[4]) * capability).ToString() + "," + "0" + "," + "0" + "," + dev[5] + "," + dev[6] + "\r\n";
                                }
                                strLine = readLine.ReadLine();
                            }
                            PSPDEV ct = new PSPDEV();
                            ct.SvgUID = tlVectorControl1.SVGDocument.CurrentLayer.ID;
                            ct.Type = "Use";
                            IList cont = Services.BaseService.GetList("SelectPSPDEVBySvgUIDAndType", ct);
                            if (count < cont.Count)
                            {
                                MessageBox.Show("请进行潮流计算后再查看结果!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                readLine.Close();
                                return;

                            }
                            readLine.Close();
                            if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\result.csv"))
                            {
                                File.Delete(System.Windows.Forms.Application.StartupPath + "\\result.csv");
                            }
                            op = new FileStream((System.Windows.Forms.Application.StartupPath + "\\result.csv"), FileMode.OpenOrCreate);
                            str1 = new StreamWriter(op, Encoding.GetEncoding("GB2312"));
                            str1.Write(output);
                            str1.Close();

                            if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\DH1.txt"))
                            {
                            }
                            else
                            {
                                return;
                            }
                            if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\IH1.txt"))
                            {
                            }
                            else
                            {
                                return;
                            }
                            dh = new FileStream(System.Windows.Forms.Application.StartupPath + "\\DH1.txt", FileMode.Open);
                            dh2 = new FileStream(System.Windows.Forms.Application.StartupPath + "\\IH1.txt", FileMode.Open);
                            readLine2 = new StreamReader(dh2);
                            readLine = new StreamReader(dh);
                            charSplit = new char[] { ' ' };
                            strLine = readLine.ReadLine();
                            strLine2 = readLine2.ReadLine();

                            output = null;

                            output += ("全网交流线结果报表" + "\r\n" + "\r\n");
                            output += ("单位:kA\\kV\\MW\\Mvar" + "\r\n" + "\r\n");
                            output += ("支路名称" + "," + "支路有功" + "," + "支路无功" + "," + "有功损耗" + "," + "无功损耗" + "," + "电流幅值" + "," + "电流相角" + "," + "越限标志" + "," + "\r\n");
                            while (strLine != null && strLine2 != null && strLine != "" && strLine2 != "")
                            {
                                array1 = strLine.Split(charSplit);
                                array2 = strLine2.Split(charSplit2);

                                string[] dev = new string[20];
                                dev.Initialize();
                                int i = 0;
                                PSPDEV CR = new PSPDEV();
                                CR.SvgUID = tlVectorControl1.SVGDocument.CurrentLayer.ID;

                                foreach (string str in array1)
                                {
                                    if (str != "")
                                    {
                                        if (i == 0)
                                        {
                                            dev[i++] = str.ToString();
                                        }
                                        else
                                        {
                                            if (str != "NaN")
                                            {
                                                dev[i++] = Convert.ToDouble(str).ToString();
                                            }
                                            else
                                            {
                                                dev[i++] = str;
                                            }

                                        }
                                    }

                                }
                                i = 7;
                                for (int j = 3; j < 5; j++)
                                {
                                    if (array2[j] != "")
                                    {
                                        if (array2[j] != "NaN")
                                        {
                                            dev[i++] = Convert.ToDouble(array2[j]).ToString();
                                        }
                                        else
                                        {
                                            dev[i++] = array2[j];
                                        }
                                    }

                                }
                                CR.Name = dev[0];
                                CR.Type = "Polyline";
                                CR = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByName", CR);
                                if (CR.ReferenceVolt != null && CR.ReferenceVolt != 0)
                                {
                                    volt = CR.ReferenceVolt;
                                }
                                else
                                    volt = standvolt;
                                current = capability / (Math.Sqrt(3) * volt);
                                if (CR != null)
                                {
                                    if (Convert.ToDouble(dev[7]) * current * 1000 > CR.LineChange)
                                    {
                                        dev[11] = "1";
                                    }
                                    else
                                    {
                                        dev[11] = "0";
                                    }
                                    output += CR.Name + "," + (Convert.ToDouble(dev[3]) * capability).ToString() + "," + (Convert.ToDouble(dev[4]) * capability).ToString() + "," + (Convert.ToDouble(dev[5]) * capability).ToString() + "," + (Convert.ToDouble(dev[6]) * capability).ToString() + "," + (Convert.ToDouble(dev[7]) * current).ToString() + "," + (Convert.ToDouble(dev[8]) * Rad_to_Deg).ToString() + "," + dev[11] + "," + "\r\n";
                                }
                                else
                                {
                                    CR = new PSPDEV();
                                    CR.Name = dev[0];
                                    CR.Type = "TransformLine";
                                    CR.SvgUID = tlVectorControl1.SVGDocument.CurrentLayer.ID;
                                    CR = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByName", CR);
                                    if (CR != null)
                                    {
                                        if (Convert.ToDouble(dev[7]) * current * 1000 > CR.LineChange)
                                        {
                                            dev[11] = "1";
                                        }
                                        else
                                        {
                                            dev[11] = "0";
                                        }
                                        output += CR.Name + "," + (Convert.ToDouble(dev[3]) * capability).ToString() + "," + (Convert.ToDouble(dev[4]) * capability).ToString() + "," + (Convert.ToDouble(dev[5]) * capability).ToString() + "," + (Convert.ToDouble(dev[6]) * capability).ToString() + "," + (Convert.ToDouble(dev[7]) * current).ToString() + "," + (Convert.ToDouble(dev[8]) * Rad_to_Deg).ToString() + "," + dev[11] + "," + "\r\n";
                                    }
                                }

                                strLine = readLine.ReadLine();
                                strLine2 = readLine2.ReadLine();
                            }
                            readLine.Close();
                            readLine2.Close();
                            if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\result1.csv"))
                            {
                                File.Delete(System.Windows.Forms.Application.StartupPath + "\\result1.csv");
                            }
                            op = new FileStream((System.Windows.Forms.Application.StartupPath + "\\result1.csv"), FileMode.OpenOrCreate);
                            str1 = new StreamWriter(op, Encoding.GetEncoding("GB2312"));
                            str1.Write(output);
                            str1.Close();

                            ex = new Excel.Application();
                            ex.Application.Workbooks.Add(System.Windows.Forms.Application.StartupPath + "\\result.csv");
                            xSheet = (Excel.Worksheet)ex.Worksheets[1];
                            ex.Worksheets.Add(System.Reflection.Missing.Value, xSheet, 1, System.Reflection.Missing.Value);

                            result1 = new Excel.Application();
                            result1.Application.Workbooks.Add(System.Windows.Forms.Application.StartupPath + "\\result1.csv");
                            tempSheet = (Excel.Worksheet)result1.Worksheets.get_Item(1);
                            newWorksheet = (Excel.Worksheet)ex.Worksheets.get_Item(2);
                            newWorksheet.Name = "线路电流";
                            xSheet.Name = "母线潮流";
                            ex.Visible = true;

                            tempSheet.Cells.Select();
                            tempSheet.Cells.Copy(System.Reflection.Missing.Value);
                            newWorksheet.Paste(System.Reflection.Missing.Value, System.Reflection.Missing.Value);
                            xSheet.Rows.AutoFit();
                            xSheet.Columns.AutoFit();
                            newWorksheet.Rows.AutoFit();
                            newWorksheet.Columns.AutoFit();
                            xSheet.get_Range(xSheet.Cells[1, 1], xSheet.Cells[1, 9]).MergeCells = true;
                            xSheet.get_Range(xSheet.Cells[1, 1], xSheet.Cells[1, 1]).Font.Size = 20;
                            xSheet.get_Range(xSheet.Cells[1, 1], xSheet.Cells[1, 1]).Font.Name = "黑体";
                            xSheet.get_Range(xSheet.Cells[1, 1], xSheet.Cells[1, 1]).HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
                            xSheet.get_Range(xSheet.Cells[5, 1], xSheet.Cells[5, 9]).Interior.ColorIndex = 45;
                            xSheet.get_Range(xSheet.Cells[6, 1], xSheet.Cells[xSheet.UsedRange.Rows.Count, 1]).Interior.ColorIndex = 6;
                            xSheet.get_Range(xSheet.Cells[6, 2], xSheet.Cells[xSheet.UsedRange.Rows.Count, 9]).NumberFormat = "0.0000_ ";
                            xSheet.get_Range(xSheet.Cells[3, 1], xSheet.Cells[xSheet.UsedRange.Rows.Count, 9]).Font.Name = "楷体_GB2312";

                            newWorksheet.get_Range(newWorksheet.Cells[1, 1], newWorksheet.Cells[1, 9]).MergeCells = true;
                            newWorksheet.get_Range(newWorksheet.Cells[1, 1], newWorksheet.Cells[1, 1]).Font.Size = 20;
                            newWorksheet.get_Range(newWorksheet.Cells[1, 1], newWorksheet.Cells[1, 1]).Font.Name = "黑体";
                            newWorksheet.get_Range(newWorksheet.Cells[1, 1], newWorksheet.Cells[1, 1]).HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
                            newWorksheet.get_Range(newWorksheet.Cells[5, 1], newWorksheet.Cells[5, 8]).Interior.ColorIndex = 45;
                            newWorksheet.get_Range(newWorksheet.Cells[6, 1], newWorksheet.Cells[newWorksheet.UsedRange.Rows.Count, 1]).Interior.ColorIndex = 6;
                            newWorksheet.get_Range(newWorksheet.Cells[6, 2], newWorksheet.Cells[newWorksheet.UsedRange.Rows.Count, 9]).NumberFormat = "0.0000_ ";
                            newWorksheet.get_Range(newWorksheet.Cells[3, 1], newWorksheet.Cells[newWorksheet.UsedRange.Rows.Count, 9]).Font.Name = "楷体_GB2312";

                            //op = new FileStream((System.Windows.Forms.Application.StartupPath + "\\fck.excel"), FileMode.OpenOrCreate);
                            //str1 = new StreamWriter(op, Encoding.GetEncoding("GB2312"));

                            string fn = tlVectorControl1.SVGDocument.FileName;

                            //result1.Save(System.Windows.Forms.Application.StartupPath + "\\fck.xls");

                            newWorksheet.SaveAs(System.Windows.Forms.Application.StartupPath + "\\" + fn + "牛拉法计算结果.xls", Excel.XlFileFormat.xlXMLSpreadsheet, null, null, false, false, false, null, null, null);

                            //str1.Write();
                            //op.Close();

                            System.Windows.Forms.Clipboard.Clear();
                            result1.Workbooks.Close();
                            result1.Quit();

                        }
                        catch (System.Exception e1)
                        {
                            MessageBox.Show("请进行潮流计算后再查看结果!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        //}
                        break;
                    case "GaussSeidelResult":
                        try
                        {

                            if (!Check())
                            {
                                return;
                            }
                            Gauss pspgauss = new Gauss();
                            pspgauss.CurrentCal();
                            if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\" + tlVectorControl1.SVGDocument.FileName + "高斯-赛德尔计算结果.xls"))
                            {
                                File.Delete(System.Windows.Forms.Application.StartupPath + "\\" + tlVectorControl1.SVGDocument.FileName + "高斯-赛德尔计算结果.xls");
                                //OpenRead(System.Windows.Forms.Application.StartupPath + "\\" + tlVectorControl1.SVGDocument.FileName + ".xls");
                            }

                            double yinzi = 0, capability = 0, volt = 0, current = 0, Rad_to_Deg = 57.29577951;
                            PSPDEV benchmark = new PSPDEV();
                            benchmark.Type = "power";
                            benchmark.SvgUID = tlVectorControl1.SVGDocument.SvgdataUid;
                            IList list3 = Services.BaseService.GetList("SelectPSPDEVBySvgUIDAndType", benchmark);
                            if (list3 == null)
                            {
                                MessageBox.Show("请设置基准后再进行计算!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                return;
                            }
                            foreach (PSPDEV dev in list3)
                            {
                                yinzi = Convert.ToDouble(dev.PowerFactor);
                                capability = Convert.ToDouble(dev.StandardCurrent);
                                volt = Convert.ToDouble(dev.StandardVolt);
                                if (dev.PowerFactor == 0)
                                {
                                    yinzi = 1;
                                }
                                if (dev.StandardCurrent == 0)
                                {
                                    capability = 1;
                                }
                                if (dev.StandardVolt == 0)
                                {
                                    volt = 1;
                                }
                                current = capability / (Math.Sqrt(3) * volt);
                            };
                            if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\PF3.txt"))
                            {
                            }
                            else
                            {
                                return;
                            }
                            dh = new FileStream(System.Windows.Forms.Application.StartupPath + "\\PF3.txt", FileMode.Open);
                            readLine = new StreamReader(dh);

                            charSplit = new char[] { ' ' };
                            strLine = readLine.ReadLine();

                            output += ("全网母线(发电、负荷)结果报表 " + "\r\n" + "\r\n");
                            output += ("单位:kA\\kV\\MW\\Mvar" + "\r\n" + "\r\n");
                            output += ("母线名" + "," + "电压幅值" + "," + "电压相角" + "," + "有功发电" + "," + "无功发电" + "," + "有功负荷" + "," + "无功负荷" + "," + "越限标志" + "," + "过载标志" + "\r\n");
                            int count = 0;
                            while (strLine != null && strLine != "")
                            {
                                array1 = strLine.Split(charSplit);
                                string[] dev = new string[9];
                                dev.Initialize();
                                int i = 0;
                                count++;
                                PSPDEV CR = new PSPDEV();
                                CR.SvgUID = tlVectorControl1.SVGDocument.CurrentLayer.ID;

                                foreach (string str in array1)
                                {
                                    if (str != "")
                                    {
                                        if (str != "NaN")
                                        {
                                            dev[i++] = Convert.ToDouble(str).ToString();
                                        }
                                        else
                                        {
                                            dev[i++] = str;
                                        }

                                    }

                                }

                                CR.Number = Convert.ToInt32(dev[0]);
                                CR.Type = "Use";
                                CR = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByNumberAndSvgUIDAndType", CR);
                                double vTemp = Convert.ToDouble(dev[1]) * volt;
                                double vTemp1 = volt * 95 / 100;
                                double vTemp2 = volt * 105 / 100;

                                if (vTemp >= vTemp1 && vTemp <= vTemp2)
                                {
                                    dev[5] = "0";
                                }
                                else
                                {
                                    dev[5] = "1";
                                }
                                if (Convert.ToDouble(dev[3]) * capability > Convert.ToDouble(CR.Burthen))
                                {
                                    dev[6] = "1";
                                }
                                else
                                {
                                    dev[6] = "0";
                                }

                                if (Convert.ToDouble(dev[3]) < 0)
                                {

                                    output += CR.Name + "," + (Convert.ToDouble(dev[1]) * volt).ToString() + "," + (Convert.ToDouble(dev[2]) * Rad_to_Deg).ToString() + "," + "0" + "," + "0" + "," + (Convert.ToDouble(dev[3]) * capability).ToString() + "," + (Convert.ToDouble(dev[4]) * capability).ToString() + "," + dev[5] + "," + dev[6] + "\r\n";
                                }
                                else
                                {

                                    output += CR.Name + "," + (Convert.ToDouble(dev[1]) * volt).ToString() + "," + (Convert.ToDouble(dev[2]) * Rad_to_Deg).ToString() + "," + (Convert.ToDouble(dev[3]) * capability).ToString() + "," + (Convert.ToDouble(dev[4]) * capability).ToString() + "," + "0" + "," + "0" + "," + dev[5] + "," + dev[6] + "\r\n";
                                }
                                strLine = readLine.ReadLine();
                            }
                            PSPDEV ct = new PSPDEV();
                            ct.SvgUID = tlVectorControl1.SVGDocument.CurrentLayer.ID;
                            ct.Type = "Use";
                            IList cont = Services.BaseService.GetList("SelectPSPDEVBySvgUIDAndType", ct);
                            if (count < cont.Count)
                            {
                                MessageBox.Show("请进行潮流计算后再查看结果!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                readLine.Close();
                                return;

                            }
                            readLine.Close();
                            if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\result.csv"))
                            {
                                File.Delete(System.Windows.Forms.Application.StartupPath + "\\result.csv");
                            }
                            op = new FileStream((System.Windows.Forms.Application.StartupPath + "\\result.csv"), FileMode.OpenOrCreate);
                            str1 = new StreamWriter(op, Encoding.GetEncoding("GB2312"));
                            str1.Write(output);
                            str1.Close();

                            if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\DH3.txt"))
                            {
                            }
                            else
                            {
                                return;
                            }
                            if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\IH3.txt"))
                            {
                            }
                            else
                            {
                                return;
                            }
                            dh = new FileStream(System.Windows.Forms.Application.StartupPath + "\\DH3.txt", FileMode.Open);
                            dh2 = new FileStream(System.Windows.Forms.Application.StartupPath + "\\IH3.txt", FileMode.Open);
                            readLine2 = new StreamReader(dh2);
                            readLine = new StreamReader(dh);
                            charSplit = new char[] { ' ' };
                            strLine = readLine.ReadLine();
                            strLine2 = readLine2.ReadLine();

                            output = null;

                            output += ("全网交流线结果报表" + "\r\n" + "\r\n");
                            output += ("单位:kA\\kV\\MW\\Mvar" + "\r\n" + "\r\n");
                            output += ("支路名称" + "," + "支路有功" + "," + "支路无功" + "," + "有功损耗" + "," + "无功损耗" + "," + "电流幅值" + "," + "电流相角" + "," + "越限标志" + "," + "\r\n");
                            while (strLine != null && strLine2 != null && strLine != "" && strLine2 != "")
                            {
                                array1 = strLine.Split(charSplit);
                                array2 = strLine2.Split(charSplit2);

                                string[] dev = new string[20];
                                dev.Initialize();
                                int i = 0;
                                PSPDEV CR = new PSPDEV();
                                CR.SvgUID = tlVectorControl1.SVGDocument.CurrentLayer.ID;

                                foreach (string str in array1)
                                {
                                    if (str != "")
                                    {
                                        if (i == 0)
                                        {
                                            dev[i++] = str.ToString();
                                        }
                                        else
                                        {
                                            if (str != "NaN")
                                            {
                                                dev[i++] = Convert.ToDouble(str).ToString();
                                            }
                                            else
                                            {
                                                dev[i++] = str;
                                            }

                                        }
                                    }

                                }
                                i = 7;
                                for (int j = 3; j < 5; j++)
                                {
                                    if (array2[j] != "")
                                    {
                                        if (array2[j] != "NaN")
                                        {
                                            dev[i++] = Convert.ToDouble(array2[j]).ToString();
                                        }
                                        else
                                        {
                                            dev[i++] = array2[j];
                                        }
                                    }

                                }
                                CR.Name = dev[0];
                                CR.Type = "Polyline";
                                CR = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByName", CR);

                                if (CR != null)
                                {
                                    if (Convert.ToDouble(dev[7]) * current * 1000 > CR.LineChange)
                                    {
                                        dev[11] = "1";
                                    }
                                    else
                                    {
                                        dev[11] = "0";
                                    }
                                    output += CR.Name + "," + (Convert.ToDouble(dev[3]) * capability).ToString() + "," + (Convert.ToDouble(dev[4]) * capability).ToString() + "," + (Convert.ToDouble(dev[5]) * capability).ToString() + "," + (Convert.ToDouble(dev[6]) * capability).ToString() + "," + (Convert.ToDouble(dev[7]) * current).ToString() + "," + (Convert.ToDouble(dev[8]) * Rad_to_Deg).ToString() + "," + dev[11] + "," + "\r\n";
                                }
                                else
                                {
                                    CR = new PSPDEV();
                                    CR.Name = dev[0];
                                    CR.Type = "TransformLine";
                                    CR.SvgUID = tlVectorControl1.SVGDocument.CurrentLayer.ID;
                                    CR = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByName", CR);
                                    if (CR != null)
                                    {
                                        if (Convert.ToDouble(dev[7]) * current * 1000 > CR.LineChange)
                                        {
                                            dev[11] = "1";
                                        }
                                        else
                                        {
                                            dev[11] = "0";
                                        }
                                        output += CR.Name + "," + (Convert.ToDouble(dev[3]) * capability).ToString() + "," + (Convert.ToDouble(dev[4]) * capability).ToString() + "," + (Convert.ToDouble(dev[5]) * capability).ToString() + "," + (Convert.ToDouble(dev[6]) * capability).ToString() + "," + (Convert.ToDouble(dev[7]) * current).ToString() + "," + (Convert.ToDouble(dev[8]) * Rad_to_Deg).ToString() + "," + dev[11] + "," + "\r\n";
                                    }
                                }

                                strLine = readLine.ReadLine();
                                strLine2 = readLine2.ReadLine();
                            }
                            readLine.Close();
                            readLine2.Close();
                            if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\result1.csv"))
                            {
                                File.Delete(System.Windows.Forms.Application.StartupPath + "\\result1.csv");
                            }
                            op = new FileStream((System.Windows.Forms.Application.StartupPath + "\\result1.csv"), FileMode.OpenOrCreate);
                            str1 = new StreamWriter(op, Encoding.GetEncoding("GB2312"));
                            str1.Write(output);
                            str1.Close();

                            ex = new Excel.Application();
                            ex.Application.Workbooks.Add(System.Windows.Forms.Application.StartupPath + "\\result.csv");
                            xSheet = (Excel.Worksheet)ex.Worksheets[1];
                            ex.Worksheets.Add(System.Reflection.Missing.Value, xSheet, 1, System.Reflection.Missing.Value);

                            result1 = new Excel.Application();
                            result1.Application.Workbooks.Add(System.Windows.Forms.Application.StartupPath + "\\result1.csv");
                            tempSheet = (Excel.Worksheet)result1.Worksheets.get_Item(1);
                            newWorksheet = (Excel.Worksheet)ex.Worksheets.get_Item(2);
                            newWorksheet.Name = "线路电流";
                            xSheet.Name = "母线潮流";
                            ex.Visible = true;

                            tempSheet.Cells.Select();
                            tempSheet.Cells.Copy(System.Reflection.Missing.Value);
                            newWorksheet.Paste(System.Reflection.Missing.Value, System.Reflection.Missing.Value);
                            xSheet.Rows.AutoFit();
                            xSheet.Columns.AutoFit();
                            newWorksheet.Rows.AutoFit();
                            newWorksheet.Columns.AutoFit();
                            xSheet.get_Range(xSheet.Cells[1, 1], xSheet.Cells[1, 9]).MergeCells = true;
                            xSheet.get_Range(xSheet.Cells[1, 1], xSheet.Cells[1, 1]).Font.Size = 20;
                            xSheet.get_Range(xSheet.Cells[1, 1], xSheet.Cells[1, 1]).Font.Name = "黑体";
                            xSheet.get_Range(xSheet.Cells[1, 1], xSheet.Cells[1, 1]).HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
                            xSheet.get_Range(xSheet.Cells[5, 1], xSheet.Cells[5, 9]).Interior.ColorIndex = 45;
                            xSheet.get_Range(xSheet.Cells[6, 1], xSheet.Cells[xSheet.UsedRange.Rows.Count, 1]).Interior.ColorIndex = 6;
                            xSheet.get_Range(xSheet.Cells[6, 2], xSheet.Cells[xSheet.UsedRange.Rows.Count, 9]).NumberFormat = "0.0000_ ";
                            xSheet.get_Range(xSheet.Cells[3, 1], xSheet.Cells[xSheet.UsedRange.Rows.Count, 9]).Font.Name = "楷体_GB2312";

                            newWorksheet.get_Range(newWorksheet.Cells[1, 1], newWorksheet.Cells[1, 9]).MergeCells = true;
                            newWorksheet.get_Range(newWorksheet.Cells[1, 1], newWorksheet.Cells[1, 1]).Font.Size = 20;
                            newWorksheet.get_Range(newWorksheet.Cells[1, 1], newWorksheet.Cells[1, 1]).Font.Name = "黑体";
                            newWorksheet.get_Range(newWorksheet.Cells[1, 1], newWorksheet.Cells[1, 1]).HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
                            newWorksheet.get_Range(newWorksheet.Cells[5, 1], newWorksheet.Cells[5, 8]).Interior.ColorIndex = 45;
                            newWorksheet.get_Range(newWorksheet.Cells[6, 1], newWorksheet.Cells[newWorksheet.UsedRange.Rows.Count, 1]).Interior.ColorIndex = 6;
                            newWorksheet.get_Range(newWorksheet.Cells[6, 2], newWorksheet.Cells[newWorksheet.UsedRange.Rows.Count, 9]).NumberFormat = "0.0000_ ";
                            newWorksheet.get_Range(newWorksheet.Cells[3, 1], newWorksheet.Cells[newWorksheet.UsedRange.Rows.Count, 9]).Font.Name = "楷体_GB2312";

                            //op = new FileStream((System.Windows.Forms.Application.StartupPath + "\\fck.excel"), FileMode.OpenOrCreate);
                            //str1 = new StreamWriter(op, Encoding.GetEncoding("GB2312"));

                            string fn = tlVectorControl1.SVGDocument.FileName;

                            //result1.Save(System.Windows.Forms.Application.StartupPath + "\\fck.xls");

                            newWorksheet.SaveAs(System.Windows.Forms.Application.StartupPath + "\\" + fn + "高斯-赛德尔计算结果.xls", Excel.XlFileFormat.xlXMLSpreadsheet, null, null, false, false, false, null, null, null);

                            //str1.Write();
                            //op.Close();

                            System.Windows.Forms.Clipboard.Clear();
                            result1.Workbooks.Close();
                            result1.Quit();

                        }
                        catch (System.Exception e1)
                        {
                            MessageBox.Show("请进行潮流计算后再查看结果!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }

                        break;
                    case "N_RZYzResult":
                        try
                        {
                            if (!Check())
                            {
                                return;
                            }
                            ZYZ zyz = new ZYZ();
                            zyz.CurrentCal();
                            if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\" + tlVectorControl1.SVGDocument.FileName + "最优乘子法计算结果.xls"))
                            {
                                File.Delete(System.Windows.Forms.Application.StartupPath + "\\" + tlVectorControl1.SVGDocument.FileName + "最优乘子法计算结果.xls");
                                //OpenRead(System.Windows.Forms.Application.StartupPath + "\\" + tlVectorControl1.SVGDocument.FileName + ".xls");
                            }

                            double yinzi = 0, capability = 0, volt = 0, current = 0, Rad_to_Deg = 57.29577951;
                            PSPDEV benchmark = new PSPDEV();
                            benchmark.Type = "power";
                            benchmark.SvgUID = tlVectorControl1.SVGDocument.SvgdataUid;
                            IList list3 = Services.BaseService.GetList("SelectPSPDEVBySvgUIDAndType", benchmark);
                            if (list3 == null)
                            {
                                MessageBox.Show("请设置基准后再进行计算!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                return;
                            }
                            foreach (PSPDEV dev in list3)
                            {
                                yinzi = Convert.ToDouble(dev.PowerFactor);
                                capability = Convert.ToDouble(dev.StandardCurrent);
                                volt = Convert.ToDouble(dev.StandardVolt);
                                if (dev.PowerFactor == 0)
                                {
                                    yinzi = 1;
                                }
                                if (dev.StandardCurrent == 0)
                                {
                                    capability = 1;
                                }
                                if (dev.StandardVolt == 0)
                                {
                                    volt = 1;
                                }
                                current = capability / (Math.Sqrt(3) * volt);
                            }
                            if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\PF4.txt"))
                            {
                            }
                            else
                            {
                                return;
                            }
                            dh = new FileStream(System.Windows.Forms.Application.StartupPath + "\\PF4.txt", FileMode.Open);
                            readLine = new StreamReader(dh);

                            charSplit = new char[] { ' ' };
                            strLine = readLine.ReadLine();

                            output += ("全网母线(发电、负荷)结果报表 " + "\r\n" + "\r\n");
                            output += ("单位:kA\\kV\\MW\\Mvar" + "\r\n" + "\r\n");
                            output += ("母线名" + "," + "电压幅值" + "," + "电压相角" + "," + "有功发电" + "," + "无功发电" + "," + "有功负荷" + "," + "无功负荷" + "," + "越限标志" + "," + "过载标志" + "\r\n");
                            int count = 0;
                            while (strLine != null && strLine != "")
                            {
                                array1 = strLine.Split(charSplit);
                                string[] dev = new string[9];
                                dev.Initialize();
                                int i = 0;
                                count++;
                                PSPDEV CR = new PSPDEV();
                                CR.SvgUID = tlVectorControl1.SVGDocument.CurrentLayer.ID;

                                foreach (string str in array1)
                                {
                                    if (str != "")
                                    {
                                        if (str != "NaN")
                                        {
                                            dev[i++] = Convert.ToDouble(str).ToString();
                                        }
                                        else
                                        {
                                            dev[i++] = str;
                                        }

                                    }

                                }

                                CR.Number = Convert.ToInt32(dev[0]);
                                CR.Type = "Use";
                                CR = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByNumberAndSvgUIDAndType", CR);
                                double vTemp = Convert.ToDouble(dev[1]) * volt;
                                double vTemp1 = volt * 95 / 100;
                                double vTemp2 = volt * 105 / 100;

                                if (vTemp >= vTemp1 && vTemp <= vTemp2)
                                {
                                    dev[5] = "0";
                                }
                                else
                                {
                                    dev[5] = "1";
                                }
                                if (Convert.ToDouble(dev[3]) * capability > Convert.ToDouble(CR.Burthen))
                                {
                                    dev[6] = "1";
                                }
                                else
                                {
                                    dev[6] = "0";
                                }
                                if (Convert.ToDouble(dev[3]) < 0)
                                {

                                    output += CR.Name + "," + (Convert.ToDouble(dev[1]) * volt).ToString() + "," + (Convert.ToDouble(dev[2]) * Rad_to_Deg).ToString() + "," + "0" + "," + "0" + "," + (Convert.ToDouble(dev[3]) * capability).ToString() + "," + (Convert.ToDouble(dev[4]) * capability).ToString() + "," + dev[5] + "," + dev[6] + "\r\n";
                                }
                                else
                                {

                                    output += CR.Name + "," + (Convert.ToDouble(dev[1]) * volt).ToString() + "," + (Convert.ToDouble(dev[2]) * Rad_to_Deg).ToString() + "," + (Convert.ToDouble(dev[3]) * capability).ToString() + "," + (Convert.ToDouble(dev[4]) * capability).ToString() + "," + "0" + "," + "0" + "," + dev[5] + "," + dev[6] + "\r\n";
                                }
                                strLine = readLine.ReadLine();
                            }
                            PSPDEV ct = new PSPDEV();
                            ct.SvgUID = tlVectorControl1.SVGDocument.CurrentLayer.ID;
                            ct.Type = "Use";
                            IList cont = Services.BaseService.GetList("SelectPSPDEVBySvgUIDAndType", ct);
                            if (count < cont.Count)
                            {
                                MessageBox.Show("请进行潮流计算后再查看结果!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                readLine.Close();
                                return;

                            }
                            readLine.Close();
                            if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\result.csv"))
                            {
                                File.Delete(System.Windows.Forms.Application.StartupPath + "\\result.csv");
                            }
                            op = new FileStream((System.Windows.Forms.Application.StartupPath + "\\result.csv"), FileMode.OpenOrCreate);
                            str1 = new StreamWriter(op, Encoding.GetEncoding("GB2312"));
                            str1.Write(output);
                            str1.Close();

                            if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\DH4.txt"))
                            {
                            }
                            else
                            {
                                return;
                            }
                            if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\IH4.txt"))
                            {
                            }
                            else
                            {
                                return;
                            }
                            dh = new FileStream(System.Windows.Forms.Application.StartupPath + "\\DH4.txt", FileMode.Open);
                            dh2 = new FileStream(System.Windows.Forms.Application.StartupPath + "\\IH4.txt", FileMode.Open);
                            readLine2 = new StreamReader(dh2);
                            readLine = new StreamReader(dh);
                            charSplit = new char[] { ' ' };
                            strLine = readLine.ReadLine();
                            strLine2 = readLine2.ReadLine();

                            output = null;

                            output += ("全网交流线结果报表" + "\r\n" + "\r\n");
                            output += ("单位:kA\\kV\\MW\\Mvar" + "\r\n" + "\r\n");
                            output += ("支路名称" + "," + "支路有功" + "," + "支路无功" + "," + "有功损耗" + "," + "无功损耗" + "," + "电流幅值" + "," + "电流相角" + "," + "越限标志" + "," + "\r\n");
                            while (strLine != null && strLine2 != null && strLine != "" && strLine2 != "")
                            {
                                array1 = strLine.Split(charSplit);
                                array2 = strLine2.Split(charSplit2);

                                string[] dev = new string[20];
                                dev.Initialize();
                                int i = 0;
                                PSPDEV CR = new PSPDEV();
                                CR.SvgUID = tlVectorControl1.SVGDocument.CurrentLayer.ID;

                                foreach (string str in array1)
                                {
                                    if (str != "")
                                    {
                                        if (i == 0)
                                        {
                                            dev[i++] = str.ToString();
                                        }
                                        else
                                        {
                                            if (str != "NaN")
                                            {
                                                dev[i++] = Convert.ToDouble(str).ToString();
                                            }
                                            else
                                            {
                                                dev[i++] = str;
                                            }

                                        }
                                    }

                                }
                                i = 7;
                                for (int j = 3; j < 5; j++)
                                {
                                    if (array2[j] != "")
                                    {
                                        if (array2[j] != "NaN")
                                        {
                                            dev[i++] = Convert.ToDouble(array2[j]).ToString();
                                        }
                                        else
                                        {
                                            dev[i++] = array2[j];
                                        }
                                    }

                                }
                                CR.Name = dev[0];
                                CR.Type = "Polyline";
                                CR = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByName", CR);

                                if (CR != null)
                                {
                                    if (Convert.ToDouble(dev[7]) * current * 1000 > CR.LineChange)
                                    {
                                        dev[11] = "1";
                                    }
                                    else
                                    {
                                        dev[11] = "0";
                                    }
                                    output += CR.Name + "," + (Convert.ToDouble(dev[3]) * capability).ToString() + "," + (Convert.ToDouble(dev[4]) * capability).ToString() + "," + (Convert.ToDouble(dev[5]) * capability).ToString() + "," + (Convert.ToDouble(dev[6]) * capability).ToString() + "," + (Convert.ToDouble(dev[7]) * current).ToString() + "," + (Convert.ToDouble(dev[8]) * Rad_to_Deg).ToString() + "," + dev[11] + "," + "\r\n";
                                }
                                else
                                {
                                    CR = new PSPDEV();
                                    CR.Name = dev[0];
                                    CR.Type = "TransformLine";
                                    CR.SvgUID = tlVectorControl1.SVGDocument.CurrentLayer.ID;
                                    CR = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByName", CR);
                                    if (CR != null)
                                    {
                                        if (Convert.ToDouble(dev[7]) * current * 1000 > CR.LineChange)
                                        {
                                            dev[11] = "1";
                                        }
                                        else
                                        {
                                            dev[11] = "0";
                                        }
                                        output += CR.Name + "," + (Convert.ToDouble(dev[3]) * capability).ToString() + "," + (Convert.ToDouble(dev[4]) * capability).ToString() + "," + (Convert.ToDouble(dev[5]) * capability).ToString() + "," + (Convert.ToDouble(dev[6]) * capability).ToString() + "," + (Convert.ToDouble(dev[7]) * current).ToString() + "," + (Convert.ToDouble(dev[8]) * Rad_to_Deg).ToString() + "," + dev[11] + "," + "\r\n";
                                    }
                                }

                                strLine = readLine.ReadLine();
                                strLine2 = readLine2.ReadLine();
                            }
                            readLine.Close();
                            readLine2.Close();
                            if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\result1.csv"))
                            {
                                File.Delete(System.Windows.Forms.Application.StartupPath + "\\result1.csv");
                            }
                            op = new FileStream((System.Windows.Forms.Application.StartupPath + "\\result1.csv"), FileMode.OpenOrCreate);
                            str1 = new StreamWriter(op, Encoding.GetEncoding("GB2312"));
                            str1.Write(output);
                            str1.Close();

                            ex = new Excel.Application();
                            ex.Application.Workbooks.Add(System.Windows.Forms.Application.StartupPath + "\\result.csv");
                            xSheet = (Excel.Worksheet)ex.Worksheets[1];
                            ex.Worksheets.Add(System.Reflection.Missing.Value, xSheet, 1, System.Reflection.Missing.Value);

                            result1 = new Excel.Application();
                            result1.Application.Workbooks.Add(System.Windows.Forms.Application.StartupPath + "\\result1.csv");
                            tempSheet = (Excel.Worksheet)result1.Worksheets.get_Item(1);
                            newWorksheet = (Excel.Worksheet)ex.Worksheets.get_Item(2);
                            newWorksheet.Name = "线路电流";
                            xSheet.Name = "母线潮流";
                            ex.Visible = true;

                            tempSheet.Cells.Select();
                            tempSheet.Cells.Copy(System.Reflection.Missing.Value);
                            newWorksheet.Paste(System.Reflection.Missing.Value, System.Reflection.Missing.Value);
                            xSheet.Rows.AutoFit();
                            xSheet.Columns.AutoFit();
                            newWorksheet.Rows.AutoFit();
                            newWorksheet.Columns.AutoFit();
                            xSheet.get_Range(xSheet.Cells[1, 1], xSheet.Cells[1, 9]).MergeCells = true;
                            xSheet.get_Range(xSheet.Cells[1, 1], xSheet.Cells[1, 1]).Font.Size = 20;
                            xSheet.get_Range(xSheet.Cells[1, 1], xSheet.Cells[1, 1]).Font.Name = "黑体";
                            xSheet.get_Range(xSheet.Cells[1, 1], xSheet.Cells[1, 1]).HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
                            xSheet.get_Range(xSheet.Cells[5, 1], xSheet.Cells[5, 9]).Interior.ColorIndex = 45;
                            xSheet.get_Range(xSheet.Cells[6, 1], xSheet.Cells[xSheet.UsedRange.Rows.Count, 1]).Interior.ColorIndex = 6;
                            xSheet.get_Range(xSheet.Cells[6, 2], xSheet.Cells[xSheet.UsedRange.Rows.Count, 9]).NumberFormat = "0.0000_ ";
                            xSheet.get_Range(xSheet.Cells[3, 1], xSheet.Cells[xSheet.UsedRange.Rows.Count, 9]).Font.Name = "楷体_GB2312";

                            newWorksheet.get_Range(newWorksheet.Cells[1, 1], newWorksheet.Cells[1, 9]).MergeCells = true;
                            newWorksheet.get_Range(newWorksheet.Cells[1, 1], newWorksheet.Cells[1, 1]).Font.Size = 20;
                            newWorksheet.get_Range(newWorksheet.Cells[1, 1], newWorksheet.Cells[1, 1]).Font.Name = "黑体";
                            newWorksheet.get_Range(newWorksheet.Cells[1, 1], newWorksheet.Cells[1, 1]).HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
                            newWorksheet.get_Range(newWorksheet.Cells[5, 1], newWorksheet.Cells[5, 8]).Interior.ColorIndex = 45;
                            newWorksheet.get_Range(newWorksheet.Cells[6, 1], newWorksheet.Cells[newWorksheet.UsedRange.Rows.Count, 1]).Interior.ColorIndex = 6;
                            newWorksheet.get_Range(newWorksheet.Cells[6, 2], newWorksheet.Cells[newWorksheet.UsedRange.Rows.Count, 9]).NumberFormat = "0.0000_ ";
                            newWorksheet.get_Range(newWorksheet.Cells[3, 1], newWorksheet.Cells[newWorksheet.UsedRange.Rows.Count, 9]).Font.Name = "楷体_GB2312";

                            //op = new FileStream((System.Windows.Forms.Application.StartupPath + "\\fck.excel"), FileMode.OpenOrCreate);
                            //str1 = new StreamWriter(op, Encoding.GetEncoding("GB2312"));

                            string fn = tlVectorControl1.SVGDocument.FileName;

                            //result1.Save(System.Windows.Forms.Application.StartupPath + "\\fck.xls");

                            newWorksheet.SaveAs(System.Windows.Forms.Application.StartupPath + "\\" + fn + "最优乘子法计算结果.xls", Excel.XlFileFormat.xlXMLSpreadsheet, null, null, false, false, false, null, null, null);

                            //str1.Write();
                            //op.Close();

                            System.Windows.Forms.Clipboard.Clear();
                            result1.Workbooks.Close();
                            result1.Quit();

                        }
                        catch (System.Exception e1)
                        {
                            MessageBox.Show("请进行潮流计算后再查看结果!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }

                        break;
                    case "VoltEvaluation":
                        PspVoltEvaluation();
                        break;
                    case "PowerLoss":
                        try
                        {
                            PSPDEV _dev = new PSPDEV();
                            _dev.SvgUID = tlVectorControl1.SVGDocument.CurrentLayer.ID;
                            _dev.Type = "Polyline";
                            IList list = Services.BaseService.GetList("SelectPSPDEVBySvgUIDAndType", _dev);
                            for (int i = 0; i < list.Count; i++)
                            {
                                PSPDEV _pp = (PSPDEV)list[i];
                                if (_pp.BigP == 0)
                                {
                                    MessageBox.Show("请设置线路" + _pp.Name + "的建设投资。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                    return;
                                }
                            }
                            if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\DH1.txt"))
                            {
                            }
                            else
                            {
                                return;
                            }
                            dh = new FileStream(System.Windows.Forms.Application.StartupPath + "\\DH1.txt", FileMode.Open);
                            readLine = new StreamReader(dh);
                            charSplit = new char[] { ' ' };
                            strLine = readLine.ReadLine();
                            output = null;
                            output += ("全网交流线结果报表" + "\r\n" + "\r\n");
                            output += ("单位:kA\\kV\\MW\\Mvar" + "\r\n" + "\r\n");
                            output += ("支路名称" + "," + "支路有功" + "," + "支路无功" + "," + "有功损耗" + "," + "无功损耗" + "\r\n");
                            while (strLine != null)
                            {
                                array1 = strLine.Split(charSplit);
                                string[] dev = new string[9];
                                dev.Initialize();
                                int i = 0;
                                PSPDEV CR = new PSPDEV();
                            }
                        }
                        catch (System.Exception e1)
                        {
                            MessageBox.Show("请进行潮流计算后再查看结果!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }

                        break;
                    case "ZLPResult1":
                        if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\DH1.txt"))
                        {
                        }
                        else
                        {
                            return;
                        }
                        dh = new FileStream(System.Windows.Forms.Application.StartupPath + "\\DH1.txt", FileMode.Open);
                        readLine = new StreamReader(dh);
                        charSplit = new char[] { ' ' };
                        strLine = readLine.ReadLine();
                        output = null;
                        output += ("全网交流线结果报表" + "\r\n" + "\r\n");
                        output += ("单位:kA\\kV\\MW\\Mvar" + "\r\n" + "\r\n");
                        output += ("支路名称" + "," + "支路有功" + "," + "支路无功" + "," + "有功损耗" + "," + "无功损耗" + "\r\n");
                        while (strLine != null)
                        {
                            array1 = strLine.Split(charSplit);
                            string[] dev = new string[9];
                            dev.Initialize();
                            int i = 0;
                            PSPDEV CR = new PSPDEV();
                            CR.SvgUID = tlVectorControl1.SVGDocument.CurrentLayer.ID;

                            foreach (string str in array1)
                            {
                                if (str != "")
                                {
                                    if (str != "NaN")
                                    {
                                        dev[i++] = Convert.ToDouble(str).ToString();
                                    }
                                    else
                                    {
                                        dev[i++] = str;
                                    }

                                }

                            }
                            CR.Number = Convert.ToInt32(dev[0]);
                            CR.Type = "Polyline";
                            CR = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByNumberAndSvgUIDAndType", CR);
                            output += CR.Name + "," + dev[3] + "," + dev[4] + "," + dev[5] + "," + dev[6] + "\r\n";
                            strLine = readLine.ReadLine();
                        }
                        readLine.Close();
                        if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\result.csv"))
                        {
                            File.Delete(System.Windows.Forms.Application.StartupPath + "\\result.csv");
                        }
                        op = new FileStream((System.Windows.Forms.Application.StartupPath + "\\result.csv"), FileMode.OpenOrCreate);
                        str1 = new StreamWriter(op, Encoding.GetEncoding("GB2312"));
                        str1.Write(output);
                        str1.Close();

                        ex = new Excel.Application();
                        ex.Application.Workbooks.Add(System.Windows.Forms.Application.StartupPath + "\\result.csv");
                        ex.Visible = true;

                        break;

                    case "ZLAResult1":

                        if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\IH1.txt"))
                        {
                        }
                        else
                        {
                            return;
                        }
                        dh = new FileStream(System.Windows.Forms.Application.StartupPath + "\\IH1.txt", FileMode.Open);
                        readLine = new StreamReader(dh);
                        charSplit = new char[] { ' ' };
                        strLine = readLine.ReadLine();
                        output = null;

                        output += ("支路名称" + "," + "电流幅值" + "," + "电流相角" + "," + "越限标志" + "\r\n");
                        while (strLine != null)
                        {
                            array1 = strLine.Split(charSplit);
                            string[] dev = new string[9];
                            dev.Initialize();
                            int i = 0;
                            PSPDEV CR = new PSPDEV();
                            CR.SvgUID = tlVectorControl1.SVGDocument.CurrentLayer.ID;

                            foreach (string str in array1)
                            {
                                if (str != "")
                                {
                                    if (str != "NaN")
                                    {
                                        dev[i++] = Convert.ToDouble(str).ToString();
                                    }
                                    else
                                    {
                                        dev[i++] = str;
                                    }

                                }

                            }
                            CR.Number = Convert.ToInt32(dev[0]);
                            CR.Type = "Polyline";
                            CR = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByNumberAndSvgUIDAndType", CR);
                            output += CR.Name + "," + dev[3] + "," + dev[4] + "," + dev[5] + "\r\n";
                            strLine = readLine.ReadLine();
                        }
                        readLine.Close();
                        if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\result.csv"))
                        {
                            File.Delete(System.Windows.Forms.Application.StartupPath + "\\result.csv");
                        }
                        op = new FileStream((System.Windows.Forms.Application.StartupPath + "\\result.csv"), FileMode.OpenOrCreate);
                        str1 = new StreamWriter(op, Encoding.GetEncoding("GB2312"));
                        str1.Write(output);
                        str1.Close();

                        ex = new Excel.Application();
                        ex.Application.Workbooks.Add(System.Windows.Forms.Application.StartupPath + "\\result.csv");
                        ex.Visible = true;

                        break;

                    case "PQResult":
                        try
                        {
                            if (!CheckPQ())
                            {
                                return;
                            }
                            PQ_PowerFlowCalClass pq = new PQ_PowerFlowCalClass();
                            pq.CurrentCal();
                            if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\" + tlVectorControl1.SVGDocument.FileName + "PQ法计算结果.xls"))
                            {
                                //System.Diagnostics.Process.Start(System.Windows.Forms.Application.StartupPath + "\\" + tlVectorControl1.SVGDocument.FileName + "PQ法计算结果.xls");
                                File.Delete(System.Windows.Forms.Application.StartupPath + "\\" + tlVectorControl1.SVGDocument.FileName + "PQ法计算结果.xls");

                            }
                            double yinzi = 0, capability = 0, volt = 0, current = 0, Rad_to_Deg = 57.29577951;
                            PSPDEV benchmark = new PSPDEV();
                            benchmark.Type = "power";
                            benchmark.SvgUID = tlVectorControl1.SVGDocument.SvgdataUid;
                            IList list3 = Services.BaseService.GetList("SelectPSPDEVBySvgUIDAndType", benchmark);
                            if (list3 == null)
                            {
                                MessageBox.Show("请设置基准后再进行计算!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                return;
                            }
                            foreach (PSPDEV dev in list3)
                            {
                                yinzi = Convert.ToDouble(dev.PowerFactor);
                                capability = Convert.ToDouble(dev.StandardCurrent);
                                volt = Convert.ToDouble(dev.StandardVolt);
                                if (dev.PowerFactor == 0)
                                {
                                    yinzi = 1;
                                }
                                if (dev.StandardCurrent == 0)
                                {
                                    capability = 1;
                                }
                                if (dev.StandardVolt == 0)
                                {
                                    volt = 1;
                                }
                                current = capability / (Math.Sqrt(3) * volt);

                            }
                            if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\PF2.txt"))
                            {
                            }
                            else
                            {
                                return;
                            }
                            dh = new FileStream(System.Windows.Forms.Application.StartupPath + "\\PF2.txt", FileMode.Open);
                            readLine = new StreamReader(dh);

                            charSplit = new char[] { ' ' };
                            strLine = readLine.ReadLine();
                            output = null;
                            int count = 0;
                            output += ("全网母线(发电、负荷)结果报表 " + "\r\n" + "\r\n");
                            output += ("单位:kA\\kV\\MW\\Mvar" + "\r\n" + "\r\n");
                            output += ("母线名" + "," + "电压幅值" + "," + "电压相角" + "," + "有功发电" + "," + "无功发电" + "," + "有功负荷" + "," + "无功负荷" + "," + "越限标志" + "," + "过载标志" + "\r\n");
                            while (strLine != null && strLine != "")
                            {
                                array1 = strLine.Split(charSplit);
                                string[] dev = new string[9];
                                dev.Initialize();
                                int i = 0;
                                count++;
                                PSPDEV CR = new PSPDEV();
                                CR.SvgUID = tlVectorControl1.SVGDocument.CurrentLayer.ID;

                                foreach (string str in array1)
                                {
                                    if (str != "")
                                    {
                                        if (str != "NaN")
                                        {
                                            dev[i++] = Convert.ToDouble(str).ToString();
                                        }
                                        else
                                        {
                                            dev[i++] = str;
                                        }

                                    }

                                }

                                CR.Number = Convert.ToInt32(dev[0]);
                                CR.Type = "Use";
                                CR = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByNumberAndSvgUIDAndType", CR);
                                double vTemp = Convert.ToDouble(dev[1]) * volt;
                                double vTemp1 = volt * 95 / 100;
                                double vTemp2 = volt * 105 / 100;

                                if (vTemp >= vTemp1 && vTemp <= vTemp2)
                                {
                                    dev[5] = "0";
                                }
                                else
                                {
                                    dev[5] = "1";
                                }
                                if (Convert.ToDouble(dev[3]) * capability > Convert.ToDouble(CR.Burthen))
                                {
                                    dev[6] = "1";
                                }
                                else
                                {
                                    dev[6] = "0";
                                }
                                if (Convert.ToDouble(dev[3]) < 0)
                                {

                                    output += CR.Name + "," + (Convert.ToDouble(dev[1]) * volt).ToString() + "," + (Convert.ToDouble(dev[2])).ToString() + "," + "0" + "," + "0" + "," + (Convert.ToDouble(dev[3]) * capability).ToString() + "," + (Convert.ToDouble(dev[4]) * capability).ToString() + "," + dev[5] + "," + dev[6] + "\r\n";
                                }
                                else
                                {

                                    output += CR.Name + "," + (Convert.ToDouble(dev[1]) * volt).ToString() + "," + (Convert.ToDouble(dev[2])).ToString() + "," + (Convert.ToDouble(dev[3]) * capability).ToString() + "," + (Convert.ToDouble(dev[4]) * capability).ToString() + "," + "0" + "," + "0" + "," + dev[5] + "," + dev[6] + "\r\n";
                                }
                                strLine = readLine.ReadLine();
                            }
                            PSPDEV ct = new PSPDEV();
                            ct.SvgUID = tlVectorControl1.SVGDocument.CurrentLayer.ID;
                            ct.Type = "Use";
                            IList cont = Services.BaseService.GetList("SelectPSPDEVBySvgUIDAndType", ct);
                            if (count < cont.Count)
                            {
                                MessageBox.Show("请进行潮流计算后再查看结果!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                readLine.Close();
                                return;

                            }
                            readLine.Close();

                            if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\result.csv"))
                            {
                                File.Delete(System.Windows.Forms.Application.StartupPath + "\\result.csv");
                            }
                            op = new FileStream((System.Windows.Forms.Application.StartupPath + "\\result.csv"), FileMode.OpenOrCreate);
                            str1 = new StreamWriter(op, Encoding.GetEncoding("GB2312"));
                            str1.Write(output);
                            str1.Close();

                            if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\DH2.txt"))
                            {
                            }
                            else
                            {
                                return;
                            }
                            if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\IH2.txt"))
                            {
                            }
                            else
                            {
                                return;
                            }
                            dh = new FileStream(System.Windows.Forms.Application.StartupPath + "\\DH2.txt", FileMode.Open);
                            dh2 = new FileStream(System.Windows.Forms.Application.StartupPath + "\\IH2.txt", FileMode.Open);
                            readLine2 = new StreamReader(dh2);

                            readLine = new StreamReader(dh);
                            charSplit = new char[] { ' ' };
                            strLine = readLine.ReadLine();
                            charSplit2 = new char[] { ' ' };
                            strLine2 = readLine2.ReadLine();
                            output = null;
                            output += ("全网交流线结果报表" + "\r\n" + "\r\n");
                            output += ("单位:kA\\kV\\MW\\Mvar" + "\r\n" + "\r\n");
                            output += ("支路名称" + "," + "支路有功" + "," + "支路无功" + "," + "有功损耗" + "," + "无功损耗" + "," + "电流幅值" + "," + "电流相角" + "," + "越限标志" + "," + "\r\n");
                            while (strLine != null && strLine2 != null && strLine != "" && strLine2 != "")
                            {
                                array1 = strLine.Split(charSplit);
                                array2 = strLine2.Split(charSplit2);

                                string[] dev = new string[20];
                                dev.Initialize();
                                int i = 0;
                                PSPDEV CR = new PSPDEV();
                                CR.SvgUID = tlVectorControl1.SVGDocument.CurrentLayer.ID;

                                foreach (string str in array1)
                                {
                                    if (str != "")
                                    {
                                        if (i == 0)
                                        {
                                            dev[i++] = str.ToString();
                                        }
                                        else
                                        {
                                            if (str != "NaN")
                                            {
                                                dev[i++] = Convert.ToDouble(str).ToString();
                                            }
                                            else
                                            {
                                                dev[i++] = str;
                                            }

                                        }
                                    }

                                }
                                i = 7;
                                for (int j = 3; j < 5; j++)
                                {
                                    if (array2[j] != "")
                                    {
                                        if (array2[j] != "NaN")
                                        {
                                            dev[i++] = Convert.ToDouble(array2[j]).ToString();
                                        }
                                        else
                                        {
                                            dev[i++] = array2[j];
                                        }
                                    }

                                }
                                CR.Name = dev[0];
                                CR.Type = "Polyline";
                                CR = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByName", CR);

                                if (CR != null)
                                {
                                    if (Convert.ToDouble(dev[7]) * current * 1000 > CR.LineChange)
                                    {
                                        dev[11] = "1";
                                    }
                                    else
                                    {
                                        dev[11] = "0";
                                    }
                                    output += CR.Name + "," + (Convert.ToDouble(dev[3]) * capability).ToString() + "," + (Convert.ToDouble(dev[4]) * capability).ToString() + "," + (Convert.ToDouble(dev[5]) * capability).ToString() + "," + (Convert.ToDouble(dev[6]) * capability).ToString() + "," + (Convert.ToDouble(dev[7]) * current).ToString() + "," + (Convert.ToDouble(dev[8]) * Rad_to_Deg).ToString() + "," + dev[11] + "," + "\r\n";
                                }
                                else
                                {
                                    CR = new PSPDEV();
                                    CR.Name = dev[0];
                                    CR.Type = "TransformLine";
                                    CR.SvgUID = tlVectorControl1.SVGDocument.CurrentLayer.ID;
                                    CR = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByName", CR);
                                    if (CR != null)
                                    {
                                        if (Convert.ToDouble(dev[7]) * current * 1000 > CR.LineChange)
                                        {
                                            dev[11] = "1";
                                        }
                                        else
                                        {
                                            dev[11] = "0";
                                        }
                                        output += CR.Name + "," + (Convert.ToDouble(dev[3]) * capability).ToString() + "," + (Convert.ToDouble(dev[4]) * capability).ToString() + "," + (Convert.ToDouble(dev[5]) * capability).ToString() + "," + (Convert.ToDouble(dev[6]) * capability).ToString() + "," + (Convert.ToDouble(dev[7]) * current).ToString() + "," + (Convert.ToDouble(dev[8]) * Rad_to_Deg).ToString() + "," + dev[11] + "," + "\r\n";
                                    }
                                }

                                strLine = readLine.ReadLine();
                                strLine2 = readLine2.ReadLine();
                            }
                            readLine.Close();
                            readLine2.Close();

                            if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\result1.csv"))
                            {
                                File.Delete(System.Windows.Forms.Application.StartupPath + "\\result1.csv");
                            }
                            op = new FileStream((System.Windows.Forms.Application.StartupPath + "\\result1.csv"), FileMode.OpenOrCreate);
                            str1 = new StreamWriter(op, Encoding.GetEncoding("GB2312"));
                            str1.Write(output);
                            str1.Close();

                            Excel.Application ex2 = new Excel.Application();
                            ex2.Application.Workbooks.Add(System.Windows.Forms.Application.StartupPath + "\\result.csv");
                            Excel.Worksheet xSheet2 = (Excel.Worksheet)ex2.Worksheets[1];
                            ex2.Worksheets.Add(System.Reflection.Missing.Value, xSheet2, 1, System.Reflection.Missing.Value);

                            Excel.Application result11 = new Excel.Application();
                            result11.Application.Workbooks.Add(System.Windows.Forms.Application.StartupPath + "\\result1.csv");
                            Excel.Application result12 = new Excel.Application();

                            Excel.Worksheet tempSheet11 = (Excel.Worksheet)result11.Worksheets.get_Item(1);

                            Excel.Worksheet newWorksheet11 = (Excel.Worksheet)ex2.Worksheets.get_Item(2);

                            newWorksheet11.Name = "线路电流";
                            xSheet2.Name = "母线潮流";

                            ex2.Visible = true;
                            tempSheet11.Cells.Select();
                            tempSheet11.Cells.Copy(System.Reflection.Missing.Value);
                            newWorksheet11.Paste(System.Reflection.Missing.Value, System.Reflection.Missing.Value);
                            xSheet2.Rows.AutoFit();
                            xSheet2.Columns.AutoFit();
                            newWorksheet11.Rows.AutoFit();
                            newWorksheet11.Columns.AutoFit();

                            xSheet2.get_Range(xSheet2.Cells[1, 1], xSheet2.Cells[1, 9]).MergeCells = true;
                            xSheet2.get_Range(xSheet2.Cells[1, 1], xSheet2.Cells[1, 1]).Font.Size = 20;
                            xSheet2.get_Range(xSheet2.Cells[1, 1], xSheet2.Cells[1, 1]).Font.Name = "黑体";
                            xSheet2.get_Range(xSheet2.Cells[1, 1], xSheet2.Cells[1, 1]).HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
                            xSheet2.get_Range(xSheet2.Cells[5, 1], xSheet2.Cells[5, 9]).Interior.ColorIndex = 45;
                            xSheet2.get_Range(xSheet2.Cells[6, 1], xSheet2.Cells[xSheet2.UsedRange.Rows.Count, 1]).Interior.ColorIndex = 6;
                            xSheet2.get_Range(xSheet2.Cells[6, 2], xSheet2.Cells[xSheet2.UsedRange.Rows.Count, 9]).NumberFormat = "0.0000_ ";
                            xSheet2.get_Range(xSheet2.Cells[3, 1], xSheet2.Cells[xSheet2.UsedRange.Rows.Count, 9]).Font.Name = "楷体_GB2312";

                            newWorksheet11.get_Range(newWorksheet11.Cells[1, 1], newWorksheet11.Cells[1, 9]).MergeCells = true;
                            newWorksheet11.get_Range(newWorksheet11.Cells[1, 1], newWorksheet11.Cells[1, 1]).Font.Size = 20;
                            newWorksheet11.get_Range(newWorksheet11.Cells[1, 1], newWorksheet11.Cells[1, 1]).Font.Name = "黑体";
                            newWorksheet11.get_Range(newWorksheet11.Cells[1, 1], newWorksheet11.Cells[1, 1]).HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
                            newWorksheet11.get_Range(newWorksheet11.Cells[5, 1], newWorksheet11.Cells[5, 8]).Interior.ColorIndex = 45;
                            newWorksheet11.get_Range(newWorksheet11.Cells[6, 1], newWorksheet11.Cells[newWorksheet11.UsedRange.Rows.Count, 1]).Interior.ColorIndex = 6;
                            newWorksheet11.get_Range(newWorksheet11.Cells[6, 2], newWorksheet11.Cells[newWorksheet11.UsedRange.Rows.Count, 9]).NumberFormat = "0.0000_ ";
                            newWorksheet11.get_Range(newWorksheet11.Cells[3, 1], newWorksheet11.Cells[newWorksheet11.UsedRange.Rows.Count, 9]).Font.Name = "楷体_GB2312";

                            string fn = tlVectorControl1.SVGDocument.FileName;

                            //result1.Save(System.Windows.Forms.Application.StartupPath + "\\fck.xls");

                            newWorksheet11.SaveAs(System.Windows.Forms.Application.StartupPath + "\\" + fn + "PQ法计算结果.xls", Excel.XlFileFormat.xlXMLSpreadsheet, null, null, false, false, false, null, null, null);

                            System.Windows.Forms.Clipboard.Clear();

                            result11.Workbooks.Close();
                            result11.Quit();

                        }
                        catch (System.Exception e3)
                        {
                            MessageBox.Show("请进行潮流计算后再查看结果!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }

                        break;

                    case "mDLR":

                        if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\result.txt"))
                        {
                        }
                        else
                        {
                            return;
                        }
                        int ij = 1;
                        dh = new FileStream(System.Windows.Forms.Application.StartupPath + "\\result.txt", FileMode.Open);
                        readLine = new StreamReader(dh);

                        charSplit = new char[] { ' ' };
                        strLine = readLine.ReadLine();
                        output = null;

                        FileStream dh5 = new FileStream(System.Windows.Forms.Application.StartupPath + "\\dlb.txt", FileMode.Open);
                        StreamReader readLine5 = new StreamReader(dh5);
                        string strLine5;
                        string[] array5;
                        char[] charSplit5 = new char[] { ' ' };
                        strLine5 = readLine5.ReadLine();
                        array5 = strLine5.Split(charSplit5);

                        output += ("全网短路计算结果报表" + "\r\n" + "\r\n");

                        PSPDEV CR235 = new PSPDEV();
                        CR235.SvgUID = tlVectorControl1.SVGDocument.CurrentLayer.ID;
                        CR235.Number = Convert.ToInt32(array5[0]);
                        CR235.Type = array5[1];
                        double ibb = 0;
                        double temp11 = 0;
                        CR235 = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByNumberAndSvgUIDAndType", CR235);

                        if (CR235 == null)
                        {
                            MessageBox.Show("错误!当前图元与结果报表不符!");
                            readLine.Close();
                            readLine5.Close();
                            return;
                        }
                        output += ("短路点" + ":" + " " + CR235.Name + "   " + "故障类型" + ":" + " " + array5[2] + "\r\n" + "\r\n");

                        output += ("名称" + "," + "零序电流" + "," + "正序电流" + "," + "负序电流" + "," + "A相电流" + "," + "B相电流" + "," + "C相电流" + "," + "短路电流" + "," + "短路容量" + "," + "\r\n");
                        while (strLine != null)
                        {
                            array1 = strLine.Split(charSplit);
                            string[] dev = new string[9];
                            dev.Initialize();
                            int i = 0;
                            PSPDEV CR2 = new PSPDEV();
                            CR2.SvgUID = tlVectorControl1.SVGDocument.CurrentLayer.ID;
                            foreach (string str in array1)
                            {
                                if (str != "")
                                {
                                    if (str != "NaN")
                                    {
                                        dev[i++] = Convert.ToDouble(str).ToString();
                                    }
                                    else
                                    {
                                        dev[i++] = str;
                                    }

                                }

                            }

                            //CR2.Number = Convert.ToInt32(dev[2]);
                            //CR2.Type = "Use";
                            //CR2 = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByNumberAndSvgUIDAndType", CR2);
                            CR2.Number = Convert.ToInt32(array5[0]);
                            CR2.Type = array5[1];
                            string nodeName = CR2.Name;

                            CR2 = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByNumberAndSvgUIDAndType", CR2);
                            int vr = Convert.ToInt32(CR2.VoltR);

                            switch (vr)
                            {
                                case 220:
                                    {
                                        ibb = 251.03;
                                        for (int j = 3; j < 9; j++)
                                        {
                                            temp11 = Convert.ToDouble(dev[j]) * ibb * 0.001;
                                            dev[j] = temp11.ToString();
                                        }
                                        ibb = Convert.ToDouble(dev[4]) * 3;
                                        temp11 = 1.732 * ibb * 230;

                                    }
                                    break;
                                case 500:
                                    {
                                        ibb = 104.98;
                                        for (int j = 3; j < 9; j++)
                                        {
                                            temp11 = Convert.ToDouble(dev[j]) * ibb * 0.001;
                                            dev[j] = temp11.ToString();
                                        }
                                        ibb = Convert.ToDouble(dev[4]) * 3;
                                        temp11 = 1.732 * ibb * 550;

                                    }
                                    break;
                                default:
                                    { }
                                    break;
                            }
                            if (ij == 1)
                            {
                                output += CR2.Name + "," + dev[3] + "," + dev[4] + "," + dev[5] + "," + dev[6] + "," + dev[7] + "," + dev[8] + "," + ibb.ToString() + "," + temp11.ToString() + "," + "\r\n";
                            }
                            else
                            {
                                CR2.Number = Convert.ToInt32(dev[2]);

                                CR2.Type = "Polyline";
                                CR2 = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByNumberAndSvgUIDAndType", CR2);

                                //output += CR2.Name + "," + dev[3] + "," + dev[4] + "," + dev[5] + "," + dev[6] + "," + dev[7] + "," + dev[8] + "\r\n";
                                if (CR2 != null)
                                {
                                    output += CR2.Name + "," + dev[3] + "," + dev[4] + "," + dev[5] + "," + dev[6] + "," + dev[7] + "," + dev[8] + "\r\n";
                                }
                                else if (dev[2] == "500")
                                {
                                    output += nodeName + "故障生成线路" + "," + dev[3] + "," + dev[4] + "," + dev[5] + "," + dev[6] + "," + dev[7] + "," + dev[8] + "\r\n";
                                }
                            }
                            ij = 0;
                            strLine = readLine.ReadLine();
                        }
                        readLine.Close();
                        readLine5.Close();
                        if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\result.csv"))
                        {
                            File.Delete(System.Windows.Forms.Application.StartupPath + "\\result.csv");
                        }
                        op = new FileStream((System.Windows.Forms.Application.StartupPath + "\\result.csv"), FileMode.OpenOrCreate);
                        str1 = new StreamWriter(op, Encoding.GetEncoding("GB2312"));
                        str1.Write(output);
                        str1.Close();

                        ex = new Excel.Application();
                        ex.Application.Workbooks.Add(System.Windows.Forms.Application.StartupPath + "\\result.csv");
                        //ex.Visible = true;

                        //Excel.Application ex = new Excel.Application();

                        ex.Application.Workbooks.Add(System.Windows.Forms.Application.StartupPath + "\\result.csv");
                        xSheet = (Excel.Worksheet)ex.Worksheets[1];
                        //ex.Worksheets.Add(System.Reflection.Missing.Value, xSheet, 1, System.Reflection.Missing.Value);

                        //result1 = new Excel.Application();
                        //result1.Application.Workbooks.Add(System.Windows.Forms.Application.StartupPath + "\\result1.csv");
                        //tempSheet = (Excel.Worksheet)result1.Worksheets.get_Item(1);
                        //Excel.Worksheet newWorksheet = (Excel.Worksheet)ex.Worksheets.get_Item(2);
                        //newWorksheet.Name = "线路电流";
                        xSheet.Name = "短路计算";

                        //tempSheet.Cells.Select();
                        //tempSheet.Cells.Copy(System.Reflection.Missing.Value);
                        //newWorksheet.Paste(System.Reflection.Missing.Value, System.Reflection.Missing.Value);

                        xSheet.get_Range(xSheet.Cells[1, 1], xSheet.Cells[1, 9]).MergeCells = true;
                        xSheet.get_Range(xSheet.Cells[1, 1], xSheet.Cells[1, 1]).Font.Size = 20;
                        xSheet.get_Range(xSheet.Cells[1, 1], xSheet.Cells[1, 1]).Font.Name = "黑体";
                        xSheet.get_Range(xSheet.Cells[1, 1], xSheet.Cells[1, 1]).HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;

                        xSheet.get_Range(xSheet.Cells[3, 1], xSheet.Cells[3, 1]).Font.Name = "楷体_GB2312";

                        xSheet.get_Range(xSheet.Cells[5, 1], xSheet.Cells[5, 9]).Interior.ColorIndex = 45;

                        xSheet.get_Range(xSheet.Cells[6, 1], xSheet.Cells[xSheet.UsedRange.Rows.Count, 1]).Interior.ColorIndex = 6;
                        xSheet.get_Range(xSheet.Cells[8, 2], xSheet.Cells[xSheet.UsedRange.Rows.Count, 9]).NumberFormat = "0.0000_ ";
                        xSheet.get_Range(xSheet.Cells[5, 1], xSheet.Cells[xSheet.UsedRange.Rows.Count, 9]).Font.Name = "楷体_GB2312";

                        System.Windows.Forms.Clipboard.Clear();
                        //result1.Workbooks.Close();
                        //result1.Quit();
                        ex.Visible = true;
                        break;

                    case "mEnclosure":
                        tlVectorControl1.Operation = ToolOperation.Enclosure;

                        break;

                    case "mGroup":
                        tlVectorControl1.Group();
                        break;
                    case "mUnGroup":
                        tlVectorControl1.UnGroup();
                        break;
                    case "mlinelx":
                        tlVectorControl1.Operation = ToolOperation.ConnectLine_Line;
                        break;
                    case "mzxlx":
                        tlVectorControl1.Operation = ToolOperation.ConnectLine_Rightangle;
                        break;
                    case "mqxlx":
                        tlVectorControl1.Operation = ToolOperation.ConnectLine_Spline;
                        break;
                    case "mqzlx":
                        tlVectorControl1.Operation = ToolOperation.ConnectLine_Polyline;
                        break;
                    case "mCJ1":
                        tlVectorControl1.Operation = ToolOperation.PolyLine;
                        csOperation = CustomOperation.OP_MeasureDistance;
                        break;
                    case "powerFactor":
                        PSPDEV pspDev21 = new PSPDEV();

                        //pspDev2.SUID = Guid.NewGuid().ToString();
                        pspDev21.Type = "Power";
                        pspDev21.SvgUID = tlVectorControl1.SVGDocument.SvgdataUid;
                        pspDev21 = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVBySvgUIDAndType", pspDev21);
                        if (pspDev21 != null)
                        {
                        }
                        else
                        {
                            pspDev21 = new PSPDEV();
                            pspDev21.SUID = Guid.NewGuid().ToString();
                            pspDev21.Type = "Power";
                            pspDev21.SvgUID = tlVectorControl1.SVGDocument.SvgdataUid;
                            Services.BaseService.Create<PSPDEV>(pspDev21);
                        }
                        powerf ppz = new powerf(pspDev21);
                        if (ppz.ShowDialog() == DialogResult.OK)
                        {
                            pspDev21.PowerFactor = Convert.ToDouble(ppz.powerfactor);
                            pspDev21.StandardVolt = Convert.ToDouble(ppz.standardvolt);
                            pspDev21.StandardCurrent = Convert.ToDouble(ppz.standardcurrent);
                            pspDev21.BigP = Convert.ToDouble(ppz.bigP);
                            Services.BaseService.Update<PSPDEV>(pspDev21);
                            PSPDEV voltall = new PSPDEV();
                            voltall.Type = "Use";
                            voltall.Lable = "电厂";
                            voltall.SvgUID = tlVectorControl1.SVGDocument.CurrentLayer.ID;
                            IList allvolt = Services.BaseService.GetList("SelectPSPDEVBySvgUIDandLableandType", voltall);
                            foreach (PSPDEV dev in allvolt)
                            {
                                dev.OutP = Convert.ToDouble(dev.Burthen) * pspDev21.BigP;
                                //dev.InPutP=dev.Burthen*pspDev2.BigP;
                                dev.OutQ = dev.OutP * Math.Tan(Math.Acos(pspDev21.PowerFactor));
                                Services.BaseService.Update<PSPDEV>(dev);
                            }
                            voltall.Lable = "变电站";
                            allvolt = Services.BaseService.GetList("SelectPSPDEVBySvgUIDandLableandType", voltall);
                            foreach (PSPDEV dev in allvolt)
                            {
                                dev.InPutP = Convert.ToDouble(dev.Burthen) * pspDev21.BigP;
                                //dev.InPutP=dev.Burthen*pspDev2.BigP;
                                dev.InPutQ = dev.InPutP * pspDev21.BigP * Math.Tan(Math.Acos(pspDev21.PowerFactor));
                                Services.BaseService.Update<PSPDEV>(dev);
                            }

                        }

                        break;
                    //if (=null)
                    //{

                    #endregion

                    #region 视图
                    case "mLayer":
                        frmlar.Show();
                        break;
                    case "mOption":
                        tlVectorControl1.SetOption();
                        break;
                    case "mAirscape":
                        frmAirscape fAir = new frmAirscape();
                        fAir.InitData(tlVectorControl1);
                        fAir.Owner = this;
                        fAir.ShowInTaskbar = false;
                        fAir.Top = Screen.PrimaryScreen.WorkingArea.Height - 250;
                        fAir.Left = Screen.PrimaryScreen.WorkingArea.Width - 300;
                        fAir.Show();
                        break;
                    case "btTL":
                        frmGlebeTypeList fgle = new frmGlebeTypeList();
                        fgle.Show();
                        break;
                    #endregion

                    #region 布局,对齐,顺序
                    case "mRotate":
                        if (btItem.Tag is ButtonItem)
                        {
                            btItem = btItem.Tag as ButtonItem;
                            tlVectorControl1.FlipX();

                        }
                        else
                        {
                            tlVectorControl1.FlipX();
                        }
                        break;
                    case "mToH":

                        tlVectorControl1.FlipX();
                        //this.rotateButton.Tag = btItem;
                        //this.rotateButton.ImageIndex = btItem.ImageIndex;
                        break;
                    case "mToV":
                        tlVectorControl1.FlipY();
                        //this.rotateButton.Tag = btItem;
                        //this.rotateButton.ImageIndex = btItem.ImageIndex;
                        break;
                    case "mToLeft":
                        tlVectorControl1.RotateSelection(-90f);
                        ////this.rotateButton.Tag = btItem;
                        ////this.rotateButton.ImageIndex = btItem.ImageIndex;
                        break;
                    case "mToRight":
                        tlVectorControl1.RotateSelection(90f);
                        //this.rotateButton.Tag = btItem;
                        //this.rotateButton.ImageIndex = btItem.ImageIndex;
                        break;
                    case "mAlign":
                        if (btItem.Tag is ButtonItem)
                        {
                            btItem = btItem.Tag as ButtonItem;
                            tlVectorControl1.Align(AlignType.Left);

                        }
                        else
                        {
                            tlVectorControl1.Align(AlignType.Left);

                        }
                        tlVectorControl1.Refresh();
                        break;
                    case "mAlignLeft":
                        tlVectorControl1.Align(AlignType.Left);
                        this.alignButton.ImageIndex = btItem.ImageIndex;
                        this.alignButton.Tag = btItem;
                        tlVectorControl1.Refresh();
                        break;
                    case "mAlignRight":
                        tlVectorControl1.Align(AlignType.Right);
                        this.alignButton.ImageIndex = btItem.ImageIndex;
                        this.alignButton.Tag = btItem;
                        tlVectorControl1.Refresh();
                        break;
                    case "mAlignTop":
                        tlVectorControl1.Align(AlignType.Top);
                        this.alignButton.ImageIndex = btItem.ImageIndex;
                        this.alignButton.Tag = btItem;
                        tlVectorControl1.Refresh();
                        break;
                    case "mAlignBottom":
                        tlVectorControl1.Align(AlignType.Bottom);
                        this.alignButton.ImageIndex = btItem.ImageIndex;
                        this.alignButton.Tag = btItem;
                        tlVectorControl1.Refresh();
                        break;
                    case "mAlignHorizontalCenter":
                        tlVectorControl1.Align(AlignType.HorizontalCenter);
                        this.alignButton.ImageIndex = btItem.ImageIndex;
                        this.alignButton.Tag = btItem;
                        tlVectorControl1.Refresh();
                        break;
                    case "mAlignVerticalCenter":
                        tlVectorControl1.Align(AlignType.VerticalCenter);
                        this.alignButton.ImageIndex = btItem.ImageIndex;
                        this.alignButton.Tag = btItem;
                        tlVectorControl1.Refresh();
                        break;
                    case "mOrder":
                        if (btItem.Tag is ButtonItem)
                        {
                            btItem = btItem.Tag as ButtonItem;
                            tlVectorControl1.ChangeLevel(LevelType.Top);

                        }
                        else
                        {
                            tlVectorControl1.ChangeLevel(LevelType.Top);
                        }

                        break;
                    case "mGoTop":
                        tlVectorControl1.ChangeLevel(LevelType.Top);
                        this.orderButton.Tag = btItem;
                        this.orderButton.ImageIndex = btItem.ImageIndex;
                        break;
                    case "mGoUp":
                        tlVectorControl1.ChangeLevel(LevelType.Up);
                        this.orderButton.Tag = btItem;
                        this.orderButton.ImageIndex = btItem.ImageIndex;
                        break;
                    case "mGoDown":
                        tlVectorControl1.ChangeLevel(LevelType.Down);
                        this.orderButton.Tag = btItem;
                        this.orderButton.ImageIndex = btItem.ImageIndex;
                        break;
                    case "mGoBottom":
                        tlVectorControl1.ChangeLevel(LevelType.Bottom);
                        this.orderButton.Tag = btItem;
                        this.orderButton.ImageIndex = btItem.ImageIndex;
                        break;
                    #endregion
                    #region 图元操作
                    case "mCopy":
                        tlVectorControl1.Copy();
                        break;
                    case "mCut":
                        tlVectorControl1.Cut();
                        break;
                    case "mPaste":
                        tlVectorControl1.Paste();
                        break;
                    case "mDelete":
                        if (tlVectorControl1.SVGDocument.CurrentElement is SVG)
                        {
                        }
                        else
                        {
                            if (MessageBox.Show("确定要删除么?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                            {
                                SvgElementCollection collection = tlVectorControl1.SVGDocument.SelectCollection;
                                foreach (XmlElement element in collection)
                                {
                                    PSPDEV pspDev = new PSPDEV();
                                    pspDev.EleID = element.GetAttribute("id");
                                    pspDev.SvgUID = tlVectorControl1.SVGDocument.CurrentLayer.ID;
                                    pspDev = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVBySvgUIDandEleID", pspDev);
                                    Services.BaseService.Delete<PSPDEV>(pspDev);
                                }
                                tlVectorControl1.Delete();
                            }

                        }
                        break;
                    case "mUodo":
                        tlVectorControl1.Undo();
                        break;
                    case "mRedo":
                        tlVectorControl1.Redo();
                        break;
                    #endregion
                    #region 业务操作

                    case "mXLine":
                        tlVectorControl1.Operation = ToolOperation.Select;
                        tlVectorControl1.Operation = ToolOperation.XPolyLine;
                        break;
                    case "mYLine":
                        tlVectorControl1.Operation = ToolOperation.Select;
                        tlVectorControl1.Operation = ToolOperation.YPolyLine;
                        break;

                    case "mSaveGroup":
                        if (tlVectorControl1.SVGDocument.SelectCollection.Count > 1)
                        {
                            string content = "<svg>";
                            SvgElementCollection col = tlVectorControl1.SVGDocument.SelectCollection;
                            for (int i = 0; i < col.Count; i++)
                            {
                                SvgElement _e = (SvgElement)col[i];
                                if (_e.ID != "svg")
                                {
                                    content = content + _e.OuterXml;
                                }
                            }
                            RectangleF rect = tlVectorControl1.DrawArea.viewer.SelectedViewRectangle;

                            content = content + "</svg>";
                            frmSaveGroup fm = new frmSaveGroup();
                            fm.rect = rect;
                            fm.Content = content;
                            fm.ShowDialog();
                        }
                        else
                        {
                            MessageBox.Show("请至少选择2个图元。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return;
                        }
                        break;

                    case "mInsert":
                        frmUseGroup fg = new frmUseGroup();
                        if (fg.ShowDialog() == DialogResult.OK)
                        {
                            UseGroup u = fg.SelectedUseGroup;
                            if (u != null)
                            {
                                frmXY xy = new frmXY();
                                if (xy.ShowDialog() == DialogResult.OK)
                                {
                                    decimal x = xy.GetX();
                                    decimal y = xy.GetY();
                                    string content = u.Content;
                                    XmlDocument doc = new XmlDocument();
                                    doc.LoadXml(u.Content);
                                    XmlNodeList list = doc.ChildNodes;
                                    XmlNode _node = list[0];
                                    XmlNodeList sonlist = _node.ChildNodes;
                                    XmlElement ele = tlVectorControl1.SVGDocument.CreateElement("g");
                                    ele.SetAttribute("layer", SvgDocument.currentLayer);
                                    for (int i = 0; i < sonlist.Count; i++)
                                    {
                                        XmlNode _sonnode = sonlist[i];
                                        //string str = _sonnode.OuterXml;
                                        if (_sonnode.Name == "use")
                                        {
                                            string sid = ((XmlElement)_sonnode).GetAttribute("xlink:href");
                                            XmlNode _snode = symbolSelector.SymbolDoc.SelectSingleNode("//*[@id='" + sid.Substring(1) + "']");
                                            tlVectorControl1.SVGDocument.AddDefsElement((SvgElement)_snode);
                                        }
                                        ele.AppendChild(_sonnode);
                                        string ss = ele.OuterXml;
                                    }
                                    //RectangleF r=((Group)ele).GetBounds();
                                    string tr = "matrix(1,0,0,1,";

                                    tr = tr + Convert.ToString(x - Convert.ToDecimal(u.X)) + ",";
                                    tr = tr + Convert.ToString(y - Convert.ToDecimal(u.Y)) + ")";

                                    ele.SetAttribute("transform", tr);
                                    // transform="matrix(1,0,0,1,2558.82,-352.94)"
                                    tlVectorControl1.SVGDocument.RootElement.AppendChild(ele);
                                    tlVectorControl1.SVGDocument.SelectCollection.Clear();
                                    tlVectorControl1.SVGDocument.SelectCollection.Add((SvgElement)ele);
                                    tlVectorControl1.UnGroup();
                                    // tlVectorControl1.Refresh();
                                }
                            }
                        }
                        break;
                    #endregion
                    #region 参数维护
                    case "mNodeParam":
                        frmNodeParam dlgNodeParam = new frmNodeParam(tlVectorControl1.SVGDocument.CurrentLayer.ID);
                        dlgNodeParam.ShowDialog();
                        break;
                    case "mLineParam":
                        frmLineParamWJ dlgLineParam = new frmLineParamWJ(tlVectorControl1.SVGDocument.CurrentLayer.ID);
                        dlgLineParam.ShowDialog();
                        break;
                    case "mWire":
                        wireTypeParam wirewire = new wireTypeParam();
                        wirewire.ShowDialog();
                        break;
                    case "nTransformLineParam":
                        frmTransformLineParam frmTransfor = new frmTransformLineParam(tlVectorControl1.SVGDocument.CurrentLayer.ID);
                        frmTransfor.ShowDialog();
                        break;
                    case "nGNDLineParam":
                        break;
                    case "mLineDL":
                        frmLineParamDL dlgLineParamDL = new frmLineParamDL(tlVectorControl1.SVGDocument.CurrentLayer.ID);
                        dlgLineParamDL.ShowDialog();
                        break;
                    case "mFadianDL":
                        frmFadejieDL dlgFadeDL = new frmFadejieDL(tlVectorControl1.SVGDocument.CurrentLayer.ID);
                        dlgFadeDL.ShowDialog();
                        break;
                    case "mTest":
                        tlVectorControl1.Operation = ToolOperation.AreaSelect;
                        break;
                    case "mjianLine":

                        if (tlVectorControl1.SVGDocument.CurrentLayer.ID == tlVectorControl1.SVGDocument.SvgdataUid + "4")
                        {
                            zhengtiflag = true;
                            jiqiflag = false;
                            zhongqiflag = false;
                            yuanqiflag = false;
                            jianxiancheck();

                            MessageBox.Show("整体数据减线成功。");
                            Topology2();             //颜色发生变化
                        }
                        if (tlVectorControl1.SVGDocument.CurrentLayer.ID == tlVectorControl1.SVGDocument.SvgdataUid + "1" && zhengtiflag)
                        {
                            jiqiflag = true;
                            zhengtiflag = false;
                            zhongqiflag = false;
                            yuanqiflag = false;
                            jianxiancheck();

                            MessageBox.Show("近期数据减线成功。");
                            Topology2();             //颜色发生变化
                        }
                        if (tlVectorControl1.SVGDocument.CurrentLayer.ID == tlVectorControl1.SVGDocument.SvgdataUid + "2" && jiqiflag)
                        {
                            zhongqiflag = true;
                            jiqiflag = false;
                            yuanqiflag = false;
                            jianxiancheck();

                            MessageBox.Show("中期数据减线成功。");
                            Topology2();             //颜色发生变化
                        }
                        if (tlVectorControl1.SVGDocument.CurrentLayer.ID == tlVectorControl1.SVGDocument.SvgdataUid + "3" && zhongqiflag)
                        {
                            yuanqiflag = true;
                            jiqiflag = false;
                            zhongqiflag = false;
                            jianxiancheck();

                            MessageBox.Show("远期数据减线成功,请查看结果");
                            Topology2();             //颜色发生变化
                        }
                        if (!zhengtiflag && !jiqiflag && !zhongqiflag && !yuanqiflag)
                        {
                            string msg2 = "减线法:\r\n 1、选中整体图层进行网架优化。\r\n 2、将整体图层拷贝到近期图层,然后选中近期图层进行网架优化。\r\n 3、拷贝到中期图层,然后选中中期图层进行网架优化\r\n 4、拷贝到远期图层,然后选中远期图层进行网架优化。";
                            MessageBox.Show(msg2, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        }
                        break;
                    case "mjiaLine":

                        if (tlVectorControl1.SVGDocument.CurrentLayer.ID == tlVectorControl1.SVGDocument.SvgdataUid + "4")
                        {

                            MessageBox.Show("整体图层采用的是减线法!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            break;
                        }
                        if (tlVectorControl1.SVGDocument.CurrentLayer.ID == tlVectorControl1.SVGDocument.SvgdataUid + "1" && zhengtiflag)
                        {
                            jiqiflag = true;
                            zhengtiflag = false;
                            zhongqiflag = false;
                            yuanqiflag = false;
                            addlinecheck();
                            addrightcheck();
                            for (int i = 0; i < ercilinedengdai.Count; i++)
                            {
                                ercilinedengdai[i].LineStatus = "运行";
                                Services.BaseService.Update<PSPDEV>(ercilinedengdai[i]);
                            }
                            for (int i = 0; i < lineyiyou.Count; i++)
                            {
                                lineyiyou[i].LineStatus = "待选";
                                Services.BaseService.Update<PSPDEV>(lineyiyou[i]);
                            }
                            MessageBox.Show("近期数据加线成功。");
                            Topology2();             //颜色发生变化
                        }
                        if (tlVectorControl1.SVGDocument.CurrentLayer.ID == tlVectorControl1.SVGDocument.SvgdataUid + "2" && jiqiflag)
                        {
                            zhongqiflag = true;
                            jiqiflag = false;
                            yuanqiflag = false;
                            addlinecheck();
                            addrightcheck();
                            for (int i = 0; i < ercilinedengdai.Count; i++)
                            {
                                ercilinedengdai[i].LineStatus = "运行";
                                Services.BaseService.Update<PSPDEV>(ercilinedengdai[i]);
                            }
                            for (int i = 0; i < lineyiyou.Count; i++)
                            {
                                lineyiyou[i].LineStatus = "待选";
                                Services.BaseService.Update<PSPDEV>(lineyiyou[i]);
                            }
                            MessageBox.Show("中期数据加线成功。");
                            Topology2();             //颜色发生变化
                        }
                        if (tlVectorControl1.SVGDocument.CurrentLayer.ID == tlVectorControl1.SVGDocument.SvgdataUid + "3" && zhongqiflag)
                        {
                            yuanqiflag = true;
                            jiqiflag = false;
                            zhongqiflag = false;
                            addlinecheck();
                            addrightcheck();
                            for (int i = 0; i < ercilinedengdai.Count; i++)
                            {
                                ercilinedengdai[i].LineStatus = "运行";
                                Services.BaseService.Update<PSPDEV>(ercilinedengdai[i]);
                            }
                            for (int i = 0; i < lineyiyou.Count; i++)
                            {
                                lineyiyou[i].LineStatus = "待选";
                                Services.BaseService.Update<PSPDEV>(lineyiyou[i]);
                            }
                            MessageBox.Show("远期数据加线成功。请查看优化结果");
                            Topology2();             //颜色发生变化
                        }
                        if (!zhengtiflag && !jiqiflag && !zhongqiflag && !yuanqiflag)
                        {
                            string msg2 = "加线法:\r\n 1、选中整体图层进行网架优化,此时采用的是减线法。\r\n 2、将整体图层拷贝到近期图层,然后选中近期图层进行网架优化。\r\n 3、拷贝到中期图层,然后选中中期图层进行网架优化\r\n 4、拷贝到远期图层,然后选中远期图层进行网架优化。";
                            MessageBox.Show(msg2, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            break;
                        }
                        break;

                    case "YhResult":       //优化结果
                        if (yuanqiflag)
                        {
                            frmGProList p1 = new frmGProList();
                            p1.Show();
                            p1.LoadData(LoadData());
                        }
                        else
                            MessageBox.Show("请依次做完各个时期的优化,再看结果!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        break;
                    #endregion
                    #region 参数维护
                    case "m_in":
                        if (tlVectorControl1.SVGDocument.CurrentLayer.ID != tlVectorControl1.SVGDocument.SvgdataUid + "5")
                        {
                            MessageBox.Show("请选择背景参考层。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return;
                        }

                        StringBuilder txt = new StringBuilder("<?xml version=\"1.0\" encoding=\"utf-8\"?><svg id=\"svg\" width=\"1500\" height=\"1000\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:itop=\"http://www.Itop.com/itop\" transform=\"matrix(1 0 0 1 0 1)\"><defs>");
                        StringBuilder Allcontent = new StringBuilder();
                        string svgdefs = "";
                        string layertxt = "";

                        frmLayerSel sel = new frmLayerSel();
                        if (sel.ShowDialog() == DialogResult.OK)
                        {
                            ArrayList tlist = sel.LayList;
                            SVG_SYMBOL sym = new SVG_SYMBOL();
                            sym.svgID = oldsid;
                            IList<SVG_SYMBOL> symlist = Services.BaseService.GetList<SVG_SYMBOL>("SelectSVG_SYMBOLBySvgID", sym);
                            foreach (SVG_SYMBOL _sym in symlist)
                            {
                                svgdefs = svgdefs + _sym.XML;
                            }
                            txt.Append(svgdefs + "</defs>");
                            for (int i = 0; i < tlist.Count; i++)
                            {
                                SVG_LAYER lar = new SVG_LAYER();
                                lar.svgID = oldsid;
                                lar.SUID = ((SVG_LAYER)tlist[i]).SUID;
                                lar = (SVG_LAYER)Services.BaseService.GetObject("SelectSVG_LAYERByKey", lar);
                                layertxt = layertxt + "<layer id=\"" + lar.SUID + "\" label=\"" + lar.NAME + "\" layerType=\"" + lar.layerType + "\" visibility=\"" + lar.visibility + "\" ParentID=\"" + lar.YearID + "\" IsSelect=\"" + lar.IsSelect + "\" />";
                                Allcontent.Append(lar.XML);
                            }
                            txt.Append(layertxt);
                            txt.Append(Allcontent.ToString() + "</svg>");
                            SvgDocument document = new SvgDocument();
                            document.LoadXml(txt.ToString());
                            document.SvgdataUid = oldsid;
                            XmlNodeList xlist = document.SelectNodes("svg/polyline [@IsLead='1']");
                            for (int i = 0; i < xlist.Count; i++)
                            {
                                SvgElement gra = xlist[i] as SvgElement;
                                gra.SetAttribute("layer", tlVectorControl1.SVGDocument.SvgdataUid + "5");
                                ((IGraph)gra).Layer = tlVectorControl1.SVGDocument.CurrentLayer;
                                tlVectorControl1.SVGDocument.RootElement.AppendChild((XmlNode)gra);

                            }
                            XmlNodeList xlist2 = document.SelectNodes("svg/use");
                            for (int i = 0; i < xlist2.Count; i++)
                            {
                                SvgElement gra = xlist2[i] as SvgElement;
                                gra.SetAttribute("layer", tlVectorControl1.SVGDocument.SvgdataUid + "5");
                                ((IGraph)gra).Layer = tlVectorControl1.SVGDocument.CurrentLayer;
                                tlVectorControl1.SVGDocument.RootElement.AppendChild((XmlNode)gra);

                            }
                            tlVectorControl1.Refresh();
                            MessageBox.Show("导入数据成功。");
                        }

                        break;
                    case "m_1to2"://近期

                        //删除掉原来元素

                        deltall(tlVectorControl1.SVGDocument.SvgdataUid + "1");
                        //********
                        ArrayList sel_line1 = new ArrayList();
                        LayerGrade l1 = new LayerGrade();
                        l1.Type = "1";
                        l1.SvgDataUid = oldsid;
                        IList ttlist = Services.BaseService.GetList("SelectLayerGradeList5", l1);
                        if (ttlist.Count > 0)
                        {
                            LayerGrade n1 = (LayerGrade)ttlist[0];
                            try
                            {
                                int yy = Convert.ToInt32(n1.Name.Substring(0, 4));
                                XmlNodeList list1to2 = tlVectorControl1.SVGDocument.SelectNodes("svg/use [@layer='" + tlVectorControl1.SVGDocument.SvgdataUid + "4" + "' and @year<='" + yy + "']");
                                for (int i = 0; i < list1to2.Count; i++)
                                {
                                    SvgElement gra = list1to2[i] as SvgElement;

                                    XmlNode temp = gra.Clone();
                                    ((SvgElement)temp).SetAttribute("layer", tlVectorControl1.SVGDocument.SvgdataUid + "1");
                                    XmlNode newnode = tlVectorControl1.SVGDocument.RootElement.AppendChild((XmlNode)temp);
                                    //加入节点的名称

                                    XmlNode text = tlVectorControl1.SVGDocument.SelectSingleNode("svg/*[@ParentID='" + gra.GetAttribute("id") + "']");
                                    XmlNode textemp = text.Clone();
                                    ((SvgElement)textemp).SetAttribute("layer", tlVectorControl1.SVGDocument.SvgdataUid + "1");
                                    ((SvgElement)textemp).SetAttribute("ParentID", ((SvgElement)temp).GetAttribute("id"));
                                    tlVectorControl1.SVGDocument.RootElement.AppendChild((XmlNode)textemp);
                                    PSPDEV pspDev = new PSPDEV();
                                    pspDev.EleID = gra.ID;
                                    pspDev.SvgUID = tlVectorControl1.SVGDocument.SvgdataUid + "4";
                                    pspDev = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVBySvgUIDandEleID", pspDev);
                                    if (pspDev != null)
                                    {
                                        pspDev.SUID = Guid.NewGuid().ToString();
                                        pspDev.EleID = ((SvgElement)newnode).ID;
                                        pspDev.SvgUID = tlVectorControl1.SVGDocument.SvgdataUid + "1";
                                        Services.BaseService.Create<PSPDEV>(pspDev);
                                    }
                                }
                                XmlNodeList listline = tlVectorControl1.SVGDocument.SelectNodes("svg/polyline [@layer='" + tlVectorControl1.SVGDocument.SvgdataUid + "4']");
                                //for (int i = 0; i < list1to2.Count; i++)
                                //{
                                //    SvgElement temp = list1to2[i] as SvgElement;
                                //    RectangleF ff = ((IGraph)temp).GetBounds();
                                //    Region r = new Region(((IGraph)temp).GetBounds());
                                //    for (int j = 0; j < listline.Count;j++ )
                                //    {
                                //        Polyline pln = listline[j] as Polyline;
                                //        if (r.IsVisible(pln.Points[0]))
                                //        {
                                //            if (!sel_line1.Contains(pln))
                                //            {
                                //                sel_line1.Add(pln);
                                //            }

                                //        }
                                //    }

                                //}
                                for (int i = 0; i < listline.Count; i++)
                                {
                                    bool firstnodeflag = false; bool lastnodeflag = false;
                                    Polyline pln = listline[i] as Polyline;
                                    PSPDEV psp = new PSPDEV();
                                    psp.SvgUID = tlVectorControl1.SVGDocument.SvgdataUid + "4";
                                    psp.EleID = pln.ID;
                                    psp = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVBySvgUIDandEleID", psp);
                                    if (psp.LineStatus != "等待")
                                    {
                                        for (int j = 0; j < list1to2.Count; j++)
                                        {
                                            SvgElement temp = list1to2[j] as SvgElement;
                                            Region ff = new Region(((IGraph)temp).GetBounds());
                                            if (ff.IsVisible(pln.Points[0]))
                                            {
                                                firstnodeflag = true;
                                            }
                                            if (ff.IsVisible(pln.Points[1]))
                                            {
                                                lastnodeflag = true;
                                            }
                                        }
                                        if (firstnodeflag && lastnodeflag && !sel_line1.Contains(pln))
                                        {
                                            sel_line1.Add(pln);
                                        }

                                    }

                                }
                                for (int i = 0; i < sel_line1.Count; i++)
                                {
                                    SvgElement gra = sel_line1[i] as SvgElement;

                                    XmlNode temp = gra.Clone();
                                    ((SvgElement)temp).SetAttribute("layer", tlVectorControl1.SVGDocument.SvgdataUid + "1");
                                    XmlNode newnode = tlVectorControl1.SVGDocument.RootElement.AppendChild((XmlNode)temp);
                                    PSPDEV pspDev = new PSPDEV();
                                    pspDev.EleID = gra.ID;
                                    pspDev.SvgUID = tlVectorControl1.SVGDocument.SvgdataUid + "4";
                                    pspDev = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVBySvgUIDandEleID", pspDev);
                                    if (pspDev != null)
                                    {
                                        pspDev.SUID = Guid.NewGuid().ToString();
                                        pspDev.EleID = ((SvgElement)newnode).ID;
                                        pspDev.SvgUID = tlVectorControl1.SVGDocument.SvgdataUid + "1";
                                        Services.BaseService.Create<PSPDEV>(pspDev);
                                    }
                                }
                                MessageBox.Show("数据处理成功。");
                                Topology2();             //颜色发生变化
                            }
                            catch
                            {
                                MessageBox.Show("选择的年份前4位不是数字。");
                            }
                        }
                        break;
                    case "m_2to3"://中期
                        deltall(tlVectorControl1.SVGDocument.SvgdataUid + "2");
                        ArrayList sel_line2 = new ArrayList();
                        LayerGrade l1_2 = new LayerGrade();
                        l1_2.Type = "1";
                        l1_2.SvgDataUid = oldsid;
                        l1_2 = (LayerGrade)Services.BaseService.GetObject("SelectLayerGradeList5", l1_2);
                        LayerGrade l2_2 = new LayerGrade();
                        l2_2.Type = "2";
                        l2_2.SvgDataUid = oldsid;
                        l2_2 = (LayerGrade)Services.BaseService.GetObject("SelectLayerGradeList5", l2_2);
                        if (l1_2 != null && l2_2 != null)
                        {

                            try
                            {
                                //整体规划层里的中期数据

                                int yy1 = Convert.ToInt32(l1_2.Name.Substring(0, 4));
                                int yy2 = Convert.ToInt32(l2_2.Name.Substring(0, 4));

                                XmlNodeList list1to2 = tlVectorControl1.SVGDocument.SelectNodes("svg/use [@layer='" + tlVectorControl1.SVGDocument.SvgdataUid + "4" + "' and @year>'" + yy1 + "' and @year<='" + yy2 + "']");
                                for (int i = 0; i < list1to2.Count; i++)
                                {
                                    SvgElement gra = list1to2[i] as SvgElement;
                                    XmlNode temp = gra.Clone();
                                    ((SvgElement)temp).SetAttribute("layer", tlVectorControl1.SVGDocument.SvgdataUid + "2");
                                    XmlNode newnode = tlVectorControl1.SVGDocument.RootElement.AppendChild((XmlNode)temp);
                                    //加入节点的名称

                                    XmlNode text = tlVectorControl1.SVGDocument.SelectSingleNode("svg/*[@ParentID='" + gra.GetAttribute("id") + "']");
                                    XmlNode textemp = text.Clone();
                                    ((SvgElement)textemp).SetAttribute("layer", tlVectorControl1.SVGDocument.SvgdataUid + "2");
                                    ((SvgElement)textemp).SetAttribute("ParentID", ((SvgElement)temp).GetAttribute("id"));
                                    tlVectorControl1.SVGDocument.RootElement.AppendChild((XmlNode)textemp);
                                    PSPDEV pspDev = new PSPDEV();
                                    pspDev.EleID = gra.ID;
                                    pspDev.SvgUID = tlVectorControl1.SVGDocument.SvgdataUid + "4";
                                    pspDev = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVBySvgUIDandEleID", pspDev);
                                    if (pspDev != null)
                                    {
                                        pspDev.SUID = Guid.NewGuid().ToString();
                                        pspDev.EleID = ((SvgElement)newnode).ID;
                                        pspDev.SvgUID = tlVectorControl1.SVGDocument.SvgdataUid + "2";
                                        Services.BaseService.Create<PSPDEV>(pspDev);
                                    }
                                }

                                XmlNodeList listline2 = tlVectorControl1.SVGDocument.SelectNodes("svg/polyline [@layer='" + tlVectorControl1.SVGDocument.SvgdataUid + "4']");
                                XmlNodeList list1to1 = tlVectorControl1.SVGDocument.SelectNodes("svg/use [@layer='" + tlVectorControl1.SVGDocument.SvgdataUid + "4" + "' and @year<='" + yy1 + "']");
                                for (int i = 0; i < listline2.Count; i++)
                                {
                                    bool firstnodeflag = false; bool lastnodeflag = false; bool jinqifirstnodeflag = false; bool jinqilastnodeflag = false;
                                    Polyline pln = listline2[i] as Polyline;
                                    PSPDEV psp = new PSPDEV();
                                    psp.SvgUID = tlVectorControl1.SVGDocument.SvgdataUid + "4";
                                    psp.EleID = pln.ID;
                                    psp = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVBySvgUIDandEleID", psp);
                                    if (psp.LineStatus != "等待")
                                    {
                                        for (int j = 0; j < list1to2.Count; j++)
                                        {
                                            SvgElement temp = list1to2[j] as SvgElement;
                                            Region ff = new Region(((IGraph)temp).GetBounds());
                                            if (ff.IsVisible(pln.Points[0]))
                                            {
                                                firstnodeflag = true;
                                            }
                                            if (ff.IsVisible(pln.Points[1]))
                                            {
                                                lastnodeflag = true;
                                            }
                                        }
                                        for (int j = 0; j < list1to1.Count; j++)
                                        {
                                            SvgElement temp = list1to1[j] as SvgElement;
                                            Region ff = new Region(((IGraph)temp).GetBounds());
                                            if (ff.IsVisible(pln.Points[0]))
                                            {
                                                jinqifirstnodeflag = true;
                                            }
                                            if (ff.IsVisible(pln.Points[1]))
                                            {
                                                jinqilastnodeflag = true;
                                            }
                                        }
                                        if (firstnodeflag && lastnodeflag && !sel_line2.Contains(pln))
                                        {
                                            sel_line2.Add(pln);
                                        }
                                        if (firstnodeflag && jinqilastnodeflag && !sel_line2.Contains(pln))
                                        {
                                            sel_line2.Add(pln);
                                        }
                                        if (lastnodeflag && jinqifirstnodeflag && !sel_line2.Contains(pln))
                                        {
                                            sel_line2.Add(pln);
                                        }

                                    }

                                }
                                for (int i = 0; i < sel_line2.Count; i++)
                                {
                                    SvgElement gra = sel_line2[i] as SvgElement;

                                    XmlNode temp = gra.Clone();
                                    ((SvgElement)temp).SetAttribute("layer", tlVectorControl1.SVGDocument.SvgdataUid + "2");
                                    XmlNode newnode = tlVectorControl1.SVGDocument.RootElement.AppendChild((XmlNode)temp);
                                    PSPDEV pspDev = new PSPDEV();
                                    pspDev.EleID = gra.ID;
                                    pspDev.SvgUID = tlVectorControl1.SVGDocument.SvgdataUid + "4";
                                    pspDev = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVBySvgUIDandEleID", pspDev);
                                    if (pspDev != null)
                                    {
                                        pspDev.SUID = Guid.NewGuid().ToString();
                                        pspDev.EleID = ((SvgElement)newnode).ID;
                                        pspDev.SvgUID = tlVectorControl1.SVGDocument.SvgdataUid + "2";
                                        Services.BaseService.Create<PSPDEV>(pspDev);
                                    }
                                }
                                //近期数据
                                XmlNodeList list_1 = tlVectorControl1.SVGDocument.SelectNodes("svg/* [@layer='" + tlVectorControl1.SVGDocument.SvgdataUid + "1']");
                                for (int i = 0; i < list_1.Count; i++)
                                {
                                    SvgElement gra = list_1[i] as SvgElement;
                                    XmlNode temp = gra.Clone();
                                    ((SvgElement)temp).SetAttribute("layer", tlVectorControl1.SVGDocument.SvgdataUid + "2");
                                    XmlNode newnode = tlVectorControl1.SVGDocument.RootElement.AppendChild((XmlNode)temp);
                                    //加入节点的名称

                                    XmlNode text = tlVectorControl1.SVGDocument.SelectSingleNode("svg/*[@ParentID='" + gra.GetAttribute("id") + "']");
                                    if (text != null)
                                    {
                                        XmlNode textemp = text.Clone();
                                        ((SvgElement)textemp).SetAttribute("layer", tlVectorControl1.SVGDocument.SvgdataUid + "2");
                                        ((SvgElement)textemp).SetAttribute("ParentID", ((SvgElement)temp).GetAttribute("id"));
                                        tlVectorControl1.SVGDocument.RootElement.AppendChild((XmlNode)textemp);
                                    }

                                    PSPDEV pspDev = new PSPDEV();
                                    pspDev.EleID = gra.ID;
                                    pspDev.SvgUID = tlVectorControl1.SVGDocument.SvgdataUid + "1";
                                    pspDev = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVBySvgUIDandEleID", pspDev);
                                    if (pspDev != null)
                                    {
                                        pspDev.SUID = Guid.NewGuid().ToString();
                                        pspDev.EleID = ((SvgElement)newnode).ID;
                                        pspDev.SvgUID = tlVectorControl1.SVGDocument.SvgdataUid + "2";
                                        if (pspDev.LineStatus == "待选")
                                        {
                                            pspDev.LineStatus = "运行";
                                        }
                                        if (pspDev.LineStatus == "等待")
                                        {
                                            pspDev.LineStatus = "待选";
                                        }
                                        Services.BaseService.Create<PSPDEV>(pspDev);
                                    }
                                }
                                MessageBox.Show("数据处理成功。");
                                Topology2();             //颜色发生变化
                            }
                            catch
                            {
                                MessageBox.Show("选择的年份前4位不是数字。");
                            }
                        }
                        break;
                    case "m_3to4"://远期
                        deltall(tlVectorControl1.SVGDocument.SvgdataUid + "3");
                        ArrayList sel_line3 = new ArrayList();
                        LayerGrade l1_3 = new LayerGrade();
                        l1_3.Type = "2";
                        l1_3.SvgDataUid = oldsid;
                        l1_3 = (LayerGrade)Services.BaseService.GetObject("SelectLayerGradeList5", l1_3);
                        LayerGrade l2_3 = new LayerGrade();
                        l2_3.Type = "3";
                        l2_3.SvgDataUid = oldsid;
                        l2_3 = (LayerGrade)Services.BaseService.GetObject("SelectLayerGradeList5", l2_3);
                        if (l1_3 != null && l2_3 != null)
                        {

                            try
                            {
                                //整体规划层里的远期数据

                                int yy1 = Convert.ToInt32(l1_3.Name.Substring(0, 4));
                                int yy2 = Convert.ToInt32(l2_3.Name.Substring(0, 4));
                                XmlNodeList list1to2 = tlVectorControl1.SVGDocument.SelectNodes("svg/use [@layer='" + tlVectorControl1.SVGDocument.SvgdataUid + "4" + "' and @year>'" + yy1 + "' and @year<='" + yy2 + "']");
                                for (int i = 0; i < list1to2.Count; i++)
                                {
                                    SvgElement gra = list1to2[i] as SvgElement;
                                    XmlNode temp = gra.Clone();
                                    ((SvgElement)temp).SetAttribute("layer", tlVectorControl1.SVGDocument.SvgdataUid + "3");
                                    XmlNode newnode = tlVectorControl1.SVGDocument.RootElement.AppendChild((XmlNode)temp);
                                    XmlNode text = tlVectorControl1.SVGDocument.SelectSingleNode("svg/*[@ParentID='" + gra.GetAttribute("id") + "']");
                                    XmlNode textemp = text.Clone();
                                    ((SvgElement)textemp).SetAttribute("layer", tlVectorControl1.SVGDocument.SvgdataUid + "3");
                                    ((SvgElement)textemp).SetAttribute("ParentID", ((SvgElement)temp).GetAttribute("id"));
                                    tlVectorControl1.SVGDocument.RootElement.AppendChild((XmlNode)textemp);
                                    PSPDEV pspDev = new PSPDEV();
                                    pspDev.EleID = gra.ID;
                                    pspDev.SvgUID = tlVectorControl1.SVGDocument.SvgdataUid + "4";
                                    pspDev = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVBySvgUIDandEleID", pspDev);
                                    if (pspDev != null)
                                    {
                                        pspDev.SUID = Guid.NewGuid().ToString();
                                        pspDev.EleID = ((SvgElement)newnode).ID;
                                        pspDev.SvgUID = tlVectorControl1.SVGDocument.SvgdataUid + "3";
                                        Services.BaseService.Create<PSPDEV>(pspDev);
                                    }
                                }

                                XmlNodeList listline2 = tlVectorControl1.SVGDocument.SelectNodes("svg/polyline [@layer='" + tlVectorControl1.SVGDocument.SvgdataUid + "4']");
                                XmlNodeList list1to1 = tlVectorControl1.SVGDocument.SelectNodes("svg/use [@layer='" + tlVectorControl1.SVGDocument.SvgdataUid + "4" + "' and @year<='" + yy1 + "']");
                                for (int i = 0; i < listline2.Count; i++)
                                {
                                    bool firstnodeflag = false; bool lastnodeflag = false; bool jinqifirstnodeflag = false; bool jinqilastnodeflag = false;
                                    Polyline pln = listline2[i] as Polyline;
                                    PSPDEV psp = new PSPDEV();
                                    psp.SvgUID = tlVectorControl1.SVGDocument.SvgdataUid + "4";
                                    psp.EleID = pln.ID;
                                    psp = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVBySvgUIDandEleID", psp);
                                    if (psp.LineStatus != "等待")
                                    {
                                        for (int j = 0; j < list1to2.Count; j++)
                                        {
                                            SvgElement temp = list1to2[j] as SvgElement;
                                            Region ff = new Region(((IGraph)temp).GetBounds());
                                            if (ff.IsVisible(pln.Points[0]))
                                            {
                                                firstnodeflag = true;
                                            }
                                            if (ff.IsVisible(pln.Points[1]))
                                            {
                                                lastnodeflag = true;
                                            }
                                        }
                                        for (int j = 0; j < list1to1.Count; j++)
                                        {
                                            SvgElement temp = list1to1[j] as SvgElement;
                                            Region ff = new Region(((IGraph)temp).GetBounds());
                                            if (ff.IsVisible(pln.Points[0]))
                                            {
                                                jinqifirstnodeflag = true;
                                            }
                                            if (ff.IsVisible(pln.Points[1]))
                                            {
                                                jinqilastnodeflag = true;
                                            }
                                        }
                                        if (firstnodeflag && lastnodeflag && !sel_line3.Contains(pln))
                                        {
                                            sel_line3.Add(pln);
                                        }
                                        if (firstnodeflag && jinqilastnodeflag && !sel_line3.Contains(pln))
                                        {
                                            sel_line3.Add(pln);
                                        }
                                        if (lastnodeflag && jinqifirstnodeflag && !sel_line3.Contains(pln))
                                        {
                                            sel_line3.Add(pln);
                                        }

                                    }

                                }
                                for (int i = 0; i < sel_line3.Count; i++)
                                {
                                    SvgElement gra = sel_line3[i] as SvgElement;

                                    XmlNode temp = gra.Clone();
                                    ((SvgElement)temp).SetAttribute("layer", tlVectorControl1.SVGDocument.SvgdataUid + "3");
                                    XmlNode newnode = tlVectorControl1.SVGDocument.RootElement.AppendChild((XmlNode)temp);
                                    PSPDEV pspDev = new PSPDEV();
                                    pspDev.EleID = gra.ID;
                                    pspDev.SvgUID = tlVectorControl1.SVGDocument.SvgdataUid + "4";
                                    pspDev = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVBySvgUIDandEleID", pspDev);
                                    if (pspDev != null)
                                    {
                                        pspDev.SUID = Guid.NewGuid().ToString();
                                        pspDev.EleID = ((SvgElement)newnode).ID;
                                        pspDev.SvgUID = tlVectorControl1.SVGDocument.SvgdataUid + "3";
                                        Services.BaseService.Create<PSPDEV>(pspDev);
                                    }
                                }
                                //中期数据
                                XmlNodeList list_1 = tlVectorControl1.SVGDocument.SelectNodes("svg/* [@layer='" + tlVectorControl1.SVGDocument.SvgdataUid + "2']");
                                for (int i = 0; i < list_1.Count; i++)
                                {
                                    SvgElement gra = list_1[i] as SvgElement;
                                    XmlNode temp = gra.Clone();
                                    ((SvgElement)temp).SetAttribute("layer", tlVectorControl1.SVGDocument.SvgdataUid + "3");
                                    XmlNode newnode = tlVectorControl1.SVGDocument.RootElement.AppendChild((XmlNode)temp);
                                    //加入节点的名称

                                    XmlNode text = tlVectorControl1.SVGDocument.SelectSingleNode("svg/*[@ParentID='" + gra.GetAttribute("id") + "']");
                                    if (text != null)
                                    {
                                        XmlNode textemp = text.Clone();
                                        ((SvgElement)textemp).SetAttribute("layer", tlVectorControl1.SVGDocument.SvgdataUid + "3");
                                        ((SvgElement)textemp).SetAttribute("ParentID", ((SvgElement)temp).GetAttribute("id"));
                                        tlVectorControl1.SVGDocument.RootElement.AppendChild((XmlNode)textemp);
                                    }
                                    PSPDEV pspDev = new PSPDEV();
                                    pspDev.EleID = gra.ID;
                                    pspDev.SvgUID = tlVectorControl1.SVGDocument.SvgdataUid + "2";
                                    pspDev = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVBySvgUIDandEleID", pspDev);
                                    if (pspDev != null)
                                    {
                                        pspDev.SUID = Guid.NewGuid().ToString();
                                        pspDev.EleID = ((SvgElement)newnode).ID;
                                        pspDev.SvgUID = tlVectorControl1.SVGDocument.SvgdataUid + "3";
                                        if (pspDev.LineStatus == "待选")
                                        {
                                            pspDev.LineStatus = "运行";
                                        }
                                        if (pspDev.LineStatus == "等待")
                                        {
                                            pspDev.LineStatus = "待选";
                                        }
                                        Services.BaseService.Create<PSPDEV>(pspDev);
                                    }
                                }
                                MessageBox.Show("数据处理成功。");
                                Topology2();             //颜色发生变化
                            }
                            catch
                            {
                                MessageBox.Show("选择的年份前4位不是数字。");
                            }
                        }
                        break;
                    #endregion
                }
            }
        }
Beispiel #36
0
        string Report()
        {
            string res = Obs.ToString();

            //如果XYZ坐标已经计算出来
            if (XYZ)
            {
                res += string.Format("\r\n大地坐标(BLH)转换为空间坐标(XYZ)\r\n");
                res += "--------------------------------------\r\n";
                res += $"{"点名",-5}{"B",10}{"L",15}{"  H",8:f4}";
                res += $"{"X",15:f4} {"Y",15:f4}{"Z",15:f4}\r\n";

                foreach (var d in Obs.Data)
                {
                    res += $"{d.Name,-5}{GeoPro.Rad2Str(d.B),15}{GeoPro.Rad2Str(d.L),15}{d.H,10:f4}";
                    res += $"{d.X,15:f4}{d.Y,15:f4}{d.Z,15:f4}\r\n";
                }
            }
            if (BLH)
            {
                res += string.Format("\r\n空间坐标(XYZ)转换为大地坐标(BLH)\r\n");
                res += "--------------------------------------\r\n";
                res += $"{"点名",-5}{"X",15:f4}{"Y",15:f4}{"Z",15:f4}";
                res += $"{"B",15}{"L",15}{"   H",8:f4}\r\n";
                Position pos = new Position(Obs.Datum);

                for (int i = 0; i < Obs.Data.Count; i++)
                {
                    double B, L, H;
                    double X = Obs.Data[i].X + 1000.0; //+1000
                    double Y = Obs.Data[i].Y + 1000.0; //+1000
                    double Z = Obs.Data[i].Z + 1000.0; //+1000
                    pos.CartesianToGeodetic(X, Y, Z, out B, out L, out H);


                    res += $"{Obs.Data[i].Name,-5}{X,15:f4}{Y,15:f4}{Z,15:f4}";
                    res += $"{GeoPro.Rad2Str(B),15}{GeoPro.Rad2Str(L),15}{H,10:f4}\r\n";
                }
            }
            if (xy)
            {
                res += string.Format("\r\n高斯正算(BL-->xy)\r\n");
                res += "--------------------------------------\r\n";
                res += $"{"点名",-5} {"B",12} {"L",12}";
                res += $" {"x",10:f4} {"y",10:f4} \r\n";
                foreach (var d in Obs.Data)
                {
                    res += $"{d.Name,-5} {GeoPro.Rad2Str(d.B),12} {GeoPro.Rad2Str(d.L),12}";
                    res += $" {d.x,10:f4}  {d.y,10:f4}\r\n";
                }
            }
            if (BL)
            {
                res += string.Format("\n高斯反算(xy-->BL)\r\n");
                res += "--------------------------------------\r\n";
                res += $"{"点名",-5} {"x",10:f4} {"y",10:f4}";
                res += $" {"B",12} {"L",12}\r\n";
                Gauss  pos = new Gauss(Obs.Datum, Obs.L0);
                double B, L;
                for (int i = 0; i < Obs.Data.Count; i++)
                {
                    // Obs.Data[i].B = 0; Obs.Data[i].L = 0;
                    double x = Obs.Data[i].x + 1000.0;
                    double y = Obs.Data[i].y + 1000.0;
                    pos.xy2BL(x, y, out B, out L);

                    res += $"{Obs.Data[i].Name,-5} {x,10:f4}  {y,10:f4}";
                    res += $" {GeoPro.Rad2Str(B),15}  {GeoPro.Rad2Str(L),15}\r\n ";
                }
            }
            return(res);
        }