コード例 #1
0
        /// <summary>
        /// Fetches values from the form-fields and populates the customerDetail object.
        /// </summary>
        /// <param name="customerDetail">The CustomerDetail object into which the form-field-values are filled.</param>
        private void fetchFormValues(CustomerDetail customerDetail)
        {
            customerDetail.EmailAddress = textBox_EmailId.Text;
            customerDetail.FirstName = textBox_firstName.Text;
            customerDetail.LastName = textBox_lastName.Text;
            customerDetail.Address = textBox_Address.Text;

            String selectedAreaName = comboBox_area.SelectedValue.ToString();
            if (selectedAreaName != null)
            {
                int areaId = db.Areas.Where(x => x.AreaName.Equals(selectedAreaName)).First().AreaId;
                customerDetail.AreaId = areaId;
            }
            customerDetail.MealPlanId = Int32.Parse(comboBox_typeOfLunch.SelectedValue.ToString());
            int depositAmount = 0;
            Int32.TryParse(textBox_Deposit.Text.Trim(), out depositAmount);
            customerDetail.DepositAmount = depositAmount;
            customerDetail.PhoneNumber = textBox_PhoneNumber.Text;
            customerDetail.LunchOrDinnerId = Int32.Parse(comboBox_lunchOrDinner.SelectedValue.ToString());
            int defaultDabbawalaDeliveryCharges = 0;
            Int32.TryParse(textBox_DabbaWalaDeliveryCharges.Text.Trim(), out defaultDabbawalaDeliveryCharges);
            customerDetail.DefaultDabbawalaCharges = defaultDabbawalaDeliveryCharges;
            int initialBalance = 0;
            Int32.TryParse(textBox_currentBalance.Text.Trim(), out initialBalance);
            customerDetail.InitialBalance = initialBalance;
            customerDetail.isDeleted = "N";
        }
コード例 #2
0
 /// <summary>
 /// Create a new CustomerDetail object.
 /// </summary>
 /// <param name="customerId">Initial value of the CustomerId property.</param>
 /// <param name="firstName">Initial value of the FirstName property.</param>
 /// <param name="address">Initial value of the Address property.</param>
 /// <param name="phoneNumber">Initial value of the PhoneNumber property.</param>
 /// <param name="areaId">Initial value of the AreaId property.</param>
 /// <param name="mealPlanId">Initial value of the MealPlanId property.</param>
 /// <param name="lunchOrDinnerId">Initial value of the LunchOrDinnerId property.</param>
 /// <param name="defaultDabbawalaCharges">Initial value of the DefaultDabbawalaCharges property.</param>
 /// <param name="initialBalance">Initial value of the InitialBalance property.</param>
 public static CustomerDetail CreateCustomerDetail(global::System.Int32 customerId, global::System.String firstName, global::System.String address, global::System.String phoneNumber, global::System.Int32 areaId, global::System.Int32 mealPlanId, global::System.Int32 lunchOrDinnerId, global::System.Int32 defaultDabbawalaCharges, global::System.Int32 initialBalance)
 {
     CustomerDetail customerDetail = new CustomerDetail();
     customerDetail.CustomerId = customerId;
     customerDetail.FirstName = firstName;
     customerDetail.Address = address;
     customerDetail.PhoneNumber = phoneNumber;
     customerDetail.AreaId = areaId;
     customerDetail.MealPlanId = mealPlanId;
     customerDetail.LunchOrDinnerId = lunchOrDinnerId;
     customerDetail.DefaultDabbawalaCharges = defaultDabbawalaCharges;
     customerDetail.InitialBalance = initialBalance;
     return customerDetail;
 }
コード例 #3
0
        /// <summary>
        /// Submit button is clicked.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button_SubmitAddNewUser_Click_1(object sender, EventArgs e)
        {
            if(validate())
            return; //Validation fails.

            //Validation successful.

            //Create a new CustomerDetail object, fetch form-field-values and insert into the DB.
            CustomerDetail customerDetail = new CustomerDetail();
            int lastInsertedCustomerId = db.CustomerDetails.Count();
            customerDetail.CustomerId = lastInsertedCustomerId + 1; //New Customer's id.

            fetchFormValues(customerDetail);

            bool exceptionOccured = false;
            try
            {
                bool success = false;

                /* For every new Customer inserted into the DB, entries are made in 2 tables - CustomerDetails and CustomerDues.
                 * Hence a transaction is required. */
                using (TransactionScope transaction = new TransactionScope())
                {
                    try
                    {
                        db.CustomerDetails.AddObject(customerDetail);

                        //Pending Balance should be inserted in the CustomerDues table.
                        CustomerDue dues = new CustomerDue();
                        dues.CustomerId = customerDetail.CustomerId;
                        int dueAmount = 0;
                        Int32.TryParse(textBox_currentBalance.Text.Trim(), out dueAmount);
                        dues.DueAmount = dueAmount;

                        db.CustomerDues.AddObject(dues);

                        db.SaveChanges();
                        transaction.Complete();
                        success = true;
                    }
                    catch (Exception ex)
                    {
                        success = false;
                    }
                }
                if (success)
                    db.AcceptAllChanges(); //Transaction was successful, commit all changes.
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                exceptionOccured = true;
            }

            if (!exceptionOccured)
            {
                MessageBox.Show("User added successfully.", "Success");
            }
            else
            {
                MessageBox.Show("Something went wrong.", "Error");
            }
        }
コード例 #4
0
 /// <summary>
 /// Deprecated Method for adding a new object to the CustomerDetails EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToCustomerDetails(CustomerDetail customerDetail)
 {
     base.AddObject("CustomerDetails", customerDetail);
 }