public static bool HasErrors(this ErrorProvider ep, Form frm) { try { Clear(ep); frm.ValidateChildren(); return _count != 0; } catch { return false; } }
public void TestPublicMethods () { // Public Methods that force Handle creation: // - CreateGraphics () // - GetChildAtPoint () // - Invoke, BeginInvoke throws InvalidOperationException if Handle has not been created // - PointToClient () // - PointToScreen () // - RectangleToClient () // - RectangleToScreen () // - Select () // - Show (IWin32Window) // Notes: // - CreateControl does NOT force Handle creation! Form c = new Form (); c.BringToFront (); Assert.IsFalse (c.IsHandleCreated, "A1"); c.Contains (new Form ()); Assert.IsFalse (c.IsHandleCreated, "A2"); c.CreateControl (); Assert.IsFalse (c.IsHandleCreated, "A3"); c = new Form (); Graphics g = c.CreateGraphics (); g.Dispose (); Assert.IsTrue (c.IsHandleCreated, "A4"); c.Dispose (); c = new Form (); c.Dispose (); Assert.IsFalse (c.IsHandleCreated, "A5"); c = new Form (); // This is weird, it causes a form to appear that won't go away until you move the mouse over it, // but it doesn't create a handle?? //DragDropEffects d = c.DoDragDrop ("yo", DragDropEffects.None); //Assert.IsFalse (c.IsHandleCreated, "A6"); //Assert.AreEqual (DragDropEffects.None, d, "A6b"); //Bitmap b = new Bitmap (100, 100); //c.DrawToBitmap (b, new Rectangle (0, 0, 100, 100)); //Assert.IsFalse (c.IsHandleCreated, "A7"); //b.Dispose (); c.FindForm (); Assert.IsFalse (c.IsHandleCreated, "A8"); c.Focus (); Assert.IsFalse (c.IsHandleCreated, "A9"); c.GetChildAtPoint (new Point (10, 10)); Assert.IsTrue (c.IsHandleCreated, "A10"); c.Dispose (); c = new Form (); c.GetContainerControl (); Assert.IsFalse (c.IsHandleCreated, "A11"); c.Dispose (); c = new Form (); c.GetNextControl (new Control (), true); Assert.IsFalse (c.IsHandleCreated, "A12"); c.GetPreferredSize (Size.Empty); Assert.IsFalse (c.IsHandleCreated, "A13"); c.Hide (); Assert.IsFalse (c.IsHandleCreated, "A14"); c.Invalidate (); Assert.IsFalse (c.IsHandleCreated, "A15"); //c.Invoke (new InvokeDelegate (InvokeMethod)); //Assert.IsFalse (c.IsHandleCreated, "A16"); c.PerformLayout (); Assert.IsFalse (c.IsHandleCreated, "A17"); c.PointToClient (new Point (100, 100)); Assert.IsTrue (c.IsHandleCreated, "A18"); c.Dispose (); c = new Form (); c.PointToScreen (new Point (100, 100)); Assert.IsTrue (c.IsHandleCreated, "A19"); c.Dispose (); c = new Form (); //c.PreProcessControlMessage ??? //c.PreProcessMessage ??? c.RectangleToClient (new Rectangle (0, 0, 100, 100)); Assert.IsTrue (c.IsHandleCreated, "A20"); c.Dispose (); c = new Form (); c.RectangleToScreen (new Rectangle (0, 0, 100, 100)); Assert.IsTrue (c.IsHandleCreated, "A21"); c.Dispose (); c = new Form (); c.Refresh (); Assert.IsFalse (c.IsHandleCreated, "A22"); c.ResetBackColor (); Assert.IsFalse (c.IsHandleCreated, "A23"); c.ResetBindings (); Assert.IsFalse (c.IsHandleCreated, "A24"); c.ResetCursor (); Assert.IsFalse (c.IsHandleCreated, "A25"); c.ResetFont (); Assert.IsFalse (c.IsHandleCreated, "A26"); c.ResetForeColor (); Assert.IsFalse (c.IsHandleCreated, "A27"); c.ResetImeMode (); Assert.IsFalse (c.IsHandleCreated, "A28"); c.ResetRightToLeft (); Assert.IsFalse (c.IsHandleCreated, "A29"); c.ResetText (); Assert.IsFalse (c.IsHandleCreated, "A30"); c.SuspendLayout (); Assert.IsFalse (c.IsHandleCreated, "A31"); c.ResumeLayout (); Assert.IsFalse (c.IsHandleCreated, "A32"); c.Scale (new SizeF (1.5f, 1.5f)); Assert.IsFalse (c.IsHandleCreated, "A33"); c.Select (); Assert.IsTrue (c.IsHandleCreated, "A34"); c.Dispose (); c = new Form (); c.SelectNextControl (new Control (), true, true, true, true); Assert.IsFalse (c.IsHandleCreated, "A35"); c.SetBounds (0, 0, 100, 100); Assert.IsFalse (c.IsHandleCreated, "A36"); c.Update (); Assert.IsFalse (c.IsHandleCreated, "A37"); // Form c.Activate (); Assert.IsFalse (c.IsHandleCreated, "F1"); c.AddOwnedForm (new Form ()); Assert.IsFalse (c.IsHandleCreated, "F2"); c.Close (); Assert.IsFalse (c.IsHandleCreated, "F3"); c.Hide (); Assert.IsFalse (c.IsHandleCreated, "F4"); c.LayoutMdi (MdiLayout.Cascade); Assert.IsFalse (c.IsHandleCreated, "F5"); #if !MONO c.PerformAutoScale (); Assert.IsFalse (c.IsHandleCreated, "F6"); #endif c.PerformLayout (); Assert.IsFalse (c.IsHandleCreated, "F7"); c.AddOwnedForm (new Form ()); c.RemoveOwnedForm (c.OwnedForms [c.OwnedForms.Length - 1]); Assert.IsFalse (c.IsHandleCreated, "F8"); c.ScrollControlIntoView (null); Assert.IsFalse (c.IsHandleCreated, "F9"); c.SetAutoScrollMargin (7, 13); Assert.IsFalse (c.IsHandleCreated, "F10"); c.SetDesktopBounds (-1, -1, 144, 169); Assert.IsFalse (c.IsHandleCreated, "F11"); c.SetDesktopLocation (7, 13); Assert.IsFalse (c.IsHandleCreated, "F12"); c = new Form (); c.Show (null); Assert.IsTrue (c.IsHandleCreated, "F13"); c.Close (); c = new Form (); //c.ShowDialog () c.ToString (); Assert.IsFalse (c.IsHandleCreated, "F14"); c.Validate (); Assert.IsFalse (c.IsHandleCreated, "F15"); #if !MONO c.ValidateChildren (); Assert.IsFalse (c.IsHandleCreated, "F16"); #endif c.Close (); }
private static bool InternalExecuteWindowMenu2(IControlManager cm, WindowMenuInfo info, Form parentForm) { object entity = cm.DisplayManager.CurrentItem; int pos = cm.DisplayManager.Position; //ArchiveOperationForm opForm = masterForm as ArchiveOperationForm; switch (info.Type) { case WindowMenuType.Add: { ArchiveOperationForm.DoAddS(cm); } break; case WindowMenuType.Edit: { ArchiveOperationForm.DoEditS(cm, (parentForm as IGridNamesContainer).GridNames[0]); } break; case WindowMenuType.Delete: { ArchiveOperationForm.DoDeleteS(cm, (parentForm as IGridNamesContainer).GridNames[0]); } break; case WindowMenuType.Confirm: { parentForm.ValidateChildren(); ArchiveDetailForm.DoSaveS(cm); } break; case WindowMenuType.Cancel: { ArchiveDetailForm.DoCancelS(cm); } break; case WindowMenuType.Submit: { if (entity == null) { MessageForm.ShowError("请选择要提交的项!"); return true; } if (!MessageForm.ShowYesNo("是否确认提交?")) return true; ISubmittedEntity se = entity as ISubmittedEntity; if (se == null) { throw new ArgumentException("Submit Entity should be ISubmittedEntity!"); } if (string.IsNullOrEmpty(info.ExecuteParam)) { cm.EditCurrent(); se.Submitted = true; cm.EndEdit(); } else { ISubmittedEntityDao dao = Feng.Utils.ReflectionHelper.CreateInstanceFromName(info.ExecuteParam) as ISubmittedEntityDao; if (dao == null) { throw new ArgumentException("Submit windowMenuType's ExecuteParam should be ISubmittedEntityDao!"); } using (IRepository rep = dao.GenerateRepository()) { try { se.Submitted = true; rep.BeginTransaction(); dao.Submit(rep, entity); rep.CommitTransaction(); cm.OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, pos)); } catch (Exception ex) { se.Submitted = false; rep.RollbackTransaction(); ExceptionProcess.ProcessWithNotify(ex); } } } } break; case WindowMenuType.Unsubmit: { if (entity == null) { MessageForm.ShowError("请选择要撤销提交的项!"); return true; } if (!MessageForm.ShowYesNo("是否确认撤销提交?", "确认", true)) return true; ISubmittedEntity se = entity as ISubmittedEntity; if (se == null) { throw new ArgumentException("Submit Entity should be ISubmittedEntity!"); } if (string.IsNullOrEmpty(info.ExecuteParam)) { cm.EditCurrent(); se.Submitted = false; cm.EndEdit(); } else { ISubmittedEntityDao dao = Feng.Utils.ReflectionHelper.CreateInstanceFromName(info.ExecuteParam) as ISubmittedEntityDao; if (dao == null) { throw new ArgumentException("Submit windowMenuType's ExecuteParam should be ISubmittedEntityDao!"); } using (IRepository rep = dao.GenerateRepository()) { try { se.Submitted = false; rep.BeginTransaction(); dao.Unsubmit(rep, entity); rep.CommitTransaction(); cm.OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, pos)); } catch (Exception ex) { se.Submitted = true; rep.RollbackTransaction(); ExceptionProcess.ProcessWithNotify(ex); } } } } break; case WindowMenuType.SubmitMulti: { if (cm.DisplayManager.Count == 0) { MessageForm.ShowError("请选择要提交的项!"); return true; } if (!MessageForm.ShowYesNo("是否确认提交(当前全部)?")) return true; ISubmittedEntity se = entity as ISubmittedEntity; if (se == null) { throw new ArgumentException("Submit Entity should be ISubmittedEntity!"); } if (string.IsNullOrEmpty(info.ExecuteParam)) { IBatchDao batchDao = cm.Dao as IBatchDao; if (batchDao != null) { batchDao.SuspendOperation(); } for (int i = 0; i < cm.DisplayManager.Count; ++i) { cm.DisplayManager.Position = i; cm.EditCurrent(); (cm.DisplayManager.Items[i] as ISubmittedEntity).Submitted = true; cm.EndEdit(); } if (batchDao != null) { batchDao.ResumeOperation(); } } else { ISubmittedEntityDao dao = Feng.Utils.ReflectionHelper.CreateInstanceFromName(info.ExecuteParam) as ISubmittedEntityDao; if (dao == null) { throw new ArgumentException("Submit windowMenuType's ExecuteParam should be ISubmittedEntityDao!"); } using (IRepository rep = dao.GenerateRepository()) { try { rep.BeginTransaction(); for (int i = 0; i < cm.DisplayManager.Count; ++i) { (cm.DisplayManager.Items[i] as ISubmittedEntity).Submitted = true; dao.Submit(rep, cm.DisplayManager.Items[i]); } rep.CommitTransaction(); cm.OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, pos)); } catch (Exception ex) { se.Submitted = false; rep.RollbackTransaction(); ExceptionProcess.ProcessWithNotify(ex); } } } } break; case WindowMenuType.Cancellate: { if (entity == null) { MessageForm.ShowError("请选择要作废的项!"); return true; } if (!MessageForm.ShowYesNo("是否确认作废?", "确认", true)) return true; ICancellateDao dao = Feng.Utils.ReflectionHelper.CreateInstanceFromName(info.ExecuteParam) as ICancellateDao; if (dao == null) { throw new ArgumentException("Submit windowMenuType's ExecuteParam should be ICancellateDao!"); } using (IRepository rep = dao.GenerateRepository()) { try { rep.BeginTransaction(); dao.Cancellate(rep, entity); rep.CommitTransaction(); cm.OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, pos)); } catch (Exception ex) { rep.RollbackTransaction(); ExceptionProcess.ProcessWithNotify(ex); } } } break; case WindowMenuType.DaoProcess: { if (entity == null) { MessageForm.ShowError("请选择要操作的项!"); return true; } if (!MessageForm.ShowYesNo("是否要执行" + info.Text + "?")) return true; string[] ss = info.ExecuteParam.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); if (ss.Length != 2) { throw new ArgumentException("DaoProcess windowMenuType's ExecuteParam should be IDao;MethodName!"); } IRepositoryDao dao = Feng.Utils.ReflectionHelper.CreateInstanceFromName(ss[0].Trim()) as IRepositoryDao; if (dao == null) { throw new ArgumentException("DaoProcess windowMenuType's ExecuteParam's first part should be IDao!"); } using (IRepository rep = dao.GenerateRepository()) { try { rep.BeginTransaction(); Feng.Utils.ReflectionHelper.RunInstanceMethod(ss[0].Trim(), ss[1].Trim(), dao, new object[] { rep, entity }); rep.CommitTransaction(); cm.OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, pos)); } catch (Exception ex) { rep.RollbackTransaction(); ExceptionProcess.ProcessWithNotify(ex); } } } break; case WindowMenuType.Select: { string[] ss = info.ExecuteParam.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); if (ss.Length == 0) { throw new ArgumentException("WindowMenu's ExecuteParam is Invalid of WindowMenu " + info.Name); } ArchiveCheckForm form = ServiceProvider.GetService<IWindowFactory>().CreateWindow(ADInfoBll.Instance.GetWindowInfo(ss[0])) as ArchiveCheckForm; if (ss.Length > 1) { string exp = ss[1]; exp = EntityHelper.ReplaceEntity(exp, new EntityHelper.GetReplaceValue(delegate(string paramName) { Tuple<string, object> t = EventProcessUtils.GetDataControlValue(paramName, cm.DisplayManager); if (t.Item2 == null) { throw new InvalidUserOperationException(string.Format("请先填写{0}!", paramName)); } cm.DisplayManager.DataControls[t.Item1].ReadOnly = true; // save controlValue to entity because readonly will not save EntityScript.SetPropertyValue(cm.DisplayManager.CurrentItem, t.Item1, t.Item2); return t.Item2; })); if (string.IsNullOrEmpty(form.DisplayManager.SearchManager.AdditionalSearchExpression)) { form.DisplayManager.SearchManager.AdditionalSearchExpression = exp; } else { form.DisplayManager.SearchManager.AdditionalSearchExpression = "(" + form.DisplayManager.SearchManager.AdditionalSearchExpression + ") and " + exp; } } int detailGridIdx = 0; if (ss.Length > 2) { detailGridIdx = Feng.Utils.ConvertHelper.ToInt(ss[2]).Value; } if (form.ShowDialog(parentForm) == System.Windows.Forms.DialogResult.OK) { IControlManager detailCm = (((IArchiveDetailFormWithDetailGrids)(parentForm as IArchiveMasterForm).ArchiveDetailForm).DetailGrids[detailGridIdx] as IArchiveGrid).ControlManager; var nowList = detailCm.DisplayManager.Items; foreach (object i in form.SelectedEntites) { if (nowList.Contains(i)) continue; detailCm.AddNew(); detailCm.DisplayManager.Items[detailCm.DisplayManager.Position] = i; detailCm.EndEdit(); } } form.Dispose(); } break; case WindowMenuType.Input: throw new NotSupportedException("Not supported now!"); case WindowMenuType.ManyToOneWindow: { if (cm.DisplayManager.CurrentItem == null) { MessageForm.ShowInfo("无当前项,不能操作!"); return true; } string[] ss = info.ExecuteParam.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); if (ss.Length < 2) { throw new ArgumentException("WindowMenu's ExecuteParam is Invalid of WindowMenu " + info.Name); } ArchiveDetailForm selectForm = ServiceProvider.GetService<IWindowFactory>().CreateWindow(ADInfoBll.Instance.GetWindowInfo(ss[0])) as ArchiveDetailForm; string propertyName = ss[1]; object masterEntity = EntityScript.GetPropertyValue(cm.DisplayManager.CurrentItem, propertyName); if (masterEntity == null) { ArchiveOperationForm.DoAddS(selectForm.ControlManager); selectForm.UpdateContent(); if (selectForm.ShowDialog(parentForm) == System.Windows.Forms.DialogResult.OK) { cm.EditCurrent(); EntityScript.SetPropertyValue(cm.DisplayManager.CurrentItem, propertyName, selectForm.DisplayManager.CurrentItem); cm.EndEdit(); cm.OnCurrentItemChanged(); } } else { selectForm.ControlManager.AddNew(); selectForm.DisplayManager.Items[selectForm.DisplayManager.Position] = masterEntity; selectForm.ControlManager.EndEdit(false); ArchiveOperationForm.DoEditS(selectForm.ControlManager, selectForm.GridName); selectForm.UpdateContent(); if (selectForm.ShowDialog(parentForm) == System.Windows.Forms.DialogResult.OK) { ((parentForm as IArchiveMasterForm).MasterGrid as IBoundGrid).ReloadData(); } } selectForm.Dispose(); } break; default: return false; } return true; }