protected override void OnActivated() { base.OnActivated(); if (setEmployeeDirected != null && !ObjectSpace.IsModified) //Lọc chuyển XL văn bản khi ở chế độ xem { FillItemWithLeaderEmployeeValues(setEmployeeDirected); } Employee emp = (Employee)SecuritySystem.CurrentUser; Document curDoc = View.CurrentObject as Document; if (emp != null && curDoc != null) { //1. Cập nhật ngày đọc văn bản nếu ở chế độ View if (!ObjectSpace.IsModified) { CriteriaOperator crit = CriteriaOperator.And(new BinaryOperator("LinkEmployee.Oid", emp.Oid), new BinaryOperator("LinkDocument", curDoc)); DocumentEmployees docEmp = curDoc.Session.FindObject <DocumentEmployees>(crit); if (docEmp != null && (docEmp.DateRead == null || docEmp.DateRead == DateTime.MinValue)) { docEmp.DateRead = DateTime.Now; docEmp.Save(); View.ObjectSpace.CommitChanges(); } } } }
public object Evaluate(params object[] operands) { if (!(operands != null && operands.Length >= 1)) { return(false); } bool ret = false; 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 && operands[0].GetType() == typeof(Document)) { Document curDoc = operands[0] as Document; CriteriaOperator crit = CriteriaOperator.And(new BinaryOperator("LinkEmployee.Oid", emp.Oid), new BinaryOperator("LinkDocument.Oid", curDoc.Oid)); DocumentEmployees docEmp = emp.Session.FindObject <DocumentEmployees>(crit); if (docEmp != null && docEmp.IsFollow) { ret = true; } } return(ret); }
private void actTheodoi_Execute(object sender, SimpleActionExecuteEventArgs e) { os = Application.CreateObjectSpace(); Document currentDoc = e.CurrentObject as Document; // View.CurrentObject as Document; Employee curUser = SecuritySystem.CurrentUser as Employee; //CriteriaOperator crit; DocumentEmployees objDEmp = null; foreach (DocumentEmployees docEmp in currentDoc.DocumentEmployees) { if (docEmp != null && docEmp.LinkEmployee != null && curUser != null && docEmp.LinkEmployee.Oid == curUser.Oid && docEmp.IsDirected && docEmp.IsCurrentDirected) { objDEmp = os.FindObject <DocumentEmployees>(new BinaryOperator("Oid", docEmp.Oid)); } } if (objDEmp != null) { objDEmp.IsFollow = true; objDEmp.Save(); os.CommitChanges(); //Hiển thị OK Application.ShowViewStrategy.ShowViewInPopupWindow(Application.CreateDashboardView(Application.CreateObjectSpace(), "ActionOkDashboard", true), null, null, "OK", ""); } else { //Hiển thị lỗi quyền truy cập Application.ShowViewStrategy.ShowViewInPopupWindow(Application.CreateDashboardView(Application.CreateObjectSpace(), "AccessDeniedMessage", true), null, null, "OK", ""); } }
private void actForwardDocument_Execute(object sender, SimpleActionExecuteEventArgs e) { os = Application.CreateObjectSpace(); Document currentDoc = View.CurrentObject as Document; Document newDoc = os.CreateObject <Document>(); //.GetObject<Document>(currentDoc); //newDoc = currentDoc.CloneDocument(newDoc.Session); newDoc.DocId = currentDoc.DocId; newDoc.IsApproveed = false; newDoc.Note = @"<u>VB chuyển tiếp:</u><br />" + currentDoc.DocId; newDoc.Excerpt = string.Format("[CT] {0}", currentDoc.Excerpt); newDoc.DocDate = currentDoc.DocDate; //newDoc.DocSignees = os.GetObject<DocumentSignees>(currentDoc.DocSignees); newDoc.DocOrganization = os.GetObject <DocumentSigneesOrganization>(currentDoc.DocOrganization); newDoc.EmployeeReceiveds.Clear(); newDoc.DocumentEmployees.Clear(); newDoc.ParentDocument = os.GetObject <Document>(currentDoc); //newDoc.Save(); //Lấy file đính kèm foreach (DocumentFile curDocFile in currentDoc.FileAttachments) { if (curDocFile != null) { DocumentFile newDocFile = os.CreateObject <DocumentFile>(); newDocFile.Document = os.GetObject(newDoc); newDocFile.DocFile = os.GetObject(curDocFile.DocFile); newDocFile.Save(); } } /////// //os.CommitChanges(); Employee curUser = SecuritySystem.CurrentUser as Employee; // Gán người duyệt nếu user chuyển tiếp có vị trí lớn hơn 50 if (curUser.Position.PositionLevel >= 50) { newDoc.IsApproveed = true; newDoc.EmpApproved = os.GetObject <Employee>(curUser); DocumentEmployees approver = os.CreateObject <DocumentEmployees>(); approver.LinkDocument = newDoc; approver.LinkEmployee = newDoc.EmpApproved; newDoc.DocumentEmployees.Add(approver); } //CriteriaOperator crit; DocumentEmployees objDEmp = os.CreateObject <DocumentEmployees>(); //DocumentEmployees objDE = os.FindObject<DocumentEmployees>(new BinaryOperator()); //os.CreateObject<DocumentEmployees>(); //DetailView dv = Application.CreateDetailView(os, "DocumentEmployees_DetailView_Forward", true, objDEmp); DetailView dvDocument = Application.CreateDetailView(os, "Document_DetailView_New", true, newDoc); //ShowViewParameters svp = new ShowViewParameters(dv); //svp.TargetWindow = DevExpress.ExpressApp.TargetWindow.NewModalWindow; //svp.CreatedView = dv; //svp.NewWindowTarget = NewWindowTarget.Default; dvDocument.ViewEditMode = ViewEditMode.Edit; e.ShowViewParameters.CreatedView = dvDocument; os.SetModified(newDoc); //Application.ShowViewStrategy.ShowView(e.ShowViewParameters, new ShowViewSource(Frame, actForwardDocument)); // null, null)); }
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."); } 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 && operands[0].GetType() == typeof(Document)) { Document curDoc = operands[0] as Document; CriteriaOperator crit = CriteriaOperator.And(new BinaryOperator("LinkEmployee.Oid", emp.Oid), new BinaryOperator("LinkDocument.Oid", curDoc.Oid)); //DocumentEmployees docEmp = curDoc.Session.FindObject<DocumentEmployees>(CriteriaOperator.Parse(string.Format("LinkEmployee = {0} And LinkDocument = {1}", emp, curDoc))); DocumentEmployees docEmp = emp.Session.FindObject <DocumentEmployees>(crit); if (docEmp != null && (docEmp.DateRead == null || docEmp.DateRead == DateTime.MinValue)) { 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); }
private void actChuyenXuly_Execute(object sender, SingleChoiceActionExecuteEventArgs e) { if (e.SelectedChoiceActionItem != null) { Employee newEmp = e.SelectedChoiceActionItem.Data as Employee; Employee currentEmp = (Employee)SecuritySystem.CurrentUser; if (newEmp != null && currentEmp != null) { Document curDoc = View.CurrentObject as Document; if (curDoc != null) { //1. Bỏ chế độ isCurrentDirected int idx = curDoc.DocumentEmployees.FindIndex(x => x.LinkEmployee.Oid == currentEmp.Oid && x.IsCurrentDirected); if (idx > -1) { curDoc.DocumentEmployees[idx].IsCurrentDirected = false; curDoc.DocumentEmployees[idx].DirectedContent = string.Format("Đã chuyển \"{0}\" xử lý!", newEmp.Title); curDoc.DocumentEmployees[idx].DateDirected = DateTime.Now; int directOrder = curDoc.DocumentEmployees[idx].DirectedOrder; //2. Cập nhật người duyệt mới: add vao neu chua co idx = curDoc.DocumentEmployees.FindIndex(x => x.LinkEmployee == newEmp); if (idx > -1) //Cập nhật { curDoc.DocumentEmployees[idx].IsCurrentDirected = true; curDoc.DocumentEmployees[idx].IsDirected = true; } else //Thêm người vào danh sách { os = Application.CreateObjectSpace(); DocumentEmployees docEmp = os.CreateObject <DocumentEmployees>(); docEmp.LinkDocument = os.GetObject(curDoc); docEmp.LinkEmployee = os.GetObject(newEmp); docEmp.IsDirected = true; docEmp.IsCurrentDirected = true; docEmp.DirectedOrder = directOrder + 1; docEmp.Save(); os.CommitChanges(); //Hiển thị OK Application.ShowViewStrategy.ShowViewInPopupWindow(Application.CreateDashboardView(Application.CreateObjectSpace(), "ActionOkDashboard", true), null, null, "OK", ""); } curDoc.Save(); ObjectSpace.CommitChanges(); } } } } }
//Bắt hàm này để tránh load event saving nhiều lần private void AcceptAction_Execute(object sender, SimpleActionExecuteEventArgs e) { //Cập nhật ngày chỉ đạo if (e.CurrentObject is DocumentEmployees) { DocumentEmployees docEmp = e.CurrentObject as DocumentEmployees; docEmp.DateDirected = DateTime.Now; docEmp.LinkDocument.IsApproveed = true; docEmp.LinkDocument.EmpApproved = docEmp.LinkEmployee; docEmp.LinkDocument.ContentApproved = docEmp.DirectedContent; //docEmp.Session.CommitTransaction(); os.CommitChanges(); os.Refresh(); } }
private void refreshSelectedDepartment() { if (treeListEditor != null) { DetailView dvOwner = View.ObjectSpace.Owner as DetailView; if (dvOwner != null && dvOwner.CurrentObject != null && dvOwner.CurrentObject is DocumentEmployees) { DocumentEmployees curDocEmp = dvOwner.CurrentObject as DocumentEmployees; if (curDocEmp != null && curDocEmp.LinkDocument != null) { Document curDoc = curDocEmp.LinkDocument as Document; if ((curDoc.DepartmentReceivedsSelected.Count > 0)) { treeListEditor.SetControlSelectedObjects(curDoc.DepartmentReceivedsSelected.ToList <object>()); isFirstLoad = false; } } } } }
private void actChiDaoVanBan_Execute(object sender, SimpleActionExecuteEventArgs e) { os = Application.CreateObjectSpace(); Document currentDoc = e.CurrentObject as Document; // View.CurrentObject as Document; Employee curUser = SecuritySystem.CurrentUser as Employee; //CriteriaOperator crit; DocumentEmployees objDEmp = null; foreach (DocumentEmployees docEmp in currentDoc.DocumentEmployees) { if (docEmp != null && docEmp.LinkEmployee != null && curUser != null && docEmp.LinkEmployee.Oid == curUser.Oid && docEmp.IsDirected && docEmp.IsCurrentDirected) { objDEmp = os.FindObject <DocumentEmployees>(new BinaryOperator("Oid", docEmp.Oid)); } } if (objDEmp != null) { //DocumentEmployees objDE = os.FindObject<DocumentEmployees>(new BinaryOperator()); //os.CreateObject<DocumentEmployees>(); objDEmp.LinkDocument = os.GetObject <Document>(currentDoc); DetailView dv = Application.CreateDetailView(os, "DocumentEmployees_DetailView_Approved", true, objDEmp); dv.ViewEditMode = ViewEditMode.Edit; e.ShowViewParameters.TargetWindow = TargetWindow.NewModalWindow; e.ShowViewParameters.NewWindowTarget = NewWindowTarget.Default; e.ShowViewParameters.CreatedView = dv; e.ShowViewParameters.CreateAllControllers = true; DialogController defaultDialogController = Application.CreateController <DialogController>(); defaultDialogController.AcceptAction.Execute += AcceptAction_Execute; defaultDialogController.AcceptAction.Executed += AcceptAction_Executed; e.ShowViewParameters.Controllers.Add(defaultDialogController); // os.SetModified(objDEmp); } else { //Hiển thị lỗi quyền truy cập Application.ShowViewStrategy.ShowViewInPopupWindow(Application.CreateDashboardView(Application.CreateObjectSpace(), "AccessDeniedMessage", true), null, null, "OK", ""); } }
private void FeatureMarked(bool isFeature, SimpleActionExecuteEventArgs e) { Employee curEmp = SecuritySystem.CurrentUser as Employee; foreach (Document selectDoc in e.SelectedObjects) { CriteriaOperator crit = CriteriaOperator.And(new BinaryOperator("LinkEmployee.Oid", curEmp.Oid), new BinaryOperator("LinkDocument.Oid", selectDoc.Oid)); DocumentEmployees docEmp = View.ObjectSpace.FindObject <DocumentEmployees>(crit); if (docEmp != null) { //The Action's state is updated when objects in Views change their values. This work is done by the ActionsCriteriaViewController docEmp.IsFollow = isFeature; docEmp.Save(); docEmp.Session.CommitTransaction(); ASPxGridListEditor listEditor = ((ListView)View).Editor as ASPxGridListEditor; if (listEditor != null) { listEditor.UnselectAll(); } //View.SelectedObjects.Clear(); //View.Refresh(); } } }
protected override void OnViewControlsCreated() { base.OnViewControlsCreated(); #region 1. Đánh dấu chọn các phòng có người treeListEditor = ((ListView)View).Editor as ASPxTreeListEditor; if (View.ObjectSpace.Owner is DetailView) { dvOwner = View.ObjectSpace.Owner as DetailView; //1. Trường hợp Owner là Document if (dvOwner.CurrentObject != null && dvOwner.CurrentObject is Document) { curDoc = dvOwner.CurrentObject as Document; //2. Tạo các Event handle, khởi tạo giá trị if (treeListEditor != null) { treeList = treeListEditor.TreeList as ASPxTreeList; if (treeList != null) { treeListFixedWidth = treeList.Width.Value - 5; if (treeList.FocusedNode != null && treeList.FocusedNode.Level > 0) { treeListFixedWidth = treeList.Width.Value - 100 * treeList.FocusedNode.Level; } treeList.Width = new Unit(90, UnitType.Percentage);; treeList.Height = new Unit(100, UnitType.Percentage); treeList.Settings.ScrollableHeight = 350; treeList.SettingsBehavior.FocusNodeOnExpandButtonClick = false; treeList.SettingsBehavior.ProcessFocusedNodeChangedOnServer = false; treeList.Settings.VerticalScrollBarMode = ScrollBarMode.Visible; treeList.SettingsPager.Visible = false; treeList.SettingsPager.Summary.Visible = false; treeList.SettingsPager.PageSize = 500; treeList.SettingsSelection.Recursive = true; treeList.Settings.VerticalScrollBarMode = ScrollBarMode.Visible; treeList.Load += TreeListDepartmentReceived_Load; treeList.SelectionChanged += TreeListDepartmentReceived_SelectionChanged; } } } //2. Trường hợp Owner là DocumentEmployees (Phê duyệt/chỉ đạo) if (dvOwner.CurrentObject != null && dvOwner.CurrentObject is DocumentEmployees) { DocumentEmployees curDocEmp = dvOwner.CurrentObject as DocumentEmployees; if (curDocEmp != null && curDocEmp.LinkDocument != null) { Document curDoc = curDocEmp.LinkDocument as Document; //Tạo các Event handle, khởi tạo giá trị if (treeListEditor != null) { treeList = treeListEditor.TreeList as ASPxTreeList; if (treeList != null) { treeListFixedWidth = treeList.Width.Value - 5; treeList.Height = new Unit(100, UnitType.Percentage); treeList.Settings.ScrollableHeight = 350; treeList.SettingsPager.Visible = false; treeList.SettingsPager.Summary.Visible = false; treeList.SettingsPager.PageSize = 1000; treeList.SettingsBehavior.FocusNodeOnExpandButtonClick = false; treeList.SettingsBehavior.ProcessFocusedNodeChangedOnServer = false; treeList.Settings.VerticalScrollBarMode = ScrollBarMode.Visible; treeList.SettingsSelection.Recursive = true; treeList.Load += TreeListDepartmentReceivedDocEmp_Load; treeList.SelectionChanged += TreeListDepartmentReceived_SelectionChanged; } } } } } #endregion }
private void TreeListDepartmentReceived_SelectionChanged(object sender, EventArgs e) { //return; if (View.SelectedObjects != null && View.SelectedObjects.Count > 0) { DetailView dvo = View.ObjectSpace.Owner as DetailView; Document curDoc = null; if (dvo != null && dvo.CurrentObject != null && dvo.CurrentObject is Document) { curDoc = dvo.CurrentObject as Document; curDoc.EmployeeReceiveds.Clear(); } else if (dvo != null && dvo.CurrentObject != null && dvo.CurrentObject is DocumentEmployees) { DocumentEmployees curDocEmp = dvo.CurrentObject as DocumentEmployees; if (curDocEmp != null && curDocEmp.LinkDocument != null) { curDoc = curDocEmp.LinkDocument as Document; } } if (curDoc == null) { ///check errror return; } //a) Xác định danh sách các trưởng phòng ban đang được chọn List <Employee> lstLeaderSelected = new List <Employee>(); foreach (object obj in View.SelectedObjects) { if (obj is Department) { Department dep = obj as Department; if (dep.Employees != null && dep.Employees.Count > 0) { Employee leader = dep.getLeader(); if (leader != null) { lstLeaderSelected.Add(leader); } } else if (dep.SubordinatesDepartments.Count > 0) { foreach (Department subdep in dep.SubordinatesDepartments) { Employee leader = subdep.getLeader(); if (leader != null) { lstLeaderSelected.Add(leader); } } } } else if (obj is Employee) { Employee emp = obj as Employee; if (emp != null) { lstLeaderSelected.Add(emp); } } } lstLeaderSelected = lstLeaderSelected.Distinct(new EmployeeEqualityComparer()).ToList(); foreach (Employee employeeToAdd in lstLeaderSelected) { curDoc.EmployeeReceiveds.Add(employeeToAdd); } //View.ObjectSpace.CommitChanges(); ///Không thực hiện 3 dòng sau để cải thiện tốc độ //curDoc.Reload(); //dvo.Refresh(); //dvo.RefreshDataSource(); //Panel pan = dvo.Control as Panel; //ASPxGridView c = pan.FindControl("Document_EmployeeReceiveds_ListView") as ASPxGridView; } #region Old way /* * IObjectSpace os = Application.CreateObjectSpace(); #region 1. Duyệt danh sách department select, add vào danh sách Leader nhận nếu chưa có * if (View.SelectedObjects != null && View.SelectedObjects.Count > 0) * { * DetailView dvo = View.ObjectSpace.Owner as DetailView; * Document curDoc = null; * if (dvo != null && dvo.CurrentObject != null && dvo.CurrentObject is Document) * { * curDoc = dvo.CurrentObject as Document; * } * else if (dvo != null && dvo.CurrentObject != null && dvo.CurrentObject is DocumentEmployees) * { * DocumentEmployees curDocEmp = dvo.CurrentObject as DocumentEmployees; * if (curDocEmp != null && curDocEmp.LinkDocument != null) * { * curDoc = curDocEmp.LinkDocument as Document; * } * } * * if (curDoc == null) * { * ///check errror * return; * } * * /////1.1 Remove những obj ko được chọn (mới bỏ chọn?) * List<DocumentEmployees> objectsToDelete = new List<DocumentEmployees>(); * foreach (Employee obj in curDoc.EmployeeReceiveds) * { * if (obj != null) * { * DocumentEmployees docEmpToRemoved = os.FindObject<DocumentEmployees>( * CriteriaOperator.And(new BinaryOperator("LinkDocument", os.GetObject(curDoc)), * new BinaryOperator("LinkEmployee", os.GetObject(obj)))); * if (docEmpToRemoved != null && docEmpToRemoved.LinkEmployee != null && !View.SelectedObjects.Contains(docEmpToRemoved.LinkEmployee.Department)) * { * objectsToDelete.Add(os.GetObject(docEmpToRemoved)); * } * } * } * os.Delete(objectsToDelete); * os.CommitChanges(); * * //View.ObjectSpace.Delete(curDoc.EmployeeReceiveds); * //View.ObjectSpace.CommitChanges(); * //curDoc.EmployeeReceiveds.Clear(); * * foreach (object objDep in View.SelectedObjects) * { * if (objDep is Department) * { * Department dep = objDep as Department; * if (dep != null && dep.Employees != null && dep.Employees.Count > 0 && View.ObjectSpace != null && View.ObjectSpace.Owner != null && View.ObjectSpace.Owner is DetailView) * { * * if (dvo != null && dvo.CurrentObject != null && (dvo.CurrentObject is Document || dvo.CurrentObject is DocumentEmployees)) * { * * Employee departmentLeader = dep.getLeader(); * if (curDoc != null && curDoc.DocumentEmployees != null) // && curDoc.DocumentEmployees.Count > 0 * { * /////1.2 Add * List<CriteriaOperator> andOperator = new List<CriteriaOperator>(); * andOperator.Add(new BinaryOperator("LinkDocument", os.GetObject(curDoc))); * andOperator.Add(new BinaryOperator("LinkEmployee", os.GetObject(departmentLeader))); * DocumentEmployees leaderDocEmp = os.FindObject<DocumentEmployees>(new GroupOperator(GroupOperatorType.And, andOperator)); * * if (leaderDocEmp != null) //Đã có người này nhận văn bản, add vào list Flag nếu chưa có * { * if (!empOidStrFlag.Contains(departmentLeader.Oid.ToString())) * { * empOidStrFlag.Add(departmentLeader.Oid.ToString()); * } * } * else //Không tìm thấy? => chưa có, add vào * { * if (curDoc.DocumentEmployees == null) * { * //Vinabits: Error apply employee * return; * } * //IObjectSpace os = Application.CreateObjectSpace(); * DocumentEmployees de = os.CreateObject<DocumentEmployees>(); * de.LinkDocument = os.FindObject<Document>(new BinaryOperator("Oid", curDoc.Oid)); * de.LinkEmployee = os.FindObject<Employee>(new BinaryOperator("Oid", departmentLeader.Oid)); * de.Save(); * //de.Session.CommitTransaction(); * os.CommitChanges(); * if (!empOidStrFlag.Contains(departmentLeader.Oid.ToString())) * { * empOidStrFlag.Add(departmentLeader.Oid.ToString()); * } * curDoc.Reload(); * //Không cần add nữa * //curDoc.DocumentEmployees.Add(de); * //curDoc.Save(); * //curDoc.Session.CommitTransaction(); * } * } * * //dvo.RefreshDataSource(); * //dvo.Refresh(); * } * } * }// foreach selected * } * } #endregion */ #endregion Old way }