Skip to content

Commit 4095756

Browse files
committed
Added chapter06 samples
1 parent 58b207a commit 4095756

35 files changed

+631
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<ProjectReference Include="..\Azon.Web.Sdk\Azon.Web.Sdk.csproj" />
11+
</ItemGroup>
12+
13+
</Project>

Azon.Web.Component/Button.cs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace Azon.Web.Component;
2+
3+
public class Button(int id, string name, (double, double) position)
4+
: ButtonBase(id, name, position), IDrawable
5+
{
6+
protected bool IsCorneredCurve { get; set; }
7+
public string? Text { get; set; }
8+
9+
public void Draw()
10+
{
11+
Console.WriteLine("Button draw at {0}:{1}", Position.Item1, Position.Item2);
12+
}
13+
public override string ToString()
14+
{
15+
return $"{base.ToString()}|{Text}|{IsCorneredCurve}";
16+
}
17+
}

Azon.Web.Component/ButtonBase.cs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace Azon.Web.Component;
2+
3+
public abstract class ButtonBase(int id, string name, (double, double) position)
4+
: Control(id, name, position)
5+
{
6+
public string? BackgroundColor { get; set; }
7+
public string? ForegroundColor { get; set; }
8+
}

Azon.Web.Component/CheckBox.cs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace Azon.Web.Component;
2+
3+
public class CheckBox(int id, string name, (double, double) position)
4+
: Control(id, name, position), IDrawable
5+
{
6+
public string? Text { get; set; }
7+
public bool IsChecked { get; set; }
8+
9+
public void Draw()
10+
{
11+
Console.WriteLine("CheckBox draw at {0}:{1}", Position.Item1, Position.Item2);
12+
}
13+
public override string ToString()
14+
{
15+
return $"{base.ToString()}|{Text}|{IsChecked}";
16+
}
17+
}

Azon.Web.Component/Control.cs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace Azon.Web.Component;
2+
3+
public abstract class Control(int id, string name, (double, double) position)
4+
{
5+
public int Id { get; set; } = id;
6+
protected string? Name { get; set; } = name;
7+
protected (double, double) Position { get; set; } = position;
8+
9+
public override string ToString()
10+
{
11+
return $"{Id}|{GetType().Name}|{Name}|{Position}";
12+
}
13+
}

Azon.Web.Component/DbConnector.cs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace Azon.Web.Component;
2+
3+
public class DbConnector(int id, string name, (double, double) position)
4+
: Control(id, name, position)
5+
{
6+
public string? ConnectionString { get; set; }
7+
8+
public override string ToString()
9+
{
10+
return $"{base.ToString()}|{ConnectionString}";
11+
}
12+
}

Azon.Web.Component/Form.cs

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
namespace Azon.Web.Component;
2+
3+
public class Form(IPersistence persistence)
4+
{
5+
private readonly List<Control> _controls = [];
6+
private readonly IPersistence _persistence = persistence;
7+
8+
public void AddControls(params Control[] controls)
9+
{
10+
_controls.AddRange(controls);
11+
}
12+
public void LocateAll()
13+
{
14+
foreach (Control control in _controls)
15+
{
16+
Console.WriteLine($"{control.Id} location set");
17+
}
18+
}
19+
public void DrawAll()
20+
{
21+
foreach (Control control in _controls)
22+
{
23+
if (control is IDrawable drawable)
24+
{
25+
drawable.Draw();
26+
}
27+
}
28+
}
29+
30+
public void Save()
31+
{
32+
_persistence.Save(_controls);
33+
}
34+
}

Azon.Web.Component/GridBox.cs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace Azon.Web.Component;
2+
3+
internal class GridBox(int id, string name, (double, double) position)
4+
: Control(id, name, position), IDrawable
5+
{
6+
public int RowCount { get; set; }
7+
public int ColumnCount { get; set; }
8+
9+
public void Draw()
10+
{
11+
Console.WriteLine("GridBox draw at {0}:{1}", Position.Item1, Position.Item2);
12+
}
13+
public override string ToString()
14+
{
15+
return $"{base.ToString()}|{RowCount}|{ColumnCount}";
16+
}
17+
}

Azon.Web.Component/Label.cs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace Azon.Web.Component;
2+
3+
public class Label(int id, string name, (double, double) position)
4+
: Control(id, name, position), IDrawable
5+
{
6+
public string Text { get; set; }
7+
8+
public void Draw()
9+
{
10+
Console.WriteLine("Label draw at {0}:{1}", Position.Item1, Position.Item2);
11+
}
12+
public override string ToString()
13+
{
14+
return $"{base.ToString()}|{Text}";
15+
}
16+
}

Azon.Web.Component/LinkButton.cs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace Azon.Web.Component;
2+
3+
public class LinkButton(int id, string name, (double, double) position)
4+
: ButtonBase(id, name, position), IDrawable
5+
{
6+
public Uri Url { get; set; }
7+
8+
public void Draw()
9+
{
10+
Console.WriteLine("LinkButton draw at {0}:{1}", Position.Item1, Position.Item2);
11+
}
12+
public override string ToString()
13+
{
14+
return $"{base.ToString()}|{Url}";
15+
}
16+
}

Azon.Web.Component/RadioButton.cs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace Azon.Web.Component;
2+
3+
public class RadioButton(int id, string name, (double, double) position)
4+
: ButtonBase(id, name, position), IDrawable
5+
{
6+
public List<string> Options { get; set; } = [];
7+
public string SelectedOption { get; set; }
8+
9+
public void Draw()
10+
{
11+
Console.WriteLine("RadioButton draw at {0}:{1}", Position.Item1, Position.Item2);
12+
}
13+
public override string ToString()
14+
{
15+
return $"{base.ToString()}|{SelectedOption}";
16+
}
17+
}
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<ProjectReference Include="..\Azon.Web.Persistence\Azon.Web.Persistence.csproj" />
12+
<ProjectReference Include="..\Azon.Web.Sdk\Azon.Web.Sdk.csproj" />
13+
</ItemGroup>
14+
15+
</Project>

Azon.Web.Editor/Program.cs

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using Azon.Web.Persistence;
2+
using Azon.Web.Sdk.Components;
3+
4+
namespace Azon.Web.Editor;
5+
6+
internal class Program
7+
{
8+
static void Main(string[] args)
9+
{
10+
var csvPersistence = new CsvPersistence();
11+
Form mainForm = new(csvPersistence);
12+
13+
Button btnSave = new(101, "btnSave", (0, 100))
14+
{
15+
Text = "Save"
16+
};
17+
Button btnClose = new(102, "btnClose", (0, 500))
18+
{
19+
Text = "Close"
20+
};
21+
CheckBox chkIsActiveProfile = new(104, "chkIsActive", (0, 10))
22+
{
23+
Text = "Is Active Profile",
24+
IsChecked = true
25+
};
26+
Label lblTitle = new(106, "lblTitle", (50, 50))
27+
{
28+
Text = "Title"
29+
};
30+
LinkButton lnkAbout = new(204, "lnkAbout", (400, 50))
31+
{
32+
Url = new Uri("https://www.azon.com.tr/about")
33+
};
34+
DbConnector dbConnector = new(90, "dbConnector", (0, 0))
35+
{
36+
ConnectionString = "data source=localhost:database=Northwind;integrated security=sspi"
37+
};
38+
39+
mainForm.AddControls(btnSave, btnClose, lblTitle, lnkAbout, chkIsActiveProfile, dbConnector);
40+
mainForm.DrawAll();
41+
mainForm.Save();
42+
}
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<ProjectReference Include="..\Azon.Web.Sdk\Azon.Web.Sdk.csproj" />
11+
</ItemGroup>
12+
13+
</Project>
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using Azon.Web.Sdk.Components;
2+
using Azon.Web.Sdk.Contracts;
3+
using System.Text;
4+
5+
namespace Azon.Web.Persistence;
6+
7+
public class CsvPersistence
8+
: IFilePersistence
9+
{
10+
public string FilePath { get; set; } = Path.Combine(Environment.CurrentDirectory, "Form.dat");
11+
public void Save(List<Control> controls)
12+
{
13+
var builder = new StringBuilder();
14+
foreach (Control control in controls)
15+
{
16+
builder.AppendLine(control.ToString());
17+
}
18+
var content = builder.ToString();
19+
File.WriteAllText(FilePath, content);
20+
}
21+
}

Azon.Web.Persistence/DbPersistence.cs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using Azon.Web.Sdk.Components;
2+
using Azon.Web.Sdk.Contracts;
3+
4+
namespace Azon.Web.Persistence;
5+
6+
public class DbPersistence
7+
: IPersistence
8+
{
9+
public void Save(List<Control> controls)
10+
{
11+
Console.WriteLine("Database save");
12+
}
13+
}

Azon.Web.Sdk/Azon.Web.Sdk.csproj

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
9+
</Project>

Azon.Web.Sdk/Components/Button.cs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using Azon.Web.Sdk.Contracts;
2+
3+
namespace Azon.Web.Sdk.Components;
4+
5+
public class Button(int id, string name, (double, double) position)
6+
: ButtonBase(id, name, position), IDrawable
7+
{
8+
protected bool IsCorneredCurve { get; set; }
9+
public string? Text { get; set; }
10+
11+
public void Draw()
12+
{
13+
Console.WriteLine("Button draw at {0}:{1}", Position.Item1, Position.Item2);
14+
}
15+
public override string ToString()
16+
{
17+
return $"{base.ToString()}|{Text}|{IsCorneredCurve}";
18+
}
19+
}

Azon.Web.Sdk/Components/ButtonBase.cs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace Azon.Web.Sdk.Components;
2+
3+
public abstract class ButtonBase(int id, string name, (double, double) position)
4+
: Control(id, name, position)
5+
{
6+
public string? BackgroundColor { get; set; }
7+
public string? ForegroundColor { get; set; }
8+
}

Azon.Web.Sdk/Components/CheckBox.cs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using Azon.Web.Sdk.Contracts;
2+
3+
namespace Azon.Web.Sdk.Components;
4+
5+
public class CheckBox(int id, string name, (double, double) position)
6+
: Control(id, name, position), IDrawable
7+
{
8+
public string? Text { get; set; }
9+
public bool IsChecked { get; set; }
10+
11+
public void Draw()
12+
{
13+
Console.WriteLine("CheckBox draw at {0}:{1}", Position.Item1, Position.Item2);
14+
}
15+
public override string ToString()
16+
{
17+
return $"{base.ToString()}|{Text}|{IsChecked}";
18+
}
19+
}

Azon.Web.Sdk/Components/Control.cs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace Azon.Web.Sdk.Components;
2+
3+
public abstract class Control(int id, string name, (double, double) position)
4+
{
5+
public int Id { get; set; } = id;
6+
protected string? Name { get; set; } = name;
7+
protected (double, double) Position { get; set; } = position;
8+
9+
public override string ToString()
10+
{
11+
return $"{Id}|{GetType().Name}|{Name}|{Position}";
12+
}
13+
}
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace Azon.Web.Sdk.Components;
2+
3+
public class DbConnector(int id, string name, (double, double) position)
4+
: Control(id, name, position)
5+
{
6+
public string? ConnectionString { get; set; }
7+
8+
public override string ToString()
9+
{
10+
return $"{base.ToString()}|{ConnectionString}";
11+
}
12+
}

0 commit comments

Comments
 (0)