public SystemStatus GetLaji() { SystemStatus laji; using (chargebitEntities db = new chargebitEntities()) { List <LaJi> lajis = (from l in db.LaJi where l.PId == 3 orderby l.UP descending select l).ToList <LaJi>(); if (lajis.Count > 1) { db.Database.SqlQuery <int>("delete * from LaJi"); LaJi tmp = new LaJi() { PId = 3, UP = true }; db.LaJi.Add(tmp); db.SaveChanges(); laji = SystemStatus.RUNNING; } else { if (lajis[0].UP) { laji = SystemStatus.RUNNING; } else { laji = SystemStatus.DOWN; } } } return(laji); }
public void StartSystem() { if (!CurrentLoginUser.IsWebMaster) { throw new KMBitException("你不是系统管理员(站长),没有权限软开启系统"); } using (chargebitEntities db = new chargebitEntities()) { List <LaJi> lajis = (from l in db.LaJi where l.PId == 3 orderby l.UP descending select l).ToList <LaJi>(); LaJi lj = lajis[0]; lj.UP = true; db.SaveChanges(); } }
public ChargeResult Charge(ChargeOrder order) { ChargeResult result = null; ICharge chargeMgr = null; chargebitEntities db = null; Charge_Order cOrder = null; try { db = new chargebitEntities(); cOrder = (from co in db.Charge_Order where co.Id == order.Id select co).FirstOrDefault <Charge_Order>(); List <LaJi> las = (from laji in db.LaJi where laji.PId == 3 select laji).ToList <LaJi>(); if (las.Count == 0) { result = new ChargeResult() { Status = ChargeStatus.FAILED, Message = "系统已经被停用,请联系统管理员" }; Logger.Warn(result.Message); return(result); } if (las.Count > 1) { result = new ChargeResult() { Status = ChargeStatus.FAILED, Message = "系统设置有错误,请联系统管理员" }; Logger.Warn(result.Message); return(result); } LaJi la = las[0]; if (!la.UP) { result = new ChargeResult() { Status = ChargeStatus.FAILED, Message = "系统已经被停用,请联系统管理员" }; Logger.Warn(result.Message); return(result); } if (cOrder == null) { result = new ChargeResult() { Status = ChargeStatus.FAILED, Message = ChargeConstant.ORDER_NOT_EXIST }; return(result); } Resource_taocan taocan = (from tc in db.Resource_taocan where tc.Id == order.ResourceTaocanId select tc).FirstOrDefault <Resource_taocan>(); if (!taocan.Enabled) { result = new ChargeResult() { Status = ChargeStatus.FAILED, Message = ChargeConstant.RESOURCE_TAOCAN_DISABLED }; return(result); } KMBit.DAL.Resource resource = (from ri in db.Resource join tr in db.Resource_taocan on ri.Id equals tr.Resource_id where tr.Id == order.ResourceTaocanId select ri).FirstOrDefault <Resource>(); if (resource == null) { db.Charge_Order.Remove(cOrder); db.SaveChanges(); result = new ChargeResult() { Status = ChargeStatus.FAILED, Message = "落地资源部存在,请联系平台管理员" }; return(result); } if (!resource.Enabled) { db.Charge_Order.Remove(cOrder); db.SaveChanges(); result = new ChargeResult() { Status = ChargeStatus.FAILED, Message = ChargeConstant.RESOURCE_DISABLED }; return(result); } if (order.ResourceId == 0) { order.ResourceId = resource.Id; } KMBit.DAL.Resrouce_interface rInterface = (from ri in db.Resrouce_interface where ri.Resource_id == order.ResourceId select ri).FirstOrDefault <Resrouce_interface>(); if (rInterface == null) { db.Charge_Order.Remove(cOrder); db.SaveChanges(); result = new ChargeResult() { Status = ChargeStatus.FAILED, Message = ChargeConstant.RESOURCE_INTERFACE_NOT_CONFIGURED }; return(result); } object o = Assembly.Load(rInterface.Interface_assemblyname).CreateInstance(rInterface.Interface_classname); chargeMgr = (ICharge)o; result = chargeMgr.Charge(order); } catch (Exception ex) { Logger.Error(ex); if (cOrder != null) { db.Charge_Order.Remove(cOrder); db.SaveChanges(); } } finally { if (db != null) { db.Dispose(); } } return(result); }