Exemplo n.º 1
0
        private void PromptTextASAPList()
        {
            if (!PrefC.GetBool(PrefName.WebSchedAsapEnabled) || Appointments.RefreshASAP(0, 0, _appt.ClinicNum, new List <ApptStatus>()).Count == 0 ||
                !MsgBox.Show("Appointment", MsgBoxButtons.YesNo, "Text patients on the ASAP List and offer them this opening?"))
            {
                return;
            }
            DateTime slotStart = AppointmentL.DateSelected.Date;            //Midnight
            DateTime slotEnd   = AppointmentL.DateSelected.Date.AddDays(1); //Midnight tomorrow
            //Loop through all other appts in the op to find a slot that will not overlap.
            List <Appointment> listApptsInOp = Appointments.GetAppointmentsForOpsByPeriod(new List <long> {
                _appt.Op
            }, _appt.AptDateTime);

            foreach (Appointment otherAppt in listApptsInOp.Where(x => x.AptNum != _appt.AptNum))
            {
                DateTime dateEndApt = otherAppt.AptDateTime.AddMinutes(otherAppt.Pattern.Length * 5);
                if (dateEndApt.Between(slotStart, _appt.AptDateTime))
                {
                    slotStart = dateEndApt;
                }
                if (otherAppt.AptDateTime.Between(_appt.AptDateTime, slotEnd))
                {
                    slotEnd = otherAppt.AptDateTime;
                }
            }
            slotStart = ODMathLib.Max(slotStart, _appt.AptDateTime.AddHours(-1));
            slotEnd   = ODMathLib.Min(slotEnd, _appt.AptDateTime.AddHours(3));
            FormASAP formASAP = new FormASAP(_appt.AptDateTime, slotStart, slotEnd, _appt.Op);

            formASAP.ShowDialog();
        }
Exemplo n.º 2
0
            ///<summary>Returns true if the time length requested will fit in the time slot and there are no other appointments in the slot.</summary>
            public bool IsApptSlotAvailable(int minutes, long opNum, DateTime slotStart, DateTime slotEnd)
            {
                if (!_listDateOps.Any(x => x.Item1 == slotStart.Date && x.Item2 == opNum))
                {
                    _listAppts.AddRange(Appointments.GetApptsForDatesOps(new List <ODTuple <DateTime, long> > {
                        new ODTuple <DateTime, long>(slotStart.Date, opNum)
                    }));
                    _listDateOps.Add(new Tuple <DateTime, long>(slotStart.Date, opNum));
                }
                DateTime newSlotEnd = ODMathLib.Min(slotStart.AddMinutes(minutes), slotEnd);

                if (_listAppts.Where(x => x.Op == opNum)
                    .Any(x => MiscUtils.DoSlotsOverlap(x.AptDateTime, x.AptDateTime.AddMinutes(x.Length), slotStart, newSlotEnd)))
                {
                    return(false);
                }
                return(true);
            }
Exemplo n.º 3
0
        ///<summary>Applies the document specified cropping, flip, rotation, brightness and contrast transformations to the image and returns the resulting image. Zoom and translation must be handled by the calling code. The returned image is always a new image that can be modified without affecting the original image. The change in the image's center point is returned into deltaCenter, so that rotation offsets can be properly calculated when displaying the returned image.</summary>
        public static Bitmap ApplyDocumentSettingsToImage(Document doc, Bitmap image, ImageSettingFlags settings)
        {
            if (image == null)           //Any operation on a non-existant image produces a non-existant image.
            {
                return(null);
            }
            if (doc == null)           //No doc implies no operations, implies that the image should be returned "unaltered".
            //return (Bitmap)image.Clone();//this would keep the original resolution, which causes problems.
            {
                return(new Bitmap(image));               //resets the resolution to 96, just like it does for docs 20 lines down.
            }
            //CROP - Implies that the croping rectangle must be saved in raw-image-space coordinates,
            //with an origin of that equal to the upper left hand portion of the image.
            Rectangle cropResult;

            if ((settings & ImageSettingFlags.CROP) != 0 &&                                                   //Crop not requested.
                doc.CropW > 0 && doc.CropH > 0)                                                               //No clip area yet defined, so no clipping is performed.
            {
                float[] cropDims = ODMathLib.IntersectRectangles(0, 0, image.Width, image.Height,             //Intersect image rectangle with
                                                                 doc.CropX, doc.CropY, doc.CropW, doc.CropH); //document crop rectangle.
                if (cropDims.Length == 0)                                                                     //The entire image has been cropped away.
                {
                    return(null);
                }
                //Rounds dims up, so that data is not lost, but possibly not removing all of what was expected.
                cropResult = new Rectangle((int)cropDims[0], (int)cropDims[1],
                                           (int)Math.Ceiling(cropDims[2]), (int)Math.Ceiling(cropDims[3]));
            }
            else
            {
                cropResult = new Rectangle(0, 0, image.Width, image.Height);                //No cropping.
            }
            //Always use 32-bit images in memory. We could use 24-bit images here (it works in Windows, but MONO produces
            //output using 32-bit data on a 24-bit image in that case, providing horrible output). Perhaps we can update
            //this when MONO is more fully featured.
            Bitmap    cropped     = new Bitmap(cropResult.Width, cropResult.Height, PixelFormat.Format32bppArgb);
            Graphics  g           = Graphics.FromImage(cropped);
            Rectangle croppedDims = new Rectangle(0, 0, cropped.Width, cropped.Height);

            g.DrawImage(image, croppedDims, cropResult, GraphicsUnit.Pixel);
            g.Dispose();
            //FLIP AND ROTATE - must match the operations in GetDocumentFlippedRotatedMatrix().
            if ((settings & ImageSettingFlags.FLIP) != 0)
            {
                if (doc.IsFlipped)
                {
                    cropped.RotateFlip(RotateFlipType.RotateNoneFlipX);
                }
            }
            if ((settings & ImageSettingFlags.ROTATE) != 0)
            {
                if (doc.DegreesRotated % 360 == 90)
                {
                    cropped.RotateFlip(RotateFlipType.Rotate90FlipNone);
                }
                else if (doc.DegreesRotated % 360 == 180)
                {
                    cropped.RotateFlip(RotateFlipType.Rotate180FlipNone);
                }
                else if (doc.DegreesRotated % 360 == 270)
                {
                    cropped.RotateFlip(RotateFlipType.Rotate270FlipNone);
                }
            }
            //APPLY BRIGHTNESS AND CONTRAST -
            //TODO: should be updated later for more general functions
            //(create inputValues and outputValues from stored db function/table).
            if ((settings & ImageSettingFlags.COLORFUNCTION) != 0 &&
                doc.WindowingMax != 0 &&                             //Do not apply color function if brightness/contrast have never been set (assume normal settings).
                !(doc.WindowingMax == 255 && doc.WindowingMin == 0)) //Don't apply if brightness/contrast settings are normal.
            {
                float[] inputValues = new float[] {
                    doc.WindowingMin / 255f,
                    doc.WindowingMax / 255f,
                };
                float[] outputValues = new float[] {
                    0,
                    1,
                };
                BitmapData croppedData = null;
                try {
                    croppedData = cropped.LockBits(new Rectangle(0, 0, cropped.Width, cropped.Height),
                                                   ImageLockMode.ReadWrite, cropped.PixelFormat);
                    unsafe {
                        byte *pBits;
                        if (croppedData.Stride < 0)
                        {
                            pBits = (byte *)croppedData.Scan0.ToPointer() + croppedData.Stride * (croppedData.Height - 1);
                        }
                        else
                        {
                            pBits = (byte *)croppedData.Scan0.ToPointer();
                        }
                        //The following loop goes through each byte of each 32-bit value and applies the color function to it.
                        //Thus, the same transformation is performed to all 4 color components equivalently for each pixel.
                        for (int i = 0; i < croppedData.Stride * croppedData.Height; i++)
                        {
                            float colorComponent = pBits[i] / 255f;
                            float rangedOutput;
                            if (colorComponent <= inputValues[0])
                            {
                                rangedOutput = outputValues[0];
                            }
                            else if (colorComponent >= inputValues[inputValues.Length - 1])
                            {
                                rangedOutput = outputValues[outputValues.Length - 1];
                            }
                            else
                            {
                                int j = 0;
                                while (!(inputValues[j] <= colorComponent && colorComponent < inputValues[j + 1]))
                                {
                                    j++;
                                }
                                rangedOutput = ((colorComponent - inputValues[j]) * (outputValues[j + 1] - outputValues[j]))
                                               / (inputValues[j + 1] - inputValues[j]);
                            }
                            pBits[i] = (byte)Math.Round(255 * rangedOutput);
                        }
                    }
                }
                catch {
                }
                finally {
                    try {
                        cropped.UnlockBits(croppedData);
                    }
                    catch {
                    }
                }
            }
            return(cropped);
        }