Esempio n. 1
0
        /// <summary>
        /// 发送配药指令
        /// </summary>
        /// <param name="id"></param>
        private void SendDispensing(int id)
        {
            Patient    patient    = MedicineLogic.QueryPatientById(id);
            Device     device     = MedicineLogic.QueryDeviceById(patient.DeviceId);
            Dispensing dispensing = MedicineLogic.QueryFirstDispensingByPatientId(id);

            if (dispensing == null || dispensing.Id <= 0)
            {
                return;
            }
            byte[] zero     = { 0x00 };
            byte[] deviceNo = device.DeviceNo <= 255 ? zero.Concat(Common.IntToHexByte(device.DeviceNo)).ToArray() : Common.IntToHexByte(device.DeviceNo);
            byte[] funcNo   = { 0x02 };
            byte[] data     = { };
            byte[] open     = { 0x31 };
            byte[] close    = { 0x30 };
            byte[] byteflg  = dispensing.Id > 255 ? Common.IntToHexByte(dispensing.Id) : zero.Concat(Common.IntToHexByte(dispensing.Id)).ToArray();
            data = Enum.GetValues(typeof(TakeTime)).Cast <object>().Aggregate(data, (current, i) => current.Concat((Convert.ToInt32(dispensing.TakeTime) & i.GetHashCode()) != 0 ? open : close).ToArray());
            data = deviceNo.Concat(funcNo).Concat(data).Concat(byteflg).ToArray();
            AutoSendData(device.DeviceIP, data, byteflg);
        }
Esempio n. 2
0
        /// <summary>
        /// Add
        /// </summary>
        /// <param name="entity">entity</param>
        /// <returns>
        /// 返回结果
        /// </returns>
        public long Add(Dispensing entity)
        {
            this.ClearParameters();
            StringBuilder sql = new StringBuilder();

            sql.Append("INSERT INTO Dispensing (");
            sql.Append(" PatientId, ");
            sql.Append(" MedicineId, ");
            sql.Append(" MedicineNumber, ");
            sql.Append(" TakeTime, ");
            sql.Append(" IsTake, ");
            sql.Append(" Deleted ");
            sql.Append(") VALUES(");
            sql.Append(" @PatientId, ");
            sql.Append(" @MedicineId, ");
            sql.Append(" @MedicineNumber, ");
            sql.Append(" @TakeTime, ");
            sql.Append(" @IsTake, ");
            sql.Append(" @Deleted ");
            sql.Append("); ");
            sql.Append("SELECT @Id:= LAST_INSERT_ID(); ");

            this.AddParameter("@PatientId", entity.PatientId);
            this.AddParameter("@MedicineId", entity.MedicineId);
            this.AddParameter("@MedicineNumber", entity.MedicineNumber);
            this.AddParameter("@TakeTime", entity.TakeTime);
            this.AddParameter("@IsTake", entity.IsTake);
            this.AddParameter("@Deleted", entity.Deleted);

            object obj    = this.ExecuteScalar(sql.ToString());
            var    result = obj == null ? 0 : Convert.ToInt64(obj);

            if (result <= 0)
            {
                throw new CustomException("添加失败");
            }
            return(result);
        }