-
Notifications
You must be signed in to change notification settings - Fork 0
/
PrintForm.cs
142 lines (116 loc) · 4.19 KB
/
PrintForm.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using System.Drawing.Printing;
namespace Cashier_Dekstop_App
{
public partial class PrintForm : Form
{
public string DataBillNo, DataDate, DataTotalBill, DataDiscount, DataNetPay;
private SqlCommand cmd;
private SqlDataAdapter da;
private DataTable dt;
private SqlDataReader dr;
koneksi sql_Connection = new koneksi();
public PrintForm()
{
InitializeComponent();
}
private void PrintForm_Load(object sender, EventArgs e)
{
lbl_DataBillNo.Text = DataBillNo.ToString();
lbl_DataDate.Text = DataDate.ToString();
lbl_DataTotalBill.Text = DataTotalBill.ToString();
lbl_DataDiscount.Text = DataDiscount.ToString();
lbl_DataNetPay.Text = DataNetPay.ToString();
SqlConnection myconn = sql_Connection.GetConn();
myconn.Open();
cmd = myconn.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "SELECT * FROM TBL_RowData WHERE BillNo LIKE('" + lbl_DataBillNo.Text + "%' )";
cmd.ExecuteNonQuery();
dt = new DataTable();
da = new SqlDataAdapter(cmd);
da.Fill(dt);
dataGridView1.DataSource = dt;
myconn.Close();
dataGridView1.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView1.Columns[5].Visible = false;
dataGridView1.Columns[6].Visible = false;
fillProductForm();
}
private void lbl_Area_Click(object sender, EventArgs e)
{
}
private void fillProductForm()
{
comboBox1.Select();
comboBox1.Items.Clear(); // Clear combo box before load form
SqlConnection myconn = sql_Connection.GetConn();
myconn.Open();
cmd = myconn.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "SELECT ProName from TBL_Products ORDER BY ProName ASC";
cmd.ExecuteNonQuery();
DataTable dt = new DataTable();
da = new SqlDataAdapter(cmd);
da.Fill(dt);
foreach (DataRow dr in dt.Rows)
{
comboBox1.Items.Add(dr["ProName"].ToString());
}
myconn.Close();
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void dataGridView1_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
{
LoadSerialNo();
}
private void LoadSerialNo()
{
int i = 0;
foreach (DataGridViewRow row in dataGridView1.Rows)
{
row.Cells[0].Value = i;
i++;
}
}
private void label7_Click(object sender, EventArgs e)
{
}
private void btn_Print_Click(object sender, EventArgs e)
{
print(this.panelPrint);
}
private void print(Panel pnl)
{
PrinterSettings ps = new PrinterSettings();
panelPrint = pnl;
getPrintArea(pnl);
printPreviewDialog1.Document = printDocument1;
printDocument1.PrintPage += new PrintPageEventHandler(printDocument1_PrintPage);
printPreviewDialog1.ShowDialog();
}
private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
{
Rectangle pagearea = e.PageBounds;
e.Graphics.DrawImage(memoryimg, (pagearea.Width / 2) - (this.panelPrint.Width / 2), this.panelPrint.Location.Y);
}
private Bitmap memoryimg;
private void getPrintArea(Panel pnl)
{
memoryimg = new Bitmap(pnl.Width, pnl.Height);
pnl.DrawToBitmap(memoryimg, new Rectangle(0, 0, pnl.Width, pnl.Height));
}
}
}