public void UpdateObject(BusinessObject obj) { if (DataStructureProvider.IsTableColumn(obj.AATableName, ABCCommon.ABCConstString.colSelected)) { ABCDynamicInvoker.SetValue(obj, ABCCommon.ABCConstString.colSelected, false); } if (String.IsNullOrWhiteSpace(ABCBaseUserProvider.CurrentUserName) == false && DataStructureProvider.IsTableColumn(obj.AATableName, ABCCommon.ABCConstString.colUpdateUser)) { ABCDynamicInvoker.SetValue(obj, ABCCommon.ABCConstString.colUpdateUser, ABCBaseUserProvider.CurrentUserName); } if (DataStructureProvider.IsTableColumn(obj.AATableName, ABCCommon.ABCConstString.colUpdateTime)) { ABCDynamicInvoker.SetValue(obj, ABCCommon.ABCConstString.colUpdateTime, ABCApp.ABCDataGlobal.WorkingDate); } BusinessObjectHelper.GenerateNoColumn(obj, false); if (DatabaseHelper.IsSQLConnection()) { (DatabaseHelper as SqlDatabaseHelper).RunStoredProcedure(StoredProcedureGenerator.GetSPName(StoredProcedureGenerator.SPType.Update, TableName), obj); } else { DatabaseHelper.RunScript(QueryTemplateGenerator.GenUpdate(TableName), obj); } }
public static bool SetAutoValue(BusinessObject obj) { bool isModified = false; #region Edit Count if (DataStructureProvider.IsTableColumn(obj.AATableName, ABCCommon.ABCConstString.colEditCount)) { int iCount = -1; object objCount = ABCDynamicInvoker.GetValue(obj, ABCCommon.ABCConstString.colEditCount); if (objCount != null && objCount != DBNull.Value) { iCount = Convert.ToInt32(objCount); } iCount++; object objOldValue = ABCDynamicInvoker.GetValue(obj, ABCCommon.ABCConstString.colEditCount); ABCDynamicInvoker.SetValue(obj, ABCCommon.ABCConstString.colEditCount, iCount); if (Convert.ToInt32(objOldValue) != iCount) { isModified = true; } } #endregion isModified = isModified || CurrencyProvider.GenerateCurrencyValue(obj); return(isModified); }
public static void GetAllController(AppDomain domain, String strAssFileName) { try { Assembly assEntities = domain.Load(AssemblyName.GetAssemblyName(strAssFileName)); if (assEntities == null) { return; } foreach (Type type in assEntities.GetTypes()) { if (typeof(BusinessObjectController).IsAssignableFrom(type)) { BusinessObjectController Ctrl = (BusinessObjectController)ABCDynamicInvoker.CreateInstanceObject(type); if (Ctrl != null) { BusControllersList.Add(type.Name, Ctrl); } } } } catch (Exception ex) { } }
public static bool IsCleanObject(BusinessObject obj) { if (TemplateObjectList.ContainsKey(obj.AATableName) == false) { TemplateObjectList.Add(obj.AATableName, (BusinessObject)ABCDynamicInvoker.CreateInstanceObject(obj.GetType())); } InitPropertyList(obj.AATableName); BusinessObject objTemplate = TemplateObjectList[obj.AATableName]; if (objTemplate != null) { foreach (PropertyInfo proInfo in PropertyList[obj.AATableName].Values) { object obj1 = proInfo.GetValue(obj, null); object obj2 = proInfo.GetValue(objTemplate, null); if (obj1 == obj2 || (obj1 == null && obj2 == null) || (obj1 != null && obj2 != null && obj1.ToString() == obj2.ToString())) { continue; } return(false); } } return(true); }
public static Dictionary <String, object> GetSameColumnValues(List <BusinessObject> lstObjects) { Dictionary <String, object> lstResults = new Dictionary <string, object>(); foreach (String strProName in GetSameColumnNames(lstObjects)) { bool isSameValue = true; object objFieldValue = null; foreach (BusinessObject obj in lstObjects) { if (objFieldValue == null) { objFieldValue = ABCDynamicInvoker.GetValue(obj, strProName); continue; } if (objFieldValue != ABCDynamicInvoker.GetValue(obj, strProName)) { isSameValue = false; break; } } if (isSameValue) { if (lstResults.ContainsKey(strProName) == false) { lstResults.Add(strProName, objFieldValue); } } } return(lstResults); }
public static Guid GetIDValue(BusinessObject obj) { if (obj == null) { return(Guid.Empty); } string strPrimaryKeyColumn = DataStructureProvider.GetPrimaryKeyColumn(obj.AATableName); return(ABCHelper.DataConverter.ConvertToGuid(ABCDynamicInvoker.GetValue(obj, strPrimaryKeyColumn))); }
public static BusinessObject GetBusinessObject(String strTableName) { Type type = GetBusinessObjectType(strTableName); if (type != null) { return((BusinessObject)ABCDynamicInvoker.CreateInstanceObject(type)); } return(null); }
public static List <object> GetListDataByColumn(List <BusinessObject> lstObjects, String strFieldName) { List <object> lstReturns = new List <object>(); foreach (BusinessObject obj in lstObjects) { object objValue = ABCDynamicInvoker.GetValue(obj, strFieldName); if (objValue != null && lstReturns.Contains(objValue) == false) { lstReturns.Add(objValue); } } return(lstReturns); }
public void GetFromBusinessObject(BusinessObject objBusinessObject) { BusinessObjectHelper.InitPropertyList(this.AATableName); BusinessObjectHelper.InitPropertyList(objBusinessObject.AATableName); foreach (PropertyInfo srcProp in BusinessObjectHelper.PropertyList[objBusinessObject.AATableName].Values) { PropertyInfo destProp = BusinessObjectHelper.GetProperty(this.AATableName, srcProp.Name); if (destProp != null) { object objValue = ABCDynamicInvoker.GetValue(objBusinessObject, srcProp); ABCDynamicInvoker.SetValue(this, destProp, objValue); } } }
public BusinessObject SetToBusinessObject(String strDestTableName) { BusinessObject objResultObject = BusinessObjectFactory.GetBusinessObject(strDestTableName + "Info"); foreach (PropertyInfo destProp in BusinessObjectHelper.PropertyList[strDestTableName].Values) { PropertyInfo srcProp = BusinessObjectHelper.GetProperty(this.AATableName, destProp.Name); if (srcProp != null) { object objValue = ABCDynamicInvoker.GetValue(this, srcProp); ABCDynamicInvoker.SetValue(objResultObject, destProp, objValue); } } return(objResultObject); }
public static String GetRemarkValue(BusinessObject obj) { if (obj == null) { return(null); } object objReturn = ABCDynamicInvoker.GetValue(obj, "Remark"); if (objReturn != null) { return(objReturn.ToString()); } return(""); }
public static String GetDisplayValue(BusinessObject obj) { if (obj == null) { return(null); } string strCol = DataStructureProvider.GetDisplayColumn(obj.AATableName); object objReturn = ABCDynamicInvoker.GetValue(obj, strCol); if (objReturn != null) { return(objReturn.ToString()); } return(""); }
public static bool GenerateNoColumn(BusinessObject obj, bool isAlwayGenerate) { String strNoCol = DataStructureProvider.GetNOColumn(obj.AATableName); if (!String.IsNullOrWhiteSpace(strNoCol)) { if (isAlwayGenerate || String.IsNullOrWhiteSpace(ABCDynamicInvoker.GetValue(obj, strNoCol).ToString())) { String strNo = NumberingProvider.GenerateNo(obj); if (!String.IsNullOrWhiteSpace(strNo)) { ABCDynamicInvoker.SetValue(obj, strNoCol, strNo); return(true); } } } return(false); }
public Nullable <Guid> GetIDByNo(String strObjectNo) { BusinessObject obj = GetObjectByNo(strObjectNo); if (obj == null) { return(null); } object objID = ABCDynamicInvoker.GetValue(obj, DataStructureProvider.GetPrimaryKeyColumn(TableName)); if (objID == null) { return(null); } return((Nullable <Guid>)objID); }
public static bool IsModifiedObject(BusinessObject obj) { String strPKCol = DataStructureProvider.GetPrimaryKeyColumn(obj.AATableName); object objID = ABCDynamicInvoker.GetValue(obj, strPKCol); if (objID == null || objID == DBNull.Value) { return(true); } Guid id = Guid.Empty; if (objID is Guid) { id = (Guid)objID; } else if (objID is Nullable <Guid> && ((Nullable <Guid>)objID).HasValue) { id = ((Nullable <Guid>)objID).Value; } else { return(true); } BusinessObject obj2 = BusinessControllerFactory.GetBusinessController(obj.AATableName).GetObjectByID(id); InitPropertyList(obj.AATableName); foreach (PropertyInfo proInfo in PropertyList[obj.AATableName].Values) { object pro1 = proInfo.GetValue(obj, null); object pro2 = proInfo.GetValue(obj2, null); if (pro1 == pro2 || (pro1 == null && pro2 == null) || (pro1 != null && pro2 != null && pro1.ToString() == pro2.ToString())) { continue; } return(true); } return(false); }
public virtual Guid CreateObject(BusinessObject obj) { #region Default Value if (DataStructureProvider.IsTableColumn(obj.AATableName, ABCCommon.ABCConstString.colSelected)) { ABCDynamicInvoker.SetValue(obj, ABCCommon.ABCConstString.colSelected, false); } if (String.IsNullOrWhiteSpace(ABCBaseUserProvider.CurrentUserName) == false && DataStructureProvider.IsTableColumn(obj.AATableName, ABCCommon.ABCConstString.colCreateUser)) { ABCDynamicInvoker.SetValue(obj, ABCCommon.ABCConstString.colCreateUser, ABCBaseUserProvider.CurrentUserName); } if (DataStructureProvider.IsTableColumn(obj.AATableName, ABCCommon.ABCConstString.colCreateTime)) { ABCDynamicInvoker.SetValue(obj, ABCCommon.ABCConstString.colCreateTime, ABCApp.ABCDataGlobal.WorkingDate); } #endregion Guid iID = Guid.Empty; if (DatabaseHelper.IsSQLConnection()) { iID = ABCHelper.DataConverter.ConvertToGuid((DatabaseHelper as SqlDatabaseHelper).RunStoredProcedure(StoredProcedureGenerator.GetSPName(StoredProcedureGenerator.SPType.Insert, TableName), obj)); } else { String strQuery = QueryTemplateGenerator.GenInsert(TableName); iID = Guid.NewGuid(); strQuery = strQuery.Replace(String.Format("@{0}", DataStructureProvider.GetPrimaryKeyColumn(TableName)), "'" + iID.ToString() + "'"); DatabaseHelper.RunScript(strQuery, obj); } ABCDynamicInvoker.SetValue(obj, DataStructureProvider.GetPrimaryKeyColumn(obj.AATableName), iID); if (BusinessObjectHelper.GenerateNoColumn(obj, true)) { UpdateObject(obj); } return(iID); }
public static void SetDefaultValue(BusinessObject obj) { if (DataStructureProvider.IsTableColumn(obj.AATableName, ABCCommon.ABCConstString.colDocumentDate)) { ABCDynamicInvoker.SetValue(obj, ABCCommon.ABCConstString.colDocumentDate, ABCApp.ABCDataGlobal.WorkingDate); } if (DataStructureProvider.IsTableColumn(obj.AATableName, "DocumentExpireDate")) { ABCDynamicInvoker.SetValue(obj, "DocumentExpireDate", ABCApp.ABCDataGlobal.WorkingDate.AddMonths(1)); } if (DataStructureProvider.IsTableColumn(obj.AATableName, ABCCommon.ABCConstString.colVoucherDate)) { ABCDynamicInvoker.SetValue(obj, ABCCommon.ABCConstString.colVoucherDate, ABCApp.ABCDataGlobal.WorkingDate); } if (DataStructureProvider.IsTableColumn(obj.AATableName, ABCCommon.ABCConstString.colApprovalStatus)) { ABCDynamicInvoker.SetValue(obj, ABCCommon.ABCConstString.colApprovalStatus, ABCCommon.ABCConstString.ApprovalTypeNew); } if (DataStructureProvider.IsTableColumn(obj.AATableName, ABCCommon.ABCConstString.colApprovedDate)) { ABCDynamicInvoker.SetValue(obj, ABCCommon.ABCConstString.colApprovedDate, null); } if (DataStructureProvider.IsTableColumn(obj.AATableName, ABCCommon.ABCConstString.colJournalStatus)) { ABCDynamicInvoker.SetValue(obj, ABCCommon.ABCConstString.colJournalStatus, ABCCommon.ABCConstString.PostStatusNew); } if (DataStructureProvider.IsTableColumn(obj.AATableName, ABCCommon.ABCConstString.colJournalDate)) { ABCDynamicInvoker.SetValue(obj, ABCCommon.ABCConstString.colJournalDate, ABCApp.ABCDataGlobal.WorkingDate); } if (DataStructureProvider.IsTableColumn(obj.AATableName, ABCCommon.ABCConstString.colLockStatus)) { ABCDynamicInvoker.SetValue(obj, ABCCommon.ABCConstString.colLockStatus, ABCCommon.ABCConstString.LockStatusNew); } obj.SetNoValue(String.Empty); CurrencyProvider.GenerateCurrencyValue(obj); }
public void DeleteObject(BusinessObject obj) { object objID = (object)ABCDynamicInvoker.GetValue(obj, DataStructureProvider.GetPrimaryKeyColumn(obj.AATableName)); Guid id = Guid.Empty; if (objID is Guid) { id = (Guid)objID; } else if (objID is Nullable <Guid> && ((Nullable <Guid>)objID).HasValue) { id = ((Nullable <Guid>)objID).Value; } else { return; } DeleteObject(id); }
public static bool IsPostedObject(String strTableName, Guid iID) { BusinessObjectController ctrl = BusinessControllerFactory.GetBusinessController(strTableName); if (ctrl == null) { return(true); } BusinessObject obj = ctrl.GetObjectByID(iID); if (obj == null) { return(true); } object objTemp = ABCDynamicInvoker.GetValue(obj, ABCCommon.ABCConstString.colJournalStatus); return(objTemp != null && objTemp.ToString() == ABCCommon.ABCConstString.PostStatusPosted); }
public static BusinessObject GetBusinessObject(DataRow row, String strTableName) { if (row == null) { return(null); } InitPropertyList(strTableName); Dictionary <String, PropertyInfo> lstInner = null; if (PropertyList.TryGetValue(strTableName, out lstInner) == false) { return(null); } #region ABCDynamicInvoker BusinessObject obj = BusinessObjectFactory.GetBusinessObject(strTableName); foreach (DataColumn column in row.Table.Columns) { object objValue = row[column]; if (objValue == System.DBNull.Value) { continue; } if (objValue.GetType() == typeof(Int64)) { objValue = Convert.ToInt32(objValue); } PropertyInfo property = null; lstInner.TryGetValue(column.ColumnName, out property); if (property != null) { ABCDynamicInvoker.SetValue(obj, property, objValue); } } return(obj); #endregion }
public static bool CopyField(BusinessObject objFrom, BusinessObject objTo, String strFromField, String strToField, Boolean isCleanFieldOnly) { if (objFrom == null || objTo == null) { return(false); } if (isCleanFieldOnly == false || (isCleanFieldOnly && IsCleanField(objTo, strToField))) { object objValue = ABCDynamicInvoker.GetValue(objFrom, strFromField); if (objValue != null) { object objOldValue = ABCDynamicInvoker.GetValue(objTo, strToField); ABCDynamicInvoker.SetValue(objTo, strToField, objValue); if (objOldValue != objValue) { return(true); } } } return(false); }
public static bool IsCleanField(BusinessObject obj, String strFieldName) { if (TemplateObjectList.ContainsKey(obj.AATableName) == false) { TemplateObjectList.Add(obj.AATableName, (BusinessObject)ABCDynamicInvoker.CreateInstanceObject(obj.GetType())); } InitPropertyList(obj.AATableName); BusinessObject objTemplate = TemplateObjectList[obj.AATableName]; if (objTemplate != null && PropertyList[obj.AATableName].ContainsKey(strFieldName)) { PropertyInfo proInfo = PropertyList[obj.AATableName][strFieldName]; object obj1 = proInfo.GetValue(obj, null); object obj2 = proInfo.GetValue(objTemplate, null); if (obj1 == obj2 || (obj1 == null && obj2 == null) || (obj1 != null && obj2 != null && obj1.ToString() == obj2.ToString())) { return(true); } } return(false); }
public static String GetNameValue(BusinessObject obj) { if (obj == null) { return(String.Empty); } string strName = DataStructureProvider.GetNAMEColumn(obj.AATableName); if (String.IsNullOrWhiteSpace(strName)) { strName = DataStructureProvider.GetNOColumn(obj.AATableName); } object objReturn = ABCDynamicInvoker.GetValue(obj, strName); if (objReturn != null) { return(objReturn.ToString()); } return(String.Empty); }
public static bool CopyFKFields(BusinessObject objFrom, BusinessObject objTo, Boolean isCleanFieldOnly) { if (objFrom == null || objTo == null) { return(false); } bool isCopied = false; String strFromName = objFrom.AATableName; String strToName = objTo.AATableName; BusinessObjectHelper.InitPropertyList(strToName); foreach (PropertyInfo propTo in BusinessObjectHelper.PropertyList[strToName].Values) { if (DataStructureProvider.IsForeignKey(strToName, propTo.Name) == false) { continue; } PropertyInfo propFrom = BusinessObjectHelper.GetProperty(strFromName, propTo.Name); if (propFrom != null) { if (isCleanFieldOnly == false || (isCleanFieldOnly && IsCleanField(objTo, propTo.Name))) { object objValue = ABCDynamicInvoker.GetValue(objFrom, propFrom); object objOldValue = ABCDynamicInvoker.GetValue(objTo, propTo); ABCDynamicInvoker.SetValue(objTo, propTo, objValue); if (objOldValue != objValue) { isCopied = true; } } } } return(isCopied); }
public object Clone(Type destType) { if (destType == this.GetType()) { return(this.MemberwiseClone()); } Type orgType = this.GetType(); BusinessObject newObject = (BusinessObject)Activator.CreateInstance(destType); PropertyInfo[] properties = destType.GetProperties(); foreach (PropertyInfo prop in properties) { PropertyInfo orgPro = orgType.GetProperty(prop.Name); if (orgPro != null) { object objValue = ABCDynamicInvoker.GetValue(this, orgPro); ABCDynamicInvoker.SetValue(newObject, prop, objValue); } } return(newObject); }
public Guid GetIDByName(String strObjectName) { BusinessObject obj = GetObjectByName(strObjectName); return((Guid)ABCDynamicInvoker.GetValue(obj, DataStructureProvider.GetPrimaryKeyColumn(TableName))); }
public static void SetIDValue(BusinessObject obj, Guid iID) { string strPrimaryKeyColumn = DataStructureProvider.GetPrimaryKeyColumn(obj.AATableName); ABCDynamicInvoker.SetValue(obj, strPrimaryKeyColumn, iID); }
public static void CopyFKFields(BusinessObject sourceObj, String strItemTableName) { if (sourceObj == null) { return; } String strFK = DataStructureProvider.GetForeignKeyOfTableName(strItemTableName, sourceObj.AATableName); if (String.IsNullOrWhiteSpace(strFK)) { return; } String strQuery = String.Format("UPDATE {0} SET ", strItemTableName); Dictionary <String, object> lstCols = new Dictionary <string, object>(); foreach (PropertyInfo pro in BusinessObjectHelper.PropertyList[sourceObj.AATableName].Values) { if (DataStructureProvider.IsTableColumn(strItemTableName, pro.Name) == false) { continue; } if (DataStructureProvider.IsForeignKey(sourceObj.AATableName, pro.Name)) { lstCols.Add(pro.Name, ABCHelper.DataConverter.ConvertToGuid(ABCDynamicInvoker.GetValue(sourceObj, pro))); } if (pro.Name == ABCCommon.ABCConstString.colApprovalStatus || pro.Name == ABCCommon.ABCConstString.colApprovedDate || pro.Name == ABCCommon.ABCConstString.colDocumentDate || pro.Name == ABCCommon.ABCConstString.colLockStatus || pro.Name == ABCCommon.ABCConstString.colVoucher || pro.Name == ABCCommon.ABCConstString.colVoucherDate || pro.Name == ABCCommon.ABCConstString.colJournalStatus || pro.Name == ABCCommon.ABCConstString.colJournalDate || pro.Name == ABCCommon.ABCConstString.colUpdateTime || pro.Name == ABCCommon.ABCConstString.colUpdateUser) { lstCols.Add(pro.Name, ABCDynamicInvoker.GetValue(sourceObj, pro)); } } int i = -1; foreach (String strKey in lstCols.Keys) { i++; if (lstCols[strKey] != null && lstCols[strKey] != DBNull.Value) { String strValue = lstCols[strKey].ToString(); if (lstCols[strKey] is DateTime) { strValue = ((DateTime)lstCols[strKey]).ToString("yyyy-MM-dd HH:mm:ss"); } if (lstCols[strKey] is Nullable <DateTime> ) { strValue = ((Nullable <DateTime>)lstCols[strKey]).Value.ToString("yyyy-MM-dd HH:mm:ss"); } if (i < lstCols.Count - 1) { strQuery = strQuery + String.Format(" [{0}] = '{1}',", strKey, strValue); } else { strQuery = strQuery + String.Format(" [{0}] = '{1}'", strKey, strValue); } } else { if (i < lstCols.Count - 1) { strQuery = strQuery + String.Format(" [{0}] = NULL,", strKey); } else { strQuery = strQuery + String.Format(" [{0}] =NULL", strKey); } } } strQuery = strQuery + String.Format(" WHERE [{0}] ='{1}' ", strFK, sourceObj.GetID()); BusinessObjectController.RunQuery(strQuery); }
public static void SetNOValue(BusinessObject obj, String strNo) { string strNOCol = DataStructureProvider.GetNOColumn(obj.AATableName); ABCDynamicInvoker.SetValue(obj, strNOCol, strNo); }
public String GetNoByID(Guid iObjectID) { BusinessObject obj = GetObjectByID(iObjectID); return((String)ABCDynamicInvoker.GetValue(obj, DataStructureProvider.GetNOColumn(TableName))); }