BLL层
#region 策略模式
public abstract class Spend
{
public abstract string acceptCash(Entity.DownLine downLine);
}
//计算一般用户金额
public class FixedUser : Spend
{
public override string acceptCash(Entity.DownLine downLine)
{
#region 计算一般用户收费金额
//计算上机时间
TimeSpan ontime1 = Convert.ToDateTime(DateTime.Now.ToString())- Convert.ToDateTime(downLine.OnTime);
//转化时间
//double ontime2 = Convert.ToDouble(ontime1.TotalHours);
//int time = Convert.ToInt32(ontime2 + 1);
//downLine.SpendTime = Convert.ToString(time);
//计算收费金额
downLine.SpendMoney = Convert.ToString(Convert.ToInt32(downLine.SpendTime) * Convert.ToInt32(downLine.Rate));
return Convert.ToString(downLine);
#endregion
}
}
//计算超级用户金额
public class SuperUser : Spend
{
public override string acceptCash(Entity.DownLine downLine)
{
#region 超级用户金额
//计算上机时间
//TimeSpan ontime1 = Convert.ToDateTime(DateTime.Now.ToString()) - Convert.ToDateTime(downLine.OnTime);
////转换时间
//double ontime2 = Convert.ToDouble(ontime1.TotalHours);
//downLine.SpendTime = Convert.ToString(ontime2 + 1);
downLine.SpendMoney = Convert.ToString(Convert.ToInt32(downLine.SpendTime) * Convert.ToInt32(downLine.TmpRate));
return Convert.ToString(downLine);
#endregion
}
}
//下机处理职责链模式
public abstract class OperateMoneyManager
{
protected OperateMoneyManager successor;
//设置继承者
public void SetSuccessor(OperateMoneyManager successor)
{
this.successor = successor;
}
//处理请求的抽象方法
public FixedUser FixedUser = new FixedUser();
public SuperUser SuperUser = new SuperUser();
public abstract void GetMoney(Entity.DownLine downLine);
}
//具体策略
public class OperateMoneyOne : OperateMoneyManager
{
public override void GetMoney(Entity.DownLine downLine)
{
//当上机时间小于准备时间,不收费
if (Convert.ToDouble(downLine.SpendTime) <= Convert.ToDouble(downLine.PrepareTime))
{
downLine.SpendTime = Convert.ToString(0);
downLine.SpendMoney = Convert.ToString(0);
}
else
{
successor.GetMoney( downLine);
}
}
}
public class OperateMoneyTwo : OperateMoneyManager
{
public override void GetMoney(Entity.DownLine downLine)
{
if (Convert.ToDouble(downLine.SpendTime) > (Convert.ToDouble(downLine.PrepareTime) / 60))
{
if (downLine.Type == "普通用户")
{
FixedUser.acceptCash(downLine);//调用策略模式
}
else
{
SuperUser.acceptCash(downLine);
}
}
else
{
successor.GetMoney(downLine);
}
}
}
#endregion
Facade层
public void Money(Entity.DownLine downLine)
{
//实例化具体策略
BLL.OperateMoneyManager one = new BLL.OperateMoneyOne();
BLL.OperateMoneyManager two = new BLL.OperateMoneyTwo();
//设置职责链上家和下家
one.SetSuccessor(two);
//提交请求到 B层
one.GetMoney(downLine);
}
UI层
{
//给上机表数据赋值
Entity.DownLine downLine = new Entity.DownLine();
Facade.DownLineFacade down = new Facade.DownLineFacade();
downLine.CardNO = Convert.ToInt32( txtCardNO.Text.Trim());
DataTable flag = down.FindOnLine(downLine);
if (flag.Rows .Count ==0)
{
MessageBox.Show("此卡号未上机","温馨提示",0,MessageBoxIcon.Warning);
}
else
{
downLine.OnTime = flag.Rows[0][1].ToString();
downLine.Type = flag.Rows[0][2].ToString();
downLine.Money = flag.Rows[0][3].ToString();
DataTable flags = down.FindBasicdata(downLine);
if (flags .Rows.Count !=0)
{
//basicdata表信息
downLine.Rate =flags.Rows[0][0].ToString();
downLine.TmpRate = flags.Rows[0][1].ToString();
downLine.UnitTime = flags.Rows[0][2].ToString();
downLine.PrepareTime= flags.Rows[0][3].ToString();
downLine.LimitMoney =flags.Rows[0][4].ToString();
TimeSpan ontime1 = Convert.ToDateTime(DateTime.Now.ToString()) - Convert.ToDateTime(downLine.OnTime);
//转化时间
double ontime2 = Convert.ToDouble(ontime1.TotalHours);
int time = Convert.ToInt32(ontime2 + 1);
downLine.SpendTime = Convert.ToString(time);
//计算金额
Facade.DownLineFacade downs=new Facade.DownLineFacade();
downs.Money(downLine);
//修改mation金额
downLine.Money = Convert.ToString( Convert.ToInt32(downLine.Money) - Convert.ToInt32(downLine.SpendMoney));
bool flagss = down.UpdataMation(downLine);
if (flagss==true)
{
//删除上机表信息
bool delete = down.DeleteOnLine(downLine);
if (delete==true)
{
//添加纪录
downLine.OnTime=flag.Rows[0][1].ToString();
downLine.DownTime= DateTime.Now.ToString();
downLine.Computer = flag.Rows[0][4].ToString();
downLine.UserName = UserName;
bool insert = down.InsertDownLine(downLine);
if (insert==true)
{
txtMoney.Text = downLine.Money;
MessageBox.Show("退卡成功", "温馨提示", 0, MessageBoxIcon.Information);
}
}
}
}
}
}
catch (Exception)
{
throw;
}