private void updateData_Click(object sender, EventArgs e)
        {
            try
            {
                using (var db = new PartDbEntities())
                {
                    var        acc = db.Accounts.FirstOrDefault(u => u.UserId == id);
                    Encryption en  = new Encryption();

                    acc.Username = textBox1.Text;
                    acc.Password = en.Encrypt(textBox2.Text);

                    db.SaveChanges();

                    MessageBox.Show("You successfully updated acc info");
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Error");

                throw;
            }

            LoadData();
        }
示例#2
0
        public void LoadData(string username)
        {
            using (var db = new PartDbEntities())
            {
                var acc = db.Accounts.FirstOrDefault(u => u.Username == username);



                List <string> data = new List <string>();

                data.Add(acc.Username);
                data.Add(acc.Password);
                data.Add(acc.FirstName);
                data.Add(acc.LastName);
                data.Add(acc.Email);
                data.Add(acc.Phone);
                data.Add(acc.Address);

                int count = data.Count - 1;
                foreach (TextBox textbox in Controls.OfType <TextBox>())
                {
                    while (count > -1)
                    {
                        textbox.Text = data[count];
                        break;
                    }
                    count--;
                }
            }
        }
        private void dataGridViewUsers_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Delete)
            {
                OnKeyPress(new KeyPressEventArgs((Char)Keys.Delete));
                using (var db = new PartDbEntities())
                {
                    var acc = db.Accounts.FirstOrDefault(u => u.UserId == id);

                    if (acc.Username == "admin")
                    {
                        return;
                    }

                    DialogResult dialogResult = MessageBox.Show("Do you want delete this record", "Confirm",
                                                                MessageBoxButtons.YesNo);

                    if (dialogResult == DialogResult.Yes)
                    {
                        db.DeleteUser(id);
                        LoadData();
                    }
                }
            }
        }
示例#4
0
        private void Search()
        {
            string text = TextBox1Search.Text;

            using (var db = new PartDbEntities())
            {
                List <Part> a    = new List <Part>();
                var         part = a;
                if (searchByComboBox.Text == "PartID")
                {
                    part = db.Parts.Where(p => p.PartId.Contains(text)).ToList();
                }
                else
                {
                    part = db.Parts.Where(p => p.PartName.Contains(text) || p.PartId.Contains(text)).ToList();
                }


                dataGridView.DataSource = part.ToList();
            }

            if (text == "")
            {
                LoadData();
            }
        }
 private void LoadData()
 {
     using (var db = new PartDbEntities())
     {
         var allParts = from p in db.Accounts select p;
         dataGridViewUsers.DataSource = allParts.ToList();
     }
 }
示例#6
0
        private void createNewUser_Click(object sender, EventArgs e)
        {
            Encryption en = new Encryption();

            using (var db = new PartDbEntities())
            {
                string newPass = "";
                newPass = TextBox2Password.Text;
                newPass = en.Encrypt(newPass);
                db.NewUser(TextBox1Username.Text, newPass);
            }
        }
        private void dataGridViewUsers_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            groupBoxData.Visible = true;
            using (var db = new PartDbEntities())
            {
                var acc = db.Accounts.FirstOrDefault(u => u.UserId == id);

                textBox1.Text = acc.Username;
                textBox2.Text = acc.Password;
            }
            this.Size = new Size(577, 407);
        }
示例#8
0
 private void deleteBtn_Click(object sender, EventArgs e)
 {
     using (var db = new PartDbEntities())
     {
         DialogResult dialogResult = MessageBox.Show("Do you want delete this record", "Confirm",
                                                     MessageBoxButtons.YesNo);
         if (dialogResult == DialogResult.Yes)
         {
             db.DeletePart(id);
             LoadData();
         }
     }
 }
示例#9
0
        private void saveBtn_Click(object sender, EventArgs e)
        {
            OperationCheck();
            if (isUpdate)
            {
                try
                {
                    using (var db = new PartDbEntities())
                    {
                        var data = db.Parts.FirstOrDefault(x => x.Id == ID);


                        data.PartName = textBox1PartName.Text;
                        data.Type     = comboBox1Type.Text;
                        data.PartId   = textBox2PartID.Text;
                        data.Car      = textBox3CarModel.Text;
                        data.Price    = decimal.Parse(numericUpDown1Price.Value.ToString());
                        data.Quantity = float.Parse(numericUpDown2Quantity.Value.ToString());

                        db.SaveChanges();
                    }

                    MessageBox.Show("You successfully updated info");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
            else
            {
                partName = textBox1PartName.Text;
                type     = comboBox1Type.Text;
                partID   = textBox2PartID.Text;
                carModel = textBox3CarModel.Text;
                price    = decimal.Parse(numericUpDown1Price.Value.ToString());
                quantity = float.Parse(numericUpDown2Quantity.Value.ToString());


                using (var db = new PartDbEntities())
                {
                    db.InsertPart(partName, type, partID, carModel, price, quantity);
                }

                MessageBox.Show("You successfully inserted your info");
            }


            this.Hide();
        }
示例#10
0
        private void dataGridView_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Delete)
            {
                OnKeyPress(new KeyPressEventArgs((Char)Keys.Delete));
                using (var db = new PartDbEntities())
                {
                    DialogResult dialogResult = MessageBox.Show("Do you want delete this record", "Confirm",
                                                                MessageBoxButtons.YesNo);

                    if (dialogResult == DialogResult.Yes)
                    {
                        db.DeletePart(id);
                        LoadData();
                    }
                }
            }
        }
示例#11
0
        private void saveBtn_Click(object sender, EventArgs e)
        {
            if (TextBox3FirstName.Text.Length < 3 && TextBox4LastName.Text.Length < 3 && TextBox5Email.Text.Length < 8 &&
                TextBox6Phone.Text.Length <= 9)
            {
                TextBox3FirstName.Text = firstName;
                TextBox4LastName.Text  = lastName;
                TextBox5Email.Text     = email;
                TextBox6Phone.Text     = phone;
                TextBox7Address.Text   = address;

                MessageBox.Show("Invalid data");
            }
            else
            {
                try
                {
                    using (var db = new PartDbEntities())
                    {
                        var acc = db.Accounts.FirstOrDefault(u => u.Username == TextBox1Username.Text);

                        acc.FirstName = TextBox3FirstName.Text;
                        acc.LastName  = TextBox4LastName.Text;
                        acc.Email     = TextBox5Email.Text;
                        acc.Phone     = TextBox6Phone.Text;
                        acc.Address   = TextBox7Address.Text;

                        db.SaveChanges();
                        partBtn.Enabled = true;
                    }

                    MessageBox.Show("You successfully updated your account info");
                    label8.Visible = false;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }

            saveBtn.Visible  = false;
            editInfo.Visible = true;
            ReadOnlyTrue();
        }
示例#12
0
        public ProfileForm(string username, string password)
        {
            InitializeComponent();

            TextBox1Username.Text = username;
            TextBox2Password.Text = password;
            user = username;
            pass = password;


            using (var db = new PartDbEntities())
            {
                var acc = db.Accounts.FirstOrDefault(u => u.Username == TextBox1Username.Text);

                if (acc.FirstName == null || acc.LastName == null || acc.Email == null ||
                    acc.Phone == null || acc.Address == null)
                {
                    label8.Visible  = true;
                    partBtn.Enabled = false;
                }
                else
                {
                    id        = acc.UserId;
                    firstName = acc.FirstName;
                    lastName  = acc.LastName;
                    email     = acc.Email;
                    phone     = acc.Phone;
                    address   = acc.Address;

                    TextBox3FirstName.Text = firstName;
                    TextBox4LastName.Text  = lastName;
                    TextBox5Email.Text     = email;
                    TextBox6Phone.Text     = phone;
                    TextBox7Address.Text   = address;
                }

                if (acc.Username == "admin")
                {
                    newAccButton.Visible = true;
                    allUsersBtn.Visible  = true;
                }
            }
        }
示例#13
0
        private void button1_Click(object sender, EventArgs e)
        {
            using (var db = new PartDbEntities())
            {
                try
                {
                    string     username = usernameTextBox.Text;
                    string     password = passwordTextBox.Text;
                    Encryption en       = new Encryption();
                    password = en.Encrypt(password);

                    var acc = db.Accounts.FirstOrDefault(u => u.Username == username && u.Password == password);

                    if (acc == null)
                    {
                        MessageBox.Show("Invalid account");
                        return;
                    }

                    if (acc.Username == username && acc.Password == password)
                    {
                        isValidAcc = true;

                        if (acc.FirstName != null && acc.LastName != null && acc.Email != null && acc.Phone != null && acc.Address != null)
                        {
                            this.Hide();
                            Parts p = new Parts(username, password);
                            p.Show();
                        }
                        else
                        {
                            this.Hide();
                            ProfileForm pf = new ProfileForm(username, password);
                            pf.Show();
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
        private void Search()
        {
            string text = textBox3.Text;

            using (var db = new PartDbEntities())
            {
                List <Account> a    = new List <Account>();
                var            part = a;

                part = db.Accounts.Where(p => p.Username.Contains(text) || p.FirstName.Contains(text) ||
                                         p.LastName.Contains(text) || p.Phone.Contains(text)).ToList();

                dataGridViewUsers.DataSource = part.ToList();
            }

            if (text == "")
            {
                LoadData();
            }
        }
示例#15
0
        public void DataLoad()
        {
            try
            {
                if (ID > 0)
                {
                    using (var db = new PartDbEntities())
                    {
                        var data = db.Parts.FirstOrDefault(x => x.Id == ID);

                        partName = data.PartName;
                        type     = data.Type;
                        partID   = data.PartId;
                        carModel = data.Car;
                        price    = data.Price;
                        quantity = float.Parse(data.Quantity.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }