コード例 #1
0
        public void BinaryGenerationProcess()
        {
            var memberList = db.tbl_member_tree.Where(x => x.LeftPoint >= 500 && x.RightPoint >= 500).ToList();

            using (var tr = db.Database.BeginTransaction())
            {
                try
                {
                    memberList.ForEach(x =>
                    {
                        int matchcount        = 0;
                        double?bLeftPoint     = x.LeftPoint;
                        double?bRightPoint    = x.RightPoint;
                        tbl_member_tree mTree = x;

                        if (x.LeftPoint > x.RightPoint)
                        {
                            if (x.RightPoint > 10000)
                            {
                                matchcount      = 20;
                                mTree.LeftPoint = 0;
                            }
                            else
                            {
                                matchcount      = (int)x.RightPoint / 500;
                                mTree.LeftPoint = (x.LeftPoint - (matchcount * 500)) > 10000 ? 10000 : x.LeftPoint - (matchcount * 500);
                            }


                            mTree.RightPoint = 0;
                        }
                        else if (x.LeftPoint == x.RightPoint)
                        {
                            if (x.RightPoint > 10000)
                            {
                                matchcount       = 20;
                                mTree.RightPoint = 0;
                            }
                            else
                            {
                                matchcount       = (int)x.RightPoint / 500;
                                mTree.RightPoint = x.RightPoint - (matchcount * 500);
                            }

                            mTree.LeftPoint = 0;
                        }
                        else
                        {
                            if (x.LeftPoint > 10000)
                            {
                                matchcount       = 20;
                                mTree.RightPoint = 0;
                            }
                            else
                            {
                                matchcount       = (int)x.LeftPoint / 500;
                                mTree.RightPoint = (x.RightPoint - (matchcount * 500)) > 10000 ? 10000 : x.RightPoint - (matchcount * 500);
                            }

                            mTree.LeftPoint = 0;
                        }


                        tbl_binary_matching_data bmD = new tbl_binary_matching_data();
                        bmD.PlacementID = x.PlacementID;
                        //bmD.BPCode =
                        //bmD.ProcessDate = dateParameter;
                        //bmD.InputerID = User.Identity.Name;
                        //bmD.AuthorizerID
                        bmD.BLeftPoint    = bLeftPoint;
                        bmD.BRightPoint   = bRightPoint;
                        bmD.MatchingCount = matchcount;
                        bmD.ALeftPoint    = mTree.LeftPoint;
                        bmD.ARightPoint   = mTree.RightPoint;
                        bmD.PostingDate   = DateTime.Now.Date;

                        db.Entry(mTree).State = System.Data.Entity.EntityState.Modified;
                        db.tbl_binary_matching_data.Add(bmD);
                        db.SaveChanges();
                    });

                    tr.Commit();
                    Log.Information("[M_0000010] PV BV Generation procession completed");
                }
                catch (Exception ex)
                {
                    Log.Error(ex, "[M_0000010] [ERROR]");
                    tr.Rollback();
                }
            }
        }
コード例 #2
0
ファイル: BTreeHelpers.cs プロジェクト: smwahidur/kdm
        public void BinaryMatchingnProcess(string BPCode)
        {
            #region Set max point 10000

            var memberListforall = db.tbl_member_tree.Where(y => y.LeftPoint > 10000 || y.RightPoint > 10000).ToList();

            foreach (var m in memberListforall)
            {
                if (m.LeftPoint > 10000)
                {
                    m.LeftPoint = 10000;
                }
                if (m.RightPoint > 10000)
                {
                    m.RightPoint = 10000;
                }
            }

            db.SaveChanges();

            #endregion

            #region Calculate matching and Update Left and Right Points in Tree
            var memberList = db.tbl_member_tree.Where(x => x.LeftPoint >= 500 && x.RightPoint >= 500).ToList();

            using (var tr = db.Database.BeginTransaction())
            {
                try
                {
                    memberList.ForEach(x =>
                    {
                        int matchcount        = 0;
                        double?bLeftPoint     = x.LeftPoint;
                        double?bRightPoint    = x.RightPoint;
                        tbl_member_tree mTree = x;

                        if (x.LeftPoint > x.RightPoint)
                        {
                            if (x.RightPoint > 10000)
                            {
                                matchcount       = 20;
                                mTree.LeftPoint  = 0;
                                mTree.RightPoint = 0;
                            }
                            else
                            {
                                matchcount       = (int)x.RightPoint / 500;
                                mTree.LeftPoint  = (x.LeftPoint - (matchcount * 500)) > 10000 ? 10000 : x.LeftPoint - (matchcount * 500);
                                mTree.RightPoint = x.RightPoint - (matchcount * 500);
                            }
                        }
                        else if (x.LeftPoint == x.RightPoint)
                        {
                            if (x.RightPoint > 10000)
                            {
                                matchcount       = 20;
                                mTree.RightPoint = 0;
                                mTree.LeftPoint  = 0;
                            }
                            else
                            {
                                matchcount       = (int)x.RightPoint / 500;
                                mTree.RightPoint = x.RightPoint - (matchcount * 500);
                                mTree.LeftPoint  = x.LeftPoint - (matchcount * 500);
                            }
                        }
                        else
                        {
                            if (x.LeftPoint > 10000)
                            {
                                matchcount       = 20;
                                mTree.RightPoint = 0;
                                mTree.LeftPoint  = 0;
                            }
                            else
                            {
                                matchcount       = (int)x.LeftPoint / 500;
                                mTree.RightPoint = (x.RightPoint - (matchcount * 500)) > 10000 ? 10000 : x.RightPoint - (matchcount * 500);
                                mTree.LeftPoint  = x.LeftPoint - (matchcount * 500);
                            }
                        }



                        tbl_binary_matching_data bmD = new tbl_binary_matching_data();
                        bmD.PlacementID = x.PlacementID;
                        bmD.BPCode      = BPCode;
                        //bmD.ProcessDate = dateParameter;
                        //bmD.InputerID = User.Identity.Name;
                        //bmD.AuthorizerID
                        bmD.BLeftPoint    = bLeftPoint;
                        bmD.BRightPoint   = bRightPoint;
                        bmD.MatchingCount = matchcount;
                        bmD.ALeftPoint    = mTree.LeftPoint;
                        bmD.ARightPoint   = mTree.RightPoint;
                        bmD.PostingDate   = DateTime.Now.Date;

                        db.Entry(mTree).State = System.Data.Entity.EntityState.Modified;
                        db.tbl_binary_matching_data.Add(bmD);
                        db.SaveChanges();
                    });

                    string   user        = HttpContext.Current.User.Identity.GetUserName();
                    DateTime processDate = DateTime.Now.Date;
                    DateTime processTime = DateTime.Now;
                    db.tbl_process_code.Add(new tbl_process_code()
                    {
                        ProcessNo   = BPCode,
                        ProcessBy   = user,
                        ProcessDate = processDate,
                        ProcessTime = processTime,
                        PostingDate = processDate
                    });

                    db.SaveChanges();

                    tr.Commit();
                    Log.Information("[M_0000010] Matching Process Completed");
                }
                catch (Exception ex)
                {
                    Log.Error(ex, "[M_0000010] [ERROR]");
                    tr.Rollback();
                }
            }

            #endregion
        }