|
i am receiving Emplid in this action,
public ActionResult showDDL(int? EmplID = null)
{
ViewBag.EmplID = EmplID;
if (EmplID == null)
{
IEnumerable<GetAtdRecord_SpResult> EmployeeAtd_2 = DataContext.GetAtdRecord_Sp(0).ToList();
return View(EmployeeAtd_2);
}
else if (EmplID != null)
{
IEnumerable<GetAtdRecord_SpResult> EmployeeAtd_2 = DataContext.GetAtdRecord_Sp(EmplID).ToList();
return View(EmployeeAtd_2);
}
return View();
}
View:
@{
var grid = new WebGrid(ViewData.Model, defaultSort: "EmplID", rowsPerPage: 20);
}
@if (Model.Count > 0)
{
<div id="AllEmpGrid_ByName">
@grid.GetHtml(columns: grid.Columns(
grid.Column("EmplID", "Employee ID"),
grid.Column("EmplName", "Employee Name"),
grid.Column("ShiftID", "Shift ID"),
grid.Column("DateVisited", "Date of Visit"),
grid.Column("InTime", "In Time"),
grid.Column("TimeOut", "Time Out"),
grid.Column("OverTime", "Over Time"),
grid.Column("TotalWorkingTime", "Total Working Time")
))
</div>
using (Html.BeginForm("ToExcel", "Home", FormMethod.Get))
{
<button type="submit" class="button_form button_download" >Download in Excel</button>
}
}
else
{
<h2 class="error" >No Data Found</h2>
}
In same View you can see, button DOWNLOAD IN EXCEL, i want to pass this emplID to ToExcel method
public ActionResult ToExcel(int? empid )
{
var DataContext = new EmployeeRecordDataContext();
var grid = new GridView();
grid.DataSource = DataContext.GetAtdRecord_Sp(null).ToList();
grid.DataBind();
Response.ClearContent();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment; filename=AttendanceSheet.xls");
Response.ContentType = "application/ms-excel";
Response.Charset = "";
StringWriter sw = new StringWriter();
System.Web.UI.HtmlTextWriter htw = new System.Web.UI.HtmlTextWriter(sw);
grid.RenderControl(htw);
Response.Output.Write(sw.ToString());
Response.Flush();
Response.End();
return RedirectToAction("index");
}
i can't figure out that how to pass EmplID recieved in Action 'showDDL' to EmpID when i click Button "Download in Excel" ?
|
|
|
|
|
And what has this got to do with databases?
You'll stand more chance of getting an answer if you post your question in the correct forum[^].
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
This query shows emplName,emplID, totalworking time, InTime, OutTime, DateVisited, Overtime for an employee based on his InTime and Outime, that's OK. Now i am trying to modify it to show only emplID, EmplName, Total Working hours(Per month), total overtime (per month).
e.g.
Empid EmplName TotalWorkingHours TotalOvertime Month
00001 John 77:00 05:55 2013-02
00002 Masn 57:00 04:56 2013-02
Query:
with times as (
SELECT t1.EmplID
, t3.EmplName
, min(t1.RecTime) AS InTime
, max(t2.RecTime) AS [TimeOut]
, t4.ShiftId as ShiftID
, t4.StAtdTime as ShStartTime
, t4.EndAtdTime as ShEndTime
, cast(min(t1.RecTime) as datetime) AS InTimeSub
, cast(max(t2.RecTime) as datetime) AS TimeOutSub
, t1.RecDate AS [DateVisited]
FROM AtdRecord t1
INNER JOIN
AtdRecord t2
ON t1.EmplID = t2.EmplID
AND t1.RecDate = t2.RecDate
AND t1.RecTime < t2.RecTime
inner join
HrEmployee t3
ON t3.EmplID = t1.EmplID
inner join AtdShiftSect t4
ON t3.ShiftId = t4.ShiftId
group by
t1.EmplID
, t3.EmplName
, t1.RecDate
, t4.ShiftId
, t4.StAtdTime
, t4.EndAtdTime
)
SELECT
EmplID
,EmplName
,ShiftId As ShiftID
,InTime
,[TimeOut]
,convert(char(5),cast([TimeOutSub] - InTimeSub as time), 108) TotalWorkingTime
,[DateVisited]
,CASE WHEN [InTime] IS NOT NULL AND [TimeOut] IS NOT NULL THEN
CONVERT(char(5),CASE WHEN CAST([TimeOutSub] AS DATETIME) >= ShEndTime And ShiftID = 'S002' Then LEFT(CONVERT(varchar(12), DATEADD(ms, DATEDIFF(ms, CAST(ShEndTime AS DATETIME),CAST([TimeOutSub] AS DATETIME)),0), 108),5)
WHEN CAST([TimeOutSub] AS DATETIME) >= ShEndTime And ShiftID = 'S001' Then LEFT(CONVERT(varchar(12), DATEADD(ms, DATEDIFF(ms, CAST(ShEndTime AS DATETIME), CAST([TimeOutSub] AS DATETIME)),0), 108),5)
ELSE '00:00' END, 108)
ELSE 'ABSENT' END AS OverTime
FROM times order by EmplID, ShiftID, DateVisited
|
|
|
|
|
Just remove the columns you don't need and you should be good to go. Are you facing any issues?
|
|
|
|
|
sorry what ? i need sum of time per month sir
|
|
|
|
|
|
i have written this query to show total working time and overtime of an employee on particular date (if he has came) otherwise it doesn't show record for a person if his INTIME and TIMEOUT are empty but i don't want this now, i want if for a particular date person's INtime and OutTime are empty then put 00:00 in his intime, outtime, totalworkingtime, overtime.
e.g.
EmplID EmplName ShiftID intime Outtime totalworking overtime dateVisited
0000001 John S001 00:00 00:00 00:00: 00:00 2013-12-01
Query:
with times as (
SELECT t1.EmplID
, t3.EmplName
, min(t1.RecTime) AS InTime
, max(t2.RecTime) AS [TimeOut]
, t4.ShiftId as ShiftID
, t4.StAtdTime as ShStartTime
, t4.EndAtdTime as ShEndTime
, cast(min(t1.RecTime) as datetime) AS InTimeSub
, cast(max(t2.RecTime) as datetime) AS TimeOutSub
, t1.RecDate AS [DateVisited]
FROM AtdRecord t1
INNER JOIN
AtdRecord t2
ON t1.EmplID = t2.EmplID
AND t1.RecDate = t2.RecDate
AND t1.RecTime < t2.RecTime
inner join
HrEmployee t3
ON t3.EmplID = t1.EmplID
inner join AtdShiftSect t4
ON t3.ShiftId = t4.ShiftId
group by
t1.EmplID
, t3.EmplName
, t1.RecDate
, t4.ShiftId
, t4.StAtdTime
, t4.EndAtdTime
)
SELECT
EmplID
,EmplName
,ShiftId As ShiftID
,InTime
,[TimeOut]
,convert(char(5),cast([TimeOutSub] - InTimeSub as time), 108) TotalWorkingTime
,[DateVisited]
,CASE WHEN [InTime] IS NOT NULL AND [TimeOut] IS NOT NULL THEN
CONVERT(char(5),CASE WHEN CAST([TimeOutSub] AS DATETIME) >= ShEndTime And ShiftID = 'S002' Then LEFT(CONVERT(varchar(12), DATEADD(ms, DATEDIFF(ms, CAST(ShEndTime AS DATETIME),CAST([TimeOutSub] AS DATETIME)),0), 108),5)
WHEN CAST([TimeOutSub] AS DATETIME) >= ShEndTime And ShiftID = 'S001' Then LEFT(CONVERT(varchar(12), DATEADD(ms, DATEDIFF(ms, CAST(ShEndTime AS DATETIME), CAST([TimeOutSub] AS DATETIME)),0), 108),5)
ELSE '00:00' END, 108)
ELSE 'ABSENT' END AS OverTime
FROM times order by EmplID, ShiftID, DateVisited
|
|
|
|
|
Change your inner joins to outer joins
=========================================================
I'm an optoholic - my glass is always half full of vodka.
=========================================================
|
|
|
|
|
When building these type of query I break it down to getting the primary list (employees) and getting the data you are reporting (timesheet information) then I use a left outer join between the primary and data queries and use ISNULL to display the default values (00:00).
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hey guys
I have two tables
1- Holds the cars passed (CarId, DeviceId, PassDate)
2- Holds the List of Cameras capturing each car (DeviceID, DeviceName)
I want to check on a specific Date the maximum number of car passed in period(every 60 minutes, 2 hours …)
So I have to use a double loop the first for each device and the second for the period.
For(everydevice)
{
For(every period in the time)
}
The should look like this List
Device Name --------- Max Passed Cars
Since I’m new to oracle SQL Programming I dunno how to implement this, I appreciate it if you can help me out
|
|
|
|
|
You can do this in a single select query, grouping by deviceID, calculating Count(carId) with a where clause on the passdate between period start and period end
=========================================================
I'm an optoholic - my glass is always half full of vodka.
=========================================================
|
|
|
|
|
If i'm not mistaken this works when I want to get the maximum number, but here I want to see for example what is the maximum passed number of cars in every 60 minutes.
|
|
|
|
|
You can also add a grouping on the DatePassed column, formatted in such a way as to just display the date and hour
=========================================================
I'm an optoholic - my glass is always half full of vodka.
=========================================================
|
|
|
|
|
Chris Quinn wrote: I'm an optoholic
Actually, you mean optiholic because optimist is spelled with an 'i', not an 'o'.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
... but alcoholic is spelt with an o, not an i!
=========================================================
I'm an optoholic - my glass is always half full of vodka.
=========================================================
|
|
|
|
|
Touche!
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
I wish everyone was as clear in what they want.
WITH CTE AS (
SELECT CarId
,TO_CHAR(PassDate, 'YYYY-MM-DD HH24') AS hours
,TRUNC(PassDate, 'HH24') AS hours
,DeviceName
FROM cars c,devices d
WHERE c.DeviceID = d.DeviceID
)
SELECT Count(carID) Cars_passed
,hours
,devicename
FROM CTE
GROUP BY hourly
,devicename
<edit>Revisited and fixed so that hours remains the correct type</edit>
modified 5-Feb-14 1:44am.
|
|
|
|
|
Thanx. 
|
|
|
|
|
Today I have a question to make regarding the Roles.
Just because I’m confused around this issue I’d like to ask the following questions, and please I would like to receive clear and easy understandable answers. Not deep analyze.
1.What is the Roles for a programmer?
2.What is the role of the Schemas owned by this… which related with them?
3.What is the meaning and the use for Securables in Roles
4.Why we add Users to a Role?
5.How we may handle the Roles in conjunction with to the Users, inside of a project?
Thank you very much in advance.
|
|
|
|
|
Lefteris Gkinis wrote: 1.What is the Roles for a programmer? "SQL Server provides server-level roles to help you manage the permissions on a server. These roles are security principals that group other principals. Server-level roles are server-wide in their permissions scope. (Roles are like groups in the Windows operating system.)"
Source[^]
Lefteris Gkinis wrote: 2.What is the role of the Schemas owned by this… which related with them? "CREATE SCHEMA can create a schema, the tables and views it contains, and GRANT, REVOKE, or DENY permissions on any securable in a single statement."
Source[^]
Lefteris Gkinis wrote: 3.What is the meaning and the use for Securables in Roles "Securables are the resources to which the SQL Server Database Engine authorization system regulates access. For example, a table is a securable. Some securables can be contained within others, creating nested hierarchies called "scopes" that can themselves be secured. The securable scopes are server, database, and schema."
Source[^]
Lefteris Gkinis wrote: 4.Why we add Users to a Role? "Roles can simplify security administration in databases with a large number of users or with a complex security system."
Source[^]
Lefteris Gkinis wrote: 5.How we may handle the Roles in conjunction with to the Users, inside of a project?
That depends on the project, and it's specific needs. There's no alternative but to read the entire thing[^] - this isn't a topic that can be condensed to a few guidelines.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
hi,
am adding new record for every transaction,then how to get the last 3 transaction values.
|
|
|
|
|
It would be best to have a TIMESTAMP column that defaults to CURRENT_TIMESTAMP .. it is the only true predictive behavior you can find here.
The second-best thing you can do is ORDER BY ID DESC LIMIT 1 and hope the newest ID is the largest value.
check this also accessing-last-inserted-row-in-mysql[^]
Hope it will help..
|
|
|
|
|
Not only one record. there exist duplicates(Means no primary key)
get the last inserted 3 records for the same id
|
|
|
|
|
Member 10263519 wrote: am adding new record for every transaction,then how to get the last 3 transaction values You can't get them at transaction-level, as they don't exist at that level. A transaction can touch multiple tables, so those 3 "last values" might be all in different tables (or in the same record).
If you're trying to write an audit, look into triggers.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi,
I have a POS machine which is developed in C# .NET windows application and MySQL backend. The application will be installed locally on more than one outlet.
How can I make sure users in outlet won't mess with the database if any smart guy there! I though of hdoing it using MySQL users but I make a limited users then my applicaton won't be able to write to the database?
What can I do? What's your advise?
Thanks
Jassim
Technology News @ www.JassimRahma.com
|
|
|
|
|