public System.Data.DataTable JnOperationsByHouse(Server srv, System.DateTime dateBeg, System.DateTime dateEnd, CalcOperationGroup opGroup, Organization srvProvider, ServiceTypeOld srvType) { System.Data.DataTable table = new System.Data.DataTable(); System.Data.SqlClient.SqlConnection connection = new System.Data.SqlClient.SqlConnection(string.Format("Data Source = {0};Initial Catalog = {1};User ID={2};pwd={3}", new object[] { srv.IpAddress, srv.DbName, srv.UserName, srv.UserPwd })); try { connection.Open(); System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand("", connection); command.set_CommandTimeout(0); command.Parameters.Add("@fromDate", System.Data.SqlDbType.DateTime).set_Value(dateBeg); command.Parameters.Add("@toDate", System.Data.SqlDbType.DateTime).set_Value(dateEnd); command.Parameters.Add("@operGroupName", System.Data.SqlDbType.VarChar, 0xff).set_Value(opGroup.Name); command.Parameters.Add("@providerName", System.Data.SqlDbType.VarChar, 0xff).set_Value((srvProvider.Id == 0L) ? ((object) System.DBNull.Value) : ((object) srvProvider.ShortName)); command.Parameters.Add("@serviceTypeName", System.Data.SqlDbType.VarChar, 0xff).set_Value((srvType.Id == 0L) ? ((object) System.DBNull.Value) : ((object) srvType.ShortName)); command.set_CommandText("\r\n\t\t\t\t\tselect providerName srvProvider, serviceTypeName srvType, sum(summ) summ\r\n\t\t\t\t\t\t--, apartmentAddrName house\r\n\t\t\t\t\t\t, ( case when apartmentAddrLevel = 40 then sn.LocalAddress_ToString(apartmentParentAddrId, 0) \r\n\t\t\t\t\t\t\telse sn.LocalAddress_ToString(apartmentAddrId, 0) end ) house\r\n\t\t\t\t\tfrom sn.JnGroupView\r\n\t\t\t\t\twhere operGroupName=@operGroupName and\r\n\t\t\t\t\t\t period>=@fromDate and period<@toDate and\r\n\t\t\t\t\t\t (@providerName is null or @providerName=providerName) and\r\n\t\t\t\t\t\t (@serviceTypeName is null or @serviceTypeName=serviceTypeName)\r\n\t\t\t\t\tgroup by providerName, serviceTypeName, apartmentAddrLevel, apartmentParentAddrId, apartmentAddrId"); new System.Data.SqlClient.SqlDataAdapter(command).Fill(table); } finally { connection.Close(); } return table; }
public System.Data.DataTable JnOperations(Server srv, System.DateTime dateBeg, System.DateTime dateEnd, CalcOperationGroup opGroup, Organization srvProvider, ServiceTypeOld srvType) { System.Data.DataTable table = new System.Data.DataTable(); System.Data.SqlClient.SqlConnection connection = new System.Data.SqlClient.SqlConnection(string.Format("Data Source = {0};Initial Catalog = {1};User ID={2};pwd={3}", new object[] { srv.IpAddress, srv.DbName, srv.UserName, srv.UserPwd })); try { connection.Open(); System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand("", connection); command.set_CommandTimeout(0); command.Parameters.Add("@operGroup", System.Data.SqlDbType.VarChar, 0xff).set_Value(opGroup.Name); command.Parameters.Add("@fromDate", System.Data.SqlDbType.DateTime).set_Value(dateBeg); command.Parameters.Add("@toDate", System.Data.SqlDbType.DateTime).set_Value(dateEnd); command.Parameters.Add("@serviceProvider", System.Data.SqlDbType.VarChar, 0xff).set_Value((srvProvider.Id == 0L) ? ((object) System.DBNull.Value) : ((object) srvProvider.ShortName)); command.Parameters.Add("@serviceType", System.Data.SqlDbType.VarChar, 0xff).set_Value((srvType.Id == 0L) ? ((object) System.DBNull.Value) : ((object) srvType.ShortName)); command.set_CommandText("\r\n\t\t\t\t\tif object_id('tempdb..#t') is not null drop table #t\r\n\r\n\t\t\t\t\tselect ' '+srvProvider srvProvider, \r\n\t\t\t\t\t\t' '+houseHolder houseHolder, \r\n\t\t\t\t\t\t' '+srvType srvType, summ\r\n\t\t\t\t\tinto #t\r\n\t\t\t\t\tfrom sn.GetJnReportByGroup(@operGroup,@fromDate,@toDate,@serviceProvider,@serviceType) t\r\n\t\t\t\t\t--все внутренние суммы\r\n\t\t\t\t\tselect srvProvider, houseHolder, srvType, summ\r\n\t\t\t\t\tfrom #t\r\n\t\t\t\t\tunion\r\n/*\t\t\t\t\t--итоги поставщику по нескольким управляющим компаниям (строка)\r\n\t\t\t\t\tselect srvProvider, ' Итого' houseHolder, srvType, sum(summ) summ\r\n\t\t\t\t\tfrom #t\r\n\t\t\t\t\tgroup by srvProvider, srvType\r\n\t\t\t\t\thaving count(distinct houseHolder)>1\r\n\t\t\t\t\tunion\r\n\t\t\t\t\t--итоги поставщику по нескольким управляющим компаниям (сумма в конце)\r\n\t\t\t\t\tselect srvProvider, ' Итого' houseHolder, 'ИТОГО' srvType, sum(summ) summ\r\n\t\t\t\t\tfrom #t\r\n\t\t\t\t\tgroup by srvProvider\r\n\t\t\t\t\thaving count(distinct houseHolder)>1\r\n\t\t\t\t\tunion\r\n*/\t\t\t\t\t--итоги по поставщику с одной управляющей компанией (сумма в конце)\r\n\t\t\t\t\tselect srvProvider, houseHolder, 'ИТОГО' srvType, sum(summ) summ\r\n\t\t\t\t\tfrom #t\r\n\t\t\t\t\tgroup by srvProvider, houseHolder\r\n\t\t\t\t\tunion\r\n\t\t\t\t\t--итоги по группам услуг\r\n\t\t\t\t\tselect 'ИТОГО', '' houseHolder, srvType, sum(summ) summ\r\n\t\t\t\t\tfrom #t\r\n\t\t\t\t\tgroup by srvType\r\n\t\t\t\t\tunion\r\n\t\t\t\t\t--итоги по всей выборке\r\n\t\t\t\t\tselect 'ИТОГО', '' houseHolder, 'ИТОГО' srvType, sum(summ) summ\r\n\t\t\t\t\tfrom #t\t\t\t\t\t\r\n\t\t\t\t"); new System.Data.SqlClient.SqlDataAdapter(command).Fill(table); } finally { connection.Close(); } return table; }