using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using DirectService.Tools;
using JLHHJSvr.BLL;
using JLHHJSvr.Com;
using JLHHJSvr.Com.Model;
using JLHHJSvr.LJException;
using JLHHJSvr.Tools;
using LJLib.DAL.SQL;
using LJLib.Net.SPI.Server;
using LJLib.SQLEX;

namespace JLHHJSvr.Excutor
{
    internal sealed class GetBedNetVarListExcutor : ExcutorBase<GetBedNetVarListRequest, GetBedNetVarListResponse>
    {
        protected override void ExcuteInternal(GetBedNetVarListRequest request, object state, GetBedNetVarListResponse rslt)
        {
            var tokendata = BllHelper.GetToken(request.token);
            if (tokendata == null)
            {
                rslt.ErrMsg = "会话已经中断，请重新登录";
                return;
            }

            using (var con = GlobalVar.ConnectionString.NewSqlConnection())
            using (var cmd = con.CreateCommand())
            {
                con.Open();

                rslt.list = new List<u_bednet_var>();

                var selectStr = @"SELECT varid
	                                    ,varkind
	                                    ,varcode
	                                    ,varname
	                                    ,varclass
	                                    ,vartype
	                                    ,varunit
	                                    ,varvalue
	                                    ,dscrp
	                                    ,createtime
	                                    ,createby
                                    FROM u_bednet_var";
                DbSqlHelper.SelectJoin(cmd, selectStr, null, null, "varid", "varid,varkind,varcode,varname,varclass,vartype,varunit,varvalue,dscrp,createtime,createby", request.pageIndex, request.pageSize, rslt.list);

                foreach(var item in rslt.list)
                {
                    var selectMxStr = @"SELECT
	                                        u_bednet_varmx.varmxid, 
	                                        u_bednet_varmx.varid, 
	                                        u_bednet_varmx.line_diameter, 
	                                        u_bednet_varmx.bednettypeid, 
	                                        u_bednet_varmx.varvalue, 
	                                        u_bednet_varmx.pricelistid
                                        FROM
	                                        u_bednet_varmx";
                    DbSqlHelper.SelectJoin(cmd, selectMxStr, null, null, "varid", "varid,varkind,varcode,varname,varclass,vartype,varunit,varvalue,dscrp,createtime,createby", request.pageIndex, request.pageSize, rslt.list);

                }
            }
        }
    }
}
