{"id":14986400,"url":"https://github.com/wilfredpine/csharp-custom-classes","last_synced_at":"2026-03-14T23:38:37.630Z","repository":{"id":153315490,"uuid":"339276179","full_name":"wilfredpine/csharp-custom-classes","owner":"wilfredpine","description":"C# custom classes for .Net Windows Form Application inspired by MVP architecture.","archived":false,"fork":false,"pushed_at":"2024-11-13T08:53:58.000Z","size":3481,"stargazers_count":34,"open_issues_count":0,"forks_count":28,"subscribers_count":10,"default_branch":"main","last_synced_at":"2025-05-06T21:37:17.369Z","etag":null,"topics":["c-sharp","class","classes","classes-and-objects","csharp","dotnet","event-driven-programming","mvp","mysql","object-oriented-programming","oop","reusable-code","sql","windows-application","windows-desktop","windows-forms"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wilfredpine.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-02-16T03:38:11.000Z","updated_at":"2024-11-19T15:33:57.000Z","dependencies_parsed_at":null,"dependency_job_id":"cb1441e6-fe14-4d52-b3a6-970f68dde777","html_url":"https://github.com/wilfredpine/csharp-custom-classes","commit_stats":{"total_commits":36,"total_committers":2,"mean_commits":18.0,"dds":"0.33333333333333337","last_synced_commit":"4bc4e1680bfc220e7433f54e38cf4a5bb6f66835"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/wilfredpine/csharp-custom-classes","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wilfredpine%2Fcsharp-custom-classes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wilfredpine%2Fcsharp-custom-classes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wilfredpine%2Fcsharp-custom-classes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wilfredpine%2Fcsharp-custom-classes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wilfredpine","download_url":"https://codeload.github.com/wilfredpine/csharp-custom-classes/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wilfredpine%2Fcsharp-custom-classes/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273987977,"owners_count":25202987,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-07T02:00:09.463Z","response_time":67,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c-sharp","class","classes","classes-and-objects","csharp","dotnet","event-driven-programming","mvp","mysql","object-oriented-programming","oop","reusable-code","sql","windows-application","windows-desktop","windows-forms"],"created_at":"2024-09-24T14:12:49.021Z","updated_at":"2026-03-14T23:38:32.607Z","avatar_url":"https://github.com/wilfredpine.png","language":"C#","readme":"# CSharf Custom Classes\n\nCustom [Classes](https://github.com/wilfredpine/csharp-custom-classes/tree/main/Classes) for Windows Form Application using C# in Object-Oriented Programming and Event-Driven approach Developed by Wilfred V. Pine\n@2020\n\n\n- You are free to contribute in this project library :)\n\n\n[MIT License](https://github.com/wilfredpine/CSharf-Custom-Classes/blob/main/LICENSE)\n\n## [Classes](https://github.com/wilfredpine/csharp-custom-classes/tree/main/Classes)\n\n## How to use?\n1. Download the [Classes](https://github.com/wilfredpine/csharp-custom-classes/tree/main/Classes) folder \n2. Create a Windows Form Application project for .Net Framework Desktop Application.\n3. In your Solution Explorer, right click on your project and add a folder named \"`Classes`\"\n4. Then right click on your created \"`Classes`\" folder and add existing item. Browse the classes that you downloaded from step 1.\n5. From your project folder root directory (in oyur Solution Explorer), create a class named \" [Config](https://github.com/wilfredpine/csharp-custom-classes/blob/main/Config.cs) \" and create a public instance of all the classes from [Classes](https://github.com/wilfredpine/csharp-custom-classes/tree/main/Classes) folder. See the code below:\n```c#\n    using Classes; // include the \"Classes\" folder\n    namespace MySampleProject\n    {\n        class Config\n        {\n            /*\n            * Database Information\n            */\n                private static string host = \"localhost\";\n                private static string dbname = \"dbinformation\";\n                private static string dbuser = \"root\";\n                private static string dbpassword = \"\";\n            /*\n            * Classes\n            */\n                public Database db;\n                public Validation validate;\n                public Form_UI ui;\n                public Visualizer visualizer;\n                public Str_Date_Time date_time;\n                public Upload upload;\n            /*\n            * Constructor\n            */\n                public Config()\n                {\n                    this.db = new Database(host, dbuser, dbpassword, dbname);\n                    this.validate = new Validation();\n                    this.ui = new Form_UI();\n                    this.visualizer = new Visualizer();\n                    this.date_time = new Str_Date_Time();\n                    this.upload = new Upload();\n                }\n        }\n    }\n```\n6. To your Form (example; FormLogin), create an instance of your [Config](https://github.com/wilfredpine/csharp-custom-classes/blob/main/Config.cs) class.\n```c#\n    public partial class FormLogin : Form\n    {\n        Config config = new Config(); // your Config class\n\n        public FormLogin()\n        {\n            InitializeComponent();\n        }\n```\n7. You can now use [Database](https://github.com/wilfredpine/csharp-custom-classes/blob/main/Classes/Database.cs) , [Validation](https://github.com/wilfredpine/csharp-custom-classes/blob/main/Classes/Validation.cs) , [Visualizer](https://github.com/wilfredpine/csharp-custom-classes/blob/main/Classes/Visualizer.cs) , [Upload](https://github.com/wilfredpine/csharp-custom-classes/blob/main/Classes/Upload.cs) , [Date_Time](https://github.com/wilfredpine/csharp-custom-classes/blob/main/Classes/Str_Date_Time.cs) , \u0026 [Form_UI](https://github.com/wilfredpine/csharp-custom-classes/blob/main/Classes/Form_UI.cs) Class.\n```c#\n    config.db.....\n    config.validate......\n    config.ui......\n    config.visualizer.....\n    config.date_time.....\n    config.upload.......\n```\n\n\n## 1. Using [Database](https://github.com/wilfredpine/csharp-custom-classes/blob/main/Classes/Database.cs) class - this is use for MySqlClient configurations, sql statements, \u0026 etc. This will also included the loading of data to a form control including dataGridView and comboBox.\n\n#### Requirements\n* MySql Server ([Wamp Server](https://wampserver.aviatechno.net/?lang=es\u0026prerequis=afficher))\n* Install [MySql Connector .Net](https://dev.mysql.com/downloads/connector/net/)\n* After you installed MySQL Connector .Net, go to `C:\\Program Files (x86)\\MySQL\\MySQL Connector Net 8.0.27\\Assemblies\\v4.5.2\\` and use the `MySql.Data.dll` as a reference for your project. \n    Note: `\\v4.5.2\\` is the .Net version of your project, you can use other version inside `C:\\Program Files (x86)\\MySQL\\MySQL Connector Net 8.0.27\\Assemblies\\` folder.\n* \u0026 Now you can use MySQLClient, Good Luck!\n\n#####   tips: how to add reference for your project?\n* On your solution explorer (on your project references), right click and choose add References, then browse the library you want to add (e.g. `C:\\Program Files (x86)\\MySQL\\MySQL Connector Net 8.0.27\\Assemblies\\v4.5.2\\MySql.Data.dll`)\n\n\n\n#### Using Database' Methods\n\nSql Statements\n\n* `select(string qry)` 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.\n\n```c#\nvar reader = config.db.select(\"select * from users\");\nwhile (reader.Read())\n{\n    //reader[\"userid\"].ToString();\n}\n```\n\n* `save(string table, string[] column, string[] bind, string msg = \"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. \n\nThe `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.\n\n```c#\nstring[] column = { \"username\", \"password\", \"sex\" };\nstring[] value = { txtUsername.Text, txtPassword.Text, cmbSex.Text };\nconfig.db.save(\"users\", column, value); // config.db.save(\"users\", column, value, \"User successfully saved!\");\n```\n\n* `cud(string qry, string msg = \"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.\n\n```c#\nconfig.db.cud(\"Sql Query Here\",\"Custom Notification Message\");\n//or\nconfig.db.cud(\"Sql Query Here\");\n```\n\nExample:\n```c#\nconfig.db.cud(\"INSERT INTO users (username,password,sex) VALUES ('\" + txtUsername.Text + \"','\" + txtPassword.Text + \"','\" + cmbSex.Text + \"')\",\"User successfully saved!\");\n```\n\n\n* `table(string qry, DataGridView dgv, string[] header = null)` or table() method is use for displaying data to a DataGridView Control using the DataSource properties.\n\nThe `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.\n\n```c#\n//using custom header\nstring[] customheader = { \"User ID\", \"Username\", \"Gender\" };\n//the table methods\nconfig.db.table(\"select userid,username,sex from users\", dgvUsers, customheader); // dgvUsers is the name of your datagridview\n```\n\n```c#\n//the table methods without custom header\nconfig.db.table(\"select userid,username,sex from users\", dgvUsers);\n```\n\n* `list(string qry, ComboBox comboBox)` or list() method is use to display data to your comboBox control as an items.\n\n```c#\nconfig.db.list(\"select course_name from courses\", cmbCourse); // cmbCourse is the name of your comboBox control\n```\n\n* `exist(string qry)` or exist() method is use to validate if a data is existing in your database. It will return `true` if exist.\n```c#\nif(config.db.exist(\"select username from courses where username = '\"+ txtusername.Text +\"'\"))\n{\n    MessageBox.Show(\"Username already exist!\");\n}else{\n    // save\n}\n```\n\n* `maxid(String column, String tbl)` or maxid() method is use to get the last inserted `id` in your database. The column parameter is the name of the column you want to select, and the tbl parameter is your table name.\n\n```c#\nint id = config.db.maxid('userid', 'users'); // it will return an int value\n```\n\n\n\n\n## 2. Using [Form_UI](https://github.com/wilfredpine/csharp-custom-classes/blob/main/Classes/Form_UI.cs) class - \n\nThis class includes the traditional way of displaying form. Also includes the advanced UI manipulation using MDI or Multiple Document Interface.\n\n#### The Basic :\n\n* `Show(Form frmNew, Form frmOld)` or Show() method is simply use for displaying new Form and hiding active Form. \n - Behind the methods: `frmain.Show();` `this.Hide();`\n```c#\nfrmMain frmain = new frmMain();\nconfig.ui.Show(frmain, this); // or config.ui.Show(new frmMain());\n```\n\n* `Dialog(Form frm)` or Dialog() methods use for displaying Form as Dialog.\n\n```c#\nfrmMain frmain = new frmMain();\nconfig.ui.Dialog(frmain); // or config.ui.Show(new frmMain());\n```\n#### The MDI :\n\n* `FormShow(Form frm, string dstyle = \"Fill\")` or FormShow() methods is use for displaying form child to your MdiParent Form.\n\nInstantiate an object `dash` of a form `frmDashboard`.\n```c#\nfrmDashboard dash = new frmDashboard();\n```\nPassing 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`.\n```c#\nconfig.ui.FormShow(dash, \"Top\");\n```\n\n```c#\n// Fill\nfrmDashboard dash = new frmDashboard();\nconfig.ui.FormShow(dash); // or config.ui.FormShow(new frmDashboard());\n```\n\n\n\n## 3. Using [Visualizer](https://github.com/wilfredpine/csharp-custom-classes/blob/main/Classes/Visualizer.cs) class - use for visualization of data.\n\n* `chart(Chart chart, string SeriesName, string[] x, int[] y, string chartType = \"Column\")` or chart() method\n\nThe `chart` parameter is the name of your Chart Control. You can add a Serries by passing to `SeriesName` parameter and AddXY using `x` and `y` parameter. `x` is the legend, name or label of every data you want to display while `y` is the number value or count.\n\nExample: \n\n```c#\nvoid loadChartSample()\n{\n    /*\n    * SERIES 'MALE'\n    */\n    // Array Legend\n    string[] X = { \"BSIT\", \"BSED\", \"AB\" };\n    // Array Value\n    int[] Y = { 12, 14, 9 };\n    // Pass to Chart Methods = Male Series\n    config.visualizer.chart(chartUser, \"Male\", X, Y, \"Pie\");\n    //_________________________________________________________________________________\n    /*\n    * NEW SERIES 'FEMALE'\n    */\n    string[] x2 = { \"BSIT\", \"BSED\", \"AB\" };\n    int[] y2 = { 6, 0, 16 };\n    // Female Series\n    config.visualizer.chart(chartUser, \"Female\", x2, y2, \"Pie\");\n}\n```\n\nHow to add an item to array?\n\n```c#\nstring[] X = { \"BSIT\", \"BSED\" };\n// Add 1 item to array X\nX = X.Concat(new string[] { \"AB\" }).ToArray(); \n// The new X is { \"BSIT\", \"BSED\", \"AB\" }\n\nint[] Y = { 12, 14 };\n// Add 1 item to array Y\nY = Y.Concat(new int[] { 2 }).ToArray(); \n// Y = 12, 14, 2\n```\n\n* Chart data from database (Dynamic)\n\n```c#\n/*\n* SERIES 'MALE'\n*/\n//initialized empty array\nstring[] X = {};\nint[] Y = {};\n\nvar reader = db.select(\"select count(*) as c, course from users where sex = 'MALE'\");\nwhile (reader.Read())\n{\n    X = X.Concat(new string[] { reader[\"course\"].ToString() }).ToArray(); // string[] X = { \"BSIT\", \"BSED\", \"AB\" };\n    Y = Y.Concat(new int[] { Int32.Parse(reader[\"c\"].ToString()) }).ToArray(); // int[] Y = { 12, 14, 9 };\n}\n// Chart Methods\n// ChartSeries = \"MALE\"; ChartType = \"Bar\"; // Chart type is optional, the default is column\nconfig.visualizer.chart(chartUser, \"MALE\", X, Y, \"Bar\");\n\n/*\n* SERIES 'FEMALE'\n*/\n//initialized empty array\nstring[] x2 = {};\nint[] y2 = {};\n\nvar reader = db.select(\"select count(*) as c, course from users where sex = 'FEMALE'\");\nwhile (reader.Read())\n{\n    x2 = x2.Concat(new string[] { reader[\"course\"].ToString() }).ToArray(); // string[] x2 = { \"BSIT\", \"BSED\", \"AB\" };\n    y2 = y2.Concat(new int[] { Int32.Parse(reader[\"c\"].ToString()) }).ToArray(); // int[] y2 = { 6, 0, 16 };\n}\n// Chart Methods\n// ChartSeries = \"FEMALE\"; ChartType = \"Bar\"; // Chart type is optional, the default is column\nconfig.visualizer.chart(chartUser, \"FEMALE\", x2, y2, \"Bar\");\n```\n\n\n\n## 4. Using [Validations](https://github.com/wilfredpine/csharp-custom-classes/blob/main/Classes/Validation.cs) class - use for validationg inputs (keyboard events, mouse events, etc.)\n\n\n* The `txtRequired(TextBox[] txt, bool allow_message = false, string msg = \"Please fillup required fields!\")` or txtRequired() method use to validate required textbox controls. There is also validation for comboBox controls, the `cmbRequired(ComboBox[] cmb, bool allow_message = false, string msg = \"Please select required fields!\")` method. These functions return `false` if ther is an empty value in the fields.\n\n```c#\nTextBox[] txt = { txtUsername, txtPassword, txtCPassword };\nComboBox[] cmb = { cmbSex };\nif (!config.validate.txtRequired(txt) || !config.validate.cmbRequired(cmb))\n    return;\n```\n\n* The `alpha(KeyPressEventArgs e)` 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.\n\n```c#\nprivate void txtUsername_KeyPress(object sender, KeyPressEventArgs e)\n{\n    config.validate.alphanum(e);\n}\n```\n\n\n\n## 5. Using [Date_time](https://github.com/wilfredpine/csharp-custom-classes/blob/main/Classes/Str_Date_Time.cs) class - for date \u0026 time format conversion\n\n* \n\n\n## 6. Using [Upload](https://github.com/wilfredpine/csharp-custom-classes/blob/main/Classes/Upload.cs) class - working with files \u0026 directories\n\n* \n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwilfredpine%2Fcsharp-custom-classes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwilfredpine%2Fcsharp-custom-classes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwilfredpine%2Fcsharp-custom-classes/lists"}