private void button1_Click(object sender, EventArgs e)
        {
            FaridiaIronStoreEntities db = new FaridiaIronStoreEntities();

            if (textBox1.Text.Count() != 0 && textBox2.Text.Count() != 0 && textBox3.Text.Count() != 0 && textBox3.Text.Count() < 15)
            {
                string       userName     = textBox1.Text;
                string       password     = textBox2.Text;
                string       phone        = textBox3.Text;
                string       email        = textBox4.Text;
                string       designation  = textBox5.Text;
                Entity.Login existingUser = db.Logins.Where(aa => aa.UserName.Equals(userName)).FirstOrDefault();
                if (existingUser == null)
                {
                    Entity.Login login = new Entity.Login();
                    login.UserName    = userName;
                    login.Password    = password;
                    login.Phone       = phone;
                    login.Email       = email;
                    login.Designation = designation;
                    db.Logins.Add(login);
                    db.SaveChanges();
                    MessageBox.Show("User Added");
                    this.Close();
                }
                else
                {
                    MessageBox.Show("UserName Already Exists");
                }
            }
            else
            {
                MessageBox.Show("Fill Empty Fields");
            }
        }
Exemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            FaridiaIronStoreEntities db = new FaridiaIronStoreEntities();
            int id = int.Parse(textBox6.Text);

            Entity.Login login = db.Logins.Find(id);
            db.Logins.Remove(login);
            db.SaveChanges();
            MessageBox.Show("User Deleted");
            this.Close();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            FaridiaIronStoreEntities db = new FaridiaIronStoreEntities();
            string loginId     = textBox6.Text;
            string userName    = textBox1.Text;
            string password    = textBox2.Text;
            string phone       = textBox3.Text;
            string email       = textBox4.Text;
            string designation = textBox5.Text;
            int    id          = int.Parse(loginId);

            Entity.Login login = db.Logins.Where(a => a.LoginId == id).First();
            login.UserName    = userName;
            login.Password    = password;
            login.Phone       = phone;
            login.Email       = email;
            login.Designation = designation;
            db.SaveChanges();
            MessageBox.Show("User Updated");
            this.Close();
        }
        private void button2_Click(object sender, EventArgs e)
        {
            string presetMasterPassword = "******";
            FaridiaIronStoreEntities db = new FaridiaIronStoreEntities();
            string userName             = UserName.Text;
            string newPassword          = NewPassword.Text;
            string masterPassword       = MasterPassword.Text;

            if (userName.Count() != 0 && newPassword.Count() != 0 && masterPassword.Count() != 0)
            {
                Entity.Login existingUser = db.Logins.Where(aa => aa.UserName.Equals(userName)).FirstOrDefault();
                if (existingUser != null)
                {
                    if (masterPassword.Equals(presetMasterPassword))
                    {
                        existingUser.Password = newPassword;
                        MessageBox.Show("Password Changes");
                        db.SaveChanges();
                        this.Hide();
                        Login login = new Login();
                        login.Show();
                    }
                    else
                    {
                        MessageBox.Show("Enter Valid MasterPassword");
                    }
                }
                else
                {
                    MessageBox.Show("Enter Valid UserName");
                }
            }
            else
            {
                MessageBox.Show("Fill All Fields");
            }
        }