Skip to content

Commit b26a564

Browse files
committed
add contact form and fix minor bugs
1 parent 6ab7f17 commit b26a564

File tree

8 files changed

+720
-260
lines changed

8 files changed

+720
-260
lines changed

.github/workflows/Release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ jobs:
2525
with:
2626
artifacts: |
2727
UnderAutomation.Yaskawa.zip
28-
**/publish/**/UnderAutomation.Yaskawa.Showcase.*.exe
28+
**/bin/publish/UnderAutomation.Yaskawa.Showcase.Forms.exe
2929
bodyFile: "whatsNew.md"
3030
token: ${{ secrets.GITHUB_TOKEN }}

UnderAutomation.Yaskawa.Showcase.Forms/Components/ContactControl.Designer.cs

Lines changed: 199 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
using System.Net;
2+
using System.Text;
3+
using System.Text.Json;
4+
using System.Windows.Forms;
5+
6+
public partial class ContactControl : UserControl, IUserControl
7+
{
8+
9+
public ContactControl()
10+
{
11+
InitializeComponent();
12+
13+
setEmailAnimation();
14+
}
15+
16+
#region IUserControl
17+
public string Title => "Need help ?";
18+
19+
public bool FeatureEnabled => true;
20+
21+
public void PeriodicUpdate() { }
22+
23+
public void OnClose() { }
24+
25+
public void OnOpen() { setEmailAnimation(); }
26+
27+
28+
#endregion
29+
30+
public void SetMessage(string message)
31+
{
32+
txtMessage.Text = message;
33+
}
34+
35+
private async void btnSend_Click(object sender, System.EventArgs e)
36+
{
37+
var payloadObject = new
38+
{
39+
email = txtEmail.Text,
40+
subject = $"Yaskawa Desktop showcase - {DateTime.UtcNow.ToString("yyMMddHHmmss")}",
41+
message = txtMessage.Text
42+
};
43+
44+
string payload = JsonSerializer.Serialize(payloadObject);
45+
var content = new StringContent(payload, Encoding.UTF8, "application/json");
46+
47+
try
48+
{
49+
using (var client = new HttpClient())
50+
{
51+
HttpResponseMessage response = await client.PostAsync("https://formspree.io/f/mleawvqb", content);
52+
53+
if (response.IsSuccessStatusCode)
54+
{
55+
MessageBox.Show("Message sent! ", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
56+
}
57+
else
58+
{
59+
MessageBox.Show($"Error: {response.StatusCode}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
60+
}
61+
}
62+
}
63+
catch (HttpRequestException ex)
64+
{
65+
MessageBox.Show($"Request error: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
66+
}
67+
68+
}
69+
70+
private void txtEmail_TextChanged(object sender, System.EventArgs e)
71+
{
72+
setEmailAnimation();
73+
}
74+
75+
private void setEmailAnimation()
76+
{
77+
if (chkAnonymous.Checked || (txtEmail.Text.Contains("@") && txtEmail.Text.Contains(".")))
78+
{
79+
emailErrorProvider.Clear();
80+
btnSend.Enabled = true;
81+
}
82+
else
83+
{
84+
emailErrorProvider.SetError(txtEmail, "please provide an email to get an answer");
85+
btnSend.Enabled = false;
86+
}
87+
}
88+
89+
private void chkAnonymous_CheckedChanged(object sender, System.EventArgs e)
90+
{
91+
if (chkAnonymous.Checked) txtEmail.Text = "";
92+
txtEmail.Enabled = !chkAnonymous.Checked;
93+
setEmailAnimation();
94+
}
95+
}

0 commit comments

Comments
 (0)