如何在ASP.NET中实现日历布局逻辑,并使用MS SQL数据库实现C#
我在学校有这个项目,并且我创建了一个带有主页,会员注册,会员登录,会员登录,会员资料和管理员登录页面的项目,我想在我的主页上实现此布局用户已登录并能够在员工在家工作时可以选择日期,应该选择一个日期,然后插入数据库,供雇主查看谁在此特定日期或一天中在家中工作。
I have this project at school and I have created a project with homePage, member signUp, member Login, member profile, and Admin Login pages I want to implement this layout on my homepage when the user is logged in and be able to select dates when an employee is working from home should choose a date and insert into a database for the employer to see who is working from home on this specific date or day.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
continue
Well, if we break this down?
We need a listbox on the left side to display the Employee's
So, drop in a listbox, say like this:
And our code to load is thus this:
And now we have this:
Ok, now we need a calendar. Hum, ok, looking at outlook, we see that we need 6 rows of a "thing".
I think a simple Listview, and for each row (6 of them), we need a data table, with 1-7 days of data.
So, a simple list view, one row - but we spit out 6 of them.
and we want the calendar to be clickable, so each day will be a button - a LinkButton should work fine.
So, a list view could be like this:
Not a lot of markup.
Now, we need to load up the data, so we have this:
And the code to load up the calendar? A data table of 6 rows, and 7 columns, say like this code:
And we now have this:
Now, I did want to "gray" out the dates off this month, so in the Listview databound event (a great event for formatting grids or listview), then I put in this code
If the date ptr is outside of this month, we grey out the linkbutton.
so, this:
Ok, so now we have to add some code to highlight a square if this is a work at home date.
We have this data table:
So, after we load the Grid, then we click on a list view item.
That code is this:
So, we need a routine to now display (highlight) any record in the table based on employee id and the given date.
So this:
Now, that was a bit of code - but not too bad.
So, now we get this:
Ok, so now we need a click event for the square. If you click a empty square, we add a single row to the table, and if already highliged, we delete it.
So, that click event can be this:
Not bad! So, now you can click to highlight, or un-highlight a day. (it toggles the given square).
So, above should give you some ideas.
And the two helper routines I used was to get a data table.
And the other to setup the dates.
These:
and
So, it was a bit of code, but breaking down each part - into smaller bits and sizes? It was not really that hard.
Edit: the connection string
Well, the connection string is generally placed in the web.config file. However you can get visual studio to do that for you and it tends to be a whole lot easier.
So, from Visual studio, go project->"my project settings".
Say like this:
So, for things like maybe the welcome message, company name, perhaps to use some tax rate, or a bunch of typical settings that just about any and every applcation has?
Well, you can use the settings tab from above. so, say like this:
So, in above, I have My Cool Company name, and in code I can thus reference that setting. And note how I have multiple conneciton strings.
Using the above is nice, since if you choose to add a connection string, it not only means ONE PLACE in your whole application, but you can use the connection string builder to help you out.
Say, like this:
when you click on the [...], then you get this:
so, you get the connection wizard, and that makes setting up a connection a whole lot less hassile.
So, now in code, to get that string, you can use this:
Now, at the end of the day, if you go look at web.config, you see the settings in web.config, but that can be extra work, so using the above project settings is a just a great handy place to use and place all of the many settings you will have in any typical applcation.