Beispiel #1
0
        public string NewCodeGenerate(CardType cardType, Expression <Func <T, string> > filter,
                                      Expression <Func <T, bool> > where = null)
        {
            string Code()
            {
                string code      = null;
                var    codeArray = cardType.ToName().Split(' ');

                for (int i = 0; i < codeArray.Length; i++)
                {
                    code += codeArray[i];

                    if (i + 1 < codeArray.Length - 1)
                    {
                        code += " ";
                    }
                }

                return(code += "-0001");
            }

            string newCodeGenerateString(string code)
            {
                var numericalVariables = "";

                foreach (var character in code)
                {
                    if (char.IsDigit(character))
                    {
                        numericalVariables += character;
                    }
                    else
                    {
                        numericalVariables = "";
                    }
                }

                var increasedValue = (int.Parse(numericalVariables) + 1).ToString();
                var difference     = code.Length - increasedValue.Length;

                if (difference < 0)
                {
                    difference = 0;
                }

                var newVariable = code.Substring(0, difference);

                newVariable += increasedValue;

                return(newVariable);
            }

            var maxCode = where == null?_dbSet.Max(filter) : _dbSet.Where(where).Max(filter);

            return(maxCode == null?Code() : newCodeGenerateString(maxCode));
        }
 protected bool BaseDelete(BaseEntity entity, CardType cardType, bool messageShow = true)
 {
     GeneralFunctions.CreateUnitOfWork <T, TContext>(ref _unitOfWork);
     if (messageShow)
     {
         if (Messages.DeleteMessage(cardType.ToName()) != DialogResult.Yes)
         {
             return(false);
         }
     }
     _unitOfWork.Rep.Delete(entity.EntityConvert <T>());
     return(_unitOfWork.Save());
 }