Ejemplo n.º 1
0
		public int ExecuteScalar()
		{
			int result = 0;
			using (SqlConnection sqlConnection = new SqlConnection(Constants.Config.ConnectionString))
			{
				SqlCommand sqlCommand = new SqlCommand(this.Name, sqlConnection);
				sqlCommand.set_CommandType(4);
				sqlCommand.set_CommandTimeout(120);
				IEnumerator enumerator = this.StoredProcParams.GetEnumerator();
				try
				{
					while (enumerator.MoveNext())
					{
						StoredProcParam storedProcParam = (StoredProcParam)enumerator.get_Current();
						sqlCommand.get_Parameters().Add(storedProcParam.ParamID, storedProcParam.ParamValue);
					}
				}
				finally
				{
					IDisposable disposable = enumerator as IDisposable;
					if (disposable != null)
					{
						disposable.Dispose();
					}
				}
				sqlConnection.Open();
				result = Convert.ToInt32(sqlCommand.ExecuteScalar());
				sqlConnection.Close();
			}
			return result;
		}
Ejemplo n.º 2
0
		public DataSet ExecuteDataSet()
		{
			DataSet dataSet;
			using (SqlConnection sqlConnection = new SqlConnection(Constants.Config.ConnectionString))
			{
				SqlCommand sqlCommand = new SqlCommand(this.Name, sqlConnection);
				sqlCommand.set_CommandType(4);
				sqlCommand.set_CommandTimeout(120);
				IEnumerator enumerator = this.StoredProcParams.GetEnumerator();
				try
				{
					while (enumerator.MoveNext())
					{
						StoredProcParam storedProcParam = (StoredProcParam)enumerator.get_Current();
						sqlCommand.get_Parameters().Add(storedProcParam.ParamID, storedProcParam.ParamValue);
					}
				}
				finally
				{
					IDisposable disposable = enumerator as IDisposable;
					if (disposable != null)
					{
						disposable.Dispose();
					}
				}
				dataSet = new DataSet();
				SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sqlCommand);
				sqlDataAdapter.Fill(dataSet);
			}
			return dataSet;
		}
Ejemplo n.º 3
0
 private static System.Data.SqlClient.SqlCommand PrepareCommand(System.Data.SqlClient.SqlTransaction trans, string sql, System.Data.SqlClient.SqlParameter[] parameters)
 {
     System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand(sql, Connection, trans);
     command.set_CommandType(System.Data.CommandType.Text);
     command.set_CommandTimeout(0);
     if (parameters != null)
     {
         command.Parameters.AddRange(parameters);
     }
     foreach (System.Data.SqlClient.SqlParameter parameter in command.Parameters)
     {
         if (parameter.get_Value() == null)
         {
             parameter.set_Value(System.DBNull.Value);
         }
         if ((parameter.SqlDbType == System.Data.SqlDbType.DateTime) && parameter.get_Value().Equals(new System.DateTime(1, 1, 1)))
         {
             parameter.set_Value(System.DBNull.Value);
         }
     }
     return command;
 }
Ejemplo n.º 4
0
		public int ExecuteReturnVal()
		{
			int result = 0;
			using (SqlConnection sqlConnection = new SqlConnection(Constants.Config.ConnectionString))
			{
				SqlCommand sqlCommand = new SqlCommand(this.Name, sqlConnection);
				sqlCommand.set_CommandType(4);
				sqlCommand.set_CommandTimeout(120);
				SqlParameter sqlParameter = new SqlParameter("@RETURN", 8);
				sqlParameter.set_Direction(6);
				sqlCommand.get_Parameters().Add(sqlParameter);
				IEnumerator enumerator = this.StoredProcParams.GetEnumerator();
				try
				{
					while (enumerator.MoveNext())
					{
						StoredProcParam storedProcParam = (StoredProcParam)enumerator.get_Current();
						sqlCommand.get_Parameters().Add(storedProcParam.ParamID, storedProcParam.ParamValue);
					}
				}
				finally
				{
					IDisposable disposable = enumerator as IDisposable;
					if (disposable != null)
					{
						disposable.Dispose();
					}
				}
				sqlConnection.Open();
				sqlCommand.ExecuteNonQuery();
				sqlConnection.Close();
				result = (int)sqlParameter.get_Value();
			}
			return result;
		}
Ejemplo n.º 5
0
 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;
 }
Ejemplo n.º 6
0
 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;
 }