private void UpdateProfileForm_Load(object sender, System.EventArgs e)
        {
            Models.DatabaseContext databaseContext = null;
            try
            {
                databaseContext = new Models.DatabaseContext();

                Models.User currentUser =
                    databaseContext.Users
                    .Where(current => current.Id == Infrastructure.Utility.AuthenticatedUser.Id)
                    .FirstOrDefault();

                if (currentUser == null)
                {
                    System.Windows.Forms.Application.Exit();
                }

                userCodeTextBox.Text  = currentUser.Id;
                firstNameTextBox.Text = currentUser.FirstName;
                lastNameTextBox.Text  = currentUser.LastName;
                if (currentUser.IsMan == true)
                {
                    maleRadioButton.Checked   = true;
                    femaleRadioButton.Checked = false;
                }
                else
                {
                    maleRadioButton.Checked   = false;
                    femaleRadioButton.Checked = true;
                }
                if (currentUser.IsMarried == true)
                {
                    marridCheckBox.Checked = true;
                    singleCheckBox.Checked = false;
                }
                else
                {
                    marridCheckBox.Checked = false;
                    singleCheckBox.Checked = true;
                }
                ageTextBox.Text         = currentUser.Age;
                addressTextBox.Text     = currentUser.Address;
                phoneTextBox.Text       = currentUser.Phone;
                mobileTextBox.Text      = currentUser.Mobile;
                postalCodeTextBox.Text  = currentUser.PostalCode;
                descriptionTextBox.Text = currentUser.Description;
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);

                return;
            }
            finally
            {
                if (databaseContext != null)
                {
                    databaseContext.Dispose();

                    databaseContext = null;
                }
            }
        }
示例#2
0
        private void registerButton_Click(object sender, System.EventArgs e)
        {
            Models.DatabaseContext databaseContext = null;
            string errorMessage = string.Empty;

            if (string.IsNullOrWhiteSpace(usernameTextBox.Text) ||
                string.IsNullOrWhiteSpace(passwordTextBox.Text))
            {
                usernameTextBox.Text =
                    usernameTextBox.Text.Replace("", string.Empty);

                passwordTextBox.Text =
                    passwordTextBox.Text.Replace("", string.Empty);
                System.Windows.Forms.MessageBox.Show("نام کاربری و رمز عبور اجباری می باشد");

                if (usernameTextBox.Text == string.Empty)
                {
                    usernameTextBox.Focus();
                }
                else
                {
                    passwordTextBox.Focus();
                }

                return;
            }
            if (string.IsNullOrEmpty(usernameTextBox.Text) || string.IsNullOrEmpty(passwordTextBox.Text))
            {
                System.Windows.Forms.MessageBox.Show("وارد کردن نام کاربری و رمز عبور اجباری است ");
                return;
            }

            if (usernameTextBox.Text.Length < 6)
            {
                errorMessage += "نام کاربری حداقل 6 کاراکتر میباشد";
            }
            if (passwordTextBox.Text.Length < 8)
            {
                errorMessage += Environment.NewLine + "رمز عبور حداقل 8 کاراکتر میباشد";
            }
            if (string.IsNullOrEmpty(errorMessage) == false)
            {
                System.Windows.Forms.MessageBox.Show(errorMessage);
                Reset();
                return;
            }
            try
            {
                databaseContext = new Models.DatabaseContext();

                Models.User user = databaseContext.Users
                                   .Where(x => x.Username.ToLower() == usernameTextBox.Text.ToLower())
                                   .FirstOrDefault();

                if (user != null)
                {
                    errorMessage += "این نام کاربری موجود است";
                    System.Windows.Forms.MessageBox.Show(errorMessage);
                    Reset();
                    return;
                }

                user = new Models.User()
                {
                    Username = usernameTextBox.Text,
                    Password = passwordTextBox.Text,
                    FullName = fullnameTextBox.Text,
                };

                databaseContext.Users.Add(user);
                databaseContext.SaveChanges();
                System.Windows.Forms.MessageBox.Show("اطلاعات با موفقیت ثبت شد");
                return;
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("Error" + ex.Message);
                Reset();
                return;
            }
            finally
            {
                if (databaseContext != null)
                {
                    databaseContext.Dispose();
                }
            }
        }
        private void registerButton_Click(object sender, System.EventArgs e)
        {
            Models.DatabaseContext databaseContext = null;

            try
            {
                databaseContext =
                    new Models.DatabaseContext();

                Models.User foundeduser =
                    databaseContext.Users
                    .Where(current => current.Id == userCodeTextBox.Text)
                    .FirstOrDefault();

                if (foundeduser == null)
                {
                    System.Windows.Forms.MessageBox.Show("There Is No Such A User Anymore!");

                    Close();
                }
                foundeduser.FirstName = firstNameTextBox.Text;
                foundeduser.LastName  = lastNameTextBox.Text;
                if (maleRadioButton.Checked == true)
                {
                    foundeduser.IsMan = true;
                }
                if (femaleRadioButton.Checked == true)
                {
                    foundeduser.IsMan = false;
                }
                if (marridCheckBox.Checked == true)
                {
                    foundeduser.IsMarried = true;
                }
                if (singleCheckBox.Checked == true)
                {
                    foundeduser.IsMarried = true;
                }
                foundeduser.Age         = ageTextBox.Text;
                foundeduser.Address     = addressTextBox.Text;
                foundeduser.Phone       = phoneTextBox.Text;
                foundeduser.Mobile      = mobileTextBox.Text;
                foundeduser.PostalCode  = postalCodeTextBox.Text;
                foundeduser.Description = descriptionTextBox.Text;

                databaseContext.SaveChanges();

                System.Windows.Forms.MessageBox.Show("Register done!");

                Close();
            }

            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);

                return;
            }

            finally
            {
                if (databaseContext != null)
                {
                    databaseContext.Dispose();

                    databaseContext = null;
                }
            }
        }
示例#4
0
        private void RegisterButton_click(object sender, EventArgs e)
        {
            Models.DatabaseContext databaseContext = null;
            databaseContext = new Models.DatabaseContext();
            try
            {
                Models.User user = databaseContext.Users.Where(current => string.Compare(current.Username, usernameTextBox.Text, true) == 0).FirstOrDefault();
                if (user != null)
                {
                    System.Windows.Forms.MessageBox.Show("This username is already exist!");
                    usernameTextBox.Focus();
                    return;
                }

                user = new Models.User();

                user.FullName = fullnameTextBox.Text;
                user.Password = passwordTextBox.Text;
                user.Username = usernameTextBox.Text;
                user.IsActive = true;
                databaseContext.Users.Add(user);
                databaseContext.SaveChanges();
                System.Windows.Forms.MessageBox.Show("Registration Done!");
                resetButton_click(null, null);
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Error: " + ex.Message);
            }
            finally
            {
                if (databaseContext != null)
                {
                    databaseContext.Dispose();
                    databaseContext = null;
                }
            }

            //if ((string.IsNullOrWhiteSpace(usernameTextBox.Text)) || (string.IsNullOrWhiteSpace(passwordTextBox.Text))) {
            //	usernameTextBox.Text = usernameTextBox.Text.Replace("", string.Empty);
            //	passwordTextBox.Text = passwordTextBox.Text.Replace("", string.Empty);
            //	System.Windows.Forms.MessageBox.Show("username and password is required!");



            //	Models.DatabaseContext databaseContext = null;
            //	try
            //	{
            //		databaseContext = new Models.DatabaseContext();
            //		Models.User user = databaseContext.Users.Where(current => string.Compare(current.Username, usernameTextBox.Text, true) == 0).FirstOrDefault();

            //		if (user != null)
            //		{
            //			System.Windows.Forms.MessageBox.Show("this username is already exist!");
            //			usernameTextBox.Focus();
            //			return;
            //		}
            //		user = new Models.User();
            //		user.Username = usernameTextBox.Text;
            //		user.Password = passwordTextBox.Text;
            //		user.FullName = passwordTextBox.Text;

            //		user.IsActive = true;
            //		databaseContext.Users.Add(user);
            //		databaseContext.SaveChanges();

            //		System.Windows.Forms.MessageBox.Show("Registration done!");

            //		resetButton_click(null, null);
            //	}
            //	catch (System.Exception ex)
            //	{
            //		System.Windows.Forms.MessageBox.Show("Error:", ex.Message);

            //	}
            //	finally
            //	{
            //		if (databaseContext != null)
            //		{
            //			databaseContext.Dispose();
            //			databaseContext = null;
            //		}
            //	}
            //}
        }
示例#5
0
        internal static void Main()
        {
            // **************************************************
            System.Windows.Forms.Application.EnableVisualStyles();
            System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false);
            // **************************************************

            // **************************************************
            // **************************************************
            // **************************************************
            Models.DatabaseContext databaseContext = null;

            try
            {
                databaseContext =
                    new Models.DatabaseContext();

                // **************************************************
                // **************************************************

                // **************************************************
                //var users =
                //	databaseContext.Users
                //	.ToList()
                //	;

                //int userCount = users.Count;
                // **************************************************

                // **************************************************
                //int userCount =
                //    databaseContext.Users
                //    .Count();
                // **************************************************

                // **************************************************
                bool hasAnyUser =
                    databaseContext.Users
                    .Any();
                // **************************************************

                if (hasAnyUser == false)
                {
                    Models.User adminUser = new Models.User
                    {
                        IsAdmin  = true,
                        IsActive = true,

                        Username = "******",
                        Password = "******",
                        FullName = "Mr. Dariush Tasdighi"

                                   //Username = "******",
                                   //Password = "******",
                                   //FullName = "Mr. Behzad Shakeri"
                    };

                    databaseContext.Users.Add(adminUser);

                    databaseContext.SaveChanges();
                }
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);

                return;
            }
            finally
            {
                if (databaseContext != null)
                {
                    databaseContext.Dispose();
                    databaseContext = null;
                }
            }
            // **************************************************
            // **************************************************
            // **************************************************

            // **************************************************
            //System.Windows.Forms.Application.Run(new StartupForm());

            //#region Runing Startup Form and then Disposing!
            //StartupForm startupForm = new StartupForm();

            //System.Windows.Forms.Application.Run(startupForm);

            //if (startupForm != null)
            //{
            //	if (startupForm.IsDisposed == false)
            //	{
            //		startupForm.Dispose();
            //	}

            //	startupForm = null;
            //}
            //#endregion /Runing Startup Form and then Disposing!
            // **************************************************

            #region Runing LoginForm and then Disposing!
            LoginForm loginForm = new LoginForm();

            System.Windows.Forms.Application.Run(loginForm);

            if (loginForm != null)
            {
                if (loginForm.IsDisposed == false)
                {
                    loginForm.Dispose();
                }

                loginForm = null;
            }
            #endregion /Runing LoginForm and then Disposing!


            //#region Runing LoginForm and then Disposing!
            //MainForm MainForm = new MainForm();

            //Application.Run(MainForm);

            //if (MainForm != null)
            //{
            //    if (MainForm.IsDisposed == false)
            //    {
            //        MainForm.Dispose();
            //    }

            //    MainForm = null;
            //}
            //#endregion /Runing LoginForm and then Disposing!
        }
        private void registerButton_Click(object sender, System.EventArgs e)
        {
            // **************************************************
            if ((string.IsNullOrWhiteSpace(usernameTextBox.Text)) ||
                (string.IsNullOrWhiteSpace(passwordTextBox.Text)))
            {
                //usernameTextBox.Text =
                //	usernameTextBox.Text.Trim();

                //passwordTextBox.Text =
                //	passwordTextBox.Text.Trim();

                usernameTextBox.Text =
                    usernameTextBox.Text.Replace(" ", string.Empty);

                passwordTextBox.Text =
                    passwordTextBox.Text.Replace(" ", string.Empty);

                System.Windows.Forms.MessageBox.Show("Username and Password is requied!");

                if (usernameTextBox.Text == string.Empty)
                {
                    usernameTextBox.Focus();
                }
                else
                {
                    passwordTextBox.Focus();
                }

                return;
            }

            string strErrorMessages = string.Empty;

            if (usernameTextBox.Text.Length < 6)
            {
                strErrorMessages =
                    "Username length should be at least 6 characters!";
            }

            if (passwordTextBox.Text.Length < 8)
            {
                if (strErrorMessages != string.Empty)
                {
                    strErrorMessages +=
                        System.Environment.NewLine;
                }

                strErrorMessages +=
                    "Password length should be at least 8 characters!";
            }

            // اگر خطایی وجود داشت
            if (strErrorMessages != string.Empty)
            {
                System.Windows.Forms.MessageBox.Show(strErrorMessages);

                return;
            }
            // **************************************************

            Models.DatabaseContext oDatabaseContext = null;

            try
            {
                oDatabaseContext =
                    new Models.DatabaseContext();

                Models.User oUser =
                    oDatabaseContext.Users
                    .Where(current => string.Compare(current.Username, usernameTextBox.Text, true) == 0)
                    .FirstOrDefault();

                if (oUser != null)
                {
                    System.Windows.Forms.MessageBox.Show
                        ("This username is already exist! Please choose another one...");

                    usernameTextBox.Focus();

                    return;
                }

                oUser = new Models.User();

                oUser.FullName = fullNameTextBox.Text;
                oUser.Password = passwordTextBox.Text;
                oUser.Username = usernameTextBox.Text;

                oUser.IsActive = true;                 // بستگی به سناریو و قواعد شرکت یا پروژه دارد

                oDatabaseContext.Users.Add(oUser);

                oDatabaseContext.SaveChanges();

                System.Windows.Forms.MessageBox.Show("Registration Done!");

                fullNameTextBox.Text = string.Empty;
                passwordTextBox.Text = string.Empty;
                usernameTextBox.Text = string.Empty;

                usernameTextBox.Focus();
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Error: " + ex.Message);
            }
            finally
            {
                if (oDatabaseContext != null)
                {
                    oDatabaseContext.Dispose();
                    oDatabaseContext = null;
                }
            }
        }
示例#7
0
        private void SubmitButton_Click(object sender, System.EventArgs e)
        {
            // **************************************************
            if ((string.IsNullOrWhiteSpace(UsernameTextBox.Text)) ||
                (string.IsNullOrWhiteSpace(PasswordTextBox.Text)))
            {
                System.Windows.Forms.MessageBox.Show("Username and Password is requied!");

                return;
            }
            else
            {
                string strErrorMessages = string.Empty;

                if (UsernameTextBox.Text.Length < 6)
                {
                    strErrorMessages =
                        "Username length should be at least 6 characters!";
                }

                if (PasswordTextBox.Text.Length < 8)
                {
                    if (strErrorMessages != string.Empty)
                    {
                        strErrorMessages +=
                            System.Environment.NewLine;
                    }

                    strErrorMessages +=
                        "Password length should be at least 8 characters!";
                }

                // اگر خطایی وجود داشت
                if (strErrorMessages != string.Empty)
                {
                    System.Windows.Forms.MessageBox.Show(strErrorMessages);

                    return;
                }
            }
            // **************************************************

            Models.DatabaseContext oDatabaseContext = null;

            try
            {
                oDatabaseContext =
                    new Models.DatabaseContext();

                Models.User oUser = new Models.User();

                oUser.IsActive = true;
                oUser.FullName = FullNameTextBox.Text;
                oUser.Password = PasswordTextBox.Text;
                oUser.Username = UsernameTextBox.Text;

                oDatabaseContext.Users.Add(oUser);

                oDatabaseContext.SaveChanges();

                System.Windows.Forms.MessageBox.Show("Registration Done!");

                FullNameTextBox.Text = string.Empty;
                PasswordTextBox.Text = string.Empty;
                UsernameTextBox.Text = string.Empty;
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Error: " + ex.Message);
            }
            finally
            {
                if (oDatabaseContext != null)
                {
                    oDatabaseContext.Dispose();
                    oDatabaseContext = null;
                }
            }
        }