Inheritance: MonoBehaviour
Exemple #1
0
		public void CastCreate()
		{
			var cast = new Cast(PrimitiveType.Word32, Constant.Real32(3.0F));
			var p = (PrimitiveType) cast.DataType;
			Assert.AreEqual(PrimitiveType.Word32, p);
			Assert.AreEqual(PrimitiveType.Real32, cast.Expression.DataType);
		}
Exemple #2
0
            private static Pair<Expression, Expression> UsualArithmeticConversions(
				Expression lop, Expression rop)
            {
                Symbols.Type lt = lop.GetType(), rt = rop.GetType();

                if (lt is Symbols.DOUBLE || rt is Symbols.DOUBLE)
                {
                    if (rt != lt)
                    {
                        if (lt is Symbols.DOUBLE) { rop = new Cast(rop, lt); }
                        else { lop = new Cast(lop, rt); }
                    }
                }
                else if (lt is Symbols.CHAR && rt is Symbols.INT) { lop = new Cast(lop, rt); }
                else if (rt is Symbols.CHAR && lt is Symbols.INT) { rop = new Cast(rop, lt); }

                return new Pair<Expression, Expression>(lop, rop);
            }
        public ActionResult Index(FormCollection collection, MovieGameModel model)
        {
            model.FirstLoad = false;

            Movie movie = new Movie();
            movie = model.GetMovieWithCast(model.Movie);

            if (movie != null)
            {
                model.Total = 1;
                model.Title = movie.title;
                model.Thumbnail = movie.posters.thumbnail;
            }
            Cast c = new Cast();
            c = movie.abridged_cast.Where(x => x.name.ToLower() == model.Actor.ToLower()).FirstOrDefault();
            if (c != null)
            {
                model.isIn = true;
                model.CharacterName = c.characters.FirstOrDefault();
            }

            return View(model);
        }
Exemple #4
0
        public bool Match(Cast c)
        {
            this.c = c;
            var cc = c.Expression as Cast;
            if (cc == null)
                return false;
            this.origExp = cc.Expression;

            this.ptC = c.DataType as PrimitiveType;
            this.ptCc = cc.DataType as PrimitiveType;
            this.ptExp = origExp.DataType as PrimitiveType;
            if (ptC == null || ptCc == null || ptExp == null)
                return false;
            // Only match widening / narrowing. 
            //$TODO: the Cast() class should really not appear
            // until after type analysis. It should be replaced
            // by a Convert(dtFrom, dtTo) expression which more
            // accurately models what is going on.
            if (ptC.Domain != ptCc.Domain || ptC.Domain != ptExp.Domain)
                return false;
            //$TODO: for now, only eliminate the casts if the 
            // original size == new size.
            return ptC.Size == ptExp.Size && ptC.Size <= ptCc.Size;
        }
Exemple #5
0
        /// <summary>
        /// Inserts or updates multiple instances of Shipper class on the database table "core.shippers";
        /// </summary>
        /// <param name="shippers">List of "Shipper" class to import.</param>
        /// <returns></returns>
        public List <object> BulkImport(List <ExpandoObject> shippers)
        {
            if (!this.SkipValidation)
            {
                if (!this.Validated)
                {
                    this.Validate(AccessTypeEnum.ImportData, this._LoginId, this._Catalog, false);
                }

                if (!this.HasAccess)
                {
                    Log.Information("Access to import entity \"Shipper\" was denied to the user with Login ID {LoginId}. {shippers}", this._LoginId, shippers);
                    throw new UnauthorizedException("Access is denied.");
                }
            }

            var result = new List <object>();
            int line   = 0;

            try
            {
                using (Database db = new Database(Factory.GetConnectionString(this._Catalog), Factory.ProviderName))
                {
                    using (Transaction transaction = db.GetTransaction())
                    {
                        foreach (dynamic shipper in shippers)
                        {
                            line++;

                            shipper.audit_user_id = this._UserId;
                            shipper.audit_ts      = System.DateTime.UtcNow;

                            object primaryKeyValue = shipper.shipper_id;

                            if (Cast.To <int>(primaryKeyValue) > 0)
                            {
                                result.Add(shipper.shipper_id);
                                db.Update("core.shippers", "shipper_id", shipper, shipper.shipper_id);
                            }
                            else
                            {
                                result.Add(db.Insert("core.shippers", "shipper_id", shipper));
                            }
                        }

                        transaction.Complete();
                    }

                    return(result);
                }
            }
            catch (NpgsqlException ex)
            {
                string errorMessage = $"Error on line {line} ";

                if (ex.Code.StartsWith("P"))
                {
                    errorMessage += Factory.GetDBErrorResource(ex);

                    throw new MixERPException(errorMessage, ex);
                }

                errorMessage += ex.Message;
                throw new MixERPException(errorMessage, ex);
            }
            catch (System.Exception ex)
            {
                string errorMessage = $"Error on line {line} ";
                throw new MixERPException(errorMessage, ex);
            }
        }
 public void VisitCast(Cast cast)
 {
     cast.Expression.Accept(this);
 }
Exemple #7
0
            public static BinaryConvertResult ConvertBinaryOperands(Expression lop, Expression rop, Token op)
            {
                Symbols.Type lt = lop.GetType(), rt = rop.GetType();
                BinaryConvertResult res = new BinaryConvertResult();
                res.op = op;
                Pair<Expression, Expression> uacon = null;
                switch (op.type)
                {
                    case Token.Type.OP_STAR:
                    case Token.Type.OP_DIV:
                        if (!lt.IsArifmetic())
                        {
                            throw new Symbols.Exception(lop, NOT_ARITHMETICAL);
                        }
                        if (!rt.IsArifmetic())
                        {
                            throw new Symbols.Exception(rop, NOT_ARITHMETICAL);
                        }

                        if (op.type == Token.Type.OP_MOD)
                        {
                            if (!lt.IsArifmetic())
                            {
                                lop = new Cast(lop, new Symbols.INT());
                            }
                            if (!rt.IsArifmetic())
                            {
                                rop = new Cast(rop, new Symbols.INT());
                            }
                            res.type = rop.GetType();
                            break;
                        }
                        uacon = UsualArithmeticConversions(lop, rop);
                        lop = uacon.first;
                        rop = uacon.last;
                        res.type = lop.GetType();
                        break;

                    case Token.Type.OP_MOD:
                        if (!lt.IsInteger())
                        {
                            throw new Symbols.Exception(lop, NOT_INTEGER);
                        }
                        if (!rt.IsInteger())
                        {
                            throw new Symbols.Exception(rop, NOT_INTEGER);
                        }

                        if (op.type == Token.Type.OP_MOD)
                        {
                            if (!(lt is Symbols.INT))
                            {
                                lop = new Cast(lop, new Symbols.INT());
                            }
                            if (!(rt is Symbols.INT))
                            {
                                rop = new Cast(rop, new Symbols.INT());
                            }
                            res.type = rop.GetType();
                            break;
                        }
                        uacon = UsualArithmeticConversions(lop, rop);
                        lop = uacon.first;
                        rop = uacon.last;
                        res.type = lop.GetType();
                        break;

                    case Token.Type.OP_PLUS:
                    case Token.Type.OP_SUB:
                        if (rt is Symbols.POINTER || lt is Symbols.POINTER)
                        {
                            if (rt is Symbols.POINTER && lt is Symbols.POINTER)
                            {
                                if (op.type == Token.Type.OP_PLUS)
                                {
                                    throw new Symbols.Exception(lop, NOT_ARITHMETICAL);
                                }
                                res.type = rt;
                                break;
                            }

                            BinaryOperator binop = new BinaryOperator(new Token(Token.Type.OP_STAR));
                            int size = 0;
                            if (rt is Symbols.POINTER)
                            {
                                lop = lt is Symbols.INT ? lop : new Cast(lop, new Symbols.INT());
                                binop.SetLeftOperand(lop);
                                size = ((Symbols.POINTER)rt).GetRefType().GetSizeType();
                                binop.SetRightOperand(new Const(size.ToString(), new Symbols.INT()));
                                lop = binop;
                                res.type = rt;
                            }
                            else
                            {
                                rop = rt is Symbols.INT ? rop : new Cast(rop, new Symbols.INT());
                                binop.SetLeftOperand(rop);
                                size = ((Symbols.POINTER)lt).GetRefType().GetSizeType();
                                binop.SetRightOperand(new Const(size.ToString(), new Symbols.INT()));
                                rop = binop;
                                res.type = lt;
                            }
                            break;
                        }

                        if (lt.IsArifmetic() || rt.IsArifmetic())
                        {
                            if (!lt.IsArifmetic())
                            {
                                throw new Symbols.Exception(lop, NOT_ARITHMETICAL);
                            }

                            if (!rt.IsArifmetic())
                            {
                                throw new Symbols.Exception(rop, NOT_ARITHMETICAL);
                            }

                            uacon = UsualArithmeticConversions(lop, rop);
                            lop = uacon.first;
                            rop = uacon.last;
                            res.type = lop.GetType();
                            break;
                        }

                        if (lt is Symbols.Func ||
                            (lt is Symbols.POINTER && ((Symbols.POINTER)lt).GetRefType() is Symbols.Func))
                        {
                            throw new Symbols.Exception(lop, NOT_COMPLETE_TYPE);
                        }

                        if (rt is Symbols.Func ||
                            (rt is Symbols.POINTER && ((Symbols.POINTER)rt).GetRefType() is Symbols.Func))
                        {
                            throw new Symbols.Exception(rop, NOT_COMPLETE_TYPE);
                        }

                        throw new Symbols.Exception(lop, string.Format(NO_OPERATOR, op.GetStrVal()));

                    case Token.Type.OP_L_SHIFT:
                    case Token.Type.OP_R_SHIFT:
                    case Token.Type.OP_BIT_AND:
                    case Token.Type.OP_BIT_OR:
                    case Token.Type.OP_XOR:
                        if (!lt.IsInteger())
                        {
                            throw new Symbols.Exception(lop, NOT_ARITHMETICAL);
                        }

                        if (!rt.IsInteger())
                        {
                            throw new Symbols.Exception(rop, NOT_ARITHMETICAL);
                        }
                        uacon = UsualArithmeticConversions(lop, rop);
                        lop = uacon.first;
                        rop = uacon.last;
                        res.type = lop.GetType();
                        break;
                    case Token.Type.OP_MORE:
                    case Token.Type.OP_LESS:
                    case Token.Type.OP_LESS_OR_EQUAL:
                    case Token.Type.OP_MORE_OR_EQUAL:
                    case Token.Type.OP_EQUAL:
                    case Token.Type.OP_NOT_EQUAL:
                        uacon = UsualArithmeticConversions(lop, rop);
                        lop = uacon.first;
                        rop = uacon.last;
                        res.type = lop.GetType();
                        break;

                    case Token.Type.OP_AND:
                    case Token.Type.OP_OR:
                        if (!(lt.IsArifmetic() || lt is Symbols.POINTER))
                        {
                            throw new Symbols.Exception(lop, string.Format(NO_OPERATOR, op.GetStrVal()));
                        }
                        if (!(rt.IsArifmetic() || rt is Symbols.POINTER))
                        {
                            throw new Symbols.Exception(rop, string.Format(NO_OPERATOR, op.GetStrVal()));
                        }
                        uacon = UsualArithmeticConversions(lop, rop);
                        lop = uacon.first;
                        rop = uacon.last;
                        res.type = lop.GetType();
                        break;

                    case Token.Type.OP_ASSIGN:
                        if (!lop.IsLvalue())
                        {
                            throw new Symbols.Exception(lop, NOT_LVALUE);
                        }

                        if (!lt.Equals(rt))
                        {
                            rop = new Cast(rop, lt);
                        }
                        res.type = lop.GetType();
                        break;

                    case Token.Type.COMMA:
                        break;

                    case Token.Type.OP_MUL_ASSIGN:
                    case Token.Type.OP_DIV_ASSIGN:
                    case Token.Type.OP_MOD_ASSIGN:
                    case Token.Type.OP_PLUS_ASSIGN:
                    case Token.Type.OP_SUB_ASSIGN:
                    case Token.Type.OP_L_SHIFT_ASSIGN:
                    case Token.Type.OP_R_SHIFT_ASSIGN:
                    case Token.Type.OP_BIT_AND_ASSIGN:
                    case Token.Type.OP_BIT_OR_ASSIGN:
                    case Token.Type.OP_XOR_ASSIGN:
                        Token.Type tt = Token.Type.OP_STAR;
                        switch (op.type)
                        {
                            case Token.Type.OP_MUL_ASSIGN:
                                tt = Token.Type.OP_STAR;
                                break;
                            case Token.Type.OP_DIV_ASSIGN:
                                tt = Token.Type.OP_DIV;
                                break;
                            case Token.Type.OP_MOD_ASSIGN:
                                tt = Token.Type.OP_MOD;
                                break;
                            case Token.Type.OP_PLUS_ASSIGN:
                                tt = Token.Type.OP_PLUS;
                                break;
                            case Token.Type.OP_SUB_ASSIGN:
                                tt = Token.Type.OP_SUB;
                                break;
                            case Token.Type.OP_L_SHIFT_ASSIGN:
                                tt = Token.Type.OP_L_SHIFT;
                                break;
                            case Token.Type.OP_R_SHIFT_ASSIGN:
                                tt = Token.Type.OP_R_SHIFT;
                                break;
                            case Token.Type.OP_BIT_AND_ASSIGN:
                                tt = Token.Type.OP_BIT_AND;
                                break;
                            case Token.Type.OP_BIT_OR_ASSIGN:
                                tt = Token.Type.OP_BIT_OR;
                                break;
                            case Token.Type.OP_XOR_ASSIGN:
                                tt = Token.Type.OP_XOR;
                                break;
                        }
                        BinaryOperator bop = new BinaryOperator(new Token(tt));
                        bop.SetLeftOperand(lop);
                        bop.SetRightOperand(rop);
                        res.op = new Token(op.GetIndex(), op.GetLine(), Token.Type.OP_ASSIGN, "=");
                        BinaryOperator assign = new BinaryOperator(res.op);
                        assign.SetLeftOperand(lop);
                        assign.SetRightOperand(bop);
                        BinaryConvertResult r = ConvertBinaryOperands(lop, bop, res.op);
                        rop = r.right;
                        lop = r.left;
                        res.type = lop.GetType();
                        break;

                    default:
                        throw new System.NotImplementedException();
                }

                res.left = lop;
                res.right = rop;
                return res;
            }
Exemple #8
0
 protected override IExpression ProjectAsNonConstantIExpression()
 {
     if (this.cachedProjection == null) {
     object member = this.ResolveAsValueContainer(true);
     INestedTypeDefinition groupType = member as INestedTypeDefinition;
     if (groupType != null) {
       // expression refers to a group
       Cast cast = new Cast(new Parenthesis(this.Instance, this.SourceLocation), TypeExpression.For(this.Type), this.SourceLocation);
       cast.SetContainingExpression(this);
       // TODO the projection of cast looses its source location, it only retains the source location of the casted expression,
       // so we stick the proper location on the casted expression itself
       return this.cachedProjection = cast.ProjectAsIExpression();
     }
     IFieldDefinition fieldDef = member as IFieldDefinition;
     if (fieldDef != null) {
       var addrOf = new VccAddressOf(new AddressableExpression(new ProjectionHelper(this.Qualifier, this.SimpleName, fieldDef, this.SourceLocation)), this.SourceLocation);
       addrOf.SetContainingExpression(this);
       return this.cachedProjection = addrOf.ProjectAsIExpression();
     }
     this.cachedProjection = new DummyExpression(this.SourceLocation);
       }
       return this.cachedProjection;
 }
Exemple #9
0
 private Expression ParseCastExpression(TokenSet followers)
   //^ requires this.currentToken == Token.LeftParenthesis;
   //^ ensures followers[this.currentToken] || this.currentToken == Token.EndOfFile;
 {
   SourceLocationBuilder slb = new SourceLocationBuilder(this.scanner.SourceLocationOfLastScannedToken);
   int position = this.scanner.CurrentDocumentPosition();
   this.GetNextToken();
   List<IErrorMessage> savedErrors = this.scannerAndParserErrors;
   this.scannerAndParserErrors = new List<IErrorMessage>(0);
   TypeExpression targetType = this.ParseTypeExpression(false, false, followers|Token.RightParenthesis);
   bool isCast = false;
   bool isLambda = false;
   if (this.currentToken == Token.RightParenthesis && this.scannerAndParserErrors.Count == 0) {
     if (targetType is NamedTypeExpression) {
       Token nextTok = this.PeekNextToken();
       isCast = Parser.CastFollower[nextTok];
       isLambda = nextTok == Token.Lambda;
     } else
       //Parsed a type expression that cannot also be a value expression.
       isCast = true;
   }
   this.scannerAndParserErrors = savedErrors;
   Expression expression;
   if (!isCast) {
     //Encountered an error while trying to parse (type expr) and there is some reason to be believe that this might not be a type argument list at all.
     //Back up the scanner and let the caller carry on as if it knew that < is the less than operator
     this.scanner.RestoreDocumentPosition(position);
     this.currentToken = Token.None;
     this.GetNextToken();
     if (isLambda)
       expression = this.ParseLambda(followers);
     else
       expression = this.ParseParenthesizedExpression(true, followers);
   } else {
     this.Skip(Token.RightParenthesis);
     Expression valueToCast = this.ParseUnaryExpression(followers);
     slb.UpdateToSpan(valueToCast.SourceLocation);
     expression = new Cast(valueToCast, targetType, slb);
   }
   for (; ; ) {
     switch (this.currentToken) {
       case Token.Arrow:
       case Token.Dot:
       case Token.LeftBracket:
         expression = this.ParseIndexerCallOrSelector(expression, followers);
         break;
       default:
         goto done;
     }
   }
 done:
   this.SkipTo(followers);
   return expression;
 }
Exemple #10
0
void case_645()
#line 4619 "cs-parser.jay"
{
		yyVal = new Cast ((FullNamedExpression) yyVals[-2+yyTop], (Expression) yyVals[0+yyTop], GetLocation (yyVals[-3+yyTop]));
		lbag.AddLocation (yyVal, GetLocation (yyVals[-1+yyTop]));
	  }
Exemple #11
0
            public void Cast(Cast cast)
            {
                cast.Operand.Accept(this);

                _compiler.ExtendedConvertToType(cast.Operand.Type, cast.Type, true);
            }
Exemple #12
0
        public Expression VisitPointer(Pointer ptr)
        {
            Expression e = c;

            if (IsSegmentPointer(ptr))
            {
                Identifier segID;
                if (mpSelectorToSegId.TryGetValue(c.ToUInt16(), out segID))
                {
                    return(segID);
                }
                return(e);
            }
            else if (GlobalVars != null)
            {
                // Null pointer.
                if (c.IsZero)
                {
                    var np = Address.Create(ptr, 0);
                    np.TypeVariable = c.TypeVariable;
                    np.DataType     = c.DataType;
                    return(np);
                }

                var addr = program.Platform.MakeAddressFromConstant(c);
                // An invalid pointer -- often used as sentinels in code.
                if (!program.SegmentMap.IsValidAddress(addr))
                {
                    //$TODO: probably should use a reinterpret_cast here.
                    var ce = new Cast(c.DataType, c);
                    ce.TypeVariable = c.TypeVariable;
                    ce.DataType     = ptr;
                    return(ce);
                }

                var dt = ptr.Pointee.ResolveAs <DataType>();
                if (IsCharPtrToReadonlySection(c, dt))
                {
                    PromoteToCString(c, dt);
                    return(ReadNullTerminatedString(c, dt));
                }
                StructureField f          = EnsureFieldAtOffset(GlobalVars, dt, c.ToInt32());
                var            ptrGlobals = new Pointer(GlobalVars, platform.PointerType.Size);
                e = new FieldAccess(ptr.Pointee, new Dereference(ptrGlobals, globals), f);
                if (dereferenced)
                {
                    e.DataType = ptr.Pointee;
                }
                else
                {
                    var array = f.DataType as ArrayType;
                    if (array != null) // C language rules 'promote' arrays to pointers.
                    {
                        e.DataType = program.TypeFactory.CreatePointer(
                            array.ElementType,
                            platform.PointerType.Size);
                    }
                    else
                    {
                        e = new UnaryExpression(Operator.AddrOf, ptr, e);
                    }
                }
            }
            return(e);
        }
Exemple #13
0
 private Cast FetchCast(Cast c)
 {
     c.Fetch ();
     return c;
 }
 void CAST(out pBaseLangObject outObj, pBaseLangObject parent)
 {
     var obj = new Cast(parent); outObj = obj; VarType vt; pBaseLangObject ident;
     if (la.kind == 19) {
         Get();
         obj.isStaticCast = true;
         if (StartOf(2)) {
             VARTYPE(out vt);
             obj.varType = new VarTypeObject(vt);
         } else if (StartOf(1)) {
             IDENTACCESS(out ident, obj);
             obj.varType = new VarTypeObject((Ident)ident);
         } else SynErr(81);
         Expect(19);
     } else if (la.kind == 20) {
         Get();
         obj.isStaticCast = false;
         if (StartOf(2)) {
             VARTYPE(out vt);
             obj.varType = new VarTypeObject(vt);
         } else if (StartOf(1)) {
             IDENTACCESS(out ident, obj);
             obj.varType = new VarTypeObject((Ident)ident);
         } else SynErr(82);
         Expect(20);
     } else SynErr(83);
 }
Exemple #15
0
 public static Cast CastForUrl(Channel c, string  url)
 {
     Cast k = new Cast (c);
     int id = k.IdForUrl (url);
     if (id >= 0) {
         k.id = id;
         k.FromDB ();
         return k;
     } else {
         return null;
     }
 }
 private Instruction MakeAssignment(Expression dst, Expression src)
 {
     src = src.Accept(this);
     var tvDst = dst.TypeVariable;
     dst = dst.Accept(this);
     var dtSrc = DataTypeOf(src);
     var dtDst = DataTypeOf(dst);
     if (!TypesAreCompatible(dtSrc, dtDst))
     {
         UnionType uDst = dtDst.ResolveAs<UnionType>();
         UnionType uSrc = dtSrc.ResolveAs<UnionType>();
         if (uDst != null)
         {
             // ceb = new ComplexExpressionBuilder(dtDst, dtDst, dtSrc, null, dst, null, 0);
             tvDst.DataType = dtDst;
             tvDst.OriginalDataType = dtSrc;
             dst.TypeVariable = tvDst;
             var ceb = new ComplexExpressionBuilder(dtSrc, null, dst, null, 0);
             dst = ceb.BuildComplex(false);
         }
         else if (uSrc != null)
         {
             //throw new NotImplementedException();
             //var ceb = new ComplexExpressionBuilder(dtSrc, dtSrc, dtDst, null, src, null, 0);
             //src = ceb.BuildComplex(false);
             src = new Cast(dtDst, src);
         }
         else
         {
             Debug.Print("{2} [{0}] = {3} [{1}] not supported.", dtDst, dtSrc, dst, src);
             src = new Cast(dtDst, src);
         }
     }
     var idDst = dst as Identifier;
     if (idDst != null)
         return new Assignment(idDst, src);
     else
         return new Store(dst, src);
 }
    public bool MoveNext()
    {
        if (itereader == null) {
            Reset ();
        }

        if (! itereader.Read ()) {
            itereader.Close ();
            itereader = null;
            return false;
        }
        int i = itereader.GetInt32 (0);
        itercast = new Cast (this, i);
        return true;
    }
        public BitRange VisitCast(Cast cast)
        {
            var n = cast.Expression.Accept(this);

            return(new BitRange(n.Lsb, Math.Min(n.Msb, cast.DataType.BitSize)));
        }
 /// <summary>
 /// 获取日期型数值
 /// </summary>
 /// <returns></returns>
 public DateTime GetDateTimeValue()
 {
     return(Cast.DateTime(ValueToString));
 }
Exemple #20
0
 public bool VisitCast(Cast cast, TypeVariable?tv)
 {
     MeetDataType(cast, cast.DataType);
     cast.Expression.Accept(this, cast.Expression.TypeVariable !);
     return(false);
 }
		public override void VisitCast(Cast cast)
		{
			cast.Expression.Accept(this);
			EnsureTypeVariable(cast);
		}
Exemple #22
0
    public static string FormatBool(object value, string trueString, string falseString)
    {
        bool castValue = Cast.Bool(value);

        return(castValue ? trueString : falseString);
    }
Exemple #23
0
 public void AddCast(Cast cast)
 {
     _castRepository.Add(cast);
 }
Exemple #24
0
		public virtual object Visit (Cast castExpression)
		{
			return null;
		}
Exemple #25
0
        /// <summary>
        /// 把数据行转换为ArrivalVouchs实体对象
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
        public static ArrivalVouchs ConvertToArrivalVouchs(DataRow row)
        {
            ArrivalVouchs arrivalVouchs = new ArrivalVouchs();

            arrivalVouchs.ID     = Cast.ToInteger(row["poid"]); //采购订单主表ID
            arrivalVouchs.Autoid = Cast.ToInteger(row["id"]);   //采购订单子表ID

            //是否批次管理
            arrivalVouchs.bInvBatch = Cast.ToBoolean(row["bInvBatch"]);
            //是否保质期管理
            arrivalVouchs.bInvQuality = Cast.ToBoolean(row["bInvQuality"]);

            arrivalVouchs.cVenCode  = Cast.ToString(row["cvencode"]);
            arrivalVouchs.iExchRate = Cast.ToDecimal(row["iexchrate"]);
            //arrivalVouchs.ID = Cast.ToInteger(row["id"]);
            arrivalVouchs.bTaxCost     = Cast.ToBoolean(row["btaxcost"]);
            arrivalVouchs.cInvCode     = Cast.ToString(row["cinvcode"]);
            arrivalVouchs.cInvName     = Cast.ToString(row["cinvname"]);
            arrivalVouchs.cInvStd      = Cast.ToString(row["cinvstd"]);
            arrivalVouchs.cInvm_Unit   = Cast.ToString(row["cinvm_unit"]);
            arrivalVouchs.bGsp         = Cast.ToBoolean(row["bgsp"]);
            arrivalVouchs.iMassDate    = Cast.ToInteger(row["imassdate"]);
            arrivalVouchs.cMassUnit    = Cast.ToInteger(row["cmassunit"]);
            arrivalVouchs.Quantity     = Cast.ToDecimal(row["iquantity"]); //订单数量
            arrivalVouchs.iArrQty      = Cast.ToDecimal(row["iArrQty"]);   //到货数量
            arrivalVouchs.iNum         = Cast.ToDecimal(row["inum"]);
            arrivalVouchs.iInvexchRate = Cast.ToDecimal(row["iinvexchrate"]);

            arrivalVouchs.iunitprice = Cast.ToDecimal(row["iunitprice"]); //原币无税单价
            arrivalVouchs.iTaxPrice  = Cast.ToDecimal(row["iTaxPrice"]);  //原币含税单价
            arrivalVouchs.iTax       = Cast.ToDecimal(row["iTax"]);       //原币税额
            arrivalVouchs.iSum       = Cast.ToDecimal(row["isum"]);       //原币价税合计
            arrivalVouchs.iMoney     = Cast.ToDecimal(row["iMoney"]);     //原币无税金额

            arrivalVouchs.inatunitprice = Cast.ToDecimal(row["inatunitprice"]);
            arrivalVouchs.iVouchRowNo   = Cast.ToInteger(row["ivouchrowno"]);
            arrivalVouchs.inatmoney     = Cast.ToDecimal(row["inatmoney"]);
            arrivalVouchs.inattax       = Cast.ToDecimal(row["inattax"]);
            arrivalVouchs.inatsum       = Cast.ToDecimal(row["inatsum"]);

            arrivalVouchs.iTaxRate    = Cast.ToDecimal(row["itaxrate"]);
            arrivalVouchs.Free1       = Cast.ToString(row["cfree1"]);
            arrivalVouchs.Free2       = Cast.ToString(row["cfree2"]);
            arrivalVouchs.Free3       = Cast.ToString(row["cfree3"]);
            arrivalVouchs.Free4       = Cast.ToString(row["cfree4"]);
            arrivalVouchs.Free5       = Cast.ToString(row["cfree5"]);
            arrivalVouchs.Free6       = Cast.ToString(row["cfree6"]);
            arrivalVouchs.Free7       = Cast.ToString(row["cfree7"]);
            arrivalVouchs.Free8       = Cast.ToString(row["cfree8"]);
            arrivalVouchs.Free9       = Cast.ToString(row["cfree9"]);
            arrivalVouchs.Free10      = Cast.ToString(row["cfree10"]);
            arrivalVouchs.Define22    = Cast.ToString(row["cdefine22"]);//产地
            arrivalVouchs.Define23    = Cast.ToString(row["cdefine23"]);
            arrivalVouchs.Define24    = Cast.ToString(row["cdefine24"]);
            arrivalVouchs.Define25    = Cast.ToString(row["cdefine25"]);
            arrivalVouchs.Define26    = Cast.ToDecimal(row["cdefine26"]);
            arrivalVouchs.Define27    = Cast.ToDecimal(row["cdefine27"]);
            arrivalVouchs.Define28    = Cast.ToString(row["cdefine28"]);
            arrivalVouchs.Define29    = Cast.ToString(row["cdefine29"]);
            arrivalVouchs.Define30    = Cast.ToString(row["cdefine30"]);
            arrivalVouchs.Define31    = Cast.ToString(row["cdefine31"]);
            arrivalVouchs.Define32    = Cast.ToString(row["cdefine32"]);
            arrivalVouchs.Define33    = Cast.ToString(row["cdefine33"]);
            arrivalVouchs.Define34    = Cast.ToInteger(row["cdefine34"]);
            arrivalVouchs.Define35    = Cast.ToInteger(row["cdefine35"]);
            arrivalVouchs.Define36    = Cast.ToDateTime(row["cdefine36"]);
            arrivalVouchs.Define37    = Cast.ToDateTime(row["cdefine37"]);
            arrivalVouchs.cItem_class = Cast.ToString(row["citem_class"]);
            arrivalVouchs.cItemCode   = Cast.ToString(row["citemcode"]);
            arrivalVouchs.cItemName   = Cast.ToString(row["citemname"]);


            arrivalVouchs.cinvdefine1  = Cast.ToString(row["cinvdefine1"]);
            arrivalVouchs.cinvdefine2  = Cast.ToString(row["cinvdefine2"]);
            arrivalVouchs.cinvdefine3  = Cast.ToString(row["cinvdefine3"]);
            arrivalVouchs.cinvdefine4  = Cast.ToString(row["cinvdefine4"]);
            arrivalVouchs.cinvdefine5  = Cast.ToString(row["cinvdefine5"]);
            arrivalVouchs.cinvdefine6  = Cast.ToString(row["cinvdefine6"]);
            arrivalVouchs.cinvdefine7  = Cast.ToString(row["cinvdefine7"]);
            arrivalVouchs.cinvdefine8  = Cast.ToString(row["cinvdefine8"]);
            arrivalVouchs.cinvdefine9  = Cast.ToString(row["cinvdefine9"]);
            arrivalVouchs.cinvdefine10 = Cast.ToString(row["cinvdefine10"]);
            arrivalVouchs.cinvdefine11 = Cast.ToString(row["cinvdefine11"]);
            arrivalVouchs.cinvdefine12 = Cast.ToString(row["cinvdefine12"]);
            arrivalVouchs.cinvdefine13 = Cast.ToString(row["cinvdefine13"]);
            arrivalVouchs.cinvdefine14 = Cast.ToString(row["cinvdefine14"]);
            arrivalVouchs.cinvdefine15 = Cast.ToString(row["cinvdefine15"]);
            arrivalVouchs.cinvdefine16 = Cast.ToString(row["cinvdefine16"]);


            arrivalVouchs.ContractCode    = Cast.ToString(row["contractcode"]);
            arrivalVouchs.ContractRowNo   = Cast.ToString(row["contractrowno"]);
            arrivalVouchs.ContractRowGUID = Cast.ToString(row["contractrowguid"]);
            arrivalVouchs.cSoCode         = Cast.ToString(row["csocode"]);
            arrivalVouchs.SoType          = Cast.ToInteger(row["sotype"]);
            arrivalVouchs.SoDId           = Cast.ToString(row["sodid"]);
            arrivalVouchs.cWhCode         = Cast.ToString(row["cwhcode"]);
            arrivalVouchs.cWhName         = Cast.ToString(row["cwhname"]);
            arrivalVouchs.iInvMPCost      = Cast.ToDecimal(row["iinvmpcost"]);
            arrivalVouchs.cOrderCode      = Cast.ToString(row["cordercode"]);
            arrivalVouchs.dArriveDate     = Cast.ToString(row["darrivedate"]);
            arrivalVouchs.iOrderdId       = Cast.ToInteger(row["iorderdid"]);
            arrivalVouchs.iOrderType      = Cast.ToInteger(row["iordertype"]);
            arrivalVouchs.cSoOrderCode    = Cast.ToString(row["csoordercode"]);
            arrivalVouchs.iOrderSeq       = Cast.ToInteger(row["iorderseq"]);
            arrivalVouchs.cDemandMemo     = Cast.ToString(row["cdemandmemo"]);

            arrivalVouchs.iExpiratDateCalcu = Cast.ToInteger(row["iexpiratdatecalcu"]);
            //arrivalVouchs.cExpirationDate = Cast.ToString(row["cexpirationdate"]);
            //arrivalVouchs.dExpirationDate = Cast.ToDateTime(row["dexpirationdate"]);
            arrivalVouchs.iOrderRowNo = Cast.ToInteger(row["irowno"]);//订单行号

            //委外
            //arrivalVouchs.cMoDetailsID = Cast.ToString(row["modetailsID"]);
            return(arrivalVouchs);
        }
 private void PrintResolvedCast(Cast node, int indent)
 {
     AppendLine(indent, "Type = " + node.Type);
     AppendLine(indent, "Operand =");
     PrintNode(node.Operand, indent + 1);
 }
Exemple #27
0
        /// <summary>
        /// 把数据行转换为ArrivalVouch实体对象
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
        public static ArrivalVouch ConvertToArrivalVouch(DataRow row)
        {
            ArrivalVouch arrivalVouch = new ArrivalVouch();

            //arrivalVouch.VT_ID = Cast.ToInteger(row["ivtid"]);
            //arrivalVouch.ID = Cast.ToInteger(row["id"]);
            //arrivalVouch.cCode = Cast.ToString(row["ccode"]);

            arrivalVouch.iExchRate   = Cast.ToDecimal(row["iexchrate"]);
            arrivalVouch.iTaxRate    = Cast.ToDecimal(row["itaxrate"]);
            arrivalVouch.iFlowId     = Cast.ToInteger(row["iflowid"]);
            arrivalVouch.cBusType    = Cast.ToString(row["cbustype"]);
            arrivalVouch.cOrderCode  = Cast.ToString(row["cOrderCode"]);
            arrivalVouch.dDate       = Cast.ToString(row["dPODate"]);
            arrivalVouch.cVenCode    = Cast.ToString(row["cvencode"]);
            arrivalVouch.cVenAbbName = Cast.ToString(row["cVenAbbName"]);
            arrivalVouch.cDepCode    = Cast.ToString(row["cdepcode"]);
            arrivalVouch.cDepName    = Cast.ToString(row["cdepname"]);
            arrivalVouch.cPersonCode = Cast.ToString(row["cpersoncode"]);
            arrivalVouch.cPersonName = Cast.ToString(row["cpersonname"]);
            arrivalVouch.cSCCode     = Cast.ToString(row["csccode"]);
            arrivalVouch.cMemo       = Cast.ToString(row["cmemo"]);
            arrivalVouch.cPTCode     = Cast.ToString(row["cptcode"]);
            arrivalVouch.cPayCode    = Cast.ToString(row["cpaycode"]);
            arrivalVouch.Define1     = Cast.ToString(row["cdefine1"]);
            arrivalVouch.Define2     = Cast.ToString(row["cdefine2"]);
            arrivalVouch.Define3     = Cast.ToString(row["cdefine3"]);
            arrivalVouch.Define4     = Cast.ToDateTime(row["cdefine4"]);
            arrivalVouch.Define5     = Cast.ToInteger(row["cdefine5"]);
            arrivalVouch.Define6     = Cast.ToDateTime(row["cdefine6"]);
            arrivalVouch.Define7     = Cast.ToInteger(row["cdefine7"]);
            arrivalVouch.Define8     = Cast.ToString(row["cdefine8"]);
            arrivalVouch.Define9     = Cast.ToString(row["cdefine9"]);
            arrivalVouch.Define10    = Cast.ToString(row["cdefine10"]);
            arrivalVouch.Define11    = Cast.ToString(row["cdefine11"]);
            arrivalVouch.Define12    = Cast.ToString(row["cdefine12"]);
            arrivalVouch.Define13    = Cast.ToString(row["cdefine13"]);
            arrivalVouch.Define14    = Cast.ToString(row["cdefine14"]);
            arrivalVouch.Define15    = Cast.ToInteger(row["cdefine15"]);
            arrivalVouch.Define16    = Cast.ToDecimal(row["cdefine16"]);

            arrivalVouch.cExch_Name       = Cast.ToString(row["cexch_name"]);
            arrivalVouch.cVenPUOMProtocol = Cast.ToString(row["cvenpuomprotocol"]);

            /*
             *
             *
             * arrivalVouch.iExchRate = Cast.ToDecimal(row["iexchrate"]);
             * arrivalVouch.iTaxRate = Cast.ToDecimal(row["itaxrate"]);
             * arrivalVouch.cMaker = Cast.ToString(row["cmaker"]);
             * arrivalVouch.bNegative = Cast.ToInteger(row["bnegative"]);
             * arrivalVouch.cCloser = Cast.ToString(row["ccloser"]);
             * arrivalVouch.iDiscountTaxType = Cast.ToString(row["idiscounttaxtype"]);
             * arrivalVouch.iBillType = Cast.ToString(row["ibilltype"]);
             * arrivalVouch.cVouchType = Cast.ToString(row["cvouchtype"]);
             * arrivalVouch.cGeneralOrderCode = Cast.ToString(row["cgeneralordercode"]);
             * arrivalVouch.cTmCode = Cast.ToString(row["ctmcode"]);
             * arrivalVouch.cIncotermCode = Cast.ToString(row["cincotermcode"]);
             * arrivalVouch.cTransOrderCode = Cast.ToString(row["ctransordercode"]);
             * arrivalVouch.dPortDate = Cast.ToString(row["dportdate"]);
             * arrivalVouch.cSportCode = Cast.ToString(row["csportcode"]);
             * arrivalVouch.cAportCode = Cast.ToString(row["caportcode"]);
             * arrivalVouch.cSvenCode = Cast.ToString(row["csvencode"]);
             * arrivalVouch.cArrivalPlace = Cast.ToString(row["carrivalplace"]);
             * arrivalVouch.dCloseDate = Cast.ToString(row["dclosedate"]);
             * arrivalVouch.iDec = Cast.ToInteger(row["idec"]);
             * arrivalVouch.bCal = Cast.ToBoolean(row["bcal"]);
             * arrivalVouch.Guid = Cast.ToString(row["guid"]);
             * arrivalVouch.iVerifyState = Cast.ToInteger(row["iverifystate"]);
             * arrivalVouch.cAuditDate = Cast.ToString(row["cauditdate"]);
             * arrivalVouch.cVerifier = Cast.ToString(row["cverifier"]);
             * arrivalVouch.iVerifyStateex = Cast.ToInteger(row["iverifystateex"]);
             * arrivalVouch.iReturnCount = Cast.ToInteger(row["ireturncount"]);
             * arrivalVouch.isWfContRolled = Cast.ToBoolean(row["iswfcontrolled"]);
             * arrivalVouch.cChanger = Cast.ToString(row["cchanger"]);
             * arrivalVouch.cVenName = Cast.ToString(row["cvenname"]);
             * arrivalVouch.cAddress = Cast.ToString(row["cadrowess"]);
             * arrivalVouch.ufts = Cast.ToString(row["ufts"]);
             *
             *
             */
            return(arrivalVouch);
        }
Exemple #28
0
 internal TypedList(ICollection c, Cast cast)
 {
     list = new ArrayList ();
     this.cast = cast;
     AddAll(c);
 }
Exemple #29
0
    protected void MagicItemCommand(object sender, MagicItemEventArgs e)
    {
        if (e.CommandName != "Confirm" && e.CommandName != "Save")
        {
            return;
        }
        string snnumber = this.txtSNNumber.Text.Trim();

        if (snnumber.Length <= 0)
        {
            this.lblInfo.InnerText = "发货单号码为空";
            return;
        }

        using (ISession session = new Session())
        {
            CRMSN sn = CRMSN.Retrieve(session, snnumber);
            if (sn == null)
            {
                this.lblInfo.InnerText = "发货单" + snnumber + "不存在";
                return;
            }
            if (sn.Status != CRMSNStatus.Checked && sn.Status != CRMSNStatus.Packaged)
            {
                this.lblInfo.InnerText = "发货单" + (sn.Status == CRMSNStatus.Interchanged ? "已经完成交接" : "状态为" + sn.Status.ToString()) + ",不可以进行调整";
                return;
            }
            ICHead ic = ICHead.Query(session, sn.OrderNumber);
            if (ic != null)
            {
                this.lblInfo.InnerText = sn.OrderNumber + "已经被加入到交接单" + ic.OrderNumber + "中,请先从交接单中删除该发货单后再进行修改";
                return;
            }

            this.hidSnNumber.Value = snnumber;
            if (e.CommandName == "Confirm")
            {
                this.snView.SNNumber = sn.OrderNumber;
                if (sn.LogisticsID > 0)
                {
                    this.drpLogis.SelectedValue = sn.LogisticsID.ToString();
                }
                else
                {
                    this.drpLogis.SelectedValue = "0";
                }
                this.txtInvoice.Value        = sn.InvoiceNumber;
                this.txtPackageCount.Value   = sn.PackageCount.ToString();
                this.txtPackageWeight.Value  = RenderUtil.FormatNumber(sn.PackageWeight, "##0.#0");
                this.txtShippingNumber.Value = sn.ShippingNumber;
            }
            else if (e.CommandName == "Save")
            {
                if (Cast.Int(this.drpLogis.SelectedValue, 0) <= 0)
                {
                    this.lblInfo.InnerText = "请选择物流公司";
                    return;
                }
                sn.ShippingNumber = this.txtShippingNumber.Value.Trim();
                sn.InvoiceNumber  = this.txtInvoice.Value.Trim();
                sn.PackageWeight  = Cast.Decimal(this.txtPackageWeight.Value, sn.PackageWeight);
                sn.PackageCount   = Cast.Int(this.txtPackageCount.Value, sn.PackageCount);
                sn.LogisticsID    = Cast.Int(this.drpLogis.SelectedValue, 0);
                sn.Update(session, "ShippingNumber", "InvoiceNumber", "PackageWeight", "PackageCount", "LogisticsID");
                this.lblInfo.InnerText       = "发货单" + sn.OrderNumber + "包装信息修改成功";
                this.txtSNNumber.Text        = "";
                this.snView.SNNumber         = "";
                this.txtInvoice.Value        = "";
                this.txtPackageCount.Value   = "";
                this.txtPackageWeight.Value  = "";
                this.txtShippingNumber.Value = "";
            }
        }
    }
Exemple #30
0
        public virtual Expression VisitCast(Cast cast)
        {
            var e = cast.Expression.Accept(this);

            return(new Cast(cast.DataType, e));
        }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.cmdReturn1.Visible = false;
            this.cmdReturn2.Visible = false;

            this.txtDateFrom.Text = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd");
            this.txtDateTo.Text   = DateTime.Now.ToString("yyyy-MM-dd");

            this.drpPeriod.Items.Clear();
            this.drpPeriod.Items.Add(new ListItem(" ", "0"));
            this.drpLogis.Items.Clear();
            this.drpLogis.Items.Add(new ListItem(" ", "0"));
            using (ISession session = new Session())
            {
                IList <INVPeriod> periods = INVPeriod.ClosedPeriods(session);
                foreach (INVPeriod p in periods)
                {
                    this.drpPeriod.Items.Add(new ListItem(p.PeriodCode, p.PeriodID.ToString()));
                }
                if (this.drpPeriod.Items.Count > 1)
                {
                    this.drpPeriod.SelectedIndex = 1;
                }
                IList <Logistics> logis = session.CreateEntityQuery <Logistics>()
                                          .OrderBy("ShortName")
                                          .List <Logistics>();
                foreach (Logistics lg in logis)
                {
                    this.drpLogis.Items.Add(new ListItem(lg.ShortName, lg.LogisticCompID.ToString()));
                }

                string mode = WebUtil.Param("mode");
                if (mode.Trim().ToLower() == "fix")
                {
                    //从销售款统计导航过来
                    this.cmdReturn1.Visible = true;
                    this.cmdReturn2.Visible = true;
                    this.cmdReturn1["Return"].NavigateUrl = this.cmdReturn2["Return"].NavigateUrl = WebUtil.Param("return");

                    this.drpPeriod.SelectedValue = WebUtil.ParamInt("pd", 0).ToString();
                    int logisId = WebUtil.ParamInt("lg", 0);
                    if (logisId < 0)
                    {
                        logisId = 0;
                    }
                    this.drpLogis.SelectedValue = logisId.ToString();
                    DateTime dt;
                    dt = Cast.DateTime(WebUtil.Param("df"), new DateTime(1900, 1, 1));
                    if (dt > new DateTime(1900, 1, 1))
                    {
                        this.txtDateFrom.Text = dt.ToString("yyyy-MM-dd");
                    }
                    dt = Cast.DateTime(WebUtil.Param("dt"), new DateTime(1900, 1, 1));
                    if (dt > new DateTime(1900, 1, 1))
                    {
                        this.txtDateTo.Text = dt.ToString("yyyy-MM-dd");
                    }
                }

                this.RestoreLastQuery(session);
            }
        }
        else
        {
            this.frameDownload.Attributes["src"] = "about:blank;";
        }
    }
Exemple #32
0
 public DataType VisitCast(Cast cast)
 {
     cast.Expression.Accept(this);
     return(handler.DataTypeTrait(cast, cast.DataType));
 }
    protected void MagicItemCommand(object sender, MagicItemEventArgs e)
    {
        if (e.CommandName != "Download")
        {
            return;
        }

        using (ISession session = new Session())
        {
            DateTime defaultDate = new DateTime(1900, 1, 1);
            DateTime startDate   = Cast.DateTime(this.txtDateFrom.Text, defaultDate);
            DateTime endDate     = Cast.DateTime(this.txtDateTo.Text, defaultDate);
            //如果选择了库存期间,使用库存期间的起始日期
            int periodId = Cast.Int(this.drpPeriod.SelectedValue, 0);
            if (periodId > 0)
            {
                INVPeriod period = INVPeriod.Retrieve(session, periodId);
                if (period != null)
                {
                    startDate = period.StartingDate;
                    endDate   = period.EndDate;
                }
            }
            if (startDate <= defaultDate || endDate <= defaultDate)
            {
                WebUtil.ShowError(this, "请选择时间范围或库存期间");
                return;
            }
            int logisId = WebUtil.ParamInt("lg", 0);
            if (logisId != -99)
            {
                logisId = Cast.Int(this.drpLogis.SelectedValue);
            }

            int     count = 0;
            DataSet ds    = Report.SaleAmt(session, startDate, endDate, logisId
                                           , this.txtSNNumber.Text, this.txtSONumber.Text, this.txtShippingNumber.Text
                                           , -1, 0, false, ref count);
            string fileName = DownloadUtil.DownloadXls("Sale_" + DateTime.Now.ToString("yyMMdd") + ".xls", "RPT_SALE_AMT_DTL_",
                                                       new List <DownloadFormat>()
            {
                new DownloadFormat(DataType.Date, "发货日期", "TransDate"),
                new DownloadFormat(DataType.NumberText, "发货单", "SNNumber"),
                new DownloadFormat(DataType.NumberText, "订单", "SONumber"),
                new DownloadFormat(DataType.NumberText, "运单号", "ShippingNumber"),
                new DownloadFormat(DataType.Number, "成本金额", "CostAmt"),
                new DownloadFormat(DataType.Number, "销售收入", "SaleAmt"),
                new DownloadFormat(DataType.Number, "发送费", "TransportAmt"),
                new DownloadFormat(DataType.Number, "包装费", "PackageAmt"),
                new DownloadFormat(DataType.Number, "礼券抵扣", "CouponsAmt"),
                new DownloadFormat(DataType.Number, "销售折扣", "DiscountAmt"),
                new DownloadFormat(DataType.Number, "礼金支付", "EMoneyAmt"),
                new DownloadFormat(DataType.Number, "帐户支付", "AccountReceivable"),
                new DownloadFormat(DataType.Number, "POS机收款", "PosReceivable"),
                new DownloadFormat(DataType.Number, "物流应收款", "LogisReceivable"),
                new DownloadFormat(DataType.Number, "实际应收款", "ActualReceivable")
            }, ds);
            this.frameDownload.Attributes["src"] = fileName;
            WebUtil.DownloadHack(this, "txtDateFrom", "txtDateTo");
        }
    }
Exemple #34
0
 public virtual Expression VisitCast(Cast cast)
 {
     cast.Expression = cast.Expression.Accept(this);
     return(cast);
 }
Exemple #35
0
        public virtual Expression VisitCast(Cast cast)
        {
            var exp = cast.Expression.Accept(this);

            if (exp != Constant.Invalid)
            {
                var ptCast = cast.DataType.ResolveAs <PrimitiveType>();
                if (exp is Constant c && ptCast != null)
                {
                    if (c.DataType is PrimitiveType ptSrc)
                    {
                        if (ptCast.Domain == Domain.Real)
                        {
                            if (ptSrc.Domain == Domain.Real &&
                                ptCast.Size < ptSrc.Size)
                            {
                                Changed = true;
                                return(ConstantReal.Create(ptCast, c.ToReal64()));
                            }
                        }
                        else if ((ptSrc.Domain & Domain.Integer) != 0)
                        {
                            Changed = true;
                            return(Constant.Create(ptCast, c.ToUInt64()));
                        }
                    }
                }
                if (exp is Identifier id &&
                    ctx.GetDefiningExpression(id) is MkSequence seq)
                {
                    // If we are casting a SEQ, and the corresponding element is >=
                    // the size of the cast, then use deposited part directly.
                    var lsbElem  = seq.Expressions[seq.Expressions.Length - 1];
                    int sizeDiff = lsbElem.DataType.Size - cast.DataType.Size;
                    if (sizeDiff >= 0)
                    {
                        foreach (var elem in seq.Expressions)
                        {
                            ctx.RemoveExpressionUse(elem);
                        }
                        ctx.UseExpression(lsbElem);
                        Changed = true;
                        if (sizeDiff > 0)
                        {
                            return(new Cast(cast.DataType, lsbElem));
                        }
                        else
                        {
                            return(lsbElem);
                        }
                    }
                }
                if (exp is ProcedureConstant pc && cast.DataType.BitSize == pc.DataType.BitSize)
                {
                    // (wordnn) procedure_const => procedure_const
                    return(pc);
                }
                if (exp.DataType.BitSize == cast.DataType.BitSize)
                {
                    // Redundant word-casts can be stripped.
                    if (cast.DataType.IsWord())
                    {
                        return(exp);
                    }
                }
                cast = new Cast(cast.DataType, exp);
            }
            if (castCastRule.Match(cast))
            {
                Changed = true;
                return(castCastRule.Transform());
            }
            return(cast);
        }
 /// <summary>
 /// Robust data conversion. Never throws an exception. Returns the
 /// specified default value instead.
 /// </summary>
 /// <typeparam name="T">Type of object to convert to</typeparam>
 /// <param name="value">Object to convert</param>
 /// <param name="defalt">The default value to use if the conversion fails.</param>
 /// <returns>Converted result</returns>
 /// <remarks>
 /// Handles everything System.Convert.ChangeType() does plus:<br />
 ///  • Anything ==&gt; trimmed string<br />
 ///  • string/number (True/False, t/f, 1/0, 1.0/0.0, Yes/No (in many languages)) ==&gt; Boolean<br />
 ///  • Office Automation Double/float/decimal &lt;==&gt; DateTime/DateTimeOffset<br />
 ///  • int(seconds since 1/1/1970) &lt;==&gt; DateTime/DateTimeOffset/Timespan<br />
 ///  • long(ticks) &lt;==&gt; DateTime/DateTimeOffset/Timespan<br />
 ///  • Numeric string (yyyyMMddhhmmssfff) ==&gt; DateTime/DateTimeOffset<br />
 ///  • System.Type &lt;==&gt; string<br />
 ///  • System.Guid &lt;==&gt; string<br />
 ///  • System.Version &lt;==&gt; string<br />
 ///  • [Flags] System.Enum &lt;==&gt; string/integer
 /// </remarks>
 public static T CastTo <T>(this object value, T defalt)
 {
     return((T)Cast.To(typeof(T), value, defalt));
 }
Exemple #37
0
 private void PrintResolvedCast(Cast node, int indent)
 {
     AppendLine(indent, "Type = " + node.Type);
     AppendLine(indent, "Operand =");
     PrintNode(node.Operand, indent + 1);
 }
Exemple #38
0
 public void VisitCast(Cast cast)
 {
     throw new NotImplementedException();
 }
    protected void MagicItemCommand(object sender, MagicItemEventArgs e)
    {
        if (e.CommandName != "Download")
        {
            return;
        }

        using (ISession session = new Session())
        {
            DateTime defaultDate = new DateTime(1900, 1, 1);
            DateTime startDate   = Cast.DateTime(this.txtDateFrom.Text, defaultDate);
            DateTime endDate     = Cast.DateTime(this.txtDateTo.Text, defaultDate);
            //如果选择了库存期间,使用库存期间的起始日期
            int periodId = Cast.Int(this.drpPeriod.SelectedValue, 0);
            if (periodId > 0)
            {
                INVPeriod period = INVPeriod.Retrieve(session, periodId);
                if (period != null)
                {
                    startDate = period.StartingDate;
                    endDate   = period.EndDate;
                }
            }
            if (startDate <= defaultDate || endDate <= defaultDate)
            {
                WebUtil.ShowError(this, "请选择时间范围或库存期间");
                return;
            }

            int     count = 0;
            DataSet ds    = Report.MbrAccountDetail(session, startDate, endDate
                                                    , Cast.Int(this.drpFlush.SelectedValue), Cast.Int(this.drpPayment.SelectedValue)
                                                    , this.txtOrder.Text, this.txtMbrID.Text, this.txtMbrName.Text, this.txtUser.Text
                                                    , -1, 0, false, ref count);
            string fileName = DownloadUtil.DownloadXls("Member_Account_Detail_" + DateTime.Now.ToString("yyMMdd") + ".xls", "RPT_MBR_ACC_",
                                                       new List <DownloadFormat>()
            {
                new DownloadFormat(DataType.Date, "日期", "FlushDate"),
                new DownloadFormat(DataType.Text, "变动原因", "FlushType"),
                new DownloadFormat(DataType.Text, "支付方式", "PaymentType"),
                new DownloadFormat(DataType.NumberText, "会员号", "MbrNum"),
                new DownloadFormat(DataType.Text, "姓名", "MbrName"),
                new DownloadFormat(DataType.NumberText, "凭证号", "OrderNumber"),
                new DownloadFormat(DataType.Number, "变动金额", "FlushAmt"),
                new DownloadFormat(DataType.Text, "操作人", "UserName"),
                new DownloadFormat(DataType.Text, "操作备注", "comments")
            }, ds);
            this.frameDownload.Attributes["src"] = fileName;
            WebUtil.DownloadHack(this, "txtDateFrom", "txtDateTo");
        }
    }
Exemple #40
0
        /// <summary>
        /// Inserts or updates multiple instances of AppDependency class on the database table "config.app_dependencies";
        /// </summary>
        /// <param name="appDependencies">List of "AppDependency" class to import.</param>
        /// <returns></returns>
        public List <object> BulkImport(List <ExpandoObject> appDependencies)
        {
            if (!this.SkipValidation)
            {
                if (!this.Validated)
                {
                    this.Validate(AccessTypeEnum.ImportData, this._LoginId, this._Catalog, false);
                }

                if (!this.HasAccess)
                {
                    Log.Information("Access to import entity \"AppDependency\" was denied to the user with Login ID {LoginId}. {appDependencies}", this._LoginId, appDependencies);
                    throw new UnauthorizedException("Access is denied.");
                }
            }

            var result = new List <object>();
            int line   = 0;

            try
            {
                using (Database db = new Database(ConnectionString.GetConnectionString(this._Catalog), Factory.ProviderName))
                {
                    using (ITransaction transaction = db.GetTransaction())
                    {
                        foreach (dynamic appDependency in appDependencies)
                        {
                            line++;



                            object primaryKeyValue = appDependency.app_dependency_id;

                            if (Cast.To <int>(primaryKeyValue) > 0)
                            {
                                result.Add(appDependency.app_dependency_id);
                                db.Update("config.app_dependencies", "app_dependency_id", appDependency, appDependency.app_dependency_id);
                            }
                            else
                            {
                                result.Add(db.Insert("config.app_dependencies", "app_dependency_id", appDependency));
                            }
                        }

                        transaction.Complete();
                    }

                    return(result);
                }
            }
            catch (NpgsqlException ex)
            {
                string errorMessage = $"Error on line {line} ";

                if (ex.Code.StartsWith("P"))
                {
                    errorMessage += Factory.GetDbErrorResource(ex);

                    throw new DataAccessException(errorMessage, ex);
                }

                errorMessage += ex.Message;
                throw new DataAccessException(errorMessage, ex);
            }
            catch (System.Exception ex)
            {
                string errorMessage = $"Error on line {line} ";
                throw new DataAccessException(errorMessage, ex);
            }
        }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.cmdReturn1.Visible = false;
            this.cmdReturn2.Visible = false;

            this.txtDateFrom.Text = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd");
            this.txtDateTo.Text   = DateTime.Now.ToString("yyyy-MM-dd");

            this.drpPeriod.Items.Clear();
            this.drpPeriod.Items.Add(new ListItem(" ", "0"));
            this.drpFlush.Items.Clear();
            this.drpFlush.Items.Add(new ListItem(" ", "0"));
            this.drpPayment.Items.Clear();
            this.drpPayment.Items.Add(new ListItem(" ", "0"));
            using (ISession session = new Session())
            {
                IList <INVPeriod> periods = INVPeriod.ClosedPeriods(session);
                foreach (INVPeriod p in periods)
                {
                    this.drpPeriod.Items.Add(new ListItem(p.PeriodCode, p.PeriodID.ToString()));
                }
                if (this.drpPeriod.Items.Count > 1)
                {
                    this.drpPeriod.SelectedIndex = 1;
                }
                IList <FlushType> flush = FlushType.EffectiveList(session);
                foreach (FlushType f in flush)
                {
                    this.drpFlush.Items.Add(new ListItem(f.Name, f.ID.ToString()));
                }

                //直接sql取了
                IList <PaymentMethod> payment = session.CreateObjectQuery(@"
Select * From s_payment_METHOD Where Id In(
    Select Distinct pay_method From mbr_money_history
)
order by name")
                                                .List <PaymentMethod>();
                foreach (PaymentMethod p in payment)
                {
                    this.drpPayment.Items.Add(new ListItem(p.Name, p.ID.ToString()));
                }

                string mode = WebUtil.Param("mode");
                if (mode.Trim().ToLower() == "fix")
                {
                    //从帐户变动汇总导航过来
                    this.cmdReturn1.Visible = true;
                    this.cmdReturn2.Visible = true;
                    this.cmdReturn1["Return"].NavigateUrl = this.cmdReturn2["Return"].NavigateUrl = WebUtil.Param("return");

                    this.drpPeriod.SelectedValue  = WebUtil.ParamInt("pd", 0).ToString();
                    this.drpFlush.SelectedValue   = WebUtil.ParamInt("flush", 0).ToString();
                    this.drpPayment.SelectedValue = WebUtil.ParamInt("payment", 0).ToString();
                    DateTime dt;
                    dt = Cast.DateTime(WebUtil.Param("df"), new DateTime(1900, 1, 1));
                    if (dt > new DateTime(1900, 1, 1))
                    {
                        this.txtDateFrom.Text = dt.ToString("yyyy-MM-dd");
                    }
                    dt = Cast.DateTime(WebUtil.Param("dt"), new DateTime(1900, 1, 1));
                    if (dt > new DateTime(1900, 1, 1))
                    {
                        this.txtDateTo.Text = dt.ToString("yyyy-MM-dd");
                    }
                    this.txtMbrID.Text = WebUtil.Param("mbr");
                }

                this.QueryAndBindData(session, 1, this.magicPagerMain.PageSize, true);
            }
        }
        else
        {
            this.frameDownload.Attributes["src"] = "about:blank;";
        }
    }
Exemple #42
0
        public void PopulateTeam(HtmlNode table, ref List<Cast> castList, string roleName)
        {
            var tbody = table.Element("tbody");

            if (tbody != null)
            {
                var tr = tbody.Elements("tr");
                if (tr != null)
                {
                    foreach (HtmlNode row in tr)
                    {
                        var nameNodes = row.Elements("td");
                        if (nameNodes != null)
                        {
                            Cast cast = new Cast();
                            cast.role = roleName.Replace("&nbsp;", " ");

                            foreach (HtmlNode node in nameNodes)
                            {
                                if (node.Attributes["class"] != null && node.Attributes["class"].Value == "name")
                                {
                                    var link = node.Element("a");
                                    cast.name = link.InnerText.Replace("'", string.Empty).Replace("&", string.Empty).Trim();

                                    if (link.Attributes["href"] != null)
                                    {
                                        cast.link = link.Attributes["href"].Value;
                                    }
                                }
                                else if (node.Attributes["class"] != null && node.Attributes["class"].Value == "credit")
                                {
                                    cast.charactername = node.InnerText.Replace("'", string.Empty).Replace("&", string.Empty).Trim();
                                }
                            }

                            castList.Add(cast);
                        }
                    }
                }
            }
        }
    private void QueryAndBindData(ISession session, int pageIndex, int pageSize, bool fetchRecordCount)
    {
        DateTime defaultDate = new DateTime(1900, 1, 1);
        DateTime startDate   = Cast.DateTime(this.txtDateFrom.Text, defaultDate);
        DateTime endDate     = Cast.DateTime(this.txtDateTo.Text, defaultDate);
        //如果选择了库存期间,使用库存期间的起始日期
        int periodId = Cast.Int(this.drpPeriod.SelectedValue, 0);

        if (periodId > 0)
        {
            INVPeriod period = INVPeriod.Retrieve(session, periodId);
            if (period != null)
            {
                startDate = period.StartingDate;
                endDate   = period.EndDate;
            }
        }
        if (startDate <= defaultDate || endDate <= defaultDate)
        {
            WebUtil.ShowError(this, "请选择时间范围或库存期间");
            return;
        }

        int count = 0;

        this.repeater.DataSource = Report.MbrAccountDetail(session, startDate, endDate
                                                           , Cast.Int(this.drpFlush.SelectedValue), Cast.Int(this.drpPayment.SelectedValue)
                                                           , this.txtOrder.Text, this.txtMbrID.Text, this.txtMbrName.Text, this.txtUser.Text
                                                           , pageIndex, pageSize, fetchRecordCount, ref count);
        this.repeater.DataBind();
        if (fetchRecordCount)
        {
            this.magicPagerMain.RecordCount = this.magicPagerSub.RecordCount = count;
        }
        WebUtil.SetMagicPager(magicPagerMain, pageSize, pageIndex);
        WebUtil.SetMagicPager(magicPagerSub, pageSize, pageIndex);
    }
        public override IExpression Cast(Cast cast)
        {
            if (cast.CastType == CastType.Convert)
            {
                var constant = cast.Operand as Constant;

                if (TypeUtil.CanCastImplicitely(
                    cast.Operand.Type,
                    cast.Type,
                    constant != null && constant.Value == null
                ))
                    return new Cast(cast.Operand, cast.Type);

                string methodName = null;

                switch (Type.GetTypeCode(cast.Type))
                {
                    case TypeCode.Boolean: methodName = "ToBoolean"; break;
                    case TypeCode.Byte: methodName = "ToByte"; break;
                    case TypeCode.Char: methodName = "ToChar"; break;
                    case TypeCode.DateTime: methodName = "ToDate"; break;
                    case TypeCode.Decimal: methodName = "ToDecimal"; break;
                    case TypeCode.Double: methodName = "ToDouble"; break;
                    case TypeCode.Int32: methodName = "ToInteger"; break;
                    case TypeCode.Int64: methodName = "ToLong"; break;
                    case TypeCode.SByte: methodName = "ToSByte"; break;
                    case TypeCode.Int16: methodName = "ToShort"; break;
                    case TypeCode.Single: methodName = "ToSingle"; break;
                    case TypeCode.String: methodName = "ToString"; break;
                    case TypeCode.UInt32: methodName = "ToUInteger"; break;
                    case TypeCode.UInt64: methodName = "ToULong"; break;
                    case TypeCode.UInt16: methodName = "ToUShort"; break;
                }

                if (methodName != null)
                {
                    var method = _resolver.FindOperatorMethod(
                        methodName,
                        new[] { typeof(Conversions) },
                        null,
                        new[] { cast.Operand.Type }
                    );

                    Debug.Assert(method != null && method.ReturnType == cast.Type);

                    return new MethodCall(
                        new TypeAccess(method.DeclaringType),
                        method,
                        new[]
                        {
                            cast.Operand
                        }
                    );
                }
                else
                {
                    return new Cast(cast.Operand, cast.Type);
                }
            }

            return base.Cast(cast);
        }
		public override void VisitCast(Cast cast)
		{
			cast.Expression.Accept(this);
			EnsureTypeVariable(cast);
		}
Exemple #46
0
void case_605()
#line 4404 "cs-parser.jay"
{
		Error_SyntaxError (yyToken);

		yyVal = new Cast ((FullNamedExpression) yyVals[-2+yyTop], null, GetLocation (yyVals[-3+yyTop]));
		lbag.AddLocation (yyVal, GetLocation (yyVals[-1+yyTop]));
	  }
Exemple #47
0
 // Use this for initialization
 void Awake()
 {
     audioSource = GetComponent<AudioSource>();
     _cast = GetComponent<Cast>();
 }
Exemple #48
0
		public void VisitCast(Cast cast)
		{
			int prec = SetPrecedence(PrecedenceCase);
			writer.Write("(");
            cast.DataType.Accept(new TypeFormatter(writer, true));
			writer.Write(") ");
			cast.Expression.Accept(this);
			ResetPresedence(prec);
		}
Exemple #49
0
 public TypedList(ICollection c)
 {
     list = new ArrayList ();
     cast = NoCast.Instance;
     AddAll(c);
 }
        CompiledMethod CompileBlock(Class host, Undo undo, Report Report)
        {
#if STATIC
            throw new NotSupportedException();
#else
            string current_debug_name = "eval-" + count + ".dll";
            ++count;

            AssemblyDefinitionDynamic assembly;
            AssemblyBuilderAccess     access;

            if (Environment.GetEnvironmentVariable("SAVE") != null)
            {
                access            = AssemblyBuilderAccess.RunAndSave;
                assembly          = new AssemblyDefinitionDynamic(module, current_debug_name, current_debug_name);
                assembly.Importer = importer;
            }
            else
            {
#if NET_4_0
                access = AssemblyBuilderAccess.RunAndCollect;
#else
                access = AssemblyBuilderAccess.Run;
#endif
                assembly = new AssemblyDefinitionDynamic(module, current_debug_name);
            }

            assembly.Create(AppDomain.CurrentDomain, access);

            Method expression_method;
            if (host != null)
            {
                var base_class_imported = importer.ImportType(base_class);
                var baseclass_list      = new List <FullNamedExpression> (1)
                {
                    new TypeExpression(base_class_imported, host.Location)
                };

                host.SetBaseTypes(baseclass_list);

                expression_method = (Method)host.Members[0];

                if ((expression_method.ModFlags & Modifiers.ASYNC) != 0)
                {
                    //
                    // Host method is async. When WaitOnTask is set we wrap it with wait
                    //
                    // void AsyncWait (ref object $retval) {
                    //	$retval = Host();
                    //	((Task)$retval).Wait();  // When WaitOnTask is set
                    // }
                    //
                    var p = new ParametersCompiled(
                        new Parameter(new TypeExpression(module.Compiler.BuiltinTypes.Object, Location.Null), "$retval", Parameter.Modifier.REF, null, Location.Null)
                        );

                    var method = new Method(host, new TypeExpression(module.Compiler.BuiltinTypes.Void, Location.Null),
                                            Modifiers.PUBLIC | Modifiers.STATIC, new MemberName("AsyncWait"), p, null);

                    method.Block = new ToplevelBlock(method.Compiler, p, Location.Null);
                    method.Block.AddStatement(new StatementExpression(new SimpleAssign(
                                                                          new SimpleName(p [0].Name, Location.Null),
                                                                          new Invocation(new SimpleName(expression_method.MemberName.Name, Location.Null), new Arguments(0)),
                                                                          Location.Null), Location.Null));

                    if (WaitOnTask)
                    {
                        var task = new Cast(expression_method.TypeExpression, new SimpleName(p [0].Name, Location.Null), Location.Null);

                        method.Block.AddStatement(new StatementExpression(new Invocation(
                                                                              new MemberAccess(task, "Wait", Location.Null),
                                                                              new Arguments(0)), Location.Null));
                    }

                    host.AddMember(method);

                    expression_method = method;
                }

                host.CreateContainer();
                host.DefineContainer();
                host.Define();
            }
            else
            {
                expression_method = null;
            }

            module.CreateContainer();

            // Disable module and source file re-definition checks
            module.EnableRedefinition();
            source_file.EnableRedefinition();

            module.Define();

            if (Report.Errors != 0)
            {
                if (undo != null)
                {
                    undo.ExecuteUndo();
                }

                return(null);
            }

            if (host != null)
            {
                host.PrepareEmit();
                host.EmitContainer();
            }

            module.EmitContainer();

            if (Report.Errors != 0)
            {
                if (undo != null)
                {
                    undo.ExecuteUndo();
                }
                return(null);
            }

            module.CloseContainer();
            if (host != null)
            {
                host.CloseContainer();
            }

            if (access == AssemblyBuilderAccess.RunAndSave)
            {
                assembly.Save();
            }

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

            //
            // Unlike Mono, .NET requires that the MethodInfo is fetched, it cant
            // work from MethodBuilders.   Retarded, I know.
            //
            var tt = assembly.Builder.GetType(host.TypeBuilder.Name);
            var mi = tt.GetMethod(expression_method.MemberName.Name);

            //
            // We need to then go from FieldBuilder to FieldInfo
            // or reflection gets confused (it basically gets confused, and variables override each
            // other).
            //
            foreach (var member in host.Members)
            {
                var field = member as Field;
                if (field == null)
                {
                    continue;
                }

                var fi = tt.GetField(field.Name);

                Tuple <FieldSpec, FieldInfo> old;

                // If a previous value was set, nullify it, so that we do
                // not leak memory
                if (fields.TryGetValue(field.Name, out old))
                {
                    if (old.Item1.MemberType.IsStruct)
                    {
                        //
                        // TODO: Clear fields for structs
                        //
                    }
                    else
                    {
                        try {
                            old.Item2.SetValue(null, null);
                        } catch {
                        }
                    }
                }

                fields[field.Name] = Tuple.Create(field.Spec, fi);
            }

            return((CompiledMethod)System.Delegate.CreateDelegate(typeof(CompiledMethod), mi));
#endif
        }
Exemple #51
0
		CompiledMethod CompileBlock (Class host, Undo undo, Report Report)
		{
#if STATIC
			throw new NotSupportedException ();
#else
			string current_debug_name = "eval-" + count + ".dll";
			++count;

			AssemblyDefinitionDynamic assembly;
			AssemblyBuilderAccess access;

			if (Environment.GetEnvironmentVariable ("SAVE") != null) {
				access = AssemblyBuilderAccess.RunAndSave;
				assembly = new AssemblyDefinitionDynamic (module, current_debug_name, current_debug_name);
				assembly.Importer = importer;
			} else {
#if NET_4_0
				access = AssemblyBuilderAccess.RunAndCollect;
#else
				access = AssemblyBuilderAccess.Run;
#endif
				assembly = new AssemblyDefinitionDynamic (module, current_debug_name);
			}

			assembly.Create (AppDomain.CurrentDomain, access);

			Method expression_method;
			if (host != null) {
				var base_class_imported = importer.ImportType (base_class);
				var baseclass_list = new List<FullNamedExpression> (1) {
					new TypeExpression (base_class_imported, host.Location)
				};

				host.SetBaseTypes (baseclass_list);

				expression_method = (Method) host.Members[0];

				if ((expression_method.ModFlags & Modifiers.ASYNC) != 0) {
					//
					// Host method is async. When WaitOnTask is set we wrap it with wait
					//
					// void AsyncWait (ref object $retval) {
					//	$retval = Host();
					//	((Task)$retval).Wait();  // When WaitOnTask is set
					// }
					//
					var p = new ParametersCompiled (
						new Parameter (new TypeExpression (module.Compiler.BuiltinTypes.Object, Location.Null), "$retval", Parameter.Modifier.REF, null, Location.Null)
					);

					var method = new Method(host, new TypeExpression(module.Compiler.BuiltinTypes.Void, Location.Null),
						Modifiers.PUBLIC | Modifiers.STATIC, new MemberName("AsyncWait"), p, null);

					method.Block = new ToplevelBlock(method.Compiler, p, Location.Null);
					method.Block.AddStatement(new StatementExpression (new SimpleAssign(
						new SimpleName(p [0].Name, Location.Null),
						new Invocation(new SimpleName(expression_method.MemberName.Name, Location.Null), new Arguments(0)),
						Location.Null), Location.Null));

					if (WaitOnTask) {
						var task = new Cast (expression_method.TypeExpression, new SimpleName (p [0].Name, Location.Null), Location.Null);

						method.Block.AddStatement (new StatementExpression (new Invocation (
								new MemberAccess (task, "Wait", Location.Null),
							new Arguments (0)), Location.Null));
					}

					host.AddMember(method);

					expression_method = method;
				}

				host.CreateContainer();
				host.DefineContainer();
				host.Define();

			} else {
				expression_method = null;
			}

			module.CreateContainer ();

			// Disable module and source file re-definition checks
			module.EnableRedefinition ();
			source_file.EnableRedefinition ();

			module.Define ();

			if (Report.Errors != 0){
				if (undo != null)
					undo.ExecuteUndo ();

				return null;
			}

			if (host != null){
				host.PrepareEmit ();
				host.EmitContainer ();
			}
			
			module.EmitContainer ();

			if (Report.Errors != 0){
				if (undo != null)
					undo.ExecuteUndo ();
				return null;
			}

			module.CloseContainer ();
			if (host != null)
				host.CloseContainer ();

			if (access == AssemblyBuilderAccess.RunAndSave)
				assembly.Save ();

			if (host == null)
				return null;
			
			//
			// Unlike Mono, .NET requires that the MethodInfo is fetched, it cant
			// work from MethodBuilders.   Retarded, I know.
			//
			var tt = assembly.Builder.GetType (host.TypeBuilder.Name);
			var mi = tt.GetMethod (expression_method.MemberName.Name);

			//
			// We need to then go from FieldBuilder to FieldInfo
			// or reflection gets confused (it basically gets confused, and variables override each
			// other).
			//
			foreach (var member in host.Members) {
				var field = member as Field;
				if (field == null)
					continue;

				var fi = tt.GetField (field.Name);

				Tuple<FieldSpec, FieldInfo> old;

				// If a previous value was set, nullify it, so that we do
				// not leak memory
				if (fields.TryGetValue (field.Name, out old)) {
					if (old.Item1.MemberType.IsStruct) {
						//
						// TODO: Clear fields for structs
						//
					} else {
						try {
							old.Item2.SetValue (null, null);
						} catch {
						}
					}
				}

				fields[field.Name] = Tuple.Create (field.Spec, fi);
			}
			
			return (CompiledMethod) System.Delegate.CreateDelegate (typeof (CompiledMethod), mi);
#endif
		}
			public override object Visit (Cast castExpression)
			{
				var result = new CastExpression ();
				var location = LocationsBag.GetLocations (castExpression);
				
				result.AddChild (new CSharpTokenNode (Convert (castExpression.Location), Roles.LPar), Roles.LPar);
				if (castExpression.TargetType != null)
					result.AddChild (ConvertToType (castExpression.TargetType), Roles.Type);
				if (location != null)
					result.AddChild (new CSharpTokenNode (Convert (location [0]), Roles.RPar), Roles.RPar);
				if (castExpression.Expr != null)
					result.AddChild ((Expression)castExpression.Expr.Accept (this), Roles.Expression);
				return result;
			}
Exemple #53
0
        public override Cast GetBestCast(Playfield p)
        {
            //DebugThings(p);
            playfield = p;
            Cast bc = null;

            Logger.Debug("Home = {Home}", p.home);

            #region Apollo Magic
            // Highest priority -> Can we kill the enemy with a spell
            BoardObj finisherTower = Decision.IsEnemyKillWithSpellPossible(p, out Handcard hc);
            if (finisherTower != null && (hc?.manacost > p.ownMana))
            {
                return(new Cast(hc.name, finisherTower.Position, hc));
            }
            // ------------------------------------------------------

            PlayfieldAnalyse.AnalyseLines(p);               // Danger- and Chancelevel
            currentSituation = GetCurrentFightState(p);     // Attack, Defense or UnderAttack (and where it is)
            hc = CardChoosing.GetOppositeCard(p, currentSituation) ?? CardChoosing.GetMobInPeace(p, currentSituation);
            //hc = CardChoosing.GetMobInPeace(p, currentSituation);

            if (hc == null)
            {
                Logger.Debug("Part: SpellApolloWay");
                Handcard hcApollo = SpellMagic(p, currentSituation, out VectorAI choosedPosition);

                if (hcApollo != null)
                {
                    hc = hcApollo;

                    if (choosedPosition != null && !(hc?.manacost > p.ownMana))
                    {
                        return(new Cast(hcApollo.name, choosedPosition, hcApollo));
                    }
                }
            }

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

            Logger.Debug("Part: GetSpellPosition");

            VectorAI nextPosition = SpecialPositionHandling.GetPosition(p, hc);
            if (nextPosition == null)
            {
                nextPosition = PositionChoosing.GetNextSpellPosition(currentSituation, hc, p);
            }

            bc = new Cast(hc.name, nextPosition, hc);
            #endregion
            Logger.Debug("BestCast:" + bc.SpellName + " " + bc.Position.ToString());

            if (bc?.hc?.manacost > p.ownMana)
            {
                return(null);
            }
            return(bc);
        }
Exemple #54
0
 public TypedList()
 {
     list = new ArrayList();
     cast = NoCast.Instance;
 }
Exemple #55
0
 public bool VisitCast(Cast cast)
 {
     return(cast.Expression.Accept(this));
 }
Exemple #56
0
 internal TypedList(Cast cast)
 {
     list = new ArrayList ();
     this.cast = cast;
 }
Exemple #57
0
 public override void VisitCast(Cast cast)
 {
     base.VisitCast(cast);
 }
		public virtual void VisitCast(Cast cast)
		{
			cast.Expression.Accept(this);
		}
Exemple #59
0
 void IExpressionVisitor.VisitCast(Cast cast)
 {
     throw new NotImplementedException();
 }