I am using C# to create a Windows form application. How do I create a local database table to save the data described below? Currently my data table consists of the columns of "inv_Id", "Item_Id" and "quantity". I know I need to create the columns to store each of the data items below, but I do not know how to structure the table.
- item={chair,table,pen, thumbdrive}
- Price={5,10,2,48}
- subtotal
- tax
- total
I am new at C#. I did a search for this, and found things like e.g.http://ift.tt/1MwzOm6
The data is shown in a list box and looks like:
Ordered Item:chair Price:$5.00
Ordered Item:table Price:$10.00
Ordered Item:pen Price:$2.00
Ordered Item:thumbdrive Price:$48.00Subtotal:$65.00 Tax:$3.90 Total:$68.90
The purpose for me is to create the invoice then save it in the database after calculating everything.
Here is the code that I get the data load the data from db into drop down list (for user to select which item they want to buy), then (cust selected item will be listed in the listOuput box for calculating) user will select the item, then list box will show the selected output and calculate the total like a receipt.
After calculating, I wish to store all the data at the listOutput box to my db, but I having problem here.
Problem: I do not know how to move all my data from list box to database, and link them together in the structure.
public partial class Select_Item : Form
{
SqlConnection con = new SqlConnection( @"Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\oo\Documents\Data.mdf;Integrated Security=True;Connect Timeout=30");
SqlDataAdapter da = new SqlDataAdapter();
DataTable dt = new DataTable();
public struct Orders
{
public string item;
public double price;
}
const double TAX=0.06;
Orders order = new Orders();
static double subtotal=0;
static double totalTaxes=0;
static double total;
string finalBill = "FINAL BILL: \n";
public Select_Item()
{
InitializeComponent();
}
private void getValues(string custOrder)
{
order.item = custOrder;
String a = comboBox1.Text;
order.price = Convert.ToDouble(custOrder);
listOutput.Items.Add("Price: " + order.price);
finalBill += "Ordered Item: " + a + "\nPrice: " + order.price.ToString("C2") + "\n";
updateBill();
}
private void updateBill()
{
subtotal += order.price;
total += order.price + (order.price * TAX);
totalTaxes += order.price * TAX;
listOutput.Items.Clear();
listOutput.Items.AddRange(finalBill.Split('\n'));
listOutput.Items.Add("Subtotal:" + subtotal.ToString("C2"));
listOutput.Items.Add("Tax:" + totalTaxes.ToString("C2"));
listOutput.Items.Add("Total:" + total.ToString("C2"));
}
private void dropdownSelection(object sender, EventArgs e)
{
if (sender == comboBox1)
System.Diagnostics.Debug.WriteLine("test " + comboBox1.SelectedValue.ToString());
getValues(comboBox1.SelectedValue.ToString());
}
Aucun commentaire:
Enregistrer un commentaire