I have a table in SQLserver with some values as following
+----------+------+-------+-------+-----+--------+
| MonTime | Temp | Steam | Water | Air | Vacuum |
+----------+------+-------+-------+-----+--------+
| 16:08:08 | 0 | 38 | 57 | 76 | 95 |
| 16:09:08 | 9 | 28 | 47 | 66 | 85 |
| 16:10:08 | 18 | 37 | 56 | 76 | 95 |
| 16:11:08 | 9 | 28 | 47 | 66 | 85 |
| 16:12:08 | 9 | 28 | 47 | 66 | 85 |
| 16:13:08 | 18 | 37 | 56 | 75 | 94 |
| 16:14:08 | 9 | 28 | 47 | 66 | 85 |
+----------+------+-------+-------+-----+--------+
I need to create a line chart in winform application. where x is timeline "MonTime" and y is values and a line for each col "Temp, Steam, Water, etc"
I don't know how to accomplish this. Any help??
Thanks for your support. The problem was with the MonTime datatype "Time(0)" this datatype is not supported by Chart control . I converted it to datetime in SQL and then set it up as Time in chart control X value type.
Related
I need to retrieve all Ids from two columns, which doesnt contain some other list.
For example:
If I have a variable:
I need to select List of rows in All notifications by DeliveryTypeId and NotificationGroupId where those IDs not contained in pair combination in selected notifications.
var selectedNotifications = _dbContext.UserNotificationTypeDeliveryChoice.Include(m => m.NotificationGroup)
.Include(m => m.DeliveryType)
.Where(m => m.UserDefId == userDefId && m.UserTypeId == (int)userType)
.Select(m => new NotificationGroup()
{
NotificationGroupId = m.NotificationGroup.NotificationGroupId,
Name = m.NotificationGroup.Name,
DefaultDeliveryType = new DeliveryType()
{
DeliveryTypeId = m.DeliveryType.DeliveryTypeId,
Name = m.DeliveryType.Name,
HasChoosen = true
}
}).ToList();
var selectedNotificationsMatchingIds = selectedNotifications.Select(n => new { n.NotificationGroupId, n.DefaultDeliveryType.DeliveryTypeId }).ToList();
and I need a condition witch will take all rows from db where is !contains.
example:
//NotificationGroup Codelist
+---------------------+-------------+-----------------------+
| NotificationGroupId | Name | DefaultDeliveryTypeId |
+=====================+=============+=======================+
| 1 | Comments | 1 |
+---------------------+-------------+-----------------------+
| 2 | QA | 1 |
+---------------------+-------------+-----------------------+
| 3 | Services | 1 |
+---------------------+-------------+-----------------------+
| 4 | eScheduling | 1 |
+---------------------+-------------+-----------------------+
| 5 | eDelivery | 2 |
+---------------------+-------------+-----------------------+
//Delivery Type Codelist
+----------------+-----------------+
| DeliveryTypeId | Name |
+================+=================+
| 1 | SMS |
+----------------+-----------------+
| 2 | Email |
+----------------+-----------------+
| 3 | PortalMessaging |
+----------------+-----------------+
//SELECTED NOTIFICATIONS
+--------------------------------------+-----------+----------------------------+---------------------+----------------+------------+
| UserNotificationTypeDeliveryChoiceId | UserDefID | UserCompanyOrInstitutionId | NotificationGroupId | DeliveryTypeId | UserTypeId |
+======================================+===========+============================+=====================+================+============+
| 269 | 2933 | NULL | 1 | 2 | 1 |
+--------------------------------------+-----------+----------------------------+---------------------+----------------+------------+
| 270 | 2933 | NULL | 2 | 2 | 1 |
+--------------------------------------+-----------+----------------------------+---------------------+----------------+------------+
| 271 | 2933 | NULL | 3 | 2 | 1 |
+--------------------------------------+-----------+----------------------------+---------------------+----------------+------------+
| 272 | 2933 | NULL | 4 | 2 | 1 |
+--------------------------------------+-----------+----------------------------+---------------------+----------------+------------+
| 273 | 2933 | NULL | 4 | 1 | 1 |
+--------------------------------------+-----------+----------------------------+---------------------+----------------+------------+
//ALL NOTIIFICATIONS
+-----------------------------+-------------------------------+------------+---------------------+------------------------+-------------------------+----------------+
| NotificationGroupUserTypeId | NotificationGroupChangeTypeId | UserTypeId | NotificationGroupId | NotificationTemplateId | DateCreated | DeliveryTypeId |
+=============================+===============================+============+=====================+========================+=========================+================+
| 1 | NULL | 1 | 1 | 14 | NULL | 1 |
+-----------------------------+-------------------------------+------------+---------------------+------------------------+-------------------------+----------------+
| 6 | 11 | 1 | 4 | 21 | 2011-07-18 11:13:23.543 | 2 |
+-----------------------------+-------------------------------+------------+---------------------+------------------------+-------------------------+----------------+
| 17 | NULL | 1 | 4 | 6 | NULL | 2 |
+-----------------------------+-------------------------------+------------+---------------------+------------------------+-------------------------+----------------+
| 26 | NULL | 1 | 3 | 8 | NULL | 2 |
+-----------------------------+-------------------------------+------------+---------------------+------------------------+-------------------------+----------------+
| 30 | 11 | 1 | 4 | 15 | 2011-07-17 13:16:36.897 | 1 |
+-----------------------------+-------------------------------+------------+---------------------+------------------------+-------------------------+----------------+
| 31 | 14 | 1 | 4 | 16 | 2011-07-17 13:17:00.880 | 1 |
+-----------------------------+-------------------------------+------------+---------------------+------------------------+-------------------------+----------------+
| 32 | 15 | 1 | 4 | 17 | 2011-07-17 13:17:18.220 | 1 |
+-----------------------------+-------------------------------+------------+---------------------+------------------------+-------------------------+----------------+
| 33 | 16 | 1 | 4 | 18 | 2011-07-17 13:17:34.833 | 1 |
+-----------------------------+-------------------------------+------------+---------------------+------------------------+-------------------------+----------------+
| 34 | 17 | 1 | 4 | 19 | 2011-07-17 13:17:58.337 | 1 |
+-----------------------------+-------------------------------+------------+---------------------+------------------------+-------------------------+----------------+
| 35 | 18 | 1 | 4 | 20 | 2011-07-17 13:18:35.960 | 1 |
+-----------------------------+-------------------------------+------------+---------------------+------------------------+-------------------------+----------------+
| 36 | 14 | 1 | 4 | 22 | 2011-07-18 16:00:27.320 | 2 |
+-----------------------------+-------------------------------+------------+---------------------+------------------------+-------------------------+----------------+
| 37 | 15 | 1 | 4 | 23 | 2011-07-18 16:01:17.843 | 2 |
+-----------------------------+-------------------------------+------------+---------------------+------------------------+-------------------------+----------------+
| 38 | 16 | 1 | 4 | 24 | 2011-07-18 16:01:36.300 | 2 |
+-----------------------------+-------------------------------+------------+---------------------+------------------------+-------------------------+----------------+
| 39 | 17 | 1 | 4 | 25 | 2011-07-18 16:01:55.923 | 2 |
+-----------------------------+-------------------------------+------------+---------------------+------------------------+-------------------------+----------------+
| 40 | 18 | 1 | 4 | 26 | 2011-07-18 16:02:12.607 | 2 |
+-----------------------------+-------------------------------+------------+---------------------+------------------------+-------------------------+----------------+
| 41 | 8 | 1 | 3 | 27 | 2011-11-09 12:59:51.307 | 2 |
+-----------------------------+-------------------------------+------------+---------------------+------------------------+-------------------------+----------------+
| 44 | 19 | 1 | 3 | 28 | 2011-12-21 14:57:31.780 | 2 |
+-----------------------------+-------------------------------+------------+---------------------+------------------------+-------------------------+----------------+
| 48 | 20 | 1 | 5 | 29 | 2011-12-23 10:19:16.840 | 2 |
+-----------------------------+-------------------------------+------------+---------------------+------------------------+-------------------------+----------------+
| 49 | 1 | 1 | 3 | 6 | 2011-12-22 16:09:15.047 | 2 |
+-----------------------------+-------------------------------+------------+---------------------+------------------------+-------------------------+----------------+
So I am getting in selectedNotifications correct pairs, but then when I try to filter my new query, I m getting only two pairs but I should get it (with these example):
var notSelectedNotifications = _dbContext.NotificationGroupUserType.Include(m => m.DeliveryType)
.Include(m => m.NotificationGroup)
.Where(m => m.UserTypeId == (int)userType)
.Where(m => !selectedNotificationsMatchingIds.Contains(new { m.NotificationGroup.NotificationGroupId, m.DeliveryType.DeliveryTypeId }))
.Select(m => new NotificationGroup()
{
NotificationGroupId = m.NotificationGroupId,
Name = m.NotificationGroup.Name,
DefaultDeliveryType = new DeliveryType()
{
DeliveryTypeId = m.DeliveryType.DeliveryTypeId,
Name = m.DeliveryType.Name,
HasChoosen = false
}
}).ToList();
Any advise is welcomed. If someone can tell me, how to get all of these which is not selected in selectedNotificationsMatchingIds
The Contains() method usage default equality comparer when implementation of IEqualityComparer<T> is not provided for element stored in collection. Obviously the default equality comparer will not work for element of Anonymous class stored in selectedNotificationsMatchingIds.
You have two options:
Option 1: Re-write Where condition to use Any as:
//.Where(m => !selectedNotificationsMatchingIds
// .Contains(new { m.NotificationGroup.NotificationGroupId,
// m.DeliveryType.DeliveryTypeId }))
.Where(m => !selectedNotificationsMatchingIds
.Any(c => c.NotificationGroup.NotificationGroupId == m.NotificationGroupId
&& c.DeliveryTypeId == m.DeliveryType.DeliveryTypeId))
Option 2: Create a class having properties for NotificationGroupId and DeliveryTypeId and implement IEqualityComparer<T> interface for it. Then only you can use object of that class as part of .Contains() method.
I have a Visual Studio Program where the user enters specific data of production for that day. Example:
Date | Part Number | Mold Num | Machine Num | Total Parts |Cycle
2/12/2016 | 1185-5B8 | 6580 | 12 | 220 | 56
2/12/2016 | 2249300 | 7797 | 36 | 600 | 13
2/12/2016 | 146865 | 5096789 | 56 | 500 | 15
2/16/2016 | 123456 | 7787 | 54 | 300 | 34
2/16/2016 | 123456 | 787 | 54 | 360 | 36
2/16/2016 | 123456 | 777 | 54 | 500 | 46
2/16/2016 | 123456 | 87 | 54 | 400 | 44
I'm trying to have people enter production data and then manipulate it in order to get the machine usage (MU) (Equation: Total Parts/(3600/Cycle). I want to get these things for each day and for a specific month when I call it. I looked at what others have done but they are just counting how many are in a specific date but I need to multiply, and divide other columns together in two different tables with the same dates in order to get what I need.
Example output:
2/12/2016: MU = 41.12%
2/16/2016: MU = 24.79%
February: MU = 32.96%
EDIT:
I would like to do something in the lines of this example but I do not know how to implement it to an already existing DataSet.
Grouping and Sum Datatable by two fields with different Where conditions
or this example:
Calculating percentage of a groups from datatable
I'm new to ASP.NET, I have only experiences in C# Windows Form and SQL Server. Now I have starting my new project in ASP.NET MVC and already have database from my customer. It has two model included some same column name like this:
Table 1
---------------------------------
| Location | Item | Model | Tag |
---------------------------------
| 1 | 10 | A5 | 221 |
| 2 | 10 | A6 | 233 |
| 3 | 12 | A8 | 332 |
| 4 | 15 | C1 | 223 |
Table 2
-------------------------------------------------
| Location | Item | Model | Tag | DWeek | DYear |
-------------------------------------------------
| 1 | 10 | A5 | 221 | 01 | 15 |
| 2 | 10 | A6 | 233 | 01 | 15 |
| 3 | 12 | A8 | 332 | 02 | 15 |
| 4 | 15 | C1 | 223 | 03 | 15 |
I just want to show the data which have same Location and Item in one table, I don't know how to query in Entity framework, I have only know how to code by SQL, and I think it seem to be like this:
select
r.Location
,r.Item
,d.Location
,d.Item
,d.DWeek
,d.DYear
,r.Model
,r.[Tag No]
,d.[Tag No]
from Register r, Due d
where r.Location = d.Location
and r.Item = d.Item
My question is how to query like this in Entity framework for show data in a view, and is it possible to update and create two model in the same time?
I am using Lambda Expression
var Query=Register.Join(Due,r=>r.Location,d=>d.Location,(r,d)=>new {r,d}).Where(
X=>X.r.Location = X.d.Location && X.r.Item = X.d.Item).Select(X=>new {
LOCATION_1 =X.r.Location;
ITEM_1=X.r.Item;
LOCATION_2=X.d.Location;
ITEM_2=X.d.Item;
DWEEK=X.d.DWeek;
DTEAR=X.d.DYear;
MODEL=X.r.Model;
TAGNO_1=X.r.Tag_No;
TAGNO_1=X.d.Tag_No;
}).ToList();
I know this seems like a very basic question but it isn't; I can't use SQL Server pivot because I don't want SUM, I just want to transpose.
How can I transpose SQL data either in SQL query on in C# LINQ? Which is the fastest?
General data
| Company | Product | Count |
|---------|---------|-------|
| Cloud | Nokia | 10 |
| Cloud | Samsung | 30 |
| Cloud | Sony | 42 |
| Coms | Apple | 34 |
| Coms | Nokia | 39 |
| Coms | Samsung | 11 |
| Coms | Sony | 22 |
| RP | Nokia | 22 |
| RP | Samsung | 29 |
| RP | Sony | 22 |
Into this:
| Company | Nokia | Samsung | Sony | Apple |
|---------|-------|---------|------|--------|
| Cloud | 10 | 30 | 42 | 0 |
| Coms | 39 | 11 | 22 | 34 |
| RP | 22 | 29 | 22 | 0 |
This query:
SELECT
Company
, [Nokia]
, [Samsung]
, [Sony]
, [Apple]
FROM
YourTable
PIVOT (
MAX(Count) FOR Product IN ([Nokia], [Samsung], [Sony], [Apple])
)
AS p
Will produce:
| COMPANY | NOKIA | SAMSUNG | SONY | APPLE |
|---------|-------|---------|------|--------|
| Cloud | 10 | 30 | 42 | (null) |
| Coms | 39 | 11 | 22 | 34 |
| RP | 22 | 29 | 22 | (null) |
SQLFiddle Demo
I would like to divide a worksheet into multiple files.
I have a worksheet with about 10,000 rows. there is fancy formatting, conditional formatting, nice colors, and I want to preserve all of these attributes.
I need to divide this worksheet up.
the input would be:
+-------+----+----+----+----+
| Alex | 45 | 6 | 23 | 56 |
| Alex | 61 | 47 | 56 | 56 |
| Liza | 49 | 70 | 34 | 37 |
| Alex | 33 | 30 | 22 | 39 |
| Tommy | | 66 | 62 | 29 |
| Liza | | 38 | 49 | 80 |
| Alex | 23 | 56 | 56 | 39 |
| Liza | 32 | 46 | 40 | 43 |
| Liza | | 90 | 24 | 38 |
| Tommy | 38 | 10 | 52 | 23 |
| Nancy | 35 | 36 | 23 | 25 |
+-------+----+----+----+----+
and the output would be separate files like this (please keep in mind i want to preserve all the fancy formatting, and thus the solution has work directly with excel, and not with just CSV (because csv cannot retain formatting))
end products:
+------+----+----+----+----+
| | | | | |
| Alex | 45 | 6 | 23 | 56 |
| Alex | 61 | 47 | 56 | 56 |
| Alex | 33 | 30 | 22 | 39 |
| Alex | 23 | 56 | 56 | 39 |
+------+----+----+----+----+
and
+------+----+----+----+----+
| | | | | |
| Liza | 49 | 70 | 34 | 37 |
| Liza | | 38 | 49 | 80 |
| Liza | 32 | 46 | 40 | 43 |
| Liza | | 90 | 24 | 38 |
+------+----+----+----+----+
and
+-------+----+----+----+----+
| | | | | |
| Nancy | 35 | 36 | 23 | 25 |
+-------+----+----+----+----+
and
+-------+----+----+----+----+
| | | | | |
| Tommy | | 66 | 62 | 29 |
| Tommy | 38 | 10 | 52 | 23 |
+-------+----+----+----+----+
the solution can be a combination of VBA/.NET. please note that i need multiple files as outputs.
what is the quickest way to get this working? thanks so much for any input!
please note that this is excel 2007 and later
I done this before.
You can use this code:
Option Explicit
Sub getInformations()
Dim varName As String
Application.ScreenUpdating = False
'Replace Tabelle1 with the name of your sheet where the Informations are
Worksheets("Tabelle1").Select
Worksheets("Tabelle1").Copy After:=Sheets("Tabelle1")
Sheets("Tabelle1 (2)").Select
Sheets("Tabelle1 (2)").Name = "Temp"
Do Until Range("A1").Value = vbNullString
varName = Range("A1").Value
Workbooks.Add
'Change the Path where you want to save the File
ActiveWorkbook.SaveAs ("C:\Documents and Settings\vgellhom\Desktop\" & varName & ".xls")
'Change The Name of the Excel Workbopk to the Name of the Workbook with the Names
Workbooks("Data.xls").Activate
Sheets("Temp").Select
varName = Range("A1").Value
Do While True
Cells.Find(What:=varName).Activate
Range(ActiveCell.Row & ":" & ActiveCell.Row).Select
Selection.Copy
Workbooks(varName & ".xls").Activate
ActiveSheet.Paste
ActiveCell.Offset(1, 0).Activate
'Change The Name of the Excel Workbopk to the Name of the Workbook with the Names
Workbooks("Data.xls").Activate
Sheets("Temp").Select
Selection.Delete Shift:=xlUp
If Not Cells.FindNext(After:=ActiveCell) Is Nothing Then
Cells.Find(What:=varName).Activate
Else
Exit Do
End If
Loop
Workbooks(varName & ".xls").Activate
'Change the Path where you want to save the File
Application.DisplayAlerts = False
ActiveWorkbook.Save
Application.DisplayAlerts = True
Workbooks(varName & ".xls").Close
Loop
Application.DisplayAlerts = False
Sheets("Temp").Delete
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
Hope that helps you...
Since Excel formatting is usually a big pain in the a**, I would recommend to try a following solution:
Calculate and store all the unique keys.
Create a copy of a file for each key (like file_Alex.xls[x], file_Liza.xls[x] and so on).
Process each file, deleting all non-key rows, thus all key entries are left. Also because you are only deleting entire rows all the formatting in file is retained.
This is very unoptimized, but also extremely simple solution. If it's a one-time job, it should do just fine.