private void printSalesReportBtn_Click(object sender, RoutedEventArgs e) { DataTable table = ((DataView)salesDataGrid.ItemsSource).ToTable(); string htmlTable = toHTML_Table(table); System.IO.File.WriteAllText(@"e:\Folder\abc.HTML", htmlTable); TheWebBrowser myBrowser = new TheWebBrowser(); myBrowser.Url = @"e:\Folder\abc.HTML"; myBrowser.Show(); }
private void printSalesRptBtn_Click(object sender, RoutedEventArgs e) { if (byStaffCombobox.Text != "") { string connec0 = @"Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\MerakiBusinessDB.mdf;Integrated Security=True"; using (SqlConnection loadSalesConnec = new SqlConnection(connec0)) { SqlCommand getSalesCmd = loadSalesConnec.CreateCommand(); getSalesCmd.Connection = loadSalesConnec; getSalesCmd.CommandText = "SELECT * FROM [Sales] WHERE SoldBy = @SoldBy ORDER BY dateOfSale"; getSalesCmd.Parameters.AddWithValue("@SoldBy", SqlDbType.NVarChar).Value = byStaffCombobox.Text; loadSalesConnec.Open(); SqlDataAdapter tempSalesTable = new SqlDataAdapter(getSalesCmd); DataSet tempUserHoldingSet = new DataSet("MerakiBusinessDB"); tempSalesTable.FillSchema(tempUserHoldingSet, SchemaType.Mapped, "Sales"); tempSalesTable.Fill(tempUserHoldingSet, "Sales"); DataTable salesTable = tempUserHoldingSet.Tables["Sales"]; using (SqlConnection loadRetailSalesConnec = new SqlConnection(connec0)) { SqlCommand getRetailSalesCmd = loadRetailSalesConnec.CreateCommand(); getRetailSalesCmd.Connection = loadRetailSalesConnec; getRetailSalesCmd.CommandText = "SELECT * FROM [RetailSale] WHERE SoldBy = @SoldBy ORDER BY SaleDate ASC"; getRetailSalesCmd.Parameters.AddWithValue("@SoldBy", SqlDbType.NVarChar).Value = byStaffCombobox.Text; loadRetailSalesConnec.Open(); SqlDataAdapter tempRetailSalesTable = new SqlDataAdapter(getRetailSalesCmd); DataSet tempRetailSalesHoldingSet = new DataSet("MerakiBusinessDB"); tempRetailSalesTable.FillSchema(tempRetailSalesHoldingSet, SchemaType.Mapped, "RetailSale"); tempRetailSalesTable.Fill(tempRetailSalesHoldingSet, "RetailSale"); DataTable retailSalesTable = tempRetailSalesHoldingSet.Tables["RetailSale"]; DateTime today = DateTime.Today; string htmlPacketSalesTable = toHTML_Table_PacketSales2(salesTable, " " + today.Day + "/" + today.Month + "/" + today.Year); string htmlRetailSalesTables = toHTML_Table_RetailSales2(retailSalesTable, byStaffCombobox.Text); System.IO.File.WriteAllText(@"e:\Folder\ELiza Report For-" + DateTime.Now.Day.ToString() + ".HTML", htmlPacketSalesTable); System.IO.File.AppendAllText(@"e:\Folder\abc.HTML", htmlRetailSalesTables); TheWebBrowser myBrowser = new TheWebBrowser(); myBrowser.Url = @"e:\Folder\ELiza Report For-" + DateTime.Now.Day.ToString() + ".HTML"; myBrowser.Show(); } } } else if (startDatePicker.SelectedDate == null && endDatePicker.SelectedDate != null && byStaffCombobox.Text == "") { string connec0 = @"Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\MerakiBusinessDB.mdf;Integrated Security=True"; using (SqlConnection loadSalesConnec = new SqlConnection(connec0)) { SqlCommand getSalesCmd = loadSalesConnec.CreateCommand(); getSalesCmd.Connection = loadSalesConnec; getSalesCmd.CommandText = "SELECT * FROM [Sales] WHERE DateOfSale <= @DateOfSale2 ORDER BY DateOfSale ASC"; getSalesCmd.Parameters.AddWithValue("@DateOfSale2", SqlDbType.Date).Value = Convert.ToDateTime(endDatePicker.SelectedDate.Value.ToString("MM-dd-yyyy")); loadSalesConnec.Open(); SqlDataAdapter tempSalesTable = new SqlDataAdapter(getSalesCmd); DataSet tempUserHoldingSet = new DataSet("MerakiBusinessDB"); tempSalesTable.FillSchema(tempUserHoldingSet, SchemaType.Mapped, "Sales"); tempSalesTable.Fill(tempUserHoldingSet, "Sales"); DataTable salesTable = tempUserHoldingSet.Tables["Sales"]; using (SqlConnection loadRetailSalesConnec = new SqlConnection(connec0)) { SqlCommand getRetailSalesCmd = loadRetailSalesConnec.CreateCommand(); getRetailSalesCmd.Connection = loadRetailSalesConnec; getRetailSalesCmd.CommandText = "SELECT * FROM [RetailSale] WHERE SaleDate <= @DateOfSale2 ORDER BY SaleDate ASC"; getRetailSalesCmd.Parameters.AddWithValue("@DateOfSale2", SqlDbType.Date).Value = Convert.ToDateTime(endDatePicker.SelectedDate.Value.ToString("MM-dd-yyyy")); loadRetailSalesConnec.Open(); SqlDataAdapter tempRetailSalesTable = new SqlDataAdapter(getRetailSalesCmd); DataSet tempRetailSalesHoldingSet = new DataSet("MerakiBusinessDB"); tempRetailSalesTable.FillSchema(tempRetailSalesHoldingSet, SchemaType.Mapped, "ReatilSales"); tempRetailSalesTable.Fill(tempRetailSalesHoldingSet, "ReatilSales"); DataTable retailSalesTable = tempRetailSalesHoldingSet.Tables["ReatilSales"]; string htmlPacketSalesTable1 = toHTML_Table_PacketSales1(salesTable, endDatePicker.SelectedDate.Value); string htmlRetailSalesTables1 = toHTML_Table_RetailSales1(retailSalesTable, endDatePicker.SelectedDate.Value); System.IO.File.WriteAllText(@"e:\Folder\" + DateTime.Now.Day.ToString() + ".HTML", htmlPacketSalesTable1); System.IO.File.AppendAllText(@"e:\Folder\" + DateTime.Now.Day.ToString() + ".HTML", htmlRetailSalesTables1); TheWebBrowser myBrowser = new TheWebBrowser(); myBrowser.Url = @"e:\Folder\" + DateTime.Now.Day.ToString() + ".HTML"; myBrowser.Show(); } } } else if (startDatePicker.SelectedDate != null && endDatePicker.SelectedDate == null && byStaffCombobox.Text == "") { string connec0 = @"Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\MerakiBusinessDB.mdf;Integrated Security=True"; using (SqlConnection loadSalesConnec = new SqlConnection(connec0)) { SqlCommand getSalesCmd = loadSalesConnec.CreateCommand(); getSalesCmd.Connection = loadSalesConnec; getSalesCmd.CommandText = "SELECT * FROM [Sales] WHERE DateOfSale >= @DateOfSale1 ORDER BY DateOfSale ASC"; getSalesCmd.Parameters.AddWithValue("@DateOfSale1", SqlDbType.Date).Value = Convert.ToDateTime(startDatePicker.SelectedDate.Value.ToString("MM-dd-yyyy")); loadSalesConnec.Open(); SqlDataAdapter tempSalesTable = new SqlDataAdapter(getSalesCmd); DataSet tempUserHoldingSet = new DataSet("MerakiBusinessDB"); tempSalesTable.FillSchema(tempUserHoldingSet, SchemaType.Mapped, "Sales"); tempSalesTable.Fill(tempUserHoldingSet, "Sales"); DataTable salesTable = tempUserHoldingSet.Tables["Sales"]; using (SqlConnection loadRetailSalesConnec = new SqlConnection(connec0)) { SqlCommand getRetailSalesCmd = loadRetailSalesConnec.CreateCommand(); getRetailSalesCmd.Connection = loadRetailSalesConnec; getRetailSalesCmd.CommandText = "SELECT * FROM [RetailSale] WHERE SaleDate >= @DateOfSale1 ORDER BY SaleDate ASC"; getRetailSalesCmd.Parameters.AddWithValue("@DateOfSale1", SqlDbType.Date).Value = Convert.ToDateTime(startDatePicker.SelectedDate.Value.ToString("MM-dd-yyyy")); loadRetailSalesConnec.Open(); SqlDataAdapter tempRetailSalesTable = new SqlDataAdapter(getRetailSalesCmd); DataSet tempRetailSalesHoldingSet = new DataSet("MerakiBusinessDB"); tempRetailSalesTable.FillSchema(tempRetailSalesHoldingSet, SchemaType.Mapped, "ReatilSales"); tempRetailSalesTable.Fill(tempRetailSalesHoldingSet, "ReatilSales"); DataTable retailSalesTable = tempRetailSalesHoldingSet.Tables["ReatilSales"]; string htmlPacketSalesTable1 = toHTML_Table_PacketSales1(salesTable, startDatePicker.SelectedDate.Value); string htmlRetailSalesTables1 = toHTML_Table_RetailSales1(retailSalesTable, startDatePicker.SelectedDate.Value); System.IO.File.WriteAllText(@"e:\Folder\" + DateTime.Now.Day.ToString() + ".HTML", htmlPacketSalesTable1); System.IO.File.AppendAllText(@"e:\Folder\" + DateTime.Now.Day.ToString() + ".HTML", htmlRetailSalesTables1); TheWebBrowser myBrowser = new TheWebBrowser(); myBrowser.Url = @"e:\Folder\" + DateTime.Now.Day.ToString() + ".HTML"; myBrowser.Show(); } } } #region everything is null else if (startDatePicker.SelectedDate == null && endDatePicker.SelectedDate == null && byStaffCombobox.Text == null) { MessageBox.Show("Please First Make A selection!"); } #endregion }