-
Notifications
You must be signed in to change notification settings - Fork 0
/
AddVisitForm.cs
155 lines (132 loc) · 4.48 KB
/
AddVisitForm.cs
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
using Clinic_Assistant.Domain;
using Clinic_Assistant.Service;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Clinic_Assistant
{
public partial class AddVisitForm : Form
{
public int patient_id;
public int visit_id;
bool editing = false;
public string fileName;
public AddVisitForm()
{
InitializeComponent();
}
PatientInfoForm owner;
public AddVisitForm(PatientInfoForm form, int id)
{
InitializeComponent();
owner = form;
patient_id = id;
save_visit_btn.Visible = true;
}
//ediitng
public AddVisitForm(PatientInfoForm form, int pId, int vId)
{
InitializeComponent();
owner = form;
patient_id = pId;
visit_id = vId;
editing = true;
save_edits_btn.Visible = true;
fillFormFromVisit();
}
string oldXrayName;
void fillFormFromVisit()
{
VisitService visitService = new VisitService();
Visit visit = visitService.getVisitById(visit_id);
complaint_textBox.Text = visit.complaint;
diagnosis_textBox.Text = visit.diagnosis;
tooth_textBox.Text = visit.tooth;
treatmet_textBox.Text = visit.treatment;
cost_num.Value = (int)visit.cost;
paid_num.Value = (int)visit.paid;
oldXrayName = visit.xray;
}
private void saveVisitBtn_Click(object sender, EventArgs e)
{
VisitService visitService = new VisitService();
visitService.addVisit(createVisitFromForm(), patient_id);
owner.fillGridView();
this.Close();
}
public static string RandomString()
{
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
var random = new Random();
return new string(Enumerable.Repeat(chars, 12)
.Select(s => s[random.Next(s.Length)]).ToArray());
}
private Visit createVisitFromForm()
{
string imageName="";
if(!String.IsNullOrEmpty(fileName)){
if(editing){
System.IO.File.Copy(fileName, @"..\..\xray\" + oldXrayName + ".jpg", true);
}
else{
imageName=RandomString();
System.IO.File.Copy(fileName, @"..\..\xray\" + imageName + ".jpg", true);
}
}
return new Visit()
{
date = date_dateTimePicker.Value.Date,
complaint = complaint_textBox.Text,
diagnosis = diagnosis_textBox.Text,
tooth = tooth_textBox.Text,
treatment = treatmet_textBox.Text,
cost = Decimal.ToInt32(cost_num.Value),
paid = Decimal.ToInt32(paid_num.Value),
remaining = Decimal.ToInt32(remaining_num.Value),
xray = imageName,
};
}
private void save_edits_btn_Click(object sender, EventArgs e)
{
VisitService visitService = new VisitService();
visitService.update(visit_id, createVisitFromForm());
owner.fillGridView();
this.Close();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void label3_Click(object sender, EventArgs e)
{
}
private void cost_num_ValueChanged(object sender, EventArgs e)
{
remaining_num.Value = cost_num.Value - paid_num.Value;
}
private void paid_num_ValueChanged(object sender, EventArgs e)
{
remaining_num.Value = cost_num.Value - paid_num.Value;
}
private void save_edits_btn_Click_1(object sender, EventArgs e)
{
VisitService visitService = new VisitService();
visitService.update(visit_id, createVisitFromForm());
owner.fillGridView();
this.Close();
}
//saving xray
private void button1_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
fileName = openFileDialog1.FileName;
}
}
}
}