//*****add bills to the database****// public void addInvoice(bill obj) { string query = "IF OBJECT_ID('dbo.Invoice', 'U') IS NULL "; query += "BEGIN "; query += "CREATE TABLE [dbo].[Invoice]("; query += "[BillNo] VARCHAR(25) NOT NULL CONSTRAINT pkbillno PRIMARY KEY,"; query += "[Date] VARCHAR(50) NOT NULL,"; query += "[RequiredDate] VARCHAR(25) NOT NULL,"; query += "[EmployeeNic] VARCHAR(25) NOT NULL CONSTRAINT pkemplId FOREIGN KEY (EmployeeNic) REFERENCES dbo.Employee(EmployeeNic),"; query += "[PatientNic] VARCHAR(25) NOT NULL CONSTRAINT pkpatintnic FOREIGN KEY (PatientNic) REFERENCES dbo.Patient(PatientNic),"; query += "[Total] float(53) NOT NULL,"; query += "[Description] VARCHAR(250) NOT NULL"; query += ")"; query += " END"; String sqlQuery = "INSERT INTO dbo.Invoice(BillNo,Date,RequiredDate,EmployeeNic,PatientNic,Total,Description) " + "VALUES ('" + obj.BillNo + "','" + obj.TimeDate + "','" + obj.RequiredDate + "','" + global.UserID + "','" + obj.Patientnic + "','" + obj.Total + "','" + obj.Description + "')"; getConnection(); SqlCommand cmd = new SqlCommand(query, getConnection()); cmd.ExecuteNonQuery(); SqlCommand cmd1 = new SqlCommand(sqlQuery, getConnection()); cmd1.ExecuteNonQuery(); getConnection().Close(); }
//**** add patient details to the database****// public void addPatient(bill obj) { String sqlQuery = "INSERT INTO dbo.Patient(PatientNic,Name,Dob,Gender,Address,Phone) " + "VALUES ('" + obj.Patientnic + "','" + obj.PatientName + "','" + obj.PatientDob + "','" + obj.PatientGender + "','" + obj.PatientAddress + "','" + obj.PatientContact + "')"; SqlCommand cmd1 = new SqlCommand(sqlQuery, getConnection()); cmd1.ExecuteNonQuery(); getConnection().Close(); }
private void guna2Button4_Click(object sender, EventArgs e) { if (name.Text.Trim() == string.Empty) { MessageBox.Show("Empty UserName Field!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else if (nic.Text.Trim() == string.Empty) { MessageBox.Show("Empty NIC Field!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else if (contact.Text.Trim() == string.Empty) { MessageBox.Show("Empty Contact Field!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else if (address.Text.Trim() == string.Empty) { MessageBox.Show("Empty Address Field!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else if (!male.Checked && !female.Checked && !other.Checked) { MessageBox.Show("Select Gender!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else if (paidAmount.Text.Trim() == string.Empty) { MessageBox.Show("Empty Paid Amount Field!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else { DialogResult answer; answer = MessageBox.Show("Are you sure want to Confirm Payment?", this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (answer == DialogResult.Yes) { try { //******patient database*****// DBconnection connection = new DBconnection(); string selectedGender = ""; if (male.Checked) { selectedGender = "Male"; } else if (female.Checked) { selectedGender = "Female"; } else { selectedGender = "Other"; } var dateOf = dob.Value; bill patientDetails = new bill(nic.Text, name.Text, dateOf.Date.ToString(), selectedGender, address.Text, Convert.ToInt32(contact.Text)); if (!connection.searchPatient(nic.Text)) { connection.addPatient(patientDetails); } //******bill database******// string billNumber = "B" + DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss.fff", CultureInfo.InvariantCulture); string date = DateTime.UtcNow.Date.ToString(); string requiredDate = rDate.Value.ToShortDateString(); double total1 = Convert.ToDouble(total.Text); bill billDetails = new bill(billNumber, date, requiredDate, global.UserID, nic.Text, total1, des.Text); connection.addInvoice(billDetails); //******report database******// foreach (global.reportStruct i in reportList) { report patientReport = new report(nic.Text, i.stReportNumber, i.stTest, i.stRequiredDate); DBconnection connection1 = new DBconnection(); connection1.Report(patientReport); } displayAvailableReports(); reportList.Clear(); clear(); } catch (Exception ex) { MessageBox.Show("Error:\n" + ex, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Console.WriteLine("Error:\n" + ex); } } } }