Skip to content

Commit 4d8d755

Browse files
committed
updated
1 parent 565e49f commit 4d8d755

File tree

72 files changed

+1011
-26
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+1011
-26
lines changed

.vs/Sample OOP Pro/v16/.suo

7.5 KB
Binary file not shown.
File renamed without changes.
File renamed without changes.

Sample Project/Classes/Database.cs

Lines changed: 236 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,236 @@
1+
/**
2+
* __________________________________________________________________
3+
*
4+
* C-Sharf Custom Classes
5+
* __________________________________________________________________
6+
*
7+
* MIT License
8+
*
9+
* Copyright (c) 2020 Wilfred V. Pine
10+
*
11+
* Permission is hereby granted, free of charge, to any person obtaining a copy
12+
* of this software and associated documentation files (the "Software"), to deal
13+
* in the Software without restriction, including without limitation the rights
14+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15+
* copies of the Software, and to permit persons to whom the Software is
16+
* furnished to do so, subject to the following conditions:
17+
*
18+
* The above copyright notice and this permission notice shall be included in
19+
* all copies or substantial portions of the Software.
20+
*
21+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27+
* THE SOFTWARE.
28+
*
29+
* @package C-Sharf Custom Classes
30+
* @author Wilfred V. Pine <[email protected]>
31+
* @copyright Copyright 2020 (https://red.confired.com)
32+
* @link https://confired.com
33+
* @license https://opensource.org/licenses/MIT MIT License
34+
*/
35+
36+
using System;
37+
using System.Data;
38+
using System.Windows.Forms;
39+
using MySql.Data.MySqlClient;
40+
41+
namespace Classes
42+
{
43+
class Database
44+
{
45+
private static string constring;
46+
/* MySql Classes
47+
*
48+
*/
49+
public MySqlConnection con;
50+
MySqlCommand cmd;
51+
MySqlDataReader reader;
52+
MySqlDataAdapter da;
53+
DataTable dt;
54+
55+
/* Check Database Connection
56+
*
57+
*/
58+
public Database(string host, string user, string password, string database)
59+
{
60+
try
61+
{
62+
constring = "server="+ host+";uid=" + user + ";pwd='" + password + "';database=" + database;
63+
con = new MySqlConnection(constring);
64+
if (con.State == ConnectionState.Closed)
65+
{
66+
con.Open();
67+
}
68+
}
69+
catch(MySqlException e)
70+
{
71+
MessageBox.Show(e.Message.ToString());
72+
}
73+
}
74+
75+
/* Select or search = return a row
76+
*
77+
*/
78+
public MySqlDataReader select(string qry)
79+
{
80+
con = new MySqlConnection(constring);
81+
con.Open();
82+
83+
cmd = new MySqlCommand(qry, con);
84+
reader = cmd.ExecuteReader();
85+
return reader;
86+
}
87+
88+
/* create / update / delete
89+
*
90+
*/
91+
public void cud(string qry, string msg = "Transaction Completed!")
92+
{
93+
con = new MySqlConnection(constring);
94+
con.Open();
95+
96+
cmd = new MySqlCommand(qry, con);
97+
if (cmd.ExecuteNonQuery() > 0)
98+
{
99+
MessageBox.Show(msg);
100+
}
101+
else
102+
{
103+
MessageBox.Show("Sorry! There's something wrong.");
104+
}
105+
}
106+
107+
/* Save
108+
*
109+
*/
110+
public void save(string table, string[] column, string[] bind, string msg = "Successfully saved.")
111+
{
112+
113+
con = new MySqlConnection(constring);
114+
con.Open();
115+
116+
string fields = "";
117+
foreach (string col in column)
118+
{
119+
fields = fields + col + ',';
120+
}
121+
122+
string value = "";
123+
foreach (string val in bind)
124+
{
125+
value = value + "'" + val + "',";
126+
}
127+
128+
var qry = "INSERT INTO " + table + "(" + fields.TrimEnd(',') + ") VALUES(" + value.TrimEnd(',') + ")";
129+
130+
cmd = new MySqlCommand(qry, con);
131+
if (cmd.ExecuteNonQuery() > 0)
132+
{
133+
MessageBox.Show(msg);
134+
}
135+
else
136+
{
137+
MessageBox.Show("Sorry! There's something wrong.");
138+
}
139+
}
140+
141+
/* Datasource / Select Multiple Rows / for DataGridView
142+
*
143+
*/
144+
public void table(string qry, DataGridView dgv, string[] header = null)
145+
{
146+
/*DataGridView Properties*/
147+
dgv.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
148+
dgv.MultiSelect = false;
149+
dgv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
150+
dgv.EditMode = DataGridViewEditMode.EditProgrammatically;
151+
152+
/*Database*/
153+
con = new MySqlConnection(constring);
154+
con.Open();
155+
156+
da = new MySqlDataAdapter(qry, con);
157+
dt = new DataTable();
158+
da.Fill(dt);
159+
dgv.DataSource = dt;
160+
161+
/*Custom Header*/
162+
if (header != null)
163+
{
164+
foreach (DataGridViewColumn dgvcolumn in dgv.Columns)
165+
{
166+
dgvcolumn.HeaderText = header[dgvcolumn.Index];
167+
}
168+
}
169+
dgv.ClearSelection();
170+
}
171+
172+
/* Select & Display to ComboBox
173+
*
174+
*/
175+
public void list(string qry, ComboBox comboBox)
176+
{
177+
/*ComboBox Properties*/
178+
comboBox.Items.Clear();
179+
comboBox.DropDownStyle = ComboBoxStyle.DropDownList;
180+
181+
con = new MySqlConnection(constring);
182+
con.Open();
183+
184+
cmd = new MySqlCommand(qry, con);
185+
reader = cmd.ExecuteReader();
186+
187+
while (reader.Read())
188+
{
189+
comboBox.Items.Add(reader[0].ToString());
190+
comboBox.AutoCompleteCustomSource.Add(reader[0].ToString());
191+
}
192+
}
193+
194+
/* Check data if exist
195+
* return bool
196+
*/
197+
public bool exist(string qry)
198+
{
199+
con = new MySqlConnection(constring);
200+
con.Open();
201+
202+
cmd = new MySqlCommand(qry, con);
203+
reader = cmd.ExecuteReader();
204+
if (reader.Read())
205+
return true;
206+
else
207+
return false;
208+
}
209+
210+
/* Select the Maximum Inserted Id
211+
* return int (id)
212+
*/
213+
public int maxid(String column, String tbl)
214+
{
215+
con = new MySqlConnection(constring);
216+
con.Open();
217+
218+
var cmd = new MySqlCommand("SELECT MAX(" + column + ") from " + tbl + "", con);
219+
220+
var reader = cmd.ExecuteReader();
221+
if (reader.Read())
222+
{
223+
try
224+
{
225+
return reader.GetInt32(0) + 1;
226+
}
227+
catch (Exception)
228+
{
229+
return 1;
230+
}
231+
}
232+
return 1;
233+
}
234+
235+
}
236+
}

Sample Project/Classes/Form_UI.cs

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
/**
2+
* __________________________________________________________________
3+
*
4+
* C-Sharf Custom Classes
5+
* __________________________________________________________________
6+
*
7+
* MIT License
8+
*
9+
* Copyright (c) 2020 Wilfred V. Pine
10+
*
11+
* Permission is hereby granted, free of charge, to any person obtaining a copy
12+
* of this software and associated documentation files (the "Software"), to deal
13+
* in the Software without restriction, including without limitation the rights
14+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15+
* copies of the Software, and to permit persons to whom the Software is
16+
* furnished to do so, subject to the following conditions:
17+
*
18+
* The above copyright notice and this permission notice shall be included in
19+
* all copies or substantial portions of the Software.
20+
*
21+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27+
* THE SOFTWARE.
28+
*
29+
* @package C-Sharf Custom Classes
30+
* @author Wilfred V. Pine <[email protected]>
31+
* @copyright Copyright 2020 (https://red.confired.com)
32+
* @link https://confired.com
33+
* @license https://opensource.org/licenses/MIT MIT License
34+
*/
35+
36+
using System.Drawing;
37+
using System.Windows.Forms;
38+
39+
namespace Classes
40+
{
41+
class Form_UI
42+
{
43+
#region Default
44+
45+
/* Show next then hide the current
46+
*
47+
*/
48+
public void Show(Form frmNew, Form frmOld)
49+
{
50+
frmNew.Show();
51+
frmOld.Hide();
52+
}
53+
54+
/* Show Form as dialog box (Focus Mode)
55+
*
56+
*/
57+
public void Dialog(Form frm)
58+
{
59+
frm.ShowDialog();
60+
}
61+
62+
#endregion
63+
64+
#region Multiple Document Interface
65+
66+
/* MDI show form
67+
*
68+
*/
69+
public void FormShow(Form frm, string dstyle = "Fill")
70+
{
71+
Form formMain = new Form() { FormBorderStyle = FormBorderStyle.None };
72+
// get the active MDI container
73+
foreach (Form formActive in Application.OpenForms)
74+
{
75+
if(formActive.IsMdiContainer == true)
76+
{
77+
formMain = formActive;
78+
}
79+
}
80+
// close active child form
81+
try
82+
{
83+
Form fr = new Form() { FormBorderStyle = FormBorderStyle.None };
84+
85+
fr.MdiParent = formMain;
86+
fr.Dock = DockStyle.Fill;
87+
fr.Show();
88+
foreach (Form child in formMain.MdiChildren)
89+
{
90+
child.Close();
91+
}
92+
}
93+
catch { }
94+
95+
// show child form
96+
frm.MdiParent = formMain;
97+
switch (dstyle)
98+
{
99+
case "Fill":
100+
frm.Dock = DockStyle.Fill;
101+
break;
102+
case "Top":
103+
frm.Dock = DockStyle.Top;
104+
break;
105+
case "Right":
106+
frm.Dock = DockStyle.Right;
107+
break;
108+
case "Bottom":
109+
frm.Dock = DockStyle.Bottom;
110+
break;
111+
case "Left":
112+
frm.Dock = DockStyle.Left;
113+
break;
114+
default:
115+
frm.Dock = DockStyle.None;
116+
break;
117+
}
118+
frm.Show();
119+
}
120+
121+
/* MDI active menu
122+
*
123+
*/
124+
public void active(string form, Button btn, Color col, Button[] menu, Color def_color)
125+
{
126+
// reset backcolor of menu
127+
foreach (Button button in menu)
128+
{
129+
button.BackColor = def_color;
130+
}
131+
132+
Form formMain = new Form() { FormBorderStyle = FormBorderStyle.None };
133+
134+
// get the active MDI form
135+
foreach (Form formActive in Application.OpenForms)
136+
{
137+
if (formActive.IsMdiContainer == true)
138+
{
139+
formMain = formActive;
140+
}
141+
}
142+
143+
// change backcolor of active menu
144+
foreach (Form child in formMain.MdiChildren)
145+
{
146+
if (child.Name.ToString() == form)
147+
{
148+
btn.BackColor = col;
149+
}
150+
}
151+
152+
153+
}
154+
155+
#endregion
156+
}
157+
}

0 commit comments

Comments
 (0)