コード例 #1
0
        private void button_login_Click(object sender, RoutedEventArgs e)
        {
            if (userID.Text == "" || password.Password == "" || typebox.Text == "")
            {
                MessageBox.Show("请您先填好信息再登录!");
                return;
            }

            int x;

            if (!int.TryParse(userID.Text, out x))
            {
                MessageBox.Show("您输入的信息有误");
                return;
            }

            using (SubwayDatabaseEntities6 c = new SubwayDatabaseEntities6())
            {
                var q = from t in c.Admin
                        where t.aId == x && t.aPassword == password.Password.ToString() && t.Type == typebox.Text
                        select t;
                if (q != null && q.Count() >= 1)
                {
                    AdminMainWindow.adminType = typebox.Text;
                    UserManager um = new UserManager();
                    um.ShowDialog();
                }
                else
                {
                    MessageBox.Show("您输入的信息有误");
                }
            }
        }
コード例 #2
0
ファイル: FastBuyTicket.xaml.cs プロジェクト: ezzzzz111/-
        private void get_fast_Ticket_button_click(object sender, RoutedEventArgs e)
        {
            Button btn = e.Source as Button;

            if (flag == false || UserId.Text == "" || password.Password == "")
            {
                MessageBox.Show("请您选输入好信息再取票!");
                MessageBox.Show(flag + UserId.Text + password.Password);
            }
            else
            {
                int x;
                if (int.TryParse(UserId.Text, out x))
                {
                    using (SubwayDatabaseEntities6 c = new SubwayDatabaseEntities6())
                    {
                        var q = from t in c.User
                                where t.uID == x && t.uPassword == password.Password.ToString()
                                select t;
                        if (q != null && q.Count() >= 1)
                        {
                            double balance = 0;
                            foreach (var v in q)
                            {
                                name = v.uName;
                                id   = v.uID;
                                if (v.balance >= price)
                                {
                                    v.balance -= price;
                                    balance    = v.balance;
                                }
                                else
                                {
                                    MessageBox.Show("您当前余额不足,请联系管理员充值!");
                                    return;
                                }
                            }
                            c.SaveChanges();
                            var p = from t in c.Ticket
                                    select t;
                            test test = new test();
                            test.testGrid.ItemsSource = p.ToList();
                            Ticket ticket = new Ticket()
                            {
                                UserName     = name,
                                UserID       = id,
                                Type         = type,
                                BeginStation = "*",
                                EndStation   = "*",
                                Price        = price,
                                num          = 1,
                            };
                            try
                            {
                                c.Ticket.Add(ticket);
                                c.SaveChanges();
                                MessageBox.Show("恭喜您,购票成功!\r\n您当前余额为;" + balance);
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show("购票失败:" + ex.Message);
                            }
                            var o = from t in c.Ticket
                                    select t;
                        }
                        else
                        {
                            MessageBox.Show("您输入的用户名和密码有误!");
                        }
                    }
                }
                else
                {
                    MessageBox.Show("您输入的用户名和密码有误!");
                }
            }
        }