GithubHelp home page GithubHelp logo

bubdm / csharpmvc Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hsnmtw/csharpmvc

0.0 0.0 0.0 2.97 MB

Building a simple WinForms MVC .net framework that simplify the process of building applications

C# 98.65% ASP 1.35%

csharpmvc's Introduction

csharpmvc

Building a simple WinForms MVC .net framework that simplify the process of building applications This application is built with the following considerations:

  1. Models have properties only
  2. Views have no logic, but data display and presentation only
  3. Controllers perform validation on models before passing them to Entities, also perform complex logic and acts as middle person between entities and views
  4. Entities define metadata of models and connects to the database, execute and runs queries
  5. Database type invariant

Dependencies

     [C]  
   ↗  ↓  ↘ 
[V] →[M]← [E] → [F] 
           ↓
		  [D] 
 
V: Views
M: Models
C: Controllers
E: Entities + Validation
D: Database
F: Fluent Validation (3rd party library)

** The goal is to have [V] on right side ** and all others depend on [M] ** [V] should not communicate directly to [E]

Example code

  
  // Model
  public class ExampleModel : BaseModel{
    public string ExampleProperty {get; set;}
  }
  
  //Entity
  public class ExampleEntity : AbstractDBEntity<ExampleModel> {
         public override MetaData MetaData => new MetaData() {
              PrimaryKeyField  = "Id" 
            , Fields           = new HashSet<string> { "ReadOnly","Id","CreatedBy","CreatedOn",
                                                       "UpdatedBy","UpdatedOn", "ExampleProperty" }  
            , RequiredFields   = new HashSet<string> { "Id", "ExampleProperty" }
            , UniqueKeyFields  = new HashSet<HashSet<string>> { new HashSet<string> { "ExampleProperty" } }
            , ForeignKeys      = new Dictionary<string, Tuple<string, string>> {
            }
            , Sizes            = new Dictionary<string, int> {
                ["CreatedBy"       ] = 50,
                ["UpdatedBy"       ] = 50,
                ["ExampleProperty" ] = 25,
            }
            , Source           = "ExampleTable"

        };
    }
  }
 
  //Controller
  public class ExampleController : AbstractDBController<ExampleModel> {
  }
  
  //View
  public class ExampleView : BaseView<ExampleModel, ExampleController> {  
     private Label   lblExampleProperty;
     private TextBox txtExampleProperty;
     private Button  btnSave, btnDelete, btnNew;
     
     public void InitializeComponent(){
        lblExampleProperty = new Label()  { Text = "Example:" , Left = 10, Top = 10 };
        txtExampleProperty = new TextBox(){ Text = ""         , Left = 10, Top = 30 };
        btnDelete = new Button()          { Text = "Delete"   , Left = 10, Top = 55 };
        btnSave   = new Button()          { Text = "Save"     , Left = 10, Top = 75 };
        btnNew    = new Button()          { Text = "New"      , Left = 10, Top = 95 };        
        Controls.AddRange(new Control[]{ txtExampleProperty,btnDelete, btnNew, btnSave });
     }
     
     public ExampleView(){
        InitializeComponent();
        
        Mapper["ExampleProperty"] = txtExampleProperty;  // this will bind textbox to model value
        
        //define actions
        SaveButton   = btnSave;                          
        DeleteButton = btnDelete;                        
        NewButton    = btnNew;
     }
  }
  
  //Main view
  public class MainView{
    public static void Main(){
        var form = new Form(){ Width = 400, Height = 400 };
        form.Controls.Add(new ExampleView(){ Dock = DockStyle.Fill });
        Application.EnableVisualStyles();
        Application.Run(form);
    }
  }
  

csharpmvc's People

Contributors

hsnmtw avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.