private void cbnolot_SelectedIndexChanged(object sender, EventArgs e)
        {
            ComboBox cbx = sender as ComboBox;

            id_makkebun = Convert.ToInt32(cbx.SelectedValue);
            semak_tapak semak_tapak = SemakTapakRepo.GetBy(appinfo_id, id_makkebun);

            semak_tapak_id = semak_tapak == null ? 0 : semak_tapak.id;
            BindFormLawatanPengesahanKebun(appinfo_id, id_makkebun, semak_tapak_id);
        }
        private void BindRBForm(semak_tapak semak_tapak)
        {
            if (!string.IsNullOrEmpty(semak_tapak.kecerunan))
            {
                if (semak_tapak.kecerunan == "Lebih 25 Darjah")
                {
                    rbLebih30Darjah.Checked = true;
                }
                else if (semak_tapak.kecerunan == "Kurang 25 Darjah")
                {
                    rbKurarng30Darjah.Checked = true;
                }
            }
            else
            {
                rbLebih30Darjah.Checked   = false;
                rbKurarng30Darjah.Checked = false;
            }

            if (!string.IsNullOrEmpty(semak_tapak.jentera))
            {
                if (semak_tapak.jentera == "Ya")
                {
                    rbJenteraYa.Checked = true;
                }
                else if (semak_tapak.jentera == "Tidak")
                {
                    rbJenteraTidak.Checked = true;
                }
            }
            else
            {
                rbJenteraYa.Checked    = false;
                rbJenteraTidak.Checked = false;
            }


            if (!string.IsNullOrEmpty(semak_tapak.ganoderma))
            {
                if (semak_tapak.ganoderma == "Ya")
                {
                    rbGenodermaYa.Checked = true;
                }
                else if (semak_tapak.ganoderma == "Tidak")
                {
                    rbGenodermaTidak.Checked = true;
                }
            }
            else
            {
                rbGenodermaYa.Checked    = false;
                rbGenodermaTidak.Checked = false;
            }
        }
        private void BindFormLawatanPengesahanKebun(int appinfo_id, int id_makkebun, int?semak_tapak_id)
        {
            semak_tapak semak_tapak = SemakTapakRepo.GetBy(appinfo_id, id_makkebun, semak_tapak_id);

            if (semak_tapak_id == null || semak_tapak_id <= 0)
            {
                semak_tapak = new semak_tapak();
            }
            //else
            //{
            //    semak_tapak = SemakTapakRepo.GetBy(appinfo_id, id_makkebun, semak_tapak_id);
            //}

            if (id_makkebun > 0)
            {
                cbnolot.SelectedValue = id_makkebun;
            }

            //if (!string.IsNullOrEmpty(semak_tapak.jenis_tanah))
            //{
            cbjenis_tanah.SelectedValue = string.IsNullOrEmpty(semak_tapak.jenis_tanah) ? "" : semak_tapak.jenis_tanah;
            //}
            txtbantuan.Text       = semak_tapak.bantuan;
            txtbil_pokok_tua.Text = semak_tapak.bil_pokok_tua;
            txtcatatan.Text       = semak_tapak.catatan;
            //cbjenis_tanah.SelectedValue = semak_tapak.ganoderma;
            txthasil.Text = semak_tapak.hasil;
            //cbjenis_tanah.SelectedValue = semak_tapak.jentera;
            //if (!string.IsNullOrEmpty(semak_tapak.kaedah))
            //{
            cbkaedah.SelectedValue = string.IsNullOrEmpty(semak_tapak.kaedah) ? "" : semak_tapak.kaedah;
            //}
            //txtker.SelectedValue = semak_tapak.kecerunan;
            //cbjenis_tanah.SelectedValue = semak_tapak.lampiran;
            txtluas.Text = semak_tapak.luas.ToString("#.##");
            txtperatusan_serangan.Text = semak_tapak.peratusan_serangan.ToString("#.##");
            txtptk_lawat.Text          = semak_tapak.ptk_lawat;
            if (!string.IsNullOrEmpty(semak_tapak.tarikh_lawat))
            {
                txttarikh_lawat.Value = DateTime.ParseExact(semak_tapak.tarikh_lawat, "dd-MM-yyyy", CultureInfo.InvariantCulture);
            }
            txtumr_pokok_tua.Text = semak_tapak.umr_pokok_tua;

            BindRBForm(semak_tapak);
        }
示例#4
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();
            }
        }
示例#5
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());
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                bool IsNew = false;

                if (id_makkebun <= 0)
                {
                    MessageBox.Show("Harap masukkan data dari Makluma Kebun");
                    return;
                }

                semak_tapak semak_tapak = SemakTapakRepo.GetBy((int)semak_tapak_id);
                if (semak_tapak == null)
                {
                    semak_tapak = new semak_tapak();
                    IsNew       = true;
                }

                semak_tapak.id                 = (int)semak_tapak_id;
                semak_tapak.makkebun_id        = id_makkebun;
                semak_tapak.appinfo_id         = appinfo_id;
                semak_tapak.kaedah             = cbkaedah.SelectedValue.ToString();
                semak_tapak.bantuan            = txtbantuan.Text;
                semak_tapak.jenis_tanah        = cbjenis_tanah.SelectedValue.ToString();
                semak_tapak.kecerunan          = rbLebih30Darjah.Checked ? "Lebih 25 Darjah" : rbKurarng30Darjah.Checked ? "Kurang 25 Darjah" : "";
                semak_tapak.jentera            = rbJenteraYa.Checked ? "Ya" : rbJenteraTidak.Checked ? "Tidak" : "";
                semak_tapak.ganoderma          = rbGenodermaYa.Checked ? "Ya" : rbGenodermaTidak.Checked ? "Tidak" : "";
                semak_tapak.peratusan_serangan = Convert.ToDouble(txtperatusan_serangan.Text);
                semak_tapak.umr_pokok_tua      = txtumr_pokok_tua.Text;
                semak_tapak.hasil              = txthasil.Text;
                semak_tapak.bil_pokok_tua      = txtbil_pokok_tua.Text;
                semak_tapak.tarikh_lawat       = txttarikh_lawat.Text;
                semak_tapak.ptk_lawat          = txtptk_lawat.Text;
                semak_tapak.luas               = Convert.ToDouble(txtluas.Text);
                semak_tapak.catatan            = txtcatatan.Text;
                //semak_tapak.created = txtcreated.Text;
                //semak_tapak.createdby = txtcreatedby.Text;
                //semak_tapak.lampiran = txtlampiran.Text;
                BindRBForm(semak_tapak);

                if (IsNew)
                {
                    try
                    {
                        semak_tapak.created   = DateTime.Now;;
                        semak_tapak.createdby = new VariableSettingRepo().GetBy("UserKeyIn").Value;
                        semak_tapak.lampiran  = "";// txtlampiran.Text;
                        SemakTapakRepo.Create(semak_tapak);
                        MessageBox.Show("Data berhasil disimpan [" + refno_new + " | " + MakkebunRepo.GetBy(id_makkebun).nolot + "]");
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.GetFullMessage());
                    }
                }
                else
                {
                    try
                    {
                        SemakTapakRepo.Edit(semak_tapak);
                        MessageBox.Show("Data berhasil disimpan [" + refno_new + " | " + MakkebunRepo.GetBy(id_makkebun).nolot + "]");
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.GetFullMessage());
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.GetFullMessage() + " - Harap periksa data input kembali");
                return;
            }
            button2.PerformClick();
        }