本文整理汇总了C#中RuleSet.ValidateTarget方法的典型用法代码示例。如果您正苦于以下问题:C# RuleSet.ValidateTarget方法的具体用法?C# RuleSet.ValidateTarget怎么用?C# RuleSet.ValidateTarget使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RuleSet
的用法示例。
在下文中一共展示了RuleSet.ValidateTarget方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LastName_IsRequired
public void LastName_IsRequired()
{
IPerson person = ObjectSpace.CreateObject<IPerson>();
RuleSet ruleSet = new RuleSet();
RuleSetValidationResult result = ruleSet.ValidateTarget(person, DefaultContexts.Save);
Assert.AreEqual(ValidationState.Invalid, result.GetResultItem(PersonValidationRules.LastNameIsRequired).State);
person.LastName = "Test";
result = ruleSet.ValidateTarget(person, DefaultContexts.Save);
Assert.AreEqual(ValidationState.Valid, result.GetResultItem(PersonValidationRules.LastNameIsRequired).State);
}
示例2: Test
public void Test()
{
var ruleSet = new RuleSet();
Session.DefaultSession.GetClassInfo(typeof(User)).CreateMember("Test",typeof(string)).AddAttribute(new RuleRequiredFieldAttribute(null, DefaultContexts.Save));
var target = ruleSet.ValidateTarget(new User(Session.DefaultSession), ContextIdentifier.Save);
RuleSetValidationResultItem ruleRequiredField = target.Results.Where(item => item.Rule is RuleRequiredField&&item.Rule.UsedProperties.Contains("FirstName")).Single();
Assert.AreEqual(ValidationState.Invalid, ruleRequiredField.State);
}
示例3: Many_Disabled_Objects_With_Same_ApplicationName_DifferenceType_Can_Exist
public void Many_Disabled_Objects_With_Same_ApplicationName_DifferenceType_Can_Exist(DifferenceType differenceType, ValidationState validationState)
{
var ruleSet = new RuleSet();
var persistentApplication = new PersistentApplication(Session.DefaultSession);
new ModelDifferenceObject(Session.DefaultSession) { Disabled = true, PersistentApplication = persistentApplication }.Save();
var modelDifferenceObject = new ModelDifferenceObject(Session.DefaultSession) { Disabled = true, PersistentApplication = persistentApplication };
Isolate.WhenCalled(() => modelDifferenceObject.DifferenceType).WillReturn(differenceType);
RuleSetValidationResult target = ruleSet.ValidateTarget(modelDifferenceObject, ContextIdentifier.Save);
var resultItem = target.Results.Where(item => item.Rule is RuleCombinationOfPropertiesIsUnique).Single();
Assert.AreEqual(validationState, resultItem.State);
}
示例4: DateCreated_Can_Not_Be_Null
public void DateCreated_Can_Not_Be_Null(DifferenceType differenceType, ValidationState validationState)
{
var o = new ModelDifferenceObject(Session.DefaultSession);
Isolate.WhenCalled(() => o.DifferenceType).WillReturn(differenceType);
var ruleSet = new RuleSet();
RuleSetValidationResult target = ruleSet.ValidateTarget(o, ContextIdentifier.Save);
RuleSetValidationResultItem @default = target.Results.Where(
item =>
item.Rule is RuleRequiredField &&
((RuleRequiredField)item.Rule).TargetMember.Name == o.GetPropertyInfo(x => x.DateCreated).Name).FirstOrDefault();
Assert.AreEqual(validationState, @default.State);
}
示例5: Same_Application_Objets_Cannot_Exist
public void Same_Application_Objets_Cannot_Exist(DifferenceType differenceType, ValidationState validationState)
{
var ruleSet = new RuleSet();
var persistentApplication = new PersistentApplication(Session.DefaultSession);
var modelDifferenceObject = new ModelDifferenceObject(Session.DefaultSession) { PersistentApplication = persistentApplication };
modelDifferenceObject.Save();
var modelDifferenceObject1 = new ModelDifferenceObject(Session.DefaultSession) { PersistentApplication = persistentApplication };
Isolate.WhenCalled(() => modelDifferenceObject1.DifferenceType).WillReturn(differenceType);
RuleSetValidationResult target = ruleSet.ValidateTarget(modelDifferenceObject1, ContextIdentifier.Save);
Assert.IsInstanceOfType(typeof(RuleCombinationOfPropertiesIsUnique), target.Results[0].Rule);
Assert.AreEqual(validationState, target.Results[0].State);
}
示例6: selectAcception_AcceptingAdmin
void selectAcception_AcceptingAdmin(object sender, DialogControllerAcceptingEventArgs e)
{
ObjectSpace objectSpace = Application.CreateObjectSpace();
DevExpress.ExpressApp.ListView lv = ((DevExpress.ExpressApp.ListView)((WindowController)sender).Window.View);
User u = (User)SecuritySystem.CurrentUser;
XPCollection<Role> xpc = new XPCollection<Role>(u.Roles,
new BinaryOperator("Name", "Administrators"));
XPCollection<Role> xpc2 = new XPCollection<Role>(u.Roles,
new BinaryOperator("Name", "DataAdmins"));
if (xpc.Count + xpc2.Count > 0)
{
objectSpace.Session.BeginTransaction();
Student currentStudent;
Lesson curLesson;
foreach (string studentCode in listStudentCode)
{
currentStudent = objectSpace.FindObject<Student>(
new BinaryOperator("StudentCode", studentCode));
foreach (Lesson lesson in lv.SelectedObjects)
{
curLesson = objectSpace.FindObject<Lesson>(
new BinaryOperator("Oid", lesson.Oid));
RegisterDetail regdetail = new RegisterDetail(objectSpace.Session)
{
Student = currentStudent,
Lesson = curLesson,
RegisterState = objectSpace.FindObject<RegisterState>(
new BinaryOperator("Code", "SELECTED")),
CheckState =objectSpace.FindObject<RegisterState>(
new BinaryOperator("Code", "NOTCHECKED"))
};
RuleSet ruleSet = new RuleSet();
RuleSetValidationResult result = ruleSet.ValidateTarget(regdetail, DefaultContexts.Save);
if (ValidationState.Invalid ==
result.GetResultItem("RegisterDetail.StudentRegLessonSemester").State)
{
regdetail.Delete();
}
else
{
regdetail.Save();
}
}
}
objectSpace.Session.CommitTransaction();
PopUpMessage ms = objectSpace.CreateObject<PopUpMessage>();
ms.Title = "Lỗi đăng ký";
ms.Message = string.Format("Error");
ShowViewParameters svp = new ShowViewParameters();
svp.CreatedView = Application.CreateDetailView(
objectSpace, ms);
svp.TargetWindow = TargetWindow.NewModalWindow;
svp.CreatedView.Caption = "Thông báo";
DialogController dc = Application.CreateController<DialogController>();
svp.Controllers.Add(dc);
dc.SaveOnAccept = false;
Application.ShowViewStrategy.ShowView(svp,new ShowViewSource(null,null));
//// View.ObjectSpace.CommitChanges();
//View.ObjectSpace.Refresh();
//ListView view = null;
//Frame currentFrame = ((ActionBase)sender).Controller.Frame;
//switch (currentFrame.View.ObjectTypeInfo.Name)
//{
// case "Student":
// view = Application.CreateListView(objectSpace,typeof(RegisterDetail),true);
// break;
//}
//currentFrame.SetView(view);
//e.Cancel = true;
}
}
示例7: BookRegister_Execute
//.........这里部分代码省略.........
e.ShowViewParameters.Controllers.Add(dc);
dc.SaveOnAccept = false;
return;
}
//kiem tra rang buoc so tin chi max
cparam = View.ObjectSpace.FindObject<ConstrainstParameter>(
new BinaryOperator("Code", "MAXCREDITS"));
if (cparam != null && numcredits > Convert.ToDouble(cparam.Value))
{
ms = objectSpace.CreateObject<PopUpMessage>();
ms.Title = "Lỗi đăng ký";
ms.Message = string.Format("Không đăng ký nhiều hơn {0} tín chỉ!", cparam.Value);
e.ShowViewParameters.CreatedView = Application.CreateDetailView(
objectSpace, ms);
e.ShowViewParameters.TargetWindow = TargetWindow.NewModalWindow;
e.ShowViewParameters.CreatedView.Caption = "Thông báo";
dc = Application.CreateController<DialogController>();
e.ShowViewParameters.Controllers.Add(dc);
dc.SaveOnAccept = false;
return;
}
numcredits = 0;
sumTuitionFee = 0;
string lessonCodelist = "";
string semestername = "";
foreach (RegisterDetail regDetail in ((ListView)View).SelectedObjects)
{
result = ruleSet.ValidateTarget(regDetail, DefaultContexts.Save);
if (ValidationState.Invalid ==
result.GetResultItem("RegisterDetail.StudentRegLessonSemester").State)
{
throw new UserFriendlyException(string.Format ("Đăng ký trùng môn học! Vui lòng bỏ môn trùng, Mã môn = \"{0}\"", regDetail.Lesson.Subject.SubjectCode));
}
if (regDetail.RegisterState.Code == "SELECTED")
{
numcredits += regDetail.Lesson.Subject.Credit;
sumTuitionFee += regDetail.Lesson.TuitionFee;
View.ObjectSpace.SetModified(regDetail);
View.ObjectSpace.SetModified(regDetail.Lesson);
regDetail.RegisterState = View.ObjectSpace.FindObject<RegisterState>(
new BinaryOperator("Code", "BOOKED"));
regDetail.CheckState = View.ObjectSpace.FindObject<RegisterState>(
new BinaryOperator("Code", "NOTCHECKED"));
regDetail.Lesson.NumRegistration++;
semestername = regDetail.Lesson.Semester.SemesterName;
lessonCodelist += (String.Format("{0}({1})-", regDetail.Lesson.LessonName, regDetail.Lesson.Subject.SubjectCode));
}
}
lessonCodelist = lessonCodelist.TrimEnd('-');
//create Account transaction
if (sumTuitionFee > 0)
{
AccountTransaction act = View.ObjectSpace.CreateObject<AccountTransaction>();
Student stud = View.ObjectSpace.FindObject<Student>(
new BinaryOperator("Oid", SecuritySystem.CurrentUserId));
Semester semester = View.ObjectSpace.FindObject<Semester>(
new BinaryOperator("SemesterName", semestername));
act.Student = stud;
act.MoneyAmount = -sumTuitionFee;
act.TransactingDate = DateTime.Now;
示例8: selectAcception_AcceptingStudent
void selectAcception_AcceptingStudent(object sender, DialogControllerAcceptingEventArgs e)
{
RuleSet ruleSet = new RuleSet();
RuleSetValidationResult result;
if (SecuritySystem.CurrentUser is Student)
{
ObjectSpace objectSpace = Application.CreateObjectSpace();
ListView lv = ((ListView)((WindowController)sender).Window.View);
if (SecuritySystem.CurrentUser is Student)
{
objectSpace.Session.BeginTransaction();
PopUpMessage ms = objectSpace.CreateObject<PopUpMessage>();
ms.Title = "Chọn nhóm MH thành công";
ms.Message = "";
Student student = SecuritySystem.CurrentUser as Student;
Student currentStudent = objectSpace.FindObject<Student>(
new BinaryOperator("StudentCode", student.StudentCode));
Lesson curLesson;
int checkresult, selectsubject=0;
double selectcredits = 0;
string subjectcoderesult, msgresult;
foreach (Lesson lesson in lv.SelectedObjects)
{
if (Utils.IsConfictPrerequisite(objectSpace, student.StudentCode, lesson.Subject.SubjectCode, out checkresult, out subjectcoderesult))
{
switch (checkresult)
{
case 1: msgresult = "học trước"; break;
case 2: msgresult = "tiên quyết"; break;
default: msgresult = "-"; break;
};
Subject subj = objectSpace.FindObject<Subject>(CriteriaOperator.Parse("SubjectCode =?", subjectcoderesult));
ms.Message += string.Format("Không chọn được môn [{0}]{1} do vi phạm môn {2} là [{3}]{4}\r\n",
lesson.Subject.SubjectCode, lesson.Subject.SubjectName, msgresult, subj.SubjectCode, subj.SubjectName);
continue;
}
curLesson = objectSpace.FindObject<Lesson>(
new BinaryOperator("Oid", lesson.Oid));
RegisterDetail regdetail = new RegisterDetail(objectSpace.Session)
{
Student = currentStudent,
Lesson = curLesson,
RegisterState = objectSpace.FindObject<RegisterState>(
new BinaryOperator("Code", "SELECTED")),
CheckState = objectSpace.FindObject<RegisterState>(
new BinaryOperator("Code", "NOTCHECKED"))
};
selectcredits += curLesson.Subject.Credit;
selectsubject++;
result = ruleSet.ValidateTarget(regdetail, DefaultContexts.Save);
if (ValidationState.Invalid ==
result.GetResultItem("RegisterDetail.StudentRegLessonSemester").State)
{
regdetail.Delete();
selectcredits -= curLesson.Subject.Credit;
selectsubject--;
}
}
objectSpace.Session.CommitTransaction();
View.ObjectSpace.Refresh();
ms.Message += string.Format("Tổng số chọn được {0} nhóm lớp môn học với {1} tín chỉ.", selectsubject, selectcredits);
ShowViewParameters svp = new ShowViewParameters();
svp.CreatedView = Application.CreateDetailView(
objectSpace, ms);
svp.TargetWindow = TargetWindow.NewModalWindow;
svp.CreatedView.Caption = "Thông báo";
DialogController dc = Application.CreateController<DialogController>();
svp.Controllers.Add(dc);
dc.AcceptAction.Active.SetItemValue("object", false);
dc.CancelAction.Caption = "Đóng";
dc.SaveOnAccept = false;
Application.ShowViewStrategy.ShowView(svp, new ShowViewSource(null, null));
}
}
}
示例9: DefaultRegister_Execute
private void DefaultRegister_Execute(object sender, SimpleActionExecuteEventArgs e)
{
ObjectSpace objectSpace = Application.CreateObjectSpace();
dicStudentRegDetail = new Dictionary<string, List<string>>();
Student currentStudent;
Lesson curLesson;
Dictionary<string, List<string>> errorstudent = new Dictionary<string, List<string>>();
Dictionary<string, int> dicLessonCurrentRegNum = new Dictionary<string, int>();
int numregok = 0;
Vacancy vc;
bool isConflictTKB = false;
using (XPCollection<Lesson> newCollectionSource = new XPCollection<Lesson>(objectSpace.Session))
{
objectSpace.Session.BeginTransaction();
foreach (StudentClass studentClass in View.SelectedObjects)
{
newCollectionSource.Criteria = CriteriaOperator.Parse(
"ClassIDs like ?", string.Format("%{0}%", studentClass.ClassCode));
foreach (Student student in studentClass.Students)
{
listVacancies = new List<Vacancy>();
currentStudent = objectSpace.FindObject<Student>(
new BinaryOperator("StudentCode", student.StudentCode));
foreach (Lesson lesson in newCollectionSource)
{
isConflictTKB = false;
if (!dicLessonCurrentRegNum.ContainsKey(lesson.LessonName))
{
dicLessonCurrentRegNum[lesson.LessonName] = 0;
}
foreach (TkbSemester tkbsem in lesson.TKBSemesters)
{
vc = new Vacancy(tkbsem.Day, tkbsem.Period, tkbsem.Weeks, (tkbsem.Classroom == null ? "" : tkbsem.Classroom.ClassroomCode));
if (Utils.IsConfictTKB(listVacancies, vc))
{
isConflictTKB = true;
break;
}
}
if (isConflictTKB)
{
if (!errorstudent.ContainsKey(currentStudent.StudentCode))
errorstudent.Add(currentStudent.StudentCode, new List<string>());
if (!errorstudent[currentStudent.StudentCode].Contains(lesson.Subject.SubjectCode))
errorstudent[currentStudent.StudentCode].Add(lesson.Subject.SubjectCode + "{T}");
}
else
{
//si so chon chua vuot qua
if (lesson.NumExpectation > dicLessonCurrentRegNum[lesson.LessonName] + lesson.NumRegistration)
{
curLesson = objectSpace.FindObject<Lesson>(
new BinaryOperator("Oid", lesson.Oid));
RegisterDetail regdetail = new RegisterDetail(objectSpace.Session)
{
Student = currentStudent,
Lesson = curLesson,
RegisterState = objectSpace.FindObject<RegisterState>(
new BinaryOperator("Code", "SELECTED")),
CheckState = objectSpace.FindObject<RegisterState>(
new BinaryOperator("Code", "NOTCHECKED"))
};
RuleSet ruleSet = new RuleSet();
RuleSetValidationResult result = ruleSet.ValidateTarget(regdetail, DefaultContexts.Save);
if (ValidationState.Invalid ==
result.GetResultItem("RegisterDetail.StudentRegLessonSemester").State)
{
if (!errorstudent.ContainsKey(currentStudent.StudentCode))
errorstudent.Add(currentStudent.StudentCode, new List<string>());
if (!errorstudent[currentStudent.StudentCode].Contains(curLesson.Subject.SubjectCode))
errorstudent[currentStudent.StudentCode].Add(curLesson.Subject.SubjectCode + "{D}");
regdetail.Delete();
//regdetail.Reload();
}
else
{
numregok++;
if (!dicStudentRegDetail.ContainsKey(student.StudentCode))
dicStudentRegDetail.Add(student.StudentCode,new List<string>());
dicStudentRegDetail[student.StudentCode].Add(curLesson.LessonName);
dicLessonCurrentRegNum[lesson.LessonName]++;
foreach (TkbSemester tkbsem in curLesson.TKBSemesters)
{
vc = new Vacancy(tkbsem.Day, tkbsem.Period, tkbsem.Weeks, (tkbsem.Classroom == null ? "" : tkbsem.Classroom.ClassroomCode));
listVacancies.Add(vc);
}
regdetail.Save();
}
}
else
{
if (!errorstudent.ContainsKey(currentStudent.StudentCode))
errorstudent.Add(currentStudent.StudentCode, new List<string>());
//.........这里部分代码省略.........