示例#1
0
        //网络N-1计算和输出
        public bool WebCalAndPrint(string projectSUID, string projectid, double ratedCapacity)
        {
            bool flag = true;
            FileStream dh;
            StreamReader readLine;
            // StreamReader readLine;
            ArrayList list = new ArrayList();   //用来记录线路不能解裂的位数

            char[] charSplit;
            string strLine;
            string[] array1;
            string outputZL ="";
            string outputv ="";//记录直流计算结果 线路功率和节点电压

            //string outputBC = null;   //记录补偿计算结果 节点电压
            string[] array2;

            string strLine2;

            char[] charSplit2 = new char[] { ' ' };
            List<lineclass> Overlinp = new List<lineclass>();
            List<lineclass> OverVp = new List<lineclass>();
            //Dictionary<int, List<lineclass>> OverPhege = new Dictionary<int, List<lineclass>>();       //为 线路功率的检验 键值为断开线路的编号,值为第几条线路出现了不合格

            //Dictionary<int, List<lineclass>> OverVhege = new Dictionary<int, List<lineclass>>();       //为 节点电压的检验 键值为断开线路的编号,值为第几个节点出现了不合格

            FileStream op;
            StreamWriter str1;
            FileStream dh2;
            StreamReader readLine2;
            Excel.Application ex;
            //Excel.Worksheet xSheet;
            Excel.Application result1;
            //Excel.Worksheet tempSheet;
            Excel.Worksheet newWorksheet;
            PSP_ELCPROJECT psproject = new PSP_ELCPROJECT();
            psproject.ID = projectSUID;
            psproject = (PSP_ELCPROJECT)UCDeviceBase.DataService.GetObject("SelectPSP_ELCPROJECTByKey", psproject);

            if (true)    //进行全网计算
            {
                if (!CheckN(projectSUID,projectid,ratedCapacity))
                {
                    return false;
                }

                try
                {
                    string datatime = System.DateTime.Now.ToString();
                    System.Windows.Forms.Clipboard.Clear(); //去掉剪切板中的数据

                    if (brchcount >= 50)
                    {
                        for (int i = 1; i <= 5; i++)
                        {
                            n1NL_DLL.ZYZ nl = new n1NL_DLL.ZYZ();
                            nl.jianyan(i);
                        }
                    }
                    else
                    {
                        for (int i = 1; i <= brchcount; i++)
                        {
                            n1NL_DLL.ZYZ nl = new n1NL_DLL.ZYZ();
                            nl.jianyan(i);
                        }
                    }
                    //int* busnumber;

                    //N1Test.NBcal kk = new N1Test.NBcal();                    //busnumber = kk.Show_Reliability();

                    double yinzi = 0, capability = 0, volt = 0, current = 0, standvolt = 1, Rad_to_Deg = 57.29577951;
                   // string branchname = getbranchname();
                   // string busname = getbusname();

                    capability = ratedCapacity;

                    string con = ",PSP_ELCDEVICE WHERE PSPDEV.SUID = PSP_ELCDEVICE.DeviceSUID AND PSP_ELCDEVICE.ProjectSUID = '" + projectSUID + "'AND PSPDEV.type='01'AND PSPDEV.KSwitchStatus = '0'";
                    IList cont = UCDeviceBase.DataService.GetList("SelectPSPDEVByCondition", con);
                    if (buscount < cont.Count)
                    {
                        MessageBox.Show("选择的母线又存在孤立的节点!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        return false;

                    }
                    if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\VandTheta.txt"))
                    {
                    }
                    else
                    {
                        MessageBox.Show("数据不收敛,请调整参数后重新计算!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return false;
                    }
                    if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\lineP.txt"))
                    {
                    }
                    else
                    {
                        return false;
                    }
                    dh = new FileStream(System.Windows.Forms.Application.StartupPath + "\\" + "lineP.txt", FileMode.Open);
                    dh2 = new FileStream(System.Windows.Forms.Application.StartupPath + "\\" + "VandTheta.txt", FileMode.Open);
                    readLine2 = new StreamReader(dh2, Encoding.Default);
                    readLine = new StreamReader(dh, Encoding.Default);
                    charSplit = new char[] { ' ' };
                    //strLine = readLine.ReadLine();

                    outputZL = null;
                    //outputBC=null;
                   // outputZL += ("全网可靠性结果报表" + "\r\n");
                   //// outputZL += ("开断支路名称" + "," + "剩余网络线路功率Pij和Pji的有名值" + ",,");
                   // for (int i = 0; i < brchcount - 1; i++)
                   // {
                   //     outputZL += (",,");
                   // }
                   // outputZL += ("是否越限" + "," + "\r\n");
                   // outputZL += ",";
                    int n = 0; //记录线路的行数

                    while ((strLine = readLine.ReadLine()) != null)
                    {
                        array1 = strLine.Split(charSplit);

                        string[] devzl = new string[3 * brchcount + 1];

                        devzl.Initialize();
                        int i = 0;

                        n++;
                        foreach (string str in array1)
                        {
                            if (str != "")
                            {

                                devzl[i++] = str.ToString();

                            }
                        }
                        //for (int j = 0; j < brchcount; j++)
                        //{
                        //    outputZL += devzl[3 * j + 1] + "," + ",";
                        //}
                        //outputZL += branchname;
                        //outputZL += ("," + "\r\n");
                        //outputZL += devzl[0] + ",";
                        bool lineflag = true;      //只要有一个不合格则就为不合格
                        if (devzl[1] != "-1")
                        {
                            for (int j = 0; j < brchcount; j++)
                            {

                                double pij = Convert.ToDouble(devzl[j * 3 + 2].Substring(0, devzl[j * 3 + 2].IndexOf('j') - 1)) * capability;
                                double qij = Convert.ToDouble(devzl[j * 3 + 2].Substring(devzl[j * 3 + 2].IndexOf('j') + 1)) * capability;
                                double pji = Convert.ToDouble(devzl[j * 3 + 3].Substring(0, devzl[j * 3 + 3].IndexOf('j') - 1)) * capability;
                                double qji = Convert.ToDouble(devzl[j * 3 + 3].Substring(devzl[j * 3 + 3].IndexOf('j') + 1)) * capability;
                                double Sij = System.Math.Sqrt(pij * pij + qij * qij);
                                double Sji = System.Math.Sqrt(pji * pji + qji * qji);
                                double maxSij = (Sij > Sji) ? Sij : Sji;
                                PSPDEV psp = new PSPDEV();
                                con = " WHERE Name='" + devzl[j * 3 + 1] + "' AND ProjectID = '" + projectid + "'" + "AND Type='05'";
                                IList listName = UCDeviceBase.DataService.GetList("SelectPSPDEVByCondition", con);
                                PSPDEV pspline = (PSPDEV)listName[0];
                                double voltR = pspline.RateVolt;
                                //WireCategory wirewire = new WireCategory();
                                //wirewire.WireType = pspline.LineType;
                                //if (pspline.LineType == null || pspline.LineType == "")
                                //{
                                //    MessageBox.Show(pspline.Name + "的线路类型没有输入,无法进行可靠性检验", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                //    return;
                                //}
                                //WireCategory listware = (WireCategory)UCDeviceBase.DataService.GetObject("SelectWireCategoryByKey", wirewire);
                                double Ichange = (double)pspline.Burthen;
                                double linXij = System.Math.Sqrt(3) * voltR * Ichange ;
                               // outputZL += "'" + youming(devzl[j * 3 + 2], capability) + "," + "'" + youming(devzl[j * 3 + 3], capability) + ",";
                                if (maxSij >= linXij)
                                {
                                    lineflag = false;
                                    flag = false;
                                    lineclass _line = new lineclass(n, j);
                                    Overlinp.Add(_line);
                                    // OverPhege[n] = j;
                                }

                            }
                            if (!lineflag)
                            {
                                outputZL += "不合格";
                            }
                            else
                                outputZL += "合格";
                        }
                        else
                        {
                            outputZL += "该线路不可断。";
                        }
                        //OverPhege[n] = Overlinp;
                        //Overlinp.Clear();
                        //outputZL += "\r\n";
                        while ((strLine = readLine.ReadLine()) != null)
                        {
                            array1 = strLine.Split(charSplit);

                            string[] devzl1 = new string[3 * brchcount + 1];

                            devzl1.Initialize();

                            n++;
                            i = 0;
                            foreach (string str in array1)
                            {
                                if (str != "")
                                {

                                    devzl1[i++] = str.ToString();

                                }
                            }
                            if (devzl1[1] != "-1")
                            {
                                outputZL += devzl1[0] + ",";
                                for (int j = 0; j < brchcount; j++)
                                {
                                    double pij = Convert.ToDouble(devzl1[j * 3 + 2].Substring(0, devzl1[j * 3 + 2].IndexOf('j') - 1)) * capability;
                                    double qij = Convert.ToDouble(devzl1[j * 3 + 2].Substring(devzl1[j * 3 + 2].IndexOf('j') + 1)) * capability;
                                    double pji = Convert.ToDouble(devzl1[j * 3 + 3].Substring(0, devzl1[j * 3 + 3].IndexOf('j') - 1)) * capability;
                                    double qji = Convert.ToDouble(devzl1[j * 3 + 3].Substring(devzl1[j * 3 + 3].IndexOf('j') + 1)) * capability;
                                    double Sij = System.Math.Sqrt(pij * pij + qij * qij);
                                    double Sji = System.Math.Sqrt(pji * pji + qji * qji);
                                    double maxSij = (Sij > Sji) ? Sij : Sji;

                                    con = " WHERE Name='" + devzl1[j * 3 + 1] + "' AND ProjectID = '" + projectid + "'" + "AND Type='05'";
                                    IList listName = UCDeviceBase.DataService.GetList("SelectPSPDEVByCondition", con);

                                    PSPDEV pspline = (PSPDEV)listName[0];
                                    double voltR = pspline.RateVolt;
                                    //WireCategory wirewire = new WireCategory();
                                    //wirewire.WireType = pspline.LineType;
                                    //if (pspline.LineType == null || pspline.LineType == "")
                                    //{
                                    //    MessageBox.Show(pspline.Name + "的线路类型没有输入,无法进行可靠性检验", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                    //    return;
                                    //}
                                    //WireCategory listware = (WireCategory)UCDeviceBase.DataService.GetObject("SelectWireCategoryByKey", wirewire);
                                    double Ichange = (double)pspline.Burthen;
                                    double linXij = System.Math.Sqrt(3) * voltR * Ichange ;
                                    // outputZL += "'" + devzl[j * 3 + 2] + "," + "'" + devzl[j * 3 + 3] + ",";
                                    if (maxSij >= linXij)
                                    {
                                        lineflag = false;
                                        flag = false;
                                        return flag;
                                        lineclass subline = new lineclass(n, j);
                                        Overlinp.Add(subline);
                                        //OverPhege[n] = j;
                                    }
                                    outputZL += "'" + youming(devzl1[j * 3 + 2], capability) + "," + "'" + youming(devzl1[j * 3 + 3], capability) + ",";    //在此还可以判断线路是否超载

                                }
                                if (!lineflag)
                                {
                                    outputZL += "不合格";
                                }
                                else
                                    outputZL += "合格";
                                outputZL += "\r\n";
                                //OverPhege[n] = Overlinp;
                                //Overlinp.Clear();

                            }

                            else
                            {
                                list.Add(n);
                                outputZL += devzl1[0] + "," + "为不可断裂的线路";
                                outputZL += "\r\n";
                            }

                        }
                    }
                    outputZL += "注释:红色为线路超载" + "\r\n";
                    outputZL += "操作时间为:" + datatime;
                    outputZL += "\r\n";
                    outputZL += "单位:kA\\kV\\MW\\Mvar" + "\r\n";
                    readLine.Close();
                    if (File.Exists("result1.csv"))
                    {
                        File.Delete("result1.csv");
                    }

                    op = new FileStream("result1.csv", FileMode.OpenOrCreate);
                    str1 = new StreamWriter(op, Encoding.Default);
                    str1.Write(outputZL);
                    str1.Close();

                    outputZL = null;
                    //将各个节点的电压写入其中
                    // strLine2 = readLine2.ReadLine();
                    n = 0;
                    bool busvflag1 = true;
                    outputZL += ("网络节点电压和相角" + "\r\n");
                    outputZL += ("开断支路名称" + "," + "节点电压的幅值和相角的有名值");
                    for (int i = 0; i < buscount; i++)
                    {
                        outputZL += (",,");
                    }
                    outputZL += ("是否越限" + "," + "\r\n");
                    outputZL += ",";
                    while ((strLine2 = readLine2.ReadLine()) != null)
                    {
                        array2 = strLine2.Split(charSplit);

                        string[] devzl = new string[buscount * 3 + 1];

                        devzl.Initialize();
                        int i = 0;

                        n++;
                        foreach (string str in array2)
                        {
                            if (str != "")
                            {

                                devzl[i++] = str.ToString();

                            }
                        }

                       // outputZL += busname;
                        outputZL += ("," + "\r\n");
                        outputZL += devzl[0] + ",";
                        if (devzl[1] != "-1")
                        {

                            for (int j = 0; j < buscount; j++)
                            {
                                PSPDEV pspDev = new PSPDEV();
                                con = " WHERE Name='" + devzl[j * 3 + 1] + "' AND ProjectID = '" + projectid + "'" + "AND Type='01'";
                                pspDev =(PSPDEV) UCDeviceBase.DataService.GetObject("SelectPSPDEVByCondition", con);

                                if (pspDev != null && pspDev.ReferenceVolt != 0)
                                {
                                    volt = pspDev.ReferenceVolt;
                                }
                                else
                                    volt = standvolt;
                                outputZL += "'" + (Convert.ToDouble(devzl[j * 3 + 2]) * volt).ToString() + "," + "'" + devzl[j * 3 + 3] + ",";
                                if (Convert.ToDouble(devzl[j * 3 + 2]) <= TLPSPVmin || Convert.ToDouble(devzl[j * 3 + 2]) >= TLPSPVmax)
                                {
                                    busvflag1 = false;
                                    flag = false;
                                    return flag;
                                    lineclass _vtheta = new lineclass(n, j);
                                    OverVp.Add(_vtheta);
                                    //OverVhege[n] = j;
                                }
                            }
                            if (busvflag1)
                            {
                                outputZL += "合格";
                            }
                            else
                            {
                                outputZL += "不合格";
                            }
                        }
                        else
                        {
                            outputZL += "不可断裂";
                        }
                        //OverVhege[n] = OverVp;
                        //OverVp.Clear();
                        outputZL += "\r\n";

                        while ((strLine2 = readLine2.ReadLine()) != null)
                        {
                            busvflag1 = true;
                            array2 = strLine2.Split(charSplit);

                            string[] devzl1 = new string[buscount * 3 + 1];

                            devzl1.Initialize();

                            n++;
                            i = 0;
                            foreach (string str in array2)
                            {
                                if (str != "")
                                {

                                    devzl1[i++] = str.ToString();

                                }
                            }

                            if (devzl1[1] != "-1")
                            {
                                outputZL += devzl1[0] + ",";
                                for (int j = 0; j < buscount; j++)
                                {
                                    PSPDEV pspDev = new PSPDEV();
                                    con = " WHERE Name='" + devzl1[j * 3 + 1] + "' AND ProjectID = '" + projectid + "'" + "AND Type='01'";
                                    pspDev =(PSPDEV) UCDeviceBase.DataService.GetObject("SelectPSPDEVByCondition", con);

                                    if (pspDev != null && pspDev.ReferenceVolt != 0)
                                    {
                                        volt = pspDev.ReferenceVolt;
                                    }
                                    else
                                        volt = standvolt;
                                    outputZL += "'" + (Convert.ToDouble(devzl1[j * 3 + 2]) * volt).ToString() + "," + "'" + devzl1[j * 3 + 3] + ",";   //在此还可以判断线路是否超载,如果超载加入一个标记,在excel里使其变为红色

                                    if (Convert.ToDouble(devzl1[j * 3 + 2]) >= TLPSPVmax || Convert.ToDouble(devzl1[j * 3 + 2]) <= TLPSPVmin)
                                    {
                                        lineclass vtheta = new lineclass(n, j);
                                        busvflag1 = false;
                                        flag = false;
                                        return flag;
                                        OverVp.Add(vtheta);
                                        //OverVhege[n] = j;
                                    }
                                }
                                if (busvflag1)
                                {
                                    outputZL += "合格";
                                }
                                else
                                    outputZL += "不合格";
                                outputZL += "\r\n";
                                //OverPhege[n] = OverVp;
                                //OverVp.Clear();
                            }
                            else
                            {
                                // list.Add(n);
                                outputZL += devzl1[0] + "," + "为不可断裂的线路" + ",,,,,,";
                                outputZL += "\r\n";
                            }

                        }
                    }
                    outputZL += "注释:红色为节点电压超载" + "\r\n";
                    outputZL += "节点电压合格范围为电压基准值的上下限,分别为" + TLPSPVmax + "和" + TLPSPVmin + "倍" + "\r\n";
                    outputZL += "操作时间为:" + datatime + "\r\n";
                    outputZL += "单位:kA\\kV\\MW\\Mvar" + "\r\n";
                    readLine2.Close();

                    //op = new FileStream(System.Windows.Forms.Application.StartupPath + "\\" + "reli.txt", FileMode.OpenOrCreate);
                    //str1 = new StreamWriter(op, Encoding.Default);
                    //str1.Write(outputZL);
                    //str1.Close();

                }
                catch (System.Exception e1)
                {
                    MessageBox.Show("数据存在问题,请仔细检查后再进行结果计算!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            //if (webn1.DialogResult == DialogResult.Ignore)
            //{
            //    PSPDEV pspDEV = new PSPDEV();
            //    pspDEV.ProjectID = projectid;
            //    pspDEV.SvgUID = projectSUID; //为了把 项目ID和卷id传入
            //    PartRelform selregion = new PartRelform(pspDEV);
            //    selregion.ShowDialog();
            //    if (selregion.DialogResult == DialogResult.Ignore)
            //    {
            //        DelLinenum = selregion.lineVnumlist;
            //        //DelTransnum = null;
            //       flag =  QyRelanalyst(projectSUID,projectid,ratedCapacity);
            //    }
            //    //IList list1 = UCDeviceBase.DataService.GetList("SelectPSPDEVBySvgUID", psp);
            //    //将进行潮流计算的文档传到选择网络中。

            //    else if (selregion.DialogResult == DialogResult.Yes)
            //    {
            //        DelLinenum = selregion.lineDnumlist;
            //        DelTransnum = selregion.lineVnumlist;
            //        //DelTransnum = null;
            //       flag =  QyRelanalyst(projectSUID,projectid,ratedCapacity);
            //    }
            //}
            //Operateflag = false;
            return flag;
        }
示例#2
0
        //网络N-1计算和输出
        private void WebCalAndPrint()
        {
            FileStream dh;
            StreamReader readLine;
            // StreamReader readLine;
            ArrayList list = new ArrayList();   //用来记录线路不能解裂的位数

            char[] charSplit;
            string strLine;
            string[] array1;
            string outputZL = null;   //记录直流计算结果 线路功率和节点电压

            //string outputBC = null;   //记录补偿计算结果 节点电压
            string[] array2;

            string strLine2;

            char[] charSplit2 = new char[] { ' ' };
            List<lineclass> Overlinp = new List<lineclass>();
            List<lineclass> OverVp = new List<lineclass>();
            //Dictionary<int, List<lineclass>> OverPhege = new Dictionary<int, List<lineclass>>();       //为 线路功率的检验 键值为断开线路的编号,值为第几条线路出现了不合格

            //Dictionary<int, List<lineclass>> OverVhege = new Dictionary<int, List<lineclass>>();       //为 节点电压的检验 键值为断开线路的编号,值为第几个节点出现了不合格

            FileStream op;
            StreamWriter str1;
            FileStream dh2;
            StreamReader readLine2;
            Excel.Application ex;
            //Excel.Worksheet xSheet;
            Excel.Application result1;
            //Excel.Worksheet tempSheet;
            Excel.Worksheet newWorksheet;
            WebN1 webn1 = new WebN1();
            webn1.ShowDialog();
            if (webn1.DialogResult == DialogResult.OK)    //进行全网计算
            {
                if (!CheckN())
                {
                    return;
                }

                try
                {
                    System.Windows.Forms.Clipboard.Clear(); //去掉剪切板中的数据

                    for (int i = 1; i <= brchcount + transcount; i++)
                    {
                        n1NL_DLL.ZYZ nl = new n1NL_DLL.ZYZ();
                        nl.jianyan(i);
                    }
                    //int* busnumber;

                    //N1Test.NBcal kk = new N1Test.NBcal();
                    //busnumber = kk.Show_Reliability();
                    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);
                        standvolt = volt;
                        if (dev.PowerFactor == 0)
                        {
                            yinzi = 1;
                        }
                        if (dev.StandardCurrent == 0)
                        {
                            capability = 1;
                        }
                        if (dev.StandardVolt == 0)
                        {
                            volt = 1;
                            standvolt = 1;
                        }
                        current = capability / (Math.Sqrt(3) * volt);

                    }
                    capability = 100;
                    PSPDEV ct = new PSPDEV();
                    ct.SvgUID = tlVectorControl1.SVGDocument.CurrentLayer.ID;
                    ct.Type = "Use";
                    IList cont = Services.BaseService.GetList("SelectPSPDEVBySvgUIDAndType", ct);
                    if (buscount < cont.Count)
                    {
                        MessageBox.Show("请进行潮流计算后再查看结果!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        return;

                    }
                    if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\VandTheta.txt"))
                    {
                    }
                    else
                    {
                        MessageBox.Show("数据不收敛,请调整参数后重新计算!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                    if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\lineP.txt"))
                    {
                    }
                    else
                    {
                        return;
                    }
                    dh = new FileStream(System.Windows.Forms.Application.StartupPath + "\\" + "lineP.txt", FileMode.Open);
                    dh2 = new FileStream(System.Windows.Forms.Application.StartupPath + "\\" + "VandTheta.txt", FileMode.Open);
                    readLine2 = new StreamReader(dh2);
                    readLine = new StreamReader(dh);
                    charSplit = new char[] { ' ' };
                    //strLine = readLine.ReadLine();

                    outputZL = null;
                    //outputBC=null;
                    outputZL += ("全网可靠性结果报表" + "\r\n");
                    outputZL += ("开断支路" + "," + "剩余网络线路功率Pij和Pji的标幺值" + ",,");
                    for (int i = 0; i < brchcount - 1; i++)
                    {
                        outputZL += (",,");
                    }
                    outputZL += ("是否越限" + "," + "\r\n");
                    outputZL += ",";
                    int n = 0; //记录线路的行数

                    while ((strLine = readLine.ReadLine()) != null)
                    {
                        array1 = strLine.Split(charSplit);

                        string[] devzl = new string[3 * brchcount + 1];

                        devzl.Initialize();
                        int i = 0;

                        n++;
                        foreach (string str in array1)
                        {
                            if (str != "")
                            {

                                devzl[i++] = str.ToString();

                            }
                        }
                        for (int j = 0; j < brchcount; j++)
                        {
                            outputZL += devzl[3 * j + 1] + "," + ",";
                        }
                        outputZL += ("," + "\r\n");
                        outputZL += devzl[0] + ",";
                        bool lineflag = true;      //只要有一个不合格则就为不合格
                        if (devzl[1] != "-1")
                        {
                            for (int j = 0; j < brchcount; j++)
                            {

                                double pij = Convert.ToDouble(devzl[j * 3 + 2].Substring(0, devzl[j * 3 + 2].IndexOf('j') - 1)) * capability;
                                double qij = Convert.ToDouble(devzl[j * 3 + 2].Substring(devzl[j * 3 + 2].IndexOf('j') + 1)) * capability;
                                double pji = Convert.ToDouble(devzl[j * 3 + 3].Substring(0, devzl[j * 3 + 3].IndexOf('j') - 1)) * capability;
                                double qji = Convert.ToDouble(devzl[j * 3 + 3].Substring(devzl[j * 3 + 3].IndexOf('j') + 1)) * capability;
                                double Sij = System.Math.Sqrt(pij * pij + qij * qij);
                                double Sji = System.Math.Sqrt(pji * pji + qji * qji);
                                double maxSij = (Sij > Sji) ? Sij : Sji;
                                PSPDEV psp = new PSPDEV();

                                psp.Name = devzl[j * 3 + 1];
                                psp.Type = "Polyline";
                                psp.SvgUID = tlVectorControl1.SVGDocument.CurrentLayer.ID;
                                IList listName = Services.BaseService.GetList("SelectPSPDEVByName", psp);
                                PSPDEV pspline = (PSPDEV)listName[0];
                                double voltR = pspline.VoltR;
                                WireCategory wirewire = new WireCategory();
                                wirewire.WireType = pspline.LineType;
                                if (pspline.LineType == null || pspline.LineType == "")
                                {
                                    MessageBox.Show(pspline.Name + "的线路类型没有输入,无法进行可靠性检验", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                    return;
                                }
                                WireCategory listware = (WireCategory)Services.BaseService.GetObject("SelectWireCategoryByKey", wirewire);
                                double Ichange = (double)listware.WireChange;
                                double linXij = System.Math.Sqrt(3) * voltR * Ichange / 1000;
                                outputZL += "'" + devzl[j * 3 + 2] + "," + "'" + devzl[j * 3 + 3] + ",";
                                if (maxSij >= linXij)
                                {
                                    lineflag = false;
                                    lineclass _line = new lineclass(n, j);
                                    Overlinp.Add(_line);
                                    // OverPhege[n] = j;
                                }

                            }
                            if (!lineflag)
                            {
                                outputZL += "不合格";
                            }
                            else
                                outputZL += "合格";
                        }
                        else
                        {
                            outputZL += "该线路不可断。";
                        }
                        //OverPhege[n] = Overlinp;
                        //Overlinp.Clear();
                        outputZL += "\r\n";
                        while ((strLine = readLine.ReadLine()) != null)
                        {
                            array1 = strLine.Split(charSplit);

                            string[] devzl1 = new string[3 * brchcount + 1];

                            devzl1.Initialize();

                            n++;
                            i = 0;
                            foreach (string str in array1)
                            {
                                if (str != "")
                                {

                                    devzl1[i++] = str.ToString();

                                }
                            }
                            if (devzl1[1] != "-1")
                            {
                                outputZL += devzl1[0] + ",";
                                for (int j = 0; j < brchcount; j++)
                                {
                                    double pij = Convert.ToDouble(devzl1[j * 3 + 2].Substring(0, devzl1[j * 3 + 2].IndexOf('j') - 1)) * capability;
                                    double qij = Convert.ToDouble(devzl1[j * 3 + 2].Substring(devzl1[j * 3 + 2].IndexOf('j') + 1)) * capability;
                                    double pji = Convert.ToDouble(devzl1[j * 3 + 3].Substring(0, devzl1[j * 3 + 3].IndexOf('j') - 1)) * capability;
                                    double qji = Convert.ToDouble(devzl1[j * 3 + 3].Substring(devzl1[j * 3 + 3].IndexOf('j') + 1)) * capability;
                                    double Sij = System.Math.Sqrt(pij * pij + qij * qij);
                                    double Sji = System.Math.Sqrt(pji * pji + qji * qji);
                                    double maxSij = (Sij > Sji) ? Sij : Sji;
                                    PSPDEV psp = new PSPDEV();

                                    psp.Name = devzl1[j * 3 + 1];
                                    psp.Type = "Polyline";
                                    psp.SvgUID = tlVectorControl1.SVGDocument.CurrentLayer.ID;
                                    IList listName = Services.BaseService.GetList("SelectPSPDEVByName", psp);
                                    PSPDEV pspline = (PSPDEV)listName[0];
                                    double voltR = pspline.VoltR;
                                    WireCategory wirewire = new WireCategory();
                                    wirewire.WireType = pspline.LineType;
                                    if (pspline.LineType == null || pspline.LineType == "")
                                    {
                                        MessageBox.Show(pspline.Name + "的线路类型没有输入,无法进行可靠性检验", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                        return;
                                    }
                                    WireCategory listware = (WireCategory)Services.BaseService.GetObject("SelectWireCategoryByKey", wirewire);
                                    double Ichange = (double)listware.WireChange;
                                    double linXij = System.Math.Sqrt(3) * voltR * Ichange / 1000;
                                    // outputZL += "'" + devzl[j * 3 + 2] + "," + "'" + devzl[j * 3 + 3] + ",";
                                    if (maxSij >= linXij)
                                    {
                                        lineflag = false;
                                        lineclass subline = new lineclass(n, j);
                                        Overlinp.Add(subline);
                                        //OverPhege[n] = j;
                                    }
                                    outputZL += "'" + devzl1[j * 3 + 2] + "," + "'" + devzl1[j * 3 + 3] + ",";    //在此还可以判断线路是否超载

                                }
                                if (!lineflag)
                                {
                                    outputZL += "不合格";
                                }
                                else
                                    outputZL += "合格";
                                outputZL += "\r\n";
                                //OverPhege[n] = Overlinp;
                                //Overlinp.Clear();

                            }

                            else
                            {
                                list.Add(n);
                                outputZL += devzl1[0] + "," + "为不可断裂的线路";
                                outputZL += "\r\n";
                            }

                        }
                    }
                    outputZL += "注视:" + "," + "红色为线路超载";
                    outputZL += "\r\n";
                    readLine.Close();
                    if (File.Exists("result1.csv"))
                    {
                        File.Delete("result1.csv");
                    }

                    op = new FileStream("result1.csv", FileMode.OpenOrCreate);
                    str1 = new StreamWriter(op, Encoding.GetEncoding("GB2312"));
                    str1.Write(outputZL);
                    str1.Close();

                    outputZL = null;
                    //将各个节点的电压写入其中
                    // strLine2 = readLine2.ReadLine();
                    n = 0;
                    bool busvflag1 = true;
                    outputZL += ("网络节点电压和相角" + "\r\n");
                    outputZL += ("开断支路名称" + ",");
                    for (int i = 0; i < buscount; i++)
                    {
                        outputZL += (",,");
                    }
                    outputZL += ("是否越限" + "," + "\r\n");
                    outputZL += ",";
                    while ((strLine2 = readLine2.ReadLine()) != null)
                    {
                        array2 = strLine2.Split(charSplit);

                        string[] devzl = new string[buscount * 3 + 1];

                        devzl.Initialize();
                        int i = 0;

                        n++;
                        foreach (string str in array2)
                        {
                            if (str != "")
                            {

                                devzl[i++] = str.ToString();

                            }
                        }
                        if (devzl[1] != "-1")
                        {
                            for (int j = 0; j < buscount; j++)
                            {
                                outputZL += devzl[3 * j + 1] + "," + ",";
                            }

                            outputZL += ("," + "\r\n");
                            outputZL += devzl[0] + ",";
                            for (int j = 0; j < buscount; j++)
                            {
                                PSPDEV pspDev = new PSPDEV();
                                pspDev.Name = devzl[3 * j + 1];
                                pspDev.SvgUID = tlVectorControl1.SVGDocument.CurrentLayer.ID;
                                pspDev.Type = "Use";
                                pspDev = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByName", pspDev);
                                if (pspDev.ReferenceVolt != null && pspDev.ReferenceVolt != 0)
                                {
                                    volt = pspDev.ReferenceVolt;
                                }
                                else
                                    volt = standvolt;
                                outputZL += "'" + (Convert.ToDouble(devzl[j * 3 + 2]) * volt).ToString() + "," + "'" + devzl[j * 3 + 3] + ",";
                                if (Convert.ToDouble(devzl[j * 3 + 2]) >= 1.1 || Convert.ToDouble(devzl[j * 3 + 2]) <= 0.9)
                                {
                                    busvflag1 = false;
                                    lineclass _vtheta = new lineclass(n, j);
                                    OverVp.Add(_vtheta);
                                    //OverVhege[n] = j;
                                }
                            }
                            if (busvflag1)
                            {
                                outputZL += "合格";
                            }
                            else
                            {
                                outputZL += "不合格";
                            }
                        }
                        else
                        {
                            outputZL += "不可断裂";
                        }
                        //OverVhege[n] = OverVp;
                        //OverVp.Clear();
                        outputZL += "\r\n";

                        while ((strLine2 = readLine2.ReadLine()) != null)
                        {
                            busvflag1 = true;
                            array2 = strLine2.Split(charSplit);

                            string[] devzl1 = new string[buscount * 3 + 1];

                            devzl1.Initialize();

                            n++;
                            i = 0;
                            foreach (string str in array2)
                            {
                                if (str != "")
                                {

                                    devzl1[i++] = str.ToString();

                                }
                            }
                            if (devzl1[1] != "-1")
                            {
                                outputZL += devzl1[0] + ",";
                                for (int j = 0; j < buscount; j++)
                                {
                                    PSPDEV pspDev = new PSPDEV();
                                    pspDev.Name = devzl1[3 * j + 1];
                                    pspDev.SvgUID = tlVectorControl1.SVGDocument.CurrentLayer.ID;
                                    pspDev.Type = "Use";
                                    pspDev = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByName", pspDev);
                                    if (pspDev.ReferenceVolt != null && pspDev.ReferenceVolt != 0)
                                    {
                                        volt = pspDev.ReferenceVolt;
                                    }
                                    else
                                        volt = standvolt;
                                    outputZL += "'" + (Convert.ToDouble(devzl1[j * 3 + 2]) * volt).ToString() + "," + "'" + devzl1[j * 3 + 3] + ",";   //在此还可以判断线路是否超载,如果超载加入一个标记,在excel里使其变为红色

                                    if (Convert.ToDouble(devzl1[j * 3 + 2]) >= 1.1 || Convert.ToDouble(devzl1[j * 3 + 2]) <= 0.9)
                                    {
                                        lineclass vtheta = new lineclass(n, j);
                                        busvflag1 = false;
                                        OverVp.Add(vtheta);
                                        //OverVhege[n] = j;
                                    }
                                }
                                if (busvflag1)
                                {
                                    outputZL += "合格";
                                }
                                else
                                    outputZL += "不合格";
                                outputZL += "\r\n";
                                //OverPhege[n] = OverVp;
                                //OverVp.Clear();
                            }
                            else
                            {
                                // list.Add(n);
                                outputZL += devzl1[0] + "," + "为不可断裂的线路" + ",,,,,,";
                                outputZL += "\r\n";
                            }

                        }
                    }
                    outputZL += "注视:" + "," + "红色为线路超载" + "\r\n";
                    outputZL += "," + "节点电压合格范围为电压基准值的上限下限分别为1.1和0.9" + "\r\n";
                    readLine2.Close();

                    //op = new FileStream(System.Windows.Forms.Application.StartupPath + "\\" + "reli.txt", FileMode.OpenOrCreate);
                    //str1 = new StreamWriter(op, Encoding.GetEncoding("GB2312"));
                    //str1.Write(outputZL);
                    //str1.Close();

                    if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\" + "result2.csv"))
                    {
                        File.Delete(System.Windows.Forms.Application.StartupPath + "\\" + "result2.csv");
                    }

                    op = new FileStream(System.Windows.Forms.Application.StartupPath + "\\" + "result2.csv", FileMode.OpenOrCreate);
                    str1 = new StreamWriter(op, Encoding.GetEncoding("GB2312"));
                    str1.Write(outputZL);
                    str1.Close();

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

                    Excel.Application result2 = new Excel.Application();
                    result2.Application.Workbooks.Add(System.Windows.Forms.Application.StartupPath + "\\result2.csv");
                    Excel.Worksheet tempSheet = (Excel.Worksheet)result2.Worksheets.get_Item(1);
                    Excel.Worksheet newWorksheet1 = (Excel.Worksheet)result1.Worksheets.get_Item(2);
                    newWorksheet.Name = "一般线路可靠性";
                    newWorksheet1.Name = "节点电压可靠性";
                    result1.Visible = true;

                    tempSheet.Cells.Select();
                    tempSheet.Cells.Copy(System.Reflection.Missing.Value);
                    newWorksheet1.Paste(System.Reflection.Missing.Value, System.Reflection.Missing.Value);
                    newWorksheet.Rows.AutoFit();
                    newWorksheet.Columns.AutoFit();
                    newWorksheet1.Rows.AutoFit();
                    newWorksheet1.Columns.AutoFit();

                    newWorksheet.get_Range(newWorksheet.Cells[1, 1], newWorksheet.Cells[1, 2 * brchcount + 2]).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[2, 1], newWorksheet.Cells[3, 1]).MergeCells = true;
                    newWorksheet.get_Range(newWorksheet.Cells[2, 2], newWorksheet.Cells[2, 2 * brchcount + 1]).MergeCells = true;
                    newWorksheet.get_Range(newWorksheet.Cells[2, 2], newWorksheet.Cells[2, 2]).HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
                    newWorksheet.get_Range(newWorksheet.Cells[2, 2 * brchcount + 2], newWorksheet.Cells[3, 2 * brchcount + 2]).MergeCells = true;
                    for (int i = 0; i < brchcount; i++)
                    {
                        newWorksheet.get_Range(newWorksheet.Cells[3, 2 * i + 2], newWorksheet.Cells[3, 2 * i + 3]).MergeCells = true;
                        newWorksheet.get_Range(newWorksheet.Cells[3, 2 * i + 2], newWorksheet.Cells[3, 2 * i + 3]).HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
                    }
                    // newWorksheet.get_Range(newWorksheet.Cells[4, 2], newWorksheet.Cells[4, brchcount + 1]).Interior.ColorIndex = 45;
                    newWorksheet.get_Range(newWorksheet.Cells[4, 1], newWorksheet.Cells[3 + brchcount + transcount, 1]).Interior.ColorIndex = 6;
                    //newWorksheet.get_Range(newWorksheet.Cells[5, 2], newWorksheet.Cells[newWorksheet.UsedRange.Rows.Count, brchcount + 1]).NumberFormat = "0.0000_ ";
                    newWorksheet.get_Range(newWorksheet.Cells[4, 2], newWorksheet.Cells[3 + brchcount + transcount, 2 * brchcount + 1]).NumberFormat = "@";
                    newWorksheet.get_Range(newWorksheet.Cells[2, 1], newWorksheet.Cells[3 + brchcount + transcount, 2 * brchcount + 2]).Font.Name = "楷体_GB2312";
                    //在此处将其不合格的数据显示出来

                    //foreach (KeyValuePair<int, List<lineclass>> kvp in OverPhege)
                    //{
                    for (int i = 0; i < Overlinp.Count; i++)
                    {
                        newWorksheet.get_Range(newWorksheet.Cells[3 + Overlinp[i].row, 2 * Overlinp[i].linenum + 2], newWorksheet.Cells[3 + Overlinp[i].row, 2 * Overlinp[i].linenum + 3]).Interior.ColorIndex = 3;
                    }

                    //}
                    //补偿法中的数据处理过程

                    newWorksheet1.get_Range(newWorksheet1.Cells[1, 1], newWorksheet1.Cells[1, 2 * buscount + 2]).MergeCells = true;
                    newWorksheet1.get_Range(newWorksheet1.Cells[1, 1], newWorksheet1.Cells[1, 1]).Font.Size = 20;
                    newWorksheet1.get_Range(newWorksheet1.Cells[1, 1], newWorksheet1.Cells[1, 1]).Font.Name = "黑体";
                    newWorksheet1.get_Range(newWorksheet1.Cells[1, 1], newWorksheet1.Cells[1, 1]).HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
                    newWorksheet1.get_Range(newWorksheet1.Cells[2, 1], newWorksheet1.Cells[3, 1]).MergeCells = true;  //补偿法中前面开断合并

                    newWorksheet1.get_Range(newWorksheet1.Cells[2, 2], newWorksheet1.Cells[2, 2 * buscount + 1]).MergeCells = true;
                    newWorksheet1.get_Range(newWorksheet1.Cells[2, 2 * buscount + 2], newWorksheet1.Cells[3, 2 * buscount + 2]).MergeCells = true;   //合格合并
                    newWorksheet1.get_Range(newWorksheet1.Cells[4, 1], newWorksheet1.Cells[4 + brchcount + transcount - 1, 1]).Interior.ColorIndex = 6;
                    for (int i = 0; i < buscount; i++)
                    {
                        newWorksheet1.get_Range(newWorksheet1.Cells[3, 2 * i + 2], newWorksheet1.Cells[3, 2 * i + 3]).MergeCells = true;
                        newWorksheet1.get_Range(newWorksheet1.Cells[3, 2 * i + 2], newWorksheet1.Cells[3, 2 * i + 3]).HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
                    }
                    //newWorksheet1.get_Range(newWorksheet1.Cells[7 + brchcount, 2], newWorksheet1.Cells[7 + brchcount, brchcount + 1]).Interior.ColorIndex = 45;
                    //newWorksheet1.get_Range(newWorksheet1.Cells[8 + brchcount, 1], newWorksheet1.Cells[8 + 2 * brchcount, 1]).Interior.ColorIndex = 6;
                    //newWorksheet1.get_Range(newWorksheet1.Cells[5, 2], newWorksheet1.Cells[newWorksheet1.UsedRange.Rows.Count, brchcount + 1]).NumberFormat = "0.0000_ ";
                    newWorksheet1.get_Range(newWorksheet1.Cells[4, 2], newWorksheet1.Cells[4 + brchcount + transcount, 2 * buscount + 1]).NumberFormat = "@";
                    newWorksheet1.get_Range(newWorksheet1.Cells[1, 1], newWorksheet1.Cells[4 + brchcount + transcount + 1, 2 * buscount + 2]).Font.Name = "楷体_GB2312";
                    //foreach (KeyValuePair<int, int> kvp in OverVhege)
                    //{
                    for (int i = 0; i < OverVp.Count; i++)
                    {
                        newWorksheet1.get_Range(newWorksheet1.Cells[3 + OverVp[i].row, 2 * OverVp[i].linenum + 2], newWorksheet1.Cells[3 + OverVp[i].row, 2 * OverVp[i].linenum + 3]).Interior.ColorIndex = 3;

                    }

                    //}
                    //补偿法中的数据处理过程

                    newWorksheet1.SaveAs(System.Windows.Forms.Application.StartupPath + "\\" + tlVectorControl1.SVGDocument.FileName + "可靠性计算结果.xls", Excel.XlFileFormat.xlXMLSpreadsheet, null, null, false, false, false, null, null, null);

                    result1.Workbooks.Close();
                    result1.Quit();
                    System.Windows.Forms.Clipboard.Clear(); //去掉剪切板中的数据

                    ex = new Excel.Application();
                    ex.Application.Workbooks.Add(System.Windows.Forms.Application.StartupPath + "\\" + tlVectorControl1.SVGDocument.FileName + "可靠性计算结果.xls");
                    ex.Visible = true;

                }
                catch (System.Exception e1)
                {
                    MessageBox.Show("请进行潮流计算后再查看结果!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            if (webn1.DialogResult == DialogResult.Ignore)
            {
                PSPDEV pspDEV = new PSPDEV();
                pspDEV.SvgUID = tlVectorControl1.SVGDocument.CurrentLayer.ID;
                PartRelform selregion = new PartRelform(pspDEV);
                selregion.ShowDialog();
                if (selregion.DialogResult == DialogResult.OK)
                {
                    MessageBox.Show("请选择电网的区域的线路,然后点击鼠标右键进行计算!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    Operateflag = true;
                    tlVectorControl1.CurrentOperation = ToolOperation.Select;
                    //MessageBox.Show("kankankanakna");
                    tlVectorControl1.CurrentOperation = ToolOperation.AreaSelect;

                }
                if (selregion.DialogResult == DialogResult.Ignore)
                {
                    DelLinenum = selregion.lineVnumlist;
                    //DelTransnum = null;
                    QyRelanalyst();
                }
                //IList list1 = Services.BaseService.GetList("SelectPSPDEVBySvgUID", psp);
                //将进行潮流计算的文档传到选择网络中。

                else if (selregion.DialogResult == DialogResult.Yes)
                {
                    DelLinenum = selregion.lineDnumlist;
                    DelTransnum = selregion.lineVnumlist;
                    //DelTransnum = null;
                    QyRelanalyst();
                }
            }
            //Operateflag = false;
        }