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

namespace JLHHJSvr.Excutor
{
    internal sealed class GetDwLayoutExcutor : ExcutorBase<GetDwLayoutRequest, GetDwLayoutResponse>
    {
        protected override void ExcuteInternal(GetDwLayoutRequest request, object state, GetDwLayoutResponse rslt)
        {
            var tokendata = BllHelper.GetToken(request.token);
            if (tokendata == null)
            {
                rslt.ErrMsg = "会话已中断";
                return;
            }

            rslt.layout = new FxUserDwlayout();

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

                var whereStr = "userid = @userid and dwname = @dwname";
                var parms = new Dictionary<string, object>()
                {
                    {"@userid", tokendata.userid},
                    {"@dwname", request.dwname}
                };
                var layout = new FxUserDwlayout();
                try
                {
                    if (DbSqlHelper.SelectOne(cmd, "fx_user_dwlayout", whereStr, parms, layout, "column_visible,column_width,column_x,column_autosize,column_detail_height") == 1)
                    {
                        rslt.layout = layout;
                    }
                }
                catch (Exception ex)
                {
                    Trace.Write(ex.ToString());
                }
            }
        }
    }
}
