예제 #1
0
        public bool AddNewInvoice(string billingAddress, int inputCustomerId)
        {
            using (var connection = new SqlConnection(_connectionString))
            {
                var cmd = connection.CreateCommand();
                cmd.CommandText = @"INSERT INTO Invoice
                                        (InvoiceId,CustomerId,InvoiceDate,BillingAddress,BillingCity,BillingState,BillingCountry,BillingPostalCode,Total)
                                    VALUES
                                        (@invoiceId,@customerId,2/27/18,@billingAddress,@billingCity,@billingState,'USA',@billingZip,0)";

                connection.Open();

                var invoiceQuery = new InvoiceQuery();
                var invoiceId    = invoiceQuery.GetLastInvoice() + 1;

                string[] addressInfo = ParseAddressInfo(billingAddress).Reverse().ToArray();

                var InvoiceData = InvoiceInfo(addressInfo);

                var newInvoiceId = new SqlParameter(@"invoiceId", SqlDbType.Int);
                newInvoiceId.Value = invoiceId;
                cmd.Parameters.Add(newInvoiceId);
            }
        }
        public bool AddNewInvoice(string billingAddress, int inputCustomerId)
        {
            using (var connection = new SqlConnection(_connectionString))
            {
                var cmd = connection.CreateCommand();
                cmd.CommandText = @"INSERT INTO Invoice
                                    (InvoiceId
                                   ,CustomerId
                                   ,InvoiceDate
                                   ,BillingAddress
                                   ,BillingCity
                                   ,BillingState
                                   ,BillingCountry
                                   ,BillingPostalCode
                                   ,Total)
                                   VALUES
                                   (@invoiceId,
                                    @customerId,
                                    2/28/2018,
                                    @billingAddress,
                                    @billingCity,
                                    @billingState,
                                    'USA',
                                    @billingZip,
                                    0)";

                connection.Open();

                var invoiceQuery = new InvoiceQuery();

                var invoiceId = invoiceQuery.GetLastInvoice() + 1;

                string[] addressInfo = ParseAddressInfo(billingAddress).Reverse().ToArray();

                var InvoiceData = InvoiceInfo(addressInfo);

                var newInvoiceId = new SqlParameter("@invoiceId", SqlDbType.Int);
                newInvoiceId.Value = invoiceId;
                cmd.Parameters.Add(newInvoiceId);

                var customerId = new SqlParameter("@customerId", SqlDbType.Int);
                customerId.Value = inputCustomerId;
                cmd.Parameters.Add(customerId);

                var billingAddy  = new SqlParameter("@billingAddress", SqlDbType.NVarChar);
                var billingValue = InvoiceData.BillingAddress;
                billingAddy.Value = billingValue;
                cmd.Parameters.Add(billingAddy);

                var billingCity = new SqlParameter("@billingCity", SqlDbType.NVarChar);
                billingCity.Value = InvoiceData.BillingCity;
                cmd.Parameters.Add(billingCity);

                var billingState = new SqlParameter("@billingState", SqlDbType.NVarChar);
                billingState.Value = InvoiceData.BillingState;
                cmd.Parameters.Add(billingState);

                var billingZip = new SqlParameter("@billingZip", SqlDbType.NVarChar);
                billingZip.Value = InvoiceData.BillingPostalCode;
                cmd.Parameters.Add(billingZip);

                var result = cmd.ExecuteNonQuery();

                return(result == 1);
            }
        }