tijian_jichuang/Code/ShouFei/frmTuiFei.cs

600 lines
18 KiB
C#
Raw Normal View History

2025-02-20 11:54:48 +08:00
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SOH.Kernel;
using EAS;
using EAS.Services;
using SOH.BLL;
using SOH.Entities.DTO;
using SOH.Data;
using SOH.Entities;
namespace SOH.ShouFei
{
[ModuleAttribute(ModuleID = "C17DB9E6-1C77-4585-8F0D-9498BE1FE917", ModuleName = "退费")]
public partial class frmTuiFei : SOH.Window.baseChildForm
{
private short fddm; //分店代码
private short tjlx; //体检类型1个检 2团检
public frmTuiFei()
{
InitializeComponent();
}
private void frmTuiFei_Load(object sender, EventArgs e)
{
Init();
this.gvKTF.AutoGenerateColumns = false;
this.gvTF.AutoGenerateColumns = false;
}
private void Init()
{
//获取分店代码
string fddmstr = LoginUser.yydm;
short fd = 0;
short.TryParse(fddmstr, out fd);
fddm = fd;
}
private void tb_TM_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode != Keys.Enter)
{
return;
}
//除去手动输入的条码以外,其他的清空
DoClear();
string tmstr = this.tb_TM.Text.Trim();
if (string.IsNullOrEmpty(tmstr) || tmstr.Length != 10)
{
MessageBox.Show("条码号格式不正确");
return;
}
int tm = 0;
if (Int32.TryParse(tmstr, out tm))
{
//条码格式正确,进入查询
var vs = ServiceContainer.GetService<IQianTai>();
dto_gzb dg = vs.GetInfoByTm(tm);
if (dg == null)
{
MessageBox.Show("未能找到条码对应的客户");
return;
}
if (dg.fddm != fddm)
{
MessageBox.Show("此客人不是在本店收费的");
return;
}
//tmztz=2或3的时候允许退费
if (dg.tmztz != 2 && dg.tmztz != 3)
{
MessageBox.Show("此客人的状态不允许退费");
return;
}
//体检类型赋值
this.tjlx = dg.lx;
//展示会员的相关信息
this.tbHYH.Text = dg.hyh.ToString();
this.tbXM.Text = dg.xm;
this.tbXB.Text = dg.xb == 0 ? "男" : (dg.xb == 1 ? "女" : "");
this.tbNL.Text = dg.nl.ToString();
this.tbSFLX.Text = dg.gzfbj == 0 ? "公费" : "自费";
this.tbTMH.Text = dg.tm.ToString();
this.tbTCMC.Text = dg.tcmc;
this.tbJXSF.Text = dg.jxgzfbj == 0 ? "公费" : "自费";
var vstf = ServiceContainer.GetService<ITuiFei>();
List<dto_tempdjxm> ldt = vstf.GetKtfByTm(tm, dg.lx);
this.gvKTF.DataSource = null;
this.gvTF.DataSource = null;
this.tbYTJE.Text = "0";
if (ldt == null || ldt.Count == 0)
{
}
else
{
this.gvKTF.DataSource = ldt;
}
}
else
{
MessageBox.Show("条码号格式不正确");
return;
}
}
//取消操作
private void btnQX_Click(object sender, EventArgs e)
{
this.tb_TM.Text = "";
DoClear();
}
//清空各项信息
private void DoClear()
{
this.tjlx = 0; //清除体检类型的信息
//this.tb_TM.Text = ""; //手动输入的条码号 ,要手动清空
this.tbTMH.Text = "";
this.tbHYH.Text = "";
this.tbXM.Text = "";
this.tbXB.Text = "";
this.tbNL.Text = "";
this.tbSFLX.Text = "";
this.tbTCMC.Text = "";
this.tbJXSF.Text = "";
//清空2个grid
this.gvKTF.DataSource = null;
this.gvTF.DataSource = null;
//清空金额 费用 卡信息
this.tbYTJE.Text = "0";
this.tbHJJE.Text = "0";
}
//进行退费操作
private void btnTF_Click(object sender, EventArgs e)
{
string czy=LoginUser.username;
DateTime tjrq=DateTime.Now;
//先进行相关判断
string tmstr = this.tbTMH.Text;
if(string.IsNullOrEmpty(tmstr))
{
MessageBox.Show("请扫描条码,找到相关信息后操作");
return;
}
int tm = 0;
if (!Int32.TryParse(tmstr, out tm))
{
MessageBox.Show("条码号格式错误");
return;
}
if (this.gvTF.Rows.Count == 0)
{
MessageBox.Show("没有可退费项,请选择退费项目后操作");
return;
}
//判断金额是否符合退费总金额现金0银行卡1支票2支付宝3网上套餐5免费4
string ytjestr = this.tbYTJE.Text.Trim();
if (string.IsNullOrEmpty(ytjestr) || ytjestr == "0")
{
MessageBox.Show("没有应退金额,请重新操作");
return;
}
string xjstr = this.tbXJ.Text.Trim();
string yhkstr = this.tbYHK.Text.Trim();
string zpstr = this.tbZP.Text.Trim();
string mfstr = this.tbMF.Text.Trim();
string zfbstr = this.tbZfb.Text.Trim();
string wxstr = this.tbWx.Text.Trim();
string wstcstr = this.tbWstc.Text.Trim();
int ytje =0; //应退金额
int xj = 0; //现金
int yhk = 0; //银行卡金额
int zp = 0; //支票金额
int mf = 0; //免费金额
int zfb = 0;//支付宝金额
int wx = 0;//微信金额
int wstc = 0;//网上套餐金额
if (!Int32.TryParse(ytjestr, out ytje) || ytje < 0)
{
MessageBox.Show("应退金额格式错误");
return;
}
if (!Int32.TryParse(xjstr, out xj)||xj<0)
{
MessageBox.Show("现金金额格式错误");
this.tbXJ.Select();
return;
}
if (!Int32.TryParse(yhkstr, out yhk)||yhk<0)
{
MessageBox.Show("银行卡金额格式错误");
this.tbYHK.Select();
return;
}
if (!Int32.TryParse(zpstr, out zp)||zp<0)
{
MessageBox.Show("体检卡金额格式错误");
this.tbZP.Select();
return;
}
if (!Int32.TryParse(mfstr, out mf) || mf < 0)
{
MessageBox.Show("免费金额格式错误");
this.tbMF.Select();
return;
}
if (!Int32.TryParse(zfbstr, out zfb) || zfb < 0)
{
MessageBox.Show("支付宝金额格式错误");
this.tbZfb.Select();
return;
}
if (!Int32.TryParse(wxstr, out wx) || wx < 0)
{
MessageBox.Show("微信金额格式错误");
this.tbWx.Select();
return;
}
if (!Int32.TryParse(wstcstr, out wstc) || wstc < 0)
{
MessageBox.Show("网上套餐金额格式错误");
this.tbWstc.Select();
return;
}
int zje=xj+yhk+zp+mf+zfb+wx+wstc;
if(zje!=ytje)
{
MessageBox.Show("应退金额与实际退款金额不符");
this.tbXJ.Select();
return;
}
//拼接收费明细信息
List<t_sfmxb> lts = new List<t_sfmxb>();
t_sfmxb ts = new t_sfmxb();
ts.tm = tm;
ts.tjrq = tjrq;
ts.sffx = 1;
ts.czy = czy;
if (xj > 0)
{
ts.sffs = 0; //0现金
ts.je = xj * 100;
lts.Add(ts);
}
if (yhk > 0)
{
ts.sffs = 1; //1银行卡
ts.je = yhk * 100;
lts.Add(ts);
}
if (zp > 0)
{
ts.sffs = 2; //5支票
ts.je = zp * 100;
lts.Add(ts);
}
if (mf > 0)
{
ts.sffs = 4; //2免费
ts.je = mf * 100;
lts.Add(ts);
}
if (zfb > 0)
{
ts.sffs = 3; //3支付宝
ts.je = zfb * 100;
lts.Add(ts);
}
if (wx > 0)
{
ts.sffs = 6; //6微信
ts.je = wx * 100;
lts.Add(ts);
}
if (wstc > 0)
{
ts.sffs = 5; //5网上套餐
ts.je = wstc * 100;
lts.Add(ts);
}
List<t_tfb> ltt = new List<t_tfb>(); //按照zhbm拼接退费表信息
//拼接所需参数信息
List<dto_tempdjxm> ldt = this.gvTF.DataSource == null ? null : (this.gvTF.DataSource as List<dto_tempdjxm>);
if (ldt == null || ldt.Count == 0)
{
MessageBox.Show("没有可退费项,请选择退费项目后操作");
return;
}
else
{
for (int i = 0; i < ldt.Count; i++)
{
dto_tempdjxm dt = ldt[i];
t_tfb tt = new t_tfb();
tt.tm = tm;
tt.zhbm = dt.zhbm;
tt.tfje = dt.zhjg;
tt.czy = czy;
tt.tjrq = tjrq;
ltt.Add(tt);
}
}
short lx = tjlx; //体检类型 1个人 2团体
T_drxpjl td = new T_drxpjl();
td.tm = tm;
td.xm = this.tbXM.Text;
td.hyh = this.tbHYH.Text;
td.dw = "";
td.tcorfzname = this.tbTCMC.Text;
td.shouldpay = this.tbYTJE.Text;
if (xj.ToString().Equals("0"))
{
td.pay = xj.ToString();
}
else
{
td.pay = "-" + (xj * 100).ToString();
}
if (zfb.ToString().Equals("0"))
{
td.cash = zfb.ToString();
}
else
{
td.cash = "-" + (zfb * 100).ToString();
}
if (wx.ToString().Equals("0"))
{
td.sex = wx.ToString();
}
else
{
td.sex = "-" + (wx * 100).ToString();
}
if (yhk.ToString().Equals("0"))
{
td.bank = yhk.ToString();
}
else
{
td.bank = "-" + (yhk * 100).ToString();
}
if (mf.ToString().Equals("0"))
{
td.nomoney = mf.ToString();
}
else
{
td.nomoney = "-" + (mf * 100).ToString();
}
if (zp.ToString().Equals("0"))
{
td.checkpaper = zp.ToString();
}
else
{
td.checkpaper = "-" + (zp * 100).ToString();
}
if (wstc.ToString().Equals("0"))
{
td.tccard = wstc.ToString();
}
else
{
td.tccard = "-" + (wstc * 100).ToString();
}
td.jzcard = "0";
td.jzmoney = "0";
td.paper = "0";
td.sftf = 1;
td.rq = tjrq;
td.sfjx = 0;
var vs = ServiceContainer.GetService<ITuiFei>();
OperationResult or = new OperationResult();
or = vs.TF(lx, ltt, lts, td);
if(or.State==1)
{
MessageBox.Show("退费成功");
this.tb_TM.Clear();
DoClear();
return;
}
else
{
MessageBox.Show("退费失败了,"+or.Message);
return;
}
}
private void btnJia_Click(object sender, EventArgs e)
{
if (this.gvKTF.SelectedRows.Count > 0)
{
int rindex = this.gvKTF.SelectedRows[0].Index;
dto_tempdjxm dt = this.gvKTF.Rows[rindex].DataBoundItem as dto_tempdjxm;
List<dto_tempdjxm> ldt1 = new List<dto_tempdjxm>();
ldt1 = this.gvKTF.DataSource == null ? null : (this.gvKTF.DataSource as List<dto_tempdjxm>);
if (ldt1 == null)
{
ldt1 = new List<dto_tempdjxm>();
}
ldt1.Remove(dt);
this.gvKTF.DataSource = null;
this.gvKTF.DataSource = ldt1;
List<dto_tempdjxm> ldt2 = new List<dto_tempdjxm>();
ldt2 = this.gvTF.DataSource == null ? null : this.gvTF.DataSource as List<dto_tempdjxm>;
if (ldt2 == null)
{
ldt2 = new List<dto_tempdjxm>();
}
ldt2.Add(dt);
this.gvTF.DataSource = null;
this.gvTF.DataSource = ldt2;
SetJE(ldt2);
}
else
{
return;
}
}
private void btnJian_Click(object sender, EventArgs e)
{
if (this.gvTF.SelectedRows.Count > 0)
{
int rindex = this.gvTF.SelectedRows[0].Index;
dto_tempdjxm dt = this.gvTF.Rows[rindex].DataBoundItem as dto_tempdjxm;
List<dto_tempdjxm> ldt2 = new List<dto_tempdjxm>();
ldt2 = this.gvTF.DataSource == null ? null : (this.gvTF.DataSource as List<dto_tempdjxm>);
if (ldt2 == null)
{
ldt2 = new List<dto_tempdjxm>();
}
else
{
ldt2.Remove(dt);
}
this.gvTF.DataSource = null;
this.gvTF.DataSource = ldt2;
List<dto_tempdjxm> ldt1 = new List<dto_tempdjxm>();
ldt1 = this.gvKTF.DataSource == null ? null : (this.gvKTF.DataSource as List<dto_tempdjxm>);
if (ldt1 == null)
{
ldt1 = new List<dto_tempdjxm>();
}
ldt1.Add(dt);
this.gvKTF.DataSource = null;
this.gvKTF.DataSource = ldt1;
SetJE(ldt2);
}
else
{
return;
}
}
//获取退费金额
private void SetJE(List<dto_tempdjxm> ldt)
{
if (ldt == null || ldt.Count == 0)
{
this.tbYTJE.Text = "0";
}
else
{
double je = 0D;
for (int i = 0; i < ldt.Count; i++)
{
double tempje = ldt[i].zhjg_v == null ? 0D : ldt[i].zhjg_v;
je += tempje;
}
int jeint = (int)je;
this.tbYTJE.Text = jeint.ToString();
}
}
private void tbXJ_TextChanged(object sender, EventArgs e)
{
SetHJJE();
}
private void tbYHK_TextChanged(object sender, EventArgs e)
{
SetHJJE();
}
private void tbZP_TextChanged(object sender, EventArgs e)
{
SetHJJE();
}
//根据现金、银行卡、支票的退费金额 合计出总的退费金额
private void SetHJJE()
{
string xjstr = this.tbXJ.Text.Trim();
string yhkstr = this.tbYHK.Text.Trim();
string zpstr = this.tbZP.Text.Trim();
string zfbstr = this.tbZfb.Text.Trim();
string wxstr = this.tbWx.Text.Trim();
string wstcstr = this.tbWstc.Text.Trim();
int xj = 0; //现金
int yhk = 0; //银行卡金额
int zp = 0; //支票金额
int zfb = 0;//支付宝金额
int wstc = 0;//网上套餐
int wx = 0;//微信金额
if (!Int32.TryParse(xjstr, out xj)||xj<0)
{
MessageBox.Show("现金金额格式错误");
this.tbXJ.Select();
return;
}
if (!Int32.TryParse(yhkstr, out yhk) || yhk < 0)
{
MessageBox.Show("银行卡金额格式错误");
this.tbYHK.Select();
return;
}
if (!Int32.TryParse(zpstr, out zp)||zp<0)
{
MessageBox.Show("支票金额格式错误");
this.tbZP.Select();
return;
}
if (!Int32.TryParse(zfbstr, out zfb) || zfb < 0)
{
MessageBox.Show("支付宝金额格式错误");
this.tbZfb.Select();
return;
}
if (!Int32.TryParse(wxstr, out wx) || wx < 0)
{
MessageBox.Show("微信金额格式错误");
this.tbWx.Select();
return;
}
if (!Int32.TryParse(wstcstr, out wstc) || wstc < 0)
{
MessageBox.Show("网上套餐金额格式错误");
this.tbWstc.Select();
return;
}
int zje = xj + yhk + zp+zfb+wstc+wx;
this.tbHJJE.Text = zje.ToString();
}
private void tbZfb_TextChanged(object sender, EventArgs e)
{
SetHJJE();
}
private void tbWstc_TextChanged(object sender, EventArgs e)
{
SetHJJE();
}
private void label16_Click(object sender, EventArgs e)
{
}
private void tbWx_TextChanged(object sender, EventArgs e)
{
SetHJJE();
}
}
}