You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Custom classes for Windows Form Application in C# Developed by Wilfred V. Pine
3
+
Custom [Classes](https://github.com/redmalmon/csharp-custom-classes/tree/main/Classes) for Windows Form Application using C# Developed by Wilfred V. Pine
### 1. [Database](https://github.com/redmalmon/csharp-custom-classes/blob/main/Classes/Database.cs) class - this is use for MySqlClient configurations, sql statements, & etc. This will also included the loading of data to a form control including dataGridView and comboBox.
11
-
12
-
* Instantiation - creating an object `db` from a class type `Database` and instantiate using the `new` keyword.
1. Copy the [Classes](https://github.com/redmalmon/csharp-custom-classes/tree/main/Classes) folder into your project folder.
12
+
2. From your project folder root directory, create a class named " [Config](https://github.com/redmalmon/csharp-custom-classes/blob/main/Config.cs) " and create a public instance of all the classes from [Classes](https://github.com/redmalmon/csharp-custom-classes/tree/main/Classes) folder. See the code below:
3. Create an instance of your [Config](https://github.com/redmalmon/csharp-custom-classes/blob/main/Config.cs) class.
16
51
```c#
17
-
// instantiate an object `db` from `Database` class
18
-
Databasedb=newDatabase();
52
+
publicpartialclassFormLogin : Form
53
+
{
54
+
Configconfig=newConfig(); // your Config class
55
+
56
+
publicFormLogin()
57
+
{
58
+
InitializeComponent();
59
+
}
19
60
```
61
+
4. You can now use [Database](https://github.com/redmalmon/csharp-custom-classes/blob/main/Classes/Database.cs) , [Validation](https://github.com/redmalmon/csharp-custom-classes/blob/main/Classes/Validation.cs) , [Visualizer](https://github.com/redmalmon/csharp-custom-classes/blob/main/Classes/Visualizer.cs) , [Upload](https://github.com/redmalmon/csharp-custom-classes/blob/main/Classes/Upload.cs) , [Date_Time](https://github.com/redmalmon/csharp-custom-classes/blob/main/Classes/Str_Date_Time.cs) , & [Form_UI](https://github.com/redmalmon/csharp-custom-classes/blob/main/Classes/Form_UI.cs) Class.
62
+
```c#
63
+
config.db.....
64
+
config.validate......
65
+
config.ui......
66
+
config.visualizer.....
67
+
config.date_time.....
68
+
config.upload.......
69
+
```
70
+
71
+
72
+
### Using [Database](https://github.com/redmalmon/csharp-custom-classes/blob/main/Classes/Database.cs) class - this is use for MySqlClient configurations, sql statements, & etc. This will also included the loading of data to a form control including dataGridView and comboBox.
20
73
21
74
#### Using Database' Methods
22
75
@@ -25,67 +78,97 @@ Sql Statements
25
78
* `select(stringqry)` or select() method is use for `select` statements and this method return `MySqlDataReader` that reads a forward-only stream of rows from a MySQL database.
26
79
27
80
```c#
28
-
varreader=db.select("select * from users");
81
+
var reader = config.db.select("select * fromusers");
29
82
while (reader.Read())
30
83
{
31
84
//reader["userid"].ToString();
32
85
}
33
86
```
34
87
35
-
*`save(string table, string[] column, string[] bind)` or save() method is use for `insert into` statements and does not return a value. This methods display a MessageBox for showing the result of your sql statement.
88
+
* `save(stringtable, string[] column, string[] bind, stringmsg="Successfully saved.")` or save() method is use for `insert into` statements and does not return a value. This methods display a MessageBox for showing the result of your sql statement.
36
89
37
-
The `table` parameter is use to pass your table_name from your database, while `column` parameter is use to pass your collection of column_name from your database table, and the `bind` parameter is for the collection of values of the columns.
90
+
The `table` parameter is use to pass your table_name from your database, while `column` parameter is use to pass your collection of column_name from your database table, and the `bind` parameter is for the collection of values of the columns. Since the `msg` parameter has a default value, it is optional.
*`cud(string qry, string msg = "")` or cud() method is use for your `insert into` , `update` , and `delete` statements. This method also does not return a value. This methods display a MessageBox for showing the result of your sql statement, or passing your custom notification message (optional) using `msg` parameter.
98
+
* `cud(stringqry, stringmsg="Transaction Completed!")` or cud() method is use for your `insert into` , `update` , and `delete` statements. This method also does not return a value. This methods display a MessageBox for showing the result of your sql statement, or passing your custom notification message (optional) using `msg` parameter.
*`table(string qry, DataGridView dgv, string[] header = null)` or table() method is use for displaying data to DataGridView Control using the DataSource properties.
58
111
59
-
The `qry` parameter use for your sql satements `select`. The `dgv` parameter is use to pass the name of your DataGridView Control, while the `header` parameter (optional) is use to display the custom header name for your DataGridView display.
112
+
* `table(stringqry, DataGridViewdgv, string[] header=null)` or table() method is use for displaying data to a DataGridView Control using the DataSource properties.
113
+
114
+
The `qry` parameter use for your sql satement `select`. The `dgv` parameter is use to pass the name of your DataGridView Control, while the `header` parameter (optional) is use to display the collection of custom header name for your DataGridView display.
* `list(stringqry, ComboBoxcomboBox)` or list() method is use to display data to your comboBox control as an items.
73
129
74
-
### 2. [Date_time](https://github.com/redmalmon/CSharf-Custom-Classes/blob/main/C-Sharf%20Classes/Classes/Date_time.cs) class - for date & time conversion
130
+
```c#
131
+
config.db.list("selectcourse_namefromcourses", cmbCourse); // cmbCourse is the name of your comboBox control
132
+
```
75
133
76
-
*
134
+
* `exist(stringqry)` or exist() method is use to validate if a data is existing in your database. It will return `true` if exist.
### 3. [Public_variables](https://github.com/redmalmon/CSharf-Custom-Classes/blob/main/C-Sharf%20Classes/Classes/Public_variables.cs) class - stored global variables
* `Show(FormfrmNew, FormfrmOld)` or Show() method is simply use for displaying new Form and hiding active Form.
159
+
- Behind the methods: `frmain.Show();` `this.Hide();`
160
+
```c#
161
+
frmMain frmain = new frmMain();
162
+
config.ui.Show(frmain, this); // or config.ui.Show(new frmMain());
163
+
```
164
+
165
+
* `Dialog(Form frm)` or Dialog() methods use for displaying Form as Dialog.
85
166
86
167
```c#
87
-
UI_eventsui=newUI_events();
168
+
frmMain frmain = new frmMain();
169
+
config.ui.Dialog(frmain); // or config.ui.Show(new frmMain());
88
170
```
171
+
#### The MDI :
89
172
90
173
* `FormShow(Form frm, string dstyle = "Fill")` or FormShow() methods is use for displaying form child to your MdiParent Form.
91
174
@@ -95,33 +178,17 @@ frmDashboard dash = new frmDashboard();
95
178
```
96
179
Passing object `dash` to the first parameter, and "Top" (`DockStyle` property value) to second parameter (Optional). Top property value is use for Dock properties of a form child. The default Dock property value is `DockStyle.Fill` or `Fill`.
97
180
```c#
98
-
ui.FormShow(dash, "Top");
181
+
config.ui.FormShow(dash, "Top");
99
182
```
100
183
101
184
```c#
102
185
// Fill
103
186
frmDashboard dash = new frmDashboard();
104
-
ui.FormShow(dash);
187
+
config.ui.FormShow(dash); // or config.ui.FormShow(new frmDashboard());
105
188
```
106
189
107
-
*`Show(Form frmNew, Form frmOld)` or Show() method is simply use for displaying new Form and hiding active Form.
108
-
109
-
```c#
110
-
frmMainfrmain=newfrmMain();
111
-
ui.Show(frmain, this);
112
-
//behind the methods
113
-
//frmain.Show();
114
-
//this.Hide();
115
-
```
116
-
117
-
*`Dialog(Form frm)` or Dialog() methods use for displaying Form as Dialog.
118
-
119
-
```c#
120
-
frmMainfrmain=newfrmMain();
121
-
ui.Dialog(frmain);
122
-
```
123
190
124
-
#### Chart
191
+
### Using [Visualizer](https://github.com/redmalmon/csharp-custom-classes/blob/main/Classes/Visualizer.cs) - use for visualization of data.
125
192
126
193
* `chart(Chart chart, string SeriesName, string[] x, int[] y, string chartType = "Column")` or chart() method
127
194
@@ -140,15 +207,15 @@ void loadChartSample()
140
207
// Array Value
141
208
int[] Y= { 12, 14, 9 };
142
209
// Pass to Chart Methods = Male Series
143
-
ui.chart(chartUser, "Male", X, Y, "Pie");
210
+
config.visualizer.chart(chartUser, "Male", X, Y, "Pie");
### 6. [Validations](https://github.com/redmalmon/CSharf-Custom-Classes/blob/main/C-Sharf%20Classes/Classes/Validations.cs) class - keyboard events, mouse events, etc.
196
274
197
-
* Instantiate
275
+
### Using [Validations](https://github.com/redmalmon/csharp-custom-classes/blob/main/Classes/Validation.cs) class - use for validationg inputs (keyboard events, mouse events, etc.)
198
276
199
-
```c#
200
-
Validationsvalidate=newValidations();
201
-
```
202
277
203
-
* The `txtRequired(TextBox[] txt, string msg = "")` or txtTequired() method use to validate required input controls.
278
+
* The `txtRequired(TextBox[] txt, boolallow_message=false, stringmsg="Please fillup required fields!")` or txtRequired() method use to validate required textbox controls. There is also validation for comboBox controls, the `cmbRequired(ComboBox[] cmb, boolallow_message=false, stringmsg="Please select required fields!")` method. These functions return `false` if ther is an empty value in the fields.
if (!validate.txtRequired(txt) ||!validate.cmbRequired(cmb))
283
+
if (!config.validate.txtRequired(txt) || !config.validate.cmbRequired(cmb))
209
284
return;
210
285
```
211
286
212
-
*Accepts Numbers & Letters Only
287
+
* The `alpha(KeyPressEventArgse)` or alpha() Method is use to disable a series of keyboard characters except letters. To use this method, set a KeyPress events to your texbox and call the `alphanum(e)` methods to it's event handler.
0 commit comments