Beispiel #1
0
        public virtual bool ReCalculate(BusinessObject obj, bool isSave)
        {
            if (DataStructureProvider.IsTableColumn(obj.AATableName, ABCCommon.ABCConstString.colLockStatus))
            {
                if (ABCDynamicInvoker.GetValue(obj, ABCCommon.ABCConstString.colLockStatus).ToString() == ABCCommon.ABCConstString.LockStatusLocked)
                {
                    return(false);
                }
            }

            if (obj.GetID() != Guid.Empty)
            {
                Dictionary <String, IEnumerable <BusinessObject> > lstObjecItems = new Dictionary <string, IEnumerable <BusinessObject> >();
                foreach (GEVoucherItemsInfo configItem in ConfigItems)
                {
                    if (!DataStructureProvider.IsForeignKey(configItem.ItemTableName, configItem.ItemFKField))
                    {
                        continue;
                    }

                    BusinessObjectController itemCtrl = BusinessControllerFactory.GetBusinessController(configItem.ItemTableName);

                    if (!lstObjecItems.ContainsKey(configItem.ItemTableName))
                    {
                        lstObjecItems.Add(configItem.ItemTableName, (IEnumerable <BusinessObject>)itemCtrl.GetListByForeignKey(configItem.ItemFKField, obj.GetID()));
                    }
                }

                return(ReCalculate(obj, lstObjecItems, false, String.Empty, isSave));
            }

            return(ReCalculate(obj, null, false, String.Empty, isSave));
        }
Beispiel #2
0
        public virtual bool ReCalculate(BusinessObject obj, Dictionary <String, IEnumerable <BusinessObject> > lstObjecItems, bool isCalcMainOnly, String strAfterValidateFieldName, bool isSave)
        {
            if (obj == null || obj.GetID() == Guid.Empty)
            {
                return(false);
            }

            if (DataStructureProvider.IsTableColumn(obj.AATableName, ABCCommon.ABCConstString.colLockStatus))
            {
                if (ABCDynamicInvoker.GetValue(obj, ABCCommon.ABCConstString.colLockStatus).ToString() == ABCCommon.ABCConstString.LockStatusLocked)
                {
                    return(false);
                }
            }

            if (!BeforeReCalculate(obj, lstObjecItems, isCalcMainOnly, strAfterValidateFieldName))
            {
                return(false);
            }

            if (!DoReCalculate(obj, lstObjecItems, isCalcMainOnly, strAfterValidateFieldName, isSave))
            {
                return(false);
            }

            AfterReCalculate(obj, lstObjecItems, isCalcMainOnly, strAfterValidateFieldName);
            return(true);
        }
Beispiel #3
0
        public static bool GenerateCurrencyValue(BusinessObject obj)
        {
            bool isModified = false;

            String strFK_GECurrencyID = DataStructureProvider.GetForeignKeyOfTableName(obj.AATableName, "GECurrencys");

            if (!String.IsNullOrWhiteSpace(strFK_GECurrencyID))
            {
                if (AppCurrencyID == Guid.Empty)
                {
                    String strQuery = @"SELECT FK_GECurrencyID FROM GEAppConfigs";
                    AppCurrencyID = ABCHelper.DataConverter.ConvertToGuid(BusinessObjectController.GetData(strQuery));
                }
                ABCDynamicInvoker.SetValue(obj, strFK_GECurrencyID, AppCurrencyID);
                if (AppCurrencyID != Guid.Empty && DataStructureProvider.IsTableColumn(obj.AATableName, ABCCommon.ABCConstString.colExchangeRate))
                {
                    object objDate    = DateTime.MinValue;
                    String strDateCol = String.Empty;
                    if (DataStructureProvider.IsTableColumn(obj.AATableName, ABCCommon.ABCConstString.colCreateTime))
                    {
                        strDateCol = ABCCommon.ABCConstString.colCreateTime;
                    }
                    if (DataStructureProvider.IsTableColumn(obj.AATableName, ABCCommon.ABCConstString.colDocumentDate))
                    {
                        strDateCol = ABCCommon.ABCConstString.colDocumentDate;
                    }

                    if (DataStructureProvider.IsTableColumn(obj.AATableName, ABCCommon.ABCConstString.colVoucherDate))
                    {
                        strDateCol = ABCCommon.ABCConstString.colVoucherDate;
                    }

                    if (!String.IsNullOrWhiteSpace(strDateCol))
                    {
                        objDate = ABCDynamicInvoker.GetValue(obj, strDateCol);

                        object objOldValue = ABCDynamicInvoker.GetValue(obj, ABCCommon.ABCConstString.colExchangeRate);

                        if (objDate != null && objDate is DateTime)
                        {
                            object objNewValue = CurrencyProvider.GetExchangeRate(AppCurrencyID, Convert.ToDateTime(objDate));
                            ABCDynamicInvoker.SetValue(obj, ABCCommon.ABCConstString.colExchangeRate, objNewValue);
                            isModified = isModified || (objOldValue != objNewValue);
                        }
                        else if (objDate != null && objDate is Nullable <DateTime> )
                        {
                            object objNewValue = CurrencyProvider.GetExchangeRate(AppCurrencyID, (objDate as Nullable <DateTime>).Value);
                            ABCDynamicInvoker.SetValue(obj, ABCCommon.ABCConstString.colExchangeRate, objNewValue);
                            isModified = isModified || (objOldValue != objNewValue);
                        }
                    }
                }
            }

            return(isModified);
        }
Beispiel #4
0
        public static object GetCachingObjectAccrossTable(String strTableName, Guid iFieldValue, String strFieldString, String strIDTableName)
        {
            AccrossStructInfo info = GetAccrossStructInfo(strTableName, iFieldValue, strFieldString, strIDTableName);

            if (info != null && DataStructureProvider.IsTableColumn(info.TableName, info.FieldName))
            {
                BusinessObject objResult = GetCachedBusinessObject(info.TableName, info.TableID);
                return(ABCBusinessEntities.ABCDynamicInvoker.GetValue(objResult, info.FieldName));
            }

            return(null);
        }
Beispiel #5
0
        public int GetMaxNoIndex(string tableName)
        {
            if (DataStructureProvider.IsTableColumn(tableName, "NoIndex") == false)
            {
                return(-1);
            }

            Database db = CurrentDatabase;

            if (CurrentDatabase == null)
            {
                if (DataStructureProvider.IsSystemTable(tableName))
                {
                    db = DataQueryProvider.SystemDatabase;
                }
                else
                {
                    db = DataQueryProvider.CompanyDatabase;
                }
            }

            DbCommand cmd = null;

            if (MaxIndexCommandList.TryGetValue(tableName, out cmd) == false)
            {
                String sqlCommand = String.Format("SELECT Max(NoIndex) FROM [{0}]", tableName);
                cmd = db.GetSqlStringCommand(sqlCommand);
                MaxIndexCommandList.Add(tableName, cmd);
            }

            DataSet ds = db.ExecuteDataSet(cmd);

            if (ds != null && ds.Tables.Count > 0)
            {
                if (ds.Tables[0].Rows[0][0] == System.DBNull.Value)
                {
                    return(0);
                }
                else
                {
                    return(Convert.ToInt32(ds.Tables[0].Rows[0][0]));
                }
            }
            return(-1);
        }
Beispiel #6
0
        public static object GetCachingObjectDisplayAccrossTable(String strTableName, Guid iFieldValue, String strFieldString, String strIDTableName)
        {
            AccrossStructInfo info = GetAccrossStructInfo(strTableName, iFieldValue, strFieldString, strIDTableName);

            if (info != null && DataStructureProvider.IsTableColumn(info.TableName, info.FieldName))
            {
                BusinessObject objResult = GetCachedBusinessObject(info.TableName, info.TableID);
                object         obj       = ABCBusinessEntities.ABCDynamicInvoker.GetValue(objResult, info.FieldName);

                String strEnum = DataConfigProvider.TableConfigList[info.TableName].FieldConfigList[info.FieldName].AssignedEnum;
                if (EnumProvider.EnumList.ContainsKey(strEnum) &&
                    EnumProvider.EnumList[strEnum].Items.ContainsKey(obj.ToString()))
                {
                    return(EnumProvider.EnumList[strEnum].Items[obj.ToString()].CaptionVN);
                }

                return(obj);
            }
            return(null);
        }
Beispiel #7
0
        private static void LoadLookupTable(String strTableName)
        {
            if (LookupTables.ContainsKey(strTableName) == false && LastUpdateTimes.ContainsKey(strTableName) == false)
            {
                BusinessObjectController Ctrl = BusinessControllerFactory.GetBusinessController(strTableName);
                if (Ctrl != null)
                {
                    DataSet ds = Ctrl.GetDataSetAllObjects();
                    if (ds != null && ds.Tables.Count > 0)
                    {
                        LookupTables.Add(strTableName, ds.Tables[0]);

                        if (DataStructureProvider.IsTableColumn(strTableName, ABCCommon.ABCConstString.colUpdateTime))
                        {
                            LastUpdateTimes.Add(strTableName, TimeProvider.GetTableLastUpdateTime(strTableName));
                        }
                    }
                }
            }
        }
Beispiel #8
0
        public static double GetCredit(Guid partnerID, CreditConfigType configType)
        {
            double amt = 0;

            foreach (CRCreditConfigsInfo config in GetCreditConfigs(configType))
            {
                String strFKPartnerIDCol = config.PartnerIDField;
                if (String.IsNullOrWhiteSpace(strFKPartnerIDCol))
                {
                    strFKPartnerIDCol = "FK_MAPartnerID";
                }

                String strQuery = QueryGenerator.GenSelect(config.TableName, String.Format("SUM({0})", config.AmtFCField), true);
                strQuery = QueryGenerator.AddCondition(strQuery, config.ConditionString);

                if (DataStructureProvider.IsTableColumn(config.TableName, strFKPartnerIDCol))
                {
                    strQuery = QueryGenerator.AddEqualCondition(strQuery, strFKPartnerIDCol, partnerID);
                }
                else
                {
                    if (DataStructureProvider.IsExistedTable(config.ParentTableName))
                    {
                        if (DataStructureProvider.IsTableColumn(config.ParentTableName, strFKPartnerIDCol))
                        {
                            String strFK     = DataStructureProvider.GetForeignKeyOfTableName(config.TableName, config.ParentTableName);
                            String strQuery2 = QueryGenerator.GenSelect(config.ParentTableName, DataStructureProvider.GetPrimaryKeyColumn(config.ParentTableName), true);
                            strQuery2 = QueryGenerator.AddEqualCondition(strQuery2, strFKPartnerIDCol, partnerID);
                            strQuery  = QueryGenerator.AddCondition(strQuery, String.Format("{0} IN ({1})", strFK, strQuery2));
                        }
                    }
                }

                object obj = BusinessObjectController.GetData(strQuery);
                if (obj != null && obj != DBNull.Value)
                {
                    amt += Convert.ToDouble(obj);
                }
            }
            return(amt);
        }
        public static string GetDisplayColumn(string strTableName)
        {
            String strResult = String.Empty;

            if (DataConfigProvider.TableConfigList.ContainsKey(strTableName))
            {
                foreach (DataConfigProvider.FieldConfig fieldConfig in DataConfigProvider.TableConfigList[strTableName].FieldConfigList.Values)
                {
                    if (fieldConfig.IsDisplayField)
                    {
                        strResult = fieldConfig.FieldName;
                        break;
                    }
                }
            }

            if (String.IsNullOrWhiteSpace(strResult))
            {
                strResult = DataStructureProvider.GetNAMEColumn(strTableName);
            }

            if (String.IsNullOrWhiteSpace(strResult))
            {
                strResult = DataStructureProvider.GetNOColumn(strTableName);
            }

            if (String.IsNullOrWhiteSpace(strResult))
            {
                if (DataStructureProvider.IsTableColumn(strTableName, "Remark"))
                {
                    strResult = "Remark";
                }
            }
            if (String.IsNullOrWhiteSpace(strResult))
            {
                strResult = DataStructureProvider.GetPrimaryKeyColumn(strTableName);
            }

            return(strResult);
        }
        public static ABCFormatInfo GetFormatInfo(String strTableName, String strFieldString)
        {
            if (String.IsNullOrWhiteSpace(strFieldString) || String.IsNullOrWhiteSpace(strTableName))
            {
                return(null);
            }

            String TableName = strTableName;
            String FieldName = strFieldString;

            if (strFieldString.Contains(":"))
            {
                DataCachingProvider.AccrossStructInfo structInfo = DataCachingProvider.GetAccrossStructInfo(strTableName, strFieldString);
                if (structInfo != null)
                {
                    TableName = structInfo.TableName;
                    FieldName = structInfo.FieldName;
                }
            }

            if (DataStructureProvider.IsTableColumn(TableName, FieldName) == false)
            {
                return(null);
            }

            if (DataStructureProvider.IsForeignKey(TableName, FieldName))
            {
                TableName = DataStructureProvider.GetTableNameOfForeignKey(TableName, FieldName);
                FieldName = DataStructureProvider.GetDisplayColumn(TableName);
            }
            if (DataConfigProvider.TableConfigList.ContainsKey(TableName) &&
                DataConfigProvider.TableConfigList[TableName].FieldConfigList.ContainsKey(FieldName))
            {
                return(GetFormatInfo(DataConfigProvider.TableConfigList[TableName].FieldConfigList[FieldName].Format));
            }

            return(null);
        }
Beispiel #11
0
        public static AccrossStructInfo GetAccrossStructInfo(String strTableName, Guid iFieldValue, String strFieldString, String strIDTableName)
        {
            if (String.IsNullOrWhiteSpace(strFieldString))
            {
                return(null);
            }

            String[] strArr = strFieldString.Split(':');

            if (DataStructureProvider.IsForeignKey(strTableName, strArr[0]) == false && strArr[0] != "ID")
            {
                return(null);
            }

            AccrossStructInfo result = new AccrossStructInfo();

            if (strArr[0] == "ID" && !String.IsNullOrWhiteSpace(strIDTableName))
            {
                result.TableName = strIDTableName;
            }
            else
            {
                result.TableName = DataStructureProvider.GetTableNameOfForeignKey(strTableName, strArr[0]);
            }

            result.TableID   = iFieldValue;
            result.FieldName = String.Empty;

            if (!DataStructureProvider.IsExistedTable(result.TableName))
            {
                return(null);
            }

            BusinessObject objTable = GetCachedBusinessObject(result.TableName, result.TableID);

            if (objTable == null)
            {
                return(null);
            }

            for (int i = 1; i < strArr.Length; i++)
            {
                result.FieldName = strArr[i];
                if (result.FieldName == "ID" && DataStructureProvider.IsTableColumn(result.TableName, "TableName"))
                {
                    object objTemp = ABCBusinessEntities.ABCDynamicInvoker.GetValue(objTable, "TableName");
                    if (objTemp == null)
                    {
                        break;
                    }
                    result.TableName = objTemp.ToString();

                    objTemp = ABCBusinessEntities.ABCDynamicInvoker.GetValue(objTable, result.FieldName);
                    if (objTemp == null)
                    {
                        break;
                    }
                    result.TableID = ABCHelper.DataConverter.ConvertToGuid(objTemp);
                }
                else
                {
                    if (DataStructureProvider.IsForeignKey(result.TableName, result.FieldName) == false)
                    {
                        break;
                    }

                    result.TableName = DataStructureProvider.GetTableNameOfForeignKey(result.TableName, result.FieldName);
                    object objValue = ABCBusinessEntities.ABCDynamicInvoker.GetValue(objTable, result.FieldName);
                    if (objValue == null)
                    {
                        break;
                    }

                    result.TableID = ABCHelper.DataConverter.ConvertToGuid(objValue);
                    objTable       = GetCachedBusinessObject(result.TableName, result.TableID);
                    if (objTable == null)
                    {
                        break;
                    }
                }
                result.FieldName = String.Empty;
            }

            if (DataStructureProvider.IsForeignKey(result.TableName, result.FieldName) || result.FieldName == String.Empty)
            {
                if (DataStructureProvider.IsForeignKey(result.TableName, result.FieldName))
                {
                    result.TableName = DataStructureProvider.GetTableNameOfForeignKey(result.TableName, result.FieldName);
                }

                result.FieldName = DataStructureProvider.GetDisplayColumn(result.TableName);
            }

            if (String.IsNullOrWhiteSpace(result.FieldName))
            {
                result.FieldName = DataStructureProvider.GetDisplayColumn(result.TableName);
            }
            if (String.IsNullOrWhiteSpace(result.FieldName))
            {
                result.FieldName = DataStructureProvider.GetPrimaryKeyColumn(result.TableName);
            }

            return(result);
        }
Beispiel #12
0
        public static String GenerateNo(BusinessObject obj)
        {
            if (obj.GetID() == Guid.Empty)
            {
                obj.SetNoValue(String.Empty);
                return(String.Empty);
            }

            String strNoValue = String.Empty;

            Numbering numbering = GetNumberingConfig(obj);

            if (numbering != null)
            {
                if (!numbering.IsUsePattern)
                {
                    #region Not UsePattern
                    if (numbering.MiddleConfigs.Count > 0)
                    {
                        #region Have Parts
                        List <String> lstParts = new List <string>();
                        foreach (NumberingType numberType in numbering.MiddleConfigs)
                        {
                            #region Others
                            if (numberType.IsByUser)
                            {
                            }
                            if (numberType.IsByUserGroup)
                            {
                            }
                            if (numberType.IsByEmployee)
                            {
                            }
                            if (numberType.IsByCompanyUnit)
                            {
                            }
                            #endregion

                            if ((numberType.IsYYMMCount || numberType.IsYYMMDDCount || numberType.IsMMDDCount))
                            {
                                String strDateCol = String.Empty;
                                if (DataStructureProvider.IsTableColumn(obj.AATableName, ABCCommon.ABCConstString.colCreateTime))
                                {
                                    strDateCol = ABCCommon.ABCConstString.colCreateTime;
                                }
                                if (DataStructureProvider.IsTableColumn(obj.AATableName, ABCCommon.ABCConstString.colDocumentDate))
                                {
                                    strDateCol = ABCCommon.ABCConstString.colDocumentDate;
                                }

                                if (!String.IsNullOrWhiteSpace(strDateCol))
                                {
                                    object objValue = ABCDynamicInvoker.GetValue(obj, strDateCol);
                                    if (objValue != null && (objValue is DateTime || (objValue is Nullable <DateTime> && (objValue as Nullable <DateTime>).HasValue)))
                                    {
                                        #region With DateTime
                                        DateTime createTime = DateTime.MinValue;
                                        if (objValue is Nullable <DateTime> )
                                        {
                                            createTime = (objValue as Nullable <DateTime>).Value;
                                        }
                                        else
                                        {
                                            createTime = Convert.ToDateTime(objValue);
                                        }

                                        if (numberType.IsYYMMCount)
                                        {
                                            String strQuery = QueryGenerator.GenSelect(obj.AATableName, "COUNT(*)", false, false);
                                            strQuery = QueryGenerator.AddCondition(strQuery, String.Format(@" YEAR({0}) = {1} AND MONTH({0}) = {2} AND {0} < {3}", strDateCol, createTime.Year, createTime.Month, TimeProvider.GenDateTimeString(createTime)));
                                            int iCount = Convert.ToInt32(BusinessObjectController.GetData(strQuery));
                                            if (iCount <= 0)
                                            {
                                                iCount = 0;
                                            }
                                            iCount++;


                                            int iCountSpace = numberType.CountingSpace;
                                            if (iCountSpace < iCount.ToString().Length)
                                            {
                                                iCountSpace = iCount.ToString().Length + 2;
                                            }

                                            String strTemp = createTime.ToString("yyMM") + String.Format("{0:D" + iCountSpace + "}", iCount);
                                            lstParts.Add(strTemp);
                                        }
                                        if (numberType.IsYYMMDDCount)
                                        {
                                            String strQuery = QueryGenerator.GenSelect(obj.AATableName, "COUNT(*)", false, false);
                                            strQuery = QueryGenerator.AddCondition(strQuery, String.Format(@" YEAR({0}) = {1} AND MONTH({0}) = {2} AND DAY({0}) = {3} AND {0} < {4}", strDateCol, createTime.Year, createTime.Month, createTime.Day, TimeProvider.GenDateTimeString(createTime)));
                                            int iCount = Convert.ToInt32(BusinessObjectController.GetData(strQuery));
                                            if (iCount <= 0)
                                            {
                                                iCount = 0;
                                            }
                                            iCount++;

                                            int iCountSpace = numberType.CountingSpace;
                                            if (iCountSpace < iCount.ToString().Length)
                                            {
                                                iCountSpace = iCount.ToString().Length + 2;
                                            }

                                            String strTemp = createTime.ToString("yyMMdd") + String.Format("{0:D" + iCountSpace + "}", iCount);
                                            lstParts.Add(strTemp);
                                        }
                                        if (numberType.IsMMDDCount)
                                        {
                                            String strQuery = QueryGenerator.GenSelect(obj.AATableName, "COUNT(*)", false, false);
                                            strQuery = QueryGenerator.AddCondition(strQuery, String.Format(@" YEAR({0}) = {1} AND MONTH({0}) = {2} AND DAY({0}) = {3} AND {0} < {4}", strDateCol, createTime.Year, createTime.Month, createTime.Day, TimeProvider.GenDateTimeString(createTime)));
                                            int iCount = Convert.ToInt32(BusinessObjectController.GetData(strQuery));
                                            if (iCount <= 0)
                                            {
                                                iCount = 0;
                                            }
                                            iCount++;

                                            int iCountSpace = numberType.CountingSpace;
                                            if (iCountSpace < iCount.ToString().Length)
                                            {
                                                iCountSpace = iCount.ToString().Length + 2;
                                            }

                                            String strTemp = createTime.ToString("MMdd") + String.Format("{0:D" + iCountSpace + "}", iCount);
                                            lstParts.Add(strTemp);
                                        }
                                        #endregion
                                    }
                                }
                            }

                            #region By Field
                            if (numberType.IsByField && !String.IsNullOrWhiteSpace(numberType.FieldName))
                            {
                                if (DataStructureProvider.IsTableColumn(obj.AATableName, numberType.FieldName))
                                {
                                    object objValue = ABCDynamicInvoker.GetValue(obj, numberType.FieldName);
                                    if (objValue != null)
                                    {
                                        if (DataStructureProvider.IsForeignKey(obj.AATableName, numberType.FieldName))
                                        {
                                            String strFieldName = numberType.FieldName + ":" + DataStructureProvider.GetDisplayColumn(obj.AATableName);
                                            objValue = DataCachingProvider.GetCachingObjectAccrossTable(obj, ABCHelper.DataConverter.ConvertToGuid(objValue), strFieldName);
                                        }

                                        lstParts.Add(objValue.ToString());
                                    }
                                }
                            }
                            #endregion
                        }

                        strNoValue = numbering.Prefix + String.Join(numbering.SeperateChar, lstParts) + numbering.Suffix;

                        #endregion
                    }
                    else
                    {
                        String strDateCol = String.Empty;
                        if (DataStructureProvider.IsTableColumn(obj.AATableName, ABCCommon.ABCConstString.colCreateTime))
                        {
                            strDateCol = ABCCommon.ABCConstString.colCreateTime;
                        }
                        if (DataStructureProvider.IsTableColumn(obj.AATableName, ABCCommon.ABCConstString.colDocumentDate))
                        {
                            strDateCol = ABCCommon.ABCConstString.colDocumentDate;
                        }

                        if (!String.IsNullOrWhiteSpace(strDateCol))
                        {
                            object objValue = ABCDynamicInvoker.GetValue(obj, strDateCol);
                            if (objValue != null && (objValue is DateTime || (objValue is Nullable <DateTime> && (objValue as Nullable <DateTime>).HasValue)))
                            {
                                #region With DateTime
                                DateTime createTime = DateTime.MinValue;
                                if (objValue is Nullable <DateTime> )
                                {
                                    createTime = (objValue as Nullable <DateTime>).Value;
                                }
                                else
                                {
                                    createTime = Convert.ToDateTime(objValue);
                                }

                                String strQuery = QueryGenerator.GenSelect(obj.AATableName, "COUNT(*)", false, false);
                                strQuery = QueryGenerator.AddCondition(strQuery, String.Format(@" YEAR({0}) = {1} AND MONTH({0}) = {2} AND {0} < {3}", strDateCol, createTime.Year, createTime.Month, TimeProvider.GenDateTimeString(createTime)));
                                int iCount = Convert.ToInt32(BusinessObjectController.GetData(strQuery));
                                if (iCount <= 0)
                                {
                                    iCount = 0;
                                }
                                iCount++;

                                int iCountSpace = 3;
                                if (iCountSpace < iCount.ToString().Length)
                                {
                                    iCountSpace = iCount.ToString().Length + 2;
                                }

                                strNoValue = numbering.Prefix + createTime.ToString("yyMM") + String.Format("{0:D" + iCountSpace + "}", iCount) + numbering.Suffix;

                                #endregion
                            }
                        }
                        else if (DataStructureProvider.IsTableColumn(obj.AATableName, ABCCommon.ABCConstString.colNoIndex))
                        {
                            int iNoIndex    = Convert.ToInt32(ABCDynamicInvoker.GetValue(obj, ABCCommon.ABCConstString.colNoIndex));
                            int iCountSpace = 4;
                            if (iNoIndex >= 10000)
                            {
                                iCountSpace = iNoIndex.ToString().Length + 2;
                            }
                            strNoValue = numbering.Prefix + String.Format("{0:D" + iCountSpace + "}", iNoIndex) + numbering.Suffix;
                        }
                    }
                    #endregion
                }
                else
                {
                    #region UsePattern

                    #endregion
                }
            }
            else
            {
                #region Have No Config
                if (!String.IsNullOrWhiteSpace(DataConfigProvider.TableConfigList[obj.AATableName].PrefixNo))
                {
                    strNoValue = DataConfigProvider.TableConfigList[obj.AATableName].PrefixNo;
                }
                else
                {
                    strNoValue = new Regex("[^A-Z]+").Replace(DataConfigProvider.GetTableCaption(obj.AATableName), "");
                }


                String strDateCol = String.Empty;
                if (DataStructureProvider.IsTableColumn(obj.AATableName, ABCCommon.ABCConstString.colCreateTime))
                {
                    strDateCol = ABCCommon.ABCConstString.colCreateTime;
                }
                if (DataStructureProvider.IsTableColumn(obj.AATableName, ABCCommon.ABCConstString.colDocumentDate))
                {
                    strDateCol = ABCCommon.ABCConstString.colDocumentDate;
                }

                if (!String.IsNullOrWhiteSpace(strDateCol))
                {
                    object objValue = ABCDynamicInvoker.GetValue(obj, strDateCol);
                    if (objValue != null && (objValue is DateTime || (objValue is Nullable <DateTime> && (objValue as Nullable <DateTime>).HasValue)))
                    {
                        #region With DateTime
                        DateTime createTime = DateTime.MinValue;
                        if (objValue is Nullable <DateTime> )
                        {
                            createTime = (objValue as Nullable <DateTime>).Value;
                        }
                        else
                        {
                            createTime = Convert.ToDateTime(objValue);
                        }

                        String strQuery = QueryGenerator.GenSelect(obj.AATableName, "COUNT(*)", false, false);
                        strQuery = QueryGenerator.AddCondition(strQuery, String.Format(@" YEAR({0}) = {1} AND MONTH({0}) = {2} AND {0} < {3}", strDateCol, createTime.Year, createTime.Month, TimeProvider.GenDateTimeString(createTime)));
                        int iCount = Convert.ToInt32(BusinessObjectController.GetData(strQuery));
                        if (iCount <= 0)
                        {
                            iCount = 0;
                        }
                        iCount++;

                        int iCountSpace = 3;
                        if (iCountSpace < iCount.ToString().Length)
                        {
                            iCountSpace = iCount.ToString().Length + 2;
                        }

                        strNoValue += createTime.ToString("yyMM") + String.Format("{0:D" + iCountSpace + "}", iCount);

                        #endregion
                    }
                }
                else if (DataStructureProvider.IsTableColumn(obj.AATableName, ABCCommon.ABCConstString.colNoIndex))
                {
                    int iNoIndex    = Convert.ToInt32(ABCDynamicInvoker.GetValue(obj, ABCCommon.ABCConstString.colNoIndex));
                    int iCountSpace = 4;
                    if (iNoIndex >= 10000)
                    {
                        iCountSpace = iNoIndex.ToString().Length + 2;
                    }
                    strNoValue += String.Format("{0:D" + iCountSpace + "}", iNoIndex);
                }

                #endregion
            }

            obj.SetNoValue(strNoValue);
            return(strNoValue);
        }
        public static void Synchronize(STDataServerSyncsInfo syncInfo)
        {
            if (!syncInfo.FK_STDataServerID.HasValue)
            {
                return;
            }

            if (!syncInfo.IsPull && !syncInfo.IsPush)
            {
                return;
            }

            if (syncInfo.LastSyncDate.HasValue && syncInfo.IntervalMinute.HasValue &&
                (DateTime.Now < syncInfo.LastSyncDate.Value || DateTime.Now.Subtract(syncInfo.LastSyncDate.Value).TotalMinutes < syncInfo.IntervalMinute.Value))
            {
                return;
            }

            STDataServersController serverCtrl = new STDataServersController();
            STDataServersInfo       server     = serverCtrl.GetObjectByID(syncInfo.FK_STDataServerID.Value) as STDataServersInfo;

            if (server == null)
            {
                return;
            }

            DBConnectionController connection = null;

            if (DataStructureProvider.IsSystemTable(syncInfo.TableName))
            {
                connection = InitSystemConnection(server.STDataServerID);
            }
            else
            {
                connection = InitCompanyConnection(server.STDataServerID);
            }

            if (connection != null)
            {
                using (System.Transactions.TransactionScope scope = new System.Transactions.TransactionScope())
                {
                    String strRunQuery = @"SET XACT_ABORT ON;BEGIN TRANSACTION ABCSYNC; ";
                    String strQuery    = String.Empty;

                    if (syncInfo.IsPush)
                    {
                        if (syncInfo.IsPushMatched)
                        {
                            #region Delete
                            strQuery    = String.Format(@"DELETE [{0}].[{1}].[dbo].[{2}] WHERE [{3}]  NOT IN (SELECT [{3}] FROM [dbo].[{2}] )", server.Name, connection.Connection.DatabaseName, syncInfo.TableName, DataStructureProvider.GetPrimaryKeyColumn(syncInfo.TableName));
                            strRunQuery = String.Format(@"{0} {1}", strRunQuery, Environment.NewLine + strQuery);
                            #endregion
                        }

                        #region Insert New Records
                        strQuery = QueryGenerator.GenSelect(syncInfo.TableName, DataStructureProvider.GetPrimaryKeyColumn(syncInfo.TableName), false, false);
                        if (syncInfo.LastSyncDate.HasValue && DataStructureProvider.IsTableColumn(syncInfo.TableName, ABCCommon.ABCConstString.colCreateTime))
                        {
                            strQuery = QueryGenerator.AddCondition(strQuery, String.Format("{0} > '{1}'", ABCCommon.ABCConstString.colCreateTime, syncInfo.LastSyncDate.Value.ToString("yyyy-MM-dd HH:mm:ss")));
                        }

                        strQuery    = String.Format(@"INSERT INTO [{0}].[{1}].[dbo].[{2}] SELECT * FROM [dbo].[{2}] WHERE [dbo].[{2}].[{3}] IN ({4}) AND [dbo].[{2}].[{3}] NOT IN (SELECT {3} FROM  [{0}].[{1}].[dbo].[{2}])", server.Name, connection.Connection.DatabaseName, syncInfo.TableName, DataStructureProvider.GetPrimaryKeyColumn(syncInfo.TableName), strQuery);
                        strRunQuery = String.Format(@"{0} {1}", strRunQuery, Environment.NewLine + strQuery);
                        #endregion

                        #region Update Modified Records

                        strQuery = QueryGenerator.GenSelect(syncInfo.TableName, DataStructureProvider.GetPrimaryKeyColumn(syncInfo.TableName), false, false);
                        if (syncInfo.LastSyncDate.HasValue && DataStructureProvider.IsTableColumn(syncInfo.TableName, ABCCommon.ABCConstString.colUpdateTime))
                        {
                            strQuery = QueryGenerator.AddCondition(strQuery, String.Format("{0} > '{1}'", ABCCommon.ABCConstString.colUpdateTime, syncInfo.LastSyncDate.Value.ToString("yyyy-MM-dd HH:mm:ss")));
                        }

                        strQuery = String.Format(@"UPDATE [{0}].[{1}].[dbo].[{2}] SET #FIELD# FROM [{0}].[{1}].[dbo].[{2}] Target,[dbo].[{2}] Source WHERE Target.[{3}]=Source.[{3}] AND Source.[{3}] IN ({4}) AND Source.[{3}] IN (SELECT {3} FROM  [{0}].[{1}].[dbo].[{2}])", server.Name, connection.Connection.DatabaseName, syncInfo.TableName, DataStructureProvider.GetPrimaryKeyColumn(syncInfo.TableName), strQuery);

                        List <String> lstSetFields = new List <string>();
                        foreach (String strField in DataStructureProvider.GetAllTableColumns(syncInfo.TableName).Keys)
                        {
                            if (DataStructureProvider.IsPrimaryKey(syncInfo.TableName, strField) == false)
                            {
                                lstSetFields.Add(String.Format(" [{0}]=Source.[{0}] ", strField));
                            }
                        }
                        strQuery = strQuery.Replace("#FIELD#", String.Join(",", lstSetFields));

                        strRunQuery = String.Format(@"{0} {1}", strRunQuery, Environment.NewLine + strQuery);

                        #endregion
                    }
                    if (syncInfo.IsPull)
                    {
                        if (syncInfo.IsPullMatched)
                        {
                            #region Delete
                            strQuery    = String.Format(@"DELETE [dbo].[{2}] WHERE [{3}]  NOT IN (SELECT [{3}] FROM [{0}].[{1}].[dbo].[{2}] )", server.Name, connection.Connection.DatabaseName, syncInfo.TableName, DataStructureProvider.GetPrimaryKeyColumn(syncInfo.TableName));
                            strRunQuery = String.Format(@"{0} {1}", strRunQuery, Environment.NewLine + strQuery);
                            #endregion
                        }

                        #region Insert New Records
                        strQuery = QueryGenerator.GenSelect(syncInfo.TableName, DataStructureProvider.GetPrimaryKeyColumn(syncInfo.TableName), false, false);
                        if (syncInfo.LastSyncDate.HasValue && DataStructureProvider.IsTableColumn(syncInfo.TableName, ABCCommon.ABCConstString.colCreateTime))
                        {
                            strQuery = QueryGenerator.AddCondition(strQuery, String.Format("{0} > '{1}'", ABCCommon.ABCConstString.colCreateTime, syncInfo.LastSyncDate.Value.ToString("yyyy-MM-dd HH:mm:ss")));
                        }
                        strQuery = strQuery.Replace("[dbo]", String.Format(@"[{0}].[{1}].[dbo]", server.Name, connection.Connection.DatabaseName));

                        strQuery    = String.Format(@"INSERT INTO [dbo].[{2}] SELECT * FROM [{0}].[{1}].[dbo].[{2}] WHERE [{3}] IN ({4}) AND [{3}] NOT IN (SELECT {3} FROM [dbo].[{2}])", server.Name, connection.Connection.DatabaseName, syncInfo.TableName, DataStructureProvider.GetPrimaryKeyColumn(syncInfo.TableName), strQuery);
                        strRunQuery = String.Format(@"{0} {1}", strRunQuery, Environment.NewLine + strQuery);
                        #endregion

                        #region Update Modified Records

                        strQuery = QueryGenerator.GenSelect(syncInfo.TableName, DataStructureProvider.GetPrimaryKeyColumn(syncInfo.TableName), false, false);
                        if (syncInfo.LastSyncDate.HasValue && DataStructureProvider.IsTableColumn(syncInfo.TableName, ABCCommon.ABCConstString.colUpdateTime))
                        {
                            strQuery = QueryGenerator.AddCondition(strQuery, String.Format("{0} > '{1}'", ABCCommon.ABCConstString.colUpdateTime, syncInfo.LastSyncDate.Value.ToString("yyyy-MM-dd HH:mm:ss")));
                        }

                        strQuery = strQuery.Replace("[dbo]", String.Format(@"[{0}].[{1}].[dbo]", server.Name, connection.Connection.DatabaseName));
                        strQuery = String.Format(@"UPDATE [dbo].[{2}] SET #FIELD# FROM [dbo].[{2}] Target,[{0}].[{1}].[dbo].[{2}] Source WHERE Target.[{3}]=Source.[{3}] AND Source.[{3}] IN ({4}) AND Source.[{3}] IN (SELECT {3} FROM [dbo].[{2}])", server.Name, connection.Connection.DatabaseName, syncInfo.TableName, DataStructureProvider.GetPrimaryKeyColumn(syncInfo.TableName), strQuery);

                        List <String> lstSetFields = new List <string>();
                        foreach (String strField in DataStructureProvider.GetAllTableColumns(syncInfo.TableName).Keys)
                        {
                            if (DataStructureProvider.IsPrimaryKey(syncInfo.TableName, strField) == false)
                            {
                                lstSetFields.Add(String.Format(" [{0}]=Source.[{0}] ", strField));
                            }
                        }
                        strQuery = strQuery.Replace("#FIELD#", String.Join(",", lstSetFields));

                        strRunQuery = String.Format(@"{0} {1}", strRunQuery, Environment.NewLine + strQuery);

                        #endregion
                    }

                    strRunQuery = String.Format(@"{0} COMMIT TRANSACTION ABCSYNC; SET XACT_ABORT OFF;", strRunQuery + Environment.NewLine);
                    BusinessObjectController.RunQuery(strRunQuery, syncInfo.TableName);

                    BusinessObjectController.RunQuery(String.Format(@"UPDATE STDataServerSyncs SET LastSyncDate =GetDate() WHERE STDataServerSyncID='{0}'", syncInfo.GetID()), syncInfo.AATableName);

                    scope.Complete();
                }
            }
        }
Beispiel #14
0
 public static AccrossStructInfo GetAccrossStructInfo(BusinessObject baseObj, Guid iFieldValue, String strFieldString)
 {
     if (strFieldString.Contains(":") && strFieldString.Split(':')[0] == "ID" && DataStructureProvider.IsTableColumn(baseObj.AATableName, "TableName"))
     {
         object strIDTableName = ABCDynamicInvoker.GetValue(baseObj, "TableName");
         if (strIDTableName != null)
         {
             return(GetAccrossStructInfo(baseObj.AATableName, iFieldValue, strFieldString, strIDTableName.ToString()));
         }
     }
     return(GetAccrossStructInfo(baseObj.AATableName, iFieldValue, strFieldString));
 }
Beispiel #15
0
        public static void CreateNewNotifyFromComment(String strTableName, Guid iID)
        {
            if (DataStructureProvider.IsExistedTable(strTableName) == false)
            {
                return;
            }

            String strIDCol = DataStructureProvider.GetPrimaryKeyColumn(strTableName);

            #region Get Users
            List <String> lstUsers = new List <string>();
            DataSet       ds       = BusinessObjectController.RunQuery(String.Format(@"SELECT CreateUser FROM GEComments WHERE TableName ='{0}' AND ID = '{1}' GROUP BY CreateUser", strTableName, iID));
            if (ds != null && ds.Tables.Count > 0)
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    if (lstUsers.Contains(dr[0].ToString()) == false)
                    {
                        lstUsers.Add(dr[0].ToString());
                    }
                }
            }
            ds = BusinessObjectController.RunQuery(String.Format(@"SELECT TagString FROM GEComments WHERE TableName ='{0}' AND ID = '{1}'  AND TagString IS NOT NULL AND TagString NOT LIKE '' GROUP BY TagString", strTableName, iID));
            if (ds != null && ds.Tables.Count > 0)
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    if (dr[0] != null && dr[0] != DBNull.Value && String.IsNullOrWhiteSpace(dr[0].ToString()) == false)
                    {
                        string[] arr = { "::" };
                        arr = dr[0].ToString().Split(arr, StringSplitOptions.None);
                        for (int i = 0; i < arr.Length; i++)
                        {
                            if (lstUsers.Contains(arr[i]) == false)
                            {
                                lstUsers.Add(arr[i]);
                            }
                        }
                    }
                }
            }



            if (DataStructureProvider.IsTableColumn(strTableName, ABCCommon.ABCConstString.colCreateUser))
            {
                ds = BusinessObjectController.RunQuery(String.Format(@"SELECT {0} FROM {1} WHERE {2} ='{3}'", ABCCommon.ABCConstString.colCreateUser, strTableName, strIDCol, iID));
                if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    object objCreateUser = ds.Tables[0].Rows[0][0];
                    if (objCreateUser != null && objCreateUser != DBNull.Value && lstUsers.Contains(objCreateUser.ToString()) == false)
                    {
                        lstUsers.Add(objCreateUser.ToString());
                    }
                }
            }
            if (DataStructureProvider.IsTableColumn(strTableName, ABCCommon.ABCConstString.colUpdateUser))
            {
                ds = BusinessObjectController.RunQuery(String.Format(@"SELECT {0} FROM {1} WHERE {2} ='{3}'", ABCCommon.ABCConstString.colUpdateUser, strTableName, strIDCol, iID));
                if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    object objUpdateUser = ds.Tables[0].Rows[0][0];
                    if (objUpdateUser != null && objUpdateUser != DBNull.Value && lstUsers.Contains(objUpdateUser.ToString()) == false)
                    {
                        lstUsers.Add(objUpdateUser.ToString());
                    }
                }
            }

            #endregion

            String strTitle      = DataConfigProvider.GetTableCaption(strTableName);
            String strDisplayCol = DataStructureProvider.GetDisplayColumn(strTableName);

            object obj = BusinessObjectController.GetData(String.Format(@"SELECT {0} FROM {1} WHERE {2} ='{3}' ", strDisplayCol, strTableName, strIDCol, iID));
            if (obj != null && obj != DBNull.Value)
            {
                strTitle = strTitle + " : " + obj.ToString();
            }

            foreach (String strUser in lstUsers)
            {
                if (strUser != ABCUserProvider.CurrentUserName)
                {
                    CreateNewNotify(strUser, strTitle, "", strTableName, iID, "");
                }
            }
        }
Beispiel #16
0
        public static void RefreshLookupTable(String strTableName)
        {
            bool isUpdate = false;

            lock ( LookupTables )
            {
                LoadLookupTable(strTableName);

                if (DataStructureProvider.IsTableColumn(strTableName, ABCCommon.ABCConstString.colUpdateTime) &&
                    LastUpdateTimes.ContainsKey(strTableName))
                {
                    #region Has 'UpdateTime'
                    DateTime  lastTimeInDB  = TimeProvider.GetTableLastUpdateTime(strTableName);
                    DataTable lookupTable   = LookupTables[strTableName];
                    DateTime  lastTimeInApp = LastUpdateTimes[strTableName];

                    if (DataStructureProvider.IsTableColumn(strTableName, ABCCommon.ABCConstString.colABCStatus))
                    {
                        #region Has 'ABCStatus'
                        if (lastTimeInDB > lastTimeInApp)
                        {
                            #region Refresh Modified Items
                            String  strQuery = String.Format(@"SELECT * FROM {0} WHERE ABCStatus ='Alive' AND {1}", strTableName, TimeProvider.GenCompareDateTime(ABCCommon.ABCConstString.colUpdateTime, ">", lastTimeInApp));
                            DataSet ds       = DataQueryProvider.CompanyDatabaseHelper.RunQuery(strQuery);
                            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                            {
                                BusinessObjectController controller = BusinessControllerFactory.GetBusinessController(strTableName);
                                String strPK = DataStructureProvider.GetPrimaryKeyColumn(strTableName);
                                foreach (DataRow row in ds.Tables[0].Rows)
                                {
                                    #region Row
                                    BusinessObject obj = (BusinessObject)controller.GetObjectFromDataRow(row);
                                    Guid           iID = ABCHelper.DataConverter.ConvertToGuid(ABCBusinessEntities.ABCDynamicInvoker.GetValue(obj, strPK));

                                    DataRow[] rows = lookupTable.Select(String.Format("{0}='{1}'", strPK, iID));
                                    if (rows.Length == 0) // new
                                    {
                                        lookupTable.ImportRow(row);
                                    }
                                    else
                                    {
                                        DataRow dr    = rows[0];
                                        int     index = lookupTable.Rows.IndexOf(dr);
                                        if (DataStructureProvider.IsExistABCStatus(obj.AATableName) && ABCBusinessEntities.ABCDynamicInvoker.GetValue(obj, ABCCommon.ABCConstString.colABCStatus).ToString().Equals(ABCCommon.ABCConstString.ABCStatusDeleted))       //delete
                                        {
                                            lookupTable.Rows.RemoveAt(index);
                                        }
                                        else //update
                                        {
                                            object[] lstArr = new object[row.ItemArray.Length];
                                            row.ItemArray.CopyTo(lstArr, 0);
                                            lookupTable.Rows[index].ItemArray = lstArr;
                                        }
                                    }
                                    #endregion
                                }

                                isUpdate = true;
                            }
                            #endregion
                        }
                        #endregion
                    }
                    else
                    {
                        #region Without 'ABCStatus'
                        if (lastTimeInDB > lastTimeInApp || TimeProvider.GetRecordCountOfTable(strTableName) != lookupTable.Rows.Count)
                        {
                            DataSet ds = BusinessControllerFactory.GetBusinessController(strTableName).GetDataSetAllObjects();
                            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                            {
                                lookupTable.Rows.Clear();
                                foreach (DataRow dr in ds.Tables[0].Rows)
                                {
                                    lookupTable.ImportRow(dr);
                                }

                                isUpdate = true;
                            }
                        }
                        #endregion
                    }

                    LastUpdateTimes[strTableName] = lastTimeInDB;
                    #endregion
                }
                else
                {
                    #region Without 'UpdateTime'
                    DataTable lookupTable = LookupTables[strTableName];
                    if (TimeProvider.GetRecordCountOfTable(strTableName) != lookupTable.Rows.Count)
                    {
                        DataSet ds = BusinessControllerFactory.GetBusinessController(strTableName).GetDataSetAllObjects();
                        if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                        {
                            lookupTable.Rows.Clear();
                            foreach (DataRow dr in ds.Tables[0].Rows)
                            {
                                lookupTable.ImportRow(dr);
                            }

                            isUpdate = true;
                        }
                    }
                    #endregion
                }
            }

            if (isUpdate && RefreshTableMethods.ContainsKey(strTableName))
            {
                foreach (MethodInfo method in RefreshTableMethods[strTableName])
                {
                    method.Invoke(null, new object[] {});
                }
            }
        }
Beispiel #17
0
        public static void SynchronizeFieldPermission( )
        {
            GEPermissionFieldsController permissionCtrl = new GEPermissionFieldsController();
            String strQuery = String.Format(@"DELETE FROM GEPermissionFields WHERE FK_GEPermissionID NOT IN (SELECT GEPermissionID FROM GEPermissions)");

            BusinessObjectController.RunQuery(strQuery);

            foreach (GEPermissionsInfo permission in new GEPermissionsController().GetListAllObjects())
            {
                #region Field
                Dictionary <String, GEPermissionFieldsInfo> lstFields = new Dictionary <string, GEPermissionFieldsInfo>();

                foreach (GEPermissionFieldsInfo fieldInfo in permissionCtrl.GetListByForeignKey("FK_GEPermissionID", permission.GEPermissionID).Cast <GEPermissionFieldsInfo>().ToList())
                {
                    if (lstFields.ContainsKey(fieldInfo.FieldName) == false)
                    {
                        String strTableCaption = DataConfigProvider.GetTableCaption(fieldInfo.TableName);
                        String strFieldCaption = DataConfigProvider.GetFieldCaption(fieldInfo.TableName, fieldInfo.FieldName);

                        if (DataStructureProvider.IsTableColumn(fieldInfo.TableName, fieldInfo.FieldName) &&
                            strTableCaption != String.Empty && strTableCaption != fieldInfo.TableName &&
                            strFieldCaption != String.Empty && strFieldCaption != fieldInfo.FieldName)
                        {
                            lstFields.Add(fieldInfo.TableName + fieldInfo.FieldName, fieldInfo);
                        }
                        else
                        {
                            permissionCtrl.DeleteObject(fieldInfo);
                        }
                    }
                }


                foreach (String strTableName in DataStructureProvider.DataTablesList.Keys)
                {
                    foreach (String strFieldName in DataStructureProvider.DataTablesList[strTableName].ColumnsList.Keys)
                    {
                        if (DataStructureProvider.IsPrimaryKey(strTableName, strFieldName))
                        {
                            continue;
                        }

                        if (lstFields.ContainsKey(strTableName + strFieldName) == false)
                        {
                            GEPermissionFieldsInfo fieldInfo = new GEPermissionFieldsInfo();
                            fieldInfo.FK_STFieldConfigID = DataConfigProvider.TableConfigList[strTableName].FieldConfigList[strFieldName].ConfigID;
                            fieldInfo.FK_STTableConfigID = DataConfigProvider.TableConfigList[strTableName].ConfigID;
                            fieldInfo.TableName          = strTableName;
                            fieldInfo.FieldName          = strFieldName;
                            fieldInfo.FK_GEPermissionID  = permission.GEPermissionID;
                            fieldInfo.AllowView          = true;
                            fieldInfo.AllowEdit          = true;

                            permissionCtrl.CreateObject(fieldInfo);
                            lstFields.Add(fieldInfo.TableName + fieldInfo.FieldName, fieldInfo);
                        }
                    }
                }
                #endregion
            }
        }
Beispiel #18
0
        public static String GetAlertQueryString(Guid alertID)
        {
            if (AlertList == null)
            {
                GetAlertConfigs(ABCUserProvider.CurrentUser.ADUserID);
            }

            if (AlertList.ContainsKey(alertID) == false)
            {
                return(String.Empty);
            }

            if (AlertQueryList.ContainsKey(alertID))
            {
                return(AlertQueryList[alertID]);
            }

            GEAlertsInfo alertInfo = AlertList[alertID];

            if (alertInfo == null || alertInfo.GetID() == null)
            {
                return(String.Empty);
            }

            String strQuery = QueryGenerator.GenSelect(alertInfo.TableName, "*", false);

            strQuery = QueryGenerator.AddCondition(strQuery, alertInfo.ConditionString);

            #region Filter with current User

            if (alertInfo.ByUser)
            {
                String strFK = DataStructureProvider.GetForeignKeyOfTableName(alertInfo.TableName, "ADUsers");
                if (!String.IsNullOrWhiteSpace(strFK) && ABCUserProvider.CurrentUser != null)
                {
                    strQuery = QueryGenerator.AddCondition(strQuery, String.Format(" {0} = '{1}'", strFK, ABCUserProvider.CurrentUser.ADUserID));
                }
            }
            if (alertInfo.ByUserGroup)
            {
                String strFK = DataStructureProvider.GetForeignKeyOfTableName(alertInfo.TableName, "ADUsers");
                if (!String.IsNullOrWhiteSpace(strFK) && ABCUserProvider.CurrentUser != null)
                {
                    if (ABCUserProvider.CurrentUserGroup != null)
                    {
                        String strQueryUserID = QueryGenerator.AddEqualCondition(QueryGenerator.GenSelect("ADUsers", "ADUserID", false), "FK_ADUserGroupID", ABCUserProvider.CurrentUserGroup.ADUserGroupID);
                        strQuery = QueryGenerator.AddCondition(strQuery, String.Format("{0} IN ({1})", strFK, strQueryUserID));
                    }
                }
                else
                {
                    strFK = DataStructureProvider.GetForeignKeyOfTableName(alertInfo.TableName, "ADUserGroups");
                    if (!String.IsNullOrWhiteSpace(strFK) && ABCUserProvider.CurrentUserGroup != null)
                    {
                        strQuery = QueryGenerator.AddCondition(strQuery, String.Format(" {0} = '{1}'", strFK, ABCUserProvider.CurrentUserGroup.ADUserGroupID));
                    }
                }
            }
            if (alertInfo.ByEmployee)
            {
                String strFK = DataStructureProvider.GetForeignKeyOfTableName(alertInfo.TableName, "HREmployees");
                if (!String.IsNullOrWhiteSpace(strFK) && ABCUserProvider.CurrentEmployee != null)
                {
                    strQuery = QueryGenerator.AddCondition(strQuery, String.Format(" {0} = '{1}'", strFK, ABCUserProvider.CurrentEmployee.HREmployeeID));
                }
            }
            if (alertInfo.ByCompanyUnit)
            {
                String strFK = DataStructureProvider.GetForeignKeyOfTableName(alertInfo.TableName, "GECompanyUnits");
                if (!String.IsNullOrWhiteSpace(strFK) && ABCUserProvider.CurrentCompanyUnit != null)
                {
                    strQuery = QueryGenerator.AddCondition(strQuery, String.Format(" {0} = '{1}'", strFK, ABCUserProvider.CurrentCompanyUnit.GECompanyUnitID));
                }
                else
                {
                    if (!String.IsNullOrWhiteSpace(strFK) && !String.IsNullOrWhiteSpace(DataStructureProvider.GetForeignKeyOfTableName("HREmployees", "GECompanyUnits")))
                    {
                        String strTemp = QueryGenerator.GenSelect("GECompanyUnits", DataStructureProvider.GetForeignKeyOfTableName("HREmployees", "GECompanyUnits"), false);
                        strQuery = QueryGenerator.AddCondition(strQuery, String.Format(" {0} IN ({1})", strFK, strTemp));
                    }
                }
            }
            #endregion


            if (DataStructureProvider.IsTableColumn(alertInfo.TableName, ABCCommon.ABCConstString.colDocumentDate))
            {
                strQuery = strQuery + String.Format(@" ORDER BY {0} DESC", ABCCommon.ABCConstString.colDocumentDate);
            }

            AlertQueryList.Add(alertID, strQuery);

            return(strQuery);
        }
Beispiel #19
0
        public static bool CalculateMainOnly(BaseVoucher voucher, BusinessObject obj, Dictionary <String, IEnumerable <BusinessObject> > lstObjecItems, String strAferValidateFieldName, bool isSave)
        {
            if (FormulasList == null)
            {
                InitFormulas();
            }

            if (!FormulasList.ContainsKey(obj.AATableName))
            {
                return(false);
            }

            bool isCalculated = false;

            Dictionary <String, double> lstVariables = new Dictionary <string, double>();
            bool isContinue = false;

            foreach (GEFormulaItemsInfo formula in FormulasList[obj.AATableName].Values)
            {
                if (String.IsNullOrWhiteSpace(formula.FormulaName))
                {
                    continue;
                }

                #region isNeedCalc
                bool isNeedCalc = isContinue;
                if (!isNeedCalc)
                {
                    if (formula.IsVariable)
                    {
                        isNeedCalc = true;
                    }
                    else
                    {
                        if (String.IsNullOrWhiteSpace(strAferValidateFieldName))
                        {
                            isNeedCalc = true;
                        }
                        else
                        {
                            if (FormulasList[obj.AATableName].Values.Count(t => t.FormulaName == strAferValidateFieldName) > 0)
                            {
                                if (formula.FormulaName == strAferValidateFieldName)
                                {
                                    isContinue = true;
                                    continue;
                                }
                            }
                            else
                            {
                                if (DataConfigProvider.GetFieldSortOrder(obj.AATableName, strAferValidateFieldName) <= DataConfigProvider.GetFieldSortOrder(obj.AATableName, formula.FormulaName))
                                {
                                    isContinue = true;
                                    isNeedCalc = true;
                                }
                            }
                        }
                    }
                }

                if (!isNeedCalc)
                {
                    continue;
                }
                #endregion

                object objAmt = null;
                if (formula.IsUseQuery && !String.IsNullOrWhiteSpace(formula.QueryString))
                {
                    #region Query
                    String strQuery = formula.QueryString.Replace("{TableName}", obj.AATableName);
                    if (obj.GetID() != Guid.Empty)
                    {
                        strQuery = strQuery.Replace("{ID}", obj.GetID().ToString());
                    }

                    foreach (String strProperty in DataStructureProvider.DataTablesList[obj.AATableName].ColumnsList.Keys)
                    {
                        if (strQuery.Contains("{" + strProperty + "}"))
                        {
                            object objValue = ABCDynamicInvoker.GetValue(obj, strProperty);
                            if (objValue == null || objValue == DBNull.Value)
                            {
                                strQuery = strQuery.Replace("{" + strProperty + "}", "NULL");
                            }
                            else
                            {
                                strQuery = strQuery.Replace("{" + strProperty + "}", objValue.ToString());
                            }
                        }
                    }

                    foreach (String strVariableName in lstVariables.Keys)
                    {
                        if (strQuery.Contains("{" + strVariableName + "}"))
                        {
                            strQuery = strQuery.Replace("{" + strVariableName + "}", lstVariables[strVariableName].ToString());
                        }
                    }
                    #endregion

                    objAmt = BusinessObjectController.GetData(strQuery);
                }
                else if (formula.IsUseFormula && !String.IsNullOrWhiteSpace(formula.Formula))
                {
                    String strExpression = formula.Formula;

                    #region Formula
                    foreach (String strProperty in DataStructureProvider.DataTablesList[obj.AATableName].ColumnsList.Keys)
                    {
                        strExpression = strExpression.Replace("{" + strProperty + "}", "[" + strProperty + "]");
                    }

                    foreach (String strVariableName in lstVariables.Keys)
                    {
                        strExpression = strExpression.Replace("{" + strVariableName + "}", "[" + strVariableName + "]");
                    }


                    Expression e = new Expression(strExpression);
                    foreach (String strProperty in DataStructureProvider.DataTablesList[obj.AATableName].ColumnsList.Keys)
                    {
                        if (strExpression.Contains("[" + strProperty + "]"))
                        {
                            object objValue = ABCDynamicInvoker.GetValue(obj, strProperty);
                            if (objValue == null)
                            {
                                continue;
                            }

                            double dbValue = 0;
                            Double.TryParse(objValue.ToString(), out dbValue);
                            e.Parameters[strProperty] = dbValue;
                        }
                    }

                    foreach (String strVariableName in lstVariables.Keys)
                    {
                        if (strExpression.Contains("[" + strVariableName + "]"))
                        {
                            e.Parameters[strVariableName] = lstVariables[strVariableName];
                        }
                    }

                    #endregion

                    objAmt = e.Evaluate();
                }
                else if (formula.IsUseSumFromChild)
                {
                    objAmt = 0;
                    if (lstObjecItems.ContainsKey(formula.SumChildTableName) && DataStructureProvider.IsTableColumn(formula.SumChildTableName, formula.SumChildFieldName))
                    {
                        objAmt = lstObjecItems[formula.SumChildTableName].Sum(t => Convert.ToDouble(ABCDynamicInvoker.GetValue((BusinessObject)t, formula.SumChildFieldName)));
                    }
                }

                if (formula.IsVariable && lstVariables.ContainsKey(formula.FormulaName) == false)
                {
                    lstVariables.Add(formula.FormulaName, Math.Round(Convert.ToDouble(objAmt), 3));
                }

                bool isCalculatedWithCurrentFormula = false;
                if (!formula.IsVariable && DataStructureProvider.IsTableColumn(obj.AATableName, formula.FormulaName))
                {
                    if (objAmt != null)
                    {
                        if (objAmt is double)
                        {
                            objAmt = Math.Round(Convert.ToDouble(objAmt), 3);
                        }

                        if (ABCDynamicInvoker.GetValue(obj, formula.FormulaName).ToString() != objAmt.ToString())
                        {
                            ABCDynamicInvoker.SetValue(obj, formula.FormulaName, objAmt);
                            isCalculatedWithCurrentFormula = true;
                        }
                    }
                }


                if (voucher != null && formula.IsCustomByCode)
                {
                    isCalculatedWithCurrentFormula = voucher.CustomFormulaCalc(obj, lstObjecItems, formula);
                }

                isCalculated = isCalculated | isCalculatedWithCurrentFormula;

                if (isCalculatedWithCurrentFormula && !string.IsNullOrWhiteSpace(formula.FieldRelations))
                {
                    foreach (String strRelation in formula.FieldRelations.Split(';').ToList())
                    {
                        if (FormulasList[obj.AATableName].Values.Count(t => t.FormulaName == strRelation) > 0)
                        {
                            int?iIndex = FormulasList[obj.AATableName].Values.Where(t => t.FormulaName == strRelation).Select(t => t.CalcIndex).First();
                            if (!iIndex.HasValue)
                            {
                                continue;
                            }

                            if (FormulasList[obj.AATableName].Values.Count(t => t.CalcIndex == iIndex.Value - 1) > 0)
                            {
                                iIndex = FormulasList[obj.AATableName].Values.Where(t => t.CalcIndex == iIndex.Value - 1).Select(t => t.CalcIndex).First();
                                if (!iIndex.HasValue)
                                {
                                    continue;
                                }

                                CalculateMainOnly(voucher, obj, lstObjecItems, strRelation, isSave);
                            }
                        }
                    }
                }
            }

            if (isCalculated && obj.GetID() != null && isSave)
            {
                BusinessControllerFactory.GetBusinessController(obj.AATableName).UpdateObject(obj);

                if (!CalculateQueue.ContainsKey(obj.AATableName))
                {
                    CalculateQueue.Add(obj.AATableName, new List <Guid>());
                }

                if (!CalculateQueue[obj.AATableName].Contains(obj.GetID()))
                {
                    CalculateQueue[obj.AATableName].Add(obj.GetID());

                    if (DataStructureProvider.DataTablesList.ContainsKey(obj.AATableName))
                    {
                        foreach (String strFkCol in DataStructureProvider.DataTablesList[obj.AATableName].ForeignColumnsList.Keys)
                        {
                            Guid fkID = ABCHelper.DataConverter.ConvertToGuid(ABCDynamicInvoker.GetValue(obj, strFkCol));
                            if (fkID == Guid.Empty)
                            {
                                continue;
                            }

                            BusinessObjectController FKCtrl = BusinessControllerFactory.GetBusinessController(DataStructureProvider.GetTableNameOfForeignKey(obj.AATableName, strFkCol));
                            if (FKCtrl != null)
                            {
                                BusinessObject fkObj = FKCtrl.GetObjectByID(fkID);
                                if (fkObj != null)
                                {
                                    Calculate(fkObj, true);
                                }
                            }
                        }
                    }

                    if (!CalculateQueue.ContainsKey(obj.AATableName))
                    {
                        CalculateQueue.Add(obj.AATableName, new List <Guid>());
                    }

                    if (!CalculateQueue[obj.AATableName].Contains(obj.GetID()))
                    {
                        CalculateQueue[obj.AATableName].Remove(obj.GetID());
                    }
                }
            }

            return(isCalculated);
        }