Esempio n. 1
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. 2
0
        private void cbxProfile_SelectedIndexChanged(object sender, EventArgs e)
        {
            ComboBox box         = sender as ComboBox;
            string   profileName = box.SelectedItem.ToString();

            Cursor = Cursors.WaitCursor;
            Application.DoEvents();
            foreach (HardwareProfile p in m_Cfg.ProfileList)
            {
                if (p.profileName == profileName)
                {
                    m_Cfg.SetDefaultAs(p);
                    SetGlobalConnectionString(m_Cfg);
                    ReadTable();
                    break;
                }
            }
            Cursor = Cursors.Arrow;
            textBoxUserID.Focus();
        }