EMSV1.5.0能源管理系统 软件源代码V1.00_第1页
EMSV1.5.0能源管理系统 软件源代码V1.00_第2页
EMSV1.5.0能源管理系统 软件源代码V1.00_第3页
EMSV1.5.0能源管理系统 软件源代码V1.00_第4页
EMSV1.5.0能源管理系统 软件源代码V1.00_第5页
已阅读5页,还剩80页未读 继续免费阅读

付费下载

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

EMSV1.5.0能源管理系统软件源代码文件编号生效日期受控编号保密级别一级版本号V1.00修改次数总页数85正文81附录无编制项目组各成员审核批准(版权所有,翻版必究)

评审记录对《EMSV1.5.0能源管理系统软件源代码V1.00》的评审意见上述问题修改验证后,由验证后,本文件即可发布。评审人员签字:问题修改验证结果:验证人签字:时间:年月日 变更日志编号版本修改内容修改人修改日期1V1.00初稿项目组各成员2017-10-30

目录1. EMS1.5.0代码审核报告 51.1 集成管理工具 51.2 变压器负载率报告 631.3 滑动能耗分析 681.4 碳排放 731.5 App接口 81

EMS1.5.0代码审核报告集成管理工具usingFramework.Common;usingFramework.Configuration;usingFramework.Data;usingFramework.DataConfiguration;usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.IO;usingSystem.Linq;usingSystem.ServiceProcess;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;usingSystem.Xml;usingSystem.ServiceModel;usingSystem.Configuration;usingIOMSRegister;namespaceIntegrateManageTool{publicpartialclassForm1:Form{IntegrateManageTool.BLL.CommonBllbll=newBLL.CommonBll();boolisFirstInit=false;publicForm1(){InitializeComponent();//防止线程间访问出错,临时加此属性。终极解决办法是委托或使用BackgroundWorker控件屈云明20170719DataGridView.CheckForIllegalCrossThreadCalls=false;}///<summary>///主画面加载///</summary>///<paramname="sender"></param>///<paramname="e"></param>privatevoidForm1_Load(objectsender,EventArgse){Common.WriteLog.CreateLog("开始启动集成管理工具");try{this.btnRefreshAll.Image=Image.FromFile(System.Windows.Forms.Application.StartupPath+"\\Resources\\refresh.png");this.btnAdd.Image=Image.FromFile(System.Windows.Forms.Application.StartupPath+"\\Resources\\add.png");this.btnStart.Image=Image.FromFile(System.Windows.Forms.Application.StartupPath+"\\Resources\\start.png");this.btnRestart.Image=Image.FromFile(System.Windows.Forms.Application.StartupPath+"\\Resources\\restart.png");this.btnDelete.Image=Image.FromFile(System.Windows.Forms.Application.StartupPath+"\\Resources\\delete.png");this.btnClose.Image=Image.FromFile(System.Windows.Forms.Application.StartupPath+"\\Resources\\close.png");this.btnApply.Image=Image.FromFile(System.Windows.Forms.Application.StartupPath+"\\Resources\\save.png");this.btnQuit.Image=Image.FromFile(System.Windows.Forms.Application.StartupPath+"\\Resources\\power.png");this.btnWcfOpen.Image=Image.FromFile(System.Windows.Forms.Application.StartupPath+"\\Resources\\startservice.png");this.btnWcfClose.Image=Image.FromFile(System.Windows.Forms.Application.StartupPath+"\\Resources\\stopservice.png");this.btnInstall.Image=Image.FromFile(System.Windows.Forms.Application.StartupPath+"\\Resources\\install.png");this.btnModeSwitch.Image=Image.FromFile(System.Windows.Forms.Application.StartupPath+"\\Resources\\setting.png");this.btnReadMe.Image=Image.FromFile(System.Windows.Forms.Application.StartupPath+"\\Resources\\help.png");//先加载Program.config里面的程序。若在数据库中没有就先保存入数据库。后面一律以数据库保存的为准LoadXmlProgramToDatabase();//调用刷新按钮事件初始化数据this.btnRefreshAll_Click(null,null);System.Threading.Thread.Sleep(1000);//先把集成管理工具的数据库批量适用到所有工具this.ModifyDataSrc();System.Threading.Thread.Sleep(1000);//调用刷新按钮事件初始化数据this.btnRefreshAll_Click(null,null);//定期检查进程或服务是否正常ScheduleWork();//高级功能根据配置显示if(System.Configuration.ConfigurationManager.AppSettings["IsShowAdvancedFunction"].ToLower().Equals("false")){this.groupBox3.Visible=false;this.btnModeSwitch.Visible=false;this.btnInstall.Visible=false;this.label1.Location=newPoint(this.label1.Location.X,480);this.label2.Location=newPoint(this.label2.Location.X,500);this.btnReadMe.Location=newPoint(this.btnReadMe.Location.X,480);this.btnQuit.Location=newPoint(this.btnQuit.Location.X,480);}}catch(Exceptionex){Common.WriteLog.CreateLog("启动异常:"+ex.Message);MessageBox.Show("启动异常:"+ex.Message,"出错啦",MessageBoxButtons.OK,MessageBoxIcon.Error);}Common.WriteLog.CreateLog("启动成功");//开始服务this.Start();}///<summary>///先把集成管理工具的数据库批量适用到所有工具///</summary>privatevoidModifyDataSrc(){if(isFirstInit){//当存在数据时,认为不是初始化,批量修改数据的操作return;}//%%%%%%%%%%%%%%%%%%%%%%%%%%%//初始化把数据库全部修改一遍//修改数据库连接//先判断数据库配置文件是否存在stringconnectstringTmp=string.Empty;if(System.IO.File.Exists(Application.StartupPath+"\\"+GlobalConfigurationSource.GlobalAppSettings["DatabaseListFile"])){//加载数据源DatabaseListdatabaseList=XmlHelper.XmlDeserializeFromFile<DatabaseList>(Application.StartupPath+"\\"+GlobalConfigurationSource.GlobalAppSettings["DatabaseListFile"],Encoding.UTF8);if(!string.IsNullOrEmpty(databaseList.MDatabaseInstances[0].ConnectionString)){connectstringTmp=databaseList.MDatabaseInstances[0].ConnectionString;}}else{//文件不存在的情况下记录日志后继续执行MessageBox.Show("不存在数据库文件!请检查。"+Application.StartupPath+"\\"+GlobalConfigurationSource.GlobalAppSettings["DatabaseListFile"]);}for(inti=0;i<this.dgvExeList.Rows.Count;i++){//必须有数据源才需要修改屈云明20170720if(dgvExeList.Rows[i].Cells["是否有数据源"].Value.Equals(1)){//必须名称有值的数据才有意义if(dgvExeList.Rows[i].Cells["名称"].Value!=null){XmlDocumentxml2=newXmlDocument();xml2.Load(this.dgvExeList.Rows[i].Cells["路径"].Value.ToString()+"configs\\Database.config");XmlNodexnTmp=xml2.DocumentElement;foreach(XmlNodenodeinxnTmp.ChildNodes){if(node.Name=="database"){foreach(XmlNodenode2innode.ChildNodes){node2.InnerText=connectstringTmp;}}}xml2.Save(this.dgvExeList.Rows[i].Cells["路径"].Value.ToString()+"configs\\Database.config");}}}//%%%%%%%%%%%%%%%%%%%%%%%%%%%}///<summary>///把Program.config里面配置的程序加载入数据库///</summary>privatevoidLoadXmlProgramToDatabase(){isFirstInit=bll.IsHaveDataInDB();if(isFirstInit){//当存在数据时,认为不是初始化,跳过读取Program.config的逻辑return;}//@@@@@@@@@@@@@@@@@@@@@@@@@@@@//tobecontinued把xml序列化为二进制对象,使用时再从二进制对象反序列化为xml。目的是防止用户来修改//夏工的意思是初始化文件装机时肯定存在,且永远只用一次。不考虑其他异常情况if(!System.IO.File.Exists(System.Windows.Forms.Application.StartupPath+"\\configs\\Program.config")){MessageBox.Show("执行路径根目录下找不到Program.config文件,请仔细检查\r\n路径:"+Application.StartupPath+"\\configs","文件未找到",MessageBoxButtons.OK,MessageBoxIcon.Error);return;}List<Model.ManageConfig>lstMc=newList<Model.ManageConfig>();XmlDocumentdoc=newXmlDocument();doc.Load(System.Windows.Forms.Application.StartupPath+"\\configs\\Program.config");XmlNodexn=doc.SelectSingleNode("configuration");DirectoryInfoinfo=newDirectoryInfo(Application.StartupPath);stringparentPath=info.Parent.FullName;foreach(XmlNodexn1inxn){if(xn1.OuterXml.Contains("!--")){continue;}if(xn1.Name.Equals("add")){Model.ManageConfigmc=newModel.ManageConfig();mc.Cname=xn1.SelectSingleNode("@name").InnerText;mc.ExePath=parentPath+xn1.SelectSingleNode("@relativePath").InnerText;mc.WorkType=int.Parse(xn1.SelectSingleNode("@workType").InnerText);mc.ServiceName=xn1.SelectSingleNode("@serviceName").InnerText;//存在某些程序不需要数据库配置屈云明20170720mc.IsHaveDataSrc=int.Parse(xn1.SelectSingleNode("@isHaveDataSrc").InnerText);mc.Comments="根据Program.config自动添加的";lstMc.Add(mc);}}//保存入数据库stringerrInfo=string.Empty;//返回0表示插入失败if(this.bll.BatchInsertIntoIntegrateManageConfig(lstMc,referrInfo)==0){Common.WriteLog.CreateLog("把Program.config的插入数据库失败。"+errInfo);MessageBox.Show("把Program.config的插入数据库失败。"+errInfo,"出错了",MessageBoxButtons.OK,MessageBoxIcon.Error);}//@@@@@@@@@@@@@@@@@@@@@@@@@@@@}privatevoidScheduleWork(){try{//设定固定时间检查进程是否存在,并记录日志vartimer=newSystem.Timers.Timer{Interval=int.Parse(System.Configuration.ConfigurationManager.AppSettings["checkFrenquency"])*1000,Enabled=true,AutoReset=true};timer.Elapsed+=(sender,e)=>{boolisHaveUninstallService=false;boolisHaveStoppedData=false;if(this.btnModeSwitch.Text.Equals("手动模式中")){Common.WriteLog.CreateLog("当前在"+this.btnModeSwitch.Text+",跳过定期检查并启动已停止的程序功能");return;}elseif(this.btnModeSwitch.Text.Equals("自动模式中")){Common.WriteLog.CreateLog("当前在"+this.btnModeSwitch.Text+",即将检查并启动已停止的程序");}else{Common.WriteLog.CreateLog("当前既不是手动模式,也不是自动模式。这是非常严重的问题,请联系程序开发人员!");return;}//#########################//先刷新grid的状态for(inti=0;i<this.dgvExeList.RowCount;i++){if(this.dgvExeList.Rows[i].Cells["类型"].Value.ToString().Equals(Model.EnumWorkType.WorkType.应用程序.ToString())){//状态实时获取boolbInTaskMgr=Common.Function.isExistInTaskMgr(this.dgvExeList.Rows[i].Cells["名称"].Value.ToString().Trim());stringsStatus=string.Empty;if(bInTaskMgr){sStatus="Running";this.dgvExeList.Rows[i].DefaultCellStyle.BackColor=Color.White;}else{sStatus="Stopped";this.dgvExeList.Rows[i].DefaultCellStyle.BackColor=Color.Red;Common.WriteLog.CreateLog("自动侦测到应用程序"+this.dgvExeList.Rows[i].Cells["名称"].Value.ToString()+"进程已经不存在于任务管理器中");}this.dgvExeList.Rows[i].Cells["状态"].Value=sStatus;//状态实时获取}elseif(this.dgvExeList.Rows[i].Cells["类型"].Value.ToString().Equals(Model.EnumWorkType.WorkType.服务程序.ToString())){//当服务程序的服务名称没有时,提示if(string.IsNullOrEmpty(this.dgvExeList.Rows[i].Cells["服务名称"].Value.ToString().Trim())){Common.WriteLog.CreateLog("加载"+this.dgvExeList.Rows[i].Cells["服务名称"].Value.ToString().Trim()+"时出错,服务名称为空。请检查");}else{stringsStatus=string.Empty;if(Common.Function.IsExistsService(this.dgvExeList.Rows[i].Cells["服务名称"].Value.ToString().Trim())){sStatus=Common.Function.GetServiceState(this.dgvExeList.Rows[i].Cells["服务名称"].Value.ToString().Trim()).ToString();}else{sStatus="未安装";Common.WriteLog.CreateLog("自动侦测到服务程序"+this.dgvExeList.Rows[i].Cells["服务名称"].Value.ToString()+"没有安装");}this.dgvExeList.Rows[i].Cells["状态"].Value=sStatus;//状态实时获取if(!sStatus.Equals("Running")){Common.WriteLog.CreateLog("自动侦测到服务程序"+this.dgvExeList.Rows[i].Cells["服务名称"].Value.ToString()+"的状态为"+sStatus);}}}else{Common.WriteLog.CreateLog("程序"+this.dgvExeList.Rows[i].Cells["名称"].Value.ToString()+"类型不是应用程序也不是服务程序!");this.dgvExeList.Rows[i].DefaultCellStyle.BackColor=Color.Red;continue;}}//#########################//先判断有无未安装的服务for(inti=0;i<this.dgvExeList.RowCount;i++){if(this.dgvExeList.Rows[i].Cells["类型"].Value.ToString().Equals(Model.EnumWorkType.WorkType.服务程序.ToString())){if(this.dgvExeList.Rows[i].Cells["状态"].Value.ToString().Equals("未安装")){DataGridViewCheckBoxCellcheckCell=(DataGridViewCheckBoxCell)dgvExeList.Rows[i].Cells["选择"];checkCell.Value=true;isHaveUninstallService=true;}}}//存在未安装的服务if(isHaveUninstallService){this.btnInstall_Click(null,null);}else{//若无未安装的服务,则检查有无stopped的程序for(inti=0;i<this.dgvExeList.RowCount;i++){if(this.dgvExeList.Rows[i].Cells["状态"].Value.ToString().Equals("Stopped")){DataGridViewCheckBoxCellcheckCell=(DataGridViewCheckBoxCell)dgvExeList.Rows[i].Cells["选择"];checkCell.Value=true;isHaveStoppedData=true;}}//存在则把停止的程序启动if(isHaveStoppedData){timer.Stop();this.btnStart_Click(null,null);timer.Start();}}};}catch(Exceptionex){Common.WriteLog.CreateLog("ScheduleWork方法出现异常:"+ex.Message);}}///<summary>///全部刷新按钮按下后,从数据库和配置文件中重载所有参数///</summary>///<paramname="sender"></param>///<paramname="e"></param>privatevoidbtnRefreshAll_Click(objectsender,EventArgse){//先不用绑定数据源,直接赋值灵活点//this.dgvExeList.DataSource=bll.GetAllExe();//实现要清空表格,不然刷新时返回0条数据不会重绘表格this.dgvExeList.Rows.Clear();List<Model.ManageConfig>list=bll.GetAllExe();//grid好像不能把列数变为0this.dgvExeList.RowCount=(list.Count==0)?1:list.Count;intindex=0;foreach(Model.ManageConfigmcinlist){try{DataGridViewCheckBoxCellcb=newDataGridViewCheckBoxCell(false);cb.Value=false;this.dgvExeList.Rows[index].Cells["选择"]=cb;this.dgvExeList.Rows[index].Cells["名称"].Value=mc.Cname;this.dgvExeList.Rows[index].Cells["类型"].Value=(mc.WorkType==1)?Model.EnumWorkType.WorkType.应用程序:Model.EnumWorkType.WorkType.服务程序;this.dgvExeList.Rows[index].Cells["路径"].Value=mc.ExePath;this.dgvExeList.Rows[index].Cells["备注"].Value=mc.Comments;this.dgvExeList.Rows[index].Cells["主键"].Value=mc.ObjectId;this.dgvExeList.Rows[index].Cells["服务名称"].Value=mc.ServiceName;this.dgvExeList.Rows[index].Cells["是否有数据源"].Value=mc.IsHaveDataSrc;//##################//必须存在数据源的情况下才需要读取配置文件屈云明20170720if(this.dgvExeList.Rows[index].Cells["是否有数据源"].Value.Equals(1)){//先判断数据库配置文件是否存在if(System.IO.File.Exists(mc.ExePath+GlobalConfigurationSource.GlobalAppSettings["DatabaseListFile"])){//加载数据源DatabaseListdatabaseList=XmlHelper.XmlDeserializeFromFile<DatabaseList>(mc.ExePath+"\\"+GlobalConfigurationSource.GlobalAppSettings["DatabaseListFile"],Encoding.UTF8);if(!string.IsNullOrEmpty(databaseList.MDatabaseInstances[0].ConnectionString)){this.dgvExeList.Rows[index].Cells["数据源"].Value=databaseList.MDatabaseInstances[0].ConnectionString;}}else{//文件不存在的情况下记录日志后继续执行Common.WriteLog.CreateLog("不存在文件!请检查。"+mc.ExePath+"\\"+GlobalConfigurationSource.GlobalAppSettings["DatabaseListFile"]);this.dgvExeList.Rows[index].DefaultCellStyle.BackColor=Color.Red;}}//##################//@@@@@@@@@@@@@@@@@@@@@@@@if(this.dgvExeList.Rows[index].Cells["类型"].Value.ToString().Equals(Model.EnumWorkType.WorkType.应用程序.ToString())){//状态实时获取boolbInTaskMgr=Common.Function.isExistInTaskMgr(mc.Cname.Trim());stringsStatus=string.Empty;if(bInTaskMgr){sStatus="Running";this.dgvExeList.Rows[index].DefaultCellStyle.BackColor=Color.White;}else{sStatus="Stopped";this.dgvExeList.Rows[index].DefaultCellStyle.BackColor=Color.Red;}this.dgvExeList.Rows[index].Cells["状态"].Value=sStatus;//状态实时获取}elseif(this.dgvExeList.Rows[index].Cells["类型"].Value.ToString().Equals(Model.EnumWorkType.WorkType.服务程序.ToString())){//当服务程序的服务名称没有时,提示if(string.IsNullOrEmpty(mc.ServiceName)){Common.WriteLog.CreateLog("加载"+mc.Cname+"时出错,服务名称为空。请检查");}else{stringsStatus=string.Empty;if(Common.Function.IsExistsService(mc.ServiceName.Trim())){sStatus=Common.Function.GetServiceState(mc.ServiceName.Trim()).ToString();if(sStatus.Equals("Running")){this.dgvExeList.Rows[index].DefaultCellStyle.BackColor=Color.White;}else{this.dgvExeList.Rows[index].DefaultCellStyle.BackColor=Color.Red;}}else{sStatus="未安装";this.dgvExeList.Rows[index].DefaultCellStyle.BackColor=Color.Red;}this.dgvExeList.Rows[index].Cells["状态"].Value=sStatus;//状态实时获取}}else{Common.WriteLog.CreateLog("程序"+this.dgvExeList.Rows[index].Cells["名称"].Value.ToString()+"类型不是应用程序也不是服务程序!");this.dgvExeList.Rows[index].DefaultCellStyle.BackColor=Color.Red;continue;}//@@@@@@@@@@@@@@@@@@@@@@@@index++;}catch(Exceptionex){Common.WriteLog.CreateLog("加载"+mc.Cname+"时出错,请检查"+ex.Message);continue;}}}///<summary>///弹出新增画面///</summary>///<paramname="sender"></param>///<paramname="e"></param>privatevoidbtnAdd_Click(objectsender,EventArgse){frmAddOrModifyfrm=newfrmAddOrModify();frm.StrIndicator="Add";if(frm.ShowDialog().Equals(DialogResult.OK)){//刷新this.btnRefreshAll_Click(null,null);}else{//取消按钮,什么也不做}}///<summary>///退出工具///</summary>///<paramname="sender"></param>///<paramname="e"></param>privatevoidbtnQuit_Click(objectsender,EventArgse){//会触发formclosig事件,那边会记录日志this.Close();}///<summary>///各种按钮的点击事件///</summary>///<paramname="sender"></param>///<paramname="e"></param>privatevoiddgvExeList_CellClick(objectsender,DataGridViewCellEventArgse){try{//点击列头或行头,不执行任何逻辑if(e.RowIndex==-1||e.ColumnIndex==-1){return;}//选择列if(this.dgvExeList.Columns[e.ColumnIndex].Name.Equals("选择")){DataGridViewCheckBoxCellcheckCell=(DataGridViewCheckBoxCell)dgvExeList.Rows[e.RowIndex].Cells["选择"];Booleanflag=Convert.ToBoolean(checkCell.Value);checkCell.Value=!flag;}elseif(this.dgvExeList.Columns[e.ColumnIndex].Name.Equals("安装")){//第7列是安装列。只有服务程序才需要安装if(this.dgvExeList.Rows[e.RowIndex].Cells["类型"].Value.ToString()==Model.EnumWorkType.WorkType.应用程序.ToString()){MessageBox.Show(this.dgvExeList.Rows[e.RowIndex].Cells["名称"].Value.ToString()+"是应用程序,不需要安装","不需要安装",MessageBoxButtons.OK,MessageBoxIcon.Information);return;}elseif(this.dgvExeList.Rows[e.RowIndex].Cells["类型"].Value.ToString()==Model.EnumWorkType.WorkType.服务程序.ToString()){if(Common.Function.IsExistsService(dgvExeList.Rows[e.RowIndex].Cells["服务名称"].Value.ToString())){MessageBox.Show("已经存在名称为"+dgvExeList.Rows[e.RowIndex].Cells["服务名称"].Value.ToString()+"的服务,不能重复安装","安装失败",MessageBoxButtons.OK,MessageBoxIcon.Error);return;}//显示等待框//this.Cursor=System.Windows.Forms.Cursors.WaitCursor;//调用命令安装windows服务stringstrTmp=string.Empty;if(!dgvExeList.Rows[e.RowIndex].Cells["路径"].Value.ToString().EndsWith("\\")&&!dgvExeList.Rows[e.RowIndex].Cells["名称"].Value.ToString().EndsWith("\\")){strTmp=dgvExeList.Rows[e.RowIndex].Cells["路径"].Value.ToString()+"\\"+dgvExeList.Rows[e.RowIndex].Cells["名称"].Value.ToString();}else{strTmp=dgvExeList.Rows[e.RowIndex].Cells["路径"].Value.ToString()+dgvExeList.Rows[e.RowIndex].Cells["名称"].Value.ToString();}//替换为sccreate命令创建,因为此命令可以自定义服务名称屈云明20170721//stringstr=@"%windir%\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe"+strTmp;stringstr=@"sccreate"+dgvExeList.Rows[e.RowIndex].Cells["服务名称"].Value.ToString()+"binpath="+strTmp;System.Diagnostics.Processp=newSystem.Diagnostics.Process();p.StartInfo.FileName="cmd.exe";p.StartInfo.UseShellExecute=false;//是否使用操作系统shell启动p.StartInfo.RedirectStandardInput=true;//接受来自调用程序的输入信息p.StartInfo.RedirectStandardOutput=true;//由调用程序获取输出信息p.StartInfo.RedirectStandardError=true;//重定向标准错误输出p.StartInfo.CreateNoWindow=true;//不显示程序窗口p.Start();//启动程序//向cmd窗口发送输

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论