예제 #1
0
        private void dispatcherTimer_Tick(object sender, EventArgs e)
        {
            try
            {
                if (Properties.Settings.Default.idCus > 0)
                {
                    db.Refresh(RefreshMode.KeepChanges, objCus);
                    spinPrice.EditValue = db.funCheckPrice(objClient.idClient).GetValueOrDefault();

                    txtTimePlay.Text = db.funConvertTime(SqlMethods.DateDiffSecond(objLoginCus.startTime, db.funGetdate()));

                    spinMoney.EditValue        = string.Format("{0}", SqlMethods.DateDiffSecond(objLoginCus.startTime, db.funGetdate()) * (db.funCheckPrice(objClient.idClient) / 3600));
                    spinCurrentMoney.EditValue = objCus.currentMoney.GetValueOrDefault();
                    txtEndtime.Text            = db.funConvertTime((int)(objCus.currentMoney.GetValueOrDefault() * 3600 / db.funCheckPrice(objClient.idClient).GetValueOrDefault()));
                    //if (objClient.IsExit == true)
                    //{
                    //    if (objLoginCus != null)
                    //    {
                    //        db.Login_Customers.DeleteOnSubmit(objLoginCus);
                    //        db.SubmitChanges();
                    //    }
                    //    System.Diagnostics.Process.Start("shutdown", "-s -f -t 5");
                    //}
                }
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); }
        }
예제 #2
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                objCus    = db.Customer_Informations.SingleOrDefault(p => p.username == txtUser.Text.Trim());
                objClient = db.clients.SingleOrDefault(p => p.clientName.Contains(Environment.MachineName));
                if (objClient == null)
                {
                    MessageBox.Show("Vui lòng tạo tên máy trong hệ thống trước khi login.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                if (objCus != null)
                {
                    db.Refresh(RefreshMode.KeepChanges, objCus);
                    if (objCus.currentMoney.GetValueOrDefault() > 0)
                    {
                        if (db.Login_Customers.Where(p => p.idCus == objCus.idCus).Count() > 0)
                        {
                            MessageBox.Show("Tài khoản của bạn đang được login tại một máy khác.Vui lòng kiểm tra lại.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }

                        var objLogin_Cus = new Login_Customer();
                        objLogin_Cus.idClient  = objClient.idClient;
                        objLogin_Cus.idCus     = objCus.idCus;
                        objLogin_Cus.startTime = DateTime.Now;
                        db.Login_Customers.InsertOnSubmit(objLogin_Cus);
                        db.SubmitChanges();

                        Properties.Settings.Default.idCus      = objCus.idCus;
                        Properties.Settings.Default.idLoginCus = objLogin_Cus.ID;
                        Properties.Settings.Default.idClient   = objClient.idClient;
                        Properties.Settings.Default.Save();


                        this.Hide();
                        using (var frm = new frmMain())
                        {
                            frm.ShowDialog();
                        }
                    }
                    else
                    {
                        MessageBox.Show("Tài khoản của bạn hiện không đủ để đăng nhập.Vui lòng nạp thêm tiền!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        txtUser.Text = "";
                        txtPass.Text = "";
                        txtUser.Focus();
                    }
                }
                else
                {
                    txtUser.Text = "";
                    txtPass.Text = "";
                    txtUser.Focus();
                }
            }
            catch (Exception ex) { MessageBox.Show("Lỗi:" + ex.Message, "Thông báo lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); }
        }