private void btnInsert_Click(object sender, EventArgs e) { //saat button insert/save di klik, cek apakah telah klik sebelumnya if (inserting) { //jika iya, maka validasi input sesuai soal if (txId.Text.Length != 10 || !checkNumeric(txId.Text)) { MessageBox.Show("Please fill credit card number with 10 numbers"); } else if (txName.Text.Length < 5) { MessageBox.Show("Please fill name and its length should be at least 5 characters"); } else if (cmbType.SelectedIndex < 0) { MessageBox.Show("Please select card type"); } else if (txCVV.Text.Length != 4 || !checkNumeric(txCVV.Text)) { MessageBox.Show("Please fill CVV with 4 numbers"); } else { //jika input valid, maka insert data ke table CreditCard CreditCard obj = new CreditCard(); obj.CreditCardNumber = txId.Text; obj.Name = txName.Text; obj.CardType = cmbType.SelectedItem.ToString(); obj.CVV = decimal.Parse( txCVV.Text); ent.AddToCreditCards(obj); ent.SaveChanges(); txCVV.Enabled = false; txId.Enabled = false; txName.Enabled = false; cmbType.Enabled = false; inserting = false; btnCancel.Enabled = false; btnInsert.Text = "Insert"; } } else { //jika belum, maka field untuk input enable txCVV.Enabled = true; txId.Enabled = true; txName.Enabled = true; cmbType.Enabled = true; inserting = true; btnCancel.Enabled = true; btnInsert.Text = "Save"; } }
/// <summary> /// Create a new CreditCard object. /// </summary> /// <param name="creditCardNumber">Initial value of the CreditCardNumber property.</param> /// <param name="name">Initial value of the Name property.</param> /// <param name="cardType">Initial value of the CardType property.</param> /// <param name="cVV">Initial value of the CVV property.</param> public static CreditCard CreateCreditCard(global::System.String creditCardNumber, global::System.String name, global::System.String cardType, global::System.Decimal cVV) { CreditCard creditCard = new CreditCard(); creditCard.CreditCardNumber = creditCardNumber; creditCard.Name = name; creditCard.CardType = cardType; creditCard.CVV = cVV; return creditCard; }
/// <summary> /// Deprecated Method for adding a new object to the CreditCards EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToCreditCards(CreditCard creditCard) { base.AddObject("CreditCards", creditCard); }