Example #1
0
        /// <summary>
        /// Get next value for the primary key
        /// </summary>
        /// <returns></returns>
        private static int GetNextValue()
        {
            //next value will be 1 if there is no row in the datatable.
            int nextValue = 1;

            try
            {
                //Get object collection
                VaaaN.MLFF.Libraries.CommonLibrary.CBE.TollRateCollection objs = GetAll();

                //Get all objects Id
                int[] sortedObjsId = new int[objs.Count];
                for (int i = 0; i < objs.Count; i++)
                {
                    sortedObjsId[i] = objs[i].RateId;
                }

                //Sort the object id
                Array.Sort(sortedObjsId);

                for (int j = 0; j < sortedObjsId.Length; j++)
                {
                    if (j + 1 < sortedObjsId.Length)
                    {
                        if (sortedObjsId[j] + 1 < sortedObjsId[j + 1])
                        {
                            nextValue = sortedObjsId[j] + 1;
                            break;
                        }
                    }
                    else
                    {
                        nextValue = sortedObjsId[sortedObjsId.Length - 1] + 1;
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(nextValue);
        }
Example #2
0
        public static VaaaN.MLFF.Libraries.CommonLibrary.CBE.TollRateCollection GetAll()
        {
            VaaaN.MLFF.Libraries.CommonLibrary.CBE.TollRateCollection tollRates = new VaaaN.MLFF.Libraries.CommonLibrary.CBE.TollRateCollection();
            try
            {
                //Stored procedure must have cur_out parameter.
                //There is no need to add ref cursor for oracle in code.
                string    spName  = VaaaN.MLFF.Libraries.CommonLibrary.Constants.oraclePackagePrefix + "TOLL_RATE_GETALL";
                DbCommand command = VaaaN.MLFF.Libraries.CommonLibrary.DBA.DBAccessor.GetStoredProcCommand(spName);

                DataSet   ds = VaaaN.MLFF.Libraries.CommonLibrary.DBA.DBAccessor.LoadDataSet(command, tableName);
                DataTable dt = ds.Tables[tableName];
                tollRates = ConvertDataTableToCollection(dt);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(tollRates);
        }
Example #3
0
 public static VaaaN.MLFF.Libraries.CommonLibrary.CBE.TollRateCollection GetLatestTollRates(DateTime lastCollectionUpdateTime)
 {
     VaaaN.MLFF.Libraries.CommonLibrary.CBE.TollRateCollection tollRates = new VaaaN.MLFF.Libraries.CommonLibrary.CBE.TollRateCollection();
     try
     {
         //Stored procedure must have cur_out parameter.
         //There is no need to add ref cursor for oracle in code.
         string    spName  = VaaaN.MLFF.Libraries.CommonLibrary.Constants.oraclePackagePrefix + "TOLLRATE_LATEST_GETALL";
         DbCommand command = VaaaN.MLFF.Libraries.CommonLibrary.DBA.DBAccessor.GetStoredProcCommand(spName);
         command.Parameters.Add(VaaaN.MLFF.Libraries.CommonLibrary.DBA.DBAccessor.CreateDbParameter(ref command, "P_LAST_UPDATE_TIME", DbType.DateTime, lastCollectionUpdateTime, ParameterDirection.Input));
         DataSet   ds = VaaaN.MLFF.Libraries.CommonLibrary.DBA.DBAccessor.LoadDataSet(command, tableName);
         DataTable dt = ds.Tables[tableName];
         tollRates = ConvertDataTableToCollection(dt);
     }
     catch (Exception ex)
     {
         throw ex;
     }
     return(tollRates);
 }
Example #4
0
        private decimal GetTollRate(int plazaId, int laneType, DateTime transactionTime, int vehicleClass)
        {
            decimal result = -1;

            try
            {
                //VaaaN.MLFF.Libraries.CommonLibrary.CBE.TollRateCollection currentTimeTollRates = new VaaaN.MLFF.Libraries.CommonLibrary.CBE.TollRateCollection();

                //DateTime currentStartDate = new DateTime();
                //DateTime currentEndDate = new DateTime();
                //DateTime actualEndDate = new DateTime(); //CJS
                tollRates = VaaaN.MLFF.Libraries.CommonLibrary.BLL.TollRateBLL.GetAll();
                VaaaN.MLFF.Libraries.CommonLibrary.CBE.TollRateCollection currentTimeTollRates = new VaaaN.MLFF.Libraries.CommonLibrary.CBE.TollRateCollection();

                currentTimeTollRates = VaaaN.MLFF.Libraries.CommonLibrary.Constants.GetTollRateCollection(transactionTime, tollRates);
                foreach (VaaaN.MLFF.Libraries.CommonLibrary.CBE.TollRateCBE tr in currentTimeTollRates)
                {
                    if (tr.PlazaId == plazaId && tr.LaneTypeId == laneType && tr.VehicleClassId == vehicleClass)
                    {
                        result = tr.Amount;
                        break;
                    }
                }
                // Get toll rate as per transaction time
                //foreach (VaaaN.MLFF.Libraries.CommonLibrary.CBE.TollRateCBE tr in tollRates)
                //{
                //    DateTime currentDate = transactionTime;

                //    // Get Start hour and minute
                //    int startHour = Convert.ToInt32(tr.StartTime.Substring(0, 2));
                //    int startMinute = Convert.ToInt32(tr.StartTime.Substring(3, 2));

                //    int endHour = Convert.ToInt32(tr.EndTime.Substring(0, 2));
                //    int endMinute = Convert.ToInt32(tr.EndTime.Substring(3, 2));

                //    Console.WriteLine(startHour + ", " + startMinute + " -> " + endHour + ", " + endMinute);

                //    currentStartDate = new DateTime(currentDate.Year, currentDate.Month, currentDate.Day, startHour, startMinute, currentDate.Second);
                //    currentEndDate = new DateTime(currentDate.Year, currentDate.Month, currentDate.Day, endHour, endMinute, currentDate.Second);

                //    if (startHour > endHour)// Cross day
                //    {
                //        actualEndDate = currentEndDate.AddDays(1); //this value need to be assigned to another vehicle CJS
                //    }
                //    else
                //    {
                //        actualEndDate = currentEndDate; //CJS
                //    }

                //    if (currentDate > currentStartDate && currentDate < actualEndDate)
                //    {
                //        currentTimeTollRates.Add(tr);
                //    }
                //}

                //foreach (VaaaN.MLFF.Libraries.CommonLibrary.CBE.TollRateCBE tr in currentTimeTollRates)
                //{

                //    if (tr.PlazaId == plazaId && tr.LaneTypeId == laneType && tr.VehicleClassId == vehicleClass)
                //    {
                //        result = tr.Amount;
                //        break;
                //    }
                //}
            }
            catch (Exception ex)
            {
                HelperClass.LogMessage("Failed to get toll rate." + ex.Message);
                result = -1;
            }

            return(result);
        }
Example #5
0
        public override bool SendTollRateMessage(VaaaN.MLFF.Libraries.CommonLibrary.CBE.TollRateCollection tollRates)
        {
            #region Variables

            // Get from configuration file-TODO
            //string apiURL = "http://vms.intitekno.com/index.php/getapi";
            string apiURL    = "http://10.213.0.63/node/index.php/getapi";
            string userName  = "******";
            string password  = "******";
            string x_api_key = "cda2c99fbf5e19f20d331299c15a4491";

            // 1=motorcycle
            // 2 = small car
            // 3 = medium car
            // 4 = big car

            // lane type id 1= normal, 2 = trans jakarta
            string startTime            = "";
            string endTime              = "";
            string motorCycleNormalFare = "";
            string motorCycleTrjFare    = "";
            string smallcarNormalFare   = "";
            string smallCarTrjFare      = "";
            string mediumCarNormalFare  = "";
            string mediumCarTrjFare     = "";
            string bigCarNormalFare     = "";
            string bigCarTrjFare        = "";

            bool isSuccess = false;

            #endregion

            foreach (VaaaN.MLFF.Libraries.CommonLibrary.CBE.TollRateCBE tr in tollRates)
            {
                #region Get data for json
                if (tr.VehicleClassId == 1) // Motorcycle
                {
                    if (tr.LaneTypeId == 1) // Normal
                    {
                        startTime = "\"start_time\":\"" + tr.StartTime.Substring(0, 2) + ":" + tr.StartTime.Substring(3, 2) + ":00\",";
                        endTime   = "\"end_time\":\"" + tr.EndTime.Substring(0, 2) + ":" + tr.EndTime.Substring(3, 2) + ":00\",";

                        motorCycleNormalFare = "\"motorcycle_normal_fare\":\"" + Convert.ToInt32(tr.Amount) + "\",";
                    }

                    if (tr.LaneTypeId == 2)// trj
                    {
                        motorCycleTrjFare = "\"motorcycle_trj_fare\":\"" + Convert.ToInt32(tr.Amount) + "\",";
                    }
                }

                if (tr.VehicleClassId == 2) // small car
                {
                    if (tr.LaneTypeId == 1) // Normal
                    {
                        smallcarNormalFare = "\"small_car_normal_fare\":\"" + Convert.ToInt32(tr.Amount) + "\",";
                    }

                    if (tr.LaneTypeId == 2)// trj
                    {
                        smallCarTrjFare = "\"small_car_trj_fare\":\"" + Convert.ToInt32(tr.Amount) + "\",";
                    }
                }

                if (tr.VehicleClassId == 3) // medium car
                {
                    if (tr.LaneTypeId == 1) // Normal
                    {
                        mediumCarNormalFare = "\"medium_car_normal_fare\":\"" + Convert.ToInt32(tr.Amount) + "\",";
                    }

                    if (tr.LaneTypeId == 2)// trj
                    {
                        mediumCarTrjFare = "\"medium_car_trj_fare\":\"" + Convert.ToInt32(tr.Amount) + "\",";
                    }
                }

                if (tr.VehicleClassId == 4) // big car
                {
                    if (tr.LaneTypeId == 1) // Normal
                    {
                        bigCarNormalFare = "\"big_car_normal_fare\":\"" + Convert.ToInt32(tr.Amount) + "\",";
                    }

                    if (tr.LaneTypeId == 2)// trj
                    {
                        bigCarTrjFare = "\"big_car_trj_fare\":\"" + Convert.ToInt32(tr.Amount) + "\"";
                    }
                }
                #endregion
            }

            #region Create final json
            StringBuilder json = new StringBuilder();
            json.AppendLine("{");
            json.AppendLine(startTime);
            json.AppendLine(endTime);

            json.AppendLine(motorCycleNormalFare);
            json.AppendLine(motorCycleTrjFare);

            json.AppendLine(smallcarNormalFare);
            json.AppendLine(smallCarTrjFare);

            json.AppendLine(mediumCarNormalFare);
            json.AppendLine(mediumCarTrjFare);

            json.AppendLine(bigCarNormalFare);
            json.AppendLine(bigCarTrjFare);

            json.Append("}");
            LogMessage("JSON:" + json.ToString());
            #endregion

            #region Send api request
            HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(apiURL);

            myReq.Method      = "POST";
            myReq.ContentType = "application/json; charset=UTF-8";
            myReq.Headers.Add("x-api-key", x_api_key);
            string svcCredentials = Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes(userName + ":" + password));
            myReq.Headers.Add("Authorization", "Basic " + svcCredentials);

            byte[] bytes = Encoding.UTF8.GetBytes(json.ToString());

            myReq.ContentLength = bytes.Length;
            using (Stream putStream = myReq.GetRequestStream())
            {
                putStream.Write(bytes, 0, bytes.Length);
            }

            try
            {
                //Get response from the SMS Gateway Server and read the answer
                HttpWebResponse        myResp           = (HttpWebResponse)myReq.GetResponse();
                System.IO.StreamReader respStreamReader = new System.IO.StreamReader(myResp.GetResponseStream());
                string responseString = respStreamReader.ReadToEnd();

                if (myResp.StatusCode == HttpStatusCode.OK)
                {
                    isSuccess = true;
                }
                respStreamReader.Close();
                myResp.Close();
            }
            catch (Exception ex)
            {
                VaaaN.MLFF.Libraries.CommonLibrary.Logger.Log.Write("Failed to get response from server." + ex.Message, VaaaN.MLFF.Libraries.CommonLibrary.Logger.Log.ErrorLogModule.VMS);
            }
            #endregion

            return(isSuccess);
        }
Example #6
0
        private void SendVMSMessageThreadFunction()
        {
            VaaaN.MLFF.Libraries.CommonLibrary.CBE.TollRateCollection tollRates = VaaaN.MLFF.Libraries.CommonLibrary.BLL.TollRateBLL.GetAll();

            while (!stopThread)
            {
                try
                {
                    #region Get current applicable toll rates
                    VaaaN.MLFF.Libraries.CommonLibrary.CBE.TollRateCollection currentTimeTollRates = new VaaaN.MLFF.Libraries.CommonLibrary.CBE.TollRateCollection();
                    DateTime currentDate = DateTime.Now;
                    currentTimeTollRates = VaaaN.MLFF.Libraries.CommonLibrary.Constants.GetTollRateCollection(currentDate, tollRates);

                    if (previousStartDate != currentTimeTollRates[0].StartTime)
                    {
                        if (currentTimeTollRates.Count > 0)
                        {
                            try
                            {
                                previousStartDate = currentTimeTollRates[0].StartTime;
                                LogMessage("There is change in toll rate time slot so sending toll rate message to vms for current time slot.");
                                vmsController.SendMessage(currentTimeTollRates);
                                LogMessage("Data send successfully");
                            }
                            catch (Exception ex)
                            {
                                LogMessage("Failed to send vms message." + ex.Message);
                            }
                        }
                        else
                        {
                            LogMessage("No toll rate found.");
                        }
                    }


                    DateTime currentStartDate = new DateTime();
                    DateTime currentEndDate   = new DateTime();

                    foreach (VaaaN.MLFF.Libraries.CommonLibrary.CBE.TollRateCBE tr in tollRates)
                    {
                        // Get Start hour and minute
                        int startHour   = Convert.ToInt32(tr.StartTime.Substring(0, 2));
                        int startMinute = Convert.ToInt32(tr.StartTime.Substring(3, 2));

                        int endHour   = Convert.ToInt32(tr.EndTime.Substring(0, 2));
                        int endMinute = Convert.ToInt32(tr.EndTime.Substring(3, 2));

                        currentStartDate = new DateTime(currentDate.Year, currentDate.Month, currentDate.Day, startHour, startMinute, 0);
                        currentEndDate   = new DateTime(currentDate.Year, currentDate.Month, currentDate.Day, endHour, endMinute, 0);

                        if (startHour > endHour)// Cross day
                        {
                            currentEndDate.AddDays(1);
                        }

                        if (currentDate > currentStartDate && currentDate < currentEndDate)
                        {
                            currentTimeTollRates.Add(tr);
                        }
                    }
                    #endregion
                }
                catch (Exception ex)
                {
                    LogMessage("Failed to send VMS message." + ex.Message);
                }
                finally
                {
                    Thread.Sleep(200);
                }
            }
        }
Example #7
0
        private static VaaaN.MLFF.Libraries.CommonLibrary.CBE.TollRateCollection ConvertDataTableToCollection(DataTable dt)
        {
            try
            {
                VaaaN.MLFF.Libraries.CommonLibrary.CBE.TollRateCollection tollRateCollection = new VaaaN.MLFF.Libraries.CommonLibrary.CBE.TollRateCollection();

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    VaaaN.MLFF.Libraries.CommonLibrary.CBE.TollRateCBE tollRate = new VaaaN.MLFF.Libraries.CommonLibrary.CBE.TollRateCBE();

                    if (dt.Rows[i]["TMS_ID"] != DBNull.Value)
                    {
                        tollRate.TMSId = Convert.ToInt32(dt.Rows[i]["TMS_ID"]);
                    }

                    if (dt.Rows[i]["PLAZA_ID"] != DBNull.Value)
                    {
                        tollRate.PlazaId = Convert.ToInt32(dt.Rows[i]["PLAZA_ID"]);
                    }

                    if (dt.Rows[i]["TRANSFER_STATUS"] != DBNull.Value)
                    {
                        tollRate.TransferStatus = Convert.ToInt32(dt.Rows[i]["TRANSFER_STATUS"]);
                    }

                    if (dt.Rows[i]["RATE_ID"] != DBNull.Value)
                    {
                        tollRate.RateId = Convert.ToInt32(dt.Rows[i]["RATE_ID"]);
                    }

                    if (dt.Rows[i]["PROFILE_ID"] != DBNull.Value)
                    {
                        tollRate.ProfileId = Convert.ToInt32(dt.Rows[i]["PROFILE_ID"]);
                    }

                    if (dt.Rows[i]["VEHICLE_CLASS_ID"] != DBNull.Value)
                    {
                        tollRate.VehicleClassId = Convert.ToInt32(dt.Rows[i]["VEHICLE_CLASS_ID"]);
                    }

                    if (dt.Rows[i]["VEHICLE_CLASS_NAME"] != DBNull.Value)
                    {
                        tollRate.VehicleClassName = Convert.ToString(dt.Rows[i]["VEHICLE_CLASS_NAME"]);
                    }

                    if (dt.Rows[i]["LANE_TYPE_ID"] != DBNull.Value)
                    {
                        tollRate.LaneTypeId = Convert.ToInt32(dt.Rows[i]["LANE_TYPE_ID"]);
                        if (tollRate.LaneTypeId > 0)
                        {
                            tollRate.LaneTypeName = VaaaN.MLFF.Libraries.CommonLibrary.Constants.LaneTypeName[tollRate.LaneTypeId - 1];
                        }
                    }

                    if (dt.Rows[i]["START_TIME"] != DBNull.Value)
                    {
                        tollRate.StartTime = Convert.ToString(dt.Rows[i]["START_TIME"]);
                    }

                    if (dt.Rows[i]["END_TIME"] != DBNull.Value)
                    {
                        tollRate.EndTime = Convert.ToString(dt.Rows[i]["END_TIME"]);
                    }

                    if (dt.Rows[i]["AMOUNT"] != DBNull.Value)
                    {
                        tollRate.Amount = Convert.ToDecimal(dt.Rows[i]["AMOUNT"]);
                    }

                    if (dt.Rows[i]["DESCRIPTION"] != DBNull.Value)
                    {
                        tollRate.Description = Convert.ToString(dt.Rows[i]["DESCRIPTION"]);
                    }

                    if (dt.Rows[i]["MODIFIER_ID"] != DBNull.Value)
                    {
                        tollRate.ModifiedBy = Convert.ToInt32(dt.Rows[i]["MODIFIER_ID"]);
                    }

                    if (dt.Rows[i]["CREATION_DATE"] != DBNull.Value)
                    {
                        tollRate.CreationDate = Convert.ToDateTime(dt.Rows[i]["CREATION_DATE"]);
                    }

                    if (dt.Rows[i]["MODIFICATION_DATE"] != DBNull.Value)
                    {
                        tollRate.ModificationDate = Convert.ToDateTime(dt.Rows[i]["MODIFICATION_DATE"]);
                    }

                    tollRateCollection.Add(tollRate);
                }
                return(tollRateCollection);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #8
0
 public bool SendMessage(VaaaN.MLFF.Libraries.CommonLibrary.CBE.TollRateCollection tollRates)
 {
     return(vmsBase.SendTollRateMessage(tollRates));
 }
Example #9
0
 public abstract Boolean SendTollRateMessage(VaaaN.MLFF.Libraries.CommonLibrary.CBE.TollRateCollection tollRates);