using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Data.Odbc;
using Excel = Microsoft.Office.Interop.Excel;
using System.Reflection;
using System.Collections;
using System.Threading;
using System.Data.SqlClient;
namespace DBASE
{
public partial class DDREPGEN : Form
{
public DDREPGEN()
{
InitializeComponent();
DateTime date = new DateTime();
date.GetDateTimeFormats();
timer1.Start();
date_label.Text = System.DateTime.Today.ToShortDateString();
//tread: http://www.suite101.com/article.cfm/c_sharp/96436
}
public Label qurey_label;
private OdbcConnection conn;
private OdbcConnectionStringBuilder osb = new OdbcConnectionStringBuilder();
private OdbcDataAdapter oleDbDataAdapter1;
DataTable dt = new DataTable();
DataTable dt2 = new DataTable();
//DataSet ds = new DataSet();
private void ClearDataSet(DataSet myDataSet)
{
// To test, print the number rows in each table.
foreach (DataTable dt in myDataSet.Tables)
{
Console.WriteLine(dt.TableName + "Rows.Count = " + dt.Rows.Count.ToString());
}
// Clear all rows of each table.
myDataSet.Clear();
// Print the number of rows again.
foreach (DataTable dt in myDataSet.Tables)
{
Console.WriteLine(dt.TableName + "Rows.Count = " + dt.Rows.Count.ToString());
}
}
private void buttonViewData_Click(object sender, EventArgs e)
{
//show in data grid
if (radioButtonBooth.Checked == true)
{
dataSet2.Clear();
//dataGrid1.DataSource dataSet1.dt.DefaultView;
dataGridViewBooth.DataSource = dt.DefaultView;
dataGridViewCash.Visible = false;
dataGridViewBooth.Visible = true;
//dataGridViewBooth.ClearSelection();
//ds.Clear();
dataGridViewBooth.DataSource = dt;
buttonExportData.Enabled = true;
buttonViewData.Enabled = false;
}
else if (radioButtonCash.Checked == true)
{
dataSet2.Clear();
dataGridViewCash.DataSource = dt.DefaultView;
dataGridViewBooth.Visible = false;
dataGridViewCash.Visible = true;
//dataGridViewCash.ClearSelection();
//ds.Clear();
dataGridViewCash.DataSource = dt;
buttonExportData.Enabled = true;
buttonViewData.Enabled = false;
}
}
private void buttonExit_Click(object sender, EventArgs e)
{
this.Close();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void buttonExportData_Click(object sender, EventArgs e)
{
DialogResult reply = MessageBox.Show("Are you sure you want to Export this data to excel?","TRANSPORTER",MessageBoxButtons.YesNo); //inform the user
if( reply == DialogResult.Yes)
{
//testing import
Excel.Application oXL;
Excel._Workbook oWB;
Excel._Worksheet oSheet;
Excel.Range oRng;
try
{
TextBox textBox1 = new TextBox();
string[,] arr = new string[1000, 2];
//Start Excel and get Application object.
oXL = new Excel.Application();
oXL.Visible = true;
//Get a new workbook.
oWB = (Excel._Workbook)(oXL.Workbooks.Add(Missing.Value));
oSheet = (Excel._Worksheet)oWB.ActiveSheet;
if (radioButtonCash.Checked == true)
{
//Add table headers going cell by cell.
oSheet.Cells[1, 4] = "Golden Donuts Inc.";
oSheet.Cells[2, 4] = "SAMPLE QUERY";
oSheet.Cells[2, 1] = "Shop:";
oSheet.Cells[2, 2] = shop_comboBox.Text.ToString();
oSheet.Cells[4, 1] = "Location:";
oSheet.Cells[4, 2] = location_textBox.Text.ToString();
oSheet.Cells[3, 1] = "Account No.";
oSheet.Cells[3, 2] = account_textBox.Text.ToString();
oSheet.Cells[5, 1] = "NET_SALES";
oSheet.Cells[5, 3] = "OVERAGES";
oSheet.Cells[5, 2] = "SHOP_VAT";
}
else if (radioButtonBooth.Checked == true)
{ //Add table headers going cell by cell
oSheet.Cells[1, 4] = "Golden Donuts Inc.";
oSheet.Cells[2, 4] = "BOOTH SALES";
oSheet.Cells[2, 1] = "Shop:";
oSheet.Cells[2, 2] = shop_comboBox.Text.ToString();
oSheet.Cells[4, 1] = "Location:";
oSheet.Cells[4, 2] = location_textBox.Text.ToString();
oSheet.Cells[3, 1] = "Account No.";
oSheet.Cells[3, 2] = account_textBox.Text.ToString();
oSheet.Cells[5, 1] = "DATE";
oSheet.Cells[5, 2] = "# CUST";
oSheet.Cells[5, 3] = "NET SALES";
oSheet.Cells[5, 4] = "TOTAL";
oSheet.Cells[5, 5] = "A/R - E";
oSheet.Cells[5, 6] = "TOTAL";
oSheet.Cells[5, 7] = "VAT";
oSheet.Cells[5, 8] = "OVERAGES";
oSheet.Cells[5, 9] = "OTHERS";
}
else
{
}
//AutoFit col
Gopal_nivas, if this helps please login to Mark As Answer. | Alert Moderator