public TreatmentPlan(string customerID, TreatmentPlaneState state, DateTime creationDate, DateTime treatmentPlanCompleteDate)
 {
     CustomerID        = customerID;
     State             = state;
     this.CreationDate = creationDate;
     this.TreatmentPlanCompleteDate = treatmentPlanCompleteDate;
 }
        /// <summary>
        /// Update Treatmentplan table in Firebase if state changes.
        /// </summary>
        /// <param name="state"></param>
        /// <param name="iD"></param>
        public async void UpdateTreatmentPlanState(TreatmentPlaneState state, int iD)
        {
            ConnectToFirebase();

            int realState = 0;

            if (state.ToString() == "Created")
            {
                realState = 0;
            }
            if (state.ToString() == "Accepted")
            {
                realState = 1;
            }
            if (state.ToString() == "Finish")
            {
                realState = 2;
            }


            int    treatmentPlanID           = 0;
            string customerID                = "";
            string creationDate              = "";
            string treatmentPlanCompleteDate = "";

            string userName   = DAO.GetUserID();
            String myUsername = userName;

            myUsername = myUsername.Replace(".", "-");
            String node = myUsername + "TreatmentPlans" + "/";
            var    treatmentPlanData = new TreatmentPlanData
            {
                treatmentPlanID = iD,
            };

            var results = await firebase.Child(node).OnceAsync <TreatmentPlanData>();

            foreach (var details in results)
            {
                if (iD == details.Object.treatmentPlanID)
                {
                    treatmentPlanID           = details.Object.treatmentPlanID;
                    customerID                = details.Object.customerID;
                    creationDate              = details.Object.creationDate;
                    treatmentPlanCompleteDate = details.Object.treatmentPlanCompleteDate;
                    await firebase.Child(node).Child(details.Key).DeleteAsync();

                    AddNewTreatmentPlan(treatmentPlanID, customerID, realState, creationDate, treatmentPlanCompleteDate);
                    break;
                }
            }
        }
Exemple #3
0
        //Update Treatment Plan(UpdateTreatmentPlanState) table is in TreatmentPlanViewModel
        public void UpdateTreatmentPlanState(TreatmentPlaneState state, int PlanID)
        {
            //Keep count for Sychronization
            DAOCount++;
            sqlite.UpdateCountRecordSQlite(DAOCount);
            sqlite.UpdateTreatmentPlanState(state, PlanID);

            //firease
            if (!IsWorkOffline)
            {
                FBCount++;
                firebaseDAO.UpdateCountRecordFB(FBCount);
                firebaseDAO.UpdateTreatmentPlanState(state, PlanID);
            }
        }
 public TreatmentPlan(int treatmentPLanID, string customerID, TreatmentPlaneState state, DateTime creationDate, DateTime treatmentPlanCompleteDate, int iDForCustomer) : this(treatmentPLanID, customerID, state, creationDate, treatmentPlanCompleteDate)
 {
     IDForCustomer = iDForCustomer;
 }
        /// <summary>
        ///  Write to Firebase when reading from SQLIte.
        /// </summary>
        /// <param name="state"></param>
        /// <param name="iD"></param>
        public async void AddNewTreatmentPlanState(int treatmentPlanID, string customerID, TreatmentPlaneState state, string creationDate, string treatmentPlanCompleteDate)
        {
            ConnectToFirebase();

            int realState = 0;

            if (state.ToString() == "Created")
            {
                realState = 0;
            }
            if (state.ToString() == "Accepted")
            {
                realState = 1;
            }
            if (state.ToString() == "Finish")
            {
                realState = 2;
            }

            string userName   = DAO.GetUserID();
            String myUsername = userName;

            myUsername = myUsername.Replace(".", "-");
            String node = myUsername + "TreatmentPlans" + "/";
            var    treatmentPlanData = new TreatmentPlanData
            {
                treatmentPlanID           = treatmentPlanID,
                customerID                = customerID,
                state                     = realState,
                creationDate              = creationDate,
                treatmentPlanCompleteDate = treatmentPlanCompleteDate
            };

            await firebase.Child(node).PostAsync <TreatmentPlanData>(treatmentPlanData);
        }
        public async void ReadDataFromSQLite()
        {
            //Open connection with Firebase
            ConnectToFirebase();

            string userName   = DAO.GetUserID();
            String myUsername = userName;

            myUsername = myUsername.Replace(".", "-");

            String TreatmentNode              = myUsername + "Treatments" + "/";
            String CustomerNode               = myUsername + "Customers" + "/";
            String TreatmentPlanNode          = myUsername + "TreatmentPlans" + "/";
            String TreatmentPlanTreatmentNode = myUsername + "TreatmentPlanTreatments" + "/";
            String PaymentNode = myUsername + "Payments" + "/";

            //Read from Customer Table SQLite and update Firebase Customer Table.
            using (SqliteConnection db =
                       new SqliteConnection("Filename=dentalManagerDB.db"))
            {
                //Delete customer table in Firebase
                DeleteCustomer();

                db.Open();

                SqliteCommand selectCommand = new SqliteCommand
                                                  ("SELECT * from customers", db);

                SqliteDataReader query = selectCommand.ExecuteReader();

                //Populate customer table in Firebase.
                while (query.Read())
                {
                    //query.GetString(0);
                    //query.GetString(1);
                    //query.GetString(2);
                    //query.GetString(4);
                    //query.GetString(5);
                    //query.GetString(6);
                    //query.GetString(7);
                    //query.GetString(8);
                    //query.GetString(9);
                    //query.GetString(10);
                    //query.GetString(11);
                    //Convert.ToDateTime(query.GetString(3));
                    //query.GetString(12);
                    AddNewCustomer(query.GetString(0), query.GetString(1), query.GetString(2), Convert.ToDateTime(query.GetString(3)).ToString(), query.GetString(4), query.GetString(5), query.GetString(6), query.GetString(7), query.GetString(8), query.GetString(9), query.GetString(10), query.GetString(11), query.GetString(12));
                }

                db.Close();
            }


            //Read from SQLite to update Firebase Treatment table in Firebase
            using (SqliteConnection db =
                       new SqliteConnection("Filename=dentalManagerDB.db"))
            {
                //Delete Treatment from Firebase
                DeleteTreatment();

                db.Open();

                SqliteCommand selectCommand = new SqliteCommand
                                                  ("SELECT * from treatment", db);

                SqliteDataReader query = selectCommand.ExecuteReader();

                //populate treatment table in Firebase
                while (query.Read())
                {
                    Treatment treatment = new Treatment(
                        query.GetInt32(0),
                        query.GetString(1),
                        query.GetDecimal(2)
                        );
                    AddNewTreatment(treatment);
                    if (query.GetInt32(0) == 1)
                    {
                        AddNewTreatment(treatment);
                    }
                }

                db.Close();
            }

            //Read from SQLite and update treatmentPlan in Firebase
            using (SqliteConnection db =
                       new SqliteConnection("Filename=dentalManagerDB.db"))
            {
                //Delete table from Firebase
                DeletTreatmentPlanState();

                db.Open();

                SqliteCommand selectCommand = new SqliteCommand
                                                  ("SELECT * from treatmentPlan", db);

                SqliteDataReader query = selectCommand.ExecuteReader();

                //Populate plan state table in Firebase.
                while (query.Read())
                {
                    int    id                    = query.GetInt32(0);
                    string custumerID            = query.GetString(1);
                    int    state                 = query.GetInt32(2);
                    string creationDate          = query.GetString(3);
                    TreatmentPlaneState tempSate = (TreatmentPlaneState)state;
                    string   date2               = query.GetString(4);
                    DateTime datetime2           = Convert.ToDateTime("01/01/0001 00:00:00");
                    if (!date2.Equals("0"))
                    {
                        datetime2 = Convert.ToDateTime(date2);
                    }

                    TreatmentPlan treatmentPlan = new TreatmentPlan(
                        custumerID,
                        tempSate,
                        Convert.ToDateTime(query.GetString(3)),
                        datetime2
                        );

                    AddNewTreatmentPlanState(id, custumerID, tempSate, creationDate, date2);
                }

                db.Close();
            }


            //Read from SQLite and update treatmentPlanTreatments in Firebase
            using (SqliteConnection db =
                       new SqliteConnection("Filename=dentalManagerDB.db"))
            {
                //Delete from DeleteTreatmentPlanTreatments in Firebase
                DeleteTreatmentPlanTreatments();

                db.Open();

                SqliteCommand selectCommand = new SqliteCommand
                                                  ("SELECT * from treatmentPlanTreatments;", db);

                SqliteDataReader query = selectCommand.ExecuteReader();

                while (query.Read())
                {
                    int      TreatmentPlanTreatmentsID = query.GetInt32(0);
                    int      TreatmentPlanID           = query.GetInt32(1);
                    int      TreatmentID = query.GetInt32(2);
                    decimal  price       = query.GetDecimal(3);
                    DateTime date        = Convert.ToDateTime(query.GetString(4));
                    int      toothNum    = query.GetInt32(5);
                    string   comments    = query.GetString(6);
                    bool     isDone      = query.GetInt32(7) == 0 ? false : true;
                    string   name        = "test";

                    TreatmentOnPlan treatmentOnPlan = new TreatmentOnPlan(
                        TreatmentPlanTreatmentsID,
                        TreatmentPlanID,
                        TreatmentID,
                        price,
                        date,
                        toothNum,
                        comments,
                        isDone,
                        name
                        );

                    AddNewTreatmentPlanTreatments(treatmentOnPlan, treatmentOnPlan.TreatmentPlanTreatmentsID);
                }

                db.Close();
            }

            //Read from SQLite and update payments in Firebase
            using (SqliteConnection db =
                       new SqliteConnection("Filename=dentalManagerDB.db"))
            {
                //Delete payment from firebase
                DeletePayments();

                db.Open();

                SqliteCommand selectCommand = new SqliteCommand
                                                  ("SELECT * from payments", db);

                SqliteDataReader query = selectCommand.ExecuteReader();

                //populate payment with info from SQLite
                while (query.Read())
                {
                    Payments payments = new Payments(
                        query.GetInt32(0),
                        query.GetInt32(1),
                        query.GetString(2),
                        query.GetFloat(3),
                        Convert.ToDateTime(query.GetString(4))
                        );
                    AddNewpaymentObject(payments);
                }

                db.Close();
            }


            //Read from SQLite and update countRecor in Firebase
            using (SqliteConnection db =
                       new SqliteConnection("Filename=dentalManagerDB.db"))
            {
                db.Open();

                SqliteCommand selectCommand = new SqliteCommand
                                                  ("SELECT * from countRecord ", db);

                SqliteDataReader query = selectCommand.ExecuteReader();

                while (query.Read())
                {
                    query.GetInt32(0);
                    int userCntNum = query.GetInt32(1);
                    query.GetString(2);

                    UpdateCountRecordFB(userCntNum);
                }

                db.Close();
            }
        }