using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Configuration;
using System.Drawing.Printing;
namespace Milk
{
public partial class Specific_Supplier : Form
{
public Specific_Supplier()
{
InitializeComponent();
}
OleDbConnection con = new OleDbConnection(ConfigurationManager.ConnectionStrings["con"].ConnectionString);
OleDbCommand cmd;
OleDbDataAdapter da;
DataTable dt;
OleDbDataReader dr;
public double close;
private void Specific_Supplier_Load(object sender, EventArgs e)
{
label1.Text = Supplier_Details.me.ToString();
grid();
grid1();
double amt = (Convert.ToDouble(label7.Text) - Convert.ToDouble(label9.Text));
label11.Text = amt.ToString();
close = Convert.ToDouble(label11.Text);
}
public void grid()
{
try
{
da = new OleDbDataAdapter("select S_Date,Supplier_Qty,Total_Amount From suppurchage where Supplier_Name= '" + label1.Text + "'", con);
dt = new DataTable();
da.Fill(dt);
dataGridView1.DataSource = dt;
double no = 0;
for (int i = 0; i < dt.Rows.Count; i++)
{
no += Convert.ToDouble(dt.Rows[i][2].ToString());
}
label7.Text = Math.Round(no, 2).ToString();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
public void grid1()
{
try
{
da = new OleDbDataAdapter("select Payment_Date,Amount From spayment where Supplier_Name= '" + label1.Text + "'", con);
dt = new DataTable();
da.Fill(dt);
dataGridView2.DataSource = dt;
double no2 = 0;
for (int i = 0; i < dt.Rows.Count; i++)
{
no2 += Convert.ToDouble(dt.Rows[i][1].ToString());
}
label9.Text = Math.Round(no2, 2).ToString();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
double inwardquan;
double outwardquan;
private void button1_Click(object sender, EventArgs e)
{
dateTimePicker1.Text = DateTime.Parse(dateTimePicker1.Text).ToString();
double date1 = dateTimePicker1.Value.ToOADate();
double date2 = dateTimePicker2.Value.ToOADate();
double date3 = DateTime.Now.Date.ToOADate();
label3.Text = (opening1(date1) - opening2(date1)).ToString();
label5.Text = (opening1(date2) - opening2(date2)).ToString();
gridshow3(date1, date2);
gridshow4(date1, date2);
double nos = Convert.ToDouble(label7.Text) - Convert.ToDouble(label9.Text);
label11.Text = Math.Round(nos, 2).ToString();
//if (Convert.ToDouble(label11.Text) > 0)
//{
// label12.Visible = true;
//}
//else
//{
// label10.Visible = true;
//}
}
private double opening1(double date)
{
try
{
string str = "select SUM(Total_Amount) as total from suppurchage where Supplier_Name='" + label1.Text + "' and S_Date<" + date + "";
cmd = new OleDbCommand(str, con);
da = new OleDbDataAdapter(str, con);
dt = new DataTable();
da.Fill(dt);
con.Open();
dr = cmd.ExecuteReader();
if (dr.Read())
{
inwardquan = Convert.ToDouble(dr[0].ToString());
}
con.Close();
}
catch (Exception ex)
{
con.Close();
inwardquan = 0;
}
return inwardquan;
}
private double opening2(double date)
{
try
{
string str = "select SUM(Amount) as total from spayment where supplier_Name='" + label1.Text + "' and Payment_Date<" + date + "";
cmd = new OleDbCommand(str, con);
con.Open();
dr = cmd.ExecuteReader();
if (dr.Read())
{
outwardquan = Convert.ToDouble(dr[0].ToString());
con.Close();
}
}
catch (Exception ex)
{
con.Close();
outwardquan = 0;
}
return outwardquan;
}
protected void gridshow3(double d1, double d2)
{
try
{
string str = "select S_Date,Supplier_Qty,Total_Amount from suppurchage where Supplier_Name='" + label1.Text + "' and S_Date between " + d1 + " and " + d2 + "";
da = new OleDbDataAdapter(str, con);
dt = new DataTable();
da.Fill(dt);
dataGridView1.DataSource = dt;
//if (dt.Rows.Count > 0)
//{
// dt3 = Convert.ToDateTime(dt.Rows[0][0].ToString());
//}
double no = 0;
for (int i = 0; i < dt.Rows.Count; i++)
{
no += Convert.ToDouble(dt.Rows[i][2].ToString());
}
label7.Text = Math.Round(no, 2).ToString();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
protected void gridshow4(double d1, double d2)
{
try
{
string str = "select Payment_Date,Amount from spayment where Supplier_Name='" + label1.Text + "' and Payment_Date between " + d1 + " and " + d2 + "";
da = new OleDbDataAdapter(str, con);
dt = new DataTable();
da.Fill(dt);
dataGridView2.DataSource = dt;
double no = 0;
for (int i = 0; i < dt.Rows.Count; i++)
{
no += Convert.ToDouble(dt.Rows[i][1].ToString());
}
label9.Text = Math.Round(no, 2).ToString();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
public int i;
public int k;
public int f;
public int s;
private void button3_Click(object sender, EventArgs e)
{
f = dataGridView1.Rows.Count - 1;
s = dataGridView2.Rows.Count - 1;
i = (f >= s) ? f : s;
k = 0;
while (k < i)
{
PrintDocument doc = new PrintDocument();
doc.PrintPage += new PrintPageEventHandler(doc_PrintPage);
PrintDialog dlgSettings = new PrintDialog();
dlgSettings.Document = doc;
doc.Print();
}
}
void doc_PrintPage(object sender, PrintPageEventArgs e)
{
try
{
Font font1 = new Font("Arial", 18);
Font font = new Font("Arial", 10);
//float x = e.MarginBounds.Left;
//float lineSide=font.
float y = e.MarginBounds.Top;
float lineHeight = font.GetHeight(e.Graphics);
//Header
e.Graphics.DrawString(label1.Text, font1, Brushes.Black, float.Parse("50"), float.Parse("0"));
y += lineHeight;
e.Graphics.DrawString("Date:- " + dateTimePicker1.Value.ToString("dd-MM-yyyy") + " To " + dateTimePicker2.Value.ToString("dd-MM-yyyy"), font, Brushes.Black, float.Parse("550"), float.Parse("10"));
y += lineHeight;
e.Graphics.DrawString("PURCHASE", font, Brushes.Black, float.Parse("100"), float.Parse("30"));
y += lineHeight;
e.Graphics.DrawString("PAYMENT ", font, Brushes.Black, float.Parse("500"), float.Parse("30"));
y += lineHeight;
e.Graphics.DrawString("----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------" +
"-", font, Brushes.Black, float.Parse("00"), float.Parse("45"));
y += lineHeight;
//Header
e.Graphics.DrawString("DATE", font, Brushes.Black, float.Parse("40"), float.Parse("60"));
y += lineHeight;
e.Graphics.DrawString("QUANTITY", font, Brushes.Black, float.Parse("200"), float.Parse("60"));
y += lineHeight;
e.Graphics.DrawString("AMOUNT", font, Brushes.Black, float.Parse("360"), float.Parse("60"));
y += lineHeight;
e.Graphics.DrawString("DATE", font, Brushes.Black, float.Parse("520"), float.Parse("60"));
y += lineHeight;
e.Graphics.DrawString("AMOUNT", font, Brushes.Black, float.Parse("680"), float.Parse("60"));
y += lineHeight;
//HERE I NEED TO PUT DATA GRID VIEW WHICH MAY VERY NUMBER OF ROWS EVERY TIME
//Body
e.Graphics.DrawString("---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------", font, Brushes.Black, float.Parse("00"), float.Parse("70"));
y += lineHeight;
int j = 80;
for (int l = k; l < i; l++)
{
if (l < f)
{
e.Graphics.DrawString(Convert.ToDateTime(dataGridView1.Rows[l].Cells[0].Value).ToString("dd-MM-yy"), font, Brushes.Black, float.Parse("40"), float.Parse(j.ToString()));
y += lineHeight;
e.Graphics.DrawString(dataGridView1.Rows[l].Cells[1].Value.ToString(), font, Brushes.Black, float.Parse("200"), float.Parse(j.ToString()));
y += lineHeight;
e.Graphics.DrawString(dataGridView1.Rows[l].Cells[2].Value.ToString(), font, Brushes.Black, float.Parse("360"), float.Parse(j.ToString()));
y += lineHeight;
e.Graphics.DrawString("|", font, Brushes.Black, float.Parse("450"), float.Parse(j.ToString()));
y += lineHeight;
int a = j + 12;
e.Graphics.DrawString("|", font, Brushes.Black, float.Parse("450"), float.Parse(a.ToString()));
y += lineHeight;
}
if (l < s)
{
e.Graphics.DrawString("|", font, Brushes.Black, float.Parse("450"), float.Parse(j.ToString()));
y += lineHeight;
int a = j + 12;
e.Graphics.DrawString("|", font, Brushes.Black, float.Parse("450"), float.Parse(a.ToString()));
y += lineHeight;
e.Graphics.DrawString(Convert.ToDateTime(dataGridView2.Rows[l].Cells[0].Value).ToString("dd-MM-yy"), font, Brushes.Black, float.Parse("520"), float.Parse(j.ToString()));
y += lineHeight;
e.Graphics.DrawString(dataGridView2.Rows[l].Cells[1].Value.ToString(), font, Brushes.Black, float.Parse("680"), float.Parse(j.ToString()));
y += lineHeight;
}
j = j + 20;
k++;
if (j > 1140)
{
break;
}
}
j = j + 10;
e.Graphics.DrawString("----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------", font, Brushes.Black, float.Parse("00"), float.Parse(j.ToString()));
y += lineHeight;
j = j + 20;
e.Graphics.DrawString("OPENING :-", font, Brushes.Black, float.Parse("50"), float.Parse(j.ToString()));
y += lineHeight;
e.Graphics.DrawString(label3.Text, font, Brushes.Black, float.Parse("170"), float.Parse(j.ToString()));
y += lineHeight;
e.Graphics.DrawString("CLOSING :-", font, Brushes.Black, float.Parse("400"), float.Parse(j.ToString()));
y += lineHeight;
e.Graphics.DrawString(label5.Text, font, Brushes.Black, float.Parse("510"), float.Parse(j.ToString()));
y += lineHeight;
j = j + 30;
e.Graphics.DrawString("BALANCE :- " + label11.Text, font, Brushes.Black, float.Parse("280"), float.Parse(j.ToString()));
y += lineHeight;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Configuration;
using System.Drawing.Printing;
namespace Milk
{
public partial class Specific_Supplier : Form
{
public Specific_Supplier()
{
InitializeComponent();
}
OleDbConnection con = new OleDbConnection(ConfigurationManager.ConnectionStrings["con"].ConnectionString);
OleDbCommand cmd;
OleDbDataAdapter da;
DataTable dt;
OleDbDataReader dr;
public double close;
private void Specific_Supplier_Load(object sender, EventArgs e)
{
label1.Text = Supplier_Details.me.ToString();
grid();
grid1();
double amt = (Convert.ToDouble(label7.Text) - Convert.ToDouble(label9.Text));
label11.Text = amt.ToString();
close = Convert.ToDouble(label11.Text);
}
public void grid()
{
try
{
da = new OleDbDataAdapter("select S_Date,Supplier_Qty,Total_Amount From suppurchage where Supplier_Name= '" + label1.Text + "'", con);
dt = new DataTable();
da.Fill(dt);
dataGridView1.DataSource = dt;
double no = 0;
for (int i = 0; i < dt.Rows.Count; i++)
{
no += Convert.ToDouble(dt.Rows[i][2].ToString());
}
label7.Text = Math.Round(no, 2).ToString();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
public void grid1()
{
try
{
da = new OleDbDataAdapter("select Payment_Date,Amount From spayment where Supplier_Name= '" + label1.Text + "'", con);
dt = new DataTable();
da.Fill(dt);
dataGridView2.DataSource = dt;
double no2 = 0;
for (int i = 0; i < dt.Rows.Count; i++)
{
no2 += Convert.ToDouble(dt.Rows[i][1].ToString());
}
label9.Text = Math.Round(no2, 2).ToString();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
double inwardquan;
double outwardquan;
private void button1_Click(object sender, EventArgs e)
{
dateTimePicker1.Text = DateTime.Parse(dateTimePicker1.Text).ToString();
double date1 = dateTimePicker1.Value.ToOADate();
double date2 = dateTimePicker2.Value.ToOADate();
double date3 = DateTime.Now.Date.ToOADate();
label3.Text = (opening1(date1) - opening2(date1)).ToString();
label5.Text = (opening1(date2) - opening2(date2)).ToString();
gridshow3(date1, date2);
gridshow4(date1, date2);
double nos = Convert.ToDouble(label7.Text) - Convert.ToDouble(label9.Text);
label11.Text = Math.Round(nos, 2).ToString();
//if (Convert.ToDouble(label11.Text) > 0)
//{
// label12.Visible = true;
//}
//else
//{
// label10.Visible = true;
//}
}
private double opening1(double date)
{
try
{
string str = "select SUM(Total_Amount) as total from suppurchage where Supplier_Name='" + label1.Text + "' and S_Date<" + date + "";
cmd = new OleDbCommand(str, con);
da = new OleDbDataAdapter(str, con);
dt = new DataTable();
da.Fill(dt);
con.Open();
dr = cmd.ExecuteReader();
if (dr.Read())
{
inwardquan = Convert.ToDouble(dr[0].ToString());
}
con.Close();
}
catch (Exception ex)
{
con.Close();
inwardquan = 0;
}
return inwardquan;
}
private double opening2(double date)
{
try
{
string str = "select SUM(Amount) as total from spayment where supplier_Name='" + label1.Text + "' and Payment_Date<" + date + "";
cmd = new OleDbCommand(str, con);
con.Open();
dr = cmd.ExecuteReader();
if (dr.Read())
{
outwardquan = Convert.ToDouble(dr[0].ToString());
con.Close();
}
}
catch (Exception ex)
{
con.Close();
outwardquan = 0;
}
return outwardquan;
}
protected void gridshow3(double d1, double d2)
{
try
{
string str = "select S_Date,Supplier_Qty,Total_Amount from suppurchage where Supplier_Name='" + label1.Text + "' and S_Date between " + d1 + " and " + d2 + "";
da = new OleDbDataAdapter(str, con);
dt = new DataTable();
da.Fill(dt);
dataGridView1.DataSource = dt;
//if (dt.Rows.Count > 0)
//{
// dt3 = Convert.ToDateTime(dt.Rows[0][0].ToString());
//}
double no = 0;
for (int i = 0; i < dt.Rows.Count; i++)
{
no += Convert.ToDouble(dt.Rows[i][2].ToString());
}
label7.Text = Math.Round(no, 2).ToString();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
protected void gridshow4(double d1, double d2)
{
try
{
string str = "select Payment_Date,Amount from spayment where Supplier_Name='" + label1.Text + "' and Payment_Date between " + d1 + " and " + d2 + "";
da = new OleDbDataAdapter(str, con);
dt = new DataTable();
da.Fill(dt);
dataGridView2.DataSource = dt;
double no = 0;
for (int i = 0; i < dt.Rows.Count; i++)
{
no += Convert.ToDouble(dt.Rows[i][1].ToString());
}
label9.Text = Math.Round(no, 2).ToString();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
public int i;
public int k;
public int f;
public int s;
private void button3_Click(object sender, EventArgs e)
{
f = dataGridView1.Rows.Count - 1;
s = dataGridView2.Rows.Count - 1;
i = (f >= s) ? f : s;
k = 0;
while (k < i)
{
PrintDocument doc = new PrintDocument();
doc.PrintPage += new PrintPageEventHandler(doc_PrintPage);
PrintDialog dlgSettings = new PrintDialog();
dlgSettings.Document = doc;
doc.Print();
}
}
void doc_PrintPage(object sender, PrintPageEventArgs e)
{
try
{
Font font1 = new Font("Arial", 18);
Font font = new Font("Arial", 10);
//float x = e.MarginBounds.Left;
//float lineSide=font.
float y = e.MarginBounds.Top;
float lineHeight = font.GetHeight(e.Graphics);
//Header
e.Graphics.DrawString(label1.Text, font1, Brushes.Black, float.Parse("50"), float.Parse("0"));
y += lineHeight;
e.Graphics.DrawString("Date:- " + dateTimePicker1.Value.ToString("dd-MM-yyyy") + " To " + dateTimePicker2.Value.ToString("dd-MM-yyyy"), font, Brushes.Black, float.Parse("550"), float.Parse("10"));
y += lineHeight;
e.Graphics.DrawString("PURCHASE", font, Brushes.Black, float.Parse("100"), float.Parse("30"));
y += lineHeight;
e.Graphics.DrawString("PAYMENT ", font, Brushes.Black, float.Parse("500"), float.Parse("30"));
y += lineHeight;
e.Graphics.DrawString("----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------" +
"-", font, Brushes.Black, float.Parse("00"), float.Parse("45"));
y += lineHeight;
//Header
e.Graphics.DrawString("DATE", font, Brushes.Black, float.Parse("40"), float.Parse("60"));
y += lineHeight;
e.Graphics.DrawString("QUANTITY", font, Brushes.Black, float.Parse("200"), float.Parse("60"));
y += lineHeight;
e.Graphics.DrawString("AMOUNT", font, Brushes.Black, float.Parse("360"), float.Parse("60"));
y += lineHeight;
e.Graphics.DrawString("DATE", font, Brushes.Black, float.Parse("520"), float.Parse("60"));
y += lineHeight;
e.Graphics.DrawString("AMOUNT", font, Brushes.Black, float.Parse("680"), float.Parse("60"));
y += lineHeight;
//HERE I NEED TO PUT DATA GRID VIEW WHICH MAY VERY NUMBER OF ROWS EVERY TIME
//Body
e.Graphics.DrawString("---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------", font, Brushes.Black, float.Parse("00"), float.Parse("70"));
y += lineHeight;
int j = 80;
for (int l = k; l < i; l++)
{
if (l < f)
{
e.Graphics.DrawString(Convert.ToDateTime(dataGridView1.Rows[l].Cells[0].Value).ToString("dd-MM-yy"), font, Brushes.Black, float.Parse("40"), float.Parse(j.ToString()));
y += lineHeight;
e.Graphics.DrawString(dataGridView1.Rows[l].Cells[1].Value.ToString(), font, Brushes.Black, float.Parse("200"), float.Parse(j.ToString()));
y += lineHeight;
e.Graphics.DrawString(dataGridView1.Rows[l].Cells[2].Value.ToString(), font, Brushes.Black, float.Parse("360"), float.Parse(j.ToString()));
y += lineHeight;
e.Graphics.DrawString("|", font, Brushes.Black, float.Parse("450"), float.Parse(j.ToString()));
y += lineHeight;
int a = j + 12;
e.Graphics.DrawString("|", font, Brushes.Black, float.Parse("450"), float.Parse(a.ToString()));
y += lineHeight;
}
if (l < s)
{
e.Graphics.DrawString("|", font, Brushes.Black, float.Parse("450"), float.Parse(j.ToString()));
y += lineHeight;
int a = j + 12;
e.Graphics.DrawString("|", font, Brushes.Black, float.Parse("450"), float.Parse(a.ToString()));
y += lineHeight;
e.Graphics.DrawString(Convert.ToDateTime(dataGridView2.Rows[l].Cells[0].Value).ToString("dd-MM-yy"), font, Brushes.Black, float.Parse("520"), float.Parse(j.ToString()));
y += lineHeight;
e.Graphics.DrawString(dataGridView2.Rows[l].Cells[1].Value.ToString(), font, Brushes.Black, float.Parse("680"), float.Parse(j.ToString()));
y += lineHeight;
}
j = j + 20;
k++;
if (j > 1140)
{
break;
}
}
j = j + 10;
e.Graphics.DrawString("----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------", font, Brushes.Black, float.Parse("00"), float.Parse(j.ToString()));
y += lineHeight;
j = j + 20;
e.Graphics.DrawString("OPENING :-", font, Brushes.Black, float.Parse("50"), float.Parse(j.ToString()));
y += lineHeight;
e.Graphics.DrawString(label3.Text, font, Brushes.Black, float.Parse("170"), float.Parse(j.ToString()));
y += lineHeight;
e.Graphics.DrawString("CLOSING :-", font, Brushes.Black, float.Parse("400"), float.Parse(j.ToString()));
y += lineHeight;
e.Graphics.DrawString(label5.Text, font, Brushes.Black, float.Parse("510"), float.Parse(j.ToString()));
y += lineHeight;
j = j + 30;
e.Graphics.DrawString("BALANCE :- " + label11.Text, font, Brushes.Black, float.Parse("280"), float.Parse(j.ToString()));
y += lineHeight;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
No comments:
Post a Comment