I am creating a booking system in which a member of staff will take customer details and input them into a database table called 'Customers'. Each customer is identified uniquely with a customer ID. I have another table in the database called 'Bookings' (both tables are in the same database). I created a 'Make new Booking' form in which the staff member will input 7 details of the booking (customerID, TypeOfBooking, DateOfBooking, TimeOfBooking, StaffID, DepositPaid, NumberInBooking). In an hour, there can only be one booking and a maximum of 9 bookings a day. I'm currently using a dateTime Picker to choose the date and time that a customer can have a booking. My problem is that I'm not sure what code I would use to validate this to ensure there is only one booking an hour and 9 bookings a day?
The code I would be using would be in a click event on a button called 'btnAdd'.
As of currently there is no code in this click event as I am not sure what code would be used to validate this.
Thanks
Related
I want to register and track user activities in the program. What is your suggestion? Through the database or on the program side?
On the database side, you can create triggers for changes to each table, but how can you use the username as a data retrieval record?
The program is being written with WpF and the database with SQL 2014
For better understanding, consider following scenario.
I have a table named "product" and a table named "companies". From the business logic we want to assign products to companies, which we ended up in a table "company_product". Now when a user insert new product and simultaneously assign it's companies, 2 table will be affected (the same goes for delete and update): "product" and "company_product" and we want to know:
what's inserted?
what's deleted?
what's updated to what?
And who has made these changes?
I always set up a "TransactionLog" table that has columns like:
TransactionId
UserId
Context
Details
TransactionDatetime
The combination of the User ID, Context and Details fields will allow you to capture all the details about what was done by what user. Keep Context shorter, something like a varchar(50), that is used for grouping but you can make Details varchar(max) if needed.
You can also add an additional context field if needed. Something like "Action" can be used to capture "update", "delete" or "create". For this, I would use "Context" to capture the name of the object that was being saved.
i make an example for easy explain the question>>
I have 2 tables "LOAN" and "FINE"
Attributes of LOAN are: IDLoan(INT), IDUser(INT), IDBook(INT), Date(DATETIME).
Attributes of FINE are: IDFine(INT), IDLoan(INT), Date(DATETIME).
I want my program create the new register automatically in table "FINE", if it has any LOAN DATA that is expired of date(loan 3 days only).
1)... How can i do it to increase DATE of LOAN automatic?...
Do i need to update this attribute constantly??
2)i know, i need to do this for condition>>
var LOANS = from loan in db.Loan select loan;
LOANS = LOANS.Where(s=>s.Date.Contains(DATE.NOW));
IF(LOANS!=NULL)
and..... Create REGISTER IN TABLE FINE.....etc.
have some example??
thanks all!! :)
I think what you need is to create a SQL Job that runs every x amount of time and checks the LOAN table for expired records and creates a record in the FINE table if they haven't been created yet.
No need to update anything inside the LOAN table, just create a Stored Procedure that the Job will run, inside the Stored Procedure you can put something like
INSERT INTO FINE (IDLoan, Date)
SELECT IDLoan, GETDATE()
FROM LOAN L
LEFT JOIN FINE F ON F.IDLoan = L.IDLoan
WHERE (L.Date >= DATEADD(DD,-3,GETDATE()) AND F.IDLoan IS NULL
Obviously this will vary according to your business rules, in this case the query inserts records into the FINE table for all Loans with a date older than 3 days as of now that have not been added previously.
All you need to do is specify how often the job will run and it will take care of this without you needing to create any triggers or constraints in the tables.
Working on booking management application. It allows the user to book the appointment with the doctor. However, a doctor can also able to schedule their activity like Lunch Visiting Hours and Vocation.
Doctor can block activity as recurring based on frequency(daily/weekly/monthly) set in table
Referred How to design table structure for Google Calendar like Repeat feature?
For example
From 2-Aug-2013 to 31-Aug-2013 , Lunch hour is 2 P.M to 3 P.M
From 14-Aug-2013 to 16-Aug-2013 Vocation
From 2-Aug-2013 to 31-Aug-203 Visiting Hours is 10 A.M to 2 P.M
Also they can able to repeat the same activity for next month.
How do i create table structure for maintaining this data more efficiently.
Here is my approach
DoctorId Activity FromDateTime ToDateTime Frequency
What would the great way to store the frequency column format in Database in order to easily access in C# code to generate more number of same records for different dates based on weekly/monthly?
Assuming you want a table structure that allows users to book appointments with doctors (as opposed to helping doctors manage their schedules, as the question seems to imply both at various times), we don't want to design a table that tells users what the doctor is doing. A user should only be concerned with whether a doctor is available or not - why do they need to know the doctor is on vacation? Simply seeing the doctor doesn't have openings for a week or two should be enough. The below shows a simplified table structure of this: a reference table for the doctor's names, that where DoctorID would be the join to show the doctor's name and his/her available hours.
To solve the problem of a user booking an appointment, the user would see the doctors with available times and times would be arranged in a DATETIME format so that they could schedule at the appropriate hour with the doctor. If the doctor isn't available, a time wouldn't appear for them on a specific date (meaning that users select which block of time they want - as shown in the below simple example):
CREATE TABLE Doctor(
DoctorID INT,
DoctorName VARCHAR(250)
)
CREATE TABLE Appointment(
DoctorID INT,
AppointmentHour DATETIME,
Available BIT DEFAULT 1
)
INSERT INTO Doctor
VALUES (1,'John Doe')
, (2,'Jane Doe')
INSERT INTO Appointment (DoctorID, AppointmentHour)
VALUES (1,'2013-01-01 10:00:00.000')
, (1,'2013-01-01 11:00:00.000')
, (1, '2013-01-01 13:00:00.000')
, (1, '2013-01-01 14:00:00.000')
, (2, '2013-01-01 15:00:00.000')
SELECT d.DoctorName
, a.AppointmentHour
, a.Available
FROM Appointment a
INNER JOIN Doctor d ON a.DoctorID = d.DoctorID
DROP TABLE Doctor
DROP TABLE Appointment
SQLFiddle showing this example. On the other hand, if you want to build an application for doctors to set their own schedule, that could work in a similar way where doctors would enter the times they will be available and then, as shown in the simple structure above this, the user would see those available times only (when they select a time, the Available column turns to 0 - meaning it won't display in the C# application). For instance:
UPDATE Appointment
SET Available = 0
WHERE AppointmentHour = #UserSelection --OR: #DoctorVacation/#DoctorLunch/#DoctorOther
Would be an example of the SQL statement when a user selected a time (now, other users can't select it). For the doctors, there could be a default time, like 8 AM to 5 PM where a doctor is assumed to be available, unless they decided that they won't be (in which case, those times would be removed from the appointment table, or they could also be set to 0 so that they don't appear on the application, so that users can't select those times).
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
create sql table programmatically
So for my project, I need to create a a roster table (which includes a list of employees and their hours for the week, Saturday to Friday). However, I have no idea how to add this specific table to the database. I am aware how to add specific fields from a textbox to my sql server database, but I just cannot save a table to a database! The idea is to add these weekly roster tables to the database.
Any help will be greatly appreciated.
You probably don't want to add a new table to the database for each roster, once per week. That will make historical queries (for example, the number of hours an employee worked for the last four weeks) much more difficult than they need to be. A better approach might be to use a couple of tables you create up front:
Rosters
-------
INT RosterId (or GUID, or whatever type of ID you want)
DATETIME Week
RosterRecords
-------------
INT RosterId
INT EmployeeID (or however employees are identified)
DECIMAL Hours
RosterId in Rosters links to RosterId in RosterRecords. You then just have a pile of roster records, one per employee per week/roster. Now you don't need to create new tables for each week programmatically; you just register a new roster in Rosters and create its members in RosterRecords; you can do a join later to associate a roster with its records if needed in a query.
Is there a way to only load the new or updated (edited) records in a table using Sql in C#?
Suppose i have a table which consists of 1000 student records.I want to show this information in a gridview ( this is just an example ) and upon adding or editing new entries,I want the gridview to get updated and show the latest changes to the table.If i go and have a
select *
statement ,This will definitely kill the application performance,So i thought its a good idea to try to add only those new records to the previously loaded records to the gridview.
But I'm clueless on the How to do such a task.
There is no other solution then simply architect you database.
Just one of many possible solutions: for every inserted or updated record in database you can have a timestamp. Having that information in database you can:
a) get the latest, from timestamp point of view, record in your DataGrid
b) get from darabase all reoirds that have timestamp bigger then it.
I repeat, this us just one of many possible solutions. What fits your requirements has to be decided by yourself.
Create a timestamp column and store the "last updated" date. Within your application, store the last time the data was retrieved from the database. Then, you can select only the records that have changed (or been added) since then.
The simplest way would be add a new field in the table such as ModifyDate of type datetime, and on insertion and updation of record put the current datetime in these field.
In that case you can select a query on the basis of this field as follows
Select Top 10 * from Table1 OrderBy ModifyDate desc