-
Notifications
You must be signed in to change notification settings - Fork 0
/
frmCustomers.cs
146 lines (132 loc) · 3.85 KB
/
frmCustomers.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
143
144
145
146
using System;
using System.Windows.Forms;
using UpgradeHelpers.DB.ADO;
namespace SKS
{
internal partial class frmCustomers
: System.Windows.Forms.Form
{
private bool NewMode = false;
private bool EditMode = false;
private bool CancellingMode = false;
public string CurrentCustomerID = "";
public frmCustomers()
: base()
{
if (m_vb6FormDefInstance == null)
{
if (m_InitializingDefInstance)
{
m_vb6FormDefInstance = this;
}
else
{
try
{
//For the start-up form, the first instance created is the default instance.
if (System.Reflection.Assembly.GetExecutingAssembly().EntryPoint != null && System.Reflection.Assembly.GetExecutingAssembly().EntryPoint.DeclaringType == this.GetType())
{
m_vb6FormDefInstance = this;
}
}
catch
{
}
}
}
//This call is required by the Windows Form Designer.
InitializeComponent();
ReLoadForm(false);
}
private void Form_Closed(Object eventSender, EventArgs eventArgs)
{
CurrentCustomerID = Convert.ToString(dcCustomers.Recordset.Fields["CustomerId"].Value);
}
//Private Sub dcCustomers_MoveComplete(ByVal adReason As ADODB.EventReasonEnum, ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
//NewMode = False
//EditMode = False
//CancellingMode = False
//End Sub
//Private Sub dcCustomers_WillMove(ByVal adReason As ADODB.EventReasonEnum, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
//CancellingMode = True
//End Sub
//UPGRADE_WARNING: (2080) Form_Load event was upgraded to Form_Load method and has a new behavior. More Information: https://www.mobilize.net/vbtonet/ewis/ewi2080
private void Form_Load()
{
InitForm();
}
public void InitForm()
{
dcCustomers.ConnectionString = modMain.ConnectionString;
NewMode = false;
EditMode = false;
CancellingMode = false;
}
private void Toolbar1_ButtonClick(Object eventSender, EventArgs eventArgs)
{
ToolStripItem Button = (ToolStripItem) eventSender;
object x = null;
switch(Button.Text)
{
case "Add" :
//Add new record
NewMode = true;
dcCustomers.Recordset.AddNew();
break;
case "Edit" :
//Edit mode
EditMode = true;
break;
case "Save" :
//Save data
dcCustomers.Recordset.Update();
EditMode = false;
NewMode = false;
break;
case "Delete" :
//Delete record
if (MessageBox.Show("Are you sure you want to delete this record?", "Delete record", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
{
dcCustomers.Recordset.Delete();
dcCustomers.Recordset.Requery();
}
break;
case "Search" :
//Search for records
modFunctions.SearchShow("Customers", "CompanyName", "customer");
break;
case "Cancel" :
CancellingMode = true;
//Cancel edited changes
EditMode = false;
NewMode = false;
dcCustomers.Recordset.CancelUpdate();
dcCustomers.Recordset.Requery();
CancellingMode = false;
this.Close();
break;
}
}
private void txtField_TextChanged(Object eventSender, EventArgs eventArgs)
{
if (!CancellingMode)
{
EditMode = true;
}
}
//Used already in frmSearch
public void SearchCriteriaProducts(string field, string value)
{
modConnection.ExecuteSql("Select * from Customers where " + field + " LIKE '" + value + "%'");
if (modConnection.rs.RecordCount == 0)
{
MessageBox.Show("There are no records with the selected criteria", "Search", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
modMain.LogStatus("There are " + modConnection.rs.RecordCount.ToString() + " that meet with the selected criteria");
dcCustomers.Recordset = (ADORecordSetHelper) modConnection.rs;
}
}
}
}