using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using IntelligentControlForsx.ChildForms; using IntelligentControlForsx.MyControls; using IntelligentControlForsx.Template; namespace IntelligentControlForsx.Service { public class NavService { private TemplateForm currentForm; //原标题 //public static Title title = null; //仅风机控制页标题 public static Title title = null; public static Bottom projectBottom = null; public static Bottom2 projectBottom2 = null; public Dictionary dictForm; private static MainWindow projectMDIParentForm = null; private NavService() { dictForm = new Dictionary(); dictForm.Add("pictureBoxStatistics", null); dictForm.Add("pictureBoxMainParam", null); dictForm.Add("pictureBoxHome", null); dictForm.Add("pictureBoxMatrix", null); dictForm.Add("pictureBoxControl", null); dictForm.Add("pictureBoxParamters", null); dictForm.Add("pictureBoxElectrical", null); dictForm.Add("pictureBoxFault", null); dictForm.Add("pictureBoxAGC", null); dictForm.Add("pictureBoxSYZ", null); dictForm.Add("ZMForm", null); dictForm.Add("MapForm", null); } public static NavService Instance { get { return SingletonCreator.instance; } } class SingletonCreator { internal static readonly NavService instance = new NavService(); } public List GetAllForm() { return new List(); } public void Nav(String formName, MainWindow mdiParentForm) { if (String.IsNullOrWhiteSpace(formName)) return; if (projectMDIParentForm == null) projectMDIParentForm = mdiParentForm; if (dictForm.ContainsKey(formName)) { TemplateForm form = dictForm[formName]; if (form == null) { form = CreateForm(formName, mdiParentForm); dictForm[formName] = form; } Nav(form, mdiParentForm); } } private string stationId = "SBQ_FDC"; public string StationId { get { return stationId; } set { stationId = value; } } public void StationSelectedChanged(String stationId) { this.stationId = stationId; if (currentForm != null) currentForm.SelectedStationChanged(stationId); } private TemplateForm CreateForm(String formName, MainWindow mdiParentForm) { if (projectMDIParentForm == null) projectMDIParentForm = mdiParentForm; TemplateForm form = null; switch (formName) { case "pictureBoxHome": form = new HomeForm(); form.MdiParent = mdiParentForm; form.Parent = mdiParentForm.panel1; form.Dock = DockStyle.Fill; break; case "pictureBoxMatrix": form = new MatrixForm(); form.MdiParent = mdiParentForm; form.Parent = mdiParentForm.panel1; form.Dock = DockStyle.Fill; break; case "pictureBoxStatistics": form = new StatForm(); form.MdiParent = mdiParentForm; form.Parent = mdiParentForm.panel1; form.Dock = DockStyle.Fill; break; case "pictureBoxMainParam": form = new ParamsForm(); form.MdiParent = mdiParentForm; form.Parent = mdiParentForm.panel1; form.Dock = DockStyle.Fill; break; case "pictureBoxParamters": form = new WindturbineForm(); form.MdiParent = mdiParentForm; form.Parent = mdiParentForm.panel1; form.Dock = DockStyle.Fill; break; //case "pictureBoxControl": // //form = new ControlForm2(); // //form.MdiParent = mdiParentForm; // //form.Parent = mdiParentForm.panel1; // //form.Dock = DockStyle.Fill; // form = new CleverControlForm(); // form.MdiParent = mdiParentForm; // form.Parent = mdiParentForm.panel1; // form.Dock = DockStyle.Fill; // break; case "pictureBoxSYZ": form = new ElectricalForm(); form.MdiParent = mdiParentForm; form.Parent = mdiParentForm.panel1; form.Dock = DockStyle.Fill; break; case "pictureBoxFault": form = new AlarmForm(); form.MdiParent = mdiParentForm; form.Parent = mdiParentForm.panel1; form.Dock = DockStyle.Fill; break; case "pictureBoxAGC": form = new AGCForm(); form.MdiParent = mdiParentForm; form.Parent = mdiParentForm.panel1; form.Dock = DockStyle.Fill; break; case "ZMForm": { form = new ZMForm(); form.MdiParent = mdiParentForm; form.Parent = mdiParentForm.panel1; form.Dock = DockStyle.Fill; //form = new ZMForm(); //form.MdiParent = mdiParentForm; //form.Parent = mdiParentForm.panel1; //form.Dock = DockStyle.Fill; } break; case "MapForm": { form = new MapForm(); //form = new MapForm(); form.MdiParent = mdiParentForm; form.Parent = mdiParentForm.panel1; form.Dock = DockStyle.Fill; } break; default: break; } return form; } private void Nav(TemplateForm form, MainWindow mdiParent) { if (currentForm != null) currentForm.DeActive(); form.Active(); currentForm = form; } //提供从风场总貌图 风机跳转到风机参数页面 public void NavForWindturbine(String formName, string windturbineId, string stationId) { this.stationId = stationId; if (projectBottom != null) projectBottom.StationChange(stationId); if (String.IsNullOrWhiteSpace(formName)) return; if (dictForm.ContainsKey(formName)) { TemplateForm form = dictForm[formName]; if (form == null) { if (projectMDIParentForm != null) { form = CreateForm(formName, projectMDIParentForm); dictForm[formName] = form; } } WindturbineForm fm = (WindturbineForm)form; fm.SetNowWindturbineId(windturbineId, stationId); Nav(form, projectMDIParentForm); if (title != null) { title.StyleImgChange("pictureBoxParamters"); } } } public void NavForMap(string formName, string stationId) { if (String.IsNullOrWhiteSpace(formName)) return; if (dictForm.ContainsKey(formName)) { TemplateForm form = dictForm[formName]; if (form == null) { if (projectMDIParentForm != null) { form = CreateForm(formName, projectMDIParentForm); dictForm[formName] = form; } } NavService.Instance.StationId = stationId; MapForm fm = form as MapForm; Nav(form, projectMDIParentForm); } } public void NavForElectrical(string formName, string StationId) { if (title != null) title.StyleImgChange("pictureBoxSYZ"); if (String.IsNullOrWhiteSpace(formName)) return; if (dictForm.ContainsKey(formName)) { TemplateForm form = dictForm[formName]; if (form == null) { if (projectMDIParentForm != null) { form = CreateForm(formName, projectMDIParentForm); dictForm[formName] = form; } } try { ElectricalForm eForm = (ElectricalForm)form; eForm.StationId = stationId; } catch (Exception ex) { throw; } finally { Nav(form, projectMDIParentForm); } } } } }