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.Helper;
using JLHHJSvr.LJException;
using LJLib.DAL.SQL;
using LJLib.Net.SPI.Server;
using LJLib.SQLEX;

namespace JLHHJSvr.Excutor
{
    internal sealed class DeleteSoftBedFormulaExcutor : ExcutorBase<DeleteSoftBedFormulaRequest, DeleteSoftBedFormulaResponse>
    {
        protected override void ExcuteInternal(DeleteSoftBedFormulaRequest request, object state, DeleteSoftBedFormulaResponse rslt)
        {
            var tokendata = BllHelper.GetToken(request.token);
            if (!request.list.Any())
            {
                rslt.ErrMsg = "至少提交一条需要删除的记录";
                return;
            }

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

                var basicHelper = HelperBase.GetHelper<BasicInfoHelper>(cmd);
                using (cmd.Transaction = con.BeginTransaction())
                {
                    try
                    {
                        foreach (var formula in request.list)
                        {
                            basicHelper.DeleteSoftBedFormula(formula);
                        }
                        cmd.Transaction.Commit();
                    }
                    catch (Exception e)
                    {
                        cmd.Transaction?.Rollback();
                        rslt.ErrMsg = e.Message;
                    }
                }
            }
        }
    }
}
