Exemple #1
0
        public static AccrossStructInfo GetAccrossStructInfo(String strTableName, String strFieldString)
        {
            AccrossStructInfo result = new AccrossStructInfo();

            result.FieldName = strFieldString;
            result.TableName = strTableName;

            String[] strArr = strFieldString.Split(':');
            if (strArr.Length <= 1)
            {
                return(result);
            }

            result.FieldName = strArr[0];
            result.TableName = strTableName;

            for (int i = 1; i < strArr.Length; i++)
            {
                if (DataStructureProvider.IsForeignKey(result.TableName, result.FieldName) == false)
                {
                    break;
                }

                result.TableName = DataStructureProvider.GetTableNameOfForeignKey(result.TableName, result.FieldName);
                result.FieldName = strArr[i];
            }

            if (DataStructureProvider.IsForeignKey(result.TableName, result.FieldName))
            {
                result.TableName = DataStructureProvider.GetTableNameOfForeignKey(result.TableName, result.FieldName);
                result.FieldName = DataStructureProvider.GetDisplayColumn(result.TableName);
            }

            return(result);
        }
Exemple #2
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));
        }
        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);
        }
Exemple #4
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);
        }
Exemple #5
0
        public void AddParameterForObject(BusinessObject obj, DbCommand cmd)
        {
            Database db = CurrentDatabase;

            if (CurrentDatabase == null)
            {
                if (DataStructureProvider.IsQuerySystemDB(cmd.CommandText))
                {
                    db = DataQueryProvider.SystemDatabase;
                }
                else
                {
                    db = DataQueryProvider.CompanyDatabase;
                }
            }

            if (cmd.Parameters.Count == 0)
            {
                BusinessObjectHelper.InitPropertyList(obj.AATableName);
                foreach (PropertyInfo property in BusinessObjectHelper.PropertyList[obj.AATableName].Values)
                {
                    if (property.Name == DataStructureProvider.GetPrimaryKeyColumn(obj.AATableName) && cmd.CommandText.Contains("Insert"))
                    {
                        db.AddOutParameter(cmd, property.Name, DbType.Guid, 64);
                        //     AddOutParameter( cmd , property.Name , SqlDbType.Int , 8 );
                    }
                    else
                    {
                        object objValue = ABCBusinessEntities.ABCDynamicInvoker.GetValue(obj, property);
                        if (DataStructureProvider.IsForeignKey(obj.AATableName, property.Name))
                        {
                            if (objValue == null || ABCHelper.DataConverter.ConvertToGuid(objValue) == Guid.Empty)
                            {
                                objValue = DBNull.Value;
                            }
                        }

                        if (objValue == null)
                        {
                            objValue = DBNull.Value;
                        }

                        AddInParameter(cmd, property, objValue);
                    }
                }
            }
            else
            {
                foreach (DbParameter param in cmd.Parameters)
                {
                    if (param.Direction == ParameterDirection.Input)
                    {
                        String strFieldName = param.ParameterName.Replace("@", "");

                        object objValue = ABCBusinessEntities.ABCDynamicInvoker.GetValue(obj, strFieldName);
                        if (DataStructureProvider.IsForeignKey(obj.AATableName, strFieldName))
                        {
                            if (objValue == null || ABCHelper.DataConverter.ConvertToGuid(objValue) == Guid.Empty)
                            {
                                objValue = DBNull.Value;
                            }
                        }

                        if (objValue == null)
                        {
                            objValue = DBNull.Value;
                        }

                        if (param.Value != objValue && objValue.ToString() != param.Value.ToString())
                        {
                            db.SetParameterValue(cmd, param.ParameterName, objValue);
                        }
                    }
                }
            }
        }
Exemple #6
0
        public static void GenerateDefaultTableConfig( )
        {
            String strCheckCondition = String.Empty;

            if (DataQueryProvider.IsSQLConnection("STTableConfigs"))
            {
                strCheckCondition = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME='STTableConfigs'";
            }
            else
            {
                strCheckCondition = "SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name='STTableConfigs'";
            }

            DataSet dsTemp = DataQueryProvider.RunQuery(strCheckCondition);

            if (dsTemp == null || dsTemp.Tables.Count <= 0 || dsTemp.Tables[0].Rows.Count <= 0)
            {
                return;
            }

            #region Clean First
            DataSet ds2 = DataQueryProvider.SystemDatabaseHelper.RunQuery("SELECT STTableConfigID,TableName FROM  STTableConfigs ");
            if (ds2 != null && ds2.Tables.Count > 0)
            {
                foreach (DataRow dr in ds2.Tables[0].Rows)
                {
                    if (String.IsNullOrWhiteSpace(dr[0].ToString()) == false)
                    {
                        Guid iID = Guid.Empty;
                        Guid.TryParse(dr[0].ToString(), out iID);

                        String strTableName = dr[1].ToString();
                        if (DataStructureProvider.DataTablesList.ContainsKey(strTableName) == false)
                        {
                            DataQueryProvider.SystemDatabaseHelper.RunQuery(String.Format("DELETE FROM STTableConfigs WHERE STTableConfigID='{0}'", iID.ToString()));
                        }
                    }
                }
            }

            ds2 = DataQueryProvider.SystemDatabaseHelper.RunQuery("SELECT STFieldConfigID,TableName,FieldName FROM  STFieldConfigs ");
            if (ds2 != null && ds2.Tables.Count > 0)
            {
                foreach (DataRow dr in ds2.Tables[0].Rows)
                {
                    if (String.IsNullOrWhiteSpace(dr[0].ToString()) == false)
                    {
                        Guid iID = Guid.Empty;
                        Guid.TryParse(dr[0].ToString(), out iID);
                        String strTableName = dr[1].ToString();
                        String strFieldName = dr[2].ToString();
                        if (DataStructureProvider.DataTablesList.ContainsKey(strTableName) == false ||
                            DataStructureProvider.DataTablesList[strTableName].ColumnsList.ContainsKey(strFieldName) == false)
                        {
                            DataQueryProvider.SystemDatabaseHelper.RunQuery(String.Format("DELETE FROM STFieldConfigs WHERE STFieldConfigID='{0}'", iID.ToString()));
                        }
                    }
                }
            }
            #endregion

            foreach (String strTableName in DataStructureProvider.DataTablesList.Keys)
            {
                #region Table Config
                DataSet ds = DataQueryProvider.SystemDatabaseHelper.RunQuery(String.Format("SELECT COUNT(*) FROM  STTableConfigs WHERE TableName='{0}'", strTableName));
                if (ds == null || ds.Tables.Count <= 0 || ds.Tables[0].Rows.Count <= 0 || Convert.ToInt32(ds.Tables[0].Rows[0][0]) <= 0)
                {
                    String strQuery = QueryTemplateGenerator.GenInsert("STTableConfigs");
                    strQuery = strQuery.Replace("@STTableConfigID", "'" + Guid.Empty.ToString() + "'");
                    strQuery = strQuery.Replace("@TableName", "'" + strTableName + "'");

                    String s = strTableName.Substring(2, strTableName.Length - 2);
                    //var r=new System.Text.RegularExpressions.Regex( @"(?<=[A-Z])(?=[A-Z][a-z]) |(?<=[^A-Z])(?=[A-Z]) |(?<=[A-Za-z])(?=[^A-Za-z])" , System.Text.RegularExpressions.RegexOptions.IgnorePatternWhitespace );
                    //s=r.Replace( s , " " );


                    strQuery = strQuery.Replace("@CaptionVN", "'" + s + "'");
                    strQuery = strQuery.Replace("@CaptionEN", "'" + s + "'");
                    strQuery = strQuery.Replace("@DescriptionVN", "''");
                    strQuery = strQuery.Replace("@DescriptionEN", "''");
                    strQuery = strQuery.Replace("@IsCaching", "0");
                    strQuery = strQuery.Replace("@CalcOnClient", "1");
                    strQuery = strQuery.Replace("@DeleteByOwnerOnly", "0");
                    strQuery = strQuery.Replace("@EditByOwnerOnly", "0");
                    DataQueryProvider.SystemDatabaseHelper.RunScript(strQuery);
                }
                #endregion

                #region Field Config
                List <String> lstConfig = new List <String>();

                ds = DataQueryProvider.SystemDatabaseHelper.RunQuery(String.Format("SELECT STFieldConfigID,FieldName FROM  STFieldConfigs WHERE TableName='{0}'", strTableName));
                if (ds != null && ds.Tables.Count > 0)
                {
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        if (String.IsNullOrWhiteSpace(dr[1].ToString()) == false)
                        {
                            if (lstConfig.Contains(dr[1].ToString()) == false)
                            {
                                lstConfig.Add(dr[1].ToString());
                            }
                            else
                            {
                                Guid iID = Guid.Empty;
                                Guid.TryParse(dr[0].ToString(), out iID);
                                DataQueryProvider.SystemDatabaseHelper.RunQuery(String.Format("DELETE FROM STFieldConfigs WHERE STFieldConfigID='{0}'", strTableName));
                            }
                        }
                    }
                }

                int iCount = -1;
                foreach (String strColName in DataStructureProvider.DataTablesList[strTableName].ColumnsList.Keys)
                {
                    if (DataStructureProvider.IsPrimaryKey(strTableName, strColName))
                    {
                        continue;
                    }

                    iCount++;
                    if (lstConfig.Contains(strColName) == false)
                    {
                        String strQuery = QueryTemplateGenerator.GenInsert("STFieldConfigs");
                        Guid   iID      = Guid.NewGuid();
                        strQuery = strQuery.Replace("@STFieldConfigID", "'" + iID.ToString() + "'");
                        strQuery = strQuery.Replace("@TableName", "'" + strTableName + "'");
                        strQuery = strQuery.Replace("@FieldName", "'" + strColName + "'");
                        if (DataStructureProvider.IsForeignKey(strTableName, strColName))
                        {
                            String strFKTableName = DataStructureProvider.GetTableNameOfForeignKey(strTableName, strColName);
                            String strCaptionVN   = GetTableCaption(strFKTableName);
                            if (String.IsNullOrWhiteSpace(strCaptionVN))
                            {
                                strCaptionVN = strFKTableName.Substring(2, strFKTableName.Length - 3);
                            }
                            //var r=new System.Text.RegularExpressions.Regex( @"(?<=[A-Z])(?=[A-Z][a-z]) |(?<=[^A-Z])(?=[A-Z]) |(?<=[A-Za-z])(?=[^A-Za-z])" , System.Text.RegularExpressions.RegexOptions.IgnorePatternWhitespace );
                            //strCaptionVN=r.Replace( strCaptionVN , " " );

                            strQuery = strQuery.Replace("@CaptionVN", String.Format("N'{0}'", strCaptionVN));
                            strQuery = strQuery.Replace("@CaptionEN", "'" + strFKTableName.Substring(2, strFKTableName.Length - 3) + "'");
                        }
                        else
                        {
                            strQuery = strQuery.Replace("@CaptionVN", String.Format("N'{0}'", GetFieldCaptionFromDictionary(strColName)));
                            strQuery = strQuery.Replace("@CaptionEN", "'" + strColName + "'");
                            if (DataStructureProvider.IsNOColumn(strTableName, strColName))
                            {
                                String strTableCap = GetTableCaption(strTableName);
                                if (!String.IsNullOrWhiteSpace(strTableCap))
                                {
                                    strQuery = strQuery.Replace("@CaptionVN", String.Format("N'{0}'", strTableCap));
                                }
                            }
                        }
                        strQuery = strQuery.Replace("@DescriptionVN", "''");
                        strQuery = strQuery.Replace("@DescriptionEN", "''");
                        if (strColName.Equals("ABCStatus") || strColName.Equals("EditCount") ||
                            strColName.Equals("CreateTime") || strColName.Equals("CreateUser") ||
                            strColName.Equals("UpdateTime") || strColName.Equals("UpdateUser") ||
                            strColName.Equals("NoIndex") || strColName.Equals("LastCalcDate"))
                        {
                            strQuery = strQuery.Replace("@InUse", "0");
                        }
                        else
                        {
                            strQuery = strQuery.Replace("@InUse", "1");
                        }

                        if (DataStructureProvider.IsNOColumn(strTableName, strColName) ||
                            DataStructureProvider.IsNAMEColumn(strTableName, strColName) ||
                            DataStructureProvider.IsDisplayColumn(strTableName, strColName))
                        {
                            strQuery = strQuery.Replace("@IsDefault", "1");
                        }
                        else
                        {
                            strQuery = strQuery.Replace("@IsDefault", "0");
                        }

                        strQuery = strQuery.Replace("@AssignedEnum", "''");
                        strQuery = strQuery.Replace("@FilterString", "''");
                        strQuery = strQuery.Replace("@SortOrder", String.Format("{0}", iCount));

                        if (DataStructureProvider.IsNOColumn(strTableName, strColName) ||
                            DataStructureProvider.IsNAMEColumn(strTableName, strColName))
                        {
                            strQuery = strQuery.Replace("@IsDisplayField", "1");
                        }
                        else
                        {
                            strQuery = strQuery.Replace("@IsDisplayField", "0");
                        }

                        strQuery = strQuery.Replace("@IsDisplayField", "0");
                        strQuery = strQuery.Replace("@IsGrouping", "0");

                        #region DataFormatProvider.FieldFormat
                        String strTypeName = DataStructureProvider.GetCodingType(strTableName, strColName);
                        DataFormatProvider.FieldFormat format = DataFormatProvider.FieldFormat.None;

                        if (strTypeName == "DateTime" || strTypeName == "Nullable<DateTime>")
                        {
                            format = DataFormatProvider.FieldFormat.Date;
                        }

                        if ((strTypeName == "int" || strTypeName == "Nullable<int>" || strTypeName == "Guid" || strTypeName == "Nullable<Guid>") && strColName.ToUpper().Contains("FK_") == false &&
                            DataStructureProvider.IsForeignKey(strTableName, strColName) == false &&
                            DataStructureProvider.IsPrimaryKey(strTableName, strColName) == false)
                        {
                            format = DataFormatProvider.FieldFormat.Quantity;
                        }

                        if (strTypeName == "double" || strTypeName == "decimal")
                        {
                            if (strColName.ToLower().Contains("amt") || strColName.ToLower().Contains("fee") || strColName.ToLower().Contains("cost") ||
                                strColName.ToLower().Contains("expense") || strColName.ToLower().Contains("pay") || strColName.ToLower().Contains("tax") ||
                                strColName.ToLower().Contains("gross") || strColName.ToLower().Contains("net") ||
                                strColName.ToLower().Contains("amount") || strColName.ToLower().Contains("exchange"))
                            {
                                format = DataFormatProvider.FieldFormat.Currency;
                            }
                            else
                            {
                                format = DataFormatProvider.FieldFormat.Amount;
                            }
                        }

                        if (format != DataFormatProvider.FieldFormat.None)
                        {
                            strQuery = strQuery.Replace("@Format", String.Format("'{0}'", format.ToString()));
                        }
                        else
                        {
                            strQuery = strQuery.Replace("@Format", "''");
                        }

                        #endregion

                        DataQueryProvider.SystemDatabaseHelper.RunScript(strQuery);
                    }
                }

                foreach (String strColName in lstConfig)
                {
                    if (DataStructureProvider.DataTablesList[strTableName].ColumnsList.ContainsKey(strColName) == false)
                    {
                        DataQueryProvider.SystemDatabaseHelper.RunQuery(String.Format("DELETE  FROM  STFieldConfigs WHERE TableName='{0}' AND FieldName='{1}'", strTableName, strColName));
                    }
                }
                #endregion
            }
        }
Exemple #7
0
        public static void InvalidateConfigList( )
        {
            String strCheckCondition = String.Empty;

            if (DataQueryProvider.IsSQLConnection("STTableConfigs"))
            {
                strCheckCondition = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME='STTableConfigs'";
            }
            else
            {
                strCheckCondition = "SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name='STTableConfigs'";
            }

            DataSet dsTemp = DataQueryProvider.RunQuery(strCheckCondition);

            if (dsTemp == null || dsTemp.Tables.Count <= 0 || dsTemp.Tables[0].Rows.Count <= 0)
            {
                return;
            }

            TableConfigList.Clear();

            #region Init ConfigList

            #region Field Config
            DataSet ds = DataQueryProvider.SystemDatabaseHelper.RunQuery(@"SELECT * FROM STFieldConfigs");
            if (ds != null && ds.Tables.Count > 0)
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    TableConfig tableConfig  = null;
                    String      strTableName = dr["TableName"].ToString();
                    if (TableConfigList.TryGetValue(strTableName, out tableConfig) == false)
                    {
                        tableConfig = new TableConfig();
                        TableConfigList.Add(strTableName, tableConfig);
                    }
                    if (tableConfig.FieldConfigList.ContainsKey(dr["FieldName"].ToString()) == false)
                    {
                        #region Field
                        FieldConfig config = new FieldConfig();
                        config.ConfigID  = ABCHelper.DataConverter.ConvertToGuid(dr["STFieldConfigID"]);
                        config.FieldName = dr["FieldName"].ToString();
                        config.CaptionVN = dr["CaptionVN"].ToString();
                        config.CaptionEN = dr["CaptionEN"].ToString();
                        config.DescVN    = dr["DescriptionVN"].ToString();
                        config.DescEN    = dr["DescriptionEN"].ToString();
                        config.TypeName  = DataStructureProvider.GetCodingType(strTableName, config.FieldName);

                        config.InUse = false;
                        if (dr["InUse"] != DBNull.Value)
                        {
                            config.InUse = Convert.ToBoolean(dr["InUse"]);
                        }

                        if (dr["IsDefault"] != DBNull.Value)
                        {
                            config.IsDefault = Convert.ToBoolean(dr["IsDefault"]);
                        }

                        if (dr["IsDisplayField"] != DBNull.Value)
                        {
                            config.IsDisplayField = Convert.ToBoolean(dr["IsDisplayField"]);
                        }

                        if (dr["IsGrouping"] != DBNull.Value)
                        {
                            config.IsGrouping = Convert.ToBoolean(dr["IsGrouping"]);
                        }

                        if (dr["AssignedEnum"] != DBNull.Value)
                        {
                            config.AssignedEnum = dr["AssignedEnum"].ToString();
                        }

                        if (dr["FilterString"] != DBNull.Value)
                        {
                            config.FilterString = dr["FilterString"].ToString();
                        }

                        if (dr["SortOrder"] != DBNull.Value)
                        {
                            config.SortOrder = Convert.ToInt32(dr["SortOrder"]);
                        }

                        #region FieldFormat
                        if (Enum.IsDefined(typeof(DataFormatProvider.FieldFormat), dr["Format"].ToString()))
                        {
                            DataFormatProvider.FieldFormat format = (DataFormatProvider.FieldFormat)Enum.Parse(typeof(DataFormatProvider.FieldFormat), dr["Format"].ToString());
                            if (format != DataFormatProvider.FieldFormat.None)
                            {
                                config.Format = format;
                            }
                            else
                            {
                                if (config.TypeName == "DateTime" || config.TypeName == "Nullable<DateTime>")
                                {
                                    config.Format = DataFormatProvider.FieldFormat.Date;
                                }
                                if ((config.TypeName == "int" || config.TypeName == "Nullable<int>") && config.FieldName.ToUpper().Contains("FK_") == false &&
                                    DataStructureProvider.IsForeignKey(strTableName, config.FieldName) == false &&
                                    DataStructureProvider.IsPrimaryKey(strTableName, config.FieldName) == false)
                                {
                                    config.Format = DataFormatProvider.FieldFormat.Quantity;
                                }
                                if (config.TypeName == "double" || config.TypeName == "decimal")
                                {
                                    if (config.FieldName.ToLower().Contains("amt") || config.FieldName.ToLower().Contains("amount") || config.FieldName.ToLower().Contains("exchange"))
                                    {
                                        config.Format = DataFormatProvider.FieldFormat.Currency;
                                    }
                                    else
                                    {
                                        config.Format = DataFormatProvider.FieldFormat.Amount;
                                    }
                                }
                            }
                        }
                        #endregion

                        tableConfig.FieldConfigList.Add(config.FieldName, config);
                        #endregion
                    }
                }
            }
            #endregion

            #region Table Config
            ds = DataQueryProvider.SystemDatabaseHelper.RunQuery(@"SELECT * FROM STTableConfigs");
            if (ds != null && ds.Tables.Count > 0)
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    TableConfig tableConfig  = null;
                    String      strTableName = dr["TableName"].ToString();
                    if (TableConfigList.TryGetValue(strTableName, out tableConfig))
                    {
                        tableConfig.ConfigID  = ABCHelper.DataConverter.ConvertToGuid(dr["STTableConfigID"]);
                        tableConfig.TableName = strTableName;
                        tableConfig.CaptionVN = dr["CaptionVN"].ToString();
                        tableConfig.CaptionEN = dr["CaptionEN"].ToString();
                        tableConfig.DescVN    = dr["DescriptionVN"].ToString();
                        tableConfig.DescEN    = dr["DescriptionEN"].ToString();

                        if (dr["IsCaching"] != DBNull.Value)
                        {
                            tableConfig.IsCaching = Convert.ToBoolean(dr["IsCaching"]);
                        }
                        else
                        {
                            tableConfig.IsCaching = false;
                        }
                    }
                }
            }
            #endregion

            #endregion
        }
Exemple #8
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);
        }