/// <summary> /// Switch from a view to another view when user chose another screen in the footer menu bar. /// </summary> /// <param name="newView"></param> /// <param name="clickedButton"></param> private void SwitchView(BaseUserControl newView, Button clickedButton) { if (panelMainContent.Controls.Count > 0) { // Remove the current view. BaseUserControl oldView = panelMainContent.Controls[0] as BaseUserControl; panelMainContent.Controls.Remove(oldView); oldView.Dispose(); } // Add the view to the main panel. panelMainContent.Controls.Add(newView); // Setting the view with dock style. newView.Dock = DockStyle.Fill; SetColor(clickedButton); }
public async Task doLogic(ToolStripMenuItem sender, string texto, bool removeLastChar = false) { operationPanel.Visible = true; panelHeader.Visible = true; panelBienvenido.Visible = false; if (uC != null) { uC.Dispose(); } if (menuItemName == sender.Name) { return; } menuItemName = removeLastChar ? sender.Name.Remove(sender.Name.Length - 1, 1) : sender.Name; if (!loadingCircle1.Visible && menuItemName != "Reporte") { loadingCircle1.Visible = true; loadingCircle1.Active = true; } uC = (BaseUserControl)Activator.CreateInstance(Type.GetType(string.Format("{0}.{1}", "WilmerRentCar.UserControls", menuItemName))); uC.AutoScroll = true; operationPanel.Height = uC.Height + 50; uC.Left = (operationPanel.Width - uC.Width) / 2; uC.Top = 20; operationPanel.Controls.Clear(); operationPanel.Controls.Add(uC); uC.Show(); labelGeneral.Text = texto; if (menuItemName != "Reporte") { btnAdd.Visible = true; if (isFirstClick == true) { btnAdd.Click += (object sender2, EventArgs e2) => uC.Add((bo, t) => OnError(bo, t), () => OnSuccess(), ex => ExcepcionHandler(ex)); btnUpdate.Click += (object sender2, EventArgs e2) => uC.Update((bo, t) => OnError(bo, t), () => OnSuccess(), ex => ExcepcionHandler(ex), currentRowId); } isFirstClick = false; MainPanel.Controls.Remove(tableGeneric1); if (menuItemName != "Consulta") { tableGeneric1 = new TableGeneric(btnUpdate, (DataGridViewRow row) => { var type = row.Cells[2].Value.GetType(); currentRowId = int.Parse(type.Name == "Bitmap" ? row.Cells[3].Value.ToString() : row.Cells[2].Value.ToString()); uC.Edit(row); }, (int id) => { loadingCircle1.Visible = true; loadingCircle1.Active = true; uC.Delete(id, async() => await OnSuccess()); }, (int id) => { loadingCircle1.Visible = true; loadingCircle1.Active = true; Manejador <RentaDevolucion, RentaDevolucionDto> _Manejador = new Manejador <RentaDevolucion, RentaDevolucionDto>(); RentaDevolucionDto renta = _Manejador.ObtenerPorFiltro(x => x.Id == id, new[] { "Vehiculo", "Vehiculo.Modelo", "Vehiculo.Marca" }); renta.Estado = false; _Manejador.Actualizar(renta); Manejador <BOL.Vehículo, VehículoDto> _ManejadorVehiculo = new Manejador <BOL.Vehículo, VehículoDto>(); VehículoDto _Vehiculo = _ManejadorVehiculo.ObtenerPorFiltro(x => x.Id == renta.VehiculoId, new[] { "Marca", "Modelo" }); _Vehiculo.Estado = true; _ManejadorVehiculo.Actualizar(_Vehiculo); OnSuccess(); }, menuItemName); } else { tableGeneric1 = new TableGeneric(menuItemName, loadingHandler, MainPanel.Width, false); uC.SuccessFunction += async() => await SuccessFunction(); } tableGeneric1.BackColor = Color.Transparent; //tableGeneric1.Left = (MainPanel.Width - tableGeneric1.Width) / 2; tableGeneric1.Name = "tableGeneric1"; tableGeneric1.AutoSize = true; MainPanel.Controls.Add(tableGeneric1); if (menuItemName != "Consulta") { await tableGeneric1.FillData(menuItemName, loadingHandler, MainPanel.Width); } tableGeneric1.Top = operationPanel.Height + 105; } else { btnAdd.Visible = false; } }
/// <summary> /// 生成和显示弹窗方法 /// </summary> protected override void Invoke(object parameter) { if (Content == null) { throw new NotFiniteNumberException("Content is null"); } if (Title == null) { throw new NotFiniteNumberException("Title is null"); } object[] args = null; if (Args != null) { args = Args.ToArray(); } // 调取有参构造失败后调取无参构造,待修改 IContentWindow win = null; BaseUserControl content = null; ContentWindow contentWindow = null; //当前打开的窗体 try { content = Content.Assembly.CreateInstance(Content.FullName, true, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public, null, args, null, null) as BaseUserControl; } catch (Exception) { content = Content.Assembly.CreateInstance(Content.FullName) as BaseUserControl; } // 根据弹窗类型反向生成对应的的窗口类 switch (WindowType) { case ContentWindowType.ToolBox: contentWindow = HasOpenedWindow(Title); if (contentWindow != null) { // 若已打开,则使当前窗口弹出至最上层 contentWindow.Topmost = true; return; } else { win = ToolBoxContentWindow.Create(content, Title) .SetContentMargin(ContentMargin) .SetHeight(Height) .SetWidth(Width) .SetTileBackground(TileBackground) .SetIcon(Icon); } break; case ContentWindowType.Document: contentWindow = HasOpenedWindow(Title); if (contentWindow != null) { // 若已打开,则使当前窗口弹出至最上层 contentWindow.Topmost = true; return; } else { win = ConfirmContentWindow.Create(content, Title) .SetContentMargin(ContentMargin) .SetHeight(Height) .SetTileBackground(TileBackground) .SetWidth(Width); } break; default: contentWindow = HasOpenedWindow(Title); if (contentWindow != null) { // 若已打开,则使当前窗口弹出至最上层 contentWindow.Topmost = true; return; } else { if (Title == "麻醉评分") { win = ContentWindow.Create(content, Title, false) .SetContentMargin(ContentMargin) .SetResizeMode(ResizeMode) .SetMinHeight(MinHeight) .SetMinWidth(MinWidth) .SetHeight(Height) .SetWidth(Width) .SetBorderMargin(BorderMargin) .SetTileBackground(TileBackground) .SetIcon(content.Icon); } else { win = ContentWindow.Create(content, Title) .SetContentMargin(ContentMargin) .SetResizeMode(ResizeMode) .SetMinHeight(MinHeight) .SetMinWidth(MinWidth) .SetHeight(Height) .SetWidth(Width) .SetBorderMargin(BorderMargin) .SetTileBackground(TileBackground) .SetIcon(content.Icon); } } break; } //设置内容控制窗体大小 if (!(Height > 0 & Width > 0)) { (win as Window).SizeToContent = SizeToContent.WidthAndHeight; } //边界控制 if (PositionX > 0 || PositionY > 0) { win.SetStartupLocation(WindowStartupLocation.Manual); //防止窗体显示不全 //获取屏幕的边界 double maxWidth = SystemParameters.PrimaryScreenWidth; //得到屏幕整体宽度 double maxHeight = SystemParameters.PrimaryScreenHeight; //得到屏幕整体高度 if (PositionX + Width > maxWidth) { PositionX = maxWidth - Width - 20; } if (PositionY + Height > maxHeight & PositionY - Height > 0) { PositionY = PositionY - Height; } else { if (ContentName.Equals("OperationInterfaceControl")) { } else { PositionY = maxHeight - Height - 5; } } win.SetX(PositionX); win.SetY(PositionY); } else { win.SetStartupLocation(WindowStartupLocation.CenterScreen); } content.CallBack = obj => { if (CallBackCommand != null) { CallBackCommand.Execute(obj); } }; content.Close = () => (win as Window).Close(); content.ParentWindow = (win as Window); var vm = content.DataContext as BaseViewModel; if (vm != null) { vm.Args = args; vm.CloseContentWindowDelegate = () => (win as Window).Close(); } (win as Window).Loaded += ShowContentWindowAction_Loaded; (win as Window).Closed += (s1, e1) => { content.Dispose(); object result = null; if (vm != null) { if (vm.Result != null) { result = vm.Result; } } else { result = content.Result; } // 出发回调函数 if (CallBackCommand != null) { CallBackCommand.Execute(result); } // 设置返回值 if (ContentMessage != null) { ContentMessage.Result = result; } //content.DataContext = null; //content = null; //(win as Window).Content = null; //win = null; }; if (win is ContentWindow) { ContentWindow contentWin = win as ContentWindow; contentWin.ClosingAction = (s1, e1) => { if (e1.Cancel) { return; } if (!contentWin.IsAnimationCloseWindow) { double durationTime = 0.2; switch (WindowAnimation) { case ContentWindowAnimation.FadeIn: e1.Cancel = true; DoubleAnimation daShow = new DoubleAnimation(); daShow.From = 1; daShow.To = 0.4; daShow.Duration = TimeSpan.FromSeconds(durationTime); contentWin.IsAnimationCloseWindow = true; daShow.Completed += (sender, e) => { (s1 as Window).Close(); }; (s1 as Window).BeginAnimation(Window.OpacityProperty, daShow); break; case ContentWindowAnimation.VerticalFloating: TranslateTransform tt = new TranslateTransform(); DoubleAnimation da = new DoubleAnimation(); Duration duration = new Duration(TimeSpan.FromSeconds(durationTime)); (s1 as Window).RenderTransform = tt; tt.Y = 0; da.To = (s1 as Window).ActualHeight; da.Duration = duration; contentWin.IsAnimationCloseWindow = true; da.Completed += (sender, e) => { (s1 as Window).Close(); }; tt.BeginAnimation(TranslateTransform.YProperty, da); e1.Cancel = true; break; case ContentWindowAnimation.HorizontalFloating: TranslateTransform ttHorizontal = new TranslateTransform(); DoubleAnimation daHorizontal = new DoubleAnimation(); Duration durationHorizontal = new Duration(TimeSpan.FromSeconds(durationTime)); (s1 as Window).RenderTransform = ttHorizontal; daHorizontal.From = 0; daHorizontal.To = -(s1 as Window).ActualWidth; daHorizontal.Duration = durationHorizontal; contentWin.IsAnimationCloseWindow = true; daHorizontal.Completed += (sender, e) => { (s1 as Window).Close(); }; ttHorizontal.BeginAnimation(TranslateTransform.XProperty, daHorizontal); e1.Cancel = true; break; } } else { e1.Cancel = false; } }; } if (this.Owner != null) { win.SetOwner(Owner); } if (IsModal) { win.ShowDialog(); } else { win.Show(); } }