using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EAS.Data;
using EAS.Services;
using SOH.Entities;
using EAS.Data.Access;
using EAS;
using SOH.Entities.DTO;
using SOH.Data;
using EAS.Data.Linq;
using EAS.Data.ORM;
using System.Data;
namespace SOH.BLL
{
[ServiceObject("退费功能")]
[ServiceBind(typeof(ITuiFei))]
public class TuiFeiBLL : ITuiFei
{
///
/// 根据条码、类型、公自费标记、加项公自费标记查询可退费信息
///条码号
///类型,1个检,2团检
///
//public List GetKtfByTm(int tm, short lx, short gzfbj, short jxgzfbj)
public List GetKtfByTm(int tm, short lx)
{
List ldt = new List();
using (DbEntities db = new DbEntities())
{
//个人全自费,找t_tempdjxm表中的未进行检查的信息
if (lx == 1) //自检
{
//找t_tempdjxm中ztz=0的 还没检查的项目
var data1 = from a in db.t_tempdjxms join b in db.t_zhxms on a.zhbm equals b.zhbm
where a.tm == tm && a.ztz == 0
select new dto_tempdjxm
{
zhbm=a.zhbm,
zhmc=b.zhmc,
jg= b.jg,
jg_v=b.jg_v,
zhjg=a.zhjg,
zhjg_v=a.zhjg_v
};
if (data1.Any())
{
return data1.ToList();
}
else
{
return null;
}
}
else
{
//团检的套餐不允许退费,加项可以退,找到t_tempdjxm中ztz=0 并且 zhbm在jjx表中的加项信息
var data2 = from a in db.t_tempdjxms
join b in db.t_jjxbs
on a.tm equals b.tm
join c in db.t_zhxms on a.zhbm equals c.zhbm
where a.tm == tm && a.ztz == 0 && b.jjx == 0 && a.zhbm==b.zhbm
select new dto_tempdjxm
{
zhbm = a.zhbm,
zhmc = c.zhmc,
jg = c.jg,
jg_v = c.jg_v,
zhjg = a.zhjg,
zhjg_v = a.zhjg_v
};
if (data2.Any()) //有加项的
{
return data2.ToList();
}
else //无加项的
{
return null;
}
}
}
}
///
/// 退费操作
///
///
public OperationResult TF(short lx, List ltt, List lts,T_drxpjl td)
{
OperationResult or = new OperationResult();
using (DbEntities db = new DbEntities())
{
var tran = db.CreateTransaction();
try
{
if(ltt==null||ltt.Count==0||lts==null||lts.Count==0||string.IsNullOrEmpty(lts[0].czy)||lts[0].tm==null)
{
or.State = 0;
or.Message = "请求的参数不完整";
return or;
}
string czy = lts[0].czy;
int tm = lts[0].tm;
DateTime tjrq = DateTime.Now;
int tfzje = 0;
BasicBll bb = new BasicBll(); //取各个表的xh用的
//根据sffs - 0现金 1银行 5支票,分别向t_sfmxb中插入相关sffs的信息
//"dbo.t_sfmxb" new t_sfmxb().DbTableName
int xh_sfmxb = bb.GetMax(new t_sfmxb().DbTableName, lts.Count);
for (int i = 0; i < lts.Count; i++)
{
t_sfmxb ts = lts[i];
string sfmxb_str = "insert into t_sfmxb (xh,tm,sffs,je,czy,tjrq,sffx) values (" + xh_sfmxb + "," +tm + "," + ts.sffs + "," + ts.je + ",'" + czy + "','" + tjrq + "',1)";
db.DataAccessor.Execute(sfmxb_str);
xh_sfmxb++;
}
int xh_tfb = bb.GetMax("dbo.t_tfb", ltt.Count);
for (int i = 0; i < ltt.Count; i++)
{
tfzje = tfzje + ltt[i].tfje;
t_tfb tt = ltt[i];
//t_tfb多条插入
//insert t_tfb (xh,tm,zhbm,tfje,czy,tjrq) values (113,0020065433,211,3000,'admin','2015/8/31')
string sqltfb = "insert t_tfb (xh,tm,zhbm,tfje,czy,tjrq) values (" + xh_tfb + "," + tm + "," + tt.zhbm + "," + tt.tfje + ",'" + czy + "','" + tjrq + "')";
db.DataAccessor.Execute(sqltfb);
xh_tfb++;
//根据tm和zhbm更改t_jjxb中的jjx、upflag
string sqljjxb = "update t_jjxb set jjx=1,upflag=1 where tm=" + tm + " and zhbm=" + tt.zhbm;
db.DataAccessor.Execute(sqljjxb);
//删除t_tempdjxm中的 tm 和 zhbm
string sqldel = "delete from t_tempdjxm where tm=" + tm + " and zhbm=" + tt.zhbm;
db.DataAccessor.Execute(sqldel);
//删除医生加项表记录
string sqldeljxysjl = "delete from t_jxysjl where tm=" + tm + " and zhbm=" + tt.zhbm;
db.DataAccessor.Execute(sqldeljxysjl);
}
//根据类型 是个检还是团检 更新grgzb和ttgzb中的 tjzje
string upsql = "";
if (lx == 1) //个检
{
upsql = "update t_grgzb set tjzje=tjzje-"+tfzje+" where tm=" + tm;
}
else
{
upsql = "update t_ttgzb set tjzje=tjzje-"+tfzje+" where tm=" + tm;
}
db.DataAccessor.Execute(upsql);
db.T_drxpjls.Insert(td);
//string sqlstr = "insert into t_drxpjl(xh,tm,hyh,xm,dw,tcorfzname,shouldpay,pay,cash,bank,jzcard,jzmoney,tccard,paper,nomoney,checkpaper,sftf,rq,sfjx)" +
// " values ()";
//db.DataAccessor.Execute(sqlstr);
//插入t_drxpjl
//insert into t_drxpjl(xh,tm,hyh,xm,dw,tcorfzname,shouldpay,pay,cash,bank,jzcard,
//jzmoney,tccard,paper,nomoney,checkpaper,sftf,rq,sfjx)
//values(29326,'0020065433','020065296','王雪萍','','2014体检套餐B(女未婚)','40','40',
//'40.00','0.00','','0.00','','0.00','0.00','0.00','1','2015/8/31',0)
tran.Commit();
or.State = 1;
or.Message = "退费成功";
return or;
}
catch (Exception ex)
{
tran.Rollback();
or.State = 0;
or.Message = (ex.InnerException ?? ex).Message;
return or;
}
}
}
}
}