Ejemplo n.º 1
0
        /// <summary>
        /// Draws an ellipse.
        /// </summary>
        /// <param name="rect">The rectangle.</param>
        /// <param name="fill">The fill color. If set to <c>OxyColors.Undefined</c>, the ellipse will not be filled.</param>
        /// <param name="stroke">The stroke color. If set to <c>OxyColors.Undefined</c>, the ellipse will not be stroked.</param>
        /// <param name="thickness">The thickness (in device independent units, 1/96 inch).</param>
        public void DrawEllipse(OxyRect rect, OxyColor fill, OxyColor stroke, double thickness)
        {
            DrawResult drawResult = this.Draw(new DrawEllipse(rect, fill, stroke, thickness));

            if (drawResult == DrawResult.Equal)
            {
                return;
            }

            var e = this.CreateAndAdd <Ellipse>(rect.Left, rect.Top);

            if (drawResult == DrawResult.Different)
            {
                this.SetStroke(e, stroke, thickness);
                if (fill.IsVisible())
                {
                    e.Fill = this.GetCachedBrush(fill);
                }
            }

            e.Width  = rect.Width;
            e.Height = rect.Height;
            Canvas.SetLeft(e, rect.Left);
            Canvas.SetTop(e, rect.Top);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Draws line segments defined by points (0,1) (2,3) (4,5) etc.
        /// This should have better performance than calling DrawLine for each segment.
        /// </summary>
        /// <param name="points">The points.</param>
        /// <param name="stroke">The stroke color.</param>
        /// <param name="thickness">The stroke thickness (in device independent units, 1/96 inch).</param>
        /// <param name="dashArray">The dash array (in device independent units, 1/96 inch).</param>
        /// <param name="lineJoin">The line join type.</param>
        /// <param name="aliased">if set to <c>true</c> the shape will be aliased.</param>
        public void DrawLineSegments(
            IList <ScreenPoint> points,
            OxyColor stroke,
            double thickness,
            double[] dashArray,
            LineJoin lineJoin,
            bool aliased)
        {
            if (this.UseStreamGeometry)
            {
                this.DrawLineSegmentsByStreamGeometry(points, stroke, thickness, dashArray, lineJoin, aliased);
                return;
            }

            DrawResult drawResult = this.Draw(new DrawLine(points, stroke, thickness, dashArray, lineJoin, aliased, DrawLineType.Segments));

            if (drawResult == DrawResult.Equal)
            {
                return;
            }

            Path         path         = null;
            PathGeometry pathGeometry = null;

            int count = 0;

            for (int i = 0; i + 1 < points.Count; i += 2)
            {
                if (path == null)
                {
                    path = this.CreateAndAdd <Path>();
                    this.SetStroke(path, stroke, thickness, lineJoin, dashArray, 0, aliased);
                    pathGeometry = new PathGeometry();
                }

                var figure = new PathFigure {
                    StartPoint = this.ToPoint(points[i], aliased), IsClosed = false
                };
                figure.Segments.Add(new LineSegment(this.ToPoint(points[i + 1], aliased), true)
                {
                    IsSmoothJoin = false
                });
                pathGeometry.Figures.Add(figure);

                count++;

                // Must limit the number of figures, otherwise drawing errors...
                if (count > MaxFiguresPerGeometry || dashArray != null)
                {
                    path.Data = pathGeometry;
                    path      = null;
                    count     = 0;
                }
            }

            if (path != null)
            {
                path.Data = pathGeometry;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Draws a polygon.
        /// </summary>
        /// <param name="points">The points.</param>
        /// <param name="fill">The fill color. If set to <c>OxyColors.Undefined</c>, the polygon will not be filled.</param>
        /// <param name="stroke">The stroke color. If set to <c>OxyColors.Undefined</c>, the polygon will not be stroked.</param>
        /// <param name="thickness">The stroke thickness (in device independent units, 1/96 inch).</param>
        /// <param name="dashArray">The dash array (in device independent units, 1/96 inch).</param>
        /// <param name="lineJoin">The line join type.</param>
        /// <param name="aliased">If set to <c>true</c> the polygon will be aliased.</param>
        public void DrawPolygon(
            IList <ScreenPoint> points,
            OxyColor fill,
            OxyColor stroke,
            double thickness,
            double[] dashArray,
            LineJoin lineJoin,
            bool aliased)
        {
            DrawResult drawResult = this.Draw(new DrawPolygon(points, fill, stroke, thickness, dashArray, lineJoin, aliased));

            if (drawResult == DrawResult.Equal)
            {
                return;
            }

            var e = this.CreateAndAdd <Polygon>();

            this.SetStroke(e, stroke, thickness, lineJoin, dashArray, 0, aliased);

            if (!fill.IsUndefined())
            {
                e.Fill = this.GetCachedBrush(fill);
            }

            e.Points = this.ToPointCollection(points, aliased);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Draws a collection of ellipses, where all have the same stroke and fill.
        /// This performs better than calling DrawEllipse multiple times.
        /// </summary>
        /// <param name="rectangles">The rectangles.</param>
        /// <param name="fill">The fill color. If set to <c>OxyColors.Undefined</c>, the ellipses will not be filled.</param>
        /// <param name="stroke">The stroke color. If set to <c>OxyColors.Undefined</c>, the ellipses will not be stroked.</param>
        /// <param name="thickness">The stroke thickness (in device independent units, 1/96 inch).</param>
        public void DrawEllipses(IList <OxyRect> rectangles, OxyColor fill, OxyColor stroke, double thickness)
        {
            DrawResult drawResult = this.Draw(new DrawEllipses(rectangles, fill, stroke, thickness));

            if (drawResult == DrawResult.Equal)
            {
                return;
            }

            var path = this.CreateAndAdd <Path>();

            this.SetStroke(path, stroke, thickness);
            if (!fill.IsUndefined())
            {
                path.Fill = this.GetCachedBrush(fill);
            }

            var gg = new GeometryGroup {
                FillRule = FillRule.Nonzero
            };

            foreach (var rect in rectangles)
            {
                gg.Children.Add(new EllipseGeometry(this.ToRect(rect)));
            }

            path.Data = gg;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Draws a polyline.
        /// </summary>
        /// <param name="points">The points.</param>
        /// <param name="stroke">The stroke color.</param>
        /// <param name="thickness">The stroke thickness (in device independent units, 1/96 inch).</param>
        /// <param name="dashArray">The dash array (in device independent units, 1/96 inch). Use <c>null</c> to get a solid line.</param>
        /// <param name="lineJoin">The line join type.</param>
        /// <param name="aliased">if set to <c>true</c> the shape will be aliased.</param>
        public void DrawLine(
            IList <ScreenPoint> points,
            OxyColor stroke,
            double thickness,
            double[] dashArray,
            LineJoin lineJoin,
            bool aliased)
        {
            if (thickness < this.BalancedLineDrawingThicknessLimit)
            {
                this.DrawLineBalanced(points, stroke, thickness, dashArray, lineJoin, aliased);
                return;
            }

            DrawResult drawResult = this.Draw(new DrawLine(points, stroke, thickness, dashArray, lineJoin, aliased, DrawLineType.Normal));

            if (drawResult == DrawResult.Equal)
            {
                return;
            }

            var e = this.CreateAndAdd <Polyline>();

            this.SetStroke(e, stroke, thickness, lineJoin, dashArray, 0, aliased);

            e.Points = this.ToPointCollection(points, aliased);
        }
Ejemplo n.º 6
0
        public DrawResult DrawWinner()
        {
            var generator = new Random();

            var latestLottery = _ctx.LotteryEntity.OrderByDescending(l => l.Id)
                                .Include(l => l.Tickets)
                                .ThenInclude(t => t.User)
                                .Include(l => l.LoteryCharity)
                                .ThenInclude(c => c.Charity)
                                .First();

            var pool          = latestLottery.Tickets.OrderBy(t => t.Id).ToList();
            var winningNumber = generator.Next(pool.Count);
            var winingTicket  = pool[winningNumber];
            var winningUser   = winingTicket.User;
            var voteResult    = pool.GroupBy(p => p.CharityId)
                                .Select(g => new
            {
                CharityId = g.Key,
                Votes     = g.Count()
            }).OrderByDescending(c => c.Votes)
                                .First();

            var winningCharity = this._ctx.CharityEntity.First(c => c.Id == voteResult.CharityId);

            var result = new DrawResult
            {
                TotalParticipants = pool.Count,
                Ticket            = new DrawTicket()
                {
                    Id   = winingTicket.Id,
                    Name = winingTicket.Name
                },
                User = new DrawnUser()
                {
                    Name = winningUser.Name,
                    Id   = winningUser.Id
                },
                Charity = new DrawCharity
                {
                    Id   = winningCharity.Id,
                    Name = winningCharity.Name
                }
            };

            var drawEntity = new DrawEntity()
            {
                TicketId = winingTicket.Id
            };

            _ctx.Draws.Add(drawEntity);
            _ctx.SaveChanges();
            return(result);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Draws the line segments by stream geometry.
        /// </summary>
        /// <param name="points">The points.</param>
        /// <param name="stroke">The stroke color.</param>
        /// <param name="thickness">The thickness.</param>
        /// <param name="dashArray">The dash array. Use <c>null</c> to get a solid line.</param>
        /// <param name="lineJoin">The line join.</param>
        /// <param name="aliased">Draw aliased line if set to <c>true</c> .</param>
        private void DrawLineSegmentsByStreamGeometry(
            IList <ScreenPoint> points,
            OxyColor stroke,
            double thickness,
            double[] dashArray,
            LineJoin lineJoin,
            bool aliased)
        {
            DrawResult drawResult = this.Draw(new DrawLine(points, stroke, thickness, dashArray, lineJoin, aliased, DrawLineType.StreamGeometry));

            if (drawResult == DrawResult.Equal)
            {
                return;
            }

            StreamGeometry        streamGeometry        = null;
            StreamGeometryContext streamGeometryContext = null;

            int count = 0;

            for (int i = 0; i + 1 < points.Count; i += 2)
            {
                if (streamGeometry == null)
                {
                    streamGeometry        = new StreamGeometry();
                    streamGeometryContext = streamGeometry.Open();
                }

                streamGeometryContext.BeginFigure(this.ToPoint(points[i], aliased), false, false);
                streamGeometryContext.LineTo(this.ToPoint(points[i + 1], aliased), true, false);

                count++;

                // Must limit the number of figures, otherwise drawing errors...
                if (count > MaxFiguresPerGeometry || dashArray != null)
                {
                    streamGeometryContext.Close();
                    var path = this.CreateAndAdd <Path>();
                    this.SetStroke(path, stroke, thickness, lineJoin, dashArray, 0, aliased);
                    path.Data      = streamGeometry;
                    streamGeometry = null;
                    count          = 0;
                }
            }

            if (streamGeometry != null)
            {
                streamGeometryContext.Close();
                var path = this.CreateAndAdd <Path>();
                this.SetStroke(path, stroke, thickness, lineJoin, null, 0, aliased);
                path.Data = streamGeometry;
            }
        }
Ejemplo n.º 8
0
        public bool Draw(CullList currentCullItems, ref double startHeight)
        {
            CullItem cullItem = cullItems.items[currentCalcCullItem++];

            DrawResult drawResult = cullItem.DoDraw();

            if (drawResult != DrawResult.DontDraw)
            {
                SortedFastList <CullItem> cullItems = currentCullItems.cullItems;

                cullItem.Draw(ref startHeight);
                cullItems.Add(cullItem);

                if (drawResult == DrawResult.DrawHeaderAndRemoveLastHeader)
                {
                    double height = cullItems.items[lastAddedIndex].endHeight - cullItems.items[lastAddedIndex].startHeight;;
                    startHeight -= height;
                    cullItems.RemoveAt(lastAddedIndex);

                    for (int i = lastAddedIndex; i < cullItems.Count; i++)
                    {
                        cullItems.items[i].startHeight -= height;
                        cullItems.items[i].endHeight   -= height;
                    }
                }

                if (drawResult == DrawResult.DrawHeader || drawResult == DrawResult.DrawHeaderAndRemoveLastHeader)
                {
                    lastAddedIndex = cullItems.Count - 1;
                }
                currentCullItems.lastDrawResult = drawResult;
            }

            if (currentCalcCullItem >= cullItems.Count)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Ejemplo n.º 9
0
        DrawResult IDrawOperation.Compare(IDrawOperation obj)
        {
            DrawResult result = DrawResult.Different;

            if (ReferenceEquals(obj, this))
            {
                result = DrawResult.Equal;
            }
            else if (obj is T)
            {
                if (Transposed((T)obj))
                {
                    result = DrawResult.Moved;
                }
                else
                {
                    result = DrawResult.Equal;
                }
            }
            return(result);
        }
Ejemplo n.º 10
0
        protected DrawResult Draw(IDrawOperation operation)
        {
            while (TryConsume() != null)
            {
                //throw new InvalidOperationException();
            }

            currentElementIndex = -1;
            currentOperationIndex++;

            DrawResult result = DrawResult.Different;

            bool add = true;

            if (currentOperationIndex >= 0 && currentOperationIndex < operations.Count)
            {
                result = operation.Compare(operations[currentOperationIndex]);

                if (result == DrawResult.Different)
                {
                    // Clear the operations after the current index
                    ClearAfterCurrent();
                }
                else
                {
                    // Copy the elements from the cached operation.
                    operation.CopyFrom(operations[currentOperationIndex]);
                    operations[currentOperationIndex] = operation;
                    add = false;
                }
            }

            if (add)
            {
                operations.Add(operation);
            }

            currentDrawState = result;
            return(result);
        }
Ejemplo n.º 11
0
    /// <summary>
    /// 主要查詢方法
    /// </summary>
    /// <param name="page">頁數(預設為 1)</param>
    /// <param name="NewDraw">重新抽獎(預設為 false)</param>
    /// <param name="ExportMode">匯出模式。(預設為 false)若為真,則取消分頁。</param>
    private void Query(long page = 1, bool NewDraw = false, bool ExportMode = false)
    {
        patwGridView1.Visible = false;
        btnSave.Visible       = false;
        btnExport.Visible     = false;

        string DistinctSQLStatement = "";

        if (Session["DrawIDs"] == null || NewDraw)
        {
            // 抽出結果
            DrawResult result = MakeDraw(int.Parse(tbDrawCount.Text), MaxDrawQuota, PKColumn, WinFlagColumn, DistinctColumn, TableName, BasicCondition, IsGroup);

            // 若發生異常,無法抽出
            if (!result.Result)
            {
                PatwCommon.RegisterClientScriptAlert(this, result.Msg);
                return;
            }
            else // 正常抽出
            {
                patwGridView1.Visible = true;
                btnSave.Visible       = false;
                btnExport.Visible     = true;

                // 排除重複後的名單
                DistinctSQLStatement = result.Msg;
                // 塞入 Session
                Session["DrawIDs"] = result.Msg;
            }
        }
        else
        {
            patwGridView1.Visible = true;
            btnSave.Visible       = false;
            btnExport.Visible     = true;

            // 排除重複後的名單
            DistinctSQLStatement = Convert.ToString(Session["DrawIDs"]);
        }

        // 組成 SQL 指令, 僅取上面抽出的那幾筆名單
        sql.Append(String.Format("SELECT * FROM {0}", TableName));
        sql.Append(String.Format("WHERE 1=1 AND {0} IN (SELECT MAX({0}) FROM {1} WHERE {3} IN ({2}) {4} GROUP BY {3})", PKColumn, TableName, DistinctSQLStatement, DistinctColumn, BasicCondition));

        if (!ExportMode)
        {
            var data = db.Page <DataModel_a12SupauCheckin>(page, PageSize, sql);
            patwGridView1.DataSource = data.Items;
            patwGridView1.DataBind();

            AspNetPager1.PageSize    = (int)data.ItemsPerPage;
            AspNetPager1.RecordCount = (int)data.TotalItems;
            lbTotal.Text             = "依據條件,目前共有 " + data.TotalItems.ToString() + " 筆";
        }
        else
        {
            var data = db.Query <DataModel_a12SupauCheckin>(sql);
            patwGridView1.DataSource = data;
            patwGridView1.DataBind();

            AspNetPager1.Visible = false;
            lbTotal.Text         = "依據條件,目前共有 " + data.Count() + " 筆";
        }
    }
Ejemplo n.º 12
0
    /// <summary>
    /// 抽獎方法
    /// </summary>
    /// <param name="n">欲抽出數量</param>
    /// <param name="PKColumn">主索引鍵</param>
    /// <param name="MaxDrawQuota">中獎名額</param>
    /// <param name="WinFlagColumn">中獎識別欄位</param>
    /// <param name="DistinctColumn">排除重複的欄位(判斷使用者身份的唯一值,例如:E-mail、Facebook UID 等)</param>
    /// <param name="TableName">資料表</param>
    /// <param name="BasicCondition">基本 SQL 條件</param>
    /// <param name="IsGroup">若為真,則每個人中獎機率相同;若為假,則名單越多者中獎機率越高。</param>
    /// <returns>回傳 DrawResult 類別,其下有 Result(是否成功,布林值)與 Msg(回傳訊息,若成功,則為不重複的欄位值)</returns>
    public static DrawResult MakeDraw(int n, int MaxDrawQuota, string PKColumn, string WinFlagColumn, string DistinctColumn, string TableName, string BasicCondition, bool IsGroup)
    {
        PetaPoco.Database db = new PetaPoco.Database("conn");

        int        counter = 0;
        DrawResult result  = new DrawResult();

        PetaPoco.Sql sql = PetaPoco.Sql.Builder;
        sql.Append(String.Format("SELECT MAX({0}) FROM {1} WHERE 1=1", PKColumn, TableName));
        sql.Append(BasicCondition);
        if (IsGroup)
        {
            sql.Append("GROUP BY [" + DistinctColumn + "]");
        }

        var data = db.Query <DataModel_a12SupauCheckin>(sql);

        counter = data.Count();

        if (counter < n)
        {
            result.Result = false;
            result.Msg    = "名單不足以抽出這樣的數量喔!";

            return(result);
        }

        if (n < 1)
        {
            result.Result = false;
            result.Msg    = "數量請至少為 1。";

            return(result);
        }

        if (n > MaxDrawQuota)
        {
            result.Result = false;
            result.Msg    = "抽出名額不得大於中獎名額 " + MaxDrawQuota + " 名 喔!";

            return(result);
        }

        #region 檢查剩餘名額

        sql = PetaPoco.Sql.Builder;
        sql.Append(String.Format("SELECT {0} FROM {1} WHERE {2}='1'", PKColumn, TableName, WinFlagColumn));
        sql.Append(BasicCondition);
        var r = db.Query <DataModel_a12SupauCheckin>(sql);

        // 若目前中獎人數大於等於中獎名額
        if (r.Count() >= MaxDrawQuota)
        {
            result.Result = false;
            result.Msg    = "名額已滿";

            return(result);
        }

        #endregion


        if (!IsGroup)
        {
            if (n == 1)
            {
                sql = PetaPoco.Sql.Builder;
                sql.Append(String.Format("SELECT TOP 1 {0} FROM {1} WHERE 1=1", DistinctColumn, TableName));
                sql.Append(BasicCondition);
                sql.Append("ORDER BY NEWID()");

                var a = db.SingleOrDefault <DataModel_a12SupauCheckin>(sql);
                result.Result = true;
                result.Msg    = "'" + a.sFBUID.ToString() + "'";

                return(result);
            }
            else
            {
                string list_column = MakeDraw(n - 1, MaxDrawQuota, PKColumn, WinFlagColumn, DistinctColumn, TableName, BasicCondition, IsGroup).Msg;

                sql = PetaPoco.Sql.Builder;
                sql.Append(String.Format("SELECT TOP 1 * FROM {0} WHERE 1=1", TableName));
                sql.Append(String.Format("{0} AND [{1}] NOT IN ({2})", BasicCondition, DistinctColumn, list_column));
                sql.Append("ORDER BY NEWID()");

                var a = db.SingleOrDefault <DataModel_a12SupauCheckin>(sql);

                result.Result = true;
                result.Msg    = list_column + ",'" + a.sFBUID.ToString() + "'";

                return(result);
            }
        }
        else
        {
            sql = PetaPoco.Sql.Builder;
            sql.Append(String.Format("SELECT TOP {0} {1} FROM {2} WHERE 1=1", n, DistinctColumn, TableName));
            sql.Append(BasicCondition);
            sql.Append(String.Format("GROUP BY [{0}] ORDER BY NEWID()", DistinctColumn));

            var    a           = db.Query <DataModel_a12SupauCheckin>(sql);
            string return_data = "";
            foreach (var item in a)
            {
                return_data += ",'" + item.sFBUID + "'";
            }
            return_data = return_data.Substring(1, return_data.Length - 1);

            result.Result = true;
            result.Msg    = return_data;

            return(result);
        }
    }
Ejemplo n.º 13
0
        public void Play()
        {
            var matchScore = new ScoreCalculator();
            Team1GoalsScored = matchScore.Team1Goals;
            Team2GoalsScored = matchScore.Team2Goals;

            if (Team1GoalsScored > Team2GoalsScored)
            {
                Result = new Team1WinResult();
            }
            if (Team2GoalsScored > Team1GoalsScored)
            {
                Result = new Team2WinResult();
            }
            else if (Team1GoalsScored == Team2GoalsScored)
            {
                Result = new DrawResult();
            }
        }
Ejemplo n.º 14
0
    private string WinFlagColumn = "sWin"; // 中獎識別欄位

    #endregion Fields

    #region Methods

    /// <summary>
    /// 抽獎方法
    /// </summary>
    /// <param name="n">欲抽出數量</param>
    /// <param name="PKColumn">主索引鍵</param>
    /// <param name="MaxDrawQuota">中獎名額</param>
    /// <param name="WinFlagColumn">中獎識別欄位</param>
    /// <param name="DistinctColumn">排除重複的欄位(判斷使用者身份的唯一值,例如:E-mail、Facebook UID 等)</param>
    /// <param name="TableName">資料表</param>
    /// <param name="BasicCondition">基本 SQL 條件</param>
    /// <param name="IsGroup">若為真,則每個人中獎機率相同;若為假,則名單越多者中獎機率越高。</param>
    /// <returns>回傳 DrawResult 類別,其下有 Result(是否成功,布林值)與 Msg(回傳訊息,若成功,則為不重複的欄位值)</returns>
    public static DrawResult MakeDraw(int n, int MaxDrawQuota, string PKColumn, string WinFlagColumn, string DistinctColumn, string TableName, string BasicCondition, bool IsGroup)
    {
        PetaPoco.Database db = new PetaPoco.Database("conn");

        int counter = 0;
        DrawResult result = new DrawResult();

        PetaPoco.Sql sql = PetaPoco.Sql.Builder;
        sql.Append(String.Format("SELECT MAX({0}) FROM {1} WHERE 1=1", PKColumn, TableName));
        sql.Append(BasicCondition);
        if (IsGroup)
        {
            sql.Append("GROUP BY [" + DistinctColumn + "]");
        }

        var data = db.Query<DataModel_a12SupauCheckin>(sql);
        counter = data.Count();

        if (counter < n)
        {
            result.Result = false;
            result.Msg = "名單不足以抽出這樣的數量喔!";

            return result;
        }

        if (n < 1)
        {
            result.Result = false;
            result.Msg = "數量請至少為 1。";

            return result;
        }

        if (n > MaxDrawQuota)
        {
            result.Result = false;
            result.Msg = "抽出名額不得大於中獎名額 " + MaxDrawQuota + " 名 喔!";

            return result;
        }

        #region 檢查剩餘名額

        sql = PetaPoco.Sql.Builder;
        sql.Append(String.Format("SELECT {0} FROM {1} WHERE {2}='1'", PKColumn, TableName, WinFlagColumn));
        sql.Append(BasicCondition);
        var r = db.Query<DataModel_a12SupauCheckin>(sql);

        // 若目前中獎人數大於等於中獎名額
        if (r.Count() >= MaxDrawQuota)
        {
            result.Result = false;
            result.Msg = "名額已滿";

            return result;
        }

        #endregion

        if (!IsGroup)
        {
            if (n == 1)
            {
                sql = PetaPoco.Sql.Builder;
                sql.Append(String.Format("SELECT TOP 1 {0} FROM {1} WHERE 1=1", DistinctColumn, TableName));
                sql.Append(BasicCondition);
                sql.Append("ORDER BY NEWID()");

                var a = db.SingleOrDefault<DataModel_a12SupauCheckin>(sql);
                result.Result = true;
                result.Msg = "'" + a.sFBUID.ToString() + "'";

                return result;
            }
            else
            {
                string list_column = MakeDraw(n - 1, MaxDrawQuota, PKColumn, WinFlagColumn, DistinctColumn, TableName, BasicCondition, IsGroup).Msg;

                sql = PetaPoco.Sql.Builder;
                sql.Append(String.Format("SELECT TOP 1 * FROM {0} WHERE 1=1", TableName));
                sql.Append(String.Format("{0} AND [{1}] NOT IN ({2})", BasicCondition, DistinctColumn, list_column));
                sql.Append("ORDER BY NEWID()");

                var a = db.SingleOrDefault<DataModel_a12SupauCheckin>(sql);

                result.Result = true;
                result.Msg = list_column + ",'" + a.sFBUID.ToString() + "'";

                return result;
            }
        }
        else
        {
            sql = PetaPoco.Sql.Builder;
            sql.Append(String.Format("SELECT TOP {0} {1} FROM {2} WHERE 1=1", n, DistinctColumn, TableName));
            sql.Append(BasicCondition);
            sql.Append(String.Format("GROUP BY [{0}] ORDER BY NEWID()", DistinctColumn));

            var a = db.Query<DataModel_a12SupauCheckin>(sql);
            string return_data = "";
            foreach (var item in a)
            {
                return_data += ",'" + item.sFBUID + "'";
            }
            return_data = return_data.Substring(1, return_data.Length - 1);

            result.Result = true;
            result.Msg = return_data;

            return result;
        }
    }
Ejemplo n.º 15
0
        /// <summary>
        /// Draws text.
        /// </summary>
        /// <param name="p">The position.</param>
        /// <param name="text">The text.</param>
        /// <param name="fill">The text color.</param>
        /// <param name="fontFamily">The font family.</param>
        /// <param name="fontSize">Size of the font (in device independent units, 1/96 inch).</param>
        /// <param name="fontWeight">The font weight.</param>
        /// <param name="rotate">The rotation angle.</param>
        /// <param name="halign">The horizontal alignment.</param>
        /// <param name="valign">The vertical alignment.</param>
        /// <param name="maxSize">The maximum size of the text (in device independent units, 1/96 inch).</param>
        public void DrawText(
            ScreenPoint p,
            string text,
            OxyColor fill,
            string fontFamily,
            double fontSize,
            double fontWeight,
            double rotate,
            HorizontalAlignment halign,
            VerticalAlignment valign,
            OxySize?maxSize)
        {
            DrawResult drawResult = this.Draw(new DrawText(p, text, fill, fontFamily, fontSize, fontWeight, rotate, halign, valign, maxSize));

            if (drawResult == DrawResult.Equal)
            {
                return;
            }

            var tb = this.CreateAndAdd <TextBlock>();

            tb.Text       = text;
            tb.Foreground = this.GetCachedBrush(fill);
            if (fontFamily != null)
            {
                tb.FontFamily = this.GetCachedFontFamily(fontFamily);
            }

            if (fontSize > 0)
            {
                tb.FontSize = fontSize;
            }

            if (fontWeight > 0)
            {
                tb.FontWeight = GetFontWeight(fontWeight);
            }

            TextOptions.SetTextFormattingMode(tb, this.TextFormattingMode);

            double dx = 0;
            double dy = 0;

            if (maxSize != null || halign != HorizontalAlignment.Left || valign != VerticalAlignment.Top)
            {
                tb.Measure(new Size(1000, 1000));
                var size = tb.DesiredSize;
                if (maxSize != null)
                {
                    if (size.Width > maxSize.Value.Width + 1e-3)
                    {
                        size.Width = Math.Max(maxSize.Value.Width, 0);
                    }

                    if (size.Height > maxSize.Value.Height + 1e-3)
                    {
                        size.Height = Math.Max(maxSize.Value.Height, 0);
                    }

                    tb.Width  = size.Width;
                    tb.Height = size.Height;
                }

                if (halign == HorizontalAlignment.Center)
                {
                    dx = -size.Width / 2;
                }

                if (halign == HorizontalAlignment.Right)
                {
                    dx = -size.Width;
                }

                if (valign == VerticalAlignment.Middle)
                {
                    dy = -size.Height / 2;
                }

                if (valign == VerticalAlignment.Bottom)
                {
                    dy = -size.Height;
                }
            }

            var transform = new TransformGroup();

            transform.Children.Add(new TranslateTransform(dx, dy));
            if (Math.Abs(rotate) > double.Epsilon)
            {
                transform.Children.Add(new RotateTransform(rotate));
            }

            transform.Children.Add(new TranslateTransform(p.X, p.Y));
            tb.RenderTransform = transform;
            if (tb.Clip != null)
            {
                tb.Clip.Transform = tb.RenderTransform.Inverse as Transform;
            }

            tb.SetValue(RenderOptions.ClearTypeHintProperty, ClearTypeHint.Enabled);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Draws the line using the MaxPolylinesPerLine and MinPointsPerPolyline properties.
        /// </summary>
        /// <param name="points">The points.</param>
        /// <param name="stroke">The stroke color.</param>
        /// <param name="thickness">The thickness.</param>
        /// <param name="dashArray">The dash array. Use <c>null</c> to get a solid line.</param>
        /// <param name="lineJoin">The line join.</param>
        /// <param name="aliased">Render aliased if set to <c>true</c>.</param>
        /// <remarks>See <a href="https://oxyplot.codeplex.com/discussions/456679">discussion</a>.</remarks>
        private void DrawLineBalanced(IList <ScreenPoint> points, OxyColor stroke, double thickness, double[] dashArray, LineJoin lineJoin, bool aliased)
        {
            DrawResult drawResult = this.Draw(new DrawLine(points, stroke, thickness, dashArray, lineJoin, aliased, DrawLineType.Balanced));

            if (drawResult == DrawResult.Equal)
            {
                return;
            }

            // balance the number of points per polyline and the number of polylines
            var numPointsPerPolyline = Math.Max(points.Count / MaxPolylinesPerLine, MinPointsPerPolyline);

            var polyline = this.CreateAndAdd <Polyline>();

            this.SetStroke(polyline, stroke, thickness, lineJoin, dashArray, 0, aliased);
            var pc = new PointCollection(numPointsPerPolyline);

            var    n                 = points.Count;
            double lineLength        = 0;
            var    dashPatternLength = (dashArray != null) ? dashArray.Sum() : 0;
            var    last              = new Point();

            for (int i = 0; i < n; i++)
            {
                var p = aliased ? this.ToPixelAlignedPoint(points[i]) : this.ToPoint(points[i]);
                pc.Add(p);

                // alt. 1
                if (dashArray != null)
                {
                    if (i > 0)
                    {
                        var delta = p - last;
                        var dist  = Math.Sqrt((delta.X * delta.X) + (delta.Y * delta.Y));
                        lineLength += dist;
                    }

                    last = p;
                }

                // use multiple polylines with limited number of points to improve WPF performance
                if (pc.Count >= numPointsPerPolyline)
                {
                    polyline.Points = pc;

                    if (i < n - 1)
                    {
                        // alt.2
                        ////if (dashArray != null)
                        ////{
                        ////    lineLength += this.GetLength(polyline);
                        ////}

                        // start a new polyline at last point so there is no gap (it is not necessary to use the % operator)
                        var dashOffset = dashPatternLength > 0 ? lineLength / thickness : 0;
                        polyline = this.CreateAndAdd <Polyline>();
                        this.SetStroke(polyline, stroke, thickness, lineJoin, dashArray, dashOffset, aliased);
                        pc = new PointCollection(numPointsPerPolyline)
                        {
                            pc.Last()
                        };
                    }
                }
            }

            if (pc.Count > 1 || n == 1)
            {
                polyline.Points = pc;
            }
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Draws a collection of polygons, where all polygons have the same stroke and fill.
        /// This performs better than calling DrawPolygon multiple times.
        /// </summary>
        /// <param name="polygons">The polygons.</param>
        /// <param name="fill">The fill color. If set to <c>OxyColors.Undefined</c>, the polygons will not be filled.</param>
        /// <param name="stroke">The stroke color. If set to <c>OxyColors.Undefined</c>, the polygons will not be stroked.</param>
        /// <param name="thickness">The stroke thickness (in device independent units, 1/96 inch).</param>
        /// <param name="dashArray">The dash array (in device independent units, 1/96 inch).</param>
        /// <param name="lineJoin">The line join type.</param>
        /// <param name="aliased">if set to <c>true</c> the shape will be aliased.</param>
        public void DrawPolygons(
            IList <IList <ScreenPoint> > polygons,
            OxyColor fill,
            OxyColor stroke,
            double thickness,
            double[] dashArray,
            LineJoin lineJoin,
            bool aliased)
        {
            DrawResult drawResult = this.Draw(new DrawPolygons(polygons, fill, stroke, thickness, dashArray, lineJoin, aliased));

            if (drawResult == DrawResult.Equal)
            {
                return;
            }

            var                   usg            = this.UseStreamGeometry;
            Path                  path           = null;
            StreamGeometry        streamGeometry = null;
            StreamGeometryContext sgc            = null;
            PathGeometry          pathGeometry   = null;
            int                   count          = 0;

            foreach (var polygon in polygons)
            {
                if (path == null)
                {
                    path = this.CreateAndAdd <Path>();
                    this.SetStroke(path, stroke, thickness, lineJoin, dashArray, 0, aliased);
                    if (!fill.IsUndefined())
                    {
                        path.Fill = this.GetCachedBrush(fill);
                    }

                    if (usg)
                    {
                        streamGeometry = new StreamGeometry {
                            FillRule = FillRule.Nonzero
                        };
                        sgc = streamGeometry.Open();
                    }
                    else
                    {
                        pathGeometry = new PathGeometry {
                            FillRule = FillRule.Nonzero
                        };
                    }
                }

                PathFigure figure = null;
                bool       first  = true;
                foreach (var p in polygon)
                {
                    var point = aliased ? this.ToPixelAlignedPoint(p) : this.ToPoint(p);
                    if (first)
                    {
                        if (usg)
                        {
                            sgc.BeginFigure(point, !fill.IsUndefined(), true);
                        }
                        else
                        {
                            figure = new PathFigure
                            {
                                StartPoint = point,
                                IsFilled   = !fill.IsUndefined(),
                                IsClosed   = true
                            };
                            pathGeometry.Figures.Add(figure);
                        }

                        first = false;
                    }
                    else
                    {
                        if (usg)
                        {
                            sgc.LineTo(point, !stroke.IsUndefined(), true);
                        }
                        else
                        {
                            figure.Segments.Add(new LineSegment(point, !stroke.IsUndefined())
                            {
                                IsSmoothJoin = true
                            });
                        }
                    }
                }

                count++;

                // Must limit the number of figures, otherwise drawing errors...
                if (count > MaxFiguresPerGeometry)
                {
                    if (usg)
                    {
                        sgc.Close();
                        path.Data = streamGeometry;
                    }
                    else
                    {
                        path.Data = pathGeometry;
                    }

                    path  = null;
                    count = 0;
                }
            }

            if (path != null)
            {
                if (usg)
                {
                    sgc.Close();
                    path.Data = streamGeometry;
                }
                else
                {
                    path.Data = pathGeometry;
                }
            }
        }
Ejemplo n.º 18
0
 private static async Task PrintDrawResults(DrawResult currentDraw)
 {
     await using var outputFile = new StreamWriter(Path.Combine("D:\\Temp\\", "LottoNumbers.txt"), true);
     await outputFile.WriteLineAsync($"{currentDraw.IndividualDraw.BallOne},{currentDraw.IndividualDraw.BallTwo},{currentDraw.IndividualDraw.BallThree},{currentDraw.IndividualDraw.BallFour},{currentDraw.IndividualDraw.BallFive},{currentDraw.IndividualDraw.BallSix},{currentDraw.IndividualDraw.BonusBall},{currentDraw.PowerBallNumber}");
 }
Ejemplo n.º 19
0
        protected void GetFinanceDraw()
        {
            Response.ContentType = "application/json";
            try
            {
                DrawResult model  = new DrawResult();
                Guid?      userId = WebUserAuth.UserId;
                if (userId == Guid.Empty)
                {
                    model.Status = -99;
                }
                else
                {
                    TuanDai.PortalSystem.BLL.UserBLL userbll = new TuanDai.PortalSystem.BLL.UserBLL();

                    TuanDai.PortalSystem.Model.UserBasicInfoInfo userInfo = userbll.GetUserBasicInfoModelById(userId.Value);
                    if (userInfo == null)
                    {
                        model.Status = -99;
                        PrintJson(model);
                    }
                    var param = new DynamicParameters();
                    param.Add("@userId", userId);
                    param.Add("@NickName", userInfo.NickName);
                    param.Add("@outStatus", 0, System.Data.DbType.Int32, System.Data.ParameterDirection.Output);
                    param.Add("@PrizeName", "", System.Data.DbType.String, System.Data.ParameterDirection.Output);
                    param.Add("@PrizeType", -1, System.Data.DbType.Int32, System.Data.ParameterDirection.Output);
                    param.Add("@PrizeAmount", 0, System.Data.DbType.Decimal, System.Data.ParameterDirection.Output);
                    param.Add("@PrizeId", Guid.Empty, System.Data.DbType.Guid, System.Data.ParameterDirection.Output);
                    param.Add("@PrizeRecordId", Guid.Empty, System.Data.DbType.Guid, System.Data.ParameterDirection.Output);

                    //using (SqlConnection connection = CreateReadConnection())
                    //{
                    //    connection.Execute("p_activity_GetPrize_XinXingFansMeet", param, null, null,
                    //        CommandType.StoredProcedure);
                    //    model.Status = param.Get<int>("@outStatus");
                    //    model.PrizeName = param.Get<string>("@PrizeName");
                    //    model.PrizeType = param.Get<int>("@PrizeType");
                    //    model.PrizeAmount = param.Get<decimal>("PrizeAmount");
                    //    model.PrizeId = param.Get<Guid?>("@PrizeId");
                    //    model.PrizeRecordId = param.Get<Guid?>("@PrizeRecordId");
                    //    connection.Close();
                    //    connection.Dispose();
                    //}

                    if (model.Status == 1)
                    {
                        model.NickName = userInfo.NickName;
                        int    subTypeId   = 1;
                        string description = string.Empty;
                        if (model.PrizeType == 3)
                        {
                            subTypeId   = 20;
                            description = string.Format("单笔投资满{0}元即可使用{1}元", model.PrizeAmount * 10, model.PrizeAmount);
                        }
                        else if (model.PrizeType == 10)
                        {
                            description = model.PrizeName;
                        }
                        else
                        {
                            description = "谢谢参与";
                        }
                        #region  写入团宝箱
                        if (model.PrizeType == 3 || model.PrizeType == 10)
                        {
                            TuanDai.PortalSystem.Model.SendUserPrizeInfo prizeInfo = new TuanDai.PortalSystem.Model.SendUserPrizeInfo();
                            prizeInfo.UserId = userId.Value;
                            string strRuleId = "";
                            if (model.PrizeType == 3)
                            {
                                if (model.PrizeAmount == 100)
                                {
                                    strRuleId = "4a00620e-934c-407b-8d94-28b0ec8a785f";
                                }
                                else if (model.PrizeAmount == 50)
                                {
                                    strRuleId = "5e12a736-bc66-4bd5-8f1a-e99ac134a77b";
                                }
                                else if (model.PrizeAmount == 10)
                                {
                                    strRuleId = "ddaddc5b-bb05-45bc-8242-8fb313373acf";
                                }
                                else if (model.PrizeAmount == 5)
                                {
                                    strRuleId = "b3b24200-e9df-4241-b94b-290be8185215";
                                }
                            }
                            else if (model.PrizeType == 10)
                            {
                                strRuleId = "05453294-23f7-4c19-bfe8-6f98e3c0d138";
                            }
                            if (strRuleId.IsNotEmpty())
                            {
                                prizeInfo.RuleId = Guid.Parse(strRuleId);//规则Id
                            }
                            else
                            {
                                prizeInfo.RuleId = Guid.Empty;
                            }
                            prizeInfo.PrizeName   = model.PrizeName;
                            prizeInfo.PrizeValue  = model.PrizeAmount;
                            prizeInfo.Description = "信者行万里团粉见面会抽奖-" + description;
                            int pStatus = -1;
                            userbll.SendUserPrizeNew(prizeInfo, out pStatus);

                            if (pStatus != 1)
                            {
                                //写入失败时,回滚之前数据
                                model.Status = -5;
                                this.RollBackGamePrizeData(userId.Value, model.PrizeId.Value);
                            }
                        }
                        #endregion
                    }
                }
                model.CurrentDate = DateTime.Now.ToString("yyyy-MM-dd");
                PrintJson(model);
            }
            finally {
                Response.End();
            }
        }
Ejemplo n.º 20
0
        protected void ASPxButton1_Click(object sender, EventArgs e)
        {
            var id = Convert.ToInt32(ASPxComboBox1.Value);

            if (id == 0)
            {
                return;
            }
            var db      = new Db();
            var project = db.Projects.Find(id);
            //抽取户数
            var n = Convert.ToInt32(ASPxSpinEdit1.Value);

            var results = new List <DrawResult>();



            var count = 0;

            foreach (var buiding in project.Buildings)
            {
                foreach (var progress in buiding.BuildingProgresses)
                {
                    for (var i = progress.FromFloor; i <= progress.ToFloor; i++)
                    {
                        for (var j = 1; j <= buiding.DoorsEachFloor; j++)
                        {
                            count++;
                        }
                    }
                }
            }
            var ran     = new Random();
            var ranList = new List <int>();

            if (count <= n)
            {
                //户数小于抽取户数
                for (var i = 1; i <= count; i++)
                {
                    ranList.Add(i);
                }
            }
            else
            {
                while (ranList.Count < n)
                {
                    ranList.Add(ran.Next(1, count));
                    ranList.Distinct();
                }
            }
            ranList.Sort();

            count = 0;
            foreach (var buiding in project.Buildings)
            {
                foreach (var progress in buiding.BuildingProgresses)
                {
                    for (var i = progress.FromFloor; i <= progress.ToFloor; i++)
                    {
                        for (var j = 1; j <= buiding.DoorsEachFloor; j++)
                        {
                            count++;
                            if (count == ranList[0])
                            {
                                var result = new DrawResult()
                                {
                                    Building = buiding,
                                    Floor    = i,
                                    Door     = j,
                                    Progress = progress.Progress
                                };
                                results.Add(result);
                                ranList.RemoveAt(0);
                                if (ranList.Count == 0)
                                {
                                    var tempIndex = 1;
                                    results.ForEach(r => r.Index = tempIndex++);
                                    ASPxGridView1.Visible        = true;
                                    ASPxGridView1.DataSource     = results;
                                    Session["results"]           = results;
                                    ASPxGridView1.DataBind();
                                    return;
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Draws a portion of the specified <see cref="OxyImage" />.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="srcX">The x-coordinate of the upper-left corner of the portion of the source image to draw.</param>
        /// <param name="srcY">The y-coordinate of the upper-left corner of the portion of the source image to draw.</param>
        /// <param name="srcWidth">Width of the portion of the source image to draw.</param>
        /// <param name="srcHeight">Height of the portion of the source image to draw.</param>
        /// <param name="destX">The x-coordinate of the upper-left corner of drawn image.</param>
        /// <param name="destY">The y-coordinate of the upper-left corner of drawn image.</param>
        /// <param name="destWidth">The width of the drawn image.</param>
        /// <param name="destHeight">The height of the drawn image.</param>
        /// <param name="opacity">The opacity.</param>
        /// <param name="interpolate">interpolate if set to <c>true</c>.</param>
        public void DrawImage(
            OxyImage source,
            double srcX,
            double srcY,
            double srcWidth,
            double srcHeight,
            double destX,
            double destY,
            double destWidth,
            double destHeight,
            double opacity,
            bool interpolate)
        {
            if (destWidth <= 0 || destHeight <= 0 || srcWidth <= 0 || srcHeight <= 0)
            {
                return;
            }

            DrawResult drawResult = this.Draw(new DrawImage(source,
                                                            srcX, srcY,
                                                            srcWidth, srcHeight,
                                                            destX, destY,
                                                            destWidth, destHeight,
                                                            opacity, interpolate));
            Image image = null;

            switch (drawResult)
            {
            case DrawResult.Equal:
                return;

            case DrawResult.Different:
                image = this.CreateAndAdd <Image>(destX, destY);
                var bitmapChain = this.GetImageSource(source);

                // ReSharper disable CompareOfFloatsByEqualityOperator
                if (srcX == 0 && srcY == 0 && srcWidth == bitmapChain.PixelWidth && srcHeight == bitmapChain.PixelHeight)
                // ReSharper restore CompareOfFloatsByEqualityOperator
                {
                    // do not crop
                }
                else
                {
                    bitmapChain = new CroppedBitmap(bitmapChain, new Int32Rect((int)srcX, (int)srcY, (int)srcWidth, (int)srcHeight));
                }

                image.Opacity = opacity;
                image.Width   = destWidth;
                image.Height  = destHeight;
                image.Stretch = Stretch.Fill;
                RenderOptions.SetBitmapScalingMode(image, interpolate ? BitmapScalingMode.HighQuality : BitmapScalingMode.NearestNeighbor);

                // Set the position of the image
                Canvas.SetLeft(image, destX);
                Canvas.SetTop(image, destY);
                //// alternative: image.RenderTransform = new TranslateTransform(destX, destY);

                image.Source = bitmapChain;
                break;

            case DrawResult.Moved:
                image = this.GetNext <Image>();
                // Set the position of the image
                Canvas.SetLeft(image, destX);
                Canvas.SetTop(image, destY);
                break;
            }
        }