private bool TryToSaveData()
        {
            if (!butOK.Enabled)             //if the OK button is not enabled, user does not have permission.
            {
                return(true);
            }
            if (textShowInTerminal.errorProvider1.GetError(textShowInTerminal) != "")
            {
                MsgBox.Show(this, "Please fix data entry errors first.");
                return(false);
            }
            DateTime dateTimeSheet = DateTime.MinValue;

            try{
                dateTimeSheet = DateTime.Parse(textDateTime.Text);
            }
            catch {
                MsgBox.Show(this, "Please fix data entry errors first.");
                return(false);
            }
            SheetCur.DateTimeSheet  = dateTimeSheet;
            SheetCur.Description    = textDescription.Text;
            SheetCur.InternalNote   = textNote.Text;
            SheetCur.ShowInTerminal = PIn.Byte(textShowInTerminal.Text);
            FillFieldsFromControls();            //But SheetNums will still be 0 for a new sheet.
            bool isNew = SheetCur.IsNew;

            if (isNew)
            {
                Sheets.Insert(SheetCur);
            }
            else
            {
                Sheets.Update(SheetCur);
            }
            List <SheetField> drawingList = new List <SheetField>();

            foreach (SheetField fld in SheetCur.SheetFields)
            {
                if (fld.FieldType == SheetFieldType.SigBox)
                {
                    continue;                    //done in a separate step
                }
                if (fld.FieldType == SheetFieldType.Image ||
                    fld.FieldType == SheetFieldType.Rectangle ||
                    fld.FieldType == SheetFieldType.Line)
                {
                    if (!fld.IsNew)
                    {
                        continue;                        //it only saves them when the sheet is first created because user can't edit anyway.
                    }
                }
                fld.SheetNum = SheetCur.SheetNum;              //whether or not isnew
                if (fld.FieldType == SheetFieldType.Drawing)
                {
                    fld.IsNew = true;
                    drawingList.Add(fld);
                }
                else
                {
                    if (fld.IsNew)
                    {
                        SheetFields.Insert(fld);
                    }
                    else
                    {
                        SheetFields.Update(fld);
                    }
                }
            }
            if (drawingsAltered)
            {
                //drawings get saved as a group rather than with the other fields.
                SheetFields.SetDrawings(drawingList, SheetCur.SheetNum);
            }
            if (isNew)
            {
                Sheets.SaveParameters(SheetCur);
            }
            //SigBoxes must come after ALL other types in order for the keyData to be in the right order.
            SheetField field;

            foreach (Control control in panelMain.Controls)
            {
                if (control.GetType() != typeof(OpenDental.UI.SignatureBoxWrapper))
                {
                    continue;
                }
                if (control.Tag == null)
                {
                    continue;
                }
                field = (SheetField)control.Tag;
                OpenDental.UI.SignatureBoxWrapper sigBox = (OpenDental.UI.SignatureBoxWrapper)control;
                if (sigBox.GetSigChanged())
                {
                    //refresh the fields so they are in the correct order
                    SheetFields.GetFieldsAndParameters(SheetCur);
                    bool   sigIsTopaz = sigBox.GetSigIsTopaz();
                    string keyData    = Sheets.GetSignatureKey(SheetCur);
                    string signature  = sigBox.GetSignature(keyData);
                    field.FieldValue = "";
                    if (signature != "")
                    {
                        if (sigIsTopaz)
                        {
                            field.FieldValue += "1";
                        }
                        else
                        {
                            field.FieldValue += "0";
                        }
                        field.FieldValue += signature;
                    }
                }
                field.SheetNum = SheetCur.SheetNum; //whether or not isnew
                if (isNew)                          //is this really testing the proper object?
                {
                    SheetFields.Insert(field);
                }
                else
                {
                    SheetFields.Update(field);
                }
            }
            return(true);
        }
Exemple #2
0
        public static void CreatePdfPage(Sheet sheet, PdfPage page)
        {
            page.Width  = p(sheet.Width);         //XUnit.FromInch((double)sheet.Width/100);  //new XUnit((double)sheet.Width/100,XGraphicsUnit.Inch);
            page.Height = p(sheet.Height);        //new XUnit((double)sheet.Height/100,XGraphicsUnit.Inch);
            if (sheet.IsLandscape)
            {
                page.Orientation = PageOrientation.Landscape;
            }
            XGraphics g = XGraphics.FromPdfPage(page);

            g.SmoothingMode = XSmoothingMode.HighQuality;
            //g.PageUnit=XGraphicsUnit. //wish they had pixel
            //XTextFormatter tf = new XTextFormatter(g);//needed for text wrap
            //tf.Alignment=XParagraphAlignment.Left;
            //pd.DefaultPageSettings.Landscape=
            //already done?:SheetUtil.CalculateHeights(sheet,g);//this is here because of easy access to g.
            XFont      xfont;
            XFontStyle xfontstyle;

            //first, draw images--------------------------------------------------------------------------------------
            foreach (SheetField field in sheet.SheetFields)
            {
                if (field.FieldType != SheetFieldType.Image)
                {
                    continue;
                }
                string filePathAndName = ODFileUtils.CombinePaths(SheetUtil.GetImagePath(), field.FieldName);
                Bitmap bitmapOriginal  = null;
                if (field.FieldName == "Patient Info.gif")
                {
                    bitmapOriginal = Properties.Resources.Patient_Info;
                }
                else if (File.Exists(filePathAndName))
                {
                    bitmapOriginal = new Bitmap(filePathAndName);
                }
                else
                {
                    continue;
                }
                Bitmap bitmapResampled = (Bitmap)bitmapOriginal.Clone();
                if (bitmapOriginal.HorizontalResolution != 96 || bitmapOriginal.VerticalResolution != 96)            //to avoid slowdown for other pdfs
                //The scaling on the XGraphics.DrawImage() function causes unreadable output unless the image is in 96 DPI native format.
                //We use GDI here first to convert the image to the correct size and DPI, then pass the second image to XGraphics.DrawImage().
                {
                    bitmapResampled.Dispose();
                    bitmapResampled = null;
                    bitmapResampled = new Bitmap(field.Width, field.Height);
                    Graphics gr = Graphics.FromImage(bitmapResampled);
                    gr.DrawImage(bitmapOriginal, 0, 0, field.Width, field.Height);
                    gr.Dispose();
                }
                g.DrawImage(bitmapResampled, p(field.XPos), p(field.YPos), p(field.Width), p(field.Height));
                bitmapResampled.Dispose();
                bitmapResampled = null;
                bitmapOriginal.Dispose();
                bitmapOriginal = null;
            }
            //then, drawings--------------------------------------------------------------------------------------------
            XPen pen = new XPen(XColors.Black, p(2));

            string[]     pointStr;
            List <Point> points;
            Point        point;

            string[] xy;
            foreach (SheetField field in sheet.SheetFields)
            {
                if (field.FieldType != SheetFieldType.Drawing)
                {
                    continue;
                }
                pointStr = field.FieldValue.Split(';');
                points   = new List <Point>();
                for (int j = 0; j < pointStr.Length; j++)
                {
                    xy = pointStr[j].Split(',');
                    if (xy.Length == 2)
                    {
                        point = new Point(PIn.Int(xy[0]), PIn.Int(xy[1]));
                        points.Add(point);
                    }
                }
                for (int i = 1; i < points.Count; i++)
                {
                    g.DrawLine(pen, p(points[i - 1].X), p(points[i - 1].Y), p(points[i].X), p(points[i].Y));
                }
            }
            //then, rectangles and lines----------------------------------------------------------------------------------
            XPen pen2 = new XPen(XColors.Black, p(1));

            foreach (SheetField field in sheet.SheetFields)
            {
                if (field.FieldType == SheetFieldType.Rectangle)
                {
                    g.DrawRectangle(pen2, p(field.XPos), p(field.YPos), p(field.Width), p(field.Height));
                }
                if (field.FieldType == SheetFieldType.Line)
                {
                    g.DrawLine(pen2, p(field.XPos), p(field.YPos),
                               p(field.XPos + field.Width),
                               p(field.YPos + field.Height));
                }
            }
            //then, draw text--------------------------------------------------------------------------------------------
            Bitmap   doubleBuffer = new Bitmap(sheet.Width, sheet.Height);
            Graphics gfx          = Graphics.FromImage(doubleBuffer);

            foreach (SheetField field in sheet.SheetFields)
            {
                if (field.FieldType != SheetFieldType.InputField &&
                    field.FieldType != SheetFieldType.OutputText &&
                    field.FieldType != SheetFieldType.StaticText)
                {
                    continue;
                }
                xfontstyle = XFontStyle.Regular;
                if (field.FontIsBold)
                {
                    xfontstyle = XFontStyle.Bold;
                }
                xfont = new XFont(field.FontName, field.FontSize, xfontstyle);
                //xfont=new XFont(field.FontName,field.FontSize,xfontstyle);
                //Rectangle rect=new Rectangle((int)p(field.XPos),(int)p(field.YPos),(int)p(field.Width),(int)p(field.Height));
                XRect xrect = new XRect(p(field.XPos), p(field.YPos), p(field.Width), p(field.Height));
                //XStringFormat format=new XStringFormat();
                //tf.DrawString(field.FieldValue,font,XBrushes.Black,xrect,XStringFormats.TopLeft);
                GraphicsHelper.DrawStringX(g, gfx, 1d / p(1), field.FieldValue, xfont, XBrushes.Black, xrect);
            }
            gfx.Dispose();
            //then, checkboxes----------------------------------------------------------------------------------
            XPen pen3 = new XPen(XColors.Black, p(1.6f));

            foreach (SheetField field in sheet.SheetFields)
            {
                if (field.FieldType != SheetFieldType.CheckBox)
                {
                    continue;
                }
                if (field.FieldValue == "X")
                {
                    g.DrawLine(pen3, p(field.XPos), p(field.YPos), p(field.XPos + field.Width), p(field.YPos + field.Height));
                    g.DrawLine(pen3, p(field.XPos + field.Width), p(field.YPos), p(field.XPos), p(field.YPos + field.Height));
                }
            }
            //then signature boxes----------------------------------------------------------------------
            foreach (SheetField field in sheet.SheetFields)
            {
                if (field.FieldType != SheetFieldType.SigBox)
                {
                    continue;
                }
                SignatureBoxWrapper wrapper = new SignatureBoxWrapper();
                wrapper.Width  = field.Width;
                wrapper.Height = field.Height;
                if (field.FieldValue.Length > 0)              //a signature is present
                {
                    bool sigIsTopaz = false;
                    if (field.FieldValue[0] == '1')
                    {
                        sigIsTopaz = true;
                    }
                    string signature = "";
                    if (field.FieldValue.Length > 1)
                    {
                        signature = field.FieldValue.Substring(1);
                    }
                    string keyData = Sheets.GetSignatureKey(sheet);
                    wrapper.FillSignature(sigIsTopaz, keyData, signature);
                }
                XImage sigBitmap = XImage.FromGdiPlusImage(wrapper.GetSigImage());
                g.DrawImage(sigBitmap, p(field.XPos), p(field.YPos), p(field.Width - 2), p(field.Height - 2));
            }
        }
        ///<summary>Runs as the final step of loading the form, and also immediately after fields are moved down due to growth.</summary>
        private void LayoutFields()
        {
            panelMain.Controls.Clear();
            RichTextBox   textbox;          //has to be richtextbox due to MS bug that doesn't show cursor.
            FontStyle     style;
            SheetCheckBox checkbox;

            //first, draw images---------------------------------------------------------------------------------------
            //might change this to only happen once when first loading form:
            if (pictDraw != null)
            {
                if (panelMain.Controls.Contains(pictDraw))
                {
                    Controls.Remove(pictDraw);
                }
                pictDraw = null;
            }
            imgDraw  = null;
            pictDraw = new PictureBox();
            if (SheetCur.IsLandscape)
            {
                imgDraw         = new Bitmap(SheetCur.Height, SheetCur.Width);
                pictDraw.Width  = SheetCur.Height;
                pictDraw.Height = SheetCur.Width;
            }
            else
            {
                imgDraw         = new Bitmap(SheetCur.Width, SheetCur.Height);
                pictDraw.Width  = SheetCur.Width;
                pictDraw.Height = SheetCur.Height;
            }
            pictDraw.Location = new Point(0, 0);
            pictDraw.Image    = (Image)imgDraw.Clone();
            pictDraw.SizeMode = PictureBoxSizeMode.StretchImage;
            panelMain.Controls.Add(pictDraw);
            panelMain.SendToBack();
            Graphics pictGraphics = Graphics.FromImage(imgDraw);

            foreach (SheetField field in SheetCur.SheetFields)
            {
                if (field.FieldType != SheetFieldType.Image)
                {
                    continue;
                }
                string filePathAndName = ODFileUtils.CombinePaths(SheetUtil.GetImagePath(), field.FieldName);
                Image  img             = null;
                if (field.FieldName == "Patient Info.gif")
                {
                    img = Properties.Resources.Patient_Info;
                }
                else if (File.Exists(filePathAndName))
                {
                    img = Image.FromFile(filePathAndName);
                }
                else
                {
                    continue;
                }
                pictGraphics.DrawImage(img, field.XPos, field.YPos, field.Width, field.Height);
            }
            pictGraphics.Dispose();
            //Set mouse events for the pictDraw
            pictDraw.MouseDown += new MouseEventHandler(pictDraw_MouseDown);
            pictDraw.MouseMove += new MouseEventHandler(pictDraw_MouseMove);
            pictDraw.MouseUp   += new MouseEventHandler(pictDraw_MouseUp);
            //draw drawings, rectangles, and lines-----------------------------------------------------------------------
            RefreshPanel();
            //draw textboxes----------------------------------------------------------------------------------------------
            foreach (SheetField field in SheetCur.SheetFields)
            {
                if (field.FieldType != SheetFieldType.InputField &&
                    field.FieldType != SheetFieldType.OutputText &&
                    field.FieldType != SheetFieldType.StaticText)
                {
                    continue;
                }
                textbox             = new RichTextBox();
                textbox.BorderStyle = BorderStyle.None;
                textbox.TabStop     = false;          //Only input fields allow tab stop (set below for input text).
                //textbox.Multiline=true;//due to MS malfunction at 9pt which cuts off the bottom of the text.
                if (field.FieldType == SheetFieldType.OutputText ||
                    field.FieldType == SheetFieldType.StaticText)
                {
                    //textbox.BackColor=Color.White;
                    //textbox.BackColor=Color.FromArgb(245,245,200);
                }
                else if (field.FieldType == SheetFieldType.InputField)
                {
                    textbox.BackColor = Color.FromArgb(245, 245, 200);
                    textbox.TabStop   = (field.TabOrder == 0?false:true);
                    textbox.TabIndex  = field.TabOrder;
                }
                textbox.Location   = new Point(field.XPos, field.YPos);
                textbox.Width      = field.Width;
                textbox.ScrollBars = RichTextBoxScrollBars.None;
                textbox.Text       = field.FieldValue;
                style = FontStyle.Regular;
                if (field.FontIsBold)
                {
                    style = FontStyle.Bold;
                }
                textbox.Font = new Font(field.FontName, field.FontSize, style);
                if (field.Height < textbox.Font.Height + 2)
                {
                    textbox.Multiline = false;
                    //textbox.AcceptsReturn=false;
                }
                else
                {
                    textbox.Multiline = true;
                    //textbox.AcceptsReturn=true;
                }
                textbox.Height = field.Height;
                //textbox.ScrollBars=RichTextBoxScrollBars.None;
                textbox.Tag          = field;
                textbox.TextChanged += new EventHandler(text_TextChanged);
                panelMain.Controls.Add(textbox);
                textbox.BringToFront();
            }
            //draw checkboxes----------------------------------------------------------------------------------------------
            foreach (SheetField field in SheetCur.SheetFields)
            {
                if (field.FieldType != SheetFieldType.CheckBox)
                {
                    continue;
                }
                checkbox = new SheetCheckBox();
                if (field.FieldValue == "X")
                {
                    checkbox.IsChecked = true;
                }
                checkbox.Location = new Point(field.XPos, field.YPos);
                checkbox.Width    = field.Width;
                checkbox.Height   = field.Height;
                checkbox.Tag      = field;
                checkbox.Click   += new EventHandler(text_TextChanged);
                checkbox.TabStop  = (field.TabOrder == 0?false:true);
                checkbox.TabIndex = field.TabOrder;
                panelMain.Controls.Add(checkbox);
                checkbox.BringToFront();
            }
            //draw signature boxes----------------------------------------------------------------------------------------------
            foreach (SheetField field in SheetCur.SheetFields)
            {
                if (field.FieldType != SheetFieldType.SigBox)
                {
                    continue;
                }
                OpenDental.UI.SignatureBoxWrapper sigBox = new OpenDental.UI.SignatureBoxWrapper();
                sigBox.Location = new Point(field.XPos, field.YPos);
                sigBox.Width    = field.Width;
                sigBox.Height   = field.Height;
                if (field.FieldValue.Length > 0)               //a signature is present
                {
                    bool sigIsTopaz = false;
                    if (field.FieldValue[0] == '1')
                    {
                        sigIsTopaz = true;
                    }
                    string signature = "";
                    if (field.FieldValue.Length > 1)
                    {
                        signature = field.FieldValue.Substring(1);
                    }
                    string keyData = Sheets.GetSignatureKey(SheetCur);
                    sigBox.FillSignature(sigIsTopaz, keyData, signature);
                }
                sigBox.Tag      = field;
                sigBox.TabStop  = (field.TabOrder == 0?false:true);
                sigBox.TabIndex = field.TabOrder;
                panelMain.Controls.Add(sigBox);
                sigBox.BringToFront();
            }
        }
Exemple #4
0
        private static void pd_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            Graphics g = e.Graphics;

            g.SmoothingMode = SmoothingMode.HighQuality;
            Sheet sheet = SheetList[sheetsPrinted];

            SheetUtil.CalculateHeights(sheet, g);           //this is here because of easy access to g.
            Font      font;
            FontStyle fontstyle;

            //first, draw images------------------------------------------------------------------------------------
            foreach (SheetField field in sheet.SheetFields)
            {
                if (field.FieldType != SheetFieldType.Image)
                {
                    continue;
                }
                string filePathAndName = ODFileUtils.CombinePaths(SheetUtil.GetImagePath(), field.FieldName);
                Image  img             = null; //js consider switching this from an image to a bitmap
                if (field.FieldName == "Patient Info.gif")
                {
                    img = Properties.Resources.Patient_Info;
                }
                else if (File.Exists(filePathAndName))
                {
                    img = Image.FromFile(filePathAndName);
                }
                else
                {
                    continue;
                }
                g.DrawImage(img, field.XPos, field.YPos, field.Width, field.Height);
                img.Dispose();
                img = null;
            }
            //then, drawings--------------------------------------------------------------------------------------------
            Pen pen = new Pen(Brushes.Black, 2f);

            string[]     pointStr;
            List <Point> points;
            Point        point;

            string[] xy;
            foreach (SheetField field in sheet.SheetFields)
            {
                if (field.FieldType != SheetFieldType.Drawing)
                {
                    continue;
                }
                pointStr = field.FieldValue.Split(';');
                points   = new List <Point>();
                for (int p = 0; p < pointStr.Length; p++)
                {
                    xy = pointStr[p].Split(',');
                    if (xy.Length == 2)
                    {
                        point = new Point(PIn.Int(xy[0]), PIn.Int(xy[1]));
                        points.Add(point);
                    }
                }
                for (int i = 1; i < points.Count; i++)
                {
                    g.DrawLine(pen, points[i - 1].X, points[i - 1].Y, points[i].X, points[i].Y);
                }
            }
            //then, rectangles and lines----------------------------------------------------------------------------------
            Pen pen2 = new Pen(Brushes.Black, 1f);

            foreach (SheetField field in sheet.SheetFields)
            {
                if (field.FieldType == SheetFieldType.Rectangle)
                {
                    g.DrawRectangle(pen2, field.XPos, field.YPos, field.Width, field.Height);
                }
                if (field.FieldType == SheetFieldType.Line)
                {
                    g.DrawLine(pen2, field.XPos, field.YPos,
                               field.XPos + field.Width,
                               field.YPos + field.Height);
                }
            }
            //then, draw text-----------------------------------------------------------------------------------------------
            Bitmap   doubleBuffer = new Bitmap(sheet.Width, sheet.Height);
            Graphics gfx          = Graphics.FromImage(doubleBuffer);

            foreach (SheetField field in sheet.SheetFields)
            {
                if (field.FieldType != SheetFieldType.InputField &&
                    field.FieldType != SheetFieldType.OutputText &&
                    field.FieldType != SheetFieldType.StaticText)
                {
                    continue;
                }
                fontstyle = FontStyle.Regular;
                if (field.FontIsBold)
                {
                    fontstyle = FontStyle.Bold;
                }
                font = new Font(field.FontName, field.FontSize, fontstyle);
                Plugins.HookAddCode(null, "SheetPrinting.pd_PrintPage_drawFieldLoop", field);
                GraphicsHelper.DrawString(g, gfx, field.FieldValue, font, Brushes.Black, field.Bounds);
                //g.DrawString(field.FieldValue,font,Brushes.Black,field.BoundsF);
            }
            gfx.Dispose();
            //then, checkboxes----------------------------------------------------------------------------------
            Pen pen3 = new Pen(Brushes.Black, 1.6f);

            foreach (SheetField field in sheet.SheetFields)
            {
                if (field.FieldType != SheetFieldType.CheckBox)
                {
                    continue;
                }
                if (field.FieldValue == "X")
                {
                    g.DrawLine(pen3, field.XPos, field.YPos, field.XPos + field.Width, field.YPos + field.Height);
                    g.DrawLine(pen3, field.XPos + field.Width, field.YPos, field.XPos, field.YPos + field.Height);
                }
            }
            //then signature boxes----------------------------------------------------------------------
            foreach (SheetField field in sheet.SheetFields)
            {
                if (field.FieldType != SheetFieldType.SigBox)
                {
                    continue;
                }
                SignatureBoxWrapper wrapper = new SignatureBoxWrapper();
                wrapper.Width  = field.Width;
                wrapper.Height = field.Height;
                if (field.FieldValue.Length > 0)              //a signature is present
                {
                    bool sigIsTopaz = false;
                    if (field.FieldValue[0] == '1')
                    {
                        sigIsTopaz = true;
                    }
                    string signature = "";
                    if (field.FieldValue.Length > 1)
                    {
                        signature = field.FieldValue.Substring(1);
                    }
                    string keyData = Sheets.GetSignatureKey(sheet);
                    wrapper.FillSignature(sigIsTopaz, keyData, signature);
                }
                Bitmap sigBitmap = wrapper.GetSigImage();
                g.DrawImage(sigBitmap, field.XPos, field.YPos, field.Width - 2, field.Height - 2);
            }
            g.Dispose();
            //no logic yet for multiple pages on one sheet.
            sheetsPrinted++;
            //heightsCalculated=false;
            if (sheetsPrinted < SheetList.Count)
            {
                e.HasMorePages = true;
            }
            else
            {
                e.HasMorePages = false;
                sheetsPrinted  = 0;
            }
        }