-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFormCompanyInfo.cs
More file actions
118 lines (101 loc) · 4.28 KB
/
FormCompanyInfo.cs
File metadata and controls
118 lines (101 loc) · 4.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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
61
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
110
111
112
113
114
115
116
117
118
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics.Contracts;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using CSEmployeeAttendance25.Data;
namespace CSEmployeeAttendance25
{
public partial class FormCompanyInfo : Form
{
private CompanyInfoDBHelper _companyHelper;
public FormCompanyInfo()
{
InitializeComponent();
bool setEnabled = true;
if (Program.loginUser.Role == (int)enumMyUserRoles.Admin)
setEnabled = false;
textBoxCompanyName.Enabled = setEnabled;
textBoxAddress.Enabled = setEnabled;
textBoxEmail.Enabled = setEnabled;
textBoxContactNo.Enabled = setEnabled;
textBoxWebsite.Enabled = setEnabled;
_companyHelper = new CompanyInfoDBHelper();
LoadCompanyInfo();
}
private void LoadCompanyInfo()
{
CompanyInfoDTO company = _companyHelper.GetCompanyInfo();
if (company != null)
{
textBoxCompanyName.Text = company.CompanyName;
textBoxAddress.Text = company.CompanyAddress;
textBoxEmail.Text = company.EmailId;
textBoxContactNo.Text = company.ContactNo;
textBoxWebsite.Text = company.Website;
dtpShiftStart.Value = DateTime.Today.Add(company.ShiftStart); // Convert TimeSpan to DateTime
dtpShiftEnd.Value = DateTime.Today.Add(company.ShiftEnd);
checkBoxApplyAdjustment.Checked = company.ApplyTimeAdjustment;
dtpFromHour.Value = DateTime.Today.Add(company.FromHour);
dtpToHour.Value = DateTime.Today.Add(company.ToHour);
numericUpDownDeductionMinutes.Value = company.DeductMinutes;
}
}
private void FormCompanyInfo_Load(object sender, EventArgs e)
{
}
private void buttonSave_Click(object sender, EventArgs e)
{
// Validation
if (string.IsNullOrWhiteSpace(textBoxCompanyName.Text) || string.IsNullOrWhiteSpace(textBoxContactNo.Text))
{
MessageBox.Show("Company Name and Contact No. are required.", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
// Create DTO object
CompanyInfoDTO company = new CompanyInfoDTO
{
CompanyName = textBoxCompanyName.Text.Trim(),
CompanyAddress = textBoxAddress.Text.Trim(),
EmailId = textBoxEmail.Text.Trim(),
ContactNo = textBoxContactNo.Text.Trim(),
Website = textBoxWebsite.Text.Trim(),
ShiftStart = dtpShiftStart.Value.TimeOfDay, // Convert DateTime to TimeSpan
ShiftEnd = dtpShiftEnd.Value.TimeOfDay, // Convert DateTime to TimeSpan
ApplyTimeAdjustment = checkBoxApplyAdjustment.Checked,
FromHour = dtpFromHour.Value.TimeOfDay,
ToHour = dtpToHour.Value.TimeOfDay,
DeductMinutes = (int)numericUpDownDeductionMinutes.Value
};
// Save Data
bool success = _companyHelper.SaveCompanyInfo(company);
if (success)
{
MessageBox.Show("Company info updated successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
// Update session values
Program.companyInfo = _companyHelper.GetCompanyInfo();
this.DialogResult = DialogResult.OK;
}
else
MessageBox.Show("Failed to save company info.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
private void buttonCancel_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.Cancel;
}
private void buttonClose_Click(object sender, EventArgs e)
{
this.Close();
}
private void checkBoxApplyAdjustment_CheckedChanged(object sender, EventArgs e)
{
groupBoxAdjustment.Enabled = checkBoxApplyAdjustment.Checked;
}
}
}