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

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

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


        /// <summary>
        /// 垛位信息查询
        /// </summary>
        /// <param name=" _AreaCode">区域代码</param>
        /// <returns></returns>
        public ReturnObject QueryButtress(string _ButtressCode, string _AreaCode, string _ButtressType)
        {
            string strOut = "";
            string sql = "";

            if (_ButtressType == "")
            {
                sql = "select * from KCJ_BUTTRESS_ZW where isvalid = '1' "
                              + "  ";
            }
            else
            {
                sql = "select * from KCJ_BUTTRESS_ZW where isvalid = '1' "
                               + " and buttresstype = '" + _ButtressType + "' ";
            }
           
            if (_ButtressCode.Length > 0)
            {
                sql += " and buttresscode ='" + _ButtressCode + "'";
            }
            if (_AreaCode.Length > 0)
            {
                sql += " and areacode = '" + _AreaCode + "'";
            }

            //			sql += " order by areacode asc";

            try
            {

                DataSet ds = this.DBManager.ExecuteQuery(sql, out strOut);
                ds.Tables[0].TableName = "KCJ_BUTTRESS";
                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 AddOrUpdateButtress(string _type, DataSet _ds)
        {

            ArrayList OutPutValues = new ArrayList();
            object[] values = new object[14];
            System.Data.DataRow dr = _ds.Tables[0].Rows[0];
            string strOut = "";

            try
            {
                #region "param"
                System.Data.OracleClient.OracleParameter[] param = new System.Data.OracleClient.OracleParameter[14];
                param[0] = new System.Data.OracleClient.OracleParameter();
                param[0].ParameterName = "vButtressCode";
                param[0].Direction = System.Data.ParameterDirection.Input;

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

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

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

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

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

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

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

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

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

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

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

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

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

                #region "values"
                if (_type == "add")
                {
                    values[0] = dr["Buttress"];//r["ButtressCode"]; 要求垛位编码等于垛位名称
                }
                else
                {
                    values[0] = dr["ButtressCode"];//根据垛位编码来修改
                }
                values[1] = dr["AreaCode"];
                values[2] = dr["ButtressKind"];
                values[3] = dr["ButtressType"];
                values[4] = dr["Buttress"];
                values[5] = dr["ButtressExplain"];
                values[6] = System.DateTime.Now;
                values[7] = System.DateTime.Now;
                values[8] = dr["Creator"];
                values[9] = dr["LastEditor"];
                values[10] = 1;//表示有效
                values[11] = dr["Location"];
                values[12] = _type;
                values[13] = "";
                values = Common.FixValues(values);
                #endregion

                string sql = "KCJ_STORAGEMANAGER_WX.SetButress";
                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());
            }


        }

    }
}
