Tuesday, 5 February 2019

Xamarin Empty Apps is not working

Xamarin Empty App is not working


When you decide to learn cross-platform mobile development, and then you choose Xamarin, so welcome to Microsoft world where everything depends on something.


It is too frustrating when you try to build a new project and it is not working, compilation errors every where.

Lets go straight to creating and building projects:

First lets see the different environments I have faced:
  • The best environment: 
    • Visual Studio 2017 last stable release (15.9.6 or more)
    • Windows 10 version (build) is at least 1803, referring to Microsoft: Microsoft Docs
    • Highlighting the .NET framework version to be 4.7+
  • Another environment 
    • Visual Studio 2017 last stable release (15.9.6 or more) 
    • Windows 10 version (build) is 10240
    • .NET framework 4.6+  and cannot be update because of the windows build


    The first environment you will not face any issues I hope, lets start project for the the other environment
    Important note: in the second environment, don't count on Visual Studio's Android SDK 
      I had to setup Android Studio and used it to setup Android SDK.


Cross-Platform Projects

Shared Project

  1. Open Visual Studio and create a new project



  2. Choose Shared Project



  3. As you can see, boom errors every where:



    1. 'Forms' does not exist in the namespace 'Xamarin'
    2. The other Xaml components are also missing

.NET Standard

  1. Open Visual Studio and create a new project, and choose .NET Standard


  2. You will find everything is red, boom same errors everywhere but there are more



    1. System could not be found  😓
    2. Xamarin could not be found
    3. Could not load file or assembly netstandard



Solution:
  1. Go to Nuget packages for the solution
  2. Uninstall [Xamarin.Forms package]

  3. Install  [Xamarin.Forms package] - Version 2.5+, but below 3
    --------- explained in the conclusion

  4. Clean, rebuild and run
    Congratulations no errors  



Conclusion

Now we can list some recommendations that may help you to overcome Xamarin building problems or facing similar errors.
  • First recommendation of course that you update your windows and .NET Framework
  • It is preferred that you install [Android SDK] using (Android Studio) before installing Xamarin Mobile platform
  • If you have (DotNet Framework) lower than 4.7 , Then use [Xamarin version] lower than 3, as I think that Xamarin 3+ is not supporting lower .NET Frameworks
Now You are ready for Xamarin development Happy Coding 😉

Sunday, 23 September 2018

Generating non-repeating random numbers in JS


Generating non-repeating random numbers in JavaScript

I was solving a JavaScript task, and it requested to print a random tip about JavaScript, but I didn't want to print it to repeat the tip as it boring to see the same tip over and over again. So I have built the below code to do it using (math.random), recursive function and foreach loop.

Before you judge I am still in the learning process 😀😀😁, waiting your feedback.


See the Pen Generating non-repeating random numbers in JS by Mohamed El Ghandour (@GunnZ) on CodePen.




Monday, 3 September 2018

Oracle Procedure to commit per DML statement (PL/SQL)

Commit single transaction Procedure


This procedure can be used in APIs or SQL scripts to commit a DML statement, without committing the other transaction the same script.


--This procedure is used to call an specific DML statment
-- and you need to commit the DML statment only

CREATE OR REPLACE PROCEDURE AUTON_DML (p_dmlstat VARCHAR2)
AS
   PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN                                       -- Main transaction suspends here.
   EXECUTE IMMEDIATE p_dmlstat;         -- Autonomous transaction begins here.

   COMMIT;                                -- Autonomous transaction ends here.
END;                                         -- Main transaction resumes here.


--------------------- How to USE -------------------------------------
----------------------------------------------------------------------
---EXECUTE AUTON_DML(q'[UPDATE staging_pm_schedule_table SET NOTE = 'TEST_Variable']');
--OR
---EXECUTE AUTON_DML('UPDATE staging_pm_schedule_table SET NOTE = '''TEST_Variable'''');

--*----------========----------========----------========------------*--
--*--========---- Created by: Mohamed El Ghandour :D ----========----*--
--*----------========----------========----------========------------*--

Oracle EAM Preventive Maintenance API Script (Part 2)


Second, we will have a loop and two smaller loop within the big one (one Header table, two children tables)

Note. the "AUTON_DML" is a custom procedure to update the table without committing the whole API data.

                                                          Link to the Procedure



Oracle EAM PM API Script


--*----------========----------========----------========------------*--
--*----------========----------========----------========------------*--
--*--========----- Created by: Mohamed El Ghandour -----========-----*--
--*----------========----------========----------========------------*--
--*----------========----------========----------========------------*--

-------------  Consider you have the structure below ------------------
------------- PM ------------ As a parent Record has two types of children
---------------- Activities ---------- As Child Table for the parent PM record
---------------- Rules ---------- As Child Table for the parent PM record

--*****************--
-- ** EAM Views ** --
--*****************--

-- eam_pm_schedulings_v
-- EAM_PM_ACTIVITYGROUP_V
-- eam_suppression_relations_v
-- eam_pm_scheduling_rules
-- MTL_EAM_ASSET_NUMBERS_ALL_V
-- MTL_EAM_ASSET_ACTIVITIES_V
-- eam_pm_last_service_v
-- eam_asset_meters_v


--*****************--
-- ** EAM custom Tables ** --
--*****************--

-- staging_pm_schedule_table
-- staging_activ_pm_table
-- staging_rules_pm_table

-------------********************************************-------------

-- API

DECLARE
   CURSOR stage
   IS
      SELECT *
        FROM staging_pm_schedule_table
       WHERE flag IS NULL; --= 'U';                                           -- IS NULL;

   l_stat           VARCHAR2 (10);
   l_count          NUMBER;
   l_data           VARCHAR2 (500);
   l_schedule       eam_pmdef_pub.pm_scheduling_rec_type;
   l_activity       eam_pmdef_pub.pm_activities_grp_tbl_type;
   l_day            eam_pmdef_pub.pm_rule_tbl_type;
   l_runtime        eam_pmdef_pub.pm_rule_tbl_type;
   l_list           eam_pmdef_pub.pm_rule_tbl_type;
   l_sch_id         NUMBER;
   l_id             NUMBER;
   v_obj_id         NUMBER;
   v_obj_type       NUMBER;

   -- Counters for the tables
   activ_counter    NUMBER;
   ldrule_counter   NUMBER;
   lmeter_counter   NUMBER;
   ldate_counter    NUMBER;
BEGIN
   FOR i IN stage
   LOOP
      activ_counter := 0;
      ldrule_counter := 0;
      lmeter_counter := 0;
      ldate_counter := 0;

      SELECT eam_pm_schedulings_s.NEXTVAL INTO l_sch_id FROM DUAL;

      l_schedule.pm_schedule_id := l_sch_id;
      l_schedule.NAME := i.NAME;

      SELECT maintenance_object_id, maintenance_object_type
        INTO v_obj_id, v_obj_type
        FROM MTL_EAM_ASSET_NUMBERS_ALL_V
       WHERE INSTANCE_NUMBER = i.INSTANCE_NUMBER;

      l_schedule.maintenance_object_id := v_obj_id;
      l_schedule.maintenance_object_type := v_obj_type;
      l_schedule.set_name_id := i.set_name_id;
      l_schedule.from_effective_date := i.from_effective_date;
      l_schedule.generate_wo_status := i.generate_wo_status;
      l_schedule.current_cycle := 1;
      l_schedule.current_seq := 0;
      l_schedule.interval_per_cycle := i.interval_per_cycle;
      l_schedule.generate_next_work_order := i.generate_next_work_order;
      l_schedule.non_scheduled_flag := i.non_scheduled_flag;
      l_schedule.rescheduling_point := i.rescheduling_point;
      l_schedule.default_implement := i.default_implement;
      l_schedule.whichever_first := i.whichever_first;
      l_schedule.include_manual := i.include_manual;
      l_schedule.scheduling_method_code := i.scheduling_method_code;
      l_schedule.type_code := i.type_code;
      l_schedule.auto_instantiation_flag := i.auto_instantiation_flag;

      --      l_schedule.attribute1 := i.description;

      --*******************--********************--*********************--
      ------------------------- Activities Table ------------------------
      --*******************--********************--*********************--

      FOR j
         IN (SELECT activity_association_id,
                    interval_multiple,
                    allow_repeat_in_cycle
               FROM staging_activ_pm_table
              WHERE INSTANCE_NUMBER = i.INSTANCE_NUMBER)
      LOOP
         activ_counter := activ_counter + 1;

         l_activity (activ_counter).activity_association_id :=
            j.activity_association_id;
         l_activity (activ_counter).interval_multiple := j.interval_multiple;
         l_activity (activ_counter).allow_repeat_in_cycle :=
            j.allow_repeat_in_cycle;
      END LOOP;

      --*******************--********************--*********************--
      ------------------------- Rules Tables ------------------------
      ------------------------------- 1.Date Rule
      ------------------------------- 2.Meter Rule
      ------------------------------- 3.List of Dates
      --- PM can have only one type of Rules
      --*******************--********************--*********************--

      FOR x IN (SELECT RULE_TYPE,
                       METER_ID,
                       LIST_DATE,
                       RUNTIME_INTERVAL,
                       day_interval
                  FROM staging_rules_pm_table
                 WHERE INSTANCE_NUMBER = i.INSTANCE_NUMBER)
      LOOP
         CASE
            WHEN x.RULE_TYPE = 1                               --Date interval
            THEN
               ldrule_counter := ldrule_counter + 1;
               l_day (ldrule_counter).rule_type := x.rule_type;
               l_day (ldrule_counter).day_interval := x.day_interval;
            WHEN x.RULE_TYPE = 2                              --Meter interval
            THEN
               lmeter_counter := lmeter_counter + 1;
               l_runtime (lmeter_counter).rule_type := x.rule_type;
               l_runtime (lmeter_counter).meter_id := x.meter_id;
               l_runtime (lmeter_counter).runtime_interval :=
                  x.runtime_interval;
            WHEN x.RULE_TYPE = 3                               --List of Dates
            THEN
               ldate_counter := ldate_counter + 1;
               l_list (ldate_counter).rule_type := x.rule_type;
               l_list (ldate_counter).list_date := x.list_date;
         END CASE;
      END LOOP;


      IF i.TYPE_CODE = 20
      THEN
         l_day.DELETE ();
         l_runtime.DELETE ();
      ELSE
         l_list.DELETE ();
      END IF;


      -- Run the API with the specified parameters

      eam_pmdef_pub.create_pm_def (p_api_version                 => 1.0,
                                   p_init_msg_list               => NULL,
                                   p_commit                      => 'T',
                                   p_validation_level            => NULL,
                                   x_return_status               => l_stat,
                                   x_msg_count                   => l_count,
                                   x_msg_data                    => l_data,
                                   p_pm_schedule_rec             => l_schedule,
                                   p_pm_activities_tbl           => l_activity,
                                   p_pm_day_interval_rules_tbl   => l_day,
                                   p_pm_runtime_rules_tbl        => l_runtime,
                                   p_pm_list_date_rules_tbl      => l_list,
                                   x_new_pm_schedule_id          => l_id);

      -- Update flags and notes depending to the ID
      AUTON_DML (
            'UPDATE staging_pm_schedule_table SET flag =  '''
         || l_stat
         || ''' , note = '''
         || l_count
         || ' '
         || l_data
         || ''' WHERE INSTANCE_NUMBER = '''
         || i.INSTANCE_NUMBER
         || '''');

      IF l_stat = fnd_api.g_ret_sts_success
      THEN
         COMMIT;
         DBMS_OUTPUT.put_line ('Successful');
      ELSE
         DBMS_OUTPUT.put_line (
               'Failed with error :'
            || l_count
            || ' '
            || l_stat
            || ' '
            || l_data);
         ROLLBACK;
      END IF;
   END LOOP;
END;

Oracle EAM Preventive Maintenance API Script (Part 1)


Regarding to the lack of Oracle EAM materials, I decided to share as much as I can with the explain with the simplest words to help the others so no one suffer like I did.

First, you need to create the custom tables that you will use to upload the data:

  1. Staging Main PM Table: this is the main table for the Preventive Maintenance record (Consider it the Header)
  2. Activities Table: this is the activities table per each PM record (children records of PM header)

    Note. the update statement for this table, as I assume you have already uploaded the activity association data.
  3. Rules Table: this is the rules table per each PM record (another children records of PM header)

    Note. the update statement for this table, as I assume you have already uploaded the meters data. 
                                                                   Link to Part 2 

Oracle EAM PM API Script (Tables)


------------------ Staging Main PM Table ----------------------

DROP TABLE staging_pm_schedule_table;

CREATE TABLE staging_pm_schedule_table
(
   INSTANCE_NUMBER            VARCHAR2 (30),
   Name                       VARCHAR2 (100),
   SET_NAME_ID                NUMBER,
   FROM_EFFECTIVE_DATE        DATE,
   GENERATE_WO_STATUS         NUMBER,
   INTERVAL_PER_CYCLE         NUMBER,
   GENERATE_NEXT_WORK_ORDER   VARCHAR2 (1),
   NON_SCHEDULED_FLAG         VARCHAR2 (1),
   RESCHEDULING_POINT         NUMBER,
   DEFAULT_IMPLEMENT          VARCHAR2 (1),
   WHICHEVER_FIRST            VARCHAR2 (1),
   INCLUDE_MANUAL             VARCHAR2 (1),
   SCHEDULING_METHOD_CODE     NUMBER,
   AUTO_INSTANTIATION_FLAG    VARCHAR2 (1),
   TYPE_CODE                  NUMBER,
   flag                       VARCHAR2 (10),
   note                       VARCHAR2 (500)
);

-------------------------------------------------------

SELECT * FROM staging_pm_schedule_table;

COMMIT;


--For flag reset

UPDATE staging_pm_schedule_table
   SET FLAG = NULL, NOTE = NULL
 WHERE FLAG = 'E';


------------------ Activities Table ----------------------

DROP TABLE staging_activ_pm_table;

CREATE TABLE staging_activ_pm_table
(
   INSTANCE_NUMBER           VARCHAR2 (30),
   ACTIVITY                  VARCHAR2 (40),
   ACTIVITY_ASSOCIATION_ID   NUMBER,
   INTERVAL_MULTIPLE         NUMBER,
   ALLOW_REPEAT_IN_CYCLE     VARCHAR2 (1)
);


-- Import Data first

--*****************--
-- ** EAM queries to prepare ** --
--*****************--

--Get Activity Association ID regarding to the imported data

UPDATE staging_activ_pm_table pm
   SET pm.ACTIVITY_ASSOCIATION_ID =
          (SELECT ACTIVITY_ASSOCIATION_ID
             FROM MTL_EAM_ASSET_ACTIVITIES_V
            WHERE     ACTIVITY = pm.ACTIVITY
                  AND INSTANCE_NUMBER = pm.INSTANCE_NUMBER);


-------------------------------------------------------

SELECT * FROM staging_activ_pm_table;

COMMIT;

------------------ Rules Table ----------------------

DROP TABLE staging_rules_pm_table;

CREATE TABLE staging_rules_pm_table
(
   INSTANCE_NUMBER    VARCHAR2 (30),
   RULE_TYPE          NUMBER,
   METER_ID           NUMBER,
   LIST_DATE          DATE,
   RUNTIME_INTERVAL   NUMBER,
   day_interval       NUMBER
);


-- Import Data first

--*****************--
-- ** EAM queries to prepare ** --
--*****************--

--Get meter ID and interval from meters


--*****************--
-- **For Meters only ** --
--*****************--

UPDATE staging_rules_pm_table rpm
   SET rpm.METER_ID =
          (SELECT met.METER_ID
             FROM eam_asset_meters_v met
            WHERE met.ASSET_NUMBER = rpm.INSTANCE_NUMBER),
       rpm.RUNTIME_INTERVAL =
          (SELECT met2.USER_DEFINED_RATE
             FROM eam_asset_meters_v met2
            WHERE met2.ASSET_NUMBER = rpm.INSTANCE_NUMBER)
 WHERE RULE_TYPE = 2;                                 --meters


--*****************--
--*****************--

-------------------------------------------------------

SELECT * FROM staging_rules_pm_table;



COMMIT;


--
UPDATE staging_pm_schedule_table
   SET flag = NULL, note = NULL;
--
--
--UPDATE staging_pm_schedule_table
--   SET NAME = REPLACE (NAME, '-2', '-3');
--
--UPDATE staging_pm_schedule_table
--   SET SET_NAME_ID = 1014;
--
COMMIT;

Wednesday, 20 December 2017

How to choose the best Bitcoins PTC Websites

Bitcoins through Paid to click (PTC) websites

PTC (Paid to Click) websites are websites that aim to earn money from home as they claim. But is it really worth it. That is what we are gonna talk about.




The procedure is simple, clear and you don’t need any investments to earn this online money (bitcoin). There are very many online bitcoin PTC sites in the market today, genuine and fake. 

Now let's decide if it worth to try this experiment or not. Let's Take an example from the most famous PTC website.


BTCClicks best ptc site 2017 

BTCclicks, one of the best of them as it is found in many blogs and websites. I tried it and make some calculations to check if it worth it.

First, I registered, then I surfed the ads. It was about 16 ad and it took me about 20 minutes to finish. Finally I earned 0.00046 mBTC.

By the way you can't withdraw if it is below 0.1000 mBTC as stated by the website. So let's calculate the average of getting a single withdraw.

If it took 20 minutes to finish 16 ads and I got 0.00046 then if I want to get to 0.1000 mBTC I need to calculate the average of earning from a single ad.

If we say:

0.00046 mBTC / 16 ads = 0.00002875 mBTC per ad

So, How many ads you need to click to reach 0.1000 mBTC:

0.1000 mBTC / 0.00002875 mBTC = 3478.26 ads

Then we need to know how much time it takes to get this clicks, but we need to know the average time per 1 ad first, so: 

20 minutes / 16 ads = 1.25 minute

Then,

3,478 ads x 1.25 minute = 4,347 minutes

4,347 minutes / 60 = about 73 hours

They say about this website that ads is up to 30 per day, so if we want to know how many days it can take from us with the hard work every day.

3,478 ads / 30 ads per day = 116 days

116 days / 30 days per month =  about 4 months


Conclusion


To get your first withdraw of 0.1000 mBTC that's 0.0001 BTC, and by the way that's 1.73 US dollar, you have to spend 4 months with 73 work hours to get you first approximately 2 US dollars. Are you ready for working all this time? 

So before considering the PTC websites, try this calculations to decide if it is worth your effort.

But, there is something is called referrals that help you to get those two bucks faster, I will research this and get back to you, may be there is still hope in the PTC websites.


Note: This is my first post in my first blog, so I will be pleased if you leave your feedback, and please be merciful.