示例#1
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            MyVar.mMediboxSetting.DB_SERVER       = local_txtServer.Text;
            MyVar.mMediboxSetting.DB_NAME         = local_txtDatabase.Text;
            MyVar.mMediboxSetting.DB_USERID       = local_txtUser.Text;
            MyVar.mMediboxSetting.DB_USERPASSWORD = local_txtPassword.Text;

            //Save
            try
            {
                MediboxSetting mMediboxSetting = ObjectCopier.Clone(MyVar.mMediboxSetting);

                if (!mMediboxSetting.DB_ENCRIPT)
                {
                    mMediboxSetting.DB_ENCRIPT      = true;
                    mMediboxSetting.DB_SERVER       = CryptorEngine.Encrypt(mMediboxSetting.DB_SERVER, true);
                    mMediboxSetting.DB_USERID       = CryptorEngine.Encrypt(mMediboxSetting.DB_USERID, true);
                    mMediboxSetting.DB_PORT         = CryptorEngine.Encrypt(mMediboxSetting.DB_PORT, true);
                    mMediboxSetting.DB_USERPASSWORD = CryptorEngine.Encrypt(mMediboxSetting.DB_USERPASSWORD, true);
                    mMediboxSetting.DB_NAME         = CryptorEngine.Encrypt(mMediboxSetting.DB_NAME, true);
                }

                File.WriteAllText(MyVar.SettingsFileName, JsonConvert.SerializeObject(mMediboxSetting));
            }
            catch (Exception ex)
            {
                SanitaLog.e(TAG, ex);
            }

            SoftUpdatePresenter.SetConnectionConfig(local_txtServer.Text, local_txtUser.Text, local_txtPassword.Text, local_txtDatabase.Text, MyVar.DEFAULT_PORT);

            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.Close();
        }
示例#2
0
        private void bwAsync_DoWork(object sender, DoWorkEventArgs e)
        {
            Stopwatch mStopWatch = new Stopwatch();

            mStopWatch.Start();

            SanitaLogEx.d(TAG, "Start database cache...");
            PostMessage("Start database cache ...");
            IsCacheCompleted = false;

            try
            {
                //Update timer
                SystemInfo.NOW = SoftUpdatePresenter.GetCurrentTime(null, null);

                //Kiểm tra và nâng cấp cấu trúc database
                Splasher.Status = "Check and update database...";
                SoftUpdatePresenter.DoUpdateDatabaseSQL();

                using (IDbConnection connection = SoftUpdatePresenter.GetConnection())
                {
                    //Open connection
                    connection.Open();

                    //Begin transtation
                    using (IDbTransaction trans = connection.BeginTransaction())
                    {
                        Splasher.Status = "Đang xử lý : Danh sách danh mục...".Translate();
                        DM_Intent_Type.InitDefaultList(DM_Intent_TypePresenter.GetDM_Intent_Types(connection, trans));
                        MyVar.mListDM_Intent_Type = DM_Intent_Type.GetDefaultList(0).OrderBy(p => p.DM_Intent_TypeID).ToList();

                        DM_Entity_Type.InitDefaultList(DM_Entity_TypePresenter.GetDM_Entity_Types(connection, trans));
                        MyVar.mListDM_Entity_Type = DM_Entity_Type.GetDefaultList(0).OrderBy(p => p.DM_Entity_TypeID).ToList();

                        MyVar.mListUser   = UserPresenter.GetUsers(connection, trans);
                        MyVar.mListHome   = HomePresenter.GetHomes(connection, trans);
                        MyVar.mListRoom   = RoomPresenter.GetRooms(connection, trans);
                        MyVar.mListDevice = DevicePresenter.GetDevices(connection, trans);

                        //-----------------------------------------------------------------------------

                        //Commit transtation
                        trans.Commit();

                        //Close connection
                        connection.Close();
                    }
                }

                SanitaLogEx.d(TAG, "End database cache...");
            }
            catch (Exception ex)
            {
                SanitaLogEx.e(TAG, "bwAsync_DoWork error !", ex);
            }

            IsCacheCompleted = true;
        }
示例#3
0
 private void btnKiemTraKetNoi_Click(object sender, EventArgs e)
 {
     if (SoftUpdatePresenter.CheckConnection(local_txtServer.Text, local_txtUser.Text, local_txtPassword.Text, local_txtDatabase.Text, MyVar.DEFAULT_PORT))
     {
         SanitaMessageBox.Show("Kết nối cơ sở dữ liệu thành công !", "Thông Báo");
     }
     else
     {
         SanitaMessageBox.Show("Kết nối cơ sở dữ liệu không thành công !", "Thông Báo");
     }
 }
示例#4
0
        private void bwAsync_DoWork(object sender, DoWorkEventArgs e)
        {
            Stopwatch mStopWatch = new Stopwatch();

            mStopWatch.Start();

            SanitaLogEx.d(TAG, "Start database cache...");
            PostMessage("Start database cache ...");
            IsCacheCompleted = false;

            try
            {
                //Update timer
                SystemInfo.NOW = SoftUpdatePresenter.GetCurrentTime(null, null);

                //Kiểm tra và nâng cấp cấu trúc database
                Splasher.Status = "Check and update database...";
                SoftUpdatePresenter.DoUpdateDatabaseSQL();

                using (IDbConnection connection = SoftUpdatePresenter.GetConnection())
                {
                    //Open connection
                    connection.Open();

                    //Begin transtation
                    using (IDbTransaction trans = connection.BeginTransaction())
                    {
                        MyVar.mListLoaiPhong = LoaiPhongPresenter.GetLoaiPhongs();



                        //-----------------------------------------------------------------------------

                        //Commit transtation
                        trans.Commit();

                        //Close connection
                        connection.Close();
                    }
                }

                SanitaLogEx.d(TAG, "End database cache...");
            }
            catch (Exception ex)
            {
                SanitaLogEx.e(TAG, "bwAsync_DoWork error !", ex);
            }

            IsCacheCompleted = true;
        }
示例#5
0
        private void bwAsync_Worker(object sender, DoWorkEventArgs e)
        {
            SanitaLogEx.e(TAG, "Start get timer...");

            try
            {
                using (IDbConnection connection = SoftUpdatePresenter.GetConnection())
                {
                    //Open connection
                    connection.Open();

                    //Get time
                    DateTime dt = SoftUpdatePresenter.GetCurrentTime(null, null);

                    //Close connection
                    connection.Close();
                }
            }
            catch (Exception ex)
            {
                SanitaLog.e(TAG, ex);
            }
        }
示例#6
0
 private void bwAsync_Worker(object sender, DoWorkEventArgs e)
 {
     if (SoftUpdatePresenter.SynchDatabase(m_BackgroundWorker, 0))
     {
     }
 }
示例#7
0
文件: Program.cs 项目: BuiUyen/uyen
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            SanitaLog.SetLogName("Medibox");
            SanitaLogEx.SetLogName("Medibox");

            //Create temp
            if (!Directory.Exists(Path.Combine(Application.StartupPath, "Data")))
            {
                Directory.CreateDirectory(Path.Combine(Application.StartupPath, "Data"));
            }
            if (!Directory.Exists(Path.Combine(Application.StartupPath, "Log")))
            {
                Directory.CreateDirectory(Path.Combine(Application.StartupPath, "Log"));
            }

            //Get info
            object[] customAttributes = Assembly.GetExecutingAssembly().GetCustomAttributes(false);
            foreach (object attribute in customAttributes)
            {
                if (attribute.GetType() == typeof(AssemblyDescriptionAttribute))
                {
                    MyVar.mAppDescription = ((AssemblyDescriptionAttribute)attribute).Description;
                    SanitaLog.d(TAG, "Description:" + MyVar.mAppDescription);
                }
                if (attribute.GetType() == typeof(AssemblyTitleAttribute))
                {
                    MyVar.mAppName = ((AssemblyTitleAttribute)attribute).Title;
                    SanitaLog.d(TAG, "Name:" + MyVar.mAppName);
                }
                if (attribute.GetType() == typeof(AssemblyFileVersionAttribute))
                {
                    MyVar.mAppVersion = ((AssemblyFileVersionAttribute)attribute).Version;
                    SanitaLog.d(TAG, "Version:" + MyVar.mAppVersion);
                }
            }

            //Init Toast
            ToastNotification.DefaultToastGlowColor = eToastGlowColor.Red;
            ToastNotification.DefaultToastPosition  = eToastPosition.MiddleCenter;
            ToastNotification.ToastFont             = new System.Drawing.Font("Tahoma", 10);

            //Load setting
            try
            {
                MyVar.mMediboxSetting = JsonConvert.DeserializeObject <MediboxSetting>(File.ReadAllText(MyVar.SettingsFileName));
                if (MyVar.mMediboxSetting.DB_ENCRIPT)
                {
                    MyVar.mMediboxSetting.DB_ENCRIPT      = false;
                    MyVar.mMediboxSetting.DB_SERVER       = CryptorEngine.Decrypt(MyVar.mMediboxSetting.DB_SERVER, true);
                    MyVar.mMediboxSetting.DB_USERID       = CryptorEngine.Decrypt(MyVar.mMediboxSetting.DB_USERID, true);
                    MyVar.mMediboxSetting.DB_PORT         = CryptorEngine.Decrypt(MyVar.mMediboxSetting.DB_PORT, true);
                    MyVar.mMediboxSetting.DB_USERPASSWORD = CryptorEngine.Decrypt(MyVar.mMediboxSetting.DB_USERPASSWORD, true);
                    MyVar.mMediboxSetting.DB_NAME         = CryptorEngine.Decrypt(MyVar.mMediboxSetting.DB_NAME, true);
                }
            }
            catch (Exception ex)
            {
                SanitaLog.e(TAG, ex);
            }

            //Start application
            {
                //Check database
                while (true)
                {
                    String Localserver   = MyVar.mMediboxSetting.DB_SERVER;
                    String Localdatabase = MyVar.mMediboxSetting.DB_NAME;
                    String Localuserid   = MyVar.mMediboxSetting.DB_USERID;
                    String Localpassword = MyVar.mMediboxSetting.DB_USERPASSWORD;

                    SystemInfo.DatabaseType = Sanita.Utility.Database.Utility.DatabaseUtility.DATABASE_TYPE.POSTGRESQL;
                    SoftUpdatePresenter.SetConnectionConfig(Localserver, Localuserid, Localpassword, Localdatabase, MyVar.DEFAULT_PORT);

                    //Init database
                    SoftUpdatePresenter.InitDatabase();

                    //Check database OK
                    if (!SoftUpdatePresenter.IsDatabaseOK())
                    {
                        using (FormConfigDatabase form = new FormConfigDatabase())
                        {
                            if (form.ShowDialog() == DialogResult.OK)
                            {
                                continue;
                            }
                            else
                            {
                                SanitaMessageBox.Show("Lỗi kết nối cơ sở dữ liệu !", "Thông Báo");
                                return;
                            }
                        }
                    }

                    break;
                }

                //Start main form
                FormLogin mFormLogin = new FormLogin();
                Application.Run(mFormLogin);
            }
        }