forked from messam295/BusCom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ticket.cs
130 lines (114 loc) · 4.23 KB
/
Ticket.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
using DatabaseCodeFirst.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using testProj.Models;
namespace testProj
{
public partial class Ticket : Form
{
Trip trip;
List<int> seats;
LoginUser loggedUser;
string customerName;
public Ticket(LoginUser _loggedUser,Trip _trip,List<int> _seats,string _customerName)
{
InitializeComponent();
trip = _trip;
seats = _seats;
loggedUser = _loggedUser;
customerName = _customerName;
}
//for move body of form
public const int WM_NCLBUTTONDOWN = 0xA1;
public const int HT_CAPTION = 0x2;
[DllImportAttribute("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
[DllImportAttribute("user32.dll")]
public static extern bool ReleaseCapture();
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
ReleaseCapture();
SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
}
}
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
switch (e.Button)
{
case MouseButtons.Right:
{
metroContextMenu1.Show(this, new Point(e.X, e.Y));//places the menu at the pointer position
}
break;
}
}
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawImage(bitmap, 0, 0);
}
private void printToolStripMenuItem_Click(object sender, EventArgs e)
{
Panel panel = new Panel();
this.Controls.Add(panel);
Graphics grp = panel.CreateGraphics();
Size formSize = this.ClientSize;
bitmap = new Bitmap(formSize.Width, formSize.Height, grp);
grp = Graphics.FromImage(bitmap);
Point panelLocation = PointToScreen(panel.Location);
grp.CopyFromScreen(panelLocation.X, panelLocation.Y, 0, 0, formSize);
printPreviewDialog1.Document = printDocument1;
printPreviewDialog1.PrintPreviewControl.Zoom = 1;
printPreviewDialog1.ShowDialog();
}
Bitmap bitmap;
private void CaptureScreen()
{
Graphics myGraphics = this.CreateGraphics();
Size s = pictureBox1.Size;
bitmap = new Bitmap(s.Width, s.Height, myGraphics);
Graphics memoryGraphics = Graphics.FromImage(bitmap);
memoryGraphics.CopyFromScreen(this.Location.X, this.Location.Y, 0, 0, s);
}
private void closeToolStripMenuItem_Click(object sender, EventArgs e)
{
Close();
}
private void Ticket_Load(object sender, EventArgs e)
{
//ToolTip toolTip1 = new ToolTip();
//toolTip1.ShowAlways = true;
//toolTip1.SetToolTip(metroContextMenu1, "Click me to execute.");
txtDate.Text = trip.DepartureTime.Date.ToString("dddd, dd MMMM yyyy");
txtSource.Text = trip.Source.BranchName;
txtDest.Text = trip.Destination.BranchName;
txtTime.Text = trip.DepartureTime.TimeOfDay.ToString("hh':'mm");
txtName.Text = customerName;
StringBuilder sb = new StringBuilder("");
int i = 0;
if (seats.Count>1)
for (; i < seats.Count -1; i++)
{
sb.Append($"{seats.ElementAt(i)} , ");
}
sb.Append($"{seats.ElementAt(i)}");
txtSeat.Text = sb.ToString();
}
private void nextToolStripMenuItem_Click(object sender, EventArgs e)
{
Dashboard dashboard = new Dashboard(loggedUser);
this.Hide();
dashboard.ShowDialog();
this.Close();
}
}
}