Exemplo n.º 1
0
        IPersistentMemberInfo CreateMember(Column column, IPersistentClassInfo owner, TemplateType templateType)
        {
            var        columnName = column.Name;
            ForeignKey foreignKey = _foreignKeyCalculator.GetForeignKey(column);

            if (column.IsForeignKey && owner.CodeTemplateInfo.CodeTemplate.TemplateType != TemplateType.Struct && _foreignKeyCalculator.IsOneToOne(foreignKey, columnName))
            {
                templateType = TemplateType.XPOneToOnePropertyMember;
            }
            else if (foreignKey != null && foreignKey.Columns.Count > 1)
            {
                columnName = foreignKey.ReferencedTable;
            }
            if (_objectSpace.FindObject <IPersistentMemberInfo>(info => info.Name == columnName && info.Owner == owner, PersistentCriteriaEvaluationBehavior.InTransaction) != null)
            {
                return(null);
            }
            if (!(column.IsForeignKey))
            {
                return(CreatePersistentCoreTypeMemberInfo(column, owner, templateType));
            }
            if (foreignKey != null)
            {
                IPersistentClassInfo referenceClassInfo = GetReferenceClassInfo(foreignKey.ReferencedTable);
                var persistentReferenceMemberInfo       = CreatePersistentReferenceMemberInfo(columnName, owner, referenceClassInfo, templateType);
                return(persistentReferenceMemberInfo);
            }
            throw new NotImplementedException(column.Name + " " + ((Table)column.Parent).Name);
        }
Exemplo n.º 2
0
        ModelDifferenceObject CreateDifferenceObject(string resourceName, string prefix)
        {
            ModelDifferenceObject modelDifferenceObject;

            if (prefix == XpoModelDictionaryDifferenceStore.ModelApplicationPrefix)
            {
                modelDifferenceObject = new ModelDifferenceObject(_objectSpace.Session);
            }
            else
            {
                modelDifferenceObject = new RoleModelDifferenceObject(_objectSpace.Session);
                Type   roleType = ((IRoleTypeProvider)SecuritySystem.Instance).RoleType;
                var    criteriaParametersList = resourceName.Substring(0, resourceName.IndexOf("_", StringComparison.Ordinal));
                object findObject             = _objectSpace.FindObject(roleType, CriteriaOperator.Parse("Name=?", criteriaParametersList));
                Guard.ArgumentNotNull(findObject, criteriaParametersList);
                var xpBaseCollection = ((XPBaseCollection)modelDifferenceObject.GetMemberValue("Roles"));
                xpBaseCollection.BaseAdd(findObject);
            }
            var applicationTitle = _xafApplication.Title;
            var title            = ((IModelOptionsModelDifference)_xafApplication.Model.Options).ApplicationTitle;

            if (!string.IsNullOrEmpty(title))
            {
                applicationTitle = title;
            }
            modelDifferenceObject.InitializeMembers(resourceName, applicationTitle, _xafApplication.GetType().FullName);
            return(modelDifferenceObject);
        }
Exemplo n.º 3
0
        public static XPBaseObject GetXpObjectByKeyValue(XPObjectSpace oSpace, string value, Type type)
        {
            if (string.IsNullOrEmpty(value))
            {
                return(null);
            }

            if (!type.IsSubclassOf(typeof(XPBaseObject)))
            {
                return(null);
            }

            var    defaultMember = GetDefaultMember(type);
            object result;

            value.TryToChange(defaultMember.MemberType, out result);
            var criteriaOperator = GetDefaultCriteria(defaultMember, result);
            var item             = (XPBaseObject)oSpace.FindObject(type, criteriaOperator, true);

            if (item != null)
            {
                return(item);
            }

            var nestedObjectSpace = oSpace.CreateNestedObjectSpace();

            item = (XPBaseObject)nestedObjectSpace.CreateObject(type);
            defaultMember.SetValue(item, value);

            item.Save();
            nestedObjectSpace.CommitChanges();

            return(oSpace.GetObject(item));
        }
Exemplo n.º 4
0
        public static XPBaseObject GetXpObjectByKeyValue(XPObjectSpace oSpace, string value, Type type) {
            if (string.IsNullOrEmpty(value))
                return null;

            if (!type.IsSubclassOf(typeof(XPBaseObject)))
                return null;

            var defaultMember = GetDefaultMember(type);
            object result;
            value.TryToChange(defaultMember.MemberType, out result);
            var criteriaOperator = GetDefaultCriteria(defaultMember, result);
            var item = (XPBaseObject)oSpace.FindObject(type,criteriaOperator,true);
            if (item != null)
                return item;

            var nestedObjectSpace = oSpace.CreateNestedObjectSpace();
            item = (XPBaseObject)nestedObjectSpace.CreateObject(type);
            defaultMember.SetValue(item, value);

            item.Save();
            nestedObjectSpace.CommitChanges();

            return oSpace.GetObject(item);

        }
Exemplo n.º 5
0
        public static T FindObject <T>(this XPObjectSpace objectSpace, Expression <Func <T, bool> > expression, PersistentCriteriaEvaluationBehavior persistentCriteriaEvaluationBehavior)
        {
            var objectType = XafTypesInfo.Instance.FindBussinessObjectType <T>();
            CriteriaOperator criteriaOperator = GetCriteriaOperator(objectType, expression, objectSpace);
            bool             inTransaction    = persistentCriteriaEvaluationBehavior == PersistentCriteriaEvaluationBehavior.InTransaction;

            return((T)objectSpace.FindObject(objectType, criteriaOperator, inTransaction));
        }
Exemplo n.º 6
0
        private object CreateObject(TeamEmployeeDisplay Item, object CurrentObjectValue)
        {
            object obj = null;

            obj = _ObjectSpace.CreateObject(MemberInfo.ListElementTypeInfo.Type);

            if (Item.Employee != null)
            {
                obj.SetPropertyValue("Employee", _ObjectSpace.FindObject <Employee>(new BinaryOperator("Oid", Item.ID)));
            }
            else
            {
                obj.SetPropertyValue("Team", _ObjectSpace.FindObject <Team>(new BinaryOperator("Oid", Item.ID)));
            }

            obj.SetPropertyValue(CurrentObject.GetType().BaseType.Name, _ObjectSpace.FindObject(CurrentObject.GetType(), new BinaryOperator("Oid", ((BaseObject)CurrentObject).Oid)));

            return(obj);
        }
Exemplo n.º 7
0
/*
 * DECLARE @ShhotPairOid uniqueidentifier = (SELECT TOP 1 CashSnapshotReported FROM SetOfBooks WHERE GCRecord IS NULL)
 * DECLARE @PrevShhotOid uniqueidentifier = (
 *      SELECT TOP 1 PreviousSnapshot
 *      FROM CashSnapshotReported
 *      WHERE GCRecord IS NULL AND OId = @ShhotPairOid)
 *
 * SELECT @PrevShhotOid
 */
        public static CashFlowSnapshot GetPreviousSnapshot(XPObjectSpace objSpace)
        {
            var book = objSpace.FindObject <SetOfBooks>(null);

            if (book == null || book.CashSnapshotReported == null)
            {
                return(null);
            }
            return(book.CashSnapshotReported.PreviousSnapshot);
        }
Exemplo n.º 8
0
        public static XPBaseObject GetXpObjectByKeyValue(XPObjectSpace 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);
            var firstOrDefault = item.ClassInfo
                                 .PersistentProperties
                                 .OfType <XPMemberInfo>()
                                 .FirstOrDefault(p => p.Name == keyPropertyName);

            if (firstOrDefault != null)
            {
                firstOrDefault.SetValue(item, value);
            }

            item.Save();
            nestedObjectSpace.CommitChanges();

            return(oSpace.GetObject(item));
        }
Exemplo n.º 9
0
        public FixCashFlowsAlgorithm(XPObjectSpace objSpace, CashFlowFixParam paramObj, CashFlowFixMapper mapper)
        {
            this.objSpace = objSpace;
            this.paramObj = paramObj;

            if (paramObj.Snapshot == null)
            {
                currentSnapshot = GetCurrentSnapshot(objSpace.Session);
            }
            else
            {
                currentSnapshot = paramObj.Snapshot;
            }

            if (paramObj.ApReclassActivity != null)
            {
                paramApReclassActivity = objSpace.GetObjectByKey <Activity>(objSpace.GetKeyValue(paramObj.ApReclassActivity));
            }

            defaultCounterparty = objSpace.FindObject <Counterparty>(
                CriteriaOperator.Parse("Name LIKE ?", CashDiscipline.Common.Constants.DefaultFixCounterparty));

            var query = new XPQuery <CashForecastFixTag>(objSpace.Session);

            reversalFixTag = query
                             .Where(x => x.Name == CashDiscipline.Common.Constants.ReversalFixTag).FirstOrDefault();

            revRecFixTag = query
                           .Where(x => x.Name == CashDiscipline.Common.Constants.RevRecFixTag).FirstOrDefault();

            resRevRecFixTag = query
                              .Where(x => x.Name == CashDiscipline.Common.Constants.ResRevRecFixTag).FirstOrDefault();

            payrollFixTag = query
                            .Where(x => x.Name == CashDiscipline.Common.Constants.PayrollFixTag).FirstOrDefault();

            autoFixTag = query
                         .Where(x => x.Name == CashDiscipline.Common.Constants.AutoFixTag).FirstOrDefault();

            setOfBooks  = SetOfBooks.GetInstance(objSpace);
            this.mapper = mapper;

            this.sqlDeclareClauses = CreateSqlDeclareClauses();
            var sqlStringUtil = new SqlStringUtil();

            this.parameterCommandText = sqlStringUtil.CreateCommandText(sqlDeclareClauses);
        }
Exemplo n.º 10
0
 public void CreateObjects()
 {
     foreach (var typeInfo in XafTypesInfo.Instance.PersistentTypes.Where(info => typeof(ICustomer).IsAssignableFrom(info.Type)))
     {
         if (!typeInfo.IsPersistent || _objectSpace.FindObject(typeInfo.Type, null) != null)
         {
             continue;
         }
         var dummyDataAttribute = typeInfo.FindAttribute <DummyDataAttribute>();
         if (dummyDataAttribute != null && dummyDataAttribute.Exclude)
         {
             continue;
         }
         CreateObjects(typeInfo);
     }
     _objectSpace.CommitChanges();
 }
Exemplo n.º 11
0
        public static XPBaseObject GetXpObjectByKeyValue(XPObjectSpace 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);
            var firstOrDefault = item.ClassInfo
                                    .PersistentProperties
                                    .OfType<XPMemberInfo>()
                                    .FirstOrDefault(p => p.Name == keyPropertyName);
            if (firstOrDefault != null)
                firstOrDefault.SetValue(item, value);

            item.Save();
            nestedObjectSpace.CommitChanges();

            return oSpace.GetObject(item);

        }
Exemplo n.º 12
0
        private IXPSimpleObject GetExistingOrCreateNewObject(XPObjectSpace objectSpace, string keyPropertyName,
                                                             Row excelRow, Type type)
        {
            Mapping         idMapping = ImportMap.Mappings.SingleOrDefault(p => p.MapedTo == keyPropertyName);
            IXPSimpleObject newObj    = null;

            if (idMapping != null && ImportUtils.GetQString(excelRow[idMapping.Column].Value) != string.Empty)
            {
                try{
                    //find existing object
                    Cell val  = excelRow[idMapping.Column];
                    var  gwid = new Guid(ImportUtils.GetQString(val.Value));
                    newObj =
                        objectSpace.FindObject(type, new BinaryOperator(keyPropertyName, gwid), true) as IXPSimpleObject;
                }
                catch {
                }
            }
            return(newObj ?? (objectSpace.CreateObject(type) as IXPSimpleObject));
        }
Exemplo n.º 13
0
        private void ImprFto(string format, bool imprime, bool pdf, string nameF)
        {
            if (View != null && View.ObjectSpace != null)
            {
                XPObjectSpace objectSpace = (XPObjectSpace)View.ObjectSpace;
                NominaItem    fac         = View.CurrentObject as NominaItem;
                if (fac != null)
                {
                    Session uow = fac.Session;
                    //ReportData reportData = uow.FindObject<ReportData>(new BinaryOperator("Name", format));
                    // XPCollection dosyas = new XPCollection(fac.Session, typeof(NominaItem), false);
                    //XafReport report = null;
                    NominaItem doc = fac;

                    IReportDataV2 reportData2 = objectSpace.FindObject <ReportDataV2>(
                        new BinaryOperator("DisplayName", format));

                    if (doc != null)
                    {
                        doc.Empresa = uow.FindObject <Empresa>(/*CriteriaOperator.Parse("Clave = 'icpac'")*/ null);

                        if (doc.Status == NominaItemStatus.Alta)
                        {
                            if (doc.Empleado != null)
                            {
                                doc.Empleado.Reload();
                            }
                        }

                        QRCode2(doc);

                        /*
                         * if (reportData != null)
                         * {
                         *  report = reportData.LoadReport(objectSpace) as XafReport;
                         *  report.ObjectSpace = objectSpace;
                         *  dosyas.Add(doc);
                         *  report.DataSource = dosyas;
                         *
                         *  if (pdf)
                         *  {
                         *      report.ExportToPdf(nameF);
                         *  }
                         *  if (imprime)
                         *  {
                         *      try
                         *      {
                         *          ReportPrintTool printTool = new ReportPrintTool(report);
                         *
                         *          // Solo funciona para windows !!
                         *          printTool.ShowPreviewDialog();
                         *      }
                         *      catch (Exception)
                         *      {
                         *      }
                         *  }
                         * }*/

                        if (reportData2 != null)
                        {
                            string reportContainerHandler =
                                ReportDataProvider.ReportsStorage.GetReportContainerHandle(reportData2);

                            XtraReport report2 = ReportDataProvider.ReportsStorage.LoadReport(reportData2);

                            List <NominaItem> list = new List <NominaItem>();
                            list.Add(doc);

                            report2.DataSource = list;

                            if (pdf)
                            {
                                string namF = NegocioNom.NamePdf(doc);

                                DEFile       fd = new DEFile(doc.Session);
                                MemoryStream ms = new MemoryStream();

                                report2.ExportToPdf(ms);
                                ms.Seek(0, SeekOrigin.Begin);

                                fd.File = new FileData(doc.Session);
                                fd.File.LoadFromStream(Path.GetFileName(namF), ms);
                                fd.TpArchv = ETipoArchivo.Pdf;

                                doc.DElctrnc.Archivos.Add(fd);
                            }
                            if (imprime)
                            {
                                try
                                {
                                    ReportsModuleV2.FindReportsModule(Application.Modules).ReportsDataSourceHelper.SetupBeforePrint(report2);

                                    report2.ShowPreview();
                                }
                                catch (Exception)
                                {
                                }
                            }
                        }

                        // dosyas.Dispose();
                    }
                }
            }
        }
 private IXPSimpleObject GetExistingOrCreateNewObject(XPObjectSpace objectSpace, string keyPropertyName,
     Row excelRow, Type type){
     Mapping idMapping = ImportMap.Mappings.SingleOrDefault(p => p.MapedTo == keyPropertyName);
     IXPSimpleObject newObj = null;
     if (idMapping != null && ImportUtils.GetQString(excelRow[idMapping.Column].Value) != string.Empty){
         try{
             //find existing object
             Cell val = excelRow[idMapping.Column];
             var gwid = new Guid(ImportUtils.GetQString(val.Value));
             newObj =
                 objectSpace.FindObject(type, new BinaryOperator(keyPropertyName, gwid), true) as IXPSimpleObject;
         }
         catch{
         }
     }
     return newObj ?? (objectSpace.CreateObject(type) as IXPSimpleObject);
 }
Exemplo n.º 15
0
        public void ProccesExcellRows(IEnumerable records, XPObjectSpace 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.FirstOrDefault(p => p.MapedTo == kp);
                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>().ToList();


                    foreach (var mapping in ImportMap.Mappings) {
                        if (_BgWorker.CancellationPending) { e.Cancel = true; break; }
                        Application.DoEvents();

                        var mapping1 = mapping;
                        var prop = props.FirstOrDefault(p => p.Name == mapping1.MapedTo);

                        try {
                            var val = record[mapping.Column];
                            // continue;

                            if (val != null) {
                                //if simple property
                                if (prop.ReferenceType == null && !prop.MemberType.IsEnum) {
                                    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;
                                            if (val.Value != String.Empty && Int32.TryParse(val.Value, out number))
                                                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.IsEnum) {
                                            prop.SetValue(newObj, Enum.Parse(prop.MemberType, val.Value));
                                        } else if (prop.MemberType == typeof(char))
                                            convertedValue = Convert.ChangeType(GetQString(val.Value), prop.MemberType);
                                        else if (prop.StorageType == typeof(int)) {
                                            int number;
                                            if (val.Value != String.Empty && Int32.TryParse(val.Value, out number))
                                                convertedValue = number;
                                            else
                                                convertedValue = 0;
                                        } 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 is 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 ee) {
                            message = string.Format(Resources.ExcelImportWizard_ProccesExcellRows_Error_processing_record__0____1_, i - 1, ee);
                            _BgWorker.ReportProgress(0, message);
                        }

                        if (CurrentCollectionSource != null)
                            AddNewObjectToCollectionSource(CurrentCollectionSource, newObj, ObjectSpace);
                        ObjectSpace.Session.Save(newObj);
                    }
                }

                objectSpace.CommitChanges();
                message = string.Format(Resources.ExcelImportWizard_ProccesExcellRows_Importing_record__0__succesfull_, i - 1);
                _BgWorker.ReportProgress(1, message);
                Application.DoEvents();
            }
        }
Exemplo n.º 16
0
        private void singleChoiceActionPolz_Execute(object sender, DevExpress.ExpressApp.Actions.SingleChoiceActionExecuteEventArgs e)
        {
            XPObjectSpace objectSpace = (XPObjectSpace)View.ObjectSpace;
            int           mes         = Convert.ToInt32((e.SelectedChoiceActionItem.Data));
            int           ano         = mes == 12 && DateTime.Today.Month == 1 ? DateTime.Today.Year - 1 : DateTime.Today.Year;
            DateTime      mFechaIni   = apl.Log.Fecha.FechaInicial(mes, ano);
            DateTime      mFechaFin   = apl.Log.Fecha.FechaFinal(mes, ano);

            CriteriaOperator[] operands = new CriteriaOperator[2];
            XmlDocument        docXml   = new XmlDocument();
            Ventas             vta      = objectSpace.FindObject <Ventas>(null);

            operands[0] = GroupOperator.And(new BinaryOperator("FechaDoc", mFechaIni, BinaryOperatorType.GreaterOrEqual), new BinaryOperator("FechaDoc", mFechaFin, BinaryOperatorType.LessOrEqual));
            operands[1] = new BinaryOperator("Status", DocumentoStatus.Cancelado, BinaryOperatorType.NotEqual);

            SortProperty [] sortCollection = new SortProperty[1];
            sortCollection[0] = new SortProperty("FechaDoc", SortingDirection.Ascending);

            IList arr = objectSpace.CreateCollection(typeof(DocumentoSalida), new GroupOperator(operands), sortCollection);

            if (arr.Count > 0)
            {
                string filename = string.Format("{0}.POL", mFechaIni.Month);
                using (new apl.Log.CWaitCursor())
                {
                    XmlDeclaration declaracion = docXml.CreateXmlDeclaration("1.0", null, "yes");
                    docXml.InsertBefore(declaracion, docXml.DocumentElement);
                    // docXml.LoadXml("<?xml version=\"1.0\" standalone=\"yes\"?>");
                    XmlElement data = docXml.CreateElement("DATAPACKET");
                    data.SetAttribute("Version", "2.0");
                    docXml.AppendChild(data);

                    XmlElement meta = docXml.CreateElement("METADATA");
                    data.AppendChild(meta);

                    XmlElement fields = docXml.CreateElement("FIELDS");
                    meta.AppendChild(fields);

                    XmlElement field = docXml.CreateElement("FIELD");
                    field.SetAttribute("attrname", "VersionCOI");
                    field.SetAttribute("fieldtype", "i2");
                    fields.AppendChild(field);

                    field = docXml.CreateElement("FIELD");
                    field.SetAttribute("attrname", "TipoPoliz");
                    field.SetAttribute("fieldtype", "string");
                    field.SetAttribute("WIDTH", "2");
                    fields.AppendChild(field);

                    field = docXml.CreateElement("FIELD");
                    field.SetAttribute("attrname", "DiaPoliz");
                    field.SetAttribute("fieldtype", "string");
                    field.SetAttribute("WIDTH", "2");
                    fields.AppendChild(field);

                    field = docXml.CreateElement("FIELD");
                    field.SetAttribute("attrname", "ConcepPoliz");
                    field.SetAttribute("fieldtype", "string");
                    field.SetAttribute("WIDTH", "120");
                    fields.AppendChild(field);

                    XmlElement fieldP = docXml.CreateElement("FIELD");
                    fieldP.SetAttribute("attrname", "Partidas");
                    fieldP.SetAttribute("fieldtype", "nested");
                    fields.AppendChild(fieldP);

                    XmlElement fields2 = docXml.CreateElement("FIELDS");
                    fieldP.AppendChild(fields2);

                    field = docXml.CreateElement("FIELD");
                    field.SetAttribute("attrname", "Cuenta");
                    field.SetAttribute("fieldtype", "string");
                    field.SetAttribute("WIDTH", "21");
                    fields2.AppendChild(field);

                    field = docXml.CreateElement("FIELD");
                    field.SetAttribute("attrname", "Depto");
                    field.SetAttribute("fieldtype", "i4");
                    fields2.AppendChild(field);

                    field = docXml.CreateElement("FIELD");
                    field.SetAttribute("attrname", "ConceptoPol");
                    field.SetAttribute("fieldtype", "string");
                    field.SetAttribute("WIDTH", "120");
                    fields2.AppendChild(field);

                    field = docXml.CreateElement("FIELD");
                    field.SetAttribute("attrname", "Monto");
                    field.SetAttribute("fieldtype", "r8");
                    fields2.AppendChild(field);

                    field = docXml.CreateElement("FIELD");
                    field.SetAttribute("attrname", "TipoCambio");
                    field.SetAttribute("fieldtype", "r8");
                    fields2.AppendChild(field);

                    field = docXml.CreateElement("FIELD");
                    field.SetAttribute("attrname", "DebeHaber");
                    field.SetAttribute("fieldtype", "string");
                    field.SetAttribute("WIDTH", "1");
                    fields2.AppendChild(field);


                    XmlElement parm = docXml.CreateElement("PARAMS");
                    fieldP.AppendChild(parm);

                    XmlElement parm1 = docXml.CreateElement("PARAMS");
                    meta.AppendChild(parm1);

                    XmlElement rowd = docXml.CreateElement("ROWDATA");
                    data.AppendChild(rowd);

                    XmlElement row = docXml.CreateElement("ROW");
                    row.SetAttribute("VersionCOI", "50");
                    row.SetAttribute("TipoPoliz", "Dr");
                    row.SetAttribute("DiaPoliz", string.Format("{0}", arr.Count + 1));
                    row.SetAttribute("ConcepPoliz", string.Format("RELACION DE FACTURAS DE {0} {1}", mFechaIni.ToString("MMMM").ToUpper(), mFechaIni.ToString("yyyy")));
                    rowd.AppendChild(row);

                    XmlElement par = docXml.CreateElement("Partidas");
                    row.AppendChild(par);

                    decimal  tot = 0;
                    string[] nivs;
                    string   aux = string.Empty;

                    foreach (DocumentoSalida doc in arr)
                    {
                        XmlElement part = docXml.CreateElement("ROWPartidas");
                        nivs = string.IsNullOrEmpty(doc.Cliente.Cuenta) ? null : doc.Cliente.Cuenta.Split('-');
                        if (nivs != null)
                        {
                            aux = string.Concat(nivs);
                        }

                        part.SetAttribute("Cuenta", string.Format("{0}2", aux.PadRight(20, '0')));
                        part.SetAttribute("Depto", "0");

                        aux = string.Format("F-{0}  {1}", doc.Clave.Trim(), ((PartidaSalida)(doc.VentaItems[0])).Descripcion);
                        part.SetAttribute("ConceptoPol", aux.Length > 120 ? aux.Substring(0, 119) : aux);
                        part.SetAttribute("Monto", doc.Total.ToString("F2"));
                        part.SetAttribute("TipoCambio", "1");
                        part.SetAttribute("DebeHaber", "D");
                        par.AppendChild(part);

                        tot += doc.Total;
                    }

                    XmlElement parth = docXml.CreateElement("ROWPartidas");

                    nivs = string.IsNullOrEmpty(vta.Cuenta) ? null : vta.Cuenta.Split('-');
                    if (nivs != null)
                    {
                        aux = string.Concat(nivs);
                    }

                    parth.SetAttribute("Cuenta", string.Format("{0}2", aux.PadRight(20, '0')));
                    parth.SetAttribute("Depto", "0");
                    parth.SetAttribute("ConceptoPol", string.Format("RELACION DE FACTURAS DE {0} {1}", mFechaIni.ToString("MMMM").ToUpper(), mFechaIni.ToString("yyyy")));
                    parth.SetAttribute("Monto", tot.ToString("F2"));
                    parth.SetAttribute("TipoCambio", "1");
                    parth.SetAttribute("DebeHaber", "H");
                    par.AppendChild(parth);

                    docXml.Save(filename);
                }
            }
        }
Exemplo n.º 17
0
        public void ProccesExcellRows(IEnumerable records, XPObjectSpace 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.FirstOrDefault(p => p.MapedTo == kp);
                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>().ToList();


                    foreach (var mapping in ImportMap.Mappings)
                    {
                        if (_BgWorker.CancellationPending)
                        {
                            e.Cancel = true; break;
                        }
                        Application.DoEvents();

                        var mapping1 = mapping;
                        var prop     = props.FirstOrDefault(p => p.Name == mapping1.MapedTo);

                        try {
                            var val = record[mapping.Column];
                            // continue;

                            if (val != null)
                            {
                                //if simple property
                                if (prop.ReferenceType == null && !prop.MemberType.IsEnum)
                                {
                                    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;
                                            if (val.Value != String.Empty && Int32.TryParse(val.Value, out number))
                                            {
                                                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.IsEnum)
                                        {
                                            prop.SetValue(newObj, Enum.Parse(prop.MemberType, val.Value));
                                        }
                                        else if (prop.MemberType == typeof(char))
                                        {
                                            convertedValue = Convert.ChangeType(GetQString(val.Value), prop.MemberType);
                                        }
                                        else if (prop.StorageType == typeof(int))
                                        {
                                            int number;
                                            if (val.Value != String.Empty && Int32.TryParse(val.Value, out number))
                                            {
                                                convertedValue = number;
                                            }
                                            else
                                            {
                                                convertedValue = 0;
                                            }
                                        }
                                        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 is 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 ee) {
                            message = string.Format(Resources.ExcelImportWizard_ProccesExcellRows_Error_processing_record__0____1_, i - 1, ee);
                            _BgWorker.ReportProgress(0, message);
                        }

                        if (CurrentCollectionSource != null)
                        {
                            AddNewObjectToCollectionSource(CurrentCollectionSource, newObj, ObjectSpace);
                        }
                        ObjectSpace.Session.Save(newObj);
                    }
                }

                objectSpace.CommitChanges();
                message = string.Format(Resources.ExcelImportWizard_ProccesExcellRows_Importing_record__0__succesfull_, i - 1);
                _BgWorker.ReportProgress(1, message);
                Application.DoEvents();
            }
        }