using System;
using System.Data;
using Core.Mes.IBaseInterface;
using Core.Mes.ServerFrameWork;
using System.Collections;


namespace Core.XgMes.Server.JGKC.SteelPlateManager
{
    public class SetArea : Core.Mes.ServerFrameWork.IComponent
    {
        public SetArea()
		{
			//
			// TODO: 在此处添加构造函数逻辑
			//
		}

		public override int maxValue
		{
			get
			{
				return 100;
			}
		}
		public override int minValue
		{
			get
			{
				return 50;
			}
		}

		private string strOut = "";


		/// <summary>
		/// 区域信息查询
		/// </summary>
		/// <param name=" _AreaCode">区域代码</param>
		/// <param name=" _AreaName">区域名</param>
		/// <param name=" _AreaType">区域类型</param>
		/// <returns></returns>
        public ReturnObject QueryAreaInfo(string _AreaCode, string _AreaName, string _AreaType)
		{
            string sql = "";
          
                sql = "SELECT * FROM KCJ_AREA_ZW WHERE AREACODE IS NOT NULL  ";
           
			
			if(_AreaCode.Length > 0)
			{
				sql += " AND AREACODE = '" + _AreaCode + "'";

			}
			if(_AreaName.Length > 0)
			{
				sql += " AND AREANAME = '" + _AreaName + "'";

			}
			if(_AreaType.Length > 0)
			{
				sql += " AND AREATYPE = '" + _AreaType + "'";
			}

			try
			{
			
				DataSet ds = this.DBManager.ExecuteQuery(sql,out strOut);
				ds.Tables[0].TableName = "KCJ_AREA";
				return new ReturnObject(ds,strOut);
			}
			catch(Exception ex)
			{
				System.Diagnostics.Debug.WriteLine(ex.ToString());
				return new ReturnObject(null,"数据库连接错");
			}			

		}

		
		/// <summary>
		/// 增加、更新区域信息
		/// </summary>
		/// <param name=" _type">操作类型</param>
		/// <param name=" _ds"></param>
		/// <returns></returns>
		public ReturnObject AddOrUpdateArea(string _type,System.Data.DataSet _ds)
		{
			ArrayList OutPutValues = new ArrayList();
			object [] values = new object[11];
			System.Data.DataRow dr = _ds.Tables[0].Rows[0];
			string strOut="";
			
			try
			{
				#region "param"
				System.Data.OracleClient.OracleParameter[] param = new System.Data.OracleClient.OracleParameter[11];
				param[0] = new System.Data.OracleClient.OracleParameter();
				param[0].ParameterName = "vAreaCode";
				param[0].Direction = System.Data.ParameterDirection.Input;

				param[1] = new System.Data.OracleClient.OracleParameter();
				param[1].ParameterName = "vAreaName";
				param[1].Direction = System.Data.ParameterDirection.Input;

				param[2] = new System.Data.OracleClient.OracleParameter();
				param[2].ParameterName = "vCreatTime";
				param[2].DbType = System.Data.DbType.DateTime;
				param[2].Direction = System.Data.ParameterDirection.Input;
			
				param[3] = new System.Data.OracleClient.OracleParameter();
				param[3].ParameterName = "vLastEditTime";
				param[3].DbType = System.Data.DbType.DateTime;
				param[3].Direction = System.Data.ParameterDirection.Input;

				param[4] = new System.Data.OracleClient.OracleParameter();
				param[4].ParameterName = "vCreator";
				param[4].Direction = System.Data.ParameterDirection.Input;

				param[5] = new System.Data.OracleClient.OracleParameter();
				param[5].ParameterName = "vLastEditor";
				param[5].Direction = System.Data.ParameterDirection.Input;

				param[6] = new System.Data.OracleClient.OracleParameter();
				param[6].ParameterName = "vIsValid";
				param[6].Direction = System.Data.ParameterDirection.Input;

				param[7] = new System.Data.OracleClient.OracleParameter();
				param[7].ParameterName = "vAreaExplain";
				param[7].Direction = System.Data.ParameterDirection.Input;

				param[8] = new System.Data.OracleClient.OracleParameter();
				param[8].ParameterName = "vAreaType";
				param[8].Direction = System.Data.ParameterDirection.Input;

				param[9] = new System.Data.OracleClient.OracleParameter();
				param[9].ParameterName = "vtype";
				param[9].Direction = System.Data.ParameterDirection.Input;

				param[10] = new System.Data.OracleClient.OracleParameter();
				param[10].ParameterName = "vpstr"; 
				param[10].DbType = System.Data.DbType.String;
				param[10].Direction = System.Data.ParameterDirection.Output;
				#endregion

				#region "values"
				if(_type == "add")
				{
					values[0] = dr["AreaName"];//r["AreaCode"]; 要求区域编码和区域名称相同
				}
				else
				{
					values[0] = dr["AreaCode"]; 
				}				
				values[1] = dr["AreaName"];
				values[2] = System.DateTime.Now;//r["vCreatTime"];
				values[3] = System.DateTime.Now;//r["LastEditTime"];
				values[4] = dr["Creator"];
				values[5] = dr["LastEditor"];
				values[6] = "1" ;//r["IsValid"]; 1 表示有效
				values[7] = dr["AreaExplain"]; //区域说明
				values[8] = dr["AreaType"]; //区域类型， 0： 原料 1：成品
				values[9] = _type;
				values[10] = "";//vpstr
				values = Common.FixValues(values);
				#endregion
				
				string sql="KCJ_STORAGEMANAGER_WX.SetArea";
				this.DBManager.ExecuteQuery(sql,System.Data.CommandType.StoredProcedure,param,values,ref OutPutValues,out strOut);
			
				if(strOut.Length > 0)
				{
					return new ReturnObject(strOut);
				}
				if(OutPutValues.Count > 0 &&  Common.CheckNullStr(OutPutValues[0]).Length > 0)
				{
					return new ReturnObject(OutPutValues[0].ToString());
				}
				return new ReturnObject("传递参数错误，操作失败");
			}
			catch(Exception ex)
			{
				System.Diagnostics.Debug.WriteLine(ex.ToString());
				return new ReturnObject(ex.ToString());
			}

		}



	
    }
}
