Exemplo n.º 1
0
        private void loginButton_Click(object sender, EventArgs e)
        {
            try
            {
                var cn = Properties.Settings.Default.MainConnectionString;
                if (IsServerConnected(cn))
                {
                    UserManagerDataClassesDataContext db = new UserManagerDataClassesDataContext(cn);
                    foreach (var q in db.UserTables)
                    {
                        if (q.User == this.UserNametextBox.Text && q.Password == this.PasswordTextBox.Text)
                        {
                            this.Hide();
                            LoginInfo login = new LoginInfo();
                            login.cityID       = q.City;
                            login.Name         = q.Name;
                            login.Id           = q.Id;
                            login.family       = q.Family;
                            login.permission   = q.Permission.Value;
                            login.user         = q.User;
                            login.update       = q.Update.Value;
                            login.messages     = q.Messages;
                            login.version      = q.Version ?? default(int);
                            login.adminVersion = q.AdminVersion ?? default(bool);
                            if (login.version > currentVersion && !login.adminVersion)
                            {
                                MessageBox.Show("نسخه شما بروز نیست . آخرین نسخه بروز شده را نصب کنید ", "پیغام",
                                                MessageBoxButtons.OK,
                                                MessageBoxIcon.Stop);
                                this.Close();
                                return;
                            }


                            SqlManipulator sql = new SqlManipulator();
                            if (!login.adminVersion)
                            {
                                if (login.update)
                                {
                                    MessageBox.Show(login.messages, "پیغام ",
                                                    MessageBoxButtons.OK,
                                                    MessageBoxIcon.Information);
                                    try {
                                        sql.MessagesSeenStatus(false, login);
                                    }
                                    catch (Exception)
                                    { MessageBox.Show("خطا در  پیغام"); }
                                }
                            }
                            string cityName = sql.getCityName(login.cityID);
                            login.cityName = cityName;
                            form.setLoginData(login);

                            Properties.Settings.Default.LastUser = this.UserNametextBox.Text;

                            tmr = new Timer();

                            //set time interval 3 sec

                            tmr.Interval = 3500;

                            //starts the timer
                            formwait = new SplashScreenForm();
                            formwait.Show();
                            tmr.Start();

                            tmr.Tick  += tmr_Tick;
                            permission = q.Permission.Value;
                            Properties.Settings.Default.Save();
                            return;
                        }
                    }
                    MessageBox.Show("نام کاربری و گذر واژه فاقد اعتبار است", "خطا",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                    return;
                }
                else
                {
                    MessageBox.Show("ارتباط با سرور قطع است ، تنظیمات سرور را بررسی کنید", "خطا",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);

                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }