Beispiel #1
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);
        }