private void dotNetBarManager1_ItemClick(object sender, EventArgs e)
        {
            DevComponents.DotNetBar.ButtonItem btItem = sender as DevComponents.DotNetBar.ButtonItem;
            //Layer layer1 = (Layer)LayerBox.ComboBoxEx.SelectedItem;
            if (btItem != null)
            {
                switch (btItem.Name)
                {
                    #region 文件操作
                    case "mNew":

                        //NewFile(fileType, this.Text);
                        frmNewProject frmprojectDLG = new frmNewProject();
                        frmprojectDLG.Name = "";
                        frmprojectDLG.FileType = "短路";
                        if (frmprojectDLG.ShowDialog() == DialogResult.OK)
                        {
                            tlVectorControl1.NewFile();
                            PSP_ELCPROJECT pd = new PSP_ELCPROJECT();
                            pd.Name = frmprojectDLG.Name;
                            pd.FileType = frmprojectDLG.FileType;
                            pd.Class = System.DateTime.Now.ToString();
                            pd.ProjectID = this.ProjectUID;
                            tlVectorControl1.SVGDocument.SvgdataUid = pd.ID;
                            SvgDocument.currentLayer = Layer.CreateNew("默认层", tlVectorControl1.SVGDocument).ID;
                            Layer la = tlVectorControl1.SVGDocument.GetLayerByID(SvgDocument.currentLayer);
                            la.SetAttribute("layerType", "电网规划层");
                            Services.BaseService.Create<PSP_ELCPROJECT>(pd);
                            if (pd.ID != null)
                            {
                                Open(pd.ID);
                                intdata(pd.ID);
                                this.Text = frmname + "-" + pd.Name;
                            }
                            this.Show();
                            jxtbar2(2);
                            LoadShape("symbol23.xml");
                        }
                        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;
                            }

                        }
                        OpenProject op = new OpenProject();
                        op.ProjectID = this.ProjectUID;
                        op.Initdata(true);
                        if (op.ShowDialog() == DialogResult.OK)
                        {
                            if (op.FileSUID != null)
                            {
                                Open(op.FileSUID);
                                intdata(op.FileSUID);
                                this.Text = frmname + "-" + op.FileName;
                            }
                            this.Show();
                            jxtbar2(2);
                            LoadShape("symbol23.xml");
                        }
                        break;
                    case "btExSymbol":
                        tlVectorControl1.ExportSymbol();
                        break;
                    case "mjxt"://导入接线图

                        break;
                    case "mSave":
                        Save();
                        //tlVectorControl1.Save();
                        //frmElementName dlg = new frmElementName();
                        //dlg.TextInput = tlVectorControl1.SVGDocument.FileName;
                        //if (dlg.ShowDialog() == DialogResult.OK)
                        //{
                        //    tlVectorControl1.SVGDocument.FileName = dlg.TextInput;
                        //    Save();
                        //}
                        break;
                    case "mExit":
                        this.Close();
                        break;
                    case "bt1":
                        //InitTK();
                        break;
                    case "bt2":
                        break;
                    case "mPriSet":
                        this.tlVectorControl1.Operation = ToolOperation.InterEnclosurePrint;
                        printToolStripMenuItem.Visible = true;
                        break;
                    case "mPrint":
                        tlVectorControl1.Print();

                        break;
                    case "mImport":
                        ExportImage();
                        break;
                    case "mView":
                        //frmSvgView fView = new frmSvgView();
                        //fView.Open(tlVectorControl1.SVGDocument.SvgdataUid);
                        //fView.Show();

                        break;

                    case "deviceparam":
                        frmProjectManager frmPdlg = new frmProjectManager();
                        frmPdlg.SetMode(tlVectorControl1.SVGDocument.SvgdataUid);
                        frmPdlg.ShowDialog();
                        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":

                        break;
                    case "Dlqibutt":
                        break;
                    //MessageBox.Show("请选中母线点,然后点击右键输入断路器属性" "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    //duluqiflag=true;
                    //基础操作
                    case "mFreeTransform":
                        tlVectorControl1.Operation = ToolOperation.FreeTransform;

                        break;
                    case "mCJ":
                        tlVectorControl1.Operation = ToolOperation.PolyLine;
                        csOperation = CustomOperation.OP_MeasureDistance;
                        break;
                    //case "ButtonItem2":
                    //    break;
                    #endregion
                    #region 无功优化参数维护
                    case "VoltLimit":
                        break;
                    case "GeneratorLimit":
                        break;
                    case "TransformLimit":
                        break;
                    case "SVC":
                        break;
                    #endregion
                    #region 基础图元
                    case "mLayer":
                        tlVectorControl1.LayerManager();
                        break;
                    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;
                        //tlVectorControl1.Operation = ToolOperation.ConnectLine_Polyline;
                        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":

                        break;
                    case "ButtonItem8":

                        break;
                    case "mCheck":
                        break;
                    case "niula":
                        break;
                    case "pq":

                        break;

                    case "GaussSeidel":

                        break;
                    case "PowerLossCal":

                        break;
                    case "N_RZYz":

                        break;
                    case "WebRela":                        //进行网络N-1检验

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

                        break;
                    case "Shortibut":
                        if (!addcheck())  //检验是不是还有元件需要添加

                            return;
                        ElectricShorti elc = new ElectricShorti();
                       string strID =tlVectorControl1.SVGDocument.SvgdataUid;
                        //elc.CheckDL(strID, 100);
                        int n3 = 0;
                        ShortTform shorttype = new ShortTform();
                        frnReport wduanlu = new frnReport();
                        wduanlu.Owner = this;
                        wduanlu.Text = this.Text;
                        wduanlu.Show();
                        wduanlu.ShowText += "进行相关设置\t" + System.DateTime.Now.ToString();
                        shorttype.ShowDialog();
                        if (shorttype.DialogResult == DialogResult.OK)
                        {
                            switch (shorttype.DuanluType)
                            {
                                case "单相接地":
                                    n3 = 1;
                                    break;

                                case "两相接地":
                                    n3 = 3;
                                    break;
                                case "两相故障":
                                    n3 = 2;
                                    break;
                                case "三相故障":
                                    n3 = 0;
                                    break;

                            }
                            elc.OutType = shorttype.Mathindex;
                        }
                        //elc.P1 = strID; elc.P2 = this.ProjectUID; elc.P3 = n3; elc.P4 = 100;
                        //Thread wait = new Thread(new ThreadStart(elc.temp));
                        //wait.Start();
                       // WaitDialogForm wait = null;
                        try
                        {
                            //wait = new WaitDialogForm("", "正在处理数据, 请稍候...");
                            elc.AllShort(strID, this.ProjectUID, n3, 100,wduanlu);
                           // wait.Close();
                        }
                        catch (Exception exc)
                        {
                            Debug.Fail(exc.Message);
                            HandleException.TryCatch(exc);
                            //wait.Close();
                            wduanlu.ShowText += "\r\n短路计算失败" + System.DateTime.Now.ToString();
                            return;
                        }

                        break;
                    case "ZLcheck":

                       elc = new ElectricShorti();

                        strID = tlVectorControl1.SVGDocument.SvgdataUid;
                        WaitDialogForm wait = null;
                        try
                        {
                            wait = new WaitDialogForm("", "正在处理数据, 请稍候...");
                            wait.Close();
                            elc.Allshortcheck(strID, this.ProjectUID, 100, 3);

                        }
                        catch (Exception exc)
                        {
                            Debug.Fail(exc.Message);
                            Itop.Client.Common.HandleException.TryCatch(exc);
                            wait.Close();
                            return;
                        }

                       // Allshortcheck(3);
                        dotNetBarManager1.Bars["bar2"].GetItem("ZLcheck").Enabled = false;
                        dotNetBarManager1.Bars["bar2"].GetItem("Jiaoliucheck").Enabled = true;
                        //dotNetBarManager1.Bars["bar2"].GetItem("DLqiOutResult").Enabled =true;
                        break;
                    case "Jiaoliucheck":
                       elc = new ElectricShorti();

                        strID = tlVectorControl1.SVGDocument.SvgdataUid;
                     wait = null;
                        try
                        {
                            wait = new WaitDialogForm("", "正在处理数据, 请稍候...");
                            wait.Close();
                            elc.Allshortcheck(strID, this.ProjectUID, 100, 2);

                        }
                        catch (Exception exc)
                        {
                            Debug.Fail(exc.Message);
                            Itop.Client.Common.HandleException.TryCatch(exc);
                            wait.Close();
                            return;

                        }
                       // Allshortcheck(2);
                        dotNetBarManager1.Bars["bar2"].GetItem("Jiaoliucheck").Enabled = false;
                        dotNetBarManager1.Bars["bar2"].GetItem("ZLcheck").Enabled = true;
                        break;
                    case "dd":
                        //SubPrint = true;
                        tlVectorControl1.Operation = ToolOperation.InterEnclosurePrint;
                        break;

                    case "NiulaResult":

                        break;
                    case "GaussSeidelResult":

                        break;
                    case "N_RZYzResult":

                        break;
                    case "VoltEvaluation":
                        break;
                    case "PowerLoss":

                        break;
                    case "ZLPResult1":

                        break;

                    case "mDLR":

                        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":

                        break;
                    #endregion

                    #region 视图
                    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.SvgdataUid;
                                    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;
                    case "PSPIdleOptimize":
                        break;
                    #endregion
                    #region 参数维护
                    case "mNodeParam":

                        break;
                    case "mLineParam":

                        break;
                    case "mWire":

                        break;
                    case "nTransformLineParam":

                        break;
                    case "nGNDLineParam":

                        break;
                    case "mLineDL":

                        break;
                    case "mFadianDL":

                        break;
                    case "mConvert":

                        break;

                    #endregion
                }
            }
        }
        private void contextMenuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            frnReport wFrom = new frnReport();
            if (e.ClickedItem.Text == "属性")
            {
                elementProperty();
            }
            tlVectorControl1.Operation = ToolOperation.Select;
            if (e.ClickedItem.Text == "短路计算")
            {

                wFrom.Owner = this;
                wFrom.Show();
                wFrom.Text = this.Text + "短路计算";
                wFrom.ShowText += "正在收集信息\t" + System.DateTime.Now.ToString();
                if (!addcheck(wFrom))
                {

                    return;
                }
                string duanluname = null;        //记录短路点的名字 如果是发生在支路上短路点的名字为线路连接的第一个母线名
                int tuxing = 0;
                int baobiao = 0;
                PSPDEV pspDuanlu = new PSPDEV();
                XmlElement element = tlVectorControl1.SVGDocument.CurrentElement;
                pspDuanlu.SUID = element.GetAttribute("Deviceid");
                pspDuanlu = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByKey", pspDuanlu);
                if (pspDuanlu == null)
                    return;
                if (pspDuanlu.Type != "05" && pspDuanlu.Type != "01")
                    return;
                frmDuanlu dudu = new frmDuanlu(pspDuanlu);
                dudu.projectsuid = tlVectorControl1.SVGDocument.SvgdataUid;
                ElectricShorti lec = new ElectricShorti();
                int n11 = 0, n2 = 0, n3 = 0;
                double n4 = 0;

                if (dudu.ShowDialog() == DialogResult.OK)
                {
                    //int bigsmall=Convert.ToInt32(dudu.DuanluBigsmall);
                    try
                    {
                        if (!lec.CheckDL(tlVectorControl1.SVGDocument.SvgdataUid, this.ProjectUID, 100))
                            return;
                        string nodeType;
                        if (dudu.DuanluBaobiao == "是")
                            baobiao = 1;
                        if (dudu.DuanluTuxing == "图形输出节点电压")
                            tuxing = 1;
                        if (dudu.DuanluTuxing == "图形输出短路电流")
                            tuxing = 2;
                        //Duanlu.Name = dudu.DuanluPoint;
                        //Duanlu = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByName", Duanlu);
                        n4 = (double)Convert.ToInt32(dudu.hscool) / 100;
                        nodeType = pspDuanlu.Type;
                        if (pspDuanlu.Type == "01")
                        {
                            n11 = 0;
                            n2 = pspDuanlu.Number;
                            switch (dudu.DuanluType)
                            {
                                case "单相接地":
                                    n3 = 1;
                                    break;

                                case "两相接地":
                                    n3 = 3;
                                    break;
                                case "两相故障":
                                    n3 = 2;
                                    break;
                                case "三相故障":
                                    n3 = 0;
                                    break;
                                default:
                                    n3 = 1;
                                    break;
                            }

                            string con = " ,PSP_ELCDEVICE WHERE PSPDEV.SUID = PSP_ELCDEVICE.DeviceSUID AND PSP_ELCDEVICE.ProjectSUID = '" + tlVectorControl1.SVGDocument.SvgdataUid+ "'AND PSPDEV.type='05'AND PSPDEV.KSwitchStatus = '0'order by PSPDEV.number";
                            PSPDEV psp = new PSPDEV();
                            IList list2 = Services.BaseService.GetList("SelectPSPDEVByCondition", con); ;
                            string dlr = null;
                            bool flag = false;             //记录读的是一般线路还是两绕组变压器上的母线还是三绕组上面的

                            string projectid = this.ProjectUID;
                            for (int i = 0; i < list2.Count; i++)
                            {
                                psp = list2[i] as PSPDEV;
                                con = " WHERE Name='" + psp.ISwitch + "' AND ProjectID = '" + projectid + "'" + "AND Type='07'";
                                IList listiswitch = Services.BaseService.GetList("SelectPSPDEVByCondition", con);
                                con = " WHERE Name='" + psp.JSwitch + "' AND ProjectID = '" + projectid + "'" + "AND Type='07'";
                                IList listjswitch = Services.BaseService.GetList("SelectPSPDEVByCondition", con);
                                PSPDEV pspiswitch = (PSPDEV)listiswitch[0];
                                PSPDEV pspjswitch = (PSPDEV)listjswitch[0];

                                if (pspDuanlu.Number == psp.FirstNode && pspiswitch.KSwitchStatus == "0" && pspjswitch.KSwitchStatus == "0")
                                {

                                    flag = true;
                                    dlr = "0" + " " + psp.FirstNode + " " + psp.LastNode + " " + psp.Number + " " + "0 " + " " + n3.ToString();

                                }
                                if (pspDuanlu.Number == psp.LastNode && pspiswitch.KSwitchStatus == "0" && pspjswitch.KSwitchStatus == "0")
                                {
                                    flag = true;
                                    dlr = "0" + " " + psp.FirstNode + " " + psp.LastNode + " " + psp.Number + " " + "1 " + " " + n3.ToString();
                                }
                                if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\fault.txt"))
                                {
                                    File.Delete(System.Windows.Forms.Application.StartupPath + "\\fault.txt");
                                }
                                if (flag)
                                {

                                    break;                 //跳出本循环 进行母线的另外一个母线短路

                                }
                                if (!flag)
                                    continue;
                                //写入错误中

                            }
                            if (!flag)
                            {
                                  con = " ,PSP_ELCDEVICE WHERE PSPDEV.SUID = PSP_ELCDEVICE.DeviceSUID AND PSP_ELCDEVICE.ProjectSUID = '" + tlVectorControl1.SVGDocument.SvgdataUid + "'AND PSPDEV.type='02'AND PSPDEV.KSwitchStatus = '0' order by PSPDEV.number";
                                IList list3 = Services.BaseService.GetList("SelectPSPDEVByCondition", con);
                                for (int i = 0; i < list3.Count; i++)
                                {
                                    dlr = null;
                                    psp = list3[i] as PSPDEV;
                                    PSPDEV devFirst = new PSPDEV();

                                    con = " WHERE Name='" + psp.IName + "' AND ProjectID = '" + projectid + "'" + "AND Type='01'";
                                    devFirst = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByCondition", con);
                                    PSPDEV devLast = new PSPDEV();

                                    con = " WHERE Name='" + psp.JName + "' AND ProjectID = '" + projectid + "'" + "AND Type='01'";
                                    devLast = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByCondition", con);
                                    con = " WHERE Name='" + psp.ISwitch + "' AND ProjectID = '" + projectid + "'" + "AND Type='07'";
                                    IList listiswitch = Services.BaseService.GetList("SelectPSPDEVByCondition", con);
                                    con = " WHERE Name='" + psp.JSwitch + "' AND ProjectID = '" + projectid + "'" + "AND Type='07'";
                                    IList listjswitch = Services.BaseService.GetList("SelectPSPDEVByCondition", con);
                                    PSPDEV pspiswitch = (PSPDEV)listiswitch[0];
                                    PSPDEV pspjswitch = (PSPDEV)listjswitch[0];
                                    if (pspDuanlu.Number == devFirst.Number && pspiswitch.KSwitchStatus == "0" && pspjswitch.KSwitchStatus == "0")
                                    {

                                        flag = true;
                                        dlr = "0" + " " + devFirst.Number + " " + devLast.Number + " " + psp.Number + " " + "0" + " " + n3.ToString();

                                    }
                                    if (pspDuanlu.Number == devLast.Number && pspiswitch.KSwitchStatus == "0" && pspjswitch.KSwitchStatus == "0")
                                    {
                                        flag = true;
                                        dlr = "0" + " " + devFirst.Number + " " + devLast.Number + " " + psp.Number + " " + "1" + " " + n3.ToString();
                                    }
                                    if (flag)
                                    {
                                        break;                 //跳出本循环 进行母线的另外一个母线短路

                                    }
                                    if (!flag)
                                        continue;
                                    //写入错误中

                                }
                            }
                            if (!flag)
                            {
                                con = " ,PSP_ELCDEVICE WHERE PSPDEV.SUID = PSP_ELCDEVICE.DeviceSUID AND PSP_ELCDEVICE.ProjectSUID = '" + tlVectorControl1.SVGDocument.SvgdataUid + "'AND PSPDEV.type='03'AND PSPDEV.KSwitchStatus = '0' order by PSPDEV.number";
                                IList list4 = Services.BaseService.GetList("SelectPSPDEVByCondition", con);
                                for (int i = 0; i < list4.Count; i++)
                                {
                                    dlr = null;
                                    psp = list4[i] as PSPDEV;
                                    PSPDEV devINode = new PSPDEV();

                                    con = " WHERE Name='" + psp.IName + "' AND ProjectID = '" + projectid + "'" + "AND Type='01'";
                                    devINode = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByCondition", con);
                                    PSPDEV devJNode = new PSPDEV();

                                    con = " WHERE Name='" + psp.JName + "' AND ProjectID = '" + projectid + "'" + "AND Type='01'";
                                    devJNode = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByCondition", con);
                                    PSPDEV devKNode = new PSPDEV();

                                    con = " WHERE Name='" + psp.KName + "' AND ProjectID = '" + projectid + "'" + "AND Type='01'";
                                    devKNode = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByCondition", con);

                                    con = " WHERE Name='" + psp.ISwitch + "' AND ProjectID = '" + projectid + "'" + "AND Type='07'";
                                    IList listiswitch = Services.BaseService.GetList("SelectPSPDEVByCondition", con);
                                    con = " WHERE Name='" + psp.JSwitch + "' AND ProjectID = '" + projectid + "'" + "AND Type='07'";
                                    IList listjswitch = Services.BaseService.GetList("SelectPSPDEVByCondition", con);
                                    con = " WHERE Name='" + psp.HuganLine1 + "' AND ProjectID = '" + projectid + "'" + "AND Type='07'";
                                    IList listkswitch = Services.BaseService.GetList("SelectPSPDEVByCondition", con);
                                    PSPDEV pspiswitch = (PSPDEV)listiswitch[0];
                                    PSPDEV pspjswitch = (PSPDEV)listjswitch[0];
                                    PSPDEV pspkswitch = (PSPDEV)listkswitch[0];
                                    if (pspDuanlu.Number == devINode.Number && pspiswitch.KSwitchStatus == "0" && pspjswitch.KSwitchStatus == "0" && pspkswitch.KSwitchStatus == "0")
                                    {

                                        flag = true;
                                        dlr = "0" + " " + devINode.Number + " " + devJNode.Number + " " + psp.Number + " " + "0" + " " + n3.ToString();

                                    }
                                    if (pspDuanlu.Number == devJNode.Number && pspiswitch.KSwitchStatus == "0" && pspjswitch.KSwitchStatus == "0" && pspkswitch.KSwitchStatus == "0")
                                    {
                                        flag = true;
                                        dlr = "0" + " " + devINode.Number + " " + devJNode.Number + " " + psp.Number + " " + "1" + " " + n3.ToString();
                                    }
                                    if (pspDuanlu.Number == devKNode.Number && pspiswitch.KSwitchStatus == "0" && pspjswitch.KSwitchStatus == "0" && pspkswitch.KSwitchStatus == "0")
                                    {
                                        flag = true;
                                        dlr = "0" + " " + devINode.Number + " " + devKNode.Number + " " + psp.Number + " " + "1" + " " + n3.ToString();
                                    }

                                    if (flag)
                                    {
                                        break;                 //跳出本循环 进行母线的另外一个母线短路

                                    }
                                    if (!flag)
                                        continue;
                                    //写入错误中

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

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

                        }
                        else if (pspDuanlu.Type == "05")
                        {
                            //n11 = pspDuanlu.FirstNode;
                            //n2 = pspDuanlu.LastNode;
                            n11 = pspDuanlu.Number;
                            n2 = n11;
                            switch (dudu.DuanluType)
                            {
                                case "单相接地":
                                    n3 = 1;
                                    break;

                                case "两相接地":
                                    n3 = 3;
                                    break;
                                case "两相故障":
                                    n3 = 2;
                                    break;
                                case "三相故障":
                                    n3 = 0;
                                    break;
                                default:
                                    n3 = 0;
                                    break;
                            }
                            string dlr = null;
                            if (n4 < 1 && n4 > 0)
                            {
                                duanluname = pspDuanlu.Name;
                            }
                            dlr = "0" + " " + pspDuanlu.FirstNode + " " + pspDuanlu.LastNode + " " + pspDuanlu.Number + " " + n4 + " " + n3.ToString();

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

                            FileStream VK = new FileStream((System.Windows.Forms.Application.StartupPath + "\\fault.txt"), FileMode.OpenOrCreate);
                            StreamWriter str11 = new StreamWriter(VK);
                            str11.Write(dlr);
                            str11.Close();
                        }
                        else
                        {
                            return;
                        }
                        XmlNodeList list = tlVectorControl1.SVGDocument.SelectNodes("svg/*[@flag='" + "1" + "']");
                        foreach (XmlNode node in list)
                        {
                            SvgElement elementde = node as SvgElement;
                            tlVectorControl1.SVGDocument.CurrentElement = elementde;
                            tlVectorControl1.Delete();
                        }
                        wFrom.ShowText += "\r\n进行短路计算!" + System.DateTime.Now.ToString();
                        shortcir shortCutCal = new shortcir();
                        shortCutCal.Show_shortcir(0,0);
                        //bool matrixflag=true;                //用来判断是否导纳矩阵的逆矩阵是否存在逆矩阵

                        string matrixstr = null;
                        if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\Zmatrixcheck.txt"))
                        {
                            matrixstr = "正序导纳矩阵";
                            // matrixflag = false;
                        }
                        if (matrixstr != null)
                        {
                            matrixstr += ",";
                        }
                        if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\Fmatrixcheck.txt"))
                        {
                            // matrixflag = false;
                            matrixstr += "负序导纳矩阵";
                        }
                        if (matrixstr != null)
                        {
                            matrixstr += ",";
                        }
                        if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\Lmatrixcheck.txt"))
                        {
                            //matrixflag = false;
                            matrixstr += "零序导纳矩阵";
                        }
                        if (matrixstr != null)
                        {
                            wFrom.ShowText += "\r\n" + matrixstr + "不存在逆矩阵,请调整参数后再进行计算!" + System.DateTime.Now.ToString();
                            //MessageBox.Show(matrixstr + "不存在逆矩阵,请调整参数后再进行计算!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return;
                        }
                        string duanResult = null;
                        duanResult += "短路电流简表" + "\r\n" + "\r\n";
                        if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\ShortcuitI.txt"))
                        {
                        }
                        else
                        {
                            return;
                        }
                         wFrom.ShowText += "\r\n结果显示!" + System.DateTime.Now.ToString();
                        FileStream shorcuit = new FileStream(System.Windows.Forms.Application.StartupPath + "\\ShortcuitI.txt", FileMode.Open);
                        StreamReader readLineGU = new StreamReader(shorcuit, System.Text.Encoding.Default);
                        string strLineGU;
                        string[] arrayGU;
                        char[] charSplitGU = new char[] { ' ' };
                        strLineGU = readLineGU.ReadLine();
                         int j = 0;
                        while (strLineGU != null)
                        {
                            arrayGU = strLineGU.Split(charSplitGU);
                            int i = 0;
                            string[] dev = new string[9];
                            dev.Initialize();
                            foreach (string str in arrayGU)
                            {
                                if (str != "")
                                {
                                    dev[i++] = str;
                                }
                            }
                            if (tuxing == 2 && j != 0)
                            {
                                PSPDEV CR = new PSPDEV();

                                if (dev[1] != "du")
                                {
                                   string con = " ,PSP_ELCDEVICE WHERE PSPDEV.SUID = PSP_ELCDEVICE.DeviceSUID AND PSP_ELCDEVICE.ProjectSUID = '" + tlVectorControl1.SVGDocument.SvgdataUid + "'AND PSPDEV.Name='" + dev[1] + "'";
                                    CR = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByCondition", con);
                                }
                                else
                                {
                                    string con = " ,PSP_ELCDEVICE WHERE PSPDEV.SUID = PSP_ELCDEVICE.DeviceSUID AND PSP_ELCDEVICE.ProjectSUID = '" + tlVectorControl1.SVGDocument.SvgdataUid + "'AND PSPDEV.Name='" + duanluname + "'AND PSPDEV.Type='05'";
                                    CR = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByCondition", con);
                                }

                                if (CR != null)
                                {
                                    if (CR.Type != "05")
                                    {
                                        XmlElement elementdl = tlVectorControl1.SVGDocument.SelectSingleNode("svg/*[@Deviceid='" + CR.SUID + "']") as XmlElement;

                                        if (elementdl != null)
                                        {
                                            RectangleF bound = ((IGraph)elementdl).GetBounds();
                                            XmlElement n1 = 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[3]) * 100 / (Math.Sqrt(3) * CR.ReferenceVolt)).ToString("N4");
                                            n1.SetAttribute("layer", SvgDocument.currentLayer);
                                            n1.SetAttribute("flag", "1");
                                            n1.SetAttribute("stroke", "#FF0000");
                                            tlVectorControl1.SVGDocument.RootElement.AppendChild(n1);
                                            tlVectorControl1.Operation = ToolOperation.Select;
                                            tlVectorControl1.Refresh();
                                        }
                                    }
                                    else
                                    {
                                        XmlElement elementdl = tlVectorControl1.SVGDocument.SelectSingleNode("svg/*[@Deviceid='" + CR.SUID + "']") as XmlElement;

                                        if (elementdl != null)
                                        {
                                            PointF[] t = ((Polyline)elementdl).Points;

                                            PointF[] t2 = ((Polyline)elementdl).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)elementdl).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 n2dl = tlVectorControl1.SVGDocument.CreateElement("polyline") as Polyline;
                                            PointF pStart = new PointF(center.X + (float)(15 * Math.Sin((angel) * Math.PI / 180)), center.Y - (float)(15 * Math.Cos((angel) * Math.PI / 180)));
                                            PSPDEV psp = new PSPDEV();
                                            psp.FirstNode = CR.FirstNode;
                                            psp.LastNode = CR.LastNode;
                                            string con = " ,PSP_ELCDEVICE WHERE PSPDEV.SUID = PSP_ELCDEVICE.DeviceSUID AND PSP_ELCDEVICE.ProjectSUID = '" + tlVectorControl1.SVGDocument.SvgdataUid + "'AND PSPDEV.FirstNode='" + CR.FirstNode + "'AND PSPDEV.LastNode='"+CR.LastNode+"'";
                                            IList listParallel = Services.BaseService.GetList("SelectPSPDEVByCondition", con);

                                            PSPDEV tempss = new PSPDEV();

                                            foreach (PSPDEV devP in listParallel)
                                            {
                                                if ((angel > 10 && angel < 90) || (angel < 0 && Math.Abs(angel) < 90) || (angel > 180 && angel < 350))
                                                {
                                                    if (((devP.X1) > (CR.X1)))
                                                    {
                                                        pStart = 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) > (CR.Y1)))
                                                    {
                                                        pStart = 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) > (CR.Y1)))
                                                    {
                                                        pStart = new PointF(center.X - (float)(7 * Math.Sin((angel) * Math.PI / 180)), center.Y + (float)(7 * 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));

                                            //if (Convert.ToDouble(dev[4]) >= 0)
                                            //{
                                            n1.InnerText = (Math.Abs(Convert.ToDouble(dev[3]) * 100 / (Math.Sqrt(3) * CR.ReferenceVolt))).ToString("N4");
                                            //}
                                            //else
                                            //{
                                            //    n1.InnerText = (Math.Abs(Convert.ToDouble(dev[3]))).ToString("N4");
                                            //}
                                            n1.SetAttribute("layer", SvgDocument.currentLayer);
                                            n1.SetAttribute("flag", "1");

                                            //if (Convert.ToDouble(dev[5]) == 1)
                                            //    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(dev[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);

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

                                            tlVectorControl1.SVGDocument.CurrentElement = n1 as SvgElement;

                                            RectangleF ttt = ((Polyline)elementdl).GetBounds();

                                            tlVectorControl1.RotateSelection(angel, pStart);
                                            if (Math.Abs(angel) > 90)
                                                tlVectorControl1.RotateSelection(180, pStart);
                                            PointF newp = new PointF(center.X + 10, center.Y + 10);

                                            tlVectorControl1.Refresh();

                                        }
                                    }
                                }
                                if (CR.NodeType == "05")
                                {
                                    PSPDEV fl = new PSPDEV();
                                    string con = " ,PSP_ELCDEVICE WHERE PSPDEV.SUID = PSP_ELCDEVICE.DeviceSUID AND PSP_ELCDEVICE.ProjectSUID = '" + tlVectorControl1.SVGDocument.SvgdataUid + "'AND PSPDEV.Number='" + CR.FirstNode +"'";
                                    fl = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByCondition", con);
                                    duanResult += dev[0] + "," + dev[1] + "," + Convert.ToDouble(dev[3]) * 100 / (Math.Sqrt(3) * fl.ReferenceVolt) + "\r\n";
                                }
                                else
                                {
                                    duanResult += dev[0] + "," + dev[1] + "," + Convert.ToDouble(dev[3]) * 100 / (Math.Sqrt(3) * CR.ReferenceVolt) + "\r\n";
                                }

                            }
                            else if (tuxing==1&&j!=0)
                            {
                                PSPDEV CR = new PSPDEV();

                                if (dev[1] != "du")
                                {
                                    string con = " ,PSP_ELCDEVICE WHERE PSPDEV.SUID = PSP_ELCDEVICE.DeviceSUID AND PSP_ELCDEVICE.ProjectSUID = '" + tlVectorControl1.SVGDocument.SvgdataUid + "'AND PSPDEV.Name='" + dev[1] + "'";
                                    CR = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByCondition", con);
                                }
                                else
                                {
                                    string con = " ,PSP_ELCDEVICE WHERE PSPDEV.SUID = PSP_ELCDEVICE.DeviceSUID AND PSP_ELCDEVICE.ProjectSUID = '" + tlVectorControl1.SVGDocument.SvgdataUid + "'AND PSPDEV.Name='" + duanluname + "'AND PSPDEV.Type='05'";
                                    CR = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByCondition", con);
                                }

                                if (CR.NodeType == "05")
                                {
                                    PSPDEV fl = new PSPDEV();
                                    string con = " ,PSP_ELCDEVICE WHERE PSPDEV.SUID = PSP_ELCDEVICE.DeviceSUID AND PSP_ELCDEVICE.ProjectSUID = '" + tlVectorControl1.SVGDocument.SvgdataUid + "'AND PSPDEV.Number='" + CR.FirstNode + "'";
                                    fl = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByCondition", con);
                                    duanResult += dev[0] + "," + dev[1] + "," + Convert.ToDouble(dev[3]) * 100 / (Math.Sqrt(3) * fl.ReferenceVolt) + "\r\n";
                                }
                                else
                                {
                                    duanResult += dev[0] + "," + dev[1] + "," + Convert.ToDouble(dev[3]) * 100 / (Math.Sqrt(3) * CR.ReferenceVolt) + "\r\n";
                                }
                            }
                            else if (j==0)
                            {
                                duanResult += dev[0] + "," + dev[1] + "," + dev[3]+ "\r\n";
                            }
                            strLineGU = readLineGU.ReadLine();
                            j++;
                        }
                        readLineGU.Close();
                        string dianYaResult = null;
                        dianYaResult += "母线电压结果" + "\r\n" + "\r\n";
                        if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\Sxdianya.txt"))
                        {
                        }
                        else
                        {
                            return;
                        }
                        FileStream dianYa = new FileStream(System.Windows.Forms.Application.StartupPath + "\\Sxdianya.txt", FileMode.Open);
                        StreamReader readLineDY = new StreamReader(dianYa, System.Text.Encoding.Default);
                        string strLineDY;
                        string[] arrayDY;
                        char[] charSplitDY = new char[] { ' ' };
                        strLineDY = readLineDY.ReadLine();
                        j = 0;
                        while (strLineDY != null)
                        {
                            arrayDY = strLineDY.Split(charSplitDY);
                            int i = 0;
                            string[] dev = new string[14];
                            dev.Initialize();
                            foreach (string str in arrayDY)
                            {
                                if (str != "")
                                {
                                    dev[i++] = str;
                                }
                            }
                            if (j == 0)
                            {
                                dianYaResult += dev[0] + "," + dev[1] + "," + dev[2] + "," + dev[3] + "," + dev[4] + "," + dev[5] + "," + dev[6] + "," + dev[7] + "," + dev[8] + "," +
             dev[9] + "," + dev[10] + "," + dev[11] + "," + dev[12] + "," + dev[13] + "\r\n";
                            }
                            else
                            {
                                bool flag = true;     //判断此母线是短路点母线还是一般的母线
                                PSPDEV CR = new PSPDEV();

                                if (dev[1] != "du")
                                {
                                    string con = " ,PSP_ELCDEVICE WHERE PSPDEV.SUID = PSP_ELCDEVICE.DeviceSUID AND PSP_ELCDEVICE.ProjectSUID = '" + tlVectorControl1.SVGDocument.SvgdataUid + "'AND PSPDEV.Name='" + dev[1] + "'";
                                    CR = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByCondition", con); ;
                                }
                                else
                                {
                                    flag = false;
                                    string con = " ,PSP_ELCDEVICE WHERE PSPDEV.SUID = PSP_ELCDEVICE.DeviceSUID AND PSP_ELCDEVICE.ProjectSUID = '" + tlVectorControl1.SVGDocument.SvgdataUid + "'AND PSPDEV.Name='" + duanluname + "'AND PSPDEV.Type='05'";
                                    CR = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByCondition", con);
                                }

                                //CR = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByNameANDSVG", CR);
                                if (tuxing == 1)
                                {
                                    XmlElement elementdl = tlVectorControl1.SVGDocument.SelectSingleNode("svg/*[@Deviceid='" + CR.SUID + "']") as XmlElement;

                                    if (elementdl != null)
                                    {
                                        RectangleF bound = ((IGraph)elementdl).GetBounds();
                                        XmlElement n1 = tlVectorControl1.SVGDocument.CreateElement("text") as Text;
                                        XmlElement n22 = tlVectorControl1.SVGDocument.CreateElement("text") as Text;
                                        XmlElement n33 = tlVectorControl1.SVGDocument.CreateElement("text") as Text;
                                        n1.SetAttribute("x", Convert.ToString(bound.X));
                                        n1.SetAttribute("y", Convert.ToString(bound.Y - 60));
                                        n1.InnerText = "A相:" + (Convert.ToDouble(dev[2]) * CR.ReferenceVolt).ToString("N4") + "kV/" + (Convert.ToDouble(dev[3])).ToString("N4") + "°";
                                        n1.SetAttribute("layer", SvgDocument.currentLayer);
                                        n1.SetAttribute("flag", "1");
                                        tlVectorControl1.SVGDocument.RootElement.AppendChild(n1);
                                        tlVectorControl1.Operation = ToolOperation.Select;
                                        tlVectorControl1.Refresh();
                                        n22.SetAttribute("x", Convert.ToString(bound.X));
                                        n22.SetAttribute("y", Convert.ToString(bound.Y - 40));
                                        n22.InnerText = "B相:" + (Convert.ToDouble(dev[4]) * CR.ReferenceVolt).ToString("N4") + "kV/" + (Convert.ToDouble(dev[5])).ToString("N4") + "°";
                                        n22.SetAttribute("layer", SvgDocument.currentLayer);
                                        n22.SetAttribute("flag", "1");
                                        tlVectorControl1.SVGDocument.RootElement.AppendChild(n22);
                                        tlVectorControl1.Operation = ToolOperation.Select;
                                        tlVectorControl1.Refresh();
                                        n33.SetAttribute("x", Convert.ToString(bound.X));
                                        n33.SetAttribute("y", Convert.ToString(bound.Y - 20));
                                        n33.InnerText = "C相:" + (Convert.ToDouble(dev[6]) * CR.ReferenceVolt).ToString("N4") + "kV/" + (Convert.ToDouble(dev[7])).ToString("N4") + "°";
                                        n33.SetAttribute("layer", SvgDocument.currentLayer);
                                        n33.SetAttribute("flag", "1");
                                        tlVectorControl1.SVGDocument.RootElement.AppendChild(n33);
                                        tlVectorControl1.Operation = ToolOperation.Select;
                                        tlVectorControl1.Refresh();
                                    }
                                }
                                if (flag)
                                    dianYaResult += dev[0] + "," + dev[1] + "," + Convert.ToDouble(dev[2]) * CR.ReferenceVolt + "," + dev[3] + "," + Convert.ToDouble(dev[4]) * CR.ReferenceVolt + "," + dev[5] + "," + Convert.ToDouble(dev[6]) * CR.ReferenceVolt + "," + dev[7] + "," + Convert.ToDouble(dev[8]) * CR.ReferenceVolt + "," +
                                        dev[9] + "," + Convert.ToDouble(dev[10]) * CR.ReferenceVolt + "," + dev[11] + "," + Convert.ToDouble(dev[12]) * CR.ReferenceVolt + "," + dev[13] + "\r\n";
                                else
                                    dianYaResult += dev[0] + "," + duanluname + "上短路点" + "," + Convert.ToDouble(dev[2]) * CR.ReferenceVolt + "," + dev[3] + "," + Convert.ToDouble(dev[4]) * CR.ReferenceVolt + "," + dev[5] + "," + Convert.ToDouble(dev[6]) * CR.ReferenceVolt + "," + dev[7] + "," + Convert.ToDouble(dev[8]) * CR.ReferenceVolt + "," +
                                       dev[9] + "," + Convert.ToDouble(dev[10]) * CR.ReferenceVolt + "," + dev[11] + Convert.ToDouble(dev[12]) * CR.ReferenceVolt + "," + dev[13] + "\r\n";

                            }
                            strLineDY = readLineDY.ReadLine();
                            j++;
                        }
                        readLineDY.Close();
                        string dianLiuResult = null;
                        dianLiuResult += "支路电流结果" + "\r\n" + "\r\n";
                        if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\Sxdianliu.txt"))
                        {
                        }
                        else
                        {
                            return;
                        }
                        FileStream dianLiu = new FileStream(System.Windows.Forms.Application.StartupPath + "\\Sxdianliu.txt", FileMode.Open);
                        StreamReader readLineDL = new StreamReader(dianLiu, System.Text.Encoding.Default);
                        string strLineDL;
                        string[] arrayDL;
                        char[] charSplitDL = new char[] { ' ' };
                        strLineDL = readLineDL.ReadLine();
                        j = 0;
                        while (strLineDL != null)
                        {
                            arrayDL = strLineDL.Split(charSplitDL);
                            int i = 0;
                            string[] dev = new string[15];
                            dev.Initialize();
                            foreach (string str in arrayDL)
                            {
                                if (str != "")
                                {
                                    dev[i++] = str;
                                }
                            }
                            if (j == 0)
                            {
                                dianLiuResult += dev[0] + "," + dev[1] + "," + dev[2] + "," + dev[3] + "," + dev[4] + "," + dev[5] + "," + dev[6] + "," + dev[7] + "," + dev[8] + "," +
                                             dev[9] + "," + dev[10] + "," + dev[11] + "," + dev[12] + "," + dev[13] + "," + dev[14] + "\r\n";
                            }
                            else
                            {
                                //PSPDEV CR = new PSPDEV();
                                //CR.SvgUID = tlVectorControl1.SVGDocument.SvgdataUid;
                                //CR.Number = Convert.ToInt32(dev[2]);
                                //CR.Type = "Polyline";
                                //CR = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByNumberAndSvgUIDAndType", CR);

                                //因为在线路电流输出时既有一般线路的电流、两绕组和三绕组线路的电流还有接地电容器和电抗器的电流,因此只将电流输出就行了

                                PSPDEV CR = new PSPDEV();
                               // CR.SvgUID = tlVectorControl1.SVGDocument.SvgdataUid;

                                if (dev[0] != "du")
                                {
                                    CR.Name = dev[0];
                                }
                                else
                                    CR.Name = dev[1];
                                string con = " ,PSP_ELCDEVICE WHERE PSPDEV.SUID = PSP_ELCDEVICE.DeviceSUID AND PSP_ELCDEVICE.ProjectSUID = '" + tlVectorControl1.SVGDocument.SvgdataUid + "'AND PSPDEV.Name='" + CR.Name + "'AND PSPDEV.Type='01'";
                                CR = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByCondition", con);
                                if (tuxing == 1)
                                {
                                    //    XmlElement elementdl = tlVectorControl1.SVGDocument.SelectSingleNode("svg/*[@id='" + CR.EleID + "']") as XmlElement;

                                    //    if (elementdl != null)
                                    //    {
                                    //        PointF[] t = ((Polyline)elementdl).Points;

                                    //        PointF[] t2 = ((Polyline)elementdl).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)elementdl).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 n2dl = tlVectorControl1.SVGDocument.CreateElement("polyline") as Polyline;
                                    //        PointF pStart = new PointF(center.X + (float)(15 * Math.Sin((angel) * Math.PI / 180)), center.Y - (float)(15 * Math.Cos((angel) * Math.PI / 180)));
                                    //        PSPDEV psp = new PSPDEV();
                                    //        psp.FirstNode = CR.FirstNode;
                                    //        psp.LastNode = CR.LastNode;
                                    //        psp.SvgUID = CR.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) > (CR.X1)))
                                    //                {
                                    //                    pStart = 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) > (CR.Y1)))
                                    //                {
                                    //                    pStart = 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) > (CR.Y1)))
                                    //                {
                                    //                    pStart = new PointF(center.X - (float)(7 * Math.Sin((angel) * Math.PI / 180)), center.Y + (float)(7 * 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));

                                    //        //if (Convert.ToDouble(dev[4]) >= 0)
                                    //        //{
                                    //        n1.InnerText = (Math.Abs(Convert.ToDouble(dev[3]) * 100 / (Math.Sqrt(3) * CR.ReferenceVolt))).ToString("N4");
                                    //        //}
                                    //        //else
                                    //        //{
                                    //        //    n1.InnerText = (Math.Abs(Convert.ToDouble(dev[3]))).ToString("N4");
                                    //        //}
                                    //        n1.SetAttribute("layer", SvgDocument.currentLayer);
                                    //        n1.SetAttribute("flag", "1");

                                    //        //if (Convert.ToDouble(dev[3]) == 1)
                                    //        //    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(dev[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);

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

                                    //        tlVectorControl1.SVGDocument.CurrentElement = n1 as SvgElement;

                                    //        RectangleF ttt = ((Polyline)elementdl).GetBounds();

                                    //        tlVectorControl1.RotateSelection(angel, pStart);
                                    //        if (Math.Abs(angel) > 90)
                                    //            tlVectorControl1.RotateSelection(180, pStart);
                                    //        PointF newp = new PointF(center.X + 10, center.Y + 10);

                                    //        tlVectorControl1.Refresh();

                                }
                                dianLiuResult += dev[0] + "," + dev[1] + "," + dev[2] + "," + Convert.ToDouble(dev[3]) * 100 / (Math.Sqrt(3) * CR.ReferenceVolt) + "," + dev[4] + "," + Convert.ToDouble(dev[5]) * 100 / (Math.Sqrt(3) * CR.ReferenceVolt) + "," + dev[6] + "," + Convert.ToDouble(dev[7]) * 100 / (Math.Sqrt(3) * CR.ReferenceVolt) + "," + dev[8] + "," +
                                  Convert.ToDouble(dev[9]) * 100 / (Math.Sqrt(3) * CR.ReferenceVolt) + "," + dev[10] + "," + Convert.ToDouble(dev[11]) * 100 / (Math.Sqrt(3) * CR.ReferenceVolt) + "," + dev[12] + "," + Convert.ToDouble(dev[13]) * 100 / (Math.Sqrt(3) * CR.ReferenceVolt) + "," + dev[14] + "\r\n";

                                //if (CR.NodeType == "Polyline")
                                //{
                                //    PSPDEV fl = new PSPDEV();
                                //    fl.SvgUID = tlVectorControl1.SVGDocument.SvgdataUid;
                                //    fl.Number = CR.FirstNode;
                                //    fl.Type = nodeType;
                                //    fl = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByNumberAndSvgUIDAndType", CR);
                                //    dianLiuResult += dev[0] + "," + dev[1] + "," + dev[2] + "," + Convert.ToDouble(dev[3]) * 100 / (Math.Sqrt(3) * fl.ReferenceVolt) + "," + dev[4] + "," + Convert.ToDouble(dev[5]) * 100 / (Math.Sqrt(3) * fl.ReferenceVolt) + "," + dev[6] + "," + Convert.ToDouble(dev[7]) * 100 / (Math.Sqrt(3) * fl.ReferenceVolt) + "," + dev[8] + "," +
                                //    Convert.ToDouble(dev[9]) * 100 / (Math.Sqrt(3) * fl.ReferenceVolt) + "," + dev[10] + "," + Convert.ToDouble(dev[11]) * 100 / (Math.Sqrt(3) * fl.ReferenceVolt) + dev[12] + "," + Convert.ToDouble(dev[13]) * 100 / (Math.Sqrt(3) * fl.ReferenceVolt) + "," + dev[14] + "\r\n";
                                //}
                                //else
                                //{
                                //    dianLiuResult += dev[0] + "," + dev[1] + "," + dev[2] + "," + Convert.ToDouble(dev[3]) * 100 / (Math.Sqrt(3) * CR.ReferenceVolt) + "," + dev[4] + "," + Convert.ToDouble(dev[5]) * 100 / (Math.Sqrt(3) * CR.ReferenceVolt) + "," + dev[6] + "," + Convert.ToDouble(dev[7]) * 100 / (Math.Sqrt(3) * CR.ReferenceVolt) + "," + dev[8] + "," +
                                //    Convert.ToDouble(dev[9]) * 100 / (Math.Sqrt(3) * CR.ReferenceVolt) + "," + dev[10] + "," + Convert.ToDouble(dev[11]) * 100 / (Math.Sqrt(3) * CR.ReferenceVolt) + dev[12] + "," + Convert.ToDouble(dev[13]) * 100 / (Math.Sqrt(3) * CR.ReferenceVolt) + "," + dev[14] + "\r\n";
                                //}

                            }

                            strLineDL = readLineDL.ReadLine();
                            j++;
                        }
                        readLineDL.Close();
                        if (baobiao == 1)
                        {
                             wFrom.ShowText += "\r\n形成报表!" + System.DateTime.Now.ToString();
                            if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\result.csv"))
                            {
                                File.Delete(System.Windows.Forms.Application.StartupPath + "\\result.csv");
                            }
                            FileStream tempGU = new FileStream((System.Windows.Forms.Application.StartupPath + "\\result.csv"), FileMode.OpenOrCreate);
                            StreamWriter strGU = new StreamWriter(tempGU, Encoding.GetEncoding("GB2312"));
                            strGU.Write(duanResult);
                            strGU.Close();
                            if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\result1.csv"))
                            {
                                File.Delete(System.Windows.Forms.Application.StartupPath + "\\result1.csv");
                            }
                            FileStream tempDY = new FileStream((System.Windows.Forms.Application.StartupPath + "\\result1.csv"), FileMode.OpenOrCreate);
                            StreamWriter strDY = new StreamWriter(tempDY, Encoding.GetEncoding("GB2312"));
                            strDY.Write(dianYaResult);
                            strDY.Close();
                            if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\result2.csv"))
                            {
                                File.Delete(System.Windows.Forms.Application.StartupPath + "\\result2.csv");
                            }
                            FileStream tempDL = new FileStream((System.Windows.Forms.Application.StartupPath + "\\result2.csv"), FileMode.OpenOrCreate);
                            StreamWriter strDL = new StreamWriter(tempDL, Encoding.GetEncoding("GB2312"));
                            strDL.Write(dianLiuResult);
                            strDL.Close();
                            if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\" + tlVectorControl1.SVGDocument.FileName + "短路计算结果.xls"))
                            {
                                File.Delete(System.Windows.Forms.Application.StartupPath + "\\" + tlVectorControl1.SVGDocument.FileName + "短路计算结果.xls");
                            }

                            Excel.Application ex;
                            Excel.Worksheet xSheet;
                            Excel.Application result1;
                            Excel.Application result2;
                            Excel.Worksheet tempSheet;
                            Excel.Worksheet tempSheet1;
                            Excel.Worksheet newWorksheet;
                            Excel.Worksheet newWorkSheet1;

                            object oMissing = System.Reflection.Missing.Value;
                            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);
                            xSheet = (Excel.Worksheet)ex.Worksheets[2];
                            ex.Worksheets.Add(System.Reflection.Missing.Value, xSheet, 1, System.Reflection.Missing.Value);
                            xSheet = (Excel.Worksheet)ex.Worksheets[1];
                            result1 = new Excel.Application();
                            result1.Application.Workbooks.Add(System.Windows.Forms.Application.StartupPath + "\\result1.csv");
                            result2 = new Excel.Application();
                            result2.Application.Workbooks.Add(System.Windows.Forms.Application.StartupPath + "\\result2.csv");
                            tempSheet = (Excel.Worksheet)result1.Worksheets.get_Item(1);
                            tempSheet1 = (Excel.Worksheet)result2.Worksheets.get_Item(1);
                            newWorksheet = (Excel.Worksheet)ex.Worksheets.get_Item(2);
                            newWorkSheet1 = (Excel.Worksheet)ex.Worksheets.get_Item(3);
                            newWorksheet.Name = "母线电压";
                            newWorkSheet1.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);
                            tempSheet1.Cells.Select();
                            tempSheet1.Cells.Copy(System.Reflection.Missing.Value);
                            newWorkSheet1.Paste(System.Reflection.Missing.Value, System.Reflection.Missing.Value);

                            xSheet.UsedRange.Font.Name = "楷体_GB2312";
                            newWorksheet.UsedRange.Font.Name = "楷体_GB2312";
                            newWorkSheet1.UsedRange.Font.Name = "楷体_GB2312";

                            xSheet.get_Range(xSheet.Cells[1, 1], xSheet.Cells[1, 3]).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, 3]).Interior.ColorIndex = 45;
                            xSheet.get_Range(xSheet.Cells[4, 1], xSheet.Cells[xSheet.UsedRange.Rows.Count, 1]).Interior.ColorIndex = 6;
                            xSheet.get_Range(xSheet.Cells[4, 3], xSheet.Cells[xSheet.UsedRange.Rows.Count, 13]).NumberFormat = "0.0000_ ";

                            newWorksheet.get_Range(newWorksheet.Cells[1, 1], newWorksheet.Cells[1, 14]).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[3, 1], newWorksheet.Cells[3, 14]).Interior.ColorIndex = 45;
                            newWorksheet.get_Range(newWorksheet.Cells[4, 1], newWorksheet.Cells[newWorksheet.UsedRange.Rows.Count, 1]).Interior.ColorIndex = 6;
                            newWorksheet.get_Range(newWorksheet.Cells[4, 3], newWorksheet.Cells[newWorksheet.UsedRange.Rows.Count, 13]).NumberFormat = "0.0000_ ";

                            newWorkSheet1.get_Range(newWorkSheet1.Cells[1, 1], newWorkSheet1.Cells[1, 15]).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[3, 1], newWorkSheet1.Cells[3, 15]).Interior.ColorIndex = 45;
                            newWorkSheet1.get_Range(newWorkSheet1.Cells[4, 1], newWorkSheet1.Cells[newWorkSheet1.UsedRange.Rows.Count, 1]).Interior.ColorIndex = 6;
                            newWorkSheet1.get_Range(newWorkSheet1.Cells[4, 2], newWorkSheet1.Cells[newWorkSheet1.UsedRange.Rows.Count, 2]).Interior.ColorIndex = 6;
                            newWorkSheet1.get_Range(newWorkSheet1.Cells[4, 4], newWorkSheet1.Cells[newWorkSheet1.UsedRange.Rows.Count, 14]).NumberFormat = "0.0000_ ";
                            xSheet.Rows.AutoFit();
                            xSheet.Columns.AutoFit();
                            newWorksheet.Rows.AutoFit();
                            newWorksheet.Columns.AutoFit();
                            newWorkSheet1.Rows.AutoFit();
                            newWorkSheet1.Columns.AutoFit();
                            newWorksheet.SaveAs(System.Windows.Forms.Application.StartupPath + "\\" + tlVectorControl1.SVGDocument.FileName + "短路计算结果.xls", Excel.XlFileFormat.xlXMLSpreadsheet, null, null, false, false, false, null, null, null);
                            System.Windows.Forms.Clipboard.Clear();
                            result1.Workbooks.Close();
                            result1.Quit();
                            result2.Workbooks.Close();
                            result2.Quit();
                             wFrom.ShowText += "\r\n结果成功!" + System.DateTime.Now.ToString();
                        }

                    }
                    catch (Exception e1)
                    {
                         wFrom.ShowText += "\r\n计算失败,短路数据有问题,请调整后再计算!" + System.DateTime.Now.ToString();
                       // MessageBox.Show("短路数据有问题,请调整后再计算!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
            else if (e.ClickedItem.Text == "区域打印")
            {
                setTJhide();
                PrintHelper ph = new PrintHelper(tlVectorControl1, mapview);
                ph.blshowflag = false;
                frmPrinter dlg = new frmPrinter();
                dlg.printHelper = ph;
                dlg.ShowDialog();
                setTJshow();
                return;
            }
        }
        //根据操作的次序依次显示
        private void Allshortcheck(int caozuoi)
        {
            if (!addcheck())
            {
                return;
            }
            ElectricShorti elc = new ElectricShorti();
            if (!elc.CheckDL(tlVectorControl1.SVGDocument.SvgdataUid,this.ProjectUID,100))
            {
                return;
            }
            Dictionary<int, double> nodeshorti = new Dictionary<int, double>();      //记录母线有没有进行过短路
            KeyValuePair<int, double> maxshorti = new KeyValuePair<int, double>(); //取出短路的最大短路电流

            string con = ",PSP_ELCDEVICE WHERE PSPDEV.SUID = PSP_ELCDEVICE.DeviceSUID AND PSP_ELCDEVICE.ProjectSUID = '" +tlVectorControl1.SVGDocument.SvgdataUid + "'AND PSPDEV.type='01'AND PSPDEV.KSwitchStatus = '0' order by PSPDEV.number";
            PSPDEV pspDev = new PSPDEV();
            IList list1 = Services.BaseService.GetList("SelectPSPDEVByCondition", con);

            con = " ,PSP_ELCDEVICE WHERE PSPDEV.SUID = PSP_ELCDEVICE.DeviceSUID AND PSP_ELCDEVICE.ProjectSUID = '" + tlVectorControl1.SVGDocument.SvgdataUid+ "'AND PSPDEV.type='05'AND PSPDEV.KSwitchStatus = '0'order by PSPDEV.number";
            PSPDEV psp = new PSPDEV();
            IList list2 = Services.BaseService.GetList("SelectPSPDEVByCondition", con);

            shortbuscir shortCutCal = new shortbuscir(0);
            for (int i = 0; i < list1.Count; i++)
            {
                pspDev = list1[i] as PSPDEV;
                bool flag = false;
                string dlr = null;
                for (int j = 0; j < list2.Count; j++)
                {
                    psp = list2[j] as PSPDEV;
                    con = " WHERE Name='" + psp.ISwitch + "' AND ProjectID = '" +this.ProjectUID + "'" + "AND Type='07'";
                    IList listiswitch = Services.BaseService.GetList("SelectPSPDEVByCondition", con);
                    con = " WHERE Name='" + psp.JSwitch + "' AND ProjectID = '" + this.ProjectUID + "'" + "AND Type='07'";
                    IList listjswitch = Services.BaseService.GetList("SelectPSPDEVByCondition", con);
                    PSPDEV pspiswitch = (PSPDEV)listiswitch[0];
                    PSPDEV pspjswitch = (PSPDEV)listjswitch[0];

                    if (pspDev.Number == psp.FirstNode && pspiswitch.KSwitchStatus == "0" && pspjswitch.KSwitchStatus == "0")
                    {

                        flag = true;
                        dlr = "0" + " " + psp.FirstNode + " " + psp.LastNode + " " + psp.Number + " " + "0 " + " " + "0 ";

                    }
                    if (pspDev.Number == psp.LastNode && pspiswitch.KSwitchStatus == "0" && pspjswitch.KSwitchStatus == "0")
                    {
                        flag = true;
                        dlr = "0" + " " + psp.FirstNode + " " + psp.LastNode + " " + psp.Number + " " + "1 " + " " + "0 ";
                    }
                    if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\fault.txt"))
                    {
                        File.Delete(System.Windows.Forms.Application.StartupPath + "\\fault.txt");
                    }
                    if (flag)
                    {
                        FileStream VK = new FileStream((System.Windows.Forms.Application.StartupPath + "\\fault.txt"), FileMode.OpenOrCreate);
                        StreamWriter str11 = new StreamWriter(VK);
                        str11.Write(dlr);
                        str11.Close();
                        if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\ShortcuitI.txt"))
                        {
                            File.Delete(System.Windows.Forms.Application.StartupPath + "\\ShortcuitI.txt");
                        }
                       // shortcir shortCutCal = new shortcir();
                        shortCutCal.Show_shortcir(0,0,1);
                        //bool matrixflag=true;                //用来判断是否导纳矩阵的逆矩阵是否存在逆矩阵

                        string matrixstr = null;
                        if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\Zmatrixcheck.txt"))
                        {
                            matrixstr = "正序导纳矩阵";
                            // matrixflag = false;
                        }

                        if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\Fmatrixcheck.txt"))
                        {
                            // matrixflag = false;
                            matrixstr += "负序导纳矩阵";
                        }

                        if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\Lmatrixcheck.txt"))
                        {
                            //matrixflag = false;
                            matrixstr += "零序导纳矩阵";
                        }
                        if (matrixstr != null)
                        {
                            MessageBox.Show(matrixstr + "不存在逆矩阵,请调整参数后再进行计算!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return;
                        }
                        if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\ShortcuitI.txt"))
                        {
                        }
                        else
                        {
                            return;
                        }

                        FileStream shorcuit = new FileStream(System.Windows.Forms.Application.StartupPath + "\\ShortcuitI.txt", FileMode.Open);
                        StreamReader readLineGU = new StreamReader(shorcuit, System.Text.Encoding.Default);
                        string strLineGU;
                        string[] arrayGU;
                        char[] charSplitGU = new char[] { ' ' };

                        while ((strLineGU = readLineGU.ReadLine()) != null)
                        {

                            while ((strLineGU = readLineGU.ReadLine()) != null)
                            {
                                arrayGU = strLineGU.Split(charSplitGU);
                                string[] shorti = new string[4];
                                shorti.Initialize();
                                int m = 0;
                                foreach (string str in arrayGU)
                                {

                                    if (str != "")
                                    {

                                        shorti[m++] = str.ToString();

                                    }
                                }

                                nodeshorti[pspDev.Number] = Convert.ToDouble(shorti[3]) * 100 / (Math.Sqrt(3) * pspDev.ReferenceVolt);
                            }
                        }
                        readLineGU.Close();
                        break;                 //跳出本循环 进行母线的另外一个母线短路

                    }
                    if (!flag)
                        continue;
                    //写入错误中

                }
                //如果在一般线路中没有则在两绕组中进行
                if (!flag)
                {
                    con = " ,PSP_ELCDEVICE WHERE PSPDEV.SUID = PSP_ELCDEVICE.DeviceSUID AND PSP_ELCDEVICE.ProjectSUID = '" + tlVectorControl1.SVGDocument.SvgdataUid + "'AND PSPDEV.type='02'AND PSPDEV.KSwitchStatus = '0' order by PSPDEV.number";
                    IList list3 = Services.BaseService.GetList("SelectPSPDEVByCondition", con);
                    for (int j = 0; j < list3.Count; j++)
                    {
                        dlr = null;
                        psp = list3[j] as PSPDEV;
                        PSPDEV devFirst = new PSPDEV();

                        con = " WHERE Name='" + psp.IName + "' AND ProjectID = '" + this.ProjectUID + "'" + "AND Type='01'";
                        devFirst = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByCondition", con);
                        PSPDEV devLast = new PSPDEV();

                        con = " WHERE Name='" + psp.JName + "' AND ProjectID = '" + this.ProjectUID + "'" + "AND Type='01'";
                        devLast = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByCondition", con);
                        con = " WHERE Name='" + psp.ISwitch + "' AND ProjectID = '" + this.ProjectUID + "'" + "AND Type='07'";
                        IList listiswitch = Services.BaseService.GetList("SelectPSPDEVByCondition", con);
                        con = " WHERE Name='" + psp.JSwitch + "' AND ProjectID = '" + this.ProjectUID + "'" + "AND Type='07'";
                        IList listjswitch = Services.BaseService.GetList("SelectPSPDEVByCondition", con);
                        PSPDEV pspiswitch = (PSPDEV)listiswitch[0];
                        PSPDEV pspjswitch = (PSPDEV)listjswitch[0];
                        if (pspDev.Number == devFirst.Number && pspiswitch.KSwitchStatus == "0" && pspjswitch.KSwitchStatus == "0")
                        {

                            flag = true;
                            dlr = "0" + " " + devFirst.Number + " " + devLast.Number + " " + psp.Number + " " + "0" + " " + "0";

                        }
                        if (pspDev.Number == devLast.Number && pspiswitch.KSwitchStatus == "0" && pspjswitch.KSwitchStatus == "0")
                        {
                            flag = true;
                            dlr = "0" + " " + devFirst.Number + " " + devLast.Number + " " + psp.Number + " " + "1" + " " + "0";
                        }
                        if (flag)
                        {
                            FileStream VK = new FileStream((System.Windows.Forms.Application.StartupPath + "\\fault.txt"), FileMode.OpenOrCreate);
                            StreamWriter str11 = new StreamWriter(VK);
                            str11.Write(dlr);
                            str11.Close();
                            if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\ShortcuitI.txt"))
                            {
                                File.Delete(System.Windows.Forms.Application.StartupPath + "\\ShortcuitI.txt");
                            }
                           // shortcir shortCutCal = new shortcir();
                            shortCutCal.Show_shortcir(0,0,1);
                            //bool matrixflag=true;                //用来判断是否导纳矩阵的逆矩阵是否存在逆矩阵

                            string matrixstr = null;
                            if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\Zmatrixcheck.txt"))
                            {
                                matrixstr = "正序导纳矩阵";
                                // matrixflag = false;
                            }

                            if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\Fmatrixcheck.txt"))
                            {
                                // matrixflag = false;
                                matrixstr += "负序导纳矩阵";
                            }

                            if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\Lmatrixcheck.txt"))
                            {
                                //matrixflag = false;
                                matrixstr += "零序导纳矩阵";
                            }
                            if (matrixstr != null)
                            {
                                MessageBox.Show(matrixstr + "不存在逆矩阵,请调整参数后再进行计算!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                return;
                            }
                            if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\ShortcuitI.txt"))
                            {
                            }
                            else
                            {
                                return;
                            }

                            FileStream shorcuit = new FileStream(System.Windows.Forms.Application.StartupPath + "\\ShortcuitI.txt", FileMode.Open);
                            StreamReader readLineGU = new StreamReader(shorcuit, System.Text.Encoding.Default);
                            string strLineGU;
                            string[] arrayGU;
                            char[] charSplitGU = new char[] { ' ' };

                            while ((strLineGU = readLineGU.ReadLine()) != null)
                            {

                                while ((strLineGU = readLineGU.ReadLine()) != null)
                                {
                                    arrayGU = strLineGU.Split(charSplitGU);
                                    string[] shorti = new string[4];
                                    shorti.Initialize();
                                    int m = 0;
                                    foreach (string str in arrayGU)
                                    {

                                        if (str != "")
                                        {

                                            shorti[m++] = str.ToString();

                                        }
                                    }

                                    nodeshorti[pspDev.Number] = Convert.ToDouble(shorti[3]) * 100 / (Math.Sqrt(3) * pspDev.ReferenceVolt);
                                }
                            }
                            readLineGU.Close();
                            break;                 //跳出本循环 进行母线的另外一个母线短路

                        }
                        if (!flag)
                            continue;
                        //写入错误中

                    }
                }
                if (!flag)
                {
                    con = " ,PSP_ELCDEVICE WHERE PSPDEV.SUID = PSP_ELCDEVICE.DeviceSUID AND PSP_ELCDEVICE.ProjectSUID = '" + tlVectorControl1.SVGDocument.SvgdataUid + "'AND PSPDEV.type='03'AND PSPDEV.KSwitchStatus = '0' order by PSPDEV.number";
                    IList list4 = Services.BaseService.GetList("SelectPSPDEVByCondition", con);
                    for (int j = 0; j < list4.Count; j++)
                    {
                        dlr = null;
                        psp = list4[j] as PSPDEV;
                        PSPDEV devINode = new PSPDEV();

                        con = " WHERE Name='" + psp.IName + "' AND ProjectID = '" + this.ProjectUID+ "'" + "AND Type='01'";
                        devINode = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByCondition", con);
                        PSPDEV devJNode = new PSPDEV();

                        con = " WHERE Name='" + psp.JName + "' AND ProjectID = '" + this.ProjectUID + "'" + "AND Type='01'";
                        devJNode = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByCondition", con);
                        PSPDEV devKNode = new PSPDEV();

                        con = " WHERE Name='" + psp.KName + "' AND ProjectID = '" + this.ProjectUID + "'" + "AND Type='01'";
                        devKNode = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByCondition", con);

                        con = " WHERE Name='" + psp.ISwitch + "' AND ProjectID = '" + this.ProjectUID + "'" + "AND Type='07'";
                        IList listiswitch = Services.BaseService.GetList("SelectPSPDEVByCondition", con);
                        con = " WHERE Name='" + psp.JSwitch + "' AND ProjectID = '" + this.ProjectUID + "'" + "AND Type='07'";
                        IList listjswitch = Services.BaseService.GetList("SelectPSPDEVByCondition", con);
                        con = " WHERE Name='" + psp.HuganLine1 + "' AND ProjectID = '" + this.ProjectUID + "'" + "AND Type='07'";
                        IList listkswitch = Services.BaseService.GetList("SelectPSPDEVByCondition", con);
                        PSPDEV pspiswitch = (PSPDEV)listiswitch[0];
                        PSPDEV pspjswitch = (PSPDEV)listjswitch[0];
                        PSPDEV pspkswitch = (PSPDEV)listkswitch[0];
                        if (pspDev.Number == devINode.Number && pspiswitch.KSwitchStatus == "0" && pspjswitch.KSwitchStatus == "0" && pspkswitch.KSwitchStatus == "0")
                        {

                            flag = true;
                            dlr = "0" + " " + devINode.Number + " " + devJNode.Number + " " + psp.Number + " " + "0" + " " + "0";

                        }
                        if (pspDev.Number == devJNode.Number && pspiswitch.KSwitchStatus == "0" && pspjswitch.KSwitchStatus == "0" && pspkswitch.KSwitchStatus == "0")
                        {
                            flag = true;
                            dlr = "0" + " " + devINode.Number + " " + devJNode.Number + " " + psp.Number + " " + "1" + " " + "0";
                        }
                        if (pspDev.Number == devKNode.Number && pspiswitch.KSwitchStatus == "0" && pspjswitch.KSwitchStatus == "0" && pspkswitch.KSwitchStatus == "0")
                        {
                            flag = true;
                            dlr = "0" + " " + devINode.Number + " " + devKNode.Number + " " + psp.Number + " " + "1" + " " + "0";
                        }

                        if (flag)
                        {
                            FileStream VK = new FileStream((System.Windows.Forms.Application.StartupPath + "\\fault.txt"), FileMode.OpenOrCreate);
                            StreamWriter str11 = new StreamWriter(VK);
                            str11.Write(dlr);
                            str11.Close();
                            if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\ShortcuitI.txt"))
                            {
                                File.Delete(System.Windows.Forms.Application.StartupPath + "\\ShortcuitI.txt");
                            }
                          //  shortcir shortCutCal = new shortcir();
                            shortCutCal.Show_shortcir(0,0,1);
                            //bool matrixflag=true;                //用来判断是否导纳矩阵的逆矩阵是否存在逆矩阵

                            string matrixstr = null;
                            if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\Zmatrixcheck.txt"))
                            {
                                matrixstr = "正序导纳矩阵";
                                // matrixflag = false;
                            }

                            if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\Fmatrixcheck.txt"))
                            {
                                // matrixflag = false;
                                matrixstr += "负序导纳矩阵";
                            }

                            if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\Lmatrixcheck.txt"))
                            {
                                //matrixflag = false;
                                matrixstr += "零序导纳矩阵";
                            }
                            if (matrixstr != null)
                            {
                                MessageBox.Show(matrixstr + "不存在逆矩阵,请调整参数后再进行计算!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                return;
                            }
                            if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\ShortcuitI.txt"))
                            {
                            }
                            else
                            {
                                return;
                            }

                            FileStream shorcuit = new FileStream(System.Windows.Forms.Application.StartupPath + "\\ShortcuitI.txt", FileMode.Open);
                            StreamReader readLineGU = new StreamReader(shorcuit, System.Text.Encoding.Default);
                            string strLineGU;
                            string[] arrayGU;
                            char[] charSplitGU = new char[] { ' ' };

                            while ((strLineGU = readLineGU.ReadLine()) != null)
                            {

                                while ((strLineGU = readLineGU.ReadLine()) != null)
                                {
                                    arrayGU = strLineGU.Split(charSplitGU);
                                    string[] shorti = new string[4];
                                    shorti.Initialize();
                                    int m = 0;
                                    foreach (string str in arrayGU)
                                    {

                                        if (str != "")
                                        {

                                            shorti[m++] = str.ToString();

                                        }
                                    }

                                    nodeshorti[pspDev.Number] = Convert.ToDouble(shorti[3]) * 100 / (Math.Sqrt(3) * pspDev.ReferenceVolt);
                                }
                            }
                            readLineGU.Close();
                            break;                 //跳出本循环 进行母线的另外一个母线短路

                        }
                        if (!flag)
                            continue;
                        //写入错误中

                    }
                }
            }
            //找出短路电流最大的值

            //maxshorti.Key = 1;
            //maxshorti.Value = nodeshorti[1];
            foreach (KeyValuePair<int, double> keyvalue in nodeshorti)
            {
                if (keyvalue.Value > maxshorti.Value)
                {
                    maxshorti = keyvalue;
                }
            }

            //首先取出断路器 判断它的母线在不在 如果不在就将其删除 然后与额定电压进行比较
            con = " ,PSP_ELCDEVICE WHERE PSPDEV.SUID = PSP_ELCDEVICE.DeviceSUID AND PSP_ELCDEVICE.ProjectSUID = '" + tlVectorControl1.SVGDocument.SvgdataUid + "'AND PSPDEV.type='06'AND PSPDEV.KSwitchStatus = '0' order by PSPDEV.number";
            IList list = Services.BaseService.GetList("SelectPSPDEVByCondition", con);

            for (int i = 0; i < list.Count; i++)
            {
                bool flag = false;
                pspDev = list[i] as PSPDEV;
                for (int j = 0; j < list1.Count; j++)
                {
                    psp = list1[j] as PSPDEV;
                    if (pspDev.IName == psp.Name)
                        flag = true;

                }
                if (!flag)
                {
                    Services.BaseService.Delete<PSPDEV>(pspDev);
                }
            }
            con = " ,PSP_ELCDEVICE WHERE PSPDEV.SUID = PSP_ELCDEVICE.DeviceSUID AND PSP_ELCDEVICE.ProjectSUID = '" + tlVectorControl1.SVGDocument.SvgdataUid + "'AND PSPDEV.type='06'AND PSPDEV.KSwitchStatus = '0' order by PSPDEV.number";
            list = Services.BaseService.GetList("SelectPSPDEVByCondition", con);
            for (int i = 0; i < list.Count; i++)
            {
                pspDev = list[i] as PSPDEV;
                pspDev.HuganLine3 = "";
                pspDev.KName = "";
                if (pspDev.KSwitchStatus == "0")
                {
                    pspDev.OutP = maxshorti.Value;
                    if (maxshorti.Value > pspDev.HuganTQ1)
                    {
                        pspDev.HuganLine3 = "不合格";
                    }
                    else
                    {
                        pspDev.HuganLine3 = "合格";
                    }
                    pspDev.HuganLine4 = "";
                    if (pspDev.HuganLine3 == "合格")
                    {
                        pspDev.KName = "合格";
                    }
                    else
                        pspDev.KName = "不合格";
                }

                Services.BaseService.Update<PSPDEV>(pspDev);
            }
            switch (caozuoi)
            {
                case 1:           //全部短路检验

                    {
                        pspDev.SvgUID = tlVectorControl1.SVGDocument.SvgdataUid;
                        pspDev.Type = "06";
                         DlqiCheckform dlqicheckform = new DlqiCheckform(pspDev);
                        dlqicheckform.getusercltr.gridView.GroupPanelText = "断路器开断能力评估初步结果表";
                        dlqicheckform.ShowDialog();
                        break;
                    }
                case 2:             //最大短路检验
                    {
                        con = " ,PSP_ELCDEVICE WHERE PSPDEV.SUID = PSP_ELCDEVICE.DeviceSUID AND PSP_ELCDEVICE.ProjectSUID = '" + tlVectorControl1.SVGDocument.SvgdataUid + "'AND PSPDEV.type='06'AND PSPDEV.KSwitchStatus = '0' order by PSPDEV.number";
                        list = Services.BaseService.GetList("SelectPSPDEVByCondition", con);
                        for (int i = 0; i < list.Count; i++)
                        {
                            pspDev = list[i] as PSPDEV;
                            if (pspDev.KSwitchStatus == "0")
                            {
                               con = ",PSP_ELCDEVICE WHERE PSPDEV.SUID = PSP_ELCDEVICE.DeviceSUID AND PSP_ELCDEVICE.ProjectSUID = '" + tlVectorControl1.SVGDocument.SvgdataUid+ "'AND PSPDEV.type='01'AND PSPDEV.KSwitchStatus = '0'AND PSPDEV.Name='"+pspDev.IName+"'";

                               IList list4 = Services.BaseService.GetList("SelectPSPDEVByCondition", con);
                                psp = list4[0] as PSPDEV;
                                try
                                {
                                    pspDev.OutQ = nodeshorti[psp.Number];
                                    if (pspDev.HuganLine3 == "不合格")
                                    {
                                        if (pspDev.OutQ <= pspDev.HuganTQ1)
                                        {
                                            pspDev.HuganLine3 = "合格";
                                        }
                                    }
                                    pspDev.HuganLine4 = "";

                                    if (pspDev.HuganLine3 == "合格")
                                    {
                                        pspDev.KName = "合格";
                                    }
                                    else
                                        pspDev.KName = "不合格";
                                    Services.BaseService.Update<PSPDEV>(pspDev);
                                }
                                catch (System.Exception ex)
                                {
                                    MessageBox.Show("短路数据不完整");
                                }
                            }

                        }
                        pspDev.SvgUID = tlVectorControl1.SVGDocument.SvgdataUid;
                        pspDev.Type = "06";
                        DlqiCheckform dlqicheckform = new DlqiCheckform(pspDev);
                        dlqicheckform.getusercltr.gridView.GroupPanelText = "最大短路校核结果表";
                        dlqicheckform.ShowDialog();
                        break;
                    }
                case 3:          //断路器直流检验

                    {
                        con = " ,PSP_ELCDEVICE WHERE PSPDEV.SUID = PSP_ELCDEVICE.DeviceSUID AND PSP_ELCDEVICE.ProjectSUID = '" + tlVectorControl1.SVGDocument.SvgdataUid + "'AND PSPDEV.type='06'AND PSPDEV.KSwitchStatus = '0' order by PSPDEV.number";
                        list = Services.BaseService.GetList("SelectPSPDEVByCondition", con);
                        for (int i = 0; i < list.Count; i++)
                        {
                            pspDev = list[i] as PSPDEV;
                            if (pspDev.KSwitchStatus == "0")
                            {
                                double tx = 0.0;
                                if (pspDev.HuganLine2 == "自脱扣断路器")
                                {
                                    tx = 0.0;
                                }
                                else if (pspDev.HuganLine2 == "辅助动力脱扣的断路器")
                                {
                                    tx = 10;
                                }
                                pspDev.HuganTQ4 = (pspDev.OutP / pspDev.HuganTQ1) * Math.Exp((-pspDev.HuganTQ2 - tx) / 45) * 100;
                                pspDev.HuganTQ5 = (pspDev.OutQ / pspDev.HuganTQ1) * Math.Exp((-pspDev.HuganTQ2 - tx) / 45) * 100;
                                if (pspDev.HuganTQ3 >= pspDev.HuganTQ4)
                                {
                                    pspDev.HuganLine4 = "合格";
                                }
                                if (pspDev.HuganTQ3 >= pspDev.HuganTQ5)
                                {
                                    pspDev.HuganLine4 = "合格";
                                }
                                else if (pspDev.HuganTQ3 < pspDev.HuganTQ5)
                                {
                                    pspDev.HuganLine4 = "不合格";
                                }
                                if (pspDev.HuganLine3 == "合格" && pspDev.HuganLine4 == "合格")
                                {
                                    pspDev.KName = "合格";
                                }
                                else
                                {
                                    pspDev.KName = "不合格";
                                }

                                Services.BaseService.Update<PSPDEV>(pspDev);
                            }

                        }
                        pspDev.SvgUID = tlVectorControl1.SVGDocument.SvgdataUid;
                        pspDev.Type = "06";
                        DlqiCheckform dlqicheckform = new DlqiCheckform(pspDev);
                        dlqicheckform.getusercltr.gridView.GroupPanelText = "断路器开端能力最终评估表";
                        dlqicheckform.ShowDialog();
                        break;
                    }

            }
        }
        private void AllshortItem_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            ElectricShorti elc = new ElectricShorti();
            //TreeListNode node = treeList1.FocusedNode;
            if (strID == null) {
                MessageBox.Show("����ѡ��������㷽����", "��ʾ", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            //strID = node["ID"].ToString();
            //elc.CheckDL(strID, 100);
            int n3 = 0;
            ShorttypeForm shortfangshi = new ShorttypeForm();
            ShortTform shorttype = new ShortTform();
            frnReport wFrom = new frnReport();
            wFrom.Text = "��·����";
            wFrom.Show();
            wFrom.ShowText += "�����������\t" + System.DateTime.Now.ToString();
            if (shortfangshi.ShowDialog() == DialogResult.OK) {
                if (shortfangshi.Mathindex == 0) {
                    shorttype.ShowDialog();
                    if (shorttype.DialogResult == DialogResult.OK) {
                        switch (shorttype.DuanluType) {
                            case "����ӵ�":
                                n3 = 1;
                                break;

                            case "����ӵ�":
                                n3 = 3;
                                break;
                            case "�������":
                                n3 = 2;
                                break;
                            case "�������":
                                n3 = 0;
                                break;

                        }
                        elc.OutType = shorttype.Mathindex;
                        elc.Compuflag = shorttype.Compuflag;
                    } else
                        return;
                    //WaitDialogForm wait = null;
                    try {

                        // wait = new WaitDialogForm("", "���ڴ�������, ���Ժ�...");

                        elc.AllShort(strID, this.ProjectUID, n3, 100, wFrom);
                        //elc.ALLShortThread(strID, this.ProjectUID, n3, 100, wait);
                        //wait.Close();
                    } catch (Exception exc) {
                        wFrom.ShowText += "\r\n��·����ʧ��\t" + System.DateTime.Now.ToString();
                        Debug.Fail(exc.Message);
                        Itop.Client.Common.HandleException.TryCatch(exc);
                        // wait.Close();
                        return;

                    }

                }
                if (shortfangshi.Mathindex == 1) {
                    SelshortbusForm1 selbusfrm = new SelshortbusForm1();
                    selbusfrm.ProjectSUID = strID;
                    selbusfrm.ProjectID = Itop.Client.MIS.ProgUID;
                    selbusfrm.ShowDialog();
                    if (selbusfrm.DialogResult == DialogResult.OK) {
                        List<PSPDEV> list = new List<PSPDEV>();
                        foreach (DataRow row in selbusfrm.DT.Rows) {
                            try {
                                if ((bool)row["C"]) {
                                    PSPDEV psp = new PSPDEV();
                                    psp.SUID = row["A"].ToString();

                                    psp = (PSPDEV)UCDeviceBase.DataService.GetObject("SelectPSPDEVByKey", psp);
                                    if (psp != null) {
                                        list.Add(psp);
                                    }
                                }

                            } catch (System.Exception ex) {

                            }
                        }
                        if (list.Count == 0) {
                            MessageBox.Show("û��ѡ���·��ĸ�ߣ�");
                            return;
                        }
                        shorttype.ShowDialog();
                        if (shorttype.DialogResult == DialogResult.OK) {
                            switch (shorttype.DuanluType) {
                                case "����ӵ�":
                                    n3 = 1;
                                    break;

                                case "����ӵ�":
                                    n3 = 3;
                                    break;
                                case "�������":
                                    n3 = 2;
                                    break;
                                case "�������":
                                    n3 = 0;
                                    break;

                            }
                            elc.OutType = shorttype.Mathindex;
                            elc.Compuflag = shorttype.Compuflag;
                        } else
                            return;
                        // WaitDialogForm wait = null;
                        try {
                            //wait = new WaitDialogForm("", "���ڴ�������, ���Ժ�...");
                            elc.Partshort(strID, this.ProjectUID, n3, 100, list, wFrom);
                            //wait.Close();
                        } catch (Exception exc) {
                            wFrom.ShowText += "\r\n��·����ʧ��\t" + System.DateTime.Now.ToString();
                            Debug.Fail(exc.Message);
                            Itop.Client.Common.HandleException.TryCatch(exc);
                            //wait.Close();
                            return;

                        }

                    }
                }

            }
        }
        private void ZLcheck_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            ElectricShorti elc = new ElectricShorti();
            //TreeListNode node = treeList1.FocusedNode;
            if (string.IsNullOrEmpty(strID))
            {
                MessageBox.Show("����ѡ��������㷽����", "��ʾ", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
               // strID = node["ID"].ToString();
            WaitDialogForm wait = null;
            try {
                wait = new WaitDialogForm("", "���ڴ�������, ���Ժ�...");
                wait.Close();
                elc.Allshortcheck(strID, this.ProjectUID, 100, 3);

            } catch (Exception exc) {
                Debug.Fail(exc.Message);
                Itop.Client.Common.HandleException.TryCatch(exc);
                wait.Close();
                return;
            }
        }
        public void GHWPG()
        {
            string output = null;
            frnReport wForm = new frnReport(); ;
            wForm.Owner = this;
            FileStream rs1;
            StreamWriter strRS1;
            Excel.Application mx = new Excel.Application(); ;
            Excel.Application xl = new Excel.Application(); ;
            StringBuilder stResult = new StringBuilder();
            bool N1 = false;
            String chaoliuSUID = null;
            try
            {
                frmOpenProject fop = new frmOpenProject();
                fop.ProjectID = Itop.Client.MIS.ProgUID;
                fop.Initdata();
                String strr = chaoliuSUID;
                stResult.Append("规划网架评估结果" + "\r\n" + "\r\n");
                //OpenProject op = new OpenProject();
                //op.ProjectID = Itop.Client.MIS.ProgUID;
                //op.Initdata();

                if (fop.ShowDialog() == DialogResult.OK)
                {
                    wForm.Text = this.Text + "—规划网评估";
                    wForm.Show();
                    Application.DoEvents();
                    if (fop.ChaoLiuSUID == null)
                    {
                        chaoliuSUID = fop.DuanLuSUID;
                    }
                    else
                    {
                        chaoliuSUID = fop.ChaoLiuSUID;
                    }
                    if (chaoliuSUID == null)
                    {
                        return;
                    }
                    if (chaoliuSUID != null)
                    {
                        wForm.ShowText = "正在进行潮流计算\t" + System.DateTime.Now.ToString();
                        ElectricLoadCal elc = new ElectricLoadCal();
                        bool flag = elc.LFC(chaoliuSUID, 1, 100, wForm);
                        if (flag == true)
                        {
                            wForm.ShowText += "\r\n正在处理潮流计算结果\t" + System.DateTime.Now.ToString();
                            // WaitDialogForm wf = new WaitDialogForm("", "正在处理数据, 请稍候...");
                            stResult.Append("1 潮流计算评价指标" + "\r\n");
                            stResult.Append("1.1 线路负载率" + "\r\n");
                            output = null;

                            output += ("全网交流线结果报表" + "\r\n" + "\r\n");
                            output += ("单位:kA\\kV\\MW\\Mvar" + "\r\n" + "\r\n");
                            output += ("计算日期:" + System.DateTime.Now.ToString() + "\r\n" + "\r\n");
                            output += ("支路名称" + "," + "支路有功" + "," + "支路无功" + "," + "有功损耗" + "," + "无功损耗" + "," + "电流幅值" + "," + "电流相角" + "," + "越限标志" + "," + "\r\n");
                            string strCon1 = ",PSPDEV WHERE PSPDEV.SUID = PSP_ELCDEVICE.DeviceSUID AND PSP_ELCDEVICE.ProjectSUID = '" + chaoliuSUID + "'" + " AND PSPDEV.Type = '05' order by PSPDEV.RateVolt,PSPDEV.Name";
                            IList list1 = Services.BaseService.GetList("SelectPSP_ElcDeviceByCondition", strCon1);
                            double fuzail = 0.0;
                            double Amax = 0;
                            double Amin = 0;
                            int i = 0, j = 0;
                            StringBuilder gfzlline = new StringBuilder();
                            foreach (PSP_ElcDevice elcDEV in list1)
                            {
                                PSPDEV dev = new PSPDEV();
                                dev.SUID = elcDEV.DeviceSUID;
                                dev = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByKey", dev);
                                string lineF = "否";
                                if (dev.KSwitchStatus == "1")
                                {
                                    continue;
                                }
                                if (Convert.ToDouble(GetColValue(elcDEV, 0).COL14) * 1000 > (double)dev.Burthen)
                                {
                                    lineF = "是";
                                }
                                //double vTemp = Convert.ToDouble(GetColValue(elcDEV,type-1));
                                //double vTemp1 =  TLPSPVmin * dev.RateVolt;
                                //double vTemp2 =  TLPSPVmax * dev.RateVolt;
                                output += dev.Name.ToString() + "," + Convert.ToDouble(GetColValue(elcDEV, 0).COL4).ToString() + "," + Convert.ToDouble(GetColValue(elcDEV, 0).COL5).ToString() + "," + Convert.ToDouble(GetColValue(elcDEV, 0).COL6).ToString() + "," + Convert.ToDouble(GetColValue(elcDEV, 0).COL7).ToString() + "," + Convert.ToDouble(GetColValue(elcDEV, 0).COL14).ToString() + "," + Convert.ToDouble(GetColValue(elcDEV, 0).COL15).ToString() + "," + lineF + "," + "\r\n";
                                double A = 0;
                                if (elcDEV.COL14 != "" || elcDEV.COL20 != "")
                                {
                                    A = (Convert.ToDouble(elcDEV.COL14) * 1000) / Convert.ToDouble(elcDEV.COL20);
                                }

                                if (i == 0)
                                {
                                    Amax = A;
                                    Amin = A;
                                    i++;
                                }
                                fuzail += A;
                                if (A > 1)
                                {
                                    j++;
                                    gfzlline.Append(dev.Name + "负载率" + A.ToString("#####.##") + ",");

                                }
                                if (Amin >= A)
                                {
                                    Amin = A;
                                }
                                else if (Amax < A)
                                {
                                    Amax = A;
                                }
                            }
                            try
                            {
                                if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\result1.csv"))
                                {
                                    File.Delete(System.Windows.Forms.Application.StartupPath + "\\result1.csv");
                                }
                            }
                            catch (System.Exception ex3)
                            {
                                MessageBox.Show("请关闭相关Excel后再查看结果!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }

                            rs1 = new FileStream((System.Windows.Forms.Application.StartupPath + "\\result1.csv"), FileMode.OpenOrCreate);
                            strRS1 = new StreamWriter(rs1, Encoding.Default);
                            strRS1.Write(output);
                            strRS1.Close();
                            xl.Application.Workbooks.Add(System.Windows.Forms.Application.StartupPath + "\\result1.csv");
                            fuzail = fuzail / list1.Count;
                            stResult.Append("平均负载率:," + fuzail.ToString() + ",");
                            stResult.Append("最小负载率:," + Amin.ToString() + ",");
                            stResult.Append("最大负载率:," + Amax.ToString() + ",");
                            stResult.Append("过载线路条数:," + j.ToString() + "\r\n");
                            if (j > 0)
                            {
                                stResult.Append("过载的线路为:" + gfzlline.ToString() + "\r\n");
                            }

                            strCon1 = ",PSP_ELCDEVICE WHERE PSPDEV.SUID = PSP_ELCDEVICE.DeviceSUID AND PSP_ELCDEVICE.ProjectSUID = '" + chaoliuSUID + "'" + " AND PSPDEV.Type = '02' order by PSPDEV.RateVolt,PSPDEV.Name";
                            IList list2 = Services.BaseService.GetList("SelectPSPDEVByCondition", strCon1);
                            strCon1 = ",PSP_ELCDEVICE WHERE PSPDEV.SUID = PSP_ELCDEVICE.DeviceSUID AND PSP_ELCDEVICE.ProjectSUID = '" + chaoliuSUID + "'" + " AND PSPDEV.Type = '03' order by PSPDEV.RateVolt,PSPDEV.Name";
                            IList list3 = Services.BaseService.GetList("SelectPSPDEVByCondition", strCon1);
                            if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\DH1.txt"))
                            {
                            }
                            else
                            {
                                return;
                            }
                            FileStream ih = new FileStream(System.Windows.Forms.Application.StartupPath + "\\DH1.txt", FileMode.Open);
                            StreamReader readLine = new StreamReader(ih, Encoding.Default);
                            string strLine = readLine.ReadLine();
                            char[] charSplit = new char[] { ' ' };
                            double byqFuZaiLv = 0.0;
                            double Bmax = 0;
                            double Bmin = 0;
                            int bi = 0, bj = 0;
                            gfzlline = new StringBuilder();
                            IList listobject = new List<object>();
                            while (strLine != null && strLine != "")
                            {
                                string[] array1 = strLine.Split(charSplit, StringSplitOptions.RemoveEmptyEntries);
                                listobject.Add(array1);
                                foreach (PSPDEV byq in list2)
                                {
                                    if (byq.Name == array1[0])
                                    {
                                        double tempA = Math.Sqrt(Convert.ToDouble(array1[3]) * Convert.ToDouble(array1[3]) + Convert.ToDouble(array1[4]) * Convert.ToDouble(array1[4])) / ((double)byq.Burthen);
                                        byqFuZaiLv += tempA;
                                        if (bi == 0)
                                        {
                                            Bmax = tempA;
                                            Bmin = tempA;
                                            bi++;
                                        }
                                        if (tempA > 1)
                                        {
                                            bj++;
                                            gfzlline.Append(byq.Name + "负载率" + tempA.ToString("#####.##") + ",");
                                        }
                                        if (Bmin >= tempA)
                                        {
                                            Bmin = tempA;
                                        }
                                        else if (Bmax < tempA)
                                        {
                                            Bmax = tempA;
                                        }
                                    }
                                }
                                strLine = readLine.ReadLine();
                            }
                            readLine.Close();
                            foreach (PSPDEV byq3 in list3)
                            {
                                double p = 0;
                                double q = 0;
                                foreach (string[] obj in listobject)
                                {
                                    if (obj[0] == byq3.Name && (obj[1] == byq3.KName || obj[2] == byq3.KName))
                                    {
                                        p += Convert.ToDouble(obj[3]);
                                        q += Convert.ToDouble(obj[4]);
                                    }
                                }
                                double tempA = Math.Sqrt(p * p + q * q) / byq3.SiN;
                                byqFuZaiLv += tempA;
                                if (bi == 0)
                                {
                                    Bmax = tempA;
                                    Bmin = tempA;
                                    bi++;
                                }
                                if (tempA > 1)
                                {
                                    bj++;
                                    gfzlline.Append(byq3.Name + "负载率" + tempA.ToString("#####.##") + ",");
                                }
                                if (Bmin >= tempA)
                                {
                                    Bmin = tempA;
                                }
                                else if (Bmax < tempA)
                                {
                                    Bmax = tempA;
                                }
                            }
                            if (list2.Count + list3.Count == 0)
                            {
                                byqFuZaiLv = 0;
                            }
                            else
                            {
                                byqFuZaiLv = byqFuZaiLv / (list2.Count + list3.Count);
                            }

                            stResult.Append("1.2 变压器负载率" + "\r\n");
                            stResult.Append("平均负载率:," + byqFuZaiLv.ToString() + ",");
                            stResult.Append("最小负载率:," + Bmin.ToString() + ",");
                            stResult.Append("最大负载率:," + Bmax.ToString() + ",");
                            stResult.Append("过载变压器台数:," + bj.ToString() + "\r\n");
                            if (bj > 0)
                            {
                                stResult.Append("过载变压器为:" + gfzlline.ToString() + "\r\n");
                            }
                            string strCon = ",PSPDEV WHERE PSPDEV.SUID = PSP_ELCDEVICE.DeviceSUID AND PSP_ELCDEVICE.ProjectSUID = '" + chaoliuSUID + "'" + " AND PSPDEV.Type = '01' order by PSPDEV.RateVolt,PSPDEV.Name";
                            IList list4 = Services.BaseService.GetList("SelectPSP_ElcDeviceByCondition", strCon);
                            double voltP = 0;
                            double Vmax = 0, Vmin = 0;
                            int vi = 0, vj = 0;
                            output = null;
                            gfzlline = new StringBuilder();
                            output += ("全网母线(发电、负荷)结果报表 " + "\r\n" + "\r\n");
                            output += ("单位:kA\\kV\\MW\\Mvar" + "\r\n" + "\r\n");
                            output += ("计算日期:" + System.DateTime.Now.ToString() + "\r\n" + "\r\n");
                            output += ("母线名" + "," + "电压幅值" + "," + "电压相角" + "," + "有功发电" + "," + "无功发电" + "," + "有功负荷" + "," + "无功负荷" + "," + "越限标志" + "," + "过载标志" + "\r\n");
                            foreach (PSP_ElcDevice busDEV in list4)
                            {
                                string voltF = "否";
                                string pF = "否";
                                PSPDEV dev = new PSPDEV();
                                dev.SUID = busDEV.DeviceSUID;
                                dev = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByKey", dev);
                                //double vTemp = Convert.ToDouble(GetColValue(elcDEV,type-1));
                                //double vTemp1 =  TLPSPVmin * dev.RateVolt;
                                //double vTemp2 =  TLPSPVmax * dev.RateVolt;
                                if (dev == null)
                                {
                                    continue;
                                }
                                double voltExcursion = 0.0;
                                voltExcursion = (Convert.ToDouble(busDEV.COL2) - dev.RateVolt) / dev.RateVolt;
                                voltP += Math.Abs(voltExcursion);
                                if (vi == 0)
                                {
                                    Vmax = voltExcursion;
                                    Vmin = voltExcursion;
                                    vi++;
                                }
                                if (voltFlag(voltExcursion, dev.RateVolt) == "不合格")
                                {
                                    vj++;
                                    gfzlline.Append(dev.Name + ",");
                                }
                                if (Vmin >= voltExcursion)
                                {
                                    Vmin = voltExcursion;
                                }
                                else if (Vmax < voltExcursion)
                                {
                                    Vmax = voltExcursion;
                                }
                                if (dev.KSwitchStatus == "1")
                                {
                                    continue;
                                }
                                if (Convert.ToDouble(GetColValue(busDEV, 0).COL2) < dev.iV || Convert.ToDouble(GetColValue(busDEV, 0).COL2) > dev.jV)
                                {
                                    voltF = "是";
                                }
                                if (Convert.ToDouble(GetColValue(busDEV, 0).COL2) > (double)dev.Burthen)
                                {
                                    pF = "是";
                                }

                                if (Convert.ToDouble(GetColValue(busDEV, 0).COL4) > 0)
                                {

                                    output += dev.Name + "," + Convert.ToDouble(GetColValue(busDEV, 0).COL2).ToString() + "," + Convert.ToDouble(GetColValue(busDEV, 0).COL3).ToString() + "," + Convert.ToDouble(GetColValue(busDEV, 0).COL4).ToString() + "," + Convert.ToDouble(GetColValue(busDEV, 0).COL5).ToString() + "," + "0" + "," + "0" + "," + voltF + "," + pF + "\r\n";

                                }
                                else
                                {

                                    output += dev.Name + "," + Convert.ToDouble(GetColValue(busDEV, 0).COL2).ToString() + "," + Convert.ToDouble(GetColValue(busDEV, 0).COL3).ToString() + "," + "0" + "," + "0" + "," + Convert.ToDouble(GetColValue(busDEV, 0).COL4).ToString() + "," + Convert.ToDouble(GetColValue(busDEV, 0).COL5).ToString() + "," + voltF + "," + pF + "\r\n";

                                }
                            }
                            try
                            {
                                if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\result.csv"))
                                {
                                    File.Delete(System.Windows.Forms.Application.StartupPath + "\\result.csv");
                                }
                            }
                            catch (System.Exception ex2)
                            {
                                MessageBox.Show("请关闭相关Excel后再查看结果!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }

                            rs1 = new FileStream((System.Windows.Forms.Application.StartupPath + "\\result.csv"), FileMode.OpenOrCreate);
                            strRS1 = new StreamWriter(rs1, Encoding.Default);
                            strRS1.Write(output);
                            strRS1.Close();
                            mx.Application.Workbooks.Add(System.Windows.Forms.Application.StartupPath + "\\result.csv"); ;
                            voltP = voltP / list4.Count;
                            stResult.Append("1.3 节点电压偏移" + "\r\n");
                            stResult.Append("平均节点电压偏移:," + voltP.ToString() + ",");
                            stResult.Append("最大下偏移:," + Vmin.ToString() + ",");
                            stResult.Append("最大上偏移:," + Vmax.ToString() + ",");
                            stResult.Append("电压越限节点数:," + vj.ToString() + "\r\n");
                            if (vj > 0)
                            {
                                stResult.Append("电压越限的节点为:" + gfzlline.ToString() + "\r\n");
                            }
                            {
                                string strCon11 = ",PSP_ELCDEVICE WHERE PSPDEV.SUID = PSP_ELCDEVICE.DeviceSUID AND PSP_ELCDEVICE.ProjectSUID = '" + chaoliuSUID + "'";
                                string strCon22 = null;
                                string strCon33 = null;
                                if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\DH1.txt"))
                                {
                                }
                                else
                                {
                                    return;
                                }
                                FileStream dh = new FileStream(System.Windows.Forms.Application.StartupPath + "\\DH1.txt", FileMode.Open);
                                StreamReader readLine1 = new StreamReader(dh, Encoding.Default);
                                char[] charSplit1 = new char[] { ' ' };
                                string strLine1 = readLine1.ReadLine();
                                double temp1 = 0;
                                double temp2 = 0;
                                double temp3 = 0; ;
                                double temp4 = 0;
                                double temp5 = 0, temp6 = 0, temp7 = 0, temp8 = 0;
                                string[] array1 = strLine.Split(charSplit);

                                string strCon3 = ",PSPDEV WHERE PSPDEV.SUID = PSP_ELCDEVICE.DeviceSUID AND PSP_ELCDEVICE.ProjectSUID = '" + chaoliuSUID + "'" + " AND PSPDEV.Type = '01' order by PSPDEV.RateVolt,PSPDEV.Name";
                                IList list = Services.BaseService.GetList("SelectPSP_ElcDeviceByCondition", strCon3);
                                double tempAD = 0;
                                foreach (PSP_ElcDevice elcDEV in list)
                                {
                                    PSPDEV dev = new PSPDEV();
                                    dev.SUID = elcDEV.DeviceSUID;
                                    dev = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByKey", dev);
                                    tempAD += dev.OutP;
                                    if (Convert.ToDouble(GetColValue(elcDEV, 0).COL4) < 0 && dev.NodeType == "0")
                                    {
                                        tempAD += Convert.ToDouble(GetColValue(elcDEV, 0).COL4);
                                    }
                                }
                                if (tempAD == 0)
                                {
                                    tempAD = 1;
                                }
                                while (strLine1 != null && strLine1 != "")
                                {
                                    array1 = strLine1.Split(charSplit);

                                    string[] dev = new string[20];
                                    dev.Initialize();
                                    int ii = 0;

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

                                            }
                                        }

                                    }
                                    strCon22 = " AND Type= '05' AND Name = '" + array1[0] + "' AND FirstNode = " + array1[1] + " AND LastNode = " + array1[2];
                                    strCon33 = strCon11 + strCon22;
                                    PSPDEV CR = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByCondition", strCon33);

                                    if (CR != null)
                                    {
                                        temp1 += Math.Abs(Convert.ToDouble(dev[5]) * 100);
                                        temp2 += Math.Abs(Convert.ToDouble(dev[6]) * 100);
                                        temp5 += Math.Abs(Convert.ToDouble(dev[3]) * 100);
                                        temp6 += Math.Abs(Convert.ToDouble(dev[4]) * 100);
                                    }
                                    else
                                    {
                                        strCon22 = " AND Type= '02' AND Name = '" + array1[0] + "'";
                                        strCon33 = strCon11 + strCon22;
                                        CR = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByCondition", strCon33);
                                        if (CR == null)
                                        {
                                            strCon22 = " AND Type= '03' AND Name = '" + array1[0] + "'";
                                            strCon33 = strCon11 + strCon22;
                                            CR = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByCondition", strCon33);
                                        }
                                        if (CR != null)
                                        {
                                            temp3 += Math.Abs(Convert.ToDouble(dev[5]) * 100);
                                            temp4 += Math.Abs(Convert.ToDouble(dev[6]) * 100);
                                            temp7 += Math.Abs(Convert.ToDouble(dev[3]) * 100);
                                            temp8 += Math.Abs(Convert.ToDouble(dev[4]) * 100);
                                        }
                                    }
                                    strLine1 = readLine1.ReadLine();
                                }
                                double lineLoss = temp1 / temp5;
                                double bLoss = temp3 / temp7;
                                if (temp5 == 0)
                                {
                                    lineLoss = 0;
                                }
                                if (temp7 == 0)
                                {
                                    bLoss = 0;
                                }
                                readLine1.Close();
                                stResult.Append("2 线损率" + "\r\n");
                                stResult.Append("线路有功损耗:," + lineLoss.ToString() + ",");
                                stResult.Append("变压器有功损耗:," + bLoss.ToString() + "\r\n");
                            }
                            wForm.ShowText += "\r\n正在进行N-1校验\t" + System.DateTime.Now.ToString();
                            ElcRel er = new ElcRel();
                            N1 = er.WebCalAndPrint(chaoliuSUID, Itop.Client.MIS.ProgUID, 100);
                            // wf.Close();
                        }
                        else
                        {
                            wForm.ShowText += "\r\n计算失败\t" + System.DateTime.Now.ToString();
                            MessageBox.Show("数据不收敛,请检查数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        }
                    }

                    {
                        if (fop.DuanLuSUID != null)
                        {
                            Application.DoEvents();
                            //WaitDialogForm wait = null;
                            //wait = new WaitDialogForm("", "正在处理数据, 请稍候...");
                            wForm.ShowText += "\r\n正在进行短路计算\t" + System.DateTime.Now.ToString();
                            ElectricShorti esc = new ElectricShorti();
                            esc.AllShortWJ(fop.DuanLuSUID, fop.ProjectID, 0, 100, null);
                            wForm.ShowText += "\r\n正在处理短路计算结果\t" + System.DateTime.Now.ToString();
                        }
                        else
                        {
                            Application.DoEvents();
                            //WaitDialogForm wait = null;
                            //wait = new WaitDialogForm("", "正在处理数据, 请稍候...");
                            wForm.ShowText += "\r\n正在进行短路计算\t" + System.DateTime.Now.ToString();
                            ElectricShorti esc = new ElectricShorti();
                            esc.AllShortWJ(chaoliuSUID, fop.ProjectID, 0, 100, null);
                            wForm.ShowText += "\r\n正在处理短路计算结果\t" + System.DateTime.Now.ToString();
                        }
                        // wait.Close();
                        if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\ShortcuitI.txt"))
                        {
                            StringBuilder dlrl = new StringBuilder();
                            FileStream shorcuit = new FileStream(System.Windows.Forms.Application.StartupPath + "\\ShortcuitI.txt", FileMode.Open);
                            StreamReader readLineGU = new StreamReader(shorcuit, System.Text.Encoding.Default);
                            string strLineGU;
                            string[] arrayGU;
                            char[] charSplitGU = new char[] { ' ' };
                            string strCon1 = ",PSP_ELCDEVICE WHERE PSPDEV.SUID = PSP_ELCDEVICE.DeviceSUID AND PSP_ELCDEVICE.ProjectSUID = '" + chaoliuSUID + "'";
                            string strCon2 = null;
                            string strCon = null;
                            double Ik = 0;
                            double Imax = 0;
                            double Imin = 0;
                            int ii = 0, ij = 0;
                            int num = 0;
                            strLineGU = readLineGU.ReadLine();
                            while ((strLineGU = readLineGU.ReadLine()) != null)
                            {
                                arrayGU = strLineGU.Split(charSplitGU, StringSplitOptions.RemoveEmptyEntries);
                                strCon2 = " AND Type= '01' AND Number = " + arrayGU[2] + " AND Name = '" + arrayGU[1] + "'";
                                strCon = strCon1 + strCon2;
                                PSPDEV devMX = (PSPDEV)Services.BaseService.GetObject("SelectPSPDEVByCondition", strCon);
                                if (devMX != null)
                                {
                                    double tempI = Convert.ToDouble(arrayGU[3]);
                                    Ik += tempI;
                                    num++;
                                    if (ii == 0)
                                    {
                                        Imax = tempI;
                                        Imin = tempI;
                                        ii++;
                                    }
                                    if (!shortI(tempI, (int)devMX.RateVolt))
                                    {
                                        ij++;
                                        dlrl.Append(devMX.Name + ",");
                                    }
                                    if (Imin >= tempI)
                                    {
                                        Imin = tempI;
                                    }
                                    else if (Imax < tempI)
                                    {
                                        Imax = tempI;
                                    }

                                }
                                else
                                {
                                    continue;
                                }

                            }
                            readLineGU.Close();
                            Ik = Ik / num;
                            stResult.Append("3 短路电流计算评价指标" + "\r\n");
                            stResult.Append("平均短路电流:," + Ik.ToString() + ",");
                            stResult.Append("最小短路电流:," + Imin.ToString() + ",");
                            stResult.Append("最大短路电流:," + Imax.ToString() + ",");
                            stResult.Append("短路电流超标母线数:," + ij.ToString() + "\r\n");
                            if (ij > 0)
                            {
                                stResult.Append("短路电流超标的母线为:" + dlrl.ToString() + "\r\n");
                            }
                        }
                        else
                        {
                            wForm.ShowText += "\r\n短路计算失败!\t" + System.DateTime.Now.ToString();
                        }

                    }

                    stResult.Append("4 N-1校核" + "\r\n");
                    if (N1)
                    {
                        stResult.Append("通过或不通过:," + "通过");
                    }
                    else
                    {
                        stResult.Append("通过或不通过:," + "不通过");
                    }
                    wForm.ShowText += "\r\n正在形成报表\t" + System.DateTime.Now.ToString();
                    if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\" + "result2.csv"))
                    {
                        File.Delete(System.Windows.Forms.Application.StartupPath + "\\" + "result2.csv");
                    }
                    FileStream re = new FileStream((System.Windows.Forms.Application.StartupPath + "\\result2.csv"), FileMode.OpenOrCreate);
                    StreamWriter str1 = new StreamWriter(re, Encoding.Default);
                    str1.Write(stResult);
                    str1.Close();

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

                    xSheet1.Name = "规划网评估";
                    xSheet1.get_Range(xSheet1.Cells[1, 1], xSheet1.Cells[1, 8]).MergeCells = true;
                    xSheet1.get_Range(xSheet1.Cells[1, 1], xSheet1.Cells[1, 1]).HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
                    xSheet1.get_Range(xSheet1.Cells[1, 1], xSheet1.Cells[1, 1]).Font.Size = 16;
                    xSheet1.get_Range(xSheet1.Cells[1, 1], xSheet1.Cells[1, 1]).Font.Name = "黑体";
                    xSheet1.get_Range(xSheet1.Cells[5, 2], xSheet1.Cells[5, 6]).NumberFormatLocal = "0.000%";
                    xSheet1.get_Range(xSheet1.Cells[8, 2], xSheet1.Cells[8, 6]).NumberFormatLocal = "0.000%";
                    xSheet1.get_Range(xSheet1.Cells[12, 2], xSheet1.Cells[12, 6]).NumberFormatLocal = "0.000%";
                    xSheet1.Rows.AutoFit();
                    xSheet1.Columns.AutoFit();

                    Excel.Worksheet xSheet = (Excel.Worksheet)ex.Worksheets.get_Item(2);
                    //ex.Worksheets.Add(System.Reflection.Missing.Value, xSheet, 1, System.Reflection.Missing.Value);
                    Excel.Worksheet newWorksheet = (Excel.Worksheet)ex.Worksheets.get_Item(3);
                    // ex.Worksheets.Add(System.Reflection.Missing.Value, newWorksheet, 3, System.Reflection.Missing.Value);
                    Excel.Worksheet tempSheet = (Excel.Worksheet)mx.Worksheets.get_Item(1);
                    tempSheet.Cells.Select();
                    tempSheet.Cells.Copy(System.Reflection.Missing.Value);
                    xSheet.Paste(System.Reflection.Missing.Value, System.Reflection.Missing.Value);

                    System.Windows.Forms.Clipboard.Clear();
                    tempSheet = (Excel.Worksheet)xl.Worksheets.get_Item(1);
                    tempSheet.Cells.Select();
                    tempSheet.Cells.Copy(System.Reflection.Missing.Value);
                    newWorksheet.Paste(System.Reflection.Missing.Value, System.Reflection.Missing.Value);
                    newWorksheet.Name = "线路电流";
                    xSheet.Name = "母线潮流";

                    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[7, 1], xSheet.Cells[7, 9]).Interior.ColorIndex = 45;
                    xSheet.get_Range(xSheet.Cells[8, 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[3, 1], xSheet.Cells[xSheet.UsedRange.Rows.Count, 9]).Font.Name = "楷体_GB2312";
                    //xSheet.get_Range(xSheet.Cells[3, 1], xSheet.Cells[xSheet.UsedRange.Rows.Count, 1]).NumberFormatLocal = "@";

                    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[7, 1], newWorksheet.Cells[7, 8]).Interior.ColorIndex = 45;
                    newWorksheet.get_Range(newWorksheet.Cells[8, 1], newWorksheet.Cells[newWorksheet.UsedRange.Rows.Count, 1]).Interior.ColorIndex = 6;
                    // newWorksheet.get_Range(newWorksheet.Cells[6, 1], newWorksheet.Cells[newWorksheet.UsedRange.Rows.Count, 1]).NumberFormatLocal = "@";
                    newWorksheet.get_Range(newWorksheet.Cells[8, 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.Default);
                    xSheet.Rows.AutoFit();
                    xSheet.Columns.AutoFit();
                    newWorksheet.Rows.AutoFit();
                    newWorksheet.Columns.AutoFit();
                    System.Windows.Forms.Clipboard.Clear();
                    ex.DisplayAlerts = false;
                    ex.Visible = true;
                    wForm.ShowText += "\r\n网架评估结束\t" + System.DateTime.Now.ToString();
                }
                //op.Initdata();  //临时修改
                //if (op.ShowDialog() == DialogResult.OK)
                //{

                //}

            }
            catch
            {
                wForm.ShowText += "\r\n网架评估失败\t" + System.DateTime.Now.ToString();
            }
            //wForm.Close();
        }