private void button3_Click(object sender, EventArgs e) { Orders_DATA order = new Orders_DATA(); order.User_id = user_name.Id; order.Order_date = Convert.ToDateTime(dateTimePicker1.Text); Customer_DATA customer = new Customer_DATA(); customer.ID = Convert.ToInt16(id.Text); order.Customer = customer; order.Total_paied = Convert.ToDouble(total_value.Text); Orders_BLL.Insert_Orders(order); foreach (DataGridViewRow row in dataGridView1.Rows) { Products_DATA product = new Products_DATA(); product.Id = Convert.ToInt16(row.Cells[0].Value); Orders_DATA orders = new Orders_DATA(); orders = Orders_BLL.Select_ALL_Orders().Last(); Order_Details_DATA order_details = new Order_Details_DATA(); order_details.Quantity = Convert.ToInt16(row.Cells[3].Value); order_details.Total_price = Convert.ToDouble(row.Cells[4].Value); order_details.Discount = Convert.ToDouble(row.Cells[5].Value); order_details.Total_price_after_discount = Convert.ToDouble(row.Cells[6].Value); order_details.Order = orders; order_details.Product = product; Order_Details_BLL.Insert_Order_Details(order_details); } id.Text = ""; name.Text = ""; lastname.Text = ""; phone.Text = ""; email.Text = ""; textBox2.Text = ""; product_id.Text = ""; product_name.Text = ""; product_price.Text = ""; product_quantety.Text = ""; product_total_price.Text = ""; product_discount.Text = ""; product_total.Text = ""; total_value.Text = ""; pictureBox1.Image = null; button2.Enabled = true; button3.Enabled = false; table.Clear(); dataGridView1.DataSource = table; }
private void bills_Load(object sender, EventArgs e) { DataTable table = new DataTable(); table.Columns.Add("Id"); table.Columns.Add("first_Name"); table.Columns.Add("last_Name"); table.Columns.Add("tel"); table.Columns.Add("email"); table.Columns.Add("order_date"); table.Columns.Add("user_name"); DataTable details_table = new DataTable(); details_table.Columns.Add("quantity"); details_table.Columns.Add("total_price"); details_table.Columns.Add("discount"); details_table.Columns.Add("total_price_after_discount"); details_table.Columns.Add("label_product"); details_table.Columns.Add("price"); Order_Details_DATA order_details = new Order_Details_DATA(); order_details.Order = new Orders_DATA(); order_details.Order.Customer = new Customer_DATA(); order_details = Order_Details_BLL.Select_ALL_Order_Details().Last(); Customer_DATA customer = new Customer_DATA(); List <Orders_DATA> order = new List <Orders_DATA>(); order = Orders_BLL.Select_ALL_Orders(); foreach (var item in order) { if (order_details.Order.Id == item.Id) { order_details.Order.Customer = Customer_BLL.Select_Item_Customers(item.Customer); } } List <Order_Details_DATA> list_order_details = new List <Order_Details_DATA>(); list_order_details = Order_Details_BLL.Select_ALL_Order_Details(); list_order_details = Order_Details_BLL.Select_ALL_Order_Details().Where(x => x.Order.Id == order_details.Order.Id).ToList(); Users user = new Users(); List <Users> user_list = new List <Users>(); DataTable tables = DBL.get_DATA("Select_Users"); foreach (DataRow item in tables.Rows) { user_list.Add(new Users(item["Name"].ToString(), item["Password"].ToString(), Convert.ToInt16(item["ID_User"]))); } user.Id = order_details.Order.User_id; user = user_list.Single(x => x.Id == user.Id); table.Rows.Add( order_details.Order.Id, order_details.Order.Customer.First_Name, order_details.Order.Customer.Last_Name, order_details.Order.Customer.Tel, order_details.Order.Customer.Email, order_details.Order.Order_date, user.Name ); foreach (var item in list_order_details) { details_table.Rows.Add( item.Quantity, item.Total_price, item.Discount, item.Total_price_after_discount, item.Product.Label_product, item.Product.Price ); } CrystalReport_bill s = new CrystalReport_bill(); s.Subreports[0].SetDataSource(details_table); s.Subreports[0].AfterFormatPage += Bills_AfterFormatPage; s.SetDataSource(table); crystalReportViewer1.ReportSource = s; }