├── CRUDWinFormsMVP.sln ├── CRUDWinFormsMVP ├── App.config ├── CRUDWinFormsMVP.csproj ├── Models │ ├── IPetRepository.cs │ └── PetModel.cs ├── Presenters │ ├── Common │ │ └── ModelDataValidation.cs │ ├── MainPresenter.cs │ └── PetPresenter.cs ├── Program.cs ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings ├── Views │ ├── IMainView.cs │ ├── IPetView.cs │ ├── MainView.Designer.cs │ ├── MainView.cs │ ├── MainView.resx │ ├── PetView.Designer.cs │ ├── PetView.cs │ └── PetView.resx ├── _Repositories │ ├── BaseRepository.cs │ └── PetRepository.cs ├── bin │ └── Debug │ │ ├── CRUDWinFormsMVP.exe │ │ ├── CRUDWinFormsMVP.exe.config │ │ └── CRUDWinFormsMVP.pdb └── obj │ └── Debug │ ├── CRUDWinFormsMVP.Properties.Resources.resources │ ├── CRUDWinFormsMVP.Views.MainView.resources │ ├── CRUDWinFormsMVP.Views.PetView.resources │ ├── CRUDWinFormsMVP.csproj.AssemblyReference.cache │ ├── CRUDWinFormsMVP.csproj.CoreCompileInputs.cache │ ├── CRUDWinFormsMVP.csproj.FileListAbsolute.txt │ ├── CRUDWinFormsMVP.csproj.GenerateResource.cache │ ├── CRUDWinFormsMVP.exe │ ├── CRUDWinFormsMVP.pdb │ ├── DesignTimeResolveAssemblyReferences.cache │ └── DesignTimeResolveAssemblyReferencesInput.cache ├── LICENSE ├── README.md └── VeterinaryDb.sql /CRUDWinFormsMVP.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.32228.343 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CRUDWinFormsMVP", "CRUDWinFormsMVP\CRUDWinFormsMVP.csproj", "{7C2F0CD7-CF1B-41F9-A9B9-132EBA642217}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {7C2F0CD7-CF1B-41F9-A9B9-132EBA642217}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {7C2F0CD7-CF1B-41F9-A9B9-132EBA642217}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {7C2F0CD7-CF1B-41F9-A9B9-132EBA642217}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {7C2F0CD7-CF1B-41F9-A9B9-132EBA642217}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {002004AD-BC90-4896-BE4D-D4E254DE3BEC} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /CRUDWinFormsMVP/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /CRUDWinFormsMVP/CRUDWinFormsMVP.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {7C2F0CD7-CF1B-41F9-A9B9-132EBA642217} 8 | WinExe 9 | CRUDWinFormsMVP 10 | CRUDWinFormsMVP 11 | v4.5 12 | 512 13 | true 14 | 15 | 16 | AnyCPU 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | AnyCPU 27 | pdbonly 28 | true 29 | bin\Release\ 30 | TRACE 31 | prompt 32 | 4 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 | Form 61 | 62 | 63 | MainView.cs 64 | 65 | 66 | Form 67 | 68 | 69 | PetView.cs 70 | 71 | 72 | 73 | 74 | ResXFileCodeGenerator 75 | Resources.Designer.cs 76 | Designer 77 | 78 | 79 | True 80 | Resources.resx 81 | 82 | 83 | MainView.cs 84 | 85 | 86 | PetView.cs 87 | 88 | 89 | SettingsSingleFileGenerator 90 | Settings.Designer.cs 91 | 92 | 93 | True 94 | Settings.settings 95 | True 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | -------------------------------------------------------------------------------- /CRUDWinFormsMVP/Models/IPetRepository.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace CRUDWinFormsMVP.Models 8 | { 9 | public interface IPetRepository 10 | { 11 | void Add(PetModel petModel); 12 | void Edit(PetModel petModel); 13 | void Delete(int id); 14 | IEnumerable GetAll(); 15 | IEnumerable GetByValue(string value);//Searchs 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /CRUDWinFormsMVP/Models/PetModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.ComponentModel.DataAnnotations; 7 | using System.ComponentModel; 8 | 9 | namespace CRUDWinFormsMVP.Models 10 | { 11 | public class PetModel 12 | { 13 | //Fields 14 | private int id; 15 | private string name; 16 | private string type; 17 | private string colour; 18 | 19 | //Properties - Validations 20 | [DisplayName("Pet ID")] 21 | public int Id 22 | { 23 | get { return id; } 24 | set { id = value; } 25 | } 26 | 27 | [DisplayName("Pet Name")] 28 | [Required(ErrorMessage ="Pet name is requerid")] 29 | [StringLength(50,MinimumLength =3, ErrorMessage ="Pet name must be between 3 and 50 characters")] 30 | public string Name 31 | { 32 | get { return name; } 33 | set { name = value; } 34 | } 35 | 36 | [DisplayName("Pet Type")] 37 | [Required(ErrorMessage = "Pet type is requerid")] 38 | [StringLength(50, MinimumLength = 3, ErrorMessage = "Pet type must be between 3 and 50 characters")] 39 | public string Type 40 | { 41 | get { return type; } 42 | set { type = value; } 43 | } 44 | 45 | [DisplayName("Pet Colour")] 46 | [Required(ErrorMessage = "Pet colour is requerid")] 47 | [StringLength(50, MinimumLength = 3, ErrorMessage = "Pet colour must be between 3 and 50 characters")] 48 | public string Colour 49 | { 50 | get { return colour; } 51 | set { colour = value; } 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /CRUDWinFormsMVP/Presenters/Common/ModelDataValidation.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.ComponentModel.DataAnnotations; 7 | using System.ComponentModel; 8 | 9 | namespace CRUDWinFormsMVP.Presenters.Common 10 | { 11 | public class ModelDataValidation 12 | { 13 | public void Validate(object model) 14 | { 15 | string errorMessage = ""; 16 | List results = new List(); 17 | ValidationContext context = new ValidationContext(model); 18 | bool isValid = Validator.TryValidateObject(model,context,results,true); 19 | if(isValid==false) 20 | { 21 | foreach (var item in results) 22 | errorMessage += "- " + item.ErrorMessage + "\n"; 23 | throw new Exception(errorMessage); 24 | } 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /CRUDWinFormsMVP/Presenters/MainPresenter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using CRUDWinFormsMVP.Views; 7 | using CRUDWinFormsMVP.Models; 8 | using CRUDWinFormsMVP._Repositories; 9 | using System.Windows.Forms; 10 | 11 | namespace CRUDWinFormsMVP.Presenters 12 | { 13 | public class MainPresenter 14 | { 15 | private IMainView mainView; 16 | private readonly string sqlConnectionString; 17 | 18 | public MainPresenter(IMainView mainView, string sqlConnectionString) 19 | { 20 | this.mainView = mainView; 21 | this.sqlConnectionString = sqlConnectionString; 22 | this.mainView.ShowPetView += ShowPetsView; 23 | } 24 | 25 | private void ShowPetsView(object sender, EventArgs e) 26 | { 27 | IPetView view = PetView.GetInstace((MainView)mainView); 28 | IPetRepository repository = new PetRepository(sqlConnectionString); 29 | new PetPresenter(view, repository); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /CRUDWinFormsMVP/Presenters/PetPresenter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows.Forms; 7 | using CRUDWinFormsMVP.Models; 8 | using CRUDWinFormsMVP.Views; 9 | 10 | namespace CRUDWinFormsMVP.Presenters 11 | { 12 | public class PetPresenter 13 | { 14 | //Fields 15 | private IPetView view; 16 | private IPetRepository repository; 17 | private BindingSource petsBindingSource; 18 | private IEnumerable petList; 19 | 20 | //Constructor 21 | public PetPresenter(IPetView view, IPetRepository repository) 22 | { 23 | this.petsBindingSource = new BindingSource(); 24 | this.view = view; 25 | this.repository = repository; 26 | //Subscribe event handler methods to view events 27 | this.view.SearchEvent += SearchPet; 28 | this.view.AddNewEvent += AddNewPet; 29 | this.view.EditEvent += LoadSelectedPetToEdit; 30 | this.view.DeleteEvent += DeleteSelectedPet; 31 | this.view.SaveEvent += SavePet; 32 | this.view.CancelEvent += CancelAction; 33 | //Set pets bindind source 34 | this.view.SetPetListBindingSource(petsBindingSource); 35 | //Load pet list view 36 | LoadAllPetList(); 37 | //Show view 38 | this.view.Show(); 39 | } 40 | 41 | //Methods 42 | private void LoadAllPetList() 43 | { 44 | petList = repository.GetAll(); 45 | petsBindingSource.DataSource = petList;//Set data source. 46 | } 47 | private void SearchPet(object sender, EventArgs e) 48 | { 49 | bool emptyValue = string.IsNullOrWhiteSpace(this.view.SearchValue); 50 | if (emptyValue == false) 51 | petList = repository.GetByValue(this.view.SearchValue); 52 | else petList = repository.GetAll(); 53 | petsBindingSource.DataSource = petList; 54 | } 55 | private void AddNewPet(object sender, EventArgs e) 56 | { 57 | view.IsEdit = false; 58 | } 59 | private void LoadSelectedPetToEdit(object sender, EventArgs e) 60 | { 61 | var pet = (PetModel)petsBindingSource.Current; 62 | view.PetId = pet.Id.ToString(); 63 | view.PetName = pet.Name; 64 | view.PetType = pet.Type; 65 | view.PetColour = pet.Colour; 66 | view.IsEdit = true; 67 | } 68 | private void SavePet(object sender, EventArgs e) 69 | { 70 | var model = new PetModel(); 71 | model.Id = Convert.ToInt32(view.PetId); 72 | model.Name = view.PetName; 73 | model.Type = view.PetType; 74 | model.Colour = view.PetColour; 75 | try 76 | { 77 | new Common.ModelDataValidation().Validate(model); 78 | if(view.IsEdit)//Edit model 79 | { 80 | repository.Edit(model); 81 | view.Message = "Pet edited successfuly"; 82 | } 83 | else //Add new model 84 | { 85 | repository.Add(model); 86 | view.Message = "Pet added sucessfully"; 87 | } 88 | view.IsSuccessful = true; 89 | LoadAllPetList(); 90 | CleanviewFields(); 91 | } 92 | catch (Exception ex) 93 | { 94 | view.IsSuccessful = false; 95 | view.Message = ex.Message; 96 | } 97 | } 98 | 99 | private void CleanviewFields() 100 | { 101 | view.PetId = "0"; 102 | view.PetName = ""; 103 | view.PetType = ""; 104 | view.PetColour = ""; 105 | } 106 | 107 | private void CancelAction(object sender, EventArgs e) 108 | { 109 | CleanviewFields(); 110 | } 111 | private void DeleteSelectedPet(object sender, EventArgs e) 112 | { 113 | try 114 | { 115 | var pet = (PetModel)petsBindingSource.Current; 116 | repository.Delete(pet.Id); 117 | view.IsSuccessful = true; 118 | view.Message = "Pet deleted successfully"; 119 | LoadAllPetList(); 120 | } 121 | catch (Exception ex) 122 | { 123 | view.IsSuccessful = false; 124 | view.Message = "An error ocurred, could not delete pet"; 125 | } 126 | } 127 | 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /CRUDWinFormsMVP/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using System.Windows.Forms; 6 | using CRUDWinFormsMVP.Models; 7 | using CRUDWinFormsMVP.Presenters; 8 | using CRUDWinFormsMVP._Repositories; 9 | using CRUDWinFormsMVP.Views; 10 | using System.Configuration; 11 | 12 | namespace CRUDWinFormsMVP 13 | { 14 | static class Program 15 | { 16 | /// 17 | /// The main entry point for the application. 18 | /// 19 | [STAThread] 20 | static void Main() 21 | { 22 | Application.EnableVisualStyles(); 23 | Application.SetCompatibleTextRenderingDefault(false); 24 | string sqlConnectionString = ConfigurationManager.ConnectionStrings["SqlConnection"].ConnectionString; 25 | IMainView view = new MainView(); 26 | new MainPresenter(view,sqlConnectionString); 27 | Application.Run((Form)view); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /CRUDWinFormsMVP/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("CRUDWinFormsMVP")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("CRUDWinFormsMVP")] 13 | [assembly: AssemblyCopyright("Copyright © 2022")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("7c2f0cd7-cf1b-41f9-a9b9-132eba642217")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /CRUDWinFormsMVP/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | 12 | namespace CRUDWinFormsMVP.Properties 13 | { 14 | /// 15 | /// A strongly-typed resource class, for looking up localized strings, etc. 16 | /// 17 | // This class was auto-generated by the StronglyTypedResourceBuilder 18 | // class via a tool like ResGen or Visual Studio. 19 | // To add or remove a member, edit your .ResX file then rerun ResGen 20 | // with the /str option, or rebuild your VS project. 21 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 22 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 23 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 24 | internal class Resources 25 | { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() 33 | { 34 | } 35 | 36 | /// 37 | /// Returns the cached ResourceManager instance used by this class. 38 | /// 39 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 40 | internal static global::System.Resources.ResourceManager ResourceManager 41 | { 42 | get 43 | { 44 | if ((resourceMan == null)) 45 | { 46 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("CRUDWinFormsMVP.Properties.Resources", typeof(Resources).Assembly); 47 | resourceMan = temp; 48 | } 49 | return resourceMan; 50 | } 51 | } 52 | 53 | /// 54 | /// Overrides the current thread's CurrentUICulture property for all 55 | /// resource lookups using this strongly typed resource class. 56 | /// 57 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 58 | internal static global::System.Globalization.CultureInfo Culture 59 | { 60 | get 61 | { 62 | return resourceCulture; 63 | } 64 | set 65 | { 66 | resourceCulture = value; 67 | } 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /CRUDWinFormsMVP/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 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 | text/microsoft-resx 107 | 108 | 109 | 2.0 110 | 111 | 112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 113 | 114 | 115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | -------------------------------------------------------------------------------- /CRUDWinFormsMVP/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace CRUDWinFormsMVP.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.10.0.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | 26 | [global::System.Configuration.ApplicationScopedSettingAttribute()] 27 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 28 | [global::System.Configuration.SpecialSettingAttribute(global::System.Configuration.SpecialSetting.ConnectionString)] 29 | [global::System.Configuration.DefaultSettingValueAttribute("Data Source=(local);Initial Catalog=VeterinaryDb;Integrated Security=True")] 30 | public string SqlConnection { 31 | get { 32 | return ((string)(this["SqlConnection"])); 33 | } 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /CRUDWinFormsMVP/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | <?xml version="1.0" encoding="utf-16"?> 7 | <SerializableConnectionString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 8 | <ConnectionString>Data Source=(local);Initial Catalog=VeterinaryDb;Integrated Security=True</ConnectionString> 9 | <ProviderName>System.Data.SqlClient</ProviderName> 10 | </SerializableConnectionString> 11 | Data Source=(local);Initial Catalog=VeterinaryDb;Integrated Security=True 12 | 13 | 14 | -------------------------------------------------------------------------------- /CRUDWinFormsMVP/Views/IMainView.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace CRUDWinFormsMVP.Views 8 | { 9 | public interface IMainView 10 | { 11 | event EventHandler ShowPetView; 12 | event EventHandler ShowOwnerView; 13 | event EventHandler ShowVetsView; 14 | 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /CRUDWinFormsMVP/Views/IPetView.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows.Forms; 7 | 8 | namespace CRUDWinFormsMVP.Views 9 | { 10 | public interface IPetView 11 | { 12 | //Properties - Fields 13 | string PetId { get; set; } 14 | string PetName { get; set; } 15 | string PetType { get; set; } 16 | string PetColour { get; set; } 17 | 18 | string SearchValue { get; set; } 19 | bool IsEdit { get; set; } 20 | bool IsSuccessful { get; set; } 21 | string Message { get; set; } 22 | 23 | //Events 24 | event EventHandler SearchEvent; 25 | event EventHandler AddNewEvent; 26 | event EventHandler EditEvent; 27 | event EventHandler DeleteEvent; 28 | event EventHandler SaveEvent; 29 | event EventHandler CancelEvent; 30 | 31 | //Methods 32 | void SetPetListBindingSource(BindingSource petList); 33 | void Show();//Optional 34 | 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /CRUDWinFormsMVP/Views/MainView.Designer.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace CRUDWinFormsMVP.Views 3 | { 4 | partial class MainView 5 | { 6 | /// 7 | /// Required designer variable. 8 | /// 9 | private System.ComponentModel.IContainer components = null; 10 | 11 | /// 12 | /// Clean up any resources being used. 13 | /// 14 | /// true if managed resources should be disposed; otherwise, false. 15 | protected override void Dispose(bool disposing) 16 | { 17 | if (disposing && (components != null)) 18 | { 19 | components.Dispose(); 20 | } 21 | base.Dispose(disposing); 22 | } 23 | 24 | #region Windows Form Designer generated code 25 | 26 | /// 27 | /// Required method for Designer support - do not modify 28 | /// the contents of this method with the code editor. 29 | /// 30 | private void InitializeComponent() 31 | { 32 | this.panel1 = new System.Windows.Forms.Panel(); 33 | this.btnPets = new System.Windows.Forms.Button(); 34 | this.panel1.SuspendLayout(); 35 | this.SuspendLayout(); 36 | // 37 | // panel1 38 | // 39 | this.panel1.Controls.Add(this.btnPets); 40 | this.panel1.Dock = System.Windows.Forms.DockStyle.Left; 41 | this.panel1.Location = new System.Drawing.Point(0, 0); 42 | this.panel1.Name = "panel1"; 43 | this.panel1.Size = new System.Drawing.Size(200, 565); 44 | this.panel1.TabIndex = 0; 45 | // 46 | // btnPets 47 | // 48 | this.btnPets.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 49 | this.btnPets.Location = new System.Drawing.Point(3, 54); 50 | this.btnPets.Name = "btnPets"; 51 | this.btnPets.Size = new System.Drawing.Size(197, 37); 52 | this.btnPets.TabIndex = 0; 53 | this.btnPets.Text = "Pets"; 54 | this.btnPets.UseVisualStyleBackColor = true; 55 | // 56 | // MainView 57 | // 58 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 59 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 60 | this.ClientSize = new System.Drawing.Size(1213, 565); 61 | this.Controls.Add(this.panel1); 62 | this.IsMdiContainer = true; 63 | this.Name = "MainView"; 64 | this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; 65 | this.Text = "MainView"; 66 | this.panel1.ResumeLayout(false); 67 | this.ResumeLayout(false); 68 | 69 | } 70 | 71 | #endregion 72 | 73 | private System.Windows.Forms.Panel panel1; 74 | private System.Windows.Forms.Button btnPets; 75 | } 76 | } -------------------------------------------------------------------------------- /CRUDWinFormsMVP/Views/MainView.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Data; 5 | using System.Drawing; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | using System.Windows.Forms; 10 | 11 | namespace CRUDWinFormsMVP.Views 12 | { 13 | public partial class MainView : Form, IMainView 14 | { 15 | public MainView() 16 | { 17 | InitializeComponent(); 18 | btnPets.Click += delegate { ShowPetView?.Invoke(this, EventArgs.Empty); }; 19 | } 20 | 21 | public event EventHandler ShowPetView; 22 | public event EventHandler ShowOwnerView; 23 | public event EventHandler ShowVetsView; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /CRUDWinFormsMVP/Views/MainView.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 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 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | -------------------------------------------------------------------------------- /CRUDWinFormsMVP/Views/PetView.Designer.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace CRUDWinFormsMVP.Views 3 | { 4 | partial class PetView 5 | { 6 | /// 7 | /// Required designer variable. 8 | /// 9 | private System.ComponentModel.IContainer components = null; 10 | 11 | /// 12 | /// Clean up any resources being used. 13 | /// 14 | /// true if managed resources should be disposed; otherwise, false. 15 | protected override void Dispose(bool disposing) 16 | { 17 | if (disposing && (components != null)) 18 | { 19 | components.Dispose(); 20 | } 21 | base.Dispose(disposing); 22 | } 23 | 24 | #region Windows Form Designer generated code 25 | 26 | /// 27 | /// Required method for Designer support - do not modify 28 | /// the contents of this method with the code editor. 29 | /// 30 | private void InitializeComponent() 31 | { 32 | this.label1 = new System.Windows.Forms.Label(); 33 | this.panel1 = new System.Windows.Forms.Panel(); 34 | this.btnClose = new System.Windows.Forms.Button(); 35 | this.tabControl1 = new System.Windows.Forms.TabControl(); 36 | this.tabPagePetList = new System.Windows.Forms.TabPage(); 37 | this.dataGridView = new System.Windows.Forms.DataGridView(); 38 | this.label2 = new System.Windows.Forms.Label(); 39 | this.btnDelete = new System.Windows.Forms.Button(); 40 | this.btnEdit = new System.Windows.Forms.Button(); 41 | this.btnAddNew = new System.Windows.Forms.Button(); 42 | this.btnSearch = new System.Windows.Forms.Button(); 43 | this.txtSearch = new System.Windows.Forms.TextBox(); 44 | this.tabPagePetDetail = new System.Windows.Forms.TabPage(); 45 | this.btnCancel = new System.Windows.Forms.Button(); 46 | this.btnSave = new System.Windows.Forms.Button(); 47 | this.label6 = new System.Windows.Forms.Label(); 48 | this.txtPetColour = new System.Windows.Forms.TextBox(); 49 | this.label5 = new System.Windows.Forms.Label(); 50 | this.txtPetType = new System.Windows.Forms.TextBox(); 51 | this.label4 = new System.Windows.Forms.Label(); 52 | this.txtPetName = new System.Windows.Forms.TextBox(); 53 | this.label3 = new System.Windows.Forms.Label(); 54 | this.txtPetId = new System.Windows.Forms.TextBox(); 55 | this.panel1.SuspendLayout(); 56 | this.tabControl1.SuspendLayout(); 57 | this.tabPagePetList.SuspendLayout(); 58 | ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); 59 | this.tabPagePetDetail.SuspendLayout(); 60 | this.SuspendLayout(); 61 | // 62 | // label1 63 | // 64 | this.label1.AutoSize = true; 65 | this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 66 | this.label1.Location = new System.Drawing.Point(53, 17); 67 | this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); 68 | this.label1.Name = "label1"; 69 | this.label1.Size = new System.Drawing.Size(65, 25); 70 | this.label1.TabIndex = 0; 71 | this.label1.Text = "PETS"; 72 | // 73 | // panel1 74 | // 75 | this.panel1.BackColor = System.Drawing.Color.White; 76 | this.panel1.Controls.Add(this.btnClose); 77 | this.panel1.Controls.Add(this.label1); 78 | this.panel1.Dock = System.Windows.Forms.DockStyle.Top; 79 | this.panel1.Location = new System.Drawing.Point(0, 0); 80 | this.panel1.Name = "panel1"; 81 | this.panel1.Size = new System.Drawing.Size(892, 56); 82 | this.panel1.TabIndex = 1; 83 | // 84 | // btnClose 85 | // 86 | this.btnClose.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); 87 | this.btnClose.Location = new System.Drawing.Point(851, 12); 88 | this.btnClose.Name = "btnClose"; 89 | this.btnClose.Size = new System.Drawing.Size(37, 30); 90 | this.btnClose.TabIndex = 8; 91 | this.btnClose.Text = "X"; 92 | this.btnClose.UseVisualStyleBackColor = true; 93 | // 94 | // tabControl1 95 | // 96 | this.tabControl1.Controls.Add(this.tabPagePetList); 97 | this.tabControl1.Controls.Add(this.tabPagePetDetail); 98 | this.tabControl1.Dock = System.Windows.Forms.DockStyle.Fill; 99 | this.tabControl1.Location = new System.Drawing.Point(0, 56); 100 | this.tabControl1.Name = "tabControl1"; 101 | this.tabControl1.SelectedIndex = 0; 102 | this.tabControl1.Size = new System.Drawing.Size(892, 411); 103 | this.tabControl1.TabIndex = 2; 104 | // 105 | // tabPagePetList 106 | // 107 | this.tabPagePetList.Controls.Add(this.dataGridView); 108 | this.tabPagePetList.Controls.Add(this.label2); 109 | this.tabPagePetList.Controls.Add(this.btnDelete); 110 | this.tabPagePetList.Controls.Add(this.btnEdit); 111 | this.tabPagePetList.Controls.Add(this.btnAddNew); 112 | this.tabPagePetList.Controls.Add(this.btnSearch); 113 | this.tabPagePetList.Controls.Add(this.txtSearch); 114 | this.tabPagePetList.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 115 | this.tabPagePetList.Location = new System.Drawing.Point(4, 29); 116 | this.tabPagePetList.Name = "tabPagePetList"; 117 | this.tabPagePetList.Padding = new System.Windows.Forms.Padding(3); 118 | this.tabPagePetList.Size = new System.Drawing.Size(884, 378); 119 | this.tabPagePetList.TabIndex = 0; 120 | this.tabPagePetList.Text = "Pet list"; 121 | this.tabPagePetList.UseVisualStyleBackColor = true; 122 | // 123 | // dataGridView 124 | // 125 | this.dataGridView.AllowUserToAddRows = false; 126 | this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 127 | | System.Windows.Forms.AnchorStyles.Left) 128 | | System.Windows.Forms.AnchorStyles.Right))); 129 | this.dataGridView.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill; 130 | this.dataGridView.BackgroundColor = System.Drawing.Color.Gainsboro; 131 | this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; 132 | this.dataGridView.Location = new System.Drawing.Point(24, 63); 133 | this.dataGridView.Name = "dataGridView"; 134 | this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; 135 | this.dataGridView.Size = new System.Drawing.Size(737, 307); 136 | this.dataGridView.TabIndex = 7; 137 | // 138 | // label2 139 | // 140 | this.label2.AutoSize = true; 141 | this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 142 | this.label2.Location = new System.Drawing.Point(20, 8); 143 | this.label2.Name = "label2"; 144 | this.label2.Size = new System.Drawing.Size(91, 20); 145 | this.label2.TabIndex = 5; 146 | this.label2.Text = "Search pet:"; 147 | // 148 | // btnDelete 149 | // 150 | this.btnDelete.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); 151 | this.btnDelete.Location = new System.Drawing.Point(767, 134); 152 | this.btnDelete.Name = "btnDelete"; 153 | this.btnDelete.Size = new System.Drawing.Size(99, 30); 154 | this.btnDelete.TabIndex = 4; 155 | this.btnDelete.Text = "Delete"; 156 | this.btnDelete.UseVisualStyleBackColor = true; 157 | // 158 | // btnEdit 159 | // 160 | this.btnEdit.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); 161 | this.btnEdit.Location = new System.Drawing.Point(767, 98); 162 | this.btnEdit.Name = "btnEdit"; 163 | this.btnEdit.Size = new System.Drawing.Size(99, 30); 164 | this.btnEdit.TabIndex = 3; 165 | this.btnEdit.Text = "Edit"; 166 | this.btnEdit.UseVisualStyleBackColor = true; 167 | // 168 | // btnAddNew 169 | // 170 | this.btnAddNew.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); 171 | this.btnAddNew.Location = new System.Drawing.Point(767, 62); 172 | this.btnAddNew.Name = "btnAddNew"; 173 | this.btnAddNew.Size = new System.Drawing.Size(99, 30); 174 | this.btnAddNew.TabIndex = 2; 175 | this.btnAddNew.Text = "Add new"; 176 | this.btnAddNew.UseVisualStyleBackColor = true; 177 | // 178 | // btnSearch 179 | // 180 | this.btnSearch.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); 181 | this.btnSearch.Location = new System.Drawing.Point(668, 27); 182 | this.btnSearch.Name = "btnSearch"; 183 | this.btnSearch.Size = new System.Drawing.Size(99, 30); 184 | this.btnSearch.TabIndex = 1; 185 | this.btnSearch.Text = "Search"; 186 | this.btnSearch.UseVisualStyleBackColor = true; 187 | // 188 | // txtSearch 189 | // 190 | this.txtSearch.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 191 | | System.Windows.Forms.AnchorStyles.Right))); 192 | this.txtSearch.Location = new System.Drawing.Point(24, 31); 193 | this.txtSearch.Name = "txtSearch"; 194 | this.txtSearch.Size = new System.Drawing.Size(638, 26); 195 | this.txtSearch.TabIndex = 0; 196 | // 197 | // tabPagePetDetail 198 | // 199 | this.tabPagePetDetail.Controls.Add(this.btnCancel); 200 | this.tabPagePetDetail.Controls.Add(this.btnSave); 201 | this.tabPagePetDetail.Controls.Add(this.label6); 202 | this.tabPagePetDetail.Controls.Add(this.txtPetColour); 203 | this.tabPagePetDetail.Controls.Add(this.label5); 204 | this.tabPagePetDetail.Controls.Add(this.txtPetType); 205 | this.tabPagePetDetail.Controls.Add(this.label4); 206 | this.tabPagePetDetail.Controls.Add(this.txtPetName); 207 | this.tabPagePetDetail.Controls.Add(this.label3); 208 | this.tabPagePetDetail.Controls.Add(this.txtPetId); 209 | this.tabPagePetDetail.Font = new System.Drawing.Font("Microsoft Sans Serif", 14F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 210 | this.tabPagePetDetail.Location = new System.Drawing.Point(4, 29); 211 | this.tabPagePetDetail.Name = "tabPagePetDetail"; 212 | this.tabPagePetDetail.Padding = new System.Windows.Forms.Padding(3); 213 | this.tabPagePetDetail.Size = new System.Drawing.Size(884, 378); 214 | this.tabPagePetDetail.TabIndex = 1; 215 | this.tabPagePetDetail.Text = "Pet detail"; 216 | this.tabPagePetDetail.UseVisualStyleBackColor = true; 217 | // 218 | // btnCancel 219 | // 220 | this.btnCancel.Location = new System.Drawing.Point(260, 247); 221 | this.btnCancel.Name = "btnCancel"; 222 | this.btnCancel.Size = new System.Drawing.Size(183, 44); 223 | this.btnCancel.TabIndex = 15; 224 | this.btnCancel.Text = "Cancel"; 225 | this.btnCancel.UseVisualStyleBackColor = true; 226 | // 227 | // btnSave 228 | // 229 | this.btnSave.Location = new System.Drawing.Point(63, 247); 230 | this.btnSave.Name = "btnSave"; 231 | this.btnSave.Size = new System.Drawing.Size(183, 44); 232 | this.btnSave.TabIndex = 14; 233 | this.btnSave.Text = "Save"; 234 | this.btnSave.UseVisualStyleBackColor = true; 235 | // 236 | // label6 237 | // 238 | this.label6.AutoSize = true; 239 | this.label6.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 240 | this.label6.Location = new System.Drawing.Point(59, 175); 241 | this.label6.Name = "label6"; 242 | this.label6.Size = new System.Drawing.Size(84, 20); 243 | this.label6.TabIndex = 13; 244 | this.label6.Text = "Pet colour:"; 245 | // 246 | // txtPetColour 247 | // 248 | this.txtPetColour.Location = new System.Drawing.Point(63, 198); 249 | this.txtPetColour.Name = "txtPetColour"; 250 | this.txtPetColour.Size = new System.Drawing.Size(380, 29); 251 | this.txtPetColour.TabIndex = 12; 252 | // 253 | // label5 254 | // 255 | this.label5.AutoSize = true; 256 | this.label5.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 257 | this.label5.Location = new System.Drawing.Point(256, 102); 258 | this.label5.Name = "label5"; 259 | this.label5.Size = new System.Drawing.Size(71, 20); 260 | this.label5.TabIndex = 11; 261 | this.label5.Text = "Pet type:"; 262 | // 263 | // txtPetType 264 | // 265 | this.txtPetType.Location = new System.Drawing.Point(260, 125); 266 | this.txtPetType.Name = "txtPetType"; 267 | this.txtPetType.Size = new System.Drawing.Size(183, 29); 268 | this.txtPetType.TabIndex = 10; 269 | // 270 | // label4 271 | // 272 | this.label4.AutoSize = true; 273 | this.label4.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 274 | this.label4.Location = new System.Drawing.Point(59, 102); 275 | this.label4.Name = "label4"; 276 | this.label4.Size = new System.Drawing.Size(81, 20); 277 | this.label4.TabIndex = 9; 278 | this.label4.Text = "Pet name:"; 279 | // 280 | // txtPetName 281 | // 282 | this.txtPetName.Location = new System.Drawing.Point(63, 125); 283 | this.txtPetName.Name = "txtPetName"; 284 | this.txtPetName.Size = new System.Drawing.Size(154, 29); 285 | this.txtPetName.TabIndex = 8; 286 | // 287 | // label3 288 | // 289 | this.label3.AutoSize = true; 290 | this.label3.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 291 | this.label3.Location = new System.Drawing.Point(59, 31); 292 | this.label3.Name = "label3"; 293 | this.label3.Size = new System.Drawing.Size(58, 20); 294 | this.label3.TabIndex = 7; 295 | this.label3.Text = "Pet ID:"; 296 | // 297 | // txtPetId 298 | // 299 | this.txtPetId.Location = new System.Drawing.Point(63, 54); 300 | this.txtPetId.Name = "txtPetId"; 301 | this.txtPetId.ReadOnly = true; 302 | this.txtPetId.Size = new System.Drawing.Size(154, 29); 303 | this.txtPetId.TabIndex = 6; 304 | this.txtPetId.Text = "0"; 305 | // 306 | // PetView 307 | // 308 | this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); 309 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 310 | this.ClientSize = new System.Drawing.Size(892, 467); 311 | this.Controls.Add(this.tabControl1); 312 | this.Controls.Add(this.panel1); 313 | this.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 314 | this.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); 315 | this.Name = "PetView"; 316 | this.Text = "PetView"; 317 | this.panel1.ResumeLayout(false); 318 | this.panel1.PerformLayout(); 319 | this.tabControl1.ResumeLayout(false); 320 | this.tabPagePetList.ResumeLayout(false); 321 | this.tabPagePetList.PerformLayout(); 322 | ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); 323 | this.tabPagePetDetail.ResumeLayout(false); 324 | this.tabPagePetDetail.PerformLayout(); 325 | this.ResumeLayout(false); 326 | 327 | } 328 | 329 | #endregion 330 | 331 | private System.Windows.Forms.Label label1; 332 | private System.Windows.Forms.Panel panel1; 333 | private System.Windows.Forms.TabControl tabControl1; 334 | private System.Windows.Forms.TabPage tabPagePetList; 335 | private System.Windows.Forms.Label label2; 336 | private System.Windows.Forms.Button btnDelete; 337 | private System.Windows.Forms.Button btnEdit; 338 | private System.Windows.Forms.Button btnAddNew; 339 | private System.Windows.Forms.Button btnSearch; 340 | private System.Windows.Forms.TextBox txtSearch; 341 | private System.Windows.Forms.TabPage tabPagePetDetail; 342 | private System.Windows.Forms.DataGridView dataGridView; 343 | private System.Windows.Forms.Button btnCancel; 344 | private System.Windows.Forms.Button btnSave; 345 | private System.Windows.Forms.Label label6; 346 | private System.Windows.Forms.TextBox txtPetColour; 347 | private System.Windows.Forms.Label label5; 348 | private System.Windows.Forms.TextBox txtPetType; 349 | private System.Windows.Forms.Label label4; 350 | private System.Windows.Forms.TextBox txtPetName; 351 | private System.Windows.Forms.Label label3; 352 | private System.Windows.Forms.TextBox txtPetId; 353 | private System.Windows.Forms.Button btnClose; 354 | } 355 | } -------------------------------------------------------------------------------- /CRUDWinFormsMVP/Views/PetView.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Data; 5 | using System.Drawing; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | using System.Windows.Forms; 10 | 11 | namespace CRUDWinFormsMVP.Views 12 | { 13 | public partial class PetView : Form, IPetView 14 | { 15 | //Fields 16 | private string message; 17 | private bool isSuccessful; 18 | private bool isEdit; 19 | 20 | //Constructor 21 | public PetView() 22 | { 23 | InitializeComponent(); 24 | AssociateAndRaiseViewEvents(); 25 | tabControl1.TabPages.Remove(tabPagePetDetail); 26 | btnClose.Click += delegate { this.Close(); }; 27 | } 28 | 29 | private void AssociateAndRaiseViewEvents() 30 | { 31 | //Search 32 | btnSearch.Click += delegate { SearchEvent?.Invoke(this, EventArgs.Empty); }; 33 | txtSearch.KeyDown += (s, e) => 34 | { 35 | if (e.KeyCode == Keys.Enter) 36 | SearchEvent?.Invoke(this, EventArgs.Empty); 37 | }; 38 | //Add new 39 | btnAddNew.Click += delegate 40 | { 41 | AddNewEvent?.Invoke(this, EventArgs.Empty); 42 | tabControl1.TabPages.Remove(tabPagePetList); 43 | tabControl1.TabPages.Add(tabPagePetDetail); 44 | tabPagePetDetail.Text = "Add new pet"; 45 | }; 46 | //Edit 47 | btnEdit.Click += delegate 48 | { 49 | EditEvent?.Invoke(this, EventArgs.Empty); 50 | tabControl1.TabPages.Remove(tabPagePetList); 51 | tabControl1.TabPages.Add(tabPagePetDetail); 52 | tabPagePetDetail.Text = "Edit pet"; 53 | }; 54 | //Save changes 55 | btnSave.Click += delegate 56 | { 57 | SaveEvent?.Invoke(this, EventArgs.Empty); 58 | if (isSuccessful) 59 | { 60 | tabControl1.TabPages.Remove(tabPagePetDetail); 61 | tabControl1.TabPages.Add(tabPagePetList); 62 | } 63 | MessageBox.Show(Message); 64 | }; 65 | //Cancel 66 | btnCancel.Click += delegate 67 | { 68 | CancelEvent?.Invoke(this, EventArgs.Empty); 69 | tabControl1.TabPages.Remove(tabPagePetDetail); 70 | tabControl1.TabPages.Add(tabPagePetList); 71 | }; 72 | //Delete 73 | btnDelete.Click += delegate 74 | { 75 | var result = MessageBox.Show("Are you sure you want to delete the selected pet?", "Warning", 76 | MessageBoxButtons.YesNo, MessageBoxIcon.Warning); 77 | if (result == DialogResult.Yes) 78 | { 79 | DeleteEvent?.Invoke(this, EventArgs.Empty); 80 | MessageBox.Show(Message); 81 | } 82 | }; 83 | } 84 | 85 | //Properties 86 | public string PetId 87 | { 88 | get { return txtPetId.Text; } 89 | set { txtPetId.Text = value; } 90 | } 91 | 92 | public string PetName 93 | { 94 | get { return txtPetName.Text; } 95 | set { txtPetName.Text = value; } 96 | } 97 | 98 | public string PetType 99 | { 100 | get { return txtPetType.Text; } 101 | set { txtPetType.Text = value; } 102 | } 103 | 104 | public string PetColour 105 | { 106 | get { return txtPetColour.Text; } 107 | set { txtPetColour.Text = value; } 108 | } 109 | 110 | public string SearchValue 111 | { 112 | get { return txtSearch.Text; } 113 | set { txtSearch.Text = value; } 114 | } 115 | 116 | public bool IsEdit 117 | { 118 | get { return isEdit; } 119 | set { isEdit = value; } 120 | } 121 | 122 | public bool IsSuccessful 123 | { 124 | get { return isSuccessful; } 125 | set { isSuccessful = value; } 126 | } 127 | 128 | public string Message 129 | { 130 | get { return message; } 131 | set { message = value; } 132 | } 133 | 134 | //Events 135 | public event EventHandler SearchEvent; 136 | public event EventHandler AddNewEvent; 137 | public event EventHandler EditEvent; 138 | public event EventHandler DeleteEvent; 139 | public event EventHandler SaveEvent; 140 | public event EventHandler CancelEvent; 141 | 142 | //Methods 143 | public void SetPetListBindingSource(BindingSource petList) 144 | { 145 | dataGridView.DataSource = petList; 146 | } 147 | 148 | //Singleton pattern (Open a single form instance) 149 | private static PetView instance; 150 | public static PetView GetInstace(Form parentContainer) 151 | { 152 | if (instance == null || instance.IsDisposed) 153 | { 154 | instance = new PetView(); 155 | instance.MdiParent = parentContainer; 156 | instance.FormBorderStyle = FormBorderStyle.None; 157 | instance.Dock = DockStyle.Fill; 158 | } 159 | else 160 | { 161 | if (instance.WindowState == FormWindowState.Minimized) 162 | instance.WindowState = FormWindowState.Normal; 163 | instance.BringToFront(); 164 | } 165 | return instance; 166 | } 167 | } 168 | } 169 | -------------------------------------------------------------------------------- /CRUDWinFormsMVP/Views/PetView.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 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 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | -------------------------------------------------------------------------------- /CRUDWinFormsMVP/_Repositories/BaseRepository.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace CRUDWinFormsMVP._Repositories 8 | { 9 | public abstract class BaseRepository 10 | { 11 | protected string connectionString; 12 | //... 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /CRUDWinFormsMVP/_Repositories/PetRepository.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Data.SqlClient; 7 | using System.Data; 8 | using CRUDWinFormsMVP.Models; 9 | 10 | namespace CRUDWinFormsMVP._Repositories 11 | { 12 | public class PetRepository : BaseRepository, IPetRepository 13 | { 14 | //Constructor 15 | public PetRepository(string connectionString) 16 | { 17 | this.connectionString = connectionString; 18 | } 19 | //Methods 20 | public void Add(PetModel petModel) 21 | { 22 | using (var connection = new SqlConnection(connectionString)) 23 | using (var command = new SqlCommand()) 24 | { 25 | connection.Open(); 26 | command.Connection = connection; 27 | command.CommandText = "insert into Pet values (@name, @type, @colour)"; 28 | command.Parameters.Add("@name", SqlDbType.NVarChar).Value = petModel.Name; 29 | command.Parameters.Add("@type", SqlDbType.NVarChar).Value = petModel.Type; 30 | command.Parameters.Add("@colour", SqlDbType.NVarChar).Value = petModel.Colour; 31 | command.ExecuteNonQuery(); 32 | } 33 | } 34 | public void Delete(int id) 35 | { 36 | using (var connection = new SqlConnection(connectionString)) 37 | using (var command = new SqlCommand()) 38 | { 39 | connection.Open(); 40 | command.Connection = connection; 41 | command.CommandText = "delete from Pet where Pet_Id=@id"; 42 | command.Parameters.Add("@id", SqlDbType.Int).Value = id; 43 | command.ExecuteNonQuery(); 44 | } 45 | } 46 | public void Edit(PetModel petModel) 47 | { 48 | using (var connection = new SqlConnection(connectionString)) 49 | using (var command = new SqlCommand()) 50 | { 51 | connection.Open(); 52 | command.Connection = connection; 53 | command.CommandText = @"update Pet 54 | set Pet_Name=@name,Pet_Type= @type,Pet_Colour= @colour 55 | where Pet_Id=@id"; 56 | command.Parameters.Add("@name", SqlDbType.NVarChar).Value = petModel.Name; 57 | command.Parameters.Add("@type", SqlDbType.NVarChar).Value = petModel.Type; 58 | command.Parameters.Add("@colour", SqlDbType.NVarChar).Value = petModel.Colour; 59 | command.Parameters.Add("@id", SqlDbType.Int).Value = petModel.Id; 60 | command.ExecuteNonQuery(); 61 | } 62 | } 63 | 64 | public IEnumerable GetAll() 65 | { 66 | var petList = new List(); 67 | using (var connection = new SqlConnection(connectionString)) 68 | using (var command = new SqlCommand()) 69 | { 70 | connection.Open(); 71 | command.Connection = connection; 72 | command.CommandText = "Select *from Pet order by Pet_Id desc"; 73 | using (var reader = command.ExecuteReader()) 74 | { 75 | while (reader.Read()) 76 | { 77 | var petModel = new PetModel(); 78 | petModel.Id = (int)reader[0]; 79 | petModel.Name = reader[1].ToString(); 80 | petModel.Type = reader[2].ToString(); 81 | petModel.Colour = reader[3].ToString(); 82 | petList.Add(petModel); 83 | } 84 | } 85 | } 86 | return petList; 87 | } 88 | 89 | public IEnumerable GetByValue(string value) 90 | { 91 | var petList = new List(); 92 | int petId = int.TryParse(value, out _) ? Convert.ToInt32(value) : 0; 93 | string petName = value; 94 | using (var connection = new SqlConnection(connectionString)) 95 | using (var command = new SqlCommand()) 96 | { 97 | connection.Open(); 98 | command.Connection = connection; 99 | command.CommandText = @"Select *from Pet 100 | where Pet_Id=@id or Pet_Name like @name+'%' 101 | order by Pet_Id desc"; 102 | command.Parameters.Add("@id", SqlDbType.Int).Value = petId; 103 | command.Parameters.Add("@name", SqlDbType.NVarChar).Value = petName; 104 | 105 | using (var reader = command.ExecuteReader()) 106 | { 107 | while (reader.Read()) 108 | { 109 | var petModel = new PetModel(); 110 | petModel.Id = (int)reader[0]; 111 | petModel.Name = reader[1].ToString(); 112 | petModel.Type = reader[2].ToString(); 113 | petModel.Colour = reader[3].ToString(); 114 | petList.Add(petModel); 115 | } 116 | } 117 | } 118 | return petList; 119 | } 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /CRUDWinFormsMVP/bin/Debug/CRUDWinFormsMVP.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RJCodeAdvance/CRUD-MVP-C-SHARP-SQL-WINFORMS-PART-3-FINAL/6830603df3cb2b84c2547609dad6a3d04cfcb5b1/CRUDWinFormsMVP/bin/Debug/CRUDWinFormsMVP.exe -------------------------------------------------------------------------------- /CRUDWinFormsMVP/bin/Debug/CRUDWinFormsMVP.exe.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /CRUDWinFormsMVP/bin/Debug/CRUDWinFormsMVP.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RJCodeAdvance/CRUD-MVP-C-SHARP-SQL-WINFORMS-PART-3-FINAL/6830603df3cb2b84c2547609dad6a3d04cfcb5b1/CRUDWinFormsMVP/bin/Debug/CRUDWinFormsMVP.pdb -------------------------------------------------------------------------------- /CRUDWinFormsMVP/obj/Debug/CRUDWinFormsMVP.Properties.Resources.resources: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RJCodeAdvance/CRUD-MVP-C-SHARP-SQL-WINFORMS-PART-3-FINAL/6830603df3cb2b84c2547609dad6a3d04cfcb5b1/CRUDWinFormsMVP/obj/Debug/CRUDWinFormsMVP.Properties.Resources.resources -------------------------------------------------------------------------------- /CRUDWinFormsMVP/obj/Debug/CRUDWinFormsMVP.Views.MainView.resources: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RJCodeAdvance/CRUD-MVP-C-SHARP-SQL-WINFORMS-PART-3-FINAL/6830603df3cb2b84c2547609dad6a3d04cfcb5b1/CRUDWinFormsMVP/obj/Debug/CRUDWinFormsMVP.Views.MainView.resources -------------------------------------------------------------------------------- /CRUDWinFormsMVP/obj/Debug/CRUDWinFormsMVP.Views.PetView.resources: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RJCodeAdvance/CRUD-MVP-C-SHARP-SQL-WINFORMS-PART-3-FINAL/6830603df3cb2b84c2547609dad6a3d04cfcb5b1/CRUDWinFormsMVP/obj/Debug/CRUDWinFormsMVP.Views.PetView.resources -------------------------------------------------------------------------------- /CRUDWinFormsMVP/obj/Debug/CRUDWinFormsMVP.csproj.AssemblyReference.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RJCodeAdvance/CRUD-MVP-C-SHARP-SQL-WINFORMS-PART-3-FINAL/6830603df3cb2b84c2547609dad6a3d04cfcb5b1/CRUDWinFormsMVP/obj/Debug/CRUDWinFormsMVP.csproj.AssemblyReference.cache -------------------------------------------------------------------------------- /CRUDWinFormsMVP/obj/Debug/CRUDWinFormsMVP.csproj.CoreCompileInputs.cache: -------------------------------------------------------------------------------- 1 | 2fb09f759104ec986571a6d9c1f2e6ca9b64036f 2 | -------------------------------------------------------------------------------- /CRUDWinFormsMVP/obj/Debug/CRUDWinFormsMVP.csproj.FileListAbsolute.txt: -------------------------------------------------------------------------------- 1 | D:\RJ Code Advance\Source Code C#\2022\CRUDWinFormsMVP\CRUDWinFormsMVP\obj\Debug\CRUDWinFormsMVP.csproj.AssemblyReference.cache 2 | D:\RJ Code Advance\Source Code C#\2022\CRUDWinFormsMVP\CRUDWinFormsMVP\obj\Debug\CRUDWinFormsMVP.Properties.Resources.resources 3 | D:\RJ Code Advance\Source Code C#\2022\CRUDWinFormsMVP\CRUDWinFormsMVP\obj\Debug\CRUDWinFormsMVP.csproj.GenerateResource.cache 4 | D:\RJ Code Advance\Source Code C#\2022\CRUDWinFormsMVP\CRUDWinFormsMVP\obj\Debug\CRUDWinFormsMVP.csproj.CoreCompileInputs.cache 5 | D:\RJ Code Advance\Source Code C#\2022\CRUDWinFormsMVP\CRUDWinFormsMVP\bin\Debug\CRUDWinFormsMVP.exe.config 6 | D:\RJ Code Advance\Source Code C#\2022\CRUDWinFormsMVP\CRUDWinFormsMVP\bin\Debug\CRUDWinFormsMVP.exe 7 | D:\RJ Code Advance\Source Code C#\2022\CRUDWinFormsMVP\CRUDWinFormsMVP\bin\Debug\CRUDWinFormsMVP.pdb 8 | D:\RJ Code Advance\Source Code C#\2022\CRUDWinFormsMVP\CRUDWinFormsMVP\obj\Debug\CRUDWinFormsMVP.Views.PetView.resources 9 | D:\RJ Code Advance\Source Code C#\2022\CRUDWinFormsMVP\CRUDWinFormsMVP\obj\Debug\CRUDWinFormsMVP.exe 10 | D:\RJ Code Advance\Source Code C#\2022\CRUDWinFormsMVP\CRUDWinFormsMVP\obj\Debug\CRUDWinFormsMVP.pdb 11 | D:\RJ Code Advance\Source Code C#\2022\CRUDWinFormsMVP\CRUDWinFormsMVP\obj\Debug\CRUDWinFormsMVP.Views.MainView.resources 12 | D:\RJ Code Advance\Source Code C#\2022\CRUDWinFormsMVP - Parte 3\CRUDWinFormsMVP\bin\Debug\CRUDWinFormsMVP.exe.config 13 | D:\RJ Code Advance\Source Code C#\2022\CRUDWinFormsMVP - Parte 3\CRUDWinFormsMVP\bin\Debug\CRUDWinFormsMVP.exe 14 | D:\RJ Code Advance\Source Code C#\2022\CRUDWinFormsMVP - Parte 3\CRUDWinFormsMVP\bin\Debug\CRUDWinFormsMVP.pdb 15 | D:\RJ Code Advance\Source Code C#\2022\CRUDWinFormsMVP - Parte 3\CRUDWinFormsMVP\obj\Debug\CRUDWinFormsMVP.csproj.AssemblyReference.cache 16 | D:\RJ Code Advance\Source Code C#\2022\CRUDWinFormsMVP - Parte 3\CRUDWinFormsMVP\obj\Debug\CRUDWinFormsMVP.Properties.Resources.resources 17 | D:\RJ Code Advance\Source Code C#\2022\CRUDWinFormsMVP - Parte 3\CRUDWinFormsMVP\obj\Debug\CRUDWinFormsMVP.Views.MainView.resources 18 | D:\RJ Code Advance\Source Code C#\2022\CRUDWinFormsMVP - Parte 3\CRUDWinFormsMVP\obj\Debug\CRUDWinFormsMVP.Views.PetView.resources 19 | D:\RJ Code Advance\Source Code C#\2022\CRUDWinFormsMVP - Parte 3\CRUDWinFormsMVP\obj\Debug\CRUDWinFormsMVP.csproj.GenerateResource.cache 20 | D:\RJ Code Advance\Source Code C#\2022\CRUDWinFormsMVP - Parte 3\CRUDWinFormsMVP\obj\Debug\CRUDWinFormsMVP.csproj.CoreCompileInputs.cache 21 | D:\RJ Code Advance\Source Code C#\2022\CRUDWinFormsMVP - Parte 3\CRUDWinFormsMVP\obj\Debug\CRUDWinFormsMVP.exe 22 | D:\RJ Code Advance\Source Code C#\2022\CRUDWinFormsMVP - Parte 3\CRUDWinFormsMVP\obj\Debug\CRUDWinFormsMVP.pdb 23 | -------------------------------------------------------------------------------- /CRUDWinFormsMVP/obj/Debug/CRUDWinFormsMVP.csproj.GenerateResource.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RJCodeAdvance/CRUD-MVP-C-SHARP-SQL-WINFORMS-PART-3-FINAL/6830603df3cb2b84c2547609dad6a3d04cfcb5b1/CRUDWinFormsMVP/obj/Debug/CRUDWinFormsMVP.csproj.GenerateResource.cache -------------------------------------------------------------------------------- /CRUDWinFormsMVP/obj/Debug/CRUDWinFormsMVP.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RJCodeAdvance/CRUD-MVP-C-SHARP-SQL-WINFORMS-PART-3-FINAL/6830603df3cb2b84c2547609dad6a3d04cfcb5b1/CRUDWinFormsMVP/obj/Debug/CRUDWinFormsMVP.exe -------------------------------------------------------------------------------- /CRUDWinFormsMVP/obj/Debug/CRUDWinFormsMVP.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RJCodeAdvance/CRUD-MVP-C-SHARP-SQL-WINFORMS-PART-3-FINAL/6830603df3cb2b84c2547609dad6a3d04cfcb5b1/CRUDWinFormsMVP/obj/Debug/CRUDWinFormsMVP.pdb -------------------------------------------------------------------------------- /CRUDWinFormsMVP/obj/Debug/DesignTimeResolveAssemblyReferences.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RJCodeAdvance/CRUD-MVP-C-SHARP-SQL-WINFORMS-PART-3-FINAL/6830603df3cb2b84c2547609dad6a3d04cfcb5b1/CRUDWinFormsMVP/obj/Debug/DesignTimeResolveAssemblyReferences.cache -------------------------------------------------------------------------------- /CRUDWinFormsMVP/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RJCodeAdvance/CRUD-MVP-C-SHARP-SQL-WINFORMS-PART-3-FINAL/6830603df3cb2b84c2547609dad6a3d04cfcb5b1/CRUDWinFormsMVP/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CRUD WITH MVP, C#, SQL, WINFORMS-PART 3 (FINAL) 2 | CRUD using the MVP pattern, C-Sharp, Windows Forms and SQL Server (Part 3- FINAL) 3 | -------------------------------------------------------------------------------- /VeterinaryDb.sql: -------------------------------------------------------------------------------- 1 | create database VeterinaryDb 2 | go 3 | use VeterinaryDb 4 | go 5 | create table Pet 6 | ( 7 | Pet_Id int identity (100000,1) primary key, 8 | Pet_Name nvarchar (50) not null, 9 | Pet_Type nvarchar (50) not null, 10 | Pet_Colour nvarchar (50) not null, 11 | ) 12 | go 13 | insert into Pet values('Buttons', 'Dog', 'White') 14 | insert into Pet values('Coda', 'Cat', 'Multicolor') 15 | insert into Pet values('Merlin', 'Parrot', 'Green-Yellow') 16 | insert into Pet values('Nina', 'Turtle', 'Dark Gray') 17 | insert into Pet values('Domino', 'Rabbit', 'White') 18 | insert into Pet values('Luna', 'Hamster', 'Orange') 19 | insert into Pet values('Lucy', 'Monkey', 'Brown') 20 | insert into Pet values('Daysi', 'Horse', 'White') 21 | insert into Pet values('Zoe', 'Snake', 'Yellow white') 22 | insert into Pet values('Max', 'Budgie', 'Yellow') 23 | insert into Pet values('Charlie', 'Mouse', 'White') 24 | insert into Pet values('Rocky', 'Squirrel', 'Brown-Orange') 25 | insert into Pet values('Leo', 'Dog', 'White-Black') 26 | insert into Pet values('Loki', 'Cat', 'Black') 27 | insert into Pet values('Jasper', 'Dog', 'Silver') 28 | go 29 | select *from Pet --------------------------------------------------------------------------------