Exemplo n.º 1
0
        public void linkSql()
        {
            try
            {
                // 连接数据库引擎
                using (contsDataContext aDataContext = new contsDataContext(ConnectionString))
                {
                    if (!aDataContext.DatabaseExists())
                    {
                        aDataContext.CreateDatabase();
                        // Console.WriteLine("数据库已经创建!");
                    }
                    else
                    {
                        // Console.WriteLine("数据库已经存在!");
                    }

                    // 读取数据表内容
                    var aUsers = from r in aDataContext.User select r;
                    foreach (User aUser in aUsers)
                    {
                        Console.WriteLine($"{aUser.id} : {aUser.password}");
                    }

                    Console.WriteLine("插入新记录……");
                    //User aNewUser = new User { id = "131", password = "******" };
                    //aDataContext.User.InsertOnSubmit(aNewUser);

                    //Conts aNewConts = new Conts
                    //{
                    //    id = "131",
                    //    name = "joey",
                    //    mobile = "1522328132",
                    //    birth = "1991-01-01",
                    //    sex = "Male",
                    //    memo = "didnuas"
                    //};
                    //aDataContext.Conts.InsertOnSubmit(aNewConts);


                    // Console.WriteLine("提交数据……");
                    aDataContext.SubmitChanges();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
            }
        }
Exemplo n.º 2
0
        public void Insert()
        {
            LoginModel       aLogin       = new LoginModel();
            contsDataContext aDataContext = new contsDataContext(ConnectionString);
            Conts            aNewConts    = new Conts
            {
                id     = "131",
                name   = Name,
                mobile = Mobile,
                birth  = Birth,
                sex    = Sex,
                memo   = Memo
            };

            aDataContext.Conts.InsertOnSubmit(aNewConts);
            aDataContext.SubmitChanges();
        }
Exemplo n.º 3
0
        //显示数据
        public void MainMode()
        {
            contsDataContext aDataContext = new contsDataContext(ConnectionString);
            var aConts = from r in aDataContext.Conts where r.id == LoginModel.id select r;

            foreach (Conts aCont in aConts)
            {
                memberData.Add(new MainModel()
                {
                    Name   = aCont.name,
                    Mobile = aCont.mobile,
                    Memo   = aCont.memo,
                    Sex    = aCont.sex,
                    Birth  = aCont.birth
                });
            }
        }
Exemplo n.º 4
0
        public void TurntoMain()
        {
            contsDataContext aDataContext = new contsDataContext(ConnectionString);

            User aUser = (from r in aDataContext.User where r.id == _user select r).FirstOrDefault();

            if (aUser == null)
            {
                MessageBox.Show("查无此用户");
            }
            else if (aUser.password == _password)
            {
                id = aUser.id;
                MainWindow mainWindow = new MainWindow();
                App.Current.MainWindow = mainWindow;
                mainWindow.Show();
            }
            else if (aUser.password != _password)
            {
                MessageBox.Show("密码错误!");
            }
        }