private void jianxiancheck() { 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; if (!Check()) { return; } //NIULA pspniula = new NIULA(); //pspniula.CurrentCal(); N1Test.NBcal zl = new NBcal(); //zl.Show_KmRelia(1); zl.ZLpsp(); 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 + "\\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; while (!string.IsNullOrEmpty(strLine)) { array1 = strLine.Split(charSplit); string[] dev = new string[2]; 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; } } } } CR.Name = dev[0]; CR.Type = "Polyline"; CR = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByName", CR); if (CR != null && CR.ReferenceVolt != 0) { volt = CR.ReferenceVolt; } else volt = standvolt; current = capability / (Math.Sqrt(3) * volt); if (CR != null) { if (CR.LineStatus == "待选") { for (int n = 0; n < waitlinecoll.Count; n++) //加入线路功率 { if (waitlinecoll[n].linename == CR.Name) { double linepij = System.Math.Abs(Convert.ToDouble(dev[1])) * capability; XmlNode el = tlVectorControl1.SVGDocument.SelectSingleNode("svg/polyline[@layer='" + tlVectorControl1.SVGDocument.CurrentLayer.ID + "' and @id='" + CR.EleID + "']"); double linevalue = 0; if (!string.IsNullOrEmpty(((XmlElement)el).GetAttribute("linevalue"))) { linevalue = Convert.ToDouble(((XmlElement)el).GetAttribute("linevalue")); } else linevalue = 1; waitlinecoll[n].Suid = CR.SUID; waitlinecoll[n].linepij = linepij; waitlinecoll[n].linevalue = linevalue; waitlinecoll[n].linetouzilv = linepij / linevalue; } } } //output += "'" + CR.Name.ToString() + "," + (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(); } readLine.Close(); waitlinecoll.Sort(); //进行大小排序 然后进行直流方法的检验 bool lineflag = true; //只要有一个不合格则就为不合格 bool jielieflag = true; //判断有没有线路解裂 for (int i = 0; i < waitlinecoll.Count; i++) { N1Test.NBcal kk = new N1Test.NBcal(); kk.Show_KmRelia(waitlinecoll[i].linenum); if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\ZL.txt")) { } else { return; } dh2 = new FileStream(System.Windows.Forms.Application.StartupPath + "\\ZL.txt", FileMode.Open); readLine2 = new StreamReader(dh2); charSplit2 = new char[] { ' ' }; strLine2 = readLine2.ReadLine(); output = null; while (!string.IsNullOrEmpty(strLine2)) { array2 = strLine2.Split(charSplit2); string[] dev = new string[2 * brchcount + 1]; dev.Initialize(); PSPDEV CR = new PSPDEV(); CR.SvgUID = tlVectorControl1.SVGDocument.CurrentLayer.ID; int m = 0; foreach (string str in array2) { if (str != "") { dev[m++] = str.ToString(); } } //进行解裂和负荷判断 if (dev[1] != "-1") { for (int j = 0; j < brchcount; j++) { double pij = System.Math.Abs(Convert.ToDouble(dev[j * 2 + 2])) * capability; PSPDEV psp = new PSPDEV(); psp.Name = dev[j * 2 + 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 (string.IsNullOrEmpty(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; if (pij >= linXij) { lineflag = false; //lineclass _line = new lineclass(n, j); //Overlinp.Add(_line); // OverPhege[n] = j; } } } else { jielieflag = false; } if (jielieflag && lineflag) { readLine2.Close(); //关闭读取的文件 PSPDEV psp = new PSPDEV(); psp.Name = dev[0]; psp.Type = "Polyline"; psp.SvgUID = tlVectorControl1.SVGDocument.CurrentLayer.ID; IList listName = Services.BaseService.GetList("SelectPSPDEVByName", psp); PSPDEV pspline = (PSPDEV)listName[0]; pspline.LineStatus = "等待"; Services.BaseService.Update<PSPDEV>(pspline); jianxiancheck(); //进行下一轮的减线处理 return; } /* else break;*/ strLine2 = readLine2.ReadLine(); } readLine2.Close(); } // readLine2.Close(); }
private void addrightcheck() { 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; //List<PSPDEV> linedengdai = new List<PSPDEV>(); //记录所有待选的线路(一次运行以后就会发生变化) if (!Check()) { return; } PSPDEV pspdev = new PSPDEV(); pspdev.SvgUID = tlVectorControl1.SVGDocument.CurrentLayer.ID; pspdev.LineStatus = "运行"; pspdev.Type = "Polyline"; IList list1 = Services.BaseService.GetList("SelectPSPDEVBySvgUIDAndLineStatus", pspdev); 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; ercilinedengdai.Clear();//清空之前的记录 for (int i = 0; i < list1.Count; i++) { N1Test.NBcal kk = new N1Test.NBcal(); kk.Show_ZLKMPSP(((PSPDEV)list1[i]).Number); if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\ZL.txt")) { } else { return; } dh2 = new FileStream(System.Windows.Forms.Application.StartupPath + "\\ZL.txt", FileMode.Open); readLine2 = new StreamReader(dh2); charSplit2 = new char[] { ' ' }; strLine2 = readLine2.ReadLine(); output = null; bool lineflag = true; bool jielieflag = true; while (!string.IsNullOrEmpty(strLine2)) { array2 = strLine2.Split(charSplit2); string[] dev = new string[2 * brchcount + 1]; dev.Initialize(); PSPDEV CR = new PSPDEV(); CR.SvgUID = tlVectorControl1.SVGDocument.CurrentLayer.ID; int m = 0; foreach (string str in array2) { if (str != "") { dev[m++] = str.ToString(); } } //进行解裂和负荷判断 if (dev[1] != "-1") { for (int j = 0; j < brchcount; j++) { double pij = System.Math.Abs(Convert.ToDouble(dev[j * 2 + 2])) * capability; PSPDEV psp = new PSPDEV(); psp.Name = dev[j * 2 + 1]; psp.Type = "Polyline"; psp.SvgUID = tlVectorControl1.SVGDocument.CurrentLayer.ID; IList listName = Services.BaseService.GetList("SelectPSPDEVByName", psp); PSPDEV pspline = (PSPDEV)listName[0]; if (pspline != null && !pspline.Name.Contains("虚拟线路")) { 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; if (pij >= linXij) { lineflag = false; //lineclass _line = new lineclass(n, j); //Overlinp.Add(_line); // OverPhege[n] = j; } } } } else { jielieflag = false; } strLine2 = readLine2.ReadLine(); } readLine2.Close(); if (!lineflag) { PSPDEV psperci = new PSPDEV(); psperci = (PSPDEV)list1[i]; psperci.LineStatus = "等待"; Services.BaseService.Update<PSPDEV>(psperci); ercilinedengdai.Add(psperci); break; } else //没有出现过负荷 continue; } //新添加的 如果记录二次等待的线路没有则停止下面的运行 表示断开任意一条也没有出现过负荷 if (ercilinedengdai.Count == 0) { return; } //此过程是添加一条线路使其不出现过负荷 fuhecheck(); for (int j = 0; j < linedengdai.Count; j++) { if (!Checkadd(linedengdai[j].EleID)) return; N1Test.NBcal zl = new NBcal(); //zl.Show_KmRelia(1); zl.ZLpsp(); 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; double sumpij = 0.0; bool lineflag = true; while (!string.IsNullOrEmpty(strLine)) { array1 = strLine.Split(charSplit); string[] dev = new string[2]; 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; } } } } CR.Name = dev[0]; CR.Type = "Polyline"; CR = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByName", CR); if (CR != null && CR.ReferenceVolt != 0) { volt = CR.ReferenceVolt; } else volt = standvolt; current = capability / (Math.Sqrt(3) * volt); if (CR != null && !CR.Name.Contains("虚拟线路")) { double linepij = Convert.ToDouble(dev[1]) * capability; double voltR = CR.VoltR; WireCategory wirewire = new WireCategory(); wirewire.WireType = CR.LineType; if (string.IsNullOrEmpty(CR.LineType)) { MessageBox.Show(CR.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; if (linepij >= linXij) { lineflag = false; //sumpij += linepij; } for (int k = 0; k < fuheline.Count; k++) { if (CR.SUID == fuheline[k].Suid) { sumpij += System.Math.Abs(fuheline[k].linepij - linepij); } } // // //output += "'" + CR.Name.ToString() + "," + (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(); } readLine.Close(); //if (lineflag) //如果没有出现过负荷现象 就停止进行加线 //{ // PSPDEV pspb = (PSPDEV)linedengdai[j]; // pspb.LineStatus = "运行"; // Services.BaseService.Update<PSPDEV>(pspb); // lineyiyou.Add(pspb); // for (int i = 0; i < linedengdai.Count; i++) // { // if (linedengdai[i].SUID == pspb.SUID) // { // linedengdai.RemoveAt(j); // } // } // return; //} //else //{ XmlNode el = tlVectorControl1.SVGDocument.SelectSingleNode("svg/polyline[@layer='" + tlVectorControl1.SVGDocument.CurrentLayer.ID + "' and @id='" + linedengdai[j].EleID + "']"); double linevalue = 0; if (!string.IsNullOrEmpty(((XmlElement)el).GetAttribute("linevalue"))) { linevalue = Convert.ToDouble(((XmlElement)el).GetAttribute("linevalue")); } else linevalue = 1; linedaixuan linedai = new linedaixuan(linedengdai[j].Number, linedengdai[j].SUID, linedengdai[j].Name); linedai.linepij = sumpij; linedai.linevalue = linevalue; linedai.linetouzilv = sumpij / linevalue; waitlineindex.Add(linedai); //} } waitlineindex.Sort(); //在此处获得指标最大的线路 将其线路的状态变为 运行并且在运行的集合里面记录 在等待的集合里将其线路去掉 重新进行下一轮的操作 PSPDEV pspbianhua = new PSPDEV(); if (waitlineindex.Count > 0) { pspbianhua.SUID = waitlineindex[waitlineindex.Count - 1].Suid; } else { //MessageBox.Show("没有出现过负荷的线路集,请查看一下线路参数是否设定正确!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } pspbianhua = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByKey", pspbianhua); pspbianhua.LineStatus = "运行"; Services.BaseService.Update<PSPDEV>(pspbianhua); lineyiyou.Add(pspbianhua); for (int i = 0; i < linedengdai.Count; i++) { if (linedengdai[i].SUID == pspbianhua.SUID) { linedengdai.RemoveAt(i); } } waitlineindex.Clear(); }
//记录负荷的线路 private bool fuhecheck() { 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; fuheline.Clear(); //清空上一次的记录 为下一个时期的应用做准备 // linedengdai.Clear(); //清空上一次记录待选线路 为下一个时期的应用做准备 if (!Checkfuhe()) return true; N1Test.NBcal zl = new NBcal(); //zl.Show_KmRelia(1); zl.ZLpsp(); 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 true; } 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 + "\\DH1.txt")) { } else { return true; } dh = new FileStream(System.Windows.Forms.Application.StartupPath + "\\DH1.txt", FileMode.Open); readLine = new StreamReader(dh); charSplit = new char[] { ' ' }; strLine = readLine.ReadLine(); output = null; //double sumpij = 0.0; bool lineflag = true; while (!string.IsNullOrEmpty(strLine)) { array1 = strLine.Split(charSplit); string[] dev = new string[2]; 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; } } } } CR.Name = dev[0]; CR.Type = "Polyline"; CR = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByName", CR); if (CR != null && CR.ReferenceVolt != 0) { volt = CR.ReferenceVolt; } else volt = standvolt; current = capability / (Math.Sqrt(3) * volt); if (CR != null && !CR.Name.Contains("虚拟线路")) { double linepij = System.Math.Abs(Convert.ToDouble(dev[1])) * capability; double voltR = CR.VoltR; WireCategory wirewire = new WireCategory(); wirewire.WireType = CR.LineType; if (string.IsNullOrEmpty(CR.LineType)) { MessageBox.Show(CR.Name + "的线路类型没有输入,无法进行可靠性检验", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return true; } WireCategory listware = (WireCategory)Services.BaseService.GetObject("SelectWireCategoryByKey", wirewire); double Ichange = (double)listware.WireChange; double linXij = System.Math.Sqrt(3) * voltR * Ichange / 1000; if (linepij >= linXij) { lineflag = false; linedaixuan ld = new linedaixuan(CR.Number, CR.SUID, CR.Name); ld.linepij = linepij; fuheline.Add(ld); } // // //output += "'" + CR.Name.ToString() + "," + (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(); } readLine.Close(); return lineflag; }