public DataTable ToDataTable<T>(List<T> items)
{
var tb = new DataTable(typeof(T).Name);
PropertyInfo[] props = typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance);
foreach (PropertyInfo prop in props)
{
Type t = GetCoreType(prop.PropertyType);
tb.Columns.Add(prop.Name, t);
}
foreach (T item in items)
{
var values = new object[props.Length];
for (int i = 0; i < props.Length; i++)
{
values[i] = props[i].GetValue(item, null);
}
tb.Rows.Add(values);
} return tb;
}
public static bool IsNullable(Type t)
{
return !t.IsValueType || (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(Nullable<>));
}
public static Type GetCoreType(Type t)
{
if (t != null && IsNullable(t))
{
if (!t.IsValueType)
{
return t;
}
else
{
return Nullable.GetUnderlyingType(t);
}
}
else
{
return t;
}
}
private void CollectionViewSource_Filter(object sender, FilterEventArgs e)
{
cgAssortment cgA = e.Item as cgAssortment;
bool isAccept = true;
if (cgA != null)
{
try
{
isAccept = isAccept && (!this.cbOnLink.IsChecked.Value || (this.cbOnLink.IsChecked == true && (cgA.Group5GUID == null)));
isAccept = isAccept && (!this.cbInMatrix.IsChecked.Value || (this.cbInMatrix.IsChecked == true && (cgA.InMatrix == true)));
isAccept = isAccept && (!this.dgGoodsAllF1.IsChecked.Value || (this.dgGoodsAllF1.IsChecked.Value && cgA.Code.ToString() == this.dgGoodsAllT1.Text));
isAccept = isAccept && (!this.dgGoodsAllF2.IsChecked.Value || (this.dgGoodsAllF2.IsChecked.Value && (cgA.NameLong.ToUpper().Contains(this.dgGoodsAllT2.Text.ToUpper()))));
isAccept = isAccept && (!this.dgGoodsAllF3.IsChecked.Value || (this.dgGoodsAllF3.IsChecked.Value && (cgA.cgGroup2.NameLong.ToUpper().Contains(this.dgGoodsAllT3.Text.ToUpper()))));
isAccept = isAccept && (!this.dgGoodsAllF4.IsChecked.Value || (this.dgGoodsAllF4.IsChecked.Value && cgA.cgGroup3 != null && (cgA.cgGroup3.NameLong.ToUpper().Contains(this.dgGoodsAllT4.Text.ToUpper()))));
isAccept = isAccept && (!this.dgGoodsAllF5.IsChecked.Value || (this.dgGoodsAllF5.IsChecked.Value && cgA.cgGroup4 != null && (cgA.cgGroup4.NameLong.ToUpper().Contains(this.dgGoodsAllT5.Text.ToUpper()))));
isAccept = isAccept && (!this.dgGoodsAllF6.IsChecked.Value || (this.dgGoodsAllF6.IsChecked.Value && cgA.cgGroup5 != null && (cgA.cgGroup5.NameLong.ToUpper().Contains(this.dgGoodsAllT6.Text.ToUpper()))));
isAccept = isAccept && (!this.dgGoodsAllF7.IsChecked.Value || (this.dgGoodsAllF7.IsChecked.Value && cgA.cgGroup6 != null && (cgA.cgGroup6.NameLong.ToUpper().Contains(this.dgGoodsAllT7.Text.ToUpper()))));
isAccept = isAccept && (!this.dgGoodsAllF8.IsChecked.Value || (this.dgGoodsAllF8.IsChecked.Value && cgA.cgGroup7 != null && (cgA.cgGroup7.NameLong.ToUpper().Contains(this.dgGoodsAllT8.Text.ToUpper()))));
isAccept = isAccept && (!this.dgGoodsAllF9.IsChecked.Value || (this.dgGoodsAllF9.IsChecked.Value && cgA.cgGroup8 != null && (cgA.cgGroup8.NameLong.ToUpper().Contains(this.dgGoodsAllT9.Text.ToUpper()))));
}
catch (Exception er )
{
MessageBox.Show(er.Message);
}
e.Accepted = isAccept;
}
}
select
g.gid,
g.name
from groups g
inner join groupmembers gm ON gm.memberId = 1 AND g.gid = gm.groupId
select
g.name,
COUNT(gm.id) as CountGM
from groups g
inner join groupmembers gm ON gm.memberId = 1 AND g.gid = gm.groupId
group by g.name
select
[ id пользователя]
ISNULL(U.ID, system.id] as [ID сообщения]
from tbl_notice N
left join user U ON U.ID=N.[id сообщения] and type="user"
left join Systems S ON S.ID=N.[id сообщения] and type="System"
declare @xdat xml
-- получаем xml-файл
SET @xdat = (SELECT [DataXml] FROM [TaskXml] where TaskDocGUID='1A91AED3-B5DF-4526-81E9-D54C16BB82A7')
if object_id('TempDb..#AllDataTable') > 0 drop table #AllDataTable
SELECT Product.ref.value('declare namespace pref="http://fsrar.ru/WEGAIS/ProductRef"; (pref:Type/text())[1]', 'nvarchar(50)') AS [Type]
,Product.ref.value('declare namespace pref="http://fsrar.ru/WEGAIS/ProductRef"; (pref:FullName/text())[1]', 'nvarchar(255)') AS FullName
,Product.ref.value('declare namespace pref="http://fsrar.ru/WEGAIS/ProductRef"; (pref:ShortName/text())[1]', 'nvarchar(64)') AS ShortName
,Product.ref.query('declare namespace pref="http://fsrar.ru/WEGAIS/ProductRef"; pref:Producer[1]') AS Producer
,Producer.ref.value('declare namespace oref="http://fsrar.ru/WEGAIS/ClientRef"; (oref:ClientRegId/text())[1]', 'nvarchar(50)') AS ClientRegIdProducer
,Producer.ref.value('declare namespace oref="http://fsrar.ru/WEGAIS/ClientRef"; (oref:INN/text())[1]', 'nvarchar(255)') AS INNProducer
INTO #AllDataTable
FROM @xdat.nodes('declare namespace rap="http://fsrar.ru/WEGAIS/ReplyAP";
declare namespace ns="http://fsrar.ru/WEGAIS/WB_DOC_SINGLE_01";
/ns:Documents/ns:Document/ns:ReplyAP/rap:Products/rap:Product') AS Product(ref)
CROSS APPLY Product.ref.nodes('declare namespace pref="http://fsrar.ru/WEGAIS/ProductRef"; pref:Producer') AS Producer(ref)
SELECT * FROM #AllDataTable
-- формируем докумет
DECLARE @xdat XML = (
SELECT TOP 5 GUID
,StatusDoc
FROM V_EGAIS.dbo.ActChargeOnHeader
FOR XML path('List')
,ROOT('Document')
,ELEMENTS
,type
)
-- ниже пример того что получилось
-- <Document>
-- <List>
-- <GUID>7F705894-441F-4B59-B6C4-0003579AE9BA</GUID>
-- <LDM>2016-02-04T15:58:01.650</LDM>
-- </List>
-- <List>
-- <GUID>D6EADAEB-AD45-4EB9-962D-0003B82CB431</GUID>
-- <LDM>2016-02-04T15:59:51.723</LDM>
-- </List>
-- <List>
-- <GUID>84BA1332-7C1F-4BAB-9923-0003D4B2CD7A</GUID>
-- <LDM>2016-02-04T15:58:57.443</LDM>
-- </List>
-- <List>
-- <GUID>A56EF787-3549-43DD-99E8-00043ED70C11</GUID>
-- <LDM>2016-02-04T15:56:59.223</LDM>
-- </List>
-- <List>
-- <GUID>16939553-7927-4221-B260-00044EBC225F</GUID>
-- <LDM>2016-02-04T15:57:29.297</LDM>
-- </List>
--</Document>
-- теперь производим выборку
SELECT Document.ref.value('(GUID/text())[1]', 'nvarchar(255)') AS [GUID]
,Document.ref.value('(StatusDoc/text())[1]', 'int') AS StatusDoc
FROM @xdat.nodes('/Document/List') AS Document(ref) -- тут мы показываем с какого раздела можно начинать брать данные.
void ToExcel(DataTable dt1)
{
try
{
Excel.Application EoXL;
Excel._Workbook EoWB;
Excel._Worksheet EoSheet;
Excel.Range excelRange;
EoXL = new Excel.Application();
EoXL.Visible = false;
EoWB = EoXL.Workbooks.Add(Type.Missing);
int TabRows = 1;
EoSheet = (Excel.Worksheet)EoWB.Worksheets.get_Item(1);//ссылка на лист excel
EoSheet.Name = "Отчет о кодах возвратных накладных";
EoSheet.PageSetup.Orientation = Excel.XlPageOrientation.xlLandscape;
int row = dt1.Rows.Count;
int col = dt1.Columns.Count;
EoSheet.Cells[1, 1] = "Префиксы возвратных накладных и счетов фактур подразделений";
EoSheet.Cells[1, 1].VerticalAlignment = Excel.XlVAlign.xlVAlignCenter;
EoSheet.Cells[1, 1].Font.Bold = true;
EoSheet.Cells[1, 1].Font.Size = 16;
// передаем первую таблицу, заполняем ее в памяти и передаем целиком
object[,] dataExport = new object[row, col];
for (int i = 0; i < row; i++)
{
for (int j = 0; j < col; j++)
{
dataExport[i, j] = dt1.Rows[i][j];
}
}
excelRange = EoSheet.Range[EoSheet.Cells[2 + TabRows, 1], EoSheet.Cells[row + 1 + TabRows, col]];
excelRange.set_Value(Excel.XlRangeValueDataType.xlRangeValueDefault, dataExport);
excelRange.Borders.ColorIndex = 0;
//этот кусок в качестве примера указания типа данных в ячейках
// excelRange = EoSheet.Range[EoSheet.Cells[2 + TabRows, 8], EoSheet.Cells[row + 1 + TabRows, 10]];
// excelRange.NumberFormat = "#,##0.00";
// формируем заголовок
ArrayList displayColumnExsel = new ArrayList();
foreach (DataColumn c in dt1.Columns)
{
displayColumnExsel.Add(c.ColumnName);
}
object[] dataExportH = new object[col];
for (int i = 0; i < col; i++)
dataExportH[i] = displayColumnExsel[i];
excelRange = EoSheet.Range[EoSheet.Cells[1 + TabRows, 1], EoSheet.Cells[1 + TabRows, col]];
excelRange.set_Value(Excel.XlRangeValueDataType.xlRangeValueDefault, dataExportH);
excelRange.Font.Bold = true;
excelRange.WrapText = true;
excelRange.Borders.ColorIndex = 0;
excelRange.VerticalAlignment = Excel.XlVAlign.xlVAlignCenter;
excelRange.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
EoXL.Visible = true;
}
catch (Exception er)
{
MessageBox.Show(er.Message, "Ошибка метода переноса таблиц", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
IF object_id('tempdb..#TableId') is not NULL DROP TABLE #TableId
-- создаем временную таблицу с id-заданий на перезагрузку кассы
SELECT tt.id as Targid
INTO #TableId
FROM [SES].[dbo].[TransferTargets] tt
INNER JOIN [SES].[dbo].[Cashes] cs
On tt.Targetid = cs.number and tt.TargetType = 1
-- заполнение таблицы заданий на ребут
INSERT SES.dbo.TransferCmd
(TransferType, DataId, Operation, TargetId, Data, ContextId)
SELECT
131, 0, 0, Targid, 'REBOOTCASH|TASK=0,1;QUEST=2', 0
FROM #TableId
IF object_id('tempdb..#TableId') is not NULL DROP TABLE #TableId