//===========================================================================
// 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.Collections; 
using System.Configuration; 
using System.Data;
using System.Windows.Forms;
using System.Threading;
using System.Timers;  
using JSW.Tool;
using JSW.FPMS.Tool;
using JSW.FPMS.Xian.ShiTu;
using JSW.FPMS.Xian.ShuJu;

namespace JSW.FPMS.Xian.KongZhi
{
	
	/// <summary>
	/// clsXianKongZhi 县应用系统控制
	/// MVC结构中的Controler角色
	/// </summary>
	public class clsXianKongZhi
	{
		#region 成员变量区域
		//界面(View)
		private XianForm		jieMian			= null;
		//数据管理(Model)
		private clsShuJuGuanLi   shujuGuanLi	= null;			

		#endregion

		#region 私有方法区域
		
		#endregion

		#region 公有方法区域
		/// <summary>
		/// 构造器
		/// </summary>
		public clsXianKongZhi(XianForm jieMian)
		{
			this.jieMian = jieMian;
			shujuGuanLi = new clsShuJuGuanLi();
		}

		/// <summary>
		/// 初始化
		/// </summary>
		public void  ChuShiHua() 
		{
			shujuGuanLi.ZaiRuShuJu();
			//初始化需求数据
			jieMian.SheZhiShuJuYuan(clsChangLiang.SHUJU_XUQIU,shujuGuanLi.HuoDeShuJu(clsChangLiang.SHUJU_XUQIU)); 
			//初始化信息点数据
			jieMian.SheZhiShuJuYuan(clsChangLiang.SHUJU_JIBENSHUJU_XINXIDIAN,
				shujuGuanLi.HuoDeShuJu(clsChangLiang.SHUJU_JIBENSHUJU_XINXIDIAN)); 
			//初始化需求分类数据
			jieMian.SheZhiShuJuYuan(clsChangLiang.SHUJU_JIBENSHUJU_XUQIUFENLEI ,
				shujuGuanLi.HuoDeShuJu(clsChangLiang.SHUJU_JIBENSHUJU_XUQIUFENLEI)); 
			//初始化配置信息
			jieMian.SheZhiShuJuYuan(clsChangLiang.SHUJU_PEIZHIXINXI ,
				shujuGuanLi.HuoDeShuJu(clsChangLiang.SHUJU_PEIZHIXINXI)); 

		}
		/// <summary>
		/// 控制器销毁
		/// </summary>
		public void XiaoHui() 
		{			
		}
		
		/// <summary>
		/// 需求数据更新
		/// </summary>
		public void GengXinXuQiu() 
		{		
			shujuGuanLi.XuQiuShuJuGengXin();
			jieMian.GengXinShuJu(clsChangLiang.SHUJU_XUQIU,shujuGuanLi.HuoDeShuJu(clsChangLiang.SHUJU_XUQIU));
			clsRiZhiChuLi.JiLuRiZhi("需求数据更新");
		}

		/// <summary>
		/// 获得数据集合
		/// </summary>
		/// <param name="Hang"></param>
		public  Hashtable HuoDeShuJuHashBiao(String ShuJuJian,int Hang) 
		{
			DataSet shuJu = this.shujuGuanLi.HuoDeShuJu(ShuJuJian);
			if(shuJu.Tables.Count ==0) 
			{
				return null;
			}
			if(Hang <0) 
			{
				return null;
			}
			Hashtable hang = new Hashtable();
			DataTable dt   = shuJu.Tables[0];
			for(int Loop=0;Loop<shuJu.Tables[0].Columns.Count;Loop++) 
			{
				string jian = dt.Columns[Loop].ColumnName;
				hang.Add(jian,dt.Rows[Hang].ItemArray[Loop]);
			}
			return hang;
		}
		/// <summary>
		/// 数据维护
		/// </summary>
		/// <param name="Jian">数据键值</param>
		/// <param name="MoShi">更新模式</param>
		/// <param name="ZhuJian">主键</param>
		/// <param name="ShuJu">数据</param>
		public void ShuJuWeiHu(String Jian,String MoShi,String ZhuJian,Hashtable ShuJu)  
		{
			this.shujuGuanLi.ShuJuWeiHu(Jian,MoShi,ZhuJian,ShuJu);
			jieMian.GengXinShuJu(Jian,shujuGuanLi.HuoDeShuJu(Jian));			
		}
		/// <summary>
		/// 数据维护
		/// </summary>
		/// <param name="Jian">数据键值</param>
		/// <param name="MoShi">更新模式</param>
		/// <param name="ZhuJian">主键</param>
		/// <param name="ZiDongZhuJian">主键自动增长</param>
		/// <param name="ShuJu">数据</param>
		public void ShuJuWeiHu(String Jian,String MoShi,String ZhuJian,bool ZiDongZhuJian,Hashtable ShuJu)  
		{
			this.shujuGuanLi.ShuJuWeiHu(Jian,MoShi,ZhuJian,ZiDongZhuJian,ShuJu);
			jieMian.GengXinShuJu(Jian,shujuGuanLi.HuoDeShuJu(Jian));			
		}
		
		/// <summary>
		/// 需求反馈提交
		/// </summary>
		/// <param name="ShuJu"></param>
		public void XuQiuTiJiao(DataSet ShuJu,string BianHao)
		{
			string sql = "UPDATE biao_XuQiu Set " ;
			string lieMing = "" ;
			string zhi = "" ;			
			System.Data.DataRow[] fanKuiZu = ShuJu.Tables["PeiZhiXinXi"].Select("ShuJuZuKJM = 'FanKuiZu'");
			for (int i=0;i<fanKuiZu.Length;i++)
			{
				lieMing = fanKuiZu[i]["ShuJuXiangKJM"].ToString() ;
				zhi = ShuJu.Tables["ShuJu"].Rows[0][lieMing].ToString()  ;
				sql+= lieMing + "='" + zhi + "'," ;
			}
				
			sql = sql.Substring(0,sql.Length-1);
			sql = sql + " where bianhao = " +"'" + BianHao +"'";
			this.shujuGuanLi.GengXinShuJuBySQL(sql);
			clsRiZhiChuLi.JiLuRiZhi(sql);
		}

		/// <summary>
		/// 获得数据
		/// </summary>
		/// <param name="Jian"></param>
		/// <returns></returns>
		public DataSet HuoDeShuJu(String Jian)
		{
			if(Jian.Equals(clsChangLiang.SHUJU_JIBENSHUJU))
			{
				return this.shujuGuanLi.HuoDeJiBenShuJu();
			}
			return this.shujuGuanLi.HuoDeShuJu(Jian); 
		}

		/// <summary>
		/// 获得界面描述数据
		/// zhangwj  11.8
		/// </summary>
		/// <param name="Jian">键</param>
		/// <param name="Hang">行号</param> 
		/// <returns></returns>
		public System.Data.DataSet HuoDeShuJu(string Jian,int Hang)
		{
			System.Data.DataSet fanHui = null;
			System.Collections.Hashtable table = new System.Collections.Hashtable() ;
			fanHui = this.shujuGuanLi.HuoDeShuJu(Jian) ;
			if(Hang < 0 ) return null;
				
			DataTable shujuBiao = fanHui.Tables[0];
			DataRow   shujuHang = shujuBiao.Rows[Hang];
			DataTable xinShuJuBiao = shujuBiao.Copy(); 
			DataRow   xinShuJuHang =  xinShuJuBiao.NewRow();

			for (int i=0;i<xinShuJuBiao.Columns.Count;i++)
				table.Add(xinShuJuBiao.Columns[i].ColumnName,"") ;

			for(int Loop=0;Loop<shujuBiao.Columns.Count;Loop++) 
			{
				if (table.ContainsKey(shujuBiao.Columns[Loop].ColumnName))
				{
					if (!shujuHang.IsNull(shujuBiao.Columns[Loop].ColumnName))
						xinShuJuHang[shujuBiao.Columns[Loop].ColumnName]  = shujuHang[shujuBiao.Columns[Loop].ColumnName].ToString();
				}
			}
			xinShuJuBiao.Rows.Clear();
			xinShuJuBiao.Rows.Add(xinShuJuHang);
			fanHui = new DataSet() ;
			fanHui.Merge(xinShuJuBiao);
			return fanHui ;
		}

		/// <summary>
		/// 定时刷新
		/// </summary>
		public void DingShiShuaXin() 
		{			
			this.shujuGuanLi.XuQiuShuJuGengXin();
			jieMian.GengXinShuJu(clsChangLiang.SHUJU_XUQIU,shujuGuanLi.HuoDeShuJu(clsChangLiang.SHUJU_XUQIU));
			clsRiZhiChuLi.JiLuRiZhi("需求数据更新");
		}
		#endregion


	}
}
