//===========================================================================
// Smarclient FPMS Demo Project a sample project for SmartClient technology.
// Smarclient FPMS Demo is designed and implemented bases Microsoft Application Block tech.
// Author: SFPMS Team, Date 2004-11
// Vision 1.0
// Revison History
//=============================================================================
using System;
using System.Data; 
using Microsoft.ApplicationBlocks.SmartClient.Offline;
using JSW.FPMS.Xiang.Web;

namespace JSW.FPMS.Xiang.YeWu
{
	/// <summary>
	/// 网络代理，通过这个类访问Web Service
	/// </summary>
	public class clsWangLuoDaiLi
	{
		#region 成员变量区域
		//网络服务实例
		private clsXianFuWu fuWu   = null;
		#endregion

		#region 私有方法区域
		/// <summary>
		/// 把网络服务中的数据放入请求
		/// </summary>
		/// <param name="ShuJu">网络服务返回的数据</param>
		/// <returns>请求:PlayLoad</returns>
		private Payload QingQiuChuLi(Payload QingQiu,DataSet ShuJu) 
		{
			ReferenceCacheDataPayload huanCunQingQiu = QingQiu as ReferenceCacheDataPayload;
			try
			{
				//得到网络服务数据
				huanCunQingQiu.UpdateDataToReturn(ShuJu); 
				//得到离线控制实例，操作缓存数据
				OfflineBlockBuilder liXianShiLi = OfflineBlockBuilder.Instance;
				//
				if(!(huanCunQingQiu.IsRefreshMessage() && huanCunQingQiu.DataDefinition.Dirty == true))
				{
					try
					{
						//存数据放入到参考缓存数据块中
						liXianShiLi.ReferenceDataCache.Store(huanCunQingQiu.DataDefinition, 
																		huanCunQingQiu.Results);
					}
					catch(Exception genException)
					{
						
						throw genException;
					}
				}

				//得到的数据置为干净
				liXianShiLi.ReferenceDataCache.MarkAsClean(	huanCunQingQiu.DataDefinition.OriginalKey);

				return huanCunQingQiu;	
			}
			catch(Exception genException)
			{
				//记录错误在请求当中
				huanCunQingQiu.RecordFailure(genException);
				return huanCunQingQiu;
			}

		}
		#endregion

		#region 公有方法区域
		/// <summary>
		/// 构造器
		/// </summary>
		public clsWangLuoDaiLi()
		{
			fuWu = new clsXianFuWu(); 			
		}
		/// <summary>
		/// 需求提交
		/// </summary>
		public Payload XuQiuTiJiao(Payload QingQiu)
		{
			try
			{
				DataSet ShuJu = (DataSet)QingQiu.RequestData;					
				fuWu.XuQiuTiJiao(ShuJu);
			}
			catch(Exception e)
			{
				QingQiu.RecordFailure(e);
				
			}
			return QingQiu;
		}

		/// <summary>
		/// 需求查询
		/// </summary>
		public Payload XuQiuChaXun(Payload QingQiu)
		{
			//需求查询
			return QingQiuChuLi(QingQiu,fuWu.XuQiuChaXun()); 
			
		}
		

		/// <summary>
		/// 获得基本数据
		/// </summary>
		public Payload HuoDeJiBenShuJu(Payload QingQiu) 
		{
			//需求查询
			return QingQiuChuLi(QingQiu,fuWu.HuoDeJiBenShuJu()); 
			
		}
		
		/// <summary>
		/// 获得配置信息
		/// </summary>
		public Payload HuoDePeiZhi(Payload QingQiu)
		{
			//需求查询
			return QingQiuChuLi(QingQiu,fuWu.HuoDePeiZhi()); 			
		}
		#endregion
	}
}
