Ejemplo n.º 1
0
        public void Delete(AscmDoor ascmDoor)
        {
            try
            {
                ////删除与用户的关联
                //string sql = "from AscmEmployeeCar where employeeId=" + ascmEmployee.id;
                //IList<AscmEmployeeCar> ilistAscmEmployeeCar = YnDaoHelper.GetInstance().nHibernateHelper.Find<AscmEmployeeCar>(sql);
                //if (ilistAscmEmployeeCar != null && ilistAscmEmployeeCar.Count > 0)
                //{
                //    List<AscmEmployeeCar> list = YnBaseClass2.Helper.ConvertHelper.ConvertIListToList<AscmEmployeeCar>(ilistAscmEmployeeCar);
                //    YnDaoHelper.GetInstance().nHibernateHelper.DeleteList(list);
                //}
                ////删除与模块的关联
                //sql = "from YnWebModuleRoleLink where ascmEmployee.id=" + ascmEmployee.id;
                //IList<YnWebModuleRoleLink> ilistModuleRoleLink = YnDaoHelper.GetInstance().nHibernateHelper.Find<YnWebModuleRoleLink>(sql);
                //if (ilistModuleRoleLink != null && ilistModuleRoleLink.Count > 0)
                //{
                //    List<YnWebModuleRoleLink> list = YnBaseClass2.Helper.ConvertHelper.ConvertIListToList<YnWebModuleRoleLink>(ilistModuleRoleLink);
                //    YnDaoHelper.GetInstance().nHibernateHelper.DeleteList(list);
                //}

                YnDaoHelper.GetInstance().nHibernateHelper.Delete<AscmDoor>(ascmDoor);
            }
            catch (Exception ex)
            {
                YnBaseClass2.Helper.LogHelper.GetLog().Error("删除失败(Delete AscmDoor)", ex);
                throw ex;
            }
        }
Ejemplo n.º 2
0
        public ContentResult DoorSave(AscmDoor ascmDoor_Model, int? id)
        {
            JsonObjectResult jsonObjectResult = new JsonObjectResult();
            try
            {
                AscmDoor ascmDoor = null;
                if (id.HasValue)
                {
                    ascmDoor = AscmDoorService.GetInstance().Get(id.Value);
                }
                else
                {
                    ascmDoor = new AscmDoor();
                    ascmDoor.enabled = true;
                }
                if (ascmDoor == null)
                    throw new Exception("保存大门信息失败!");
                if (string.IsNullOrEmpty(ascmDoor_Model.name))
                    throw new Exception("必须输入名称!");
                //if (ascmReadingHead_Model.plateNumber == null || ascmReadingHead_Model.plateNumber.Trim() == "")
                //    throw new Exception("员工车辆车牌号不能为空!");

                ascmDoor.name = ascmDoor_Model.name.Trim();
                ascmDoor.direction = ascmDoor_Model.direction;
                ascmDoor.vehicleType = ascmDoor_Model.vehicleType;
                ascmDoor.description = ascmDoor_Model.description;

                if (!id.HasValue)
                {
                    object object1 = YnDaoHelper.GetInstance().nHibernateHelper.GetObject("select count(*) from AscmDoor where name='" + ascmDoor_Model.name.Trim() + "'");
                    if (object1 == null)
                        throw new Exception("查询异常!");
                    int iCount = 0;
                    if (int.TryParse(object1.ToString(), out iCount) && iCount > 0)
                        throw new Exception("已经存在大门【" + ascmDoor_Model.name.Trim() + "】!");
                    int maxId = YnDaoHelper.GetInstance().nHibernateHelper.GetMaxId("select max(id) from AscmDoor");
                    ascmDoor.id = maxId + 1;
                }
                else
                {
                    object object1 = YnDaoHelper.GetInstance().nHibernateHelper.GetObject("select count(*) from AscmDoor where name='" + ascmDoor_Model.name.Trim() + "' and id<>" + id.Value + "");
                    if (object1 == null)
                        throw new Exception("查询异常!");
                    int iCount = 0;
                    if (int.TryParse(object1.ToString(), out iCount) && iCount > 0)
                        throw new Exception("已经存在大门【" + ascmDoor_Model.name.Trim() + "】!");
                    //AscmEmployeeCarService.GetInstance().Update(ascmEmployeeCar);
                }

                using (ITransaction tx = YnDaoHelper.GetInstance().nHibernateHelper.GetCurrentSession().BeginTransaction())
                {
                    try
                    {
                        if (!id.HasValue)
                        {
                            YnDaoHelper.GetInstance().nHibernateHelper.Save(ascmDoor);
                        }
                        else
                        {
                            YnDaoHelper.GetInstance().nHibernateHelper.Update(ascmDoor);
                        }

                        tx.Commit();//正确执行提交
                    }
                    catch (Exception ex)
                    {
                        tx.Rollback();//回滚
                        throw ex;
                    }
                }
                jsonObjectResult.result = true;
                jsonObjectResult.message = "";
                jsonObjectResult.id = ascmDoor.id.ToString();
                jsonObjectResult.entity = ascmDoor;
            }
            catch (Exception ex)
            {
                jsonObjectResult.message = ex.Message;
            }
            string sReturn = JsonConvert.SerializeObject(jsonObjectResult);
            return Content(sReturn);
        }
Ejemplo n.º 3
0
 public void Update(AscmDoor ascmDoor)
 {
     using (ITransaction tx = YnDaoHelper.GetInstance().nHibernateHelper.GetCurrentSession().BeginTransaction())
     {
         try
         {
             YnDaoHelper.GetInstance().nHibernateHelper.Update<AscmDoor>(ascmDoor);
             tx.Commit();//正确执行提交
         }
         catch (Exception ex)
         {
             tx.Rollback();//回滚
             YnBaseClass2.Helper.LogHelper.GetLog().Error("修改失败(Update AscmDoor)", ex);
             throw ex;
         }
     }
 }
Ejemplo n.º 4
0
 private int GetSwipeTrafficStatisticsTruck(AscmDoor ascmDoor, DateTime dt1, string direction)
 {
     try
     {
         string sql = "from AscmTruckSwipeLog where doorId=" + ascmDoor.id + " and direction like '" + direction + "%' and createTime>='" + dt1.ToString("yyyy-MM-dd 00:00:00") + "' and createTime<'" + dt1.AddDays(1).ToString("yyyy-MM-dd 00:00:00") + "'";
         List<AscmTruckSwipeLog> listAscmTruckSwipeLog = AscmTruckSwipeLogService.GetInstance().GetList(sql + " order by id");
         List<AscmTruckSwipeLog> listAscmTruckSwipeLog_tmp = new List<AscmTruckSwipeLog>();
         //for (int irow = listAscmEmpCarSwipeLog.Count - 1; irow >= 0; irow--)
         foreach (AscmTruckSwipeLog ascmTruckSwipeLog in listAscmTruckSwipeLog)
         {
             AscmTruckSwipeLog ascmTruckSwipeLog_tmp = listAscmTruckSwipeLog_tmp.FindLast(item => item.rfid == ascmTruckSwipeLog.rfid);
             int count = listAscmTruckSwipeLog_tmp.Count(item => item.rfid == ascmTruckSwipeLog.rfid);
             if (count > 5)
                 continue;
             if (ascmTruckSwipeLog_tmp == null)
             {
                 listAscmTruckSwipeLog_tmp.Add(ascmTruckSwipeLog);
             }
             else
             {
                 DateTime dtCreateTime = DateTime.Now;
                 DateTime dtCreateTime_tmp = DateTime.Now;
                 if (DateTime.TryParse(ascmTruckSwipeLog.createTime, out dtCreateTime) && DateTime.TryParse(ascmTruckSwipeLog_tmp.createTime, out dtCreateTime_tmp))
                 {
                     TimeSpan ts = dtCreateTime.Subtract(dtCreateTime_tmp);
                     if (ts.TotalMinutes > 5)
                     {
                         //10分钟内重复读过滤
                         listAscmTruckSwipeLog_tmp.Add(ascmTruckSwipeLog);
                     }
                     else
                     {
                         ascmTruckSwipeLog_tmp.createTime = ascmTruckSwipeLog.createTime;
                     }
                 }
             }
         }
         return listAscmTruckSwipeLog_tmp.Count;
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }