/// <summary> /// 更新设备 /// </summary> public bool UpdateDevice() { try { AMS_DeviceModel samedevice = AMS_DeviceBLL.GetDevicebyNo(_Number); if (samedevice == null || samedevice.Id == _Id) { AMS_DeviceModel newdevice = new AMS_DeviceModel(); newdevice.CampusId = _Campusid; newdevice.Id = _Id; newdevice.CaputrePath = _Caputrepath; newdevice.CaputreTime = _Caputretime; newdevice.IsDel = _Isdel; newdevice.Number = _Number; newdevice.Flag = true; newdevice.Describe = _Describe; if (AMS_DeviceBLL.UpdateDeviceModel(newdevice) == AdvertManage.Model.Enum.HandleResult.Failed) { throw new Exception("设备更新失败!详情请查看日志文件"); } return(true); } else { throw new Exception("该设备编号已存在!"); } } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message); return(false); } }
/// <summary> /// 添加设备 /// </summary> public bool AddDevice() { try { AMS_DeviceModel samedevice = AMS_DeviceBLL.GetDevicebyNo(_Number); if (samedevice == null) { AMS_DeviceModel newdevice = new AMS_DeviceModel(); if (_Campusid == 0) { throw new Exception("请选择校区!"); } newdevice.CampusId = _Campusid; newdevice.IsDel = _Isdel; newdevice.Number = _Number; newdevice.Flag = _Flag; newdevice.Describe = _Describe; if (AMS_DeviceBLL.AddDeviceModel(newdevice) == AdvertManage.Model.Enum.HandleResult.Failed) { throw new Exception("设备添加失败!详情请查看日志文件"); } return(true); } else { throw new Exception("该设备编号已存在!"); } } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message); return(false); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(AMS_DeviceModel model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update AMS_Device set "); strSql.Append("Number=@Number,"); strSql.Append("CampusId=@CampusId,"); strSql.Append("IsDel=@IsDel,"); strSql.Append("Flag=@Flag,"); strSql.Append("Describe=@Describe,"); strSql.Append("CaputrePath=@CaputrePath,"); strSql.Append("CaputreTime=@CaputreTime"); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@Number", SqlDbType.NVarChar, 50), new SqlParameter("@CampusId", SqlDbType.Int, 4), new SqlParameter("@IsDel", SqlDbType.Bit, 1), new SqlParameter("@Flag", SqlDbType.Bit, 1), new SqlParameter("@Describe", SqlDbType.NVarChar, 200), new SqlParameter("@CaputrePath", SqlDbType.NVarChar, 100), new SqlParameter("@CaputreTime", SqlDbType.DateTime), new SqlParameter("@Id", SqlDbType.Int, 4) }; parameters[0].Value = model.Number; parameters[1].Value = model.CampusId; parameters[2].Value = model.IsDel; parameters[3].Value = model.Flag; parameters[4].Value = model.Describe; parameters[5].Value = model.CaputrePath; parameters[6].Value = model.CaputreTime; parameters[7].Value = model.Id; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(AMS_DeviceModel model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into AMS_Device("); strSql.Append("Number,CampusId,IsDel,Flag,Describe,CaputrePath,CaputreTime)"); strSql.Append(" values ("); strSql.Append("@Number,@CampusId,@IsDel,@Flag,@Describe,@CaputrePath,@CaputreTime)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@Number", SqlDbType.NVarChar, 50), new SqlParameter("@CampusId", SqlDbType.Int, 4), new SqlParameter("@IsDel", SqlDbType.Bit, 1), new SqlParameter("@Flag", SqlDbType.Bit, 1), new SqlParameter("@Describe", SqlDbType.NVarChar, 200), new SqlParameter("@CaputrePath", SqlDbType.NVarChar, 100), new SqlParameter("@CaputreTime", SqlDbType.DateTime) }; parameters[0].Value = model.Number; parameters[1].Value = model.CampusId; parameters[2].Value = model.IsDel; parameters[3].Value = model.Flag; parameters[4].Value = model.Describe; parameters[5].Value = model.CaputrePath; parameters[6].Value = model.CaputreTime; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }