예제 #1
0
        private void barButtonItem13_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Init();  //刷新元件树
            resulttb = new DataTable();
            resulttb.Columns.Add("fhname", typeof(string));
            resulttb.Columns.Add("zbname", typeof(string));
            resulttb.Columns.Add("result", typeof(double));
            resulttb.Columns.Add("pdfs", typeof(string));
            resulttb.Columns.Add("A", typeof(string));
            resulttb.Columns.Add("B", typeof(string));
            order = 0;
            resultzbtb = new DataTable();
            resultzbtb.Columns.Add("fhname", typeof(string));
            resultzbtb.Columns.Add("zbname", typeof(string));
            resultzbtb.Columns.Add("result", typeof(double));
            resultzbtb.Columns.Add("pdfs", typeof(string));
            resultzbtb.Columns.Add("A", typeof(string));
            resultzbtb.Columns.Add("B", typeof(string));

             ExcelAccess ex = new ExcelAccess();
            try
            {

                SaveFileDialog saveFileDialog1 = new SaveFileDialog();
                string fname = Application.StartupPath + "\\xls\\tempt.xls";
                ex.Open(fname);
                //ex.ActiveSheet(1);
                ex.SetCellValue("指标", 1, 1);
                ex.SetCellValue("不同的配点方式", 1, 3);
                ex.AlignmentCells(1, 1, 1, 1, ExcelStyle.ExcelHAlign.居中, ExcelStyle.ExcelVAlign.居中);
                ex.SetFontStyle(1, 1, 1, 1, true, false, ExcelStyle.UnderlineStyle.无下划线);
                ex.CellsBackColor(1, 1, 1, 1, ExcelStyle.ColorIndex.黄色);
                ex.UnitCells(1, 1, 2, 2);
                DataTable dt = new DataTable();
                frmfxlx fm = new frmfxlx();
                if (fm.ShowDialog() == DialogResult.OK)
                {
                    dt = fm.DT1;
                    int columnscount = 0;
                    foreach (DataRow dr in dt.Rows)
                    {
                        if (Convert.ToInt32(dr["B"]) == 1)
                        {

                            TreeListNode tln = treeList1.FindNodeByKeyID(pdreltypeid);
                            bool flag = relanalsy(tln, Convert.ToInt32(dr["D"]), columnscount, ex);
                            columnscount++;
                            if (!flag)
                            {
                                ex.DisPoseExcel();
                                return;
                            }
                        }
                    }
                    //FrmResult FR = new FrmResult();
                    //FR.DT = resulttb;
                    //FR.DT1 = resultzbtb;
                    //FR.ShowDialog();
                    if (columnscount==0)
                    {
                        return;
                    }
                    ex.UnitCells(1, 3, 1, 2 + columnscount);
                    ex.AlignmentCells(1, 3, 1, 2 + columnscount, ExcelStyle.ExcelHAlign.居中, ExcelStyle.ExcelVAlign.居中);
                    ex.SetFontStyle(1, 3, 1, 2 + columnscount, true, false, ExcelStyle.UnderlineStyle.无下划线);
                    ex.CellsBackColor(1, 3, 1, 2 + columnscount, ExcelStyle.ColorIndex.黄色);
                    ex.ShowExcel();
                }
                else
                {
                    ex.DisPoseExcel();
                }

            }
            catch (System.Exception exe)
            {
                ex.DisPoseExcel();
                MessageBox.Show("存在问题!请检查数据后再计算");
            }
        }
예제 #2
0
        //以报表的形式输出结果
        //private void ExportExcel(string name)
        //{
        //    //if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\temp.xls"))
        //    //{
        //    //    File.Delete(System.Windows.Forms.Application.StartupPath + "\\temp.xls");
        //    //}
        //    //FileStream fs = new FileStream(System.Windows.Forms.Application.StartupPath + "\\temp.xls", FileMode.CreateNew);
        //    //fs.Dispose();
        //   ex = new ExcelAccess();
        //    SaveFileDialog saveFileDialog1 = new SaveFileDialog();
        //    string fname = Application.StartupPath + "\\xls\\tempt.xls";
        //    ex.Open(fname);
        //    //ex.ActiveSheet(1);
        //    try
        //    {
        //        ex.SetCellValue(name, 1, 1);
        //        ex.SetCellValue("不同的配点方式", 1, 3);
        //        ex.AlignmentCells(1, 1, 1, 1, ExcelStyle.ExcelHAlign.居中, ExcelStyle.ExcelVAlign.居中);
        //        ex.SetFontStyle(1, 1, 1, 1, true, false, ExcelStyle.UnderlineStyle.无下划线);
        //        ex.CellsBackColor(1, 1, 1, 1, ExcelStyle.ColorIndex.黄色);
        //        ex.UnitCells(1, 1, 2, 2);
        //    }
        //    catch (System.Exception e)
        //    {
        //    }
        //}
        //XL为分析的线路
        private bool relanalsy(TreeListNode xl, int fxtype,int columncounts,ExcelAccess ex)
        {
            foreach (TreeListNode tln in xl.Nodes)
            {
                if (tln.GetValue("devicetype").ToString() == "73" && string.IsNullOrEmpty(tln.GetValue("S1").ToString()) && !tln.GetValue("title").ToString().Contains("节点有问题"))
                {
                    //对子线路进行等值分析
                    dzanalsy(tln, fxtype);
                }
            }

            //求取主线相关联的负荷节点的 停电率 停电时间等
            //各个线路段对该层负荷点的 故障率和停运时间的影响
            Dictionary<PSPDEV ,List<rresult>> rescol=new Dictionary<PSPDEV,List<rresult>>();
            //主线路各负荷点的影响分析
            //下行等值化
            xxanaly(xl);

            //负荷分析
               if (everyxlanalyst(xl, ref rescol, fxtype))
               {
               //对其结果进行处理分析
               Dictionary<string, rresult> fhjg = new Dictionary<string, rresult>();
               foreach (KeyValuePair<PSPDEV, List<rresult>> kp in rescol)
               {
                   foreach (rresult re in kp.Value)
                   {
                       if (!fhjg.ContainsKey(re.deviceid.SUID))
                       {
                           fhjg.Add(re.deviceid.SUID, re);
                       }
                       else
                       {
                           rresult r = fhjg[re.deviceid.SUID];
                           r.gzl += re.gzl;
                           r.ntysj += re.ntysj;

                           fhjg[re.deviceid.SUID] = r;

                       }
                   }

               }
               Dictionary<string, rresult> fhjg1 = new Dictionary<string, rresult>();
               foreach (KeyValuePair<string, rresult> kp in fhjg)
               {
                   rresult r = kp.Value;
                   r.tysj = r.ntysj / r.gzl;
                   //重新赋其值
                   fhjg1[kp.Key] = r;
               }

               //输出结果

               int rownum = 0;
               foreach (KeyValuePair<string, rresult> kp in fhjg1)
               {
                   order++;

                   //DataRow row = resulttb.NewRow();
                   //row["fhname"] = kp.Value.deviceid.Name;
                   //row["zbname"] = "λ(次/年)";
                   //row["result"] = kp.Value.gzl;
                   //row["pdfs"] = "方式" + fxtype.ToString();
                   //row["A"] = order;
                   //resulttb.Rows.Add(row);
                   //row = resulttb.NewRow();
                   //row["fhname"] = kp.Value.deviceid.Name;
                   //row["zbname"] = "t(h)";
                   //row["result"] = kp.Value.tysj;
                   //row["pdfs"] = "方式" + fxtype.ToString();
                   //row["A"] = order;
                   //resulttb.Rows.Add(row);
                   //row = resulttb.NewRow();
                   //row["fhname"] = kp.Value.deviceid.Name;
                   //row["zbname"] = "T(h/年)";
                   //row["result"] = kp.Value.ntysj;
                   //row["pdfs"] = "方式" + fxtype.ToString();
                   //row["A"] = order;
                   //resulttb.Rows.Add(row);
                   //写到excel
                   if (columncounts == 0)
                   {
                       ex.SetCellValue(kp.Value.deviceid.Name, 3 + 3 * rownum, 1);

                       ex.UnitCells(3 + 3 * rownum, 1, 5 + 3 * rownum, 1);
                       ex.SetCellValue("λ(次/年)", 3 + 3 * rownum, 2);
                       ex.SetCellValue("t(h)", 4 + 3 * rownum, 2);
                       ex.SetCellValue("T(h/年)", 5 + 3 * rownum, 2);
                       ex.SetFontStyle(3 + 3 * rownum, 1, 5 + 3 * rownum, 1, true, true, ExcelStyle.UnderlineStyle.无下划线);
                       ex.AlignmentCells(3 + 3 * rownum, 1, 5 + 3 * rownum, 1, ExcelStyle.ExcelHAlign.居中, ExcelStyle.ExcelVAlign.居中);
                       ex.CellsBackColor(3 + 3 * rownum, 1, 5 + 3 * rownum, 1, ExcelStyle.ColorIndex.绿色);
                       ex.SetCellValue("方式" + fxtype.ToString(), 2, columncounts + 3);
                       ex.SetFontStyle(2, columncounts + 3, 2, columncounts + 3, true, true, ExcelStyle.UnderlineStyle.无下划线);
                       ex.CellsBackColor(2, columncounts + 3, 2, columncounts + 3, ExcelStyle.ColorIndex.黄色);
                       ex.SetCellValue(kp.Value.gzl.ToString(), 3 + 3 * rownum, columncounts + 3);
                       ex.SetCellValue(kp.Value.tysj.ToString(), 4 + 3 * rownum, columncounts + 3);
                       ex.SetCellValue(kp.Value.ntysj.ToString(), 5 + 3 * rownum, columncounts + 3);
                   }
                   else
                   {
                       ex.SetCellValue("方式" + fxtype.ToString(), 2, columncounts + 3);
                       ex.SetFontStyle(2, columncounts + 3, 2, columncounts + 3, true, true, ExcelStyle.UnderlineStyle.无下划线);
                       ex.CellsBackColor(2, columncounts + 3, 2, columncounts + 3, ExcelStyle.ColorIndex.黄色);
                       ex.SetCellValue(kp.Value.gzl.ToString(), 3 + 3 * rownum, columncounts + 3);
                       ex.SetCellValue(kp.Value.tysj.ToString(), 4 + 3 * rownum, columncounts + 3);
                       ex.SetCellValue(kp.Value.ntysj.ToString(), 5 + 3 * rownum, columncounts + 3);
                   }
                   rownum++;
               }

               //求结果
               double ACI = 0, CID = 0, SAIFI = 0, SAIDI = 0, CAIDI = 0, ASAI = 0, ASUI = 0, ASCI = 0, sumyh = 0;
               foreach (KeyValuePair<string, rresult> kp in fhjg1)
               {
                   ACI += kp.Value.deviceid.Num1 * kp.Value.gzl;
                   sumyh += kp.Value.deviceid.Num1;
                   CID += kp.Value.deviceid.Num1 * kp.Value.ntysj;
                   ASCI += kp.Value.deviceid.HuganTQ4 * kp.Value.ntysj;
               }
               SAIFI = ACI / sumyh;
               SAIDI = CID / sumyh;
               CAIDI = CID / ACI;
               ASAI = ((sumyh * 8760) - 605) / (sumyh * 8760);
               ASUI = 1 - ASAI;
               ASCI = ASCI / sumyh;
               order++;
               //DataRow row1 = resultzbtb.NewRow();

               //row1["zbname"] = "用户全年总停电次数ACI(次/年)";
               //row1["result"] = ACI;
               //row1["pdfs"] = "方式" + fxtype.ToString();
               //row1["A"] = order;
               //resultzbtb.Rows.Add(row1);
               //row1 = resultzbtb.NewRow();

               //row1["zbname"] = "用户总全年停电时间CID(h)";
               //row1["result"] = CID;
               //row1["pdfs"] = "方式" + fxtype.ToString();
               //row1["A"] = order;
               //resultzbtb.Rows.Add(row1);
               //row1 = resultzbtb.NewRow();

               //row1["zbname"] = "系统平均停电频率SAIFI(次/户·年)";
               //row1["result"] =SAIFI;
               //row1["pdfs"] = "方式" + fxtype.ToString();
               //row1["A"] = order;
               //resultzbtb.Rows.Add(row1);

               //row1 = resultzbtb.NewRow();
               //row1["zbname"] = "系统平均停电持续时间SAIDI(h/户·年)";
               //row1["result"] = SAIDI;
               //row1["pdfs"] = "方式" + fxtype.ToString();
               //row1["A"] = order;
               //resultzbtb.Rows.Add(row1);

               //row1 = resultzbtb.NewRow();
               //row1["zbname"] = "用户平均停电时间CAIDI(h/户·年)";
               //row1["result"] = CAIDI;
               //row1["pdfs"] = "方式" + fxtype.ToString();
               //row1["A"] = order;
               //resultzbtb.Rows.Add(row1);

               //row1 = resultzbtb.NewRow();
               //row1["zbname"] = "平均供电可用率ASAI";
               //row1["result"] = ASAI;
               //row1["pdfs"] = "方式" + fxtype.ToString();
               //row1["A"] = order;
               //resultzbtb.Rows.Add(row1);

               //row1 = resultzbtb.NewRow();
               //row1["zbname"] = "平均供电不可用率ASUI";
               //row1["result"] = ASUI;
               //row1["pdfs"] = "方式" + fxtype.ToString();
               //row1["A"] = order;
               //resultzbtb.Rows.Add(row1);

               //row1 = resultzbtb.NewRow();
               //row1["zbname"] = "平均系统缺电指标ASCI";
               //row1["result"] = ASCI;
               //row1["pdfs"] = "方式" + fxtype.ToString();
               //row1["A"] = order;
               //resultzbtb.Rows.Add(row1);

               //写到excel中
               if (columncounts == 0)
               {
                   ex.SetCellValue("系统", 3 + 3 * rownum, 1);
                   ex.UnitCells(3 + 3 * rownum, 1, 10 + 3 * rownum, 1);
                   ex.SetFontStyle(3 + 3 * rownum, 1, 10 + 3 * rownum, 1, true, true, ExcelStyle.UnderlineStyle.无下划线);

                   ex.AlignmentCells(3 + 3 * rownum, 1, 10 + 3 * rownum, 1, ExcelStyle.ExcelHAlign.居中, ExcelStyle.ExcelVAlign.居中);
                   ex.CellsBackColor(3 + 3 * rownum, 1, 10 + 3 * rownum, 1, ExcelStyle.ColorIndex.绿色);
                   ex.SetCellValue("用户全年总停电次数ACI(次/年)", 3 + 3 * rownum, 2);
                   ex.SetCellValue("用户总全年停电时间CID(h)", 4 + 3 * rownum, 2);
                   ex.SetCellValue("系统平均停电频率SAIFI(次/户·年)", 5 + 3 * rownum, 2);
                   ex.SetCellValue("系统平均停电持续时间SAIDI(h/户·年)", 6 + 3 * rownum, 2);
                   ex.SetCellValue("系用户平均停电时间CAIDI(h/户·年)", 7 + 3 * rownum, 2);
                   ex.SetCellValue("平均供电可用率ASAI", 8 + 3 * rownum, 2);
                   ex.SetCellValue("平均供电不可用率ASUI", 9 + 3 * rownum, 2);
                   ex.SetCellValue("平均系统缺电指标ASCI", 10 + 3 * rownum, 2);
                   // ex.SetCellValue("方式" + fxtype.ToString(), 1, columncounts + 2);
                   ex.SetCellValue(ACI.ToString(), 3 + 3 * rownum, columncounts + 3);
                   ex.SetCellValue(CID.ToString(), 4 + 3 * rownum, columncounts + 3);
                   ex.SetCellValue(SAIFI.ToString(), 5 + 3 * rownum, columncounts + 3);
                   ex.SetCellValue(SAIDI.ToString(), 6 + 3 * rownum, columncounts + 3);
                   ex.SetCellValue(CAIDI.ToString(), 7 + 3 * rownum, columncounts + 3);
                   ex.SetCellValue(ASAI.ToString(), 8 + 3 * rownum, columncounts + 3);
                   ex.SetCellValue(ASUI.ToString(), 9 + 3 * rownum, columncounts + 3);
                   ex.SetCellValue(ASCI.ToString(), 10 + 3 * rownum, columncounts + 3);

               }
               else
               {
                   ex.SetCellValue(ACI.ToString(), 3 + 3 * rownum, columncounts + 3);
                   ex.SetCellValue(CID.ToString(), 4 + 3 * rownum, columncounts + 3);
                   ex.SetCellValue(SAIFI.ToString(), 5 + 3 * rownum, columncounts + 3);
                   ex.SetCellValue(SAIDI.ToString(), 6 + 3 * rownum, columncounts + 3);
                   ex.SetCellValue(CAIDI.ToString(), 7 + 3 * rownum, columncounts + 3);
                   ex.SetCellValue(ASAI.ToString(), 8 + 3 * rownum, columncounts + 3);
                   ex.SetCellValue(ASUI.ToString(), 9 + 3 * rownum, columncounts + 3);
                   ex.SetCellValue(ASCI.ToString(), 10 + 3 * rownum, columncounts + 3);
               }
               return true;
               }
            else
               {
               return false;
               }
        }
예제 #3
0
        private void Extbdzreport(ArrayList extsublist1)
        {
            ExcelAccess ex = new ExcelAccess();
            try
            {

                string fname = Application.StartupPath + "\\xls\\tempt.xls";
                ex.Open(fname);
                //ex.ActiveSheet(1);
                ex.SetCellValue("变电站名称", 1, 1);
                ex.SetCellValue("容量", 1, 2);
                ex.SetCellValue("容载比", 1, 3);

                ex.AlignmentCells(1, 1, 1, 3, ExcelStyle.ExcelHAlign.居中, ExcelStyle.ExcelVAlign.居中);
                ex.SetFontStyle(1, 1, 1, 3, true, false, ExcelStyle.UnderlineStyle.无下划线);
                ex.CellsBackColor(1, 1, 1, 3, ExcelStyle.ColorIndex.黄色);

                //输出地块负荷情况
                ex.SetCellValue("变电站供应负荷情况", 3 + extsublist1.Count, 1);
                ex.UnitCells(3 + extsublist.Count, 1, 3 + extsublist1.Count, 3);
                ex.SetCellValue("变电站名称", 4 + extsublist1.Count, 1);
                ex.SetCellValue("地块编号", 4 + extsublist1.Count, 2);
                ex.SetCellValue("供应负荷", 4 + extsublist1.Count, 3);
                ex.AlignmentCells(3 + extsublist1.Count, 1, 4 + extsublist.Count, 3, ExcelStyle.ExcelHAlign.居中, ExcelStyle.ExcelVAlign.居中);
                ex.SetFontStyle(3 + extsublist1.Count, 1, 4 + extsublist.Count, 3, true, false, ExcelStyle.UnderlineStyle.无下划线);
                ex.CellsBackColor(3 + extsublist1.Count, 1, 4 + extsublist.Count, 3, ExcelStyle.ColorIndex.黄色);

                int rowcount = 0;
                for (int i = 0; i < extsublist1.Count; i++)
                {
                    XmlElement xe = extsublist1[i] as XmlElement;
                    if (!string.IsNullOrEmpty(xe.GetAttribute("subname")))
                    {
                        ex.SetCellValue(xe.GetAttribute("subname"), 2 + i, 1);
                        ex.AlignmentCells(2 + i, 1, 2 + i, 1, ExcelStyle.ExcelHAlign.居中, ExcelStyle.ExcelVAlign.居中);
                        ex.SetFontStyle(2 + i, 1, 2 + i, 1, true, false, ExcelStyle.UnderlineStyle.无下划线);
                        ex.CellsBackColor(2 + i, 1, 2 + i, 1, ExcelStyle.ColorIndex.绿色);
                    }
                    if (!string.IsNullOrEmpty(xe.GetAttribute("rl")))
                    {
                        ex.SetCellValue(xe.GetAttribute("rl"), 2 + i, 2);
                        ex.AlignmentCells(2 + i, 2, 2 + i, 2, ExcelStyle.ExcelHAlign.居中, ExcelStyle.ExcelVAlign.居中);
                        ex.SetFontStyle(2 + i, 2, 2 + i, 2, true, false, ExcelStyle.UnderlineStyle.无下划线);

                    }
                    if (!string.IsNullOrEmpty(xe.GetAttribute("yfcrzb")))
                    {
                        ex.SetCellValue(xe.GetAttribute("yfcrzb"), 2 + i, 3);
                        ex.AlignmentCells(2 + i, 3, 2 + i, 3, ExcelStyle.ExcelHAlign.居中, ExcelStyle.ExcelVAlign.居中);
                        ex.SetFontStyle(2 + i, 3, 2 + i, 3, true, false, ExcelStyle.UnderlineStyle.无下划线);

                    }
                    //地块负荷供应情况
                    string fhdk = xe.GetAttribute("fhdk");
                    if (!string.IsNullOrEmpty(fhdk))
                    {
                        string[] dkqk = (fhdk.Substring(0, fhdk.LastIndexOf(";"))).Split(';');

                        for (int j = 0; j < dkqk.Length; j++)
                        {
                            string[] dk = dkqk[j].Split(',');
                            if (!string.IsNullOrEmpty(xe.GetAttribute("subname")))
                            {
                                ex.SetCellValue(xe.GetAttribute("subname"), 5 + extsublist1.Count + rowcount, 1);
                                ex.AlignmentCells(5 + extsublist1.Count + rowcount, 1, 5 + extsublist1.Count + rowcount, 1, ExcelStyle.ExcelHAlign.居中, ExcelStyle.ExcelVAlign.居中);
                                ex.SetFontStyle(5 + extsublist1.Count + rowcount, 1, 5 + extsublist1.Count + rowcount, 1, true, false, ExcelStyle.UnderlineStyle.无下划线);
                                ex.CellsBackColor(5 + extsublist1.Count + rowcount, 1, 5 + extsublist1.Count + rowcount, 1, ExcelStyle.ColorIndex.绿色);

                            }

                            if (dk.Length > 0)
                            {
                                glebeProperty pl = new glebeProperty();
                                pl.EleID = dk[0];
                                pl.SvgUID = tlVectorControl1.SVGDocument.SvgdataUid;
                                pl = (glebeProperty)Services.BaseService.GetObject("SelectglebePropertyByEleID", pl);

                                ex.SetCellValue(pl.UseID, 5 + extsublist1.Count + rowcount, 2);
                                ex.SetCellValue((Convert.ToDouble(dk[1]) / dbl_rzb).ToString("N2"), 5 + extsublist1.Count + rowcount, 3);
                                ex.AlignmentCells(5 + extsublist1.Count + rowcount, 2, 5 + extsublist1.Count + rowcount, 3, ExcelStyle.ExcelHAlign.居中, ExcelStyle.ExcelVAlign.居中);
                                ex.SetFontStyle(5 + extsublist1.Count + rowcount, 2, 5 + extsublist1.Count + rowcount, 3, true, false, ExcelStyle.UnderlineStyle.无下划线);
                            }
                            rowcount++;
                        }
                    }

                }

                ex.ShowExcel();
            }
            catch (System.Exception e)
            {
                ex.DisPoseExcel();
            }
        }