protected override void OnActivated() { base.OnActivated(); // Perform various tasks depending on the target View. TaskExtra task = View.CurrentObject as TaskExtra; Employee currentUser = SecuritySystem.CurrentUser as Employee; if (task != null && currentUser != null && task.LastNote != null) { TrackEmployee track = View.ObjectSpace.FindObject <TrackEmployee>(CriteriaOperator.And( new BinaryOperator("ObjectType", task.LastNote.GetType().Name), new BinaryOperator("ObjOid", task.LastNote.Oid), new BinaryOperator("EmpAttack", currentUser.Oid), new BinaryOperator("TypeAttack", EmpAttackType.t0_read) )); if (track == null) { track = View.ObjectSpace.CreateObject <TrackEmployee>(); track.ObjectType = task.LastNote.GetType().Name; track.ObjOid = task.LastNote.Oid; track.EmpAttack = currentUser.Oid; track.TypeAttack = EmpAttackType.t0_read; View.ObjectSpace.CommitChanges(); } } }
public object Evaluate(params object[] operands) { if (!(operands != null && operands.Length == 1)) // && operands[0] is Guid { return(false); //throw new ArgumentException("CheckIsRead operator should have one parameter - Guid."); } if (operands[0] == null) { return(false); } bool ret = true; Employee emp = null; if (SecuritySystem.CurrentUser != null) { emp = (Employee)SecuritySystem.CurrentUser; } else if (SecuritySystem.CurrentUserId != null) { emp = SecuritySystem.LogonObjectSpace.FindObject <Employee>(new BinaryOperator("Oid", SecuritySystem.CurrentUserId)); } if (emp != null && operands[0] != null) { string strCrit = string.Format("ObjectType = '{0}' And ObjOid = {{{1}}} And EmpAttack = {{{2}}} And TypeAttack = {3}", operands[0].GetType().Name, ((BaseObject)operands[0]).Oid, emp.Oid, 0); TrackEmployee trackEmp = emp.Session.FindObject <TrackEmployee>(CriteriaOperator.Parse(strCrit)); if (trackEmp != null) { ret = false; } //using (ExplicitUnitOfWork euow = new ExplicitUnitOfWork(emp.Session.DataLayer)) //{ // XPCollection<TrackEmployee> tracks = new XPCollection<TrackEmployee>(euow); // string strCrit = string.Format("ObjectType = '{0}' And ObjOid = {{{1}}} And EmpAttack = {{{2}}} And TypeAttack = {3}", // operands[0].GetType().Name, ((BaseObject)operands[0]).Oid, emp.Oid, 0); // //EmpAttackType.t0_read ~ 0 // tracks.Criteria = CriteriaOperator.Parse(strCrit); // tracks.Load(); // if (tracks != null && tracks.Count > 0) // ret = false; //} } return(ret); }
protected override void OnActivated() { base.OnActivated(); //2. Cập nhật quá trình open Task/Message/Note Employee emp = null; if (SecuritySystem.CurrentUser != null) { emp = (Employee)SecuritySystem.CurrentUser; } else if (SecuritySystem.CurrentUserId != null) { emp = SecuritySystem.LogonObjectSpace.FindObject <Employee>(new BinaryOperator("Oid", SecuritySystem.CurrentUserId)); } if (emp != null && Application != null && View.CurrentObject != null && View is DetailView && (View.CurrentObject is TaskExtra || View.CurrentObject is NoteExtra || View.CurrentObject is Messages) ) { string strCrit = string.Format("ObjectType = '{0}' And ObjOid = {{{1}}} And EmpAttack = {{{2}}} And TypeAttack = {3}", View.CurrentObject.GetType().Name, ((BaseObject)View.CurrentObject).Oid, emp.Oid, 0); TrackEmployee trackEmp = emp.Session.FindObject <TrackEmployee>(CriteriaOperator.Parse(strCrit)); if (trackEmp == null) { IObjectSpace os = Application.CreateObjectSpace(); TrackEmployee track = os.CreateObject <TrackEmployee>(); track.DateCreated = DateTime.Now; track.ObjectType = View.CurrentObject.GetType().Name; track.ObjOid = ((BaseObject)View.CurrentObject).Oid; track.EmpAttack = emp.Oid; track.TypeAttack = EmpAttackType.t0_read; if (track.ObjOid != null && track.ObjOid != Guid.Parse("00000000-0000-0000-0000-000000000000")) { track.Save(); os.CommitChanges(); } } ///OLD WAY /* * //SqlConnection connection = (SqlConnection)Application.Connection; * SqlConnection connection = (SqlConnection)((ConnectionProviderSql)(((DevExpress.Xpo.Helpers.BaseDataLayer)(((BaseObject)SecuritySystem.CurrentUser).Session.DataLayer)).ConnectionProvider)).Connection; * if (connection != null) * { * using (IDataLayer dataLayer = new SimpleDataLayer(MSSqlConnectionProvider.CreateProviderFromConnection(connection, DevExpress.Xpo.DB.AutoCreateOption.SchemaAlreadyExists))) * { * using (ExplicitUnitOfWork euow = new ExplicitUnitOfWork(dataLayer)) * { * TrackEmployee track = new TrackEmployee(euow); * Employee emp = track.Session.GetObjectByKey<Employee>(track.Session.GetKeyValue(SecuritySystem.CurrentUser)); * * XPCollection<TrackEmployee> tracks = new XPCollection<TrackEmployee>(euow); * string strCrit = string.Format("ObjectType = '{0}' And ObjOid = {{{1}}} And EmpAttack = {{{2}}} And TypeAttack = {3}", * View.CurrentObject.GetType().Name, ((BaseObject)View.CurrentObject).Oid, emp.Oid, 0); * //EmpAttackType.t0_read ~ 0 * tracks.Criteria = CriteriaOperator.Parse(strCrit); * tracks.Load(); * * if (tracks == null || tracks.Count <= 0) * { * track.DateCreated = DateTime.Now; * track.ObjectType = View.CurrentObject.GetType().Name; * track.ObjOid = ((BaseObject)View.CurrentObject).Oid; * track.EmpAttack = emp.Oid; * track.TypeAttack = EmpAttackType.t0_read; * * if (track.ObjOid != null && track.ObjOid != Guid.Parse("00000000-0000-0000-0000-000000000000")) * { * track.Save(); * euow.CommitChanges(); * } * } * tracks.Dispose(); * euow.Dispose(); * } * //dataLayer.Dispose(); * } * } */ } }