Esempio n. 1
0
        private void FormLogin_Shown(object sender, EventArgs e)
        {
            this.cbxProfile.SelectedIndexChanged += new System.EventHandler(this.cbxProfile_SelectedIndexChanged);     // 防止未顯示就去Call
#if DEBUG
            if (!m_Cfg.IsServer)
            {
                System.Threading.Thread.Sleep(250);   // 給 WinExec一點時間,執行完 Net Use * /Delete /Yes
            }
            ShowLogin(true);
            if (!ReadTable())
            {
                MyFunction.HardwareCfg = m_Cfg;
                Form hardware = new FormHardware();
                hardware.ShowDialog();
                Close();
                return;
            }
            var row = CheckLogin("alexjean", "love2015");
            if (row != null)
            {
                GetHeaderYear();
                m_Cfg.CopyHardwareProfile(m_Cfg.ActiveProfile, m_Cfg.LoginDefaultProfile);         // 切換門店時, 比對LoginDefaultProfile,所以存下

                Form Home = new FormHome(row, m_Cfg, m_DefaultApartment, damaiDataSet.Apartment);  // Debug 把所有部門都放進去
                Visible = false;
                Home.ShowDialog();
                Close();
            }
#endif
        }
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
        private void btnLogin_Click(object sender, EventArgs e)
        {
            var row = CheckLogin();

            if (row != null)
            {
                if (m_DefaultApartment == null)
                {
                    MessageBox.Show("沒有預定要登入的門店!請找碼農!");
                    return;
                }
                var authApartments = from auth in damaiDataSet.OperatorAuthList
                                     where auth.OperatorID == row.OperatorID
                                     select auth;
                var au = from a in authApartments where a.ApartmentID == m_DefaultApartment.ApartmentID select a;
                if (au.Count() <= 0)
                {
                    MessageBox.Show("你在<" + m_DefaultApartment.ApartmentName.Trim() + ">店號" + m_DefaultApartment.AppartementCode.ToString() + ",沒有登入權限!");
                    return;
                }

                GetHeaderYear();                // 呼叫Home之前要設好
                Visible = false;
                foreach (var ap in damaiDataSet.Apartment)
                {
                    var found = from a in authApartments where a.ApartmentID == ap.ApartmentID select a;
                    if (found.Count() <= 0)
                    {
                        ap.Delete();                        // 不在授權表的拿掉
                    }
                }
                damaiDataSet.Apartment.AcceptChanges();

                m_Cfg.CopyHardwareProfile(m_Cfg.ActiveProfile, m_Cfg.LoginDefaultProfile);    // 為了讓FormHome切換時,ActiveProfile==LoginDefaultProfile 要用Local<->Cloud對應
                Form Home = new FormHome(row, m_Cfg, m_DefaultApartment, damaiDataSet.Apartment);
                Home.ShowDialog();
                Close();
            }
            else if (ErrorCount++ > 5)
            {
                MessageBox.Show("錯誤次數過多! Bye!");
                Close();
            }
        }