Exemplo n.º 1
0
        /// <summary>
        /// Process Makkebun & Lawatan
        /// </summary>
        public static void SyncToServerForMakKebun()
        {
            IAppInfoRepo    AppInfoRepo    = new AppInfoRepo();
            IMakkebunRepo   MakkebunRepo   = new MakkebunRepo();
            ISemakTapakRepo SemakTapakRepo = new SemakTapakRepo();

            IList <makkebun> lstMakKebun = MakkebunRepo.GetAllToSync();

            for (int i = 0; i < lstMakKebun.Count; i++)
            {
                makkebun makkebunsqlite = lstMakKebun[i];
                using (IDbTransaction sqlTrans = MakkebunRepo.MySQLBeginTransaction())
                {
                    // INSERT MAKKEBUN TO MYSQL
                    int iSaveMakkebun = MakkebunRepo.CreateMySQL(makkebunsqlite, sqlTrans);
                    if (iSaveMakkebun > 0)
                    {
                        makkebun lastmakkebun = MakkebunRepo.GetLastMakkebunBy(makkebunsqlite.appinfo_id);
                        makkebunsqlite.newid_makkebun = lastmakkebun.id_makkebun;
                        makkebunsqlite.syncdate       = DateTime.Now;
                        // UPDATE MAKKEBUN SQLITE
                        MakkebunRepo.UpdateSync(makkebunsqlite);

                        // GET LAWATAN SQLITE DATA
                        semak_tapak semak_tapakSqlite = SemakTapakRepo.GetBy(makkebunsqlite.appinfo_id, makkebunsqlite.id_makkebun);
                        semak_tapakSqlite.newmakkebun_id = makkebunsqlite.newid_makkebun;

                        // INSERT LAWATAN TO MYSQL
                        int iSaveSemakTapak = SemakTapakRepo.CreateMySQL(semak_tapakSqlite, sqlTrans);
                        if (iSaveSemakTapak > 0)
                        {
                            semak_tapak lastsemak_tapak = SemakTapakRepo.GetLastSemakTapakBy(makkebunsqlite.appinfo_id, semak_tapakSqlite.newmakkebun_id);
                            semak_tapakSqlite.newid    = lastsemak_tapak.id;
                            semak_tapakSqlite.syncdate = DateTime.Now;
                            // UPDATE MAKKEBUN SQLITE
                            int iSemakTapakUpdateSync = SemakTapakRepo.UpdateSync(semak_tapakSqlite);
                        }
                    }
                    sqlTrans.Commit();
                }
                AppInfoRepo.CloseMySQLDB();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Process Normal
        /// </summary>
        public static void SyncToServer()
        {
            try
            {
                IAppInfoRepo AppInfoRepo = new AppInfoRepo();
                AppInfoRepo.ResetMySQLConnection(true);
                IMakkebunRepo   MakkebunRepo   = new MakkebunRepo();
                ISemakTapakRepo SemakTapakRepo = new SemakTapakRepo();

                IList <appinfo> lstAppInfoToSync = AppInfoRepo.GetAllWithoutSync();
                for (int i = 0; i < lstAppInfoToSync.Count; i++)
                {
                    appinfo appinfoSqlite = lstAppInfoToSync[i];
                    AppInfoRepo.OpenMySQLDB();
                    WriteLog("MySQLBeginTransaction");
                    using (IDbTransaction sqlTrans = AppInfoRepo.MySQLBeginTransaction())
                    {
                        string newrefno = GenerateRefNo(appinfoSqlite.negeri, null);
                        appinfoSqlite.newrefno = newrefno;
                        // Insert To MySQL Server - AppInfo
                        WriteLog("AppInfoRepo.CreateMySQL");
                        try
                        {
                            if (AppInfoRepo.CreateMySQL(appinfoSqlite, sqlTrans) > 0)
                            {
                                // Update data local sqlite
                                appinfoSqlite.syncdate = DateTime.Now;
                                AppInfoRepo.UpdateSync(appinfoSqlite);
                                WriteLog(string.Format("AppInfoRepo.CreateMySQL & Update SQLite - {0} - {1} - {2}", appinfoSqlite.id, appinfoSqlite.refno_new, appinfoSqlite.newrefno));

                                IList <makkebun> lstMakkebunSqlite = MakkebunRepo.GetAllByAppInfo(appinfoSqlite.id);
                                for (int j = 0; j < lstMakkebunSqlite.Count; j++)
                                {
                                    makkebun makkebunSqlite = lstMakkebunSqlite[j];
                                    // INSERT MAKKEBUN TO MYSQL
                                    WriteLog("MakkebunRepo.CreateMySQL");
                                    try
                                    {
                                        int iSaveMakkebun = MakkebunRepo.CreateMySQL(makkebunSqlite, sqlTrans);
                                        if (iSaveMakkebun > 0)
                                        {
                                            makkebun lastmakkebun = MakkebunRepo.GetLastMakkebunBy(appinfoSqlite.id);
                                            makkebunSqlite.newid_makkebun = lastmakkebun.id_makkebun;
                                            makkebunSqlite.syncdate       = DateTime.Now;
                                            // UPDATE MAKKEBUN SQLITE

                                            MakkebunRepo.UpdateSync(makkebunSqlite);
                                            WriteLog(string.Format("MakkebunRepo.CreateMySQL & Update SQLite - {0} - {1} - {2}", appinfoSqlite.id, makkebunSqlite.id_makkebun, makkebunSqlite.newid_makkebun));

                                            // GET LAWATAN SQLITE DATA
                                            semak_tapak semak_tapakSqlite = SemakTapakRepo.GetBy(appinfoSqlite.id, makkebunSqlite.id_makkebun);
                                            if (semak_tapakSqlite != null)
                                            {
                                                semak_tapakSqlite.newmakkebun_id = makkebunSqlite.newid_makkebun;
                                                // INSERT LAWATAN TO MYSQL
                                                WriteLog("SemakTapakRepo.CreateMySQL");
                                                try
                                                {
                                                    int iSaveSemakTapak = SemakTapakRepo.CreateMySQL(semak_tapakSqlite, sqlTrans);
                                                    if (iSaveSemakTapak > 0)
                                                    {
                                                        semak_tapak lastsemak_tapak = SemakTapakRepo.GetLastSemakTapakBy(appinfoSqlite.id, semak_tapakSqlite.newmakkebun_id);
                                                        semak_tapakSqlite.newid    = lastsemak_tapak.id;
                                                        semak_tapakSqlite.syncdate = DateTime.Now;
                                                        // UPDATE MAKKEBUN SQLITE
                                                        int iSemakTapakUpdateSync = SemakTapakRepo.UpdateSync(semak_tapakSqlite);
                                                        WriteLog(string.Format("SemakTapakRepo.CreateMySQL & Update SQLite - {0} - {1} - {2}", appinfoSqlite.id, semak_tapakSqlite.id, semak_tapakSqlite.newid));
                                                    }
                                                }
                                                catch (Exception ex)
                                                {
                                                    WriteLog(string.Format("ERROR-SemakTapakRepo.CreateMySQL-{0}", ex.GetFullMessage()));
                                                }
                                            }
                                            else
                                            {
                                                WriteLog(string.Format("Maklumat Kebun Belum Lawat - {0}", makkebunSqlite.id_makkebun));
                                            }
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        WriteLog(string.Format("ERROR-MakkebunRepo.CreateMySQL-{0}", ex.GetFullMessage()));
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            WriteLog(string.Format("ERROR-AppInfoRepo.CreateMySQL-appinfo:{0}-refno_new:{1}-MESSAGE:{2}", appinfoSqlite.id, appinfoSqlite.refno_new, ex.GetFullMessage()));
                        }

                        sqlTrans.Commit();
                    }
                    AppInfoRepo.CloseMySQLDB();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.GetFullMessage());
            }
        }