-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBusListForm.cs
79 lines (72 loc) · 2.67 KB
/
BusListForm.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
using BusReservationSystem.Classes;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace BusReservationSystem
{
public partial class BusListForm : Form
{
//Connection String [for connecting with database]
private readonly string conStr = ConfigurationManager.ConnectionStrings["BTRS_Db"].ConnectionString;
public BusListForm()
{
InitializeComponent();
}
private void BusListForm_Load(object sender, EventArgs e)
{
RefreshGrid();
DataGridViewButtonColumn buttonColumn = new DataGridViewButtonColumn()
{
Name = "btnDel",
HeaderText = "Del Buttons",
Text = "Delete",
UseColumnTextForButtonValue = true
};
dataGridView1.Columns.Add(buttonColumn);
DataGridViewButtonColumn buttonColumn1 = new DataGridViewButtonColumn()
{
Name = "btnReasign",
HeaderText = "View",
Text = "Reasign",
UseColumnTextForButtonValue = true
};
dataGridView1.Columns.Add(buttonColumn1);
}
private void DataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == dataGridView1.Columns["btnDel"].Index)
{
Bus bus = new Bus();
if (MessageBox.Show("Are you sure about deleting this Bus?", "Warning!", MessageBoxButtons.YesNo) == DialogResult.Yes)
bus.DelBus(dataGridView1.CurrentRow.Cells["no"].Value.ToString());
RefreshGrid();
}
else if(e.ColumnIndex == dataGridView1.Columns["btnReasign"].Index)
{
AsignCounterForm asignCounter = new AsignCounterForm(dataGridView1.CurrentRow.Cells["no"].Value.ToString());
asignCounter.ShowDialog(this);
}
}
private void RefreshGrid()
{
DataTable dataTable = new DataTable();
using (SqlConnection con = new SqlConnection(conStr))
{
SqlDataAdapter da = new SqlDataAdapter();
//Select All Busses based on counter
string sql = "Select * from [Bus]";
SqlCommand cmd = new SqlCommand(sql, con);
da.SelectCommand = cmd;
da.Fill(dataTable);
}
dataGridView1.DataSource = dataTable;
}
}
}