Laden...

Abfrage

Erstellt von xcoder vor 20 Jahren Letzter Beitrag vor 20 Jahren 3.278 Views
X
xcoder Themenstarter:in
12 Beiträge seit 2003
vor 20 Jahren
Abfrage

Hallo zusammen.

Ich habe folgende Frage.

Ich soll innerhalb einer Preisliste eine Methode o.ä erstellen die die Preisliste abfragt, ob es sich bei dem Produkt um eine Komponente eines Produktes oder um ein Paket handelt. Hierfür habe ich in der datanbank ein neues Feld namens int_package eingefügt das gefüllt werden soll.

dieses int_package schleife ich auch durch alle benötigten Klassen und Methodendes Programmes mit. Ich weiß aber nicht, wie ich jetzt das realisieren soll.

Hat jemand eine Idee?

Hier der Code der Preisliste.



using System;
using System.Data;
using System.Data.SqlClient;
using Rle.DataFactory;
using PriceList.Data;
using System.Diagnostics;
using System.Configuration;

namespace PriceList
..

		#region public methods

		/// <summary>
		///     GetPriceListEntries
		///     <remarks>Get the PriceList table's entries</remarks>
		/// </summary>
		public PriceListData GetPriceListEntries()
		{
			return FillPriceListData("IT_LSG_GetPriceListEntries", "", "");
		}
		public PriceListData GetActivePriceListEntries()
		{
			return FillPriceListData("IT_LSG_GetActivePriceListEntries", "", "");
		}
	/// <summary>
		///     NewPriceListEntry
		///     <remarks>Creates a new PriceList entry</remarks>
		///     <returns>ID of the new PriceList entry</returns>
		///<param name="description">
		///		description
		///</param> 
		///<param name="price">
		///		price of the element
		///</param> 
		///<param name="status">
		///		status id
		///</param> 
		/// </summary>
		public int NewPriceListEntry(string description, double price, int status, int category,int package  )
		{
			DataSet data = new DataSet();
			
			// Create InsertCommand object of the DataAdapter as IDbCommand object 
			IDbCommand command = da.SelectCommand;

			command.Parameters.Clear();
			// Assign the parameters to the command object and define CommandType as StoredProcedure
			command.CommandText	= "IT_LSG_NewPricelistEntry";
			command.CommandType	= CommandType.StoredProcedure; 

			SqlParameter param	= new SqlParameter("@price", SqlDbType.Money);
			param.Value	= price;
			command.Parameters.Add(param);
			param	= new SqlParameter("@status", SqlDbType.Int);
			param.Value	= status;
			command.Parameters.Add(param);
			param	= new SqlParameter("@description", SqlDbType.VarChar);
			param.Value	= description;
			command.Parameters.Add(param);
			param	= new SqlParameter("@category", SqlDbType.VarChar);
			param.Value	= category;
			command.Parameters.Add(param);
			//new 19.8.03
			param	= new SqlParameter("@package", SqlDbType.Int);
			param.Value	= package;
			command.Parameters.Add(param);

			
		
			// Fill DataSet (PriceListData object)
			da.Fill(data);

			// Return the DataSet (PriceListData object)
			return Convert.ToInt32(data.Tables[0].Rows[0].ItemArray[0].ToString());
		}
		
		/// <summary>
		///     PriceListSuggestion
		///     <remarks>A list of the Component+Combination elements to suggest a new value</remarks>
		/// </summary>
		public PriceListData PriceListSuggestion()
		{
			PriceListData data = new PriceListData();
			
			// Create InsertCommand object of the DataAdapter as IDbCommand object 
			IDbCommand command = da.SelectCommand;

			command.Parameters.Clear();
			// Assign the parameters to the command object and define CommandType as StoredProcedure
			command.CommandText	= "IT_LSG_GetPriceListSuggestion";
			command.CommandType	= CommandType.StoredProcedure; 


			// Fill DataSet (PriceListData object)
			da.Fill(data);

			// Return the DataSet (PriceListData object)
			return data;
		}
		/// <summary>
		///     RemovePriceListEntry
		///     <remarks>Removes a PriceList entry</remarks>
		///<param name="element_id">
		///		element_id
		///</param> 
		/// </summary>
		public void RemovePriceListEntry(int element_id)
		{
			DataSet data = new DataSet();
			
			// Create InsertCommand object of the DataAdapter as IDbCommand object 
			IDbCommand command = da.SelectCommand;

			command.Parameters.Clear();
			// Assign the parameters to the command object and define CommandType as StoredProcedure
			command.CommandText	= "IT_LSG_RemovePricelistEntry";
			command.CommandType	= CommandType.StoredProcedure; 

			SqlParameter param	= new SqlParameter("@id", SqlDbType.Int);
			param.Value	= element_id;
			command.Parameters.Add(param);
		
			// Fill DataSet (PriceListData object)
			da.Fill(data);
			

			// Return the DataSet (PriceListData object)
			//return Convert.ToInt32(data.Tables[0].Rows[0].ItemArray[0].ToString());
		}

		/// <summary>
		///     UpdatePriceListEntry
		///     <remarks>Updates a PriceList entry</remarks>
		///<param name="ID">
		///		id of the PriceList entry
		///</param> 
		///<param name="order">
		///		the order key
		///</param> 
		///<param name="price">
		///		price of the element
		///</param> 
		///<param name="element_id">
		///		element_id
		///</param> 
		///<param name="status">
		///		status id
		///</param> 
		///<param name="package">
		///		if component -1 if selectet or package
		///</param>
		/// </summary>
		public void UpdatePriceListEntry(int id, string description, double price, int status, int category, int package)
		{
			DataSet data = new DataSet();

			// Create SelectCommand object of the DataAdapter as IDbCommand object 
			IDbCommand command = da.SelectCommand;

			command.Parameters.Clear();
			// Assign the parameters to the command object and define CommandType as StoredProcedure
			command.CommandText	= "IT_LSG_UpdatePriceListEntry";
			command.CommandType	= CommandType.StoredProcedure; 
			
			command.Parameters.Clear();
			SqlParameter param	= new SqlParameter("@price", SqlDbType.Money);
			param.Value	= price;
			command.Parameters.Add(param);
			param	= new SqlParameter("@status", SqlDbType.Int);
			param.Value	= status;
			command.Parameters.Add(param);
			param	= new SqlParameter("@description", SqlDbType.VarChar);
			param.Value	= description;
			command.Parameters.Add(param);
			param = new SqlParameter("@ID", SqlDbType.Int);
			param.Value	= id;
			command.Parameters.Add(param);
			param	= new SqlParameter("@category", SqlDbType.VarChar);
			param.Value	= category;
			command.Parameters.Add(param);
			//new 19.08.03
			param	= new SqlParameter("@package", SqlDbType.Int);
			param.Value	= package;
			command.Parameters.Add(param);


			// Fill DataSet (PriceListData object)
			try {
				da.Fill(data);
				}
			catch (Exception ex){Debug.Write(ex.ToString()); }
		}

		#endregion

		#region Dispose methods

		/// <summary>
		///     Dispose of this object's resources.
		/// </summary>
		public void Dispose()
		{
			Dispose(true);
			GC.SuppressFinalize(true); 
		}

		/// <summary>
		///		Free the instance variables of this object.
		/// </summary>
		protected virtual void Dispose(bool disposing)
		{
			if (! disposing)
				return; // we're being collected, so let the GC take care of this object

			if (da != null )
			{
				if (da.SelectCommand != null)
				{
					if( da.SelectCommand.Connection != null)
						da.SelectCommand.Connection.Dispose();
					da.SelectCommand.Dispose();
				}
				//dsCommand.Dispose();
				da = null;
			}
		}

		#endregion

		
		#region private methods

		/// <summary>
		///     FillPriceListData
		///     <remarks>
		///     Method which helps to create and populate a PriceListData dataset.
		///     Works only with SQL-Clients.
		///     Parameters:
		///								[in] commandText:  sql stored procedure to run
		///								[in] paramName   :  sql parameter name
		///								[in] paramValue   :  sql parameter
		///								
		///     Returns a dataset of type PriceListData containing resource items.
		///     For more information of kind of items see constants of 
		///     class PriceListData.
		///     </remarks> 
		/// </summary>

		private PriceListData FillPriceListData(string commandText, 
			string paramName, 
			string paramValue)
		{
			if (da== null )
			{
				throw new System.ObjectDisposedException( GetType().FullName );
			}            
			
			// Create PriceListData object (displays a DataSet because of inheritance) which will be returned.
			// See constructor of Data.PriceListData
			Data.PriceListData data = new PriceListData();
			
			// Create SelectCommand object of the DataAdapter as IDbCommand object 
			IDbCommand command								= da.SelectCommand;

			command.Parameters.Clear();
			// Assign the parameters to the command object and define CommandType as StoredProcedure
			command.CommandText				= commandText;
			command.CommandType				= CommandType.StoredProcedure; 
//			SqlParameter param				= new SqlParameter(paramName, SqlDbType.Char, 255);
//			param.Value						= paramValue;
//			command.Parameters.Add(param);            

			// If you want to add additional columns to the PriceListData table to store different information
			// use this specification or change PriceListData.
			// data.Tables["PriceLists"].Columns.Add("column_name", typeof(String));
		
		
			// Fill DataSet (PriceListData object)
			try 
			{	
				da.Fill(data);
			}
			catch (System.Data.SqlClient.SqlException e)
			{
				Debug.Write(e.ToString());
			}


			// Return the DataSet (PriceListData object)
			return data;
		}

		#endregion
	}
}

V
842 Beiträge seit 2003
vor 20 Jahren

Wie erkenne ich den unterschied zwsichen Komponente und Paket? Bzw. was ist was?
Ich weiß ja nicht, aber da es ja sicherlich einen Unterschied geben wird würde ich dir raten, lass eine Methode den Unterschied rausfinden, diese soll dann entscheiden um was es sich handelt und dann soll es in der Spalte in das dafür vorgesehene Feld >Komponente> bzw. >Paket> schreiben.

Welches wäre denn ein konkreter Programmabschnitt, ich habe den Thread hier eben gesehen, deswegen habe ich keine Lust alles durchzugehen. Poste sonst mal den genauenProgrammabschnitt, dann gucke ich mal. Kanst du vielleicht ein Beispiel schicken wie die Datenbank aussieht? Muss ja nichts von der Arbeit sein, aber so etwas nachgemachtes, dass ich mal sehen kann wie die Datenbank aussieht um gucken zu können wie man das realisieren könnte.

Ansonsten ist es eigentlich ja simpel, es gibt einen Unterschied, finde Ihn raus, gehe in das Feld und schreibe rein.

Code-Hacker

X
xcoder Themenstarter:in
12 Beiträge seit 2003
vor 20 Jahren

Hi,

thanx hat sich schon erledigt 🙂 Läuft jetzt 8)