示例#1
0
        public bool LFCER(string projectSUID, int type, float ratedCapacity)
        {
            frnReport wForm = new frnReport();
            switch(type)
            {
                case 1:
                    wForm.Text = "牛拉法潮流计算";
                    break;
                case 2:
                    wForm.Text = "PQ分解法潮流计算";
                    break;
                case 3:
                    wForm.Text = "高斯—赛德尔法计算潮流计算";
                    break;
                case 4:
                    wForm.Text = "最优乘子法潮流计算";
                    break;
                default:
                    wForm.Text = "潮流计算";
                    break;
            }
            wForm.Show();
            wForm.ShowText += "选择结果输出方式\t" + System.DateTime.Now.ToString();
            bool flag = false;
            int iResult = 0;
            frmSelectSub frmSub = new frmSelectSub();
            frmSub.ShowDialog();
            if (frmSub.DialogResult==DialogResult.OK)
            {
                iResult = frmSub.SelectSub;
            }
            else if (frmSub.DialogResult== DialogResult.Cancel)
            {
                wForm.Close();
                return false;
            }
            System.Windows.Forms.Clipboard.Clear();
            flag = LFC(projectSUID, type, ratedCapacity,wForm);
            if (flag == false)
            {
                wForm.ShowText += "\r\n潮流计算结果不收敛,请检查数据\t" + System.DateTime.Now.ToString();
                wForm.ShowText += "\r\n计算失败\t" + System.DateTime.Now.ToString();
                return false;
            }
            try
            {
                if (type == 1)
                {
                    if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\" + projectSUID + "牛拉法计算结果.xls"))
                    {
                        //System.Diagnostics.Process.Start(System.Windows.Forms.Application.StartupPath + "\\" + tlVectorControl1.SVGDocument.FileName + "线损计算结果.xls");
                        File.Delete(System.Windows.Forms.Application.StartupPath + "\\" + projectSUID + "牛拉法计算结果.xls");
                        //OpenRead(System.Windows.Forms.Application.StartupPath + "\\" + tlVectorControl1.SVGDocument.FileName + ".xls");
                    }
                }
                else if (type == 2)
                {
                    if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\" + projectSUID + "PQ分解法计算结果.xls"))
                    {
                        //System.Diagnostics.Process.Start(System.Windows.Forms.Application.StartupPath + "\\" + tlVectorControl1.SVGDocument.FileName + "线损计算结果.xls");
                        File.Delete(System.Windows.Forms.Application.StartupPath + "\\" + projectSUID + "PQ分解法计算结果.xls");
                        //OpenRead(System.Windows.Forms.Application.StartupPath + "\\" + tlVectorControl1.SVGDocument.FileName + ".xls");
                    }

                }
                else if (type == 3)
                {
                    if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\" + projectSUID + "高斯—赛德尔法计算结果.xls"))
                    {
                        //System.Diagnostics.Process.Start(System.Windows.Forms.Application.StartupPath + "\\" + tlVectorControl1.SVGDocument.FileName + "线损计算结果.xls");
                        File.Delete(System.Windows.Forms.Application.StartupPath + "\\" + projectSUID + "高斯—赛德尔法计算结果.xls");
                        //OpenRead(System.Windows.Forms.Application.StartupPath + "\\" + tlVectorControl1.SVGDocument.FileName + ".xls");
                    }

                }
                else if (type == 4)
                {
                    if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\" + projectSUID + "最优乘子法计算结果.xls"))
                    {
                        //System.Diagnostics.Process.Start(System.Windows.Forms.Application.StartupPath + "\\" + tlVectorControl1.SVGDocument.FileName + "线损计算结果.xls");
                        File.Delete(System.Windows.Forms.Application.StartupPath + "\\" + projectSUID + "最优乘子法计算结果.xls");
                        //OpenRead(System.Windows.Forms.Application.StartupPath + "\\" + tlVectorControl1.SVGDocument.FileName + ".xls");
                    }
                }
                else if (type == 5)
                {
                    if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\" + projectSUID + "配网潮流计算结果.xls"))
                    {
                        //System.Diagnostics.Process.Start(System.Windows.Forms.Application.StartupPath + "\\" + tlVectorControl1.SVGDocument.FileName + "线损计算结果.xls");
                        File.Delete(System.Windows.Forms.Application.StartupPath + "\\" + projectSUID + "配网潮流计算结果.xls");
                        //OpenRead(System.Windows.Forms.Application.StartupPath + "\\" + tlVectorControl1.SVGDocument.FileName + ".xls");
                    }
                }

                wForm.ShowText += "\r\n正在形成报表\t" + System.DateTime.Now.ToString();

                string 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 strCon = ",PSPDEV WHERE PSPDEV.SUID = PSP_ELCDEVICE.DeviceSUID AND PSP_ELCDEVICE.ProjectSUID = '" + projectSUID + "'" + " AND PSPDEV.Type = '01' order by PSPDEV.RateVolt,PSPDEV.Name";
                IList list = Services.BaseService.GetList("SelectPSP_ElcDeviceByCondition", strCon);
                foreach (PSP_ElcDevice elcDEV in list)
                {
                    PSPDEV dev = new PSPDEV();
                    dev.SUID = elcDEV.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;
                    string voltF = "否";
                    string pF = "否";
                    if (dev.KSwitchStatus=="1")
                    {
                        continue;
                    }
                    if (Convert.ToDouble(GetColValue(elcDEV, type - 1).COL2) < dev.iV || Convert.ToDouble(GetColValue(elcDEV, type - 1).COL2) > dev.jV)
                    {
                        voltF = "是";
                    }
                    double tempi = Convert.ToDouble(GetColValue(elcDEV, type - 1).COL4);
                    double tempj = Convert.ToDouble(GetColValue(elcDEV, type - 1).COL5);
                    double temptotal = Math.Sqrt(tempi * tempi + tempj * tempj);
                    if (temptotal > (double)dev.Burthen)
                    {
                        pF = "是";
                    }

                    if (Convert.ToDouble(GetColValue(elcDEV, type - 1).COL4) > 0)
                    {
                        if (iResult == 0)
                        {
                            output += dev.Name + "," + Convert.ToDouble(GetColValue(elcDEV, type - 1).COL2).ToString() + "," + Convert.ToDouble(GetColValue(elcDEV, type - 1).COL3).ToString() + "," + Convert.ToDouble(GetColValue(elcDEV, type - 1).COL4).ToString() + "," + Convert.ToDouble(GetColValue(elcDEV, type - 1).COL5).ToString() + "," + "0" + "," + "0" + "," + voltF + "," + pF + "\r\n";
                        }
                        else
                        {
                            object obj = DeviceHelper.GetDevice<PSP_Substation_Info>(dev.SvgUID);

                            if (obj != null)
                            {
                                output += ((PSP_Substation_Info)obj).Title + "," + Convert.ToDouble(GetColValue(elcDEV, type - 1).COL2).ToString() + "," + Convert.ToDouble(GetColValue(elcDEV, type - 1).COL3).ToString() + "," + Convert.ToDouble(GetColValue(elcDEV, type - 1).COL4).ToString() + "," + Convert.ToDouble(GetColValue(elcDEV, type - 1).COL5).ToString() + "," + "0" + "," + "0" + "," + voltF + "," + pF + "\r\n";

                            }
                            else
                            {
                                obj = DeviceHelper.GetDevice<PSP_PowerSubstation_Info>(dev.SvgUID);
                                if (obj != null)
                                {
                                    output += ((PSP_PowerSubstation_Info)obj).Title + "," + Convert.ToDouble(GetColValue(elcDEV, type - 1).COL2).ToString() + "," + Convert.ToDouble(GetColValue(elcDEV, type - 1).COL3).ToString() + "," + Convert.ToDouble(GetColValue(elcDEV, type - 1).COL4).ToString() + "," + Convert.ToDouble(GetColValue(elcDEV, type - 1).COL5).ToString() + "," + "0" + "," + "0" + "," + voltF + "," + pF + "\r\n";

                                }
                            }

                        }
                    }
                    else
                    {
                        if (iResult == 0)
                        {
                            output += dev.Name + "," + Convert.ToDouble(GetColValue(elcDEV, type - 1).COL2).ToString() + "," + Convert.ToDouble(GetColValue(elcDEV, type - 1).COL3).ToString() + "," + "0" + "," + "0" + "," + Convert.ToDouble(GetColValue(elcDEV, type - 1).COL4).ToString() + "," + Convert.ToDouble(GetColValue(elcDEV, type - 1).COL5).ToString() + "," + voltF + "," + pF + "\r\n";
                        }
                        else
                        {
                            object obj = DeviceHelper.GetDevice<PSP_Substation_Info>(dev.SvgUID);

                            if (obj != null)
                            {
                                output += ((PSP_Substation_Info)obj).Title + "," + Convert.ToDouble(GetColValue(elcDEV, type - 1).COL2).ToString() + "," + Convert.ToDouble(GetColValue(elcDEV, type - 1).COL3).ToString() + "," + "0" + "," + "0" + "," + Convert.ToDouble(GetColValue(elcDEV, type - 1).COL4).ToString() + "," + Convert.ToDouble(GetColValue(elcDEV, type - 1).COL5).ToString() + "," + voltF + "," + pF + "\r\n";

                            }
                            else
                            {
                                obj = DeviceHelper.GetDevice<PSP_PowerSubstation_Info>(dev.SvgUID);
                                if (obj != null)
                                {
                                    output += ((PSP_PowerSubstation_Info)obj).Title + "," + Convert.ToDouble(GetColValue(elcDEV, type - 1).COL2).ToString() + "," + Convert.ToDouble(GetColValue(elcDEV, type - 1).COL3).ToString() + "," + "0" + "," + "0" + "," + Convert.ToDouble(GetColValue(elcDEV, type - 1).COL4).ToString() + "," + Convert.ToDouble(GetColValue(elcDEV, type - 1).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);
                }

                FileStream op = new FileStream((System.Windows.Forms.Application.StartupPath + "\\result.csv"), FileMode.OpenOrCreate);
                StreamWriter str1 = new StreamWriter(op, Encoding.Default);
                str1.Write(output);
                str1.Close();

                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 = '" + projectSUID + "'" + " AND PSPDEV.Type = '05'  order by PSPDEV.RateVolt,PSPDEV.Name";
                IList list1 = Services.BaseService.GetList("SelectPSP_ElcDeviceByCondition", strCon1);

                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, type - 1).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, type - 1).COL4).ToString() + "," + Convert.ToDouble(GetColValue(elcDEV, type - 1).COL5).ToString() + "," + Convert.ToDouble(GetColValue(elcDEV, type - 1).COL6).ToString() + "," + Convert.ToDouble(GetColValue(elcDEV, type - 1).COL7).ToString() + "," + Convert.ToDouble(GetColValue(elcDEV, type - 1).COL14).ToString() + "," + Convert.ToDouble(GetColValue(elcDEV, type - 1).COL15).ToString() + "," + lineF + "," + "\r\n";
                }
                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);
                }

                op = new FileStream((System.Windows.Forms.Application.StartupPath + "\\result1.csv"), FileMode.OpenOrCreate);
                str1 = new StreamWriter(op, Encoding.Default);
                str1.Write(output);
                str1.Close();
                Excel.Application ex;
                Excel.Worksheet xSheet;
                Excel.Application result1;
                Excel.Worksheet tempSheet;
                Excel.Worksheet newWorksheet;
                ex = new Excel.Application();
                ex.Application.Workbooks.Add(System.Windows.Forms.Application.StartupPath + "\\result.csv");
                xSheet = (Excel.Worksheet)ex.Worksheets[1];
                ex.Worksheets.Add(System.Reflection.Missing.Value, xSheet, 1, System.Reflection.Missing.Value);

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

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

                xSheet.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();

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

                if (type == 1)
                {
                    newWorksheet.SaveAs(System.Windows.Forms.Application.StartupPath + "\\" + projectSUID + "牛拉法计算结果.xls", Excel.XlFileFormat.xlXMLSpreadsheet, null, null, false, false, false, null, null, null);
                }
                else if (type == 2)
                {
                    newWorksheet.SaveAs(System.Windows.Forms.Application.StartupPath + "\\" + projectSUID + "PQ分解法计算结果.xls", Excel.XlFileFormat.xlXMLSpreadsheet, null, null, false, false, false, null, null, null);
                }
                else if (type == 3)
                {
                    newWorksheet.SaveAs(System.Windows.Forms.Application.StartupPath + "\\" + projectSUID + "高斯—赛德尔法计算结果.xls", Excel.XlFileFormat.xlXMLSpreadsheet, null, null, false, false, false, null, null, null);
                }
                else if (type == 4)
                {
                    newWorksheet.SaveAs(System.Windows.Forms.Application.StartupPath + "\\" + projectSUID + "最优乘子法计算结果.xls", Excel.XlFileFormat.xlXMLSpreadsheet, null, null, false, false, false, null, null, null);
                }
                else if (type == 5)
                {
                    newWorksheet.SaveAs(System.Windows.Forms.Application.StartupPath + "\\" + projectSUID + "配网潮流计算结果.xls", Excel.XlFileFormat.xlXMLSpreadsheet, null, null, false, false, false, null, null, null);
                }
                System.Windows.Forms.Clipboard.Clear();
                result1.Workbooks.Close();
                result1.Quit();

            }
            catch (System.Exception ex)
            {
                wForm.ShowText += "\r\n计算失败\t" + System.DateTime.Now.ToString();
                return false;
            }
            wForm.ShowText += "\r\n计算成功\t" + System.DateTime.Now.ToString();
            return flag;
        }