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(); }
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(); }
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(); }