Esempio n. 1
0
        public void SetDefaultAs(HardwareProfile curr)
        {
            if (curr == null)
            {
                return;
            }
            ActiveProfile  = curr;
            ProfileName    = curr.profileName;
            IsServer       = curr.isServer;
            DotPrinterName = curr.dotPrinterName;

            //PrinterName = curr.printerName;
            //ComPortName = curr.comPortName;
            //DataDir     =curr.dataDir;
            //UserName    =curr.userName;
            //Password    =curr.password;
            //BackupDir   =curr.backupDir;

            EnableCloudSync = curr.enableCloudSync;

            Local          = curr.Local;
            Cloud          = curr.Cloud;
            Database       = curr.database;
            SharedDatabase = curr.sharedDatabase;
            //SqlServerIP = curr.sqlServerIP;
            //SqlDatabase =curr.sqlDatabase;
            //SqlUserID   =curr.sqlUserID;
            //SqlPassword =curr.sqlPassword;

            //SqlServerIPCloud = curr.sqlServerIPCloud;
            //SharedDatabaseCloud = curr.SharedDatabaseCloud;
            //SqlUserIDCloud   = curr.sqlUserIDCloud;
            //SqlPasswordCloud = curr.sqlPasswordCloud;
        }
Esempio n. 2
0
        FormSwitchApartment.DelegateApartmentSwitchTo m_DelegateApartmentSwitchTo = null;  // 在FormLoad時設定,為傳參數回來設的Delegate
        void ApartmentSwitchTo(int apartmentID)
        {
            if (apartmentID == m_DefaultApartment.ApartmentID)
            {
                MessageBox.Show("同一門店,不用切換!");
                return;
            }
            var ap = m_AuthorizedApartment.FindByApartmentID(apartmentID);

            if (ap == null)
            {
                MessageBox.Show("找不到ApartmentID<" + apartmentID.ToString() + ">,無法切換門店!");
                return;
            }
            string Name = ap.IsApartmentNameNull()    ?"ID<" + apartmentID.ToString() + ">" :ap.ApartmentName;
            string Code = ap.IsAppartementCodeNull()?"未設店號"                         :ap.AppartementCode.ToString();

            MessageBox.Show("切換至 " + Name + "<" + Code + ">");
            string database = Decrypt(ap.DatabaseName);

            if (database.Trim() == m_Config.LoginDefaultProfile.database.Trim()) // 只有LoginDefaultProfile可以使用店長本地登入 云端同步, 其餘的一律使用云端登入
            {                                                                    // 是LoginDefaultProfile, 將LoginDefaultProfile取回.
                m_Config.CopyHardwareProfile(m_Config.LoginDefaultProfile, m_Config.ActiveProfile);
                m_Config.SetDefaultAs(m_Config.ActiveProfile);
            }
            else  // 切到不是HardwareConfig所指的那家店了,資料從[Apartment]取出,破壞性設定 ActiveProfile
            {
                DB.SqlCredential lo = new DB.SqlCredential();
                lo.ServerIP = Decrypt(ap.CloudServerIP);
                lo.UserID   = Decrypt(ap.CloudUserID);
                lo.Password = Decrypt(ap.CloudPassword);
                if (!TestConn(lo, database))
                {
                    return;
                }
                m_Config.ProfileName     = "AlphaGo<" + Name + ">";
                m_Config.IsServer        = false;
                m_Config.EnableCloudSync = false;
                m_Config.Local           = lo;
                m_Config.Database        = database;
                m_Config.SharedDatabase  = Decrypt(ap.CloudSharedDatabase);
                m_Config.Cloud.ServerIP  = "";
                m_Config.Cloud.UserID    = "";
                m_Config.Cloud.Password  = "";
            }
            global::VoucherExpense.Properties.Settings.Default.DamaiConnectionString = DB.SqlConnectString(m_Config.Local, m_Config.Database);
            foreach (Form form in this.MdiChildren)
            {
                form.Close();
            }
            Form Home = new FormHome(Operator, m_Config, ap, m_AuthorizedApartment);   // Debug 把所有部門都放進去

            this.Visible = false;
            Home.ShowDialog();
            Close();
        }
Esempio n. 3
0
        bool TestConn(DB.SqlCredential lo, string database)
        {
            string        connStr = DB.SqlConnectString(lo, database);
            SqlConnection conn    = new SqlConnection(connStr);

            try
            {
                conn.Open();
            }
            catch (Exception ex)
            {
                MessageBox.Show("資料庫<" + database + ">連線失敗,原因:" + ex.Message);
                return(false);
            }
            conn.Close();
            return(true);
        }