void ObjectSpace_CustomDeleteObjects(object sender, CustomDeleteObjectsEventArgs e) { if (e.Objects != null) { foreach (object objectToDelete in e.Objects) { object deletedItem = objectToDelete; if (deletedItem != null) { if (deletedItem is EFDataViewRecord) { deletedItem = ObjectSpace.GetObject(objectToDelete); } ForceLoadDependencies(deletedItem); } } } }
void treeList_CellValueChanged(object sender, CellValueChangedEventArgs e) { var protocolRecord = (sender as ObjectTreeList).FocusedObject as ProtocolRecord; if (protocolRecord != null) { object newValue = e.Value; if (e.Value is IXPSimpleObject) { newValue = ObjectSpace.GetObject(e.Value); } if (protocolRecord.Type.Type == TypeEnum.Date) { if (e.Value is DateTime) { newValue = ((DateTime)e.Value).ToString("dd.MM.yyyy"); } } if (protocolRecord.Type.Type == TypeEnum.Time) { if (e.Value is DateTime) { newValue = ((DateTime)e.Value).TimeOfDay.ToString(@"hh\:mm\:ss"); } } object focusedObject = treeList.FocusedObject; if (focusedObject != null) { IMemberInfo focusedColumnMemberInfo = ObjectSpace.TypesInfo.FindTypeInfo(focusedObject.GetType()).FindMember(e.Column.FieldName); if (focusedColumnMemberInfo != null) { focusedColumnMemberInfo.SetValue(focusedObject, Convert.ChangeType(newValue, focusedColumnMemberInfo.MemberType)); } ObjectSpace.SetModified(focusedObject); } treeList.FilterNodes(); } }
void ObjectSpace_ObjectChanged(object sender, ObjectChangedEventArgs e) { var parent = ObjectSpace.GetObject(((NestedFrame)Frame).ViewItem.CurrentObject as Faktura); if (View.CurrentObject == e.Object && e.PropertyName == nameof(Klient.Nazwa) && ObjectSpace.IsModified && e.OldValue != e.NewValue) { Klient changedContact = (Klient)e.Object; var newCustomer = ObjectSpace.GetObjectsQuery <Klient>().Where(k => k.Nazwa == (string)e.NewValue).FirstOrDefault(); if (parent != null && newCustomer != null) { parent.ZmienKlienta(newCustomer); View.Refresh(); changedContact.Nazwa = (string)e.OldValue; } } }
private void disqualifyLead_Execute(Object sender, PopupWindowShowActionExecuteEventArgs e) { Lead lead = null; if (View.CurrentObject is XafDataViewRecord) { lead = (Lead)ObjectSpace.GetObject(View.CurrentObject); } else { lead = (Lead)View.CurrentObject; } lead.Status = ((DisqualifyLeadParameters)e.PopupWindow.View.CurrentObject).Status; View.ObjectSpace.CommitChanges(); if (View is ListView) { View.ObjectSpace.Refresh(); } }
private void qualifyLead_Execute(Object sender, PopupWindowShowActionExecuteEventArgs e) { Lead lead = null; if (View.CurrentObject is XafDataViewRecord) { lead = (Lead)ObjectSpace.GetObject(View.CurrentObject); } else { lead = (Lead)View.CurrentObject; } ((QualifyLeadParameters)e.PopupWindow.View.CurrentObject).Qualify(lead, View.ObjectSpace, Application.CreateObjectSpace(typeof(Lead))); View.ObjectSpace.CommitChanges(); if (View is ListView) { View.ObjectSpace.Refresh(); } }
public static XPBaseObject GetXpObjectByKeyValue(ObjectSpace oSpace, string value, Type type) { if (string.IsNullOrEmpty(value)) return null; if (!type.IsSubclassOf(typeof(XPBaseObject))) return null; var keyPropertyName = oSpace.Session.GetClassInfo(type). PersistentProperties. OfType<XPMemberInfo>(). Where(p => p.HasAttribute(typeof(KeyPropertyAttribute))). Select(p => p.Name). FirstOrDefault() ?? oSpace.Session.GetClassInfo(type). PersistentProperties. OfType<XPMemberInfo>(). Where(p => p.Name == "Name" || p.Name == "Code") .Select(p => p.Name) .FirstOrDefault() ?? "Oid"; var item = (XPBaseObject)oSpace.FindObject( type, new BinaryOperator(keyPropertyName, value), true); if (item != null) return item; var nestedObjectSpace = oSpace.CreateNestedObjectSpace(); item = (XPBaseObject)nestedObjectSpace.CreateObject(type); item.ClassInfo.PersistentProperties. OfType<XPMemberInfo>(). Where(p => p.Name == keyPropertyName). FirstOrDefault(). SetValue(item, value); item.Save(); nestedObjectSpace.CommitChanges(); return oSpace.GetObject(item); }
private void treeList_CellValueChanged(object sender, CellValueChangedEventArgs e) { object newValue = e.Value; if (e.Value is IXPSimpleObject) { newValue = ObjectSpace.GetObject(e.Value); } object focusedObject = _treeList.FocusedObject; if (focusedObject != null) { var focusedColumnMemberInfo = ObjectSpace.TypesInfo.FindTypeInfo(focusedObject.GetType()).FindMember(e.Column.FieldName); if (focusedColumnMemberInfo != null) { var type = Convert.ChangeType(newValue, focusedColumnMemberInfo.MemberType); focusedColumnMemberInfo.SetValue(focusedObject, type); } } }
private void WybierzFakturyAction_Execute(object sender, PopupWindowShowActionExecuteEventArgs e) { var rozliczenie = ViewCurrentObject; foreach (var obj in e.PopupWindowViewSelectedObjects) { var faktura = (Faktura)ObjectSpace.GetObject(obj); var fakturaDoRozliczenia = new FakturaDoRozliczeniaDC(); fakturaDoRozliczenia.Faktura = faktura; var kwotaDoRozliczenia = rozliczenie.Wplata.Nadplata - rozliczenie.SumaRozliczen; var kwotaFaktury = faktura.WartoscBrutto - faktura.SumaWplat; var kwotaDoFaktury = kwotaDoRozliczenia > kwotaFaktury ? kwotaFaktury : kwotaDoRozliczenia; fakturaDoRozliczenia.KwotaDoRozliczenia = kwotaDoFaktury; rozliczenie.Naleznosci.Add(fakturaDoRozliczenia); // rozliczenie.SumaRozliczen += kwotaDoFaktury ; } View.Refresh(); }
private static Node getAllNodes(ObjectSpace ObjectManager, int currentNodeID, Node parent) { try { Node n = (Node)ObjectManager.GetObject(typeof(Node), currentNodeID); n.parent = parent; ObjectQuery oq = new ObjectQuery(typeof(Node), "parentID=" + currentNodeID, "rank ASC"); //ObjectReader or = ObjectManager.GetObjectReader(typeof(Node),"parentID=" + currentNodeID); ObjectReader or = ObjectManager.GetObjectReader(oq); NodeCollection nc = new NodeCollection(); foreach (Node childNode in or) { nc.Add(getAllNodes(ObjectManager, childNode.Id, n)); } n.children = nc; return(n); } catch (Exception e) { throw new Exception("problem! currentNodeID:" + currentNodeID, e); } }
private void AllDataIsOK(SimpleActionExecuteEventArgs e) { ArrayList SelectedCtrhs = new ArrayList(); if ((e.SelectedObjects.Count > 0) && ((e.SelectedObjects[0] is XafDataViewRecord) || (e.SelectedObjects[0] is XafInstantFeedbackRecord))) { foreach (var selectedObject in e.SelectedObjects) { SelectedCtrhs.Add((CommonTrHeader)ObjectSpace.GetObject(selectedObject)); } } else { SelectedCtrhs = (ArrayList)e.SelectedObjects; } foreach (CommonTrHeader selectedCtrh in SelectedCtrhs) { selectedCtrh.Status = 5; } View.ObjectSpace.CommitChanges(); ObjectSpace.Refresh(); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void simpleAction1_Execute(object sender, SimpleActionExecuteEventArgs e) { var editDate = DateTime.Today; var lastEndTime = new TimeSpan(editDate.Hour, editDate.Minute, editDate.Second); if ((View.CurrentObject) != null) { editDate = ((IBooking)View.CurrentObject).Date; } _currentObjectSpace = Application.CreateObjectSpace(); var currentUser = ObjectSpace.GetObject(SecuritySystem.CurrentUser); var currentEmployee = ObjectSpace.FindObject <IEmployee>( CriteriaOperator.Parse("User = ?", currentUser)); var bookings = ObjectSpace.GetObjects <IBooking>( CriteriaOperator.Parse("Date = ? AND Employee = ?", editDate, currentEmployee)); var booking = _currentObjectSpace.CreateObject <IBooking>(); if (bookings.Any()) { lastEndTime = ((IBooking)View.CurrentObject)?.EndTime ?? bookings.Max(b => b.EndTime); booking.StartTime = lastEndTime; booking.EndTime = lastEndTime.Add(new TimeSpan(1, 0, 0)); booking.Date = editDate; } //Show(_currentObjectSpace, booking); ShowBookingDialog(_currentObjectSpace, booking); }
private void treeList_CellValueChanged(object sender, CellValueChangedEventArgs e) { if (!e.ChangedByUser) { return; } ObjectTreeList treeList = (ObjectTreeList)sender; object newValue = e.Value; if (e.Value is IXPSimpleObject) { newValue = ObjectSpace.GetObject(e.Value); } object focusedObject = treeList.FocusedObject; if (focusedObject != null) { IMemberInfo focusedColumnMemberInfo = ObjectSpace.TypesInfo.FindTypeInfo(focusedObject.GetType()).FindMember(e.Column.FieldName); if (focusedColumnMemberInfo != null) { focusedColumnMemberInfo.SetValue(focusedObject, Convert.ChangeType(newValue, focusedColumnMemberInfo.MemberType)); } } }
private void actAddItems_Execute(object sender, PopupWindowShowActionExecuteEventArgs e) { IList items = (IList)((ListView)e.PopupWindow.View).CollectionSource.Collection; var attribute = View.ObjectTypeInfo.FindAttribute <AddItemClassAttribute>(); if (attribute.TransactionType == EnumInventoryTransactionType.PurchaseInvoice) { foreach (var item in items) { if (((AddPurchaseItems)item).Quantity != 0) { var newObj = ObjectSpace.CreateObject <PurchaseInvoiceDetail>(); newObj.Item = ObjectSpace.GetObject(((AddPurchaseItems)item).Item); newObj.TransactionUnit = ObjectSpace.GetObject(((AddPurchaseItems)item).Unit); newObj.Quantity = ((AddPurchaseItems)item).Quantity; newObj.Price = ((AddPurchaseItems)item).Price; ((PurchaseInvoice)MasterObject).Items.Add(newObj); } } } else if (attribute.TransactionType == EnumInventoryTransactionType.SalesInvoice) { foreach (var item in items) { if (((AddSalesItems)item).Quantity != 0) { var newObj = ObjectSpace.CreateObject <SalesInvoiceDetail>(); newObj.Item = ObjectSpace.GetObject(((AddSalesItems)item).Item); newObj.TransactionUnit = ObjectSpace.GetObject(((AddSalesItems)item).Unit); newObj.Quantity = ((AddSalesItems)item).Quantity; ((SalesInvoice)MasterObject).Items.Add(newObj); } } } else if (attribute.TransactionType == EnumInventoryTransactionType.InventoryTransfer) { foreach (var item in items) { if (((AddInventoryItems)item).Quantity != 0) { var newObj = ObjectSpace.CreateObject <InventoryTransferSourceItem>(); newObj.Item = ObjectSpace.GetObject(((AddInventoryItems)item).Item); newObj.TransactionUnit = ObjectSpace.GetObject(((AddInventoryItems)item).Unit); newObj.Quantity = ((AddInventoryItems)item).Quantity; ((InventoryTransfer)MasterObject).Items.Add(newObj); } } } else if (attribute.TransactionType == EnumInventoryTransactionType.InventoryAdjustment) { foreach (var item in items) { if (((AddInventoryItems)item).Quantity != 0) { var newObj = ObjectSpace.CreateObject <InventoryAdjustmentItem>(); newObj.Item = ObjectSpace.GetObject(((AddInventoryItems)item).Item); newObj.TransactionUnit = ObjectSpace.GetObject(((AddInventoryItems)item).Unit); newObj.ActualQuantity = ((AddInventoryItems)item).Quantity; ((InventoryAdjustment)MasterObject).Items.Add(newObj); } } } else if (attribute.TransactionType == EnumInventoryTransactionType.MenuSales) { foreach (var item in items) { if (((AddMenuSalesItems)item).Quantity != 0) { var newObj = ObjectSpace.CreateObject <MenuSalesItem>(); newObj.Item = ObjectSpace.GetObject(((AddMenuSalesItems)item).Item); newObj.Quantity = ((AddMenuSalesItems)item).Quantity; ((MenuSales)MasterObject).Items.Add(newObj); } } } }
private void ExecuteAction(IObjectSpace newFormOs, 单据 fromObject, FlowAction action) { //action数据是来自于 初始化按钮时的os,它可能不是当前objectspace action = ObjectSpace.GetObject(action); var os = new NonPersistentObjectSpace(null); var toType = ReflectionHelper.FindType(action.To.Form); #region 生成目标单据主表属性 单据 toObject = null; //查找当前单据是从那张单据生成过来的 var record = ObjectSpace.FindObject <单据流程状态记录>(CriteriaOperator.Parse("目标单据=?", CurrentObject.GetMemberValue("Oid").ToString())); if (action.目标类型 == 目标类型.生成单据) { toObject = newFormOs.CreateObject(toType) as 单据; } else if (action.目标类型 == 目标类型.更新单据) { var history = ObjectSpace.FindObject <单据流程状态记录>(CriteriaOperator.Parse("来源单据=? and 执行动作.Oid=?", CurrentObject.GetMemberValue("Oid").ToString(), action.Oid)); if (history != null) { //更新动作已经执行过了,不要再执行。 return; } //如果是更新单据,那必然是有已经生成过的单据。 if (record != null) { toObject = newFormOs.GetObject(record.来源单据); // newFormOs.GetObjectByStringKey(action.ToType, record.来源单据) as 单据; } else { return; } if (toObject == null) { return; } } var clsname = action.GetFlowLogicClassFullName(); var actionLogicType = ReflectionHelper.FindType(clsname); IExecuteFlowAction actionLogic = null; if (actionLogicType != null) { actionLogic = Activator.CreateInstance(actionLogicType) as IExecuteFlowAction; if (actionLogic != null) { actionLogic.ExecuteMasterCore(fromObject, toObject); } } #endregion #region 生成目标单据子表记录 var fromItems = fromObject.GetMemberValue("明细项目") as XPBaseCollection; var toItems = toObject.GetMemberValue("明细项目") as XPBaseCollection; var toItemType = toItems.GetObjectClassInfo().ClassType; //来源单据的明细,当前单据 var detailRecords = new List <Tuple <string, string> >(); foreach (XPBaseObject item in fromItems) { //查找记录? XPBaseObject toItem = null; if (action.目标类型 == 目标类型.更新单据) { //如果是更新单据(反写)时,没有找到反写目标明细,则继续。忽略当前条目。 //recs可以查到来源明细 // var recs = record.明细.FirstOrDefault(x => x.目标 == item.GetMemberValue("Oid").ToString()); toItem = (toObject.GetMemberValue("明细项目") as IList).OfType <BaseObject>().FirstOrDefault(x => x.Oid.ToString() == recs.来源); if (toItem == null) { continue; } } else if (action.目标类型 == 目标类型.生成单据) { toItem = newFormOs.CreateObject(toItemType) as XPBaseObject; } else { throw new Exception("未处理的目标类型!"); } toItems.BaseAdd(toItem); if (actionLogic != null) { actionLogic.ExecuteChildrenCore(item, toItem); } //foreach (var f in action.ItemsMapping) //{ // var fromValue = item.Evaluate(f.FromProperty.Name); // toItem.SetMemberValue(f.ToProperty.Name, fromValue); //} detailRecords.Add(new Tuple <string, string>(item.GetMemberValue("Oid").ToString(), toItem.GetMemberValue("Oid").ToString())); } #region 生成主表记录 EventHandler act = null; act = (snd, evt) => { newFormOs.Committed -= act; var process = ObjectSpace.CreateObject <单据流程状态记录>(); process.来源单据 = this.CurrentObject as 单据; process.目标单据 = this.ObjectSpace.GetObject(toObject); process.执行动作 = action; process.业务项目 = process.来源单据.业务项目; foreach (var item in detailRecords) { var det = ObjectSpace.CreateObject <单据流程记录明细>(); det.来源 = item.Item1; det.目标 = item.Item2; process.明细.Add(det); } ObjectSpace.CommitChanges(); }; newFormOs.Committed += act; #endregion #endregion if (action.自动保存) { newFormOs.CommitChanges(); } if (action.显示编辑界面) { var para = new ShowViewParameters(); para.CreatedView = Application.CreateDetailView(newFormOs, toObject, true); para.TargetWindow = TargetWindow.Default; Application.ShowViewStrategy.ShowView(para, new ShowViewSource(this.Frame, this.FlowToNext)); //e.ShowViewParameters.CreatedView = } }
/// <summary> /// Executes this OPathQuery against an ObjectSpace data store and returns the first matching object. /// Null is returned if no object is found. /// </summary> /// <param name="os">ObjectSpace instance to use.</param> /// <param name="parameters">Parameter values to use when executing the query.</param> /// <returns>The first object matching the query; or null if no match was found.</returns> public T GetObject(ObjectSpace os, params object[] parameters) { CompiledQuery <T> cq = this.Compile(os); return((T)os.GetObject(cq, parameters)); }
protected override void OnActivated() { base.OnActivated(); Employee curEmp = SecuritySystem.CurrentUser as Employee; if (SecuritySystem.CurrentUser != null) { curEmp = (Employee)ObjectSpace.GetObject(SecuritySystem.CurrentUser); } else if (SecuritySystem.CurrentUserId != null) { curEmp = ObjectSpace.FindObject <Employee>(new BinaryOperator("Oid", SecuritySystem.CurrentUserId)); } ///Hạn chế số lượng bản ghi trả về: /// - Chỉ người được phép có thể xem được văn bản /// - Dùng tốt hơn ở đây, để lọc ngay từ server //1. Messages - Filter tin nhắn if ((View is ListView) && View.ObjectTypeInfo != null && (View.ObjectTypeInfo.Type == typeof(Messages))) { if (SecuritySystem.CurrentUser != null || SecuritySystem.CurrentUserId != null) { ((ListView)View).CollectionSource.Criteria["FilterMessage"] = CriteriaOperator.Parse("[EmployeeReceiveds][[Oid] = CurrentEmployeeOid()] Or [EmployeeSend.Oid] = CurrentEmployeeOid()"); } } //2. Document - Filter Văn bản if ((View is ListView) && View.ObjectTypeInfo != null && (View.ObjectTypeInfo.Type == typeof(Document)) && View.IsRoot) { if ((SecuritySystem.CurrentUser != null || SecuritySystem.CurrentUserId != null) && SecuritySystem.CurrentUserName != "admin") { ((ListView)View).CollectionSource.Criteria["FilterDocument"] = CriteriaOperator.Parse("([DocumentEmployees][[LinkEmployee.Oid] = CurrentEmployeeOid() And [IsDirected]]) Or ([IsApproveed] And [DocumentEmployees][[LinkEmployee.Oid] = CurrentEmployeeOid()]) Or [EmployeeCreated.Oid] = CurrentEmployeeOid()"); //CriteriaOperator crit = new ContainsOperator("DocumentEmployees", CriteriaOperator.And( // new BinaryOperator(new OperandProperty("LinkEmployee"), new OperandValue(curEmp), BinaryOperatorType.Equal), // new BinaryOperator(new OperandProperty("IsDirected"), new OperandValue(true), BinaryOperatorType.Equal))); //((ListView)View).CollectionSource.Criteria["FilterDocument"] = crit; } } //3. TaskExtra - Filter Công việc if ((View is ListView) && View.ObjectTypeInfo != null && (View.ObjectTypeInfo.Type == typeof(TaskExtra))) { if ((SecuritySystem.CurrentUser != null || SecuritySystem.CurrentUserId != null) && SecuritySystem.CurrentUserName != "admin") { ((ListView)View).CollectionSource.Criteria["FilterTaskExtra"] = CriteriaOperator.Parse("[EmployeeReceiveds][[Oid] = CurrentEmployeeOid()] Or [EmployeeCreated.Oid] = CurrentEmployeeOid() Or [TaskAssignedTo.Oid] = CurrentEmployeeOid() Or CurrentEmployeeIsRoot()"); } } //4. Nestlist DepartmentReceived - Filter danh sách phòng ban theo quyền hạn hiện tại // a) Đối với Văn bản: Tổng Giám đốc, Giám đốc, Officer => ALL; Các Trưởng phòng cấp dưới => GĐ và các bộ phận thuộc Đơn vị, Nhân viên BT => trong phòng // b) Đối với Công việc (giao việc): theo quyền... if ((View is ListView) && (View.Id == "Document_DepartmentReceiveds_ListView") && (View.ObjectTypeInfo.Type == typeof(Department))) { ListView lv = View as ListView; //lv.CollectionSource.BeginUpdateCriteria(); lv.CollectionSource.Criteria["FilterDepartmentTree"] = CriteriaOperator.Parse("1 = 2"); if (SecuritySystem.CurrentUser != null || SecuritySystem.CurrentUserId != null) { if (curEmp != null && curEmp.Position != null && curEmp.Department != null) { //a) Giám đốc hoặc Văn thư, được gởi Văn bản toàn hệ thống if (curEmp.EmployeeRoles.FindIndex(x => x.Name == "Officer" || x.Name == "Director") > -1) { //lv.CollectionSource.Criteria["FilterDepartmentTree"] = CriteriaOperator.And(CriteriaOperator.Parse("1 = 1"), new BinaryOperator("HRType", "Employee", BinaryOperatorType.NotEqual)); lv.CollectionSource.Criteria["FilterDepartmentTree"] = CriteriaOperator.Parse("1 = 1"); } else { //b) Trưởng phòng/bộ phận: được gởi trong đơn vị => Department của TP, các Department cấp dưới (nhận Department này làm Parent) và các Department cùng cấp Cha Employee curLeader = curEmp.Department.getLeader(); if (curLeader != null && curEmp.Position != null && curLeader.Position != null && curEmp.Position.PositionLevel >= curLeader.Position.PositionLevel) { Department depTmp = curEmp.Department; if (curEmp.Department.ManagerDepartment != null) { depTmp = curEmp.Department.ManagerDepartment; } //BinaryOperator capDuoi = new BinaryOperator("ListManagerDepartmentOid", curEmp.Department.Oid.ToString(), BinaryOperatorType.Like); FunctionOperator subDepartments = new FunctionOperator(FunctionOperatorType.Contains, new OperandProperty("ListManagerDepartmentOid"), depTmp.Oid.ToString()); lv.CollectionSource.Criteria["FilterDepartmentTree"] = subDepartments; } //c) Nhân viên bình thường trong phòng => gởi trong phòng thôi else { FunctionOperator subDepartments = new FunctionOperator(FunctionOperatorType.Contains, new OperandProperty("ListManagerDepartmentOid"), curEmp.Department.Oid.ToString()); lv.CollectionSource.Criteria["FilterDepartmentTree"] = subDepartments; } } } } lv.CollectionSource.Sorting.Add(new DevExpress.Xpo.SortProperty("Position.PositionLevel", DevExpress.Xpo.DB.SortingDirection.Descending)); lv.RefreshDataSource(); //lv.CollectionSource.EndUpdateCriteria(); } }
protected override void OnSaving() { base.OnSaving(); OpenDate = DateTime.Now; OpenedBy = ObjectSpace.GetObject <WXafUser>((WXafUser)SecuritySystem.CurrentUser); }
public static AdvancedArticle GetAdvancedArticle(int id, bool isPublic) { ObjectSpace os = GetObjectSpace(isPublic); return((AdvancedArticle)os.GetObject(typeof(AdvancedArticle), id)); }
private void ComprobanteExportAndMailReportAction_Execute(object sender, SingleChoiceActionExecuteEventArgs e) { if (e.SelectedObjects.Count == 0) { return; } var rutaBase = RutaExpComprobantes; if (string.IsNullOrEmpty(rutaBase)) { throw new UserFriendlyException("No está definida la ruta para exportación de comprobantes"); } var cuentaEmail = Identificadores.GetInstance(ObjectSpace).CuentaEmailFacturacion; if (cuentaEmail == null) { throw new UserFriendlyException("No está definida la cuenta de mail para el envío de comprobantes"); } var plantillaMensaje = Identificadores.GetInstance(ObjectSpace).PlantillaMensajeFacturacion; var plantillaContenido = plantillaMensaje != null ? plantillaMensaje.Contenido : ""; foreach (Comprobante obj in e.SelectedObjects) { var criteria = (CriteriaOperator) new BinaryOperator(View.ObjectTypeInfo.KeyMember.Name, ObjectSpace.GetKeyValue(obj)); var reportData = ObjectSpace.GetObject(( IReportData )e.SelectedChoiceActionItem.Data); var rep = ( XafReport )reportData.LoadReport(ObjectSpace); rep.SetFilteringObject(new LocalizedCriteriaWrapper(View.ObjectTypeInfo.Type, criteria)); var ruta = expandFilename(obj, rutaBase); var fileName = Path.GetFileName(ruta); var ms = new MemoryStream( ); rep.ExportToPdf(ms); var mail = new MailMessage( ); mail.Attachments.Add(new Attachment(ms, fileName, "application/pdf")); var cliente = ObjectSpace.FindObject <Cliente>(new BinaryOperator("Persona.Oid", obj.Destinatario.Oid)); if (cliente == null) { return; } var destinatario = cliente.EmailEnvioFacturacion; if (destinatario == null) { continue; } mail.From = new MailAddress(cuentaEmail.DireccionEmail, cuentaEmail.NombreMostrar); mail.To.Add(new MailAddress(destinatario.Valor, cliente.Persona.Nombre)); mail.CC.Add(new MailAddress("*****@*****.**", "Info (Facturacion)")); mail.Subject = fileName; mail.Body = plantillaContenido; mail.IsBodyHtml = true; cuentaEmail.SendMail(mail); } }
protected User GetUserFromToken() { var data = GetTokenData(); return(os.GetObject <User>(data.ID)); }
public override IList GetSelectedObjects() { SelectedObjects = SelectedObjects.Select(f => ObjectSpace.GetObject(f)).ToList(); return(SelectedObjects as IList); }
private void CreateScoreAction_Execute(object sender, PopupWindowShowActionExecuteEventArgs e) { EventScore newScore = new EventScore(((XPObjectSpace)ObjectSpace).Session); EnterEventScores enterEventScores = (EnterEventScores)e.PopupWindowViewCurrentObject; DecathalonEvent selectedEvent = enterEventScores.Event; string expression = selectedEvent.Definition.ScoringParameterGroups.Count > 1 ? "(" : ""; // TODO: Get Parameter values if (selectedEvent.Definition.ScoringParameterGroups.Count == 1 && selectedEvent.Definition.ScoringParameterGroups[0].ScoringParameters.Count == 1) { // Only one parameter expression += enterEventScores.ScoreParameters[0].Value; } else if (selectedEvent.Definition.ScoringParameterGroups.Count > 0) { foreach (var paramGroup in selectedEvent.Definition.ScoringParameterGroups.OrderBy(p => p.SequenceNumber)) { expression += "("; foreach (var param in paramGroup.ScoringParameters.OrderBy(p => p.SequenceNumber)) { if (param.Value == 0) { double doubleValue = enterEventScores.ScoreParameters.Where(p => p.Sequence == param.SequenceNumber && p.Group == paramGroup.SequenceNumber).FirstOrDefault().Value; if (param.SequenceNumber == 1) { if (param.OperatorString != "") { expression += doubleValue + " " + param.OperatorString; } else { expression += doubleValue; } } else if (param.SequenceNumber == paramGroup.ScoringParameters.Count) { expression += " " + doubleValue; } else { expression += " " + doubleValue + " " + param.OperatorString; } } else { if (param.SequenceNumber == 1) { if (param.OperatorString != "") { expression += param.Value + " " + param.OperatorString; } else { expression += param.Value; } } else if (param.SequenceNumber == paramGroup.ScoringParameters.Count) { expression += " " + param.Value; } else { expression += " " + param.Value + " " + param.OperatorString; } } } expression += ") " + paramGroup.OperatorString; } } expression += selectedEvent.Definition.ScoringParameterGroups.Count > 1 ? ")" : ""; // TODO: Set and show Points and save Score var dt = new DataTable(); double points = 0; string resultString = dt.Compute(expression, "").ToString(); double.TryParse(resultString, out points); newScore.Competitor = ObjectSpace.GetObject(enterEventScores.Competitor); newScore.Event = ObjectSpace.GetObject(selectedEvent); newScore.SetPoints(points); newScore.Notes += Environment.NewLine + "Calculated as: " + expression; ObjectSpace.CommitChanges(); }
public virtual void Export(object selectedObject) { var exportEngine = new ExportEngine(); var document = exportEngine.Export(View.SelectedObjects.OfType <XPBaseObject>(), ObjectSpace.GetObject((ISerializationConfigurationGroup)selectedObject)); Save(document); }
public void ProccesExcellRows(IEnumerable records, ObjectSpace objectSpace, DoWorkEventArgs e) { var i = 0; //for every row in excell sheet foreach (Row record in records) { ++i; if (i == 1) continue; if (_BgWorker.CancellationPending) { e.Cancel = true; break; } //var os = new ObjectSpace(objectSpace, XafTypesInfo.Instance); object newObj = null; //chech if row contains Oid //get key property name of the object type being imported var kp = objectSpace.GetKeyPropertyName(Type); //check if it exists in excel and is mapped ? var idMapping = ImportMap.Mappings.Where(p => p.MapedTo == kp).FirstOrDefault(); if (idMapping != null && GetQString(record[idMapping.Column].Value) != string.Empty) { try { //find existing object var val = record[idMapping.Column]; var gwid = new Guid(GetQString(val.Value)); newObj = objectSpace.FindObject(Type, new BinaryOperator(kp, gwid), true); } catch { } } if (newObj == null) //create a new instance newObj = objectSpace.CreateObject(Type) as IXPSimpleObject; string message; if (newObj != null) { var props = ((IXPSimpleObject)newObj).ClassInfo.PersistentProperties .OfType<XPMemberInfo>(); foreach (var mapping in ImportMap.Mappings) { if (_BgWorker.CancellationPending) { e.Cancel = true; break; } Application.DoEvents(); var mapping1 = mapping; var prop = props.Where(p => p.Name == mapping1.MapedTo).FirstOrDefault(); try { var val = record[mapping.Column]; // continue; if (val != null) { //if simple property if (prop.ReferenceType == null) { var isNullable = prop.MemberType.IsGenericType && prop.MemberType.GetGenericTypeDefinition() == typeof(Nullable<>); object convertedValue = null; if (prop.MemberType == null) return; if (isNullable) { if (prop.StorageType == typeof(int)) { int number; var rez = Int32.TryParse(val.Value, out number); if (rez) convertedValue = number; } else if (prop.StorageType == typeof(DateTime)) { if (val.Value != string.Empty) { //Include validate var dt = DateTime.FromOADate(Convert.ToDouble(val.Value)); convertedValue = dt; } } else if (prop.StorageType == typeof(double)) { double number; var rez = Double.TryParse(val.Value, out number); if (rez) convertedValue = number; } } else { if (prop.MemberType == typeof(char)) convertedValue = Convert.ChangeType(GetQString(val.Value), prop.MemberType); else if (prop.MemberType == typeof(Guid)) convertedValue = new Guid(GetQString(val.Value)); else if (prop.StorageType == typeof(DateTime)) { if (val.Value != string.Empty) { //Include validate var dt = DateTime.FromOADate(Convert.ToDouble(val.Value)); convertedValue = dt; } } else if (prop.MemberType == typeof(double)) { double number; // Application.CurrentCulture.NumberFormat.NumberDecimalSeparator = "."; var rez = Double.TryParse(val.Value, NumberStyles.Number, new NumberFormatInfo { NumberDecimalSeparator = "." }, out number); if (rez) convertedValue = number; } else if (prop.MemberType == typeof(bool)) { if (val.Value != string.Empty && (val.Value.Length == 1 || val.Value.ToLower() == "true" || val.Value.ToLower() == "false")) { bool truefalse; if (val.Value.ToLower() == "true" || val.Value.ToLower() == "false") truefalse = Convert.ToBoolean(val.Value); else truefalse = Convert.ToBoolean(Convert.ToInt32(val.Value)); convertedValue = truefalse; } } else convertedValue = Convert.ChangeType(val.Value, prop.MemberType); } if (convertedValue != null) { if (convertedValue.GetType() == typeof(double)) convertedValue = Math.Round((double)convertedValue, 2, MidpointRounding.ToEven); prop.SetValue(newObj, convertedValue); } } //if referenced property if (prop.ReferenceType != null) { //if other referenced type if (prop.MemberType.IsSubclassOf(typeof(XPBaseObject))) { var text = val.Value; var typ = prop.MemberType; var mval = ImportWizard.Helper.GetXpObjectByKeyValue(objectSpace, text, typ); prop.SetValue(newObj, objectSpace.GetObject(mval)); } } } } catch (Exception E) { message = string.Format("Error processing record {0}. {1}", i, E); _BgWorker.ReportProgress(0, message); } if (CurrentCollectionSource != null) AddNewObjectToCollectionSource(CurrentCollectionSource, newObj, ObjectSpace); ObjectSpace.Session.Save(newObj); } } objectSpace.CommitChanges(); message = string.Format("Importing record {0} succesfull.", i); _BgWorker.ReportProgress(1, message); Application.DoEvents(); } }