protected void Button2_Click(object sender, EventArgs e) { using (lucia_dataEntities allData = new lucia_dataEntities()) { int customer_id = Convert.ToInt32(Request.Cookies["customer_id"].Value); var direct = from dir in allData.Direct_Debit where customer_id == dir.customer_id select dir; var credit = from cre in allData.Credit_Card where customer_id == cre.customer_id select cre; if (RadioButtonList1.SelectedValue == "Direct Debit") { foreach (var r in direct) { allData.DeleteObject(r); } foreach (var c in credit) { allData.DeleteObject(c); } Direct_Debit debitCard = Direct_Debit.CreateDirect_Debit(1, nameofFI.Text, debitAccName.Text, debitType.SelectedValue, Convert.ToInt32(BSB.Text), Convert.ToInt32(debitAccNo.Text), customer_id); allData.AddToDirect_Debit(debitCard); allData.SaveChanges(); } else if (RadioButtonList1.SelectedValue == "Credit Card") { foreach (var r in direct) { allData.DeleteObject(r); } foreach (var c in credit) { allData.DeleteObject(c); } Credit_Card creditCard = Credit_Card.CreateCredit_Card(creditCardNo.Text, 14, creditCName.Text, creditType.SelectedValue, eDate.Text, customer_id, 2); allData.AddToCredit_Card(creditCard); allData.SaveChanges(); } } }
//This method should create all related data and insert them accordingly! //Associated data tables include: Application, Customer, Trade_reference, Director, Card, Cardholder, Payment (credit or debit), Acknowledgement, Cust_Postal_Address, Dir_Add, Vehicle //Because most tables have FKs toward Customer, so Customer will be created first, and Customer.ID will be then used to associate to other tables. //Becareful with FK chains! //This method is the main body of inserting input data into database. //Currently, all optional fields are not inserted!! //will put if statements in place in a later version! //Please dont forget! protected void fillTheForm(object sender, WizardNavigationEventArgs e) { int defaultID = 0; lucia_dataEntities allData = new lucia_dataEntities(); //Create customer address first; Cust_Postal_Address cust_address = Cust_Postal_Address.CreateCust_Postal_Address(defaultID, DropDownList2.Text, txSuburb.Text, txStreet.Text, Convert.ToInt32(txStreetNumber.Text), Convert.ToInt32(txPostCode.Text)); //assign optional unit number to customer if (!String.IsNullOrEmpty(txUnitNumber.Text)) cust_address.unit_number = Convert.ToInt32(txUnitNumber.Text); //add customer address to database set allData.AddToCust_Postal_Address(cust_address); defaultID++; //now create customer, reference cust_address Customer customer = Customer.CreateCustomer(defaultID, txBusinessName.Text, txTradingName.Text, Convert.ToInt32(txBusinessYear.Text), txABN.Text, txNatureOperation.Text, cust_address.id, txFirstName.Text, txLastName.Text, txPosition.Text, txPhoneNumber.Text, txMobileNumber.Text, txEmail.Text, Convert.ToDecimal(txCreditLimit.Text), DropDownList1.Text); customer.Cust_Postal_Address = cust_address; //assign optional middle name for customer if (!String.IsNullOrEmpty(txMiddleName.Text)) customer.contact_middle_name = txMiddleName.Text; //assign optional fax if (!String.IsNullOrEmpty(txFaxNumber.Text)) customer.fax_no = txFaxNumber.Text; //add customer to database set allData.AddToCustomers(customer); defaultID++; //now create application, use customer.id to reference foreign key APJProjv1.Application application = APJProjv1.Application.CreateApplication(defaultID, "submitted", DateTime.Now, 0, 0, 0, 0, customer.id); defaultID++; //now create trade_reference, this table will include 2 references and 1 existing fuel supplier Trade_Reference reference1 = Trade_Reference.CreateTrade_Reference(defaultID, txReferenceName1.Text, txReferencePhone1.Text, txExisting.Text, fuelSPhone.Text, application.id, txReferenceName2.Text, txReferencePhone2.Text); defaultID++; //now add both items into database allData.AddToApplications(application); allData.AddToTrade_Reference(reference1); //create address item for director 1 Dir_Add direct_address1 = Dir_Add.CreateDir_Add(defaultID, DropDownList3.Text, stSuburb1.Text, stSName1.Text, Convert.ToInt32(stSNumber1.Text), Convert.ToInt32(stPost1.Text)); //assign optional unit number for director 1 address if (!String.IsNullOrEmpty(stUnit1.Text)) direct_address1.unit_number = Convert.ToInt32(stUnit1.Text); //add dir_add1 to database allData.AddToDir_Add(direct_address1); defaultID++; //create director1's profile, associate him with address1 and customer and application item; //PLEASE NOTE!! TEST WHETHER FOREIGN KEYS HAVE BEEN PROPERLY SAVED IN DATABASE!! //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Director director1 = Director.CreateDirector(defaultID, stFName1.Text, stLName1.Text, direct_address1.id, customer.id, application.id); //assign optional middle name for director 1 if (!String.IsNullOrEmpty(stMName1.Text)) director1.m_name = stMName1.Text; //add phone to director 1 director1.phone = stPhoneNo1.Text; //store director1 to database allData.AddToDirectors(director1); //------ defaultID++; //create address item for director 2 Dir_Add direct_address2 = Dir_Add.CreateDir_Add(defaultID, DropDownList4.Text, stSuburb2.Text, stSName2.Text, Convert.ToInt32(stSNumber2.Text), Convert.ToInt32(stPost2.Text)); defaultID++; //assign optional unit number for director address 2 if (!String.IsNullOrEmpty(stUnit2.Text)) direct_address2.unit_number = Convert.ToInt32(stUnit2.Text); //add address 2 to database allData.AddToDir_Add(direct_address2); defaultID++; //create director 2 Director director2 = Director.CreateDirector(defaultID, stFName2.Text, stLName2.Text, direct_address2.id, customer.id, application.id); defaultID++; //assign middle name to director 2 if (!String.IsNullOrEmpty(TextBox7.Text)) director2.m_name = TextBox7.Text; //add phone number to director 2 director2.phone = stPhoneNo2.Text; //add director 2 to database; allData.AddToDirectors(director2); if (cardOptionList2.SelectedValue == "For Person") { defaultID++; //create a card item first Card card = Card.CreateCard(defaultID, 0, nameOnCard.Text, customer.id, "disabled", 1); //add card to database allData.AddToCards(card); //create cardholder item //UI does not have last name in place,will duplicate first name twice //###################NEED TO BE FIXED!!!############################# Cardholder cardholder = Cardholder.CreateCardholder(defaultID, TextBox1.Text, card.card_no); //add cardholder to database allData.AddToCardholders(cardholder); //now create reference table for card and product; for (int i = 0; i < CheckBoxList1.Items.Count; i++) { if (CheckBoxList1.Items[i].Selected) { Product_Card_Reference rf = Product_Card_Reference.CreateProduct_Card_Reference(card.card_no, CheckBoxList1.Items[i].Text, defaultID); defaultID++; allData.AddToProduct_Card_Reference(rf); } } } //vehicle specific else if (cardOptionList2.SelectedValue == "For Vehicle") { defaultID++; //create a card item first Card card = Card.CreateCard(defaultID, 0, nameOnCard.Text, customer.id, "disabled", 1); //add card to database allData.AddToCards(card); //create viechel item Vehicle vehicle = Vehicle.CreateVehicle(TextBox1.Text, card.card_no); //now create reference table for card and product; for (int i = 0; i < CheckBoxList1.Items.Count; i++) { if (CheckBoxList1.Items[i].Selected) { Product_Card_Reference rf = Product_Card_Reference.CreateProduct_Card_Reference(card.card_no, CheckBoxList1.Items[i].Text, defaultID); defaultID++; allData.AddToProduct_Card_Reference(rf); } } //add vehicle to database allData.AddToVehicles(vehicle); } //From here, we insert card items! //######################################### //This section may need further refinement, because current UI for card is not acceptable, we only use it for testing purpose! //######################################### //person specific /* if (RadioButton1.Checked) { defaultID++; //create a card item first Card card = Card.CreateCard(defaultID, 0, nameOnCard.Text, customer.id, "disabled", 1); //add card to database allData.AddToCards(card); //create cardholder item //UI does not have last name in place,will duplicate first name twice //###################NEED TO BE FIXED!!!############################# Cardholder cardholder = Cardholder.CreateCardholder(defaultID, cdHolderName1.Text,card.card_no); //add cardholder to database allData.AddToCardholders(cardholder); //now create reference table for card and product; for (int i=0;i< CheckBoxList1.Items.Count; i++) { if (CheckBoxList1.Items[i].Selected) { Product_Card_Reference rf = Product_Card_Reference.CreateProduct_Card_Reference(card.card_no, CheckBoxList1.Items[i].Text, defaultID); defaultID++; allData.AddToProduct_Card_Reference(rf); } } } //vehicle specific else if (RadioButton2.Checked) { defaultID++; //create a card item first Card card = Card.CreateCard(defaultID, 0, nameOnCard.Text, customer.id, "disabled", 1); //add card to database allData.AddToCards(card); //create viechel item Vehicle vehicle = Vehicle.CreateVehicle(carReNo1.Text, card.card_no); //now create reference table for card and product; for (int i = 0; i < CheckBoxList1.Items.Count; i++) { if (CheckBoxList1.Items[i].Selected) { Product_Card_Reference rf = Product_Card_Reference.CreateProduct_Card_Reference(card.card_no, CheckBoxList1.Items[i].Text, defaultID); defaultID++; allData.AddToProduct_Card_Reference(rf); } } //add vehicle to database allData.AddToVehicles(vehicle); }*/ //################################################### //########END OF CARD CREATION####################### //Create payment item if (RadioButtonList1.SelectedValue == debit_card) { //create a debit card item //The first parameter is just an ID Direct_Debit debitCard = Direct_Debit.CreateDirect_Debit(defaultID, nameofFI.Text, debitAccName.Text, debitType.SelectedValue, Convert.ToInt32(BSB.Text), Convert.ToInt32(debitAccNo.Text), customer.id); //add this payment item to database allData.AddToDirect_Debit(debitCard); application.payment_option = debit_card; } else if (RadioButtonList1.SelectedValue == credit_card) { //create a credit card item //######################### //UI does not support date selection yet between 14/28 //###NEED TO MODIFY UI!!############ Credit_Card creditCard = Credit_Card.CreateCredit_Card(creditCardNo.Text, 14, creditCName.Text, creditType.SelectedValue, eDate.Text, customer.id, defaultID); //add item to database allData.AddToCredit_Card(creditCard); application.payment_option = credit_card; } allData.SaveChanges(); Label57.Text = "successful!!"; allData.Dispose(); }
protected void Button2_Click(object sender, EventArgs e) { using (lucia_dataEntities allData = new lucia_dataEntities()) { int customer_id = Convert.ToInt32(Request.Cookies["customer_id"].Value); var direct = from dir in allData.Direct_Debit where customer_id == dir.customer_id select dir; var credit = from cre in allData.Credit_Card where customer_id == cre.customer_id select cre; if (RadioButtonList1.SelectedValue == "Direct Debit") { foreach (var r in direct) { allData.DeleteObject(r); } foreach (var c in credit) { allData.DeleteObject(c); } Direct_Debit debitCard = Direct_Debit.CreateDirect_Debit(1, nameofFI.Text, debitAccName.Text, debitType.SelectedValue, Convert.ToInt32(BSB.Text), Convert.ToInt32(debitAccNo.Text), customer_id); allData.AddToDirect_Debit(debitCard); allData.SaveChanges(); } else if (RadioButtonList1.SelectedValue == "Credit Card") { foreach (var r in direct) { allData.DeleteObject(r); } foreach (var c in credit) { allData.DeleteObject(c); } Credit_Card creditCard = Credit_Card.CreateCredit_Card(creditCardNo.Text, 14, creditCName.Text, creditType.SelectedValue, eDate.Text, customer_id, 2); allData.AddToCredit_Card(creditCard); allData.SaveChanges(); } if (Request.Cookies["viewMode"].Value.Contains("customer")) { operationLog log = operationLog.CreateoperationLog(customer_id, customer_id, "Payment modification", 1,DateTime.Now); allData.AddTooperationLogs(log); allData.SaveChanges(); } else { int empid = Convert.ToInt32(Request.Cookies["empid"].Value); operationLog log = operationLog.CreateoperationLog(empid, customer_id, "Payment modification", 1,DateTime.Now); allData.AddTooperationLogs(log); allData.SaveChanges(); } Button2.Enabled = false; Label57.Text = "New payment details are successfully saved!"; } }