public static bool NeedReload(this XPObjectSpace objectSpace, object currentObject) { XPMemberInfo optimisticLockFieldInfo; XPClassInfo classInfo = GetClassInfo(objectSpace, currentObject, out optimisticLockFieldInfo); Boolean isObjectChangedByAnotherUser = false; if (!objectSpace.IsDisposedObject(currentObject) && !objectSpace.IsNewObject(currentObject) && (optimisticLockFieldInfo != null)) { Object keyPropertyValue = objectSpace.GetKeyValue(currentObject); Object lockFieldValue = optimisticLockFieldInfo.GetValue(currentObject); if (lockFieldValue != null) { if (objectSpace.Session.FindObject(currentObject.GetType(), new GroupOperator( new BinaryOperator(objectSpace.GetKeyPropertyName(currentObject.GetType()), keyPropertyValue), new BinaryOperator(classInfo.OptimisticLockFieldName, lockFieldValue)), true) == null) { isObjectChangedByAnotherUser = true; } } else { if (objectSpace.Session.FindObject(currentObject.GetType(), new GroupOperator( new BinaryOperator(objectSpace.GetKeyPropertyName(currentObject.GetType()), keyPropertyValue), new NullOperator(classInfo.OptimisticLockFieldName)), true) == null) { isObjectChangedByAnotherUser = true; } } } return(isObjectChangedByAnotherUser); }
public void ProccesExcellRows(IEnumerable<Row> records, XPObjectSpace objectSpace, DoWorkEventArgs e, Type type){ int i = 0; List<XPMemberInfo> props = objectSpace.FindXPClassInfo(type).PersistentProperties .OfType<XPMemberInfo>().ToList(); //get key property name of the object type being imported string keyPropertyName = objectSpace.GetKeyPropertyName(type); //for every row in excel sheet foreach (Row excelRow in records){ ++i; if (i == 1) continue; if (_bgWorker.CancellationPending){ e.Cancel = true; break; } string message; ProcessSingleRow(objectSpace, e, type, keyPropertyName, excelRow, props, i, out message); if (i%50 == 0) objectSpace.CommitChanges(); _bgWorker.ReportProgress(1, message); Application.DoEvents(); } objectSpace.CommitChanges(); }
public void ProccesExcellRows(XPObjectSpace objectSpace, Row[] rows, Type type, int?headerRows, CancellationToken token, Utils.Threading.IProgress <string> progress) { var records = rows; int i = 0; var props = objectSpace.FindXPClassInfo(type).PersistentProperties.OfType <XPMemberInfo>().ToList(); string keyPropertyName = objectSpace.GetKeyPropertyName(type); foreach (Row excelRow in records) { ++i; if (i <= headerRows) { continue; } token.ThrowIfCancellationRequested(); string message; ProcessSingleRow(objectSpace, type, keyPropertyName, excelRow, props, i, out message, progress.Report); if (i % TransactionSize == 0) { objectSpace.CommitChanges(); progress.Report(string.Format(Resources.SuccessProcessingRecord, i - 1)); } } progress.Report(string.Format(Resources.SuccessProcessingRecord, i - 1)); objectSpace.CommitChanges(); }
public void ProccesExcellRows( XPObjectSpace objectSpace, DoWorkEventArgs e, Type type){ var workerArgs = ((WorkerArgs) e.Argument); var records = workerArgs.Rows; int i = 0; var props = objectSpace.FindXPClassInfo(type).PersistentProperties.OfType<XPMemberInfo>().ToList(); string keyPropertyName = objectSpace.GetKeyPropertyName(type); foreach (Row excelRow in records){ ++i; if (i <= workerArgs.HeaderRows) continue; if (_bgWorker.CancellationPending){ e.Cancel = true; break; } string message; ProcessSingleRow(objectSpace, e, type, keyPropertyName, excelRow, props, i, out message); if (i%50 == 0) objectSpace.CommitChanges(); _bgWorker.ReportProgress(1, message); Application.DoEvents(); } objectSpace.CommitChanges(); }
private void DeleteObjects(XPObjectSpace objSpace, IList objs, XPClassInfo classInfo) { var inOp = new InOperator( objSpace.GetKeyPropertyName(classInfo.ClassType), objs); var deleter = new BatchDeleter(objSpace); deleter.Delete(classInfo, inOp); }
public void ProccesExcellRows(IEnumerable <Row> records, XPObjectSpace objectSpace, DoWorkEventArgs e, Type type) { int i = 0; List <XPMemberInfo> props = objectSpace.FindXPClassInfo(type).PersistentProperties .OfType <XPMemberInfo>().ToList(); //get key property name of the object type being imported string keyPropertyName = objectSpace.GetKeyPropertyName(type); //for every row in excel sheet foreach (Row excelRow in records) { ++i; if (i == 1) { continue; } if (_bgWorker.CancellationPending) { e.Cancel = true; break; } string message; ProcessSingleRow(objectSpace, e, type, keyPropertyName, excelRow, props, i, out message); if (i % 50 == 0) { objectSpace.CommitChanges(); } _bgWorker.ReportProgress(1, message); Application.DoEvents(); } objectSpace.CommitChanges(); }
public void Process(IEnumerable objs) { Type objType = null; foreach (var obj in objs) { objType = obj.GetType(); } if (objType == null) { return; } var criteria = new InOperator(objSpace.GetKeyPropertyName(objType), objs); var sqlWhere = CriteriaToWhereClauseHelper.GetMsSqlWhere(XpoCriteriaFixer.Fix(criteria)); string processCommandText = CreateProcessCommandText(sqlWhere); using (var cmd = ((SqlConnection)objSpace.Session.Connection).CreateCommand()) { cmd.CommandText = parameterCommandText + "\n\n" + processCommandText; cmd.ExecuteNonQuery(); } }
public void ProccesExcellRows(XPObjectSpace objectSpace, DoWorkEventArgs e, Type type) { var workerArgs = ((WorkerArgs)e.Argument); var records = workerArgs.Rows; int i = 0; var props = objectSpace.FindXPClassInfo(type).PersistentProperties.OfType <XPMemberInfo>().ToList(); string keyPropertyName = objectSpace.GetKeyPropertyName(type); foreach (Row excelRow in records) { ++i; if (i <= workerArgs.HeaderRows) { continue; } if (_bgWorker.CancellationPending) { e.Cancel = true; break; } string message; ProcessSingleRow(objectSpace, e, type, keyPropertyName, excelRow, props, i, out message); if (i % 50 == 0) { objectSpace.CommitChanges(); } _bgWorker.ReportProgress(1, message); Application.DoEvents(); } objectSpace.CommitChanges(); }
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(); } }
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(); } }