Example #1
0
        internal static int addBall(clsRecordBall ball)
        {
            SqlCeCommand com = new SqlCeCommand("INSERT INTO tblBalls VALUES(@p1,@p2,@p3,@p4,@p5,@p6,@p7,@p8)", connection.CON_WORKING);

            com.Parameters.AddWithValue("@p1", ball.ballID);
            com.Parameters.AddWithValue("@p2", ball.overId);
            com.Parameters.AddWithValue("@p3", ball.runs);
            com.Parameters.AddWithValue("@p4", ball.extras);
            com.Parameters.AddWithValue("@p5", ball.batsmanId);
            com.Parameters.AddWithValue("@p6", ball.runTypeId);
            com.Parameters.AddWithValue("@p7", ball.shot.shotId);
            com.Parameters.AddWithValue("@p8", ball.ballTypeId);

            try
            {
                return(com.ExecuteNonQuery());
            }
            catch (Exception e)
            {
                clsMessages.showMessage(clsMessages.msgType.error, e.Message);
            }
            return(0);
        }
        public static void importBall(OleDbConnection con, string DBPath)
        {
            CON          = con;
            DatabasePath = DBPath;
            OleDbCommand     comOver = new OleDbCommand("SELECT ID FROM Overs", con);
            OleDbDataAdapter adOver  = new OleDbDataAdapter(comOver);
            DataSet          dsOver  = new DataSet("Over");

            adOver.Fill(dsOver, "Over");
            int overId = 0;

            //OleDbCommand comBall;


            int endId = 8;

            foreach (DataRow rOver in dsOver.Tables["Over"].Rows)
            {
                OleDbCommand comBall = new OleDbCommand();
                comBall.Connection = con;

                overId = Convert.ToInt32(rOver[0].ToString());
                //string commandText = "SELECT [ID], [OverID], [BowlerID], [BatsmanID], [BallType], [BatEndType], [PitchingType], [Runs], [Extras], [HowOutType], [Distance], [Angle], [AngleTypeID], [WhoOutID], [BattingStrokeTypeID], [BowlingDeliveryTypeID], [HowOutType], [WhoOutID], [Angle], [Distance] FROM Balls WHERE [OverID]=@p1";
                string commandText = "SELECT [ID], [OverID], [BowlerID], [BatsmanID], [BallType], [BatEndType], [PitchingType], [Runs], [Extras], [HowOutType], [Distance], [Angle], [AngleTypeID], [WhoOutID], [HowOutType], [WhoOutID], [Angle], [Distance] FROM Balls WHERE [OverID]=@p1";
                comBall.CommandText = commandText;
                comBall.Parameters.AddWithValue("@p1", overId);
                //MessageBox.Show(overId.ToString());
                //------ Get the bowler ID-------------------

                OleDbCommand comBwlerId = new OleDbCommand("SELECT BowlerID FROM Balls WHERE OverID=@p1", con);
                comBwlerId.Parameters.AddWithValue("@p1", overId);
                int bowlerd = 0;

                try
                {
                    bowlerd = Convert.ToInt32(comBwlerId.ExecuteScalar().ToString());
                }
                catch (Exception ex)
                {
                    clsMessages.showMessage(clsMessages.msgType.error, ex.Message);
                    return;
                }

                //-------------------------------------------
                //-----------Create over in the tables-------
                clsRecordOver over    = new clsRecordOver();
                int           overId1 = clsRecordOver.getNextOver();
                over.overId   = overId1;
                over.bowlerId = bowlerd;

                if (overId % 2 == 0)
                {
                    endId = 8;
                }
                else
                {
                    endId = 4;
                }
                over.endId = endId;
                clsRecordOver.addOver(over);
                //MessageBox.Show(endId.ToString());
                //-------------------------------------------

                OleDbDataAdapter adBall = new OleDbDataAdapter(comBall);
                DataSet          dsBall = new DataSet("Ball");
                try
                {
                    adBall.Fill(dsBall, "Ball");
                }
                catch (Exception ex)
                {
                    clsMessages.showMessage(clsMessages.msgType.error, "Error filling 'Ball' dada adapter.\n" + ex.Message);
                }

                foreach (DataRow rBall in dsBall.Tables["Ball"].Rows)
                {
                    clsRecordBall ball = new clsRecordBall();
                    try
                    {
                        ball.ballID     = Convert.ToInt32(rBall[0].ToString());
                        ball.overId     = overId1;
                        ball.runs       = Convert.ToInt32(rBall[7].ToString());
                        ball.extras     = Convert.ToInt32(rBall[8].ToString());
                        ball.batsmanId  = mapPlayer(Convert.ToInt32(rBall[3].ToString()), con);
                        ball.runTypeId  = 3;
                        ball.shot       = clsShot.getShot(1);
                        ball.ballTypeId = mapBallType(Convert.ToInt32(rBall[4].ToString()));

                        clsRecordBall.addBall(ball);

                        //Check if it is a wicket
                        int isWicket = Convert.ToInt32(rBall["HowOutType"].ToString());
                        if (isWicket > 1 && isWicket < 18)
                        {
                            //MessageBox.Show("Wicket: "+isWicket.ToString());
                            int       outBatsman = Convert.ToInt32(rBall["WhoOutID"]);
                            int       totalRuns  = getTotalRuns(outBatsman, con);
                            clsWicket wicket     = new clsWicket(ball.ballID, outBatsman, 0, totalRuns, 1);
                            clsWicket.addWicket(wicket);
                        }

                        //--------record maps---------------------
                        int   angle    = Convert.ToInt32(rBall["Angle"].ToString());
                        float distance = float.Parse(rBall["Distance"].ToString());
                        recordPositions(angle, distance * 100, ball.ballID);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
            }
        }